++result;
}
+ // And this used to fail in GiNaC 1.5.8 because it first substituted
+ // exp(x) -> exp(log(x)) -> x, and then substitued again x -> log(x)
+ e1 = exp(x);
+ e2 = e1.subs(x == log(x));
+ if (!e2.is_equal(x)) {
+ clog << "exp(x).subs(x==log(x)) erroneously returned " << e2 << " instead of x" << endl;
+ ++result;
+ }
+
e1 = sin(1+sin(x));
e2 = e1.subs(sin(wild()) == cos(wild()));
if (!e2.is_equal(cos(1+cos(x)))) {
template <template <class T, class = std::allocator<T> > class C>
ex container<C>::subs(const exmap & m, unsigned options) const
{
+ // After having subs'ed all children, this method subs'es one final
+ // level, but only if the intermediate result is a container! This is
+ // because if the intermediate result has eval'ed to a non-container a
+ // last level substitution would be wrong, as this example involving a
+ // function f and its inverse f^-1 shows:
+ // f(x).subs(x==f^-1(x))
+ // -> f(f^-1(x)) [subschildren]
+ // -> x [eval] /* must not subs(x==f^-1(x))! */
std::auto_ptr<STLT> vp = subschildren(m, options);
- if (vp.get())
- return ex_to<basic>(thiscontainer(vp)).subs_one_level(m, options);
- else
- return subs_one_level(m, options);
+ if (vp.get()) {
+ ex result(thiscontainer(vp));
+ if (is_a<container<C> >(result))
+ return ex_to<basic>(result).subs_one_level(m, options);
+ else
+ return result;
+ } else {
+ if (is_a<container<C> >(*this))
+ return subs_one_level(m, options);
+ else
+ return *this;
+ }
}
/** Compare two containers of the same type. */