Le 10/07/2012 21:58, William Stein a écrit :
On Tue, Jul 10, 2012 at 11:01 AM, Martin Raum
<[email protected]>  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...


I can't help but notice that help(f.subs) indeed says the argument should be a dict, but most examples don't do that (in fact, only the very first one uses a dict!).

Documentation bug?

Snark

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

Reply via email to