On Jul 8, 10:09 pm, William Stein <wst...@gmail.com> wrote:
> On Wed, Jul 8, 2009 at 1:28 AM, Kwankyu<ekwan...@gmail.com> wrote:
>
> > Hi,
>
> > I was surprised to see
>
> > sage: R.<x,y>=QQ[]
> > sage: g=x+y
> > sage: g.subs({x:x+1,y:x*y})
> > x*y + x + y + 1
>
> > So the order of substitution matters...unfortunately.
>
> > sage: g.subs({x:x+1}).subs({y:x*y})
> > x*y + x + 1
> > sage: g.subs({y:x*y}).subs({x:x+1})
> > x*y + x + y + 1
>
> > So the order seems to be from right to left. This seems to me
> > unnatural. Anyway this is undocumented.
>
> Actually, i guess it is documented.  However, I consider it a serious
> design flaw.
> Many thanks for pointing this out!!
>
> I consider this a serious design flaw for the following reasons:
>
>  (1) it is too hard to understand the above behavior, since it depends
> on the hash values symbolic variables, which might possibly be
> system-dependent.
>
>  (2) it is totally inconsistent with the behavior for symbolic
> expressions, where things are done right.
>
>  (3) it is totally inconsistent with the behavior of *homomorphisms*,
> where things are also done right.
>
> Here is a session to illustrate the above points:
>
> # BAD
> sage: R.<x,y>=QQ[]
> sage: g=x+y
> sage: g.subs({x:x+1,y:x*y})
> x*y + x + y + 1
>
> # BAD
> sage: R.<x,y>=QQ[]
> sage: g=x+y
> sage: g.subs(x=x+1,y=x*y)
> x*y + x + y + 1
>
> # GOOD
> sage: R.<x,y>=QQ[]
> sage: phi = R.hom([x+1,x*y])
> sage: g=x+y
> sage: phi(g)
> x*y + x + 1
>
> # GOOD
> sage: var('x,y')
> sage: g = x+y
> sage: g.subs({x:x+1,y:x*y})
> x*y + x + 1
>
> # GOOD
> sage: var('x,y')
> sage: g = x+y
> sage: g.subs(x=x+1,y=x*y)
> x*y + x + 1
>
> > What should be done to this?
>
> 1. I suggest that for now you use Hom, as illustrated above, as a workaround.
>
> 2. I think subs should be reimplemented using Hom.  Note that this
> could break existing code, so will have to be done carefully.    We
> can leave the old behavior in for speed, but as a non-default option.
>  I really hope Martin agrees with me about this, since having his
> support will make this step easier.
>
> 3. Come up with a fast way to implement the new behavior.
>

Hom works well for me. Thank you for straightening things up as
always!
> This is now trac #6482:http://sagetrac.org/sage_trac/ticket/6482
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to