Ask Your Question
1

subs(_expr) not working properly?

asked 2013-01-16 09:44:03 +0200

cschwan gravatar image

updated 2015-01-14 14:15:24 +0200

FrédéricC gravatar image

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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2013-01-16 11:46:03 +0200

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.

Try this instead:

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 information available in the relevant section of the GiNaC tutorial.

edit flag offensive delete link more

Comments

Thanks, that helped!

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

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-01-16 09:44:03 +0200

Seen: 534 times

Last updated: Jan 16 '13