On Tue, Jul 10, 2012 at 11:01 AM, Martin Raum
<
Marti...@matha.rwth-aachen.de> wrote:
> Hallo all!
>
> I have found the following bug which mostly occurs when substituting power
> series over inexact rings. E.g.
>
> R.<x> = CC[[]]
> x.subs(x = x**2)
>
> gives x. Same for the base field Qp(7).
Quick remark. It is far, far better to use a dictionary as input to
subs, if you can stand typing the extra braces. For example, the
above issue works fine with a dictionary:
sage: R.<x> = CC[[]]
sage: x.subs({x:x**2})
0.000000000000000 + 0.000000000000000*x + 1.00000000000000*x^2
The issue is that if you use subs(foo=bar), then Python interprets foo
as the keyword (=string) "foo"; there is *no way* to do subs(x=x^2) in
Python and have x be a Python variable. Here's another example where
subs with a dictionary is much better:
sage: R.<x,x> = CC[[]]; f = R.0 + R.1; f
x + x
sage: f.subs({R.0:5}) == 5 + R.1
True
sage: f.subs({R.1:5}) == 5 + R.0
True
There's no way with strings to ever do the above...
>
> The reason is that the generic method subs iterates the generators of R (in
> this case x) and checks whether any keyword matches the string
> representation of that generator. But
>
> x._repr_()
>
> does not give 'x', but 0.0... + 1.0... x.
>
> There are two obvious ways to fix this: Change _repr_ or change subs. By
> changing _repr_, we would accept that some elements are wrongly printed as
> exact elements, but this approach would correspond to the fact that
>
> CC(0) == CC(0)
>
> is true. By changing subs, we would introduce a specialized method for power
> series rings, while so far any ParentWithGens comes with the same
> implementation.
>
> I would rather change _repr_. What do you think?
>
> Best, Martin
>
> --
> --
> To post to this group, send an email to
sage-...@googlegroups.com
> To unsubscribe from this group, send an email to
>
sage-devel+...@googlegroups.com
> For more options, visit this group at
>
http://groups.google.com/group/sage-devel
> URL:
http://www.sagemath.org
--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org