# subs(_expr) not working properly?

Hi, I am trying to substitute in the following expression:

denominator = -1/2*((P3 - sqrt(P1^2 + P2^2 + P3^2))*(P1*m/(P1^2 + P2^2 + P3^2 +
sqrt(P1^2 + P2^2 + P3^2)*P0) - I*P2*m/(P1^2 + P2^2 + P3^2 + sqrt(P1^2 +
P2^2 + P3^2)*P0) + 2*P1 - 2*I*P2) - (P1 - I*P2)*(P3*m/(P1^2 + P2^2 +
P3^2 + sqrt(P1^2 + P2^2 + P3^2)*P0) + 2*P0 + 2*P3 - sqrt(P1^2 + P2^2 +
P3^2)*m/(P1^2 + P2^2 + P3^2 + sqrt(P1^2 + P2^2 +
P3^2)*P0)))/sqrt(1/2*P3*m/(P1^2 + P2^2 + P3^2 + sqrt(P1^2 + P2^2 +
P3^2)*P0) + P0 + P3 - 1/2*sqrt(P1^2 + P2^2 + P3^2)*m/(P1^2 + P2^2 + P3^2
+ sqrt(P1^2 + P2^2 + P3^2)*P0))


which uses the following variables:

var('P,P0,P1,P2,P3,Q0,Q1,Q2,Q3,q0,q1,q2,q3,m')


As you can see its not a trivial one. I am now trying to introduce some abbreviations to make the expression more readable, i.e.

denominator.subs_expr(P1^2+P2^2+P3^2==P)


This command only work partially, i.e. it replaces the expressions inside a square root, but not the remaining ones:

-1/2*((P3 - sqrt(P))*(P1*m/(P1^2 + P2^2 + P3^2 + sqrt(P)*P0) -
I*P2*m/(P1^2 + P2^2 + P3^2 + sqrt(P)*P0) + 2*P1 - 2*I*P2) - (P1 -
I*P2)*(P3*m/(P1^2 + P2^2 + P3^2 + sqrt(P)*P0) + 2*P0 + 2*P3 -
sqrt(P)*m/(P1^2 + P2^2 + P3^2 + sqrt(P)*P0)))/sqrt(1/2*P3*m/(P1^2 + P2^2
+ P3^2 + sqrt(P)*P0) + P0 + P3 - 1/2*sqrt(P)*m/(P1^2 + P2^2 + P3^2 +
sqrt(P)*P0))


Is that the supposed behavior? How can I achieve what I wanted?

edit retag close merge delete

Sort by » oldest newest most voted

When asked to replace P1^2+P2^2+P3^2 by P, GiNaC (symbolics back-end for Sage) looks for an exact match. If this sum is part of an expression, such as P1^2 + P2^2 + P3^2 + sqrt(P)*P0 there will be no substitution.

sage: denominator.substitute({P1^2: P- P2^2 - P3^2})
-1/2*((P3 - sqrt(P))*(P1*m/(sqrt(P)*P0 + P) - I*P2*m/(sqrt(P)*P0 + P) + 2*P1 - 2*I*P2) - (P1 - I*P2)*(P3*m/(sqrt(P)*P0 + P) + 2*P0 + 2*P3 - sqrt(P)*m/(sqrt(P)*P0 + P)))/sqrt(1/2*P3*m/(sqrt(P)*P0 + P) + P0 + P3 - 1/2*sqrt(P)*m/(sqrt(P)*P0 + P))


more

Thanks, that helped!

( 2013-01-17 06:07:12 +0200 )edit

ha ha ha, a very clever workaround!! +1

( 2013-01-17 10:49:48 +0200 )edit