X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fbasic.cpp;h=e8c893ba26dd59a963e00fd1056daf34f4f47bf8;hp=a3de04aab9cd306eda820e8d7b50dadc492f3164;hb=e9b5729311fcd5572d806f5df2e645e1845603e5;hpb=83a7ee99a947cbbf331018b803ad6be43a9ccd45 diff --git a/ginac/basic.cpp b/ginac/basic.cpp index a3de04aa..e8c893ba 100644 --- a/ginac/basic.cpp +++ b/ginac/basic.cpp @@ -290,7 +290,7 @@ ex & basic::operator[](size_t i) * but e.has(x+y) is false. */ bool basic::has(const ex & pattern, unsigned options) const { - lst repl_lst; + exmap repl_lst; if (match(pattern, repl_lst)) return true; for (size_t i=0; iop(0).is_equal(pattern)) - return is_equal(ex_to(it->op(1))); + for (exmap::const_iterator it = repl_lst.begin(); it != repl_lst.end(); ++it) { + if (it->first.is_equal(pattern)) + return is_equal(ex_to(it->second)); } - repl_lst.append(pattern == *this); + repl_lst[pattern] = *this; return true; } else { @@ -585,12 +585,18 @@ bool basic::match(const ex & pattern, lst & repl_lst) const if (!match_same_type(ex_to(pattern))) return false; + // Even if the expression does not match the pattern, some of + // its subexpressions could match it. For example, x^5*y^(-1) + // does not match the pattern $0^5, but its subexpression x^5 + // does. So, save repl_lst in order to not add bogus entries. + exmap tmp_repl = repl_lst; // Otherwise the subexpressions must match one-to-one for (size_t i=0; i(it->first), repl_lst)) - return it->second.subs(repl_lst, options | subs_options::no_pattern); // avoid infinite recursion when re-substituting the wildcards + return it->second.subs(repl_lst, options | subs_options::no_pattern); + // avoid infinite recursion when re-substituting the wildcards } }