On 29 sep, 21:28, Burcin Erocal <bur...@erocal.org> wrote:
> On Wed, 29 Sep 2010 07:38:59 -0700 (PDT)
>
>
>
> Jean-Pierre Flori <jpfl...@gmail.com> wrote:
> > Sage has the following behavior inherited from GiNaC (http://
> >www.ginac.de/tutorial/Pattern-matching-and-advanced-substitutions.html)
> > :
>
> > ----------------------------------------------------------------------
> > | Sage Version 4.5.3, Release Date: 2010-09-04                       |
> > | Type notebook() for the GUI, and license() for information.        |
> > ----------------------------------------------------------------------
> > sage: x,y,z = var('x,y,z')
> > sage: P = x+y
> > sage: P.subs({x+y:z})
> > z
> > sage: P = x+y+z
> > sage: P.subs({x+y:z})
> > x + y + z
> > sage: w0 = SR.wild(0)
> > sage: P.subs({x+y+w0:z+w0})
> > 2*z
> > sage: P = x+y
> > sage: P.subs({x+y+w0:z+w0})
> > z
> > sage:
>
> > Of course the same thing is happening with mul objects.
> > I think this is somewhat misleading and should at least be explained
> > in the documentation.
> > The above url is already give in the documentation of the match
> > function but not in the one of subs.
> > Maybe this explains the warning in the documentation of the subs_expr
> > function.
>
> The function substitute_expression() is one of the relics remaining
> from the old symbolics code. IMHO, we should merge it with the
> substitute() function and deprecate it.
>
>
>
> > However that warning refers to Maxima whereas :
>
> > sage: get_systems('P.subs_expr({x+y+w0:z+w0})')
> > ['ginac']
>
> > The weird example can also be solved using a wildcard :
>
> > sage: t = var('t')
> > sage: f(x,y,t) = cos(x) + sin(y) + x^2 + y^2 + t
> > sage: f
> > (x, y, t) |--> x^2 + y^2 + t + sin(y) + cos(x)
> > sage: f.subs_expr(x^2 + y^2 == t)
> > (x, y, t) |--> x^2 + y^2 + t + sin(y) + cos(x)
> > sage: f.subs_expr(x^2 + y^2 + w0 == t + w0)
> > (x, y, t) |--> 2*t + sin(y) + cos(x)
>
> > I don't know if such a trick should be implemented in Sage, pynac, or
> > even in GiNaC.
>
> You can definitely suggest it to the ginac developers. I'm curious to
> see what they think.
>
> Note that this might not be so straight forward, especially if the
> expression we're supposed to replace contains wildcards in the first
> place. We can add some logic to our interface to ginac and add the
> wildcard to the expression if none exists. Though I'm afraid this might
> increase the confusion if someone is trying to debug substitutions in a
> complex expression.
>
> One other point against doing this by default is that substituting with
> wildcards is slower. Even if we decide to do this, there should be an
> option not to.
I completely agree with that and am aware that it would be slower.
That is why I don't think it should be done by default, but something
in the doc should give someinsight on what is going on and what can be
done.

>
> Cheers,
> Burcin

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to