Wildcards for subs()
Richard B. Kreckel
kreckel at thep.physik.uni-mainz.de
Tue May 22 20:17:56 CEST 2001
On Tue, 22 May 2001, Christian Bauer wrote:
> It has been suggested to me that it would be a desirable feature for subs()
> to be able to specify wildcards for indices and function arguments so you
> could, for example
>
> - in "sin(x-1)+sin(2*y)", substitute sin(?) by cos(?)/2 to get
> "cos(x-1)/2+cos(2*y)/2"
> - in "atan2(x+y,z^2)", substitute atan2(?1,?2) by ?2/?1 to get
> "z^2/(x+y)"
> - in "F.mu*g.nu.rho+F.nu*g.mu.rho", substitute F.? by a.?+b.? to get
> "(a.mu+b.mu)*g.nu.rho+(a.nu+b.nu)*g.mu.rho"
>
> This should be relatively easy to implement by extending indexed::subs() and
> function::subs() and adding a new "wildcard/wild" class that has an integer
> member to distinguish multiple wildcards. Function substitution would then
> go something like
>
> e.subs(atan2(wild(1), wild(2)) == wild(2)/wild(1));
>
> and substitution of base expressions of indexed objects is similar:
>
> e.subs(indexed(wild(), mu) == indexed(wild(), mu)/2+indexed(A, mu));
>
> Wildcards for indices are a little more involved because indices must be of
> class idx, so one would have to write
>
> e.subs(indexed(F, varidx(wild(), 4)) ==
> indexed(a, varidx(wild(), 4)) + indexed(b, varidx(wild(), 4)));
>
> which is a little clumsy but has the advantage of taking index dimensions
> and variance into account (this can also be a disadvantage because it could
> only substitute F~mu, not F.mu).
>
> Any comments/suggestions?
Well, it doesn't sound unreasonable to me. Apart from the question what
sin(sin(x)).subs(sin(wild(1))==sqrt(1-pow(cos(wild1),2)) is supposed to
produce. Is it sin(sqrt(1-pow(cos(x),2)))? Or rather
sqrt(1-pow(cos(sqrt(1-pow(cos(x),2))),2))? subs(relational, int level=1)?
All of these have their justification, I guess. Otherwise you could just
stuff the subs into a while(foo.has(..)) { ... } loop, since that seems to
be allowed now. Also, since until now nobody has complained about the
tree traversal algorithm advertised in the Mini-FAQ at
<http://www.ginac.de/FAQ.html#treetraverse> being incomplete in this
respect one level is probably the most natural thing to do. But I may be
wrong...
Regards
-richy.
--
Richard Kreckel
<Richard.Kreckel at Uni-Mainz.DE>
<http://wwwthep.physik.uni-mainz.de/~kreckel/>
More information about the GiNaC-devel
mailing list