Ask Your Question

cschwan's profile - activity

2024-02-11 20:17:54 +0200 received badge  Famous Question (source)
2024-02-11 20:17:54 +0200 received badge  Notable Question (source)
2018-01-25 13:22:18 +0200 received badge  Popular Question (source)
2013-01-17 06:07:12 +0200 commented answer subs(_expr) not working properly?

Thanks, that helped!

2013-01-17 06:06:39 +0200 marked best answer subs(_expr) not working properly?

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.

2013-01-17 06:06:39 +0200 received badge  Scholar (source)
2013-01-17 06:06:25 +0200 received badge  Supporter (source)
2013-01-16 11:46:07 +0200 received badge  Student (source)
2013-01-16 09:44:03 +0200 asked a question 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?