Is there a reason why integers are treated so differently to variables? If, for example, 2 is replaced by a variable, everything works as expected:

h = (k1 + k2)*x
h.subs_expr(k1 + k2 == k3)

k3*x

I don't understand why g is expanded to

2*k1 + 2*k2

but h not to

x*k1 + x*k2


Is there no way to manipulate how an expression is transformed? It would be a nice feature.

Cheers
Stan

On 25/01/10 20:36, stefan wrote:
Hi Burcin,


thank you, so it won't work what I tried..

Thanks anyway.
STefan


On Monday 25 January 2010 05:41:42 pm Burcin Erocal wrote:
Hi Stefan,

On Mon, 25 Jan 2010 06:49:55 -0800 (PST)

Ichnich<warm...@web.de>  wrote:
there seems to be a bug in substitute:

var('k1 k2 k3')
f = (k1+k2)^2
f.substitute(k1+k2==k3)

gives k3^2 as expected.

var('k1 k2 k3')
f = (k1+k2)*2
f.substitute(k1+k2==k3)

gives 2*k1 + 2*k2. The same happens for +2 instead of *2.
In your example, (k1 + k2) is not a subexpression of f, so there is
nothing to substitute.

sage: var('k1 k2 k3')
(k1, k2, k3)
sage: f = (k1+k2)*2
sage: f
2*k1 + 2*k2
sage: f.has(k1+k2)
False

Is there an alternative to do a substitution?
You can rephrase your substitution as k1 == k3 - k2:

sage: f.substitute(k1==k3-k2)
2*k3


Cheers,
Burcin

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

Reply via email to