[GiNaC-list] Fw: [sage-support] (5-e^x).substitute(x=log(x)) goes wrong?

Richard B. Kreckel kreckel at ginac.de
Wed Sep 15 09:42:50 CEST 2010


Hi!

I have pushed a patch that fixes the problem.

The patch avoids the final subs_one_level on anything but containers. 
Why? As the bug shows, this substitution is wrong in the general case:

f(x).subs(x==f^-1(x))
   -> f(f^-1(x))   [subschildren]
   -> x            [eval]
   -> f^-1(x)      [subs_one_level] Bug!

On the other hand, the intent (as advertised e.g. in the tutorial) is to 
syntactically substitute functions of a certain kind etc., so, assuming 
three hypothetical function f, g, and h where f(h(x)) evaluates to g(x):

f(g(x)).subs(g(x)==h(x))
   -> f(h(x))      [subschildren]
   -> g(x)         [eval]
   -> h(x)         [subschildren] Okay!

In this case, stopping after the second step would not be satisfactory. 
This syntactic substitution is clearly only for the top level (as the 
method's name subs_one_level implies) but should not be applied to symbols.

This patch is for container<C> a.k.a. exprseq, so besides for functions 
it also applies to classes indexed and ncmul. I am reasonably sure it's 
also correct there.

This case is very similar to a problem that lead to release of GiNaC 1.0.6.

Burcin, this should apply cleanly to Sage.

Bye!
   -richy.
-- 
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>


More information about the GiNaC-list mailing list