2018-01-25 06:22:18 -0600 received badge ● Popular Question (source) 2013-01-16 23:07:12 -0600 commented answer subs(_expr) not working properly? Thanks, that helped! 2013-01-16 23:06:39 -0600 received badge ● Scholar (source) 2013-01-16 23:06:39 -0600 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-16 23:06:25 -0600 received badge ● Supporter (source) 2013-01-16 04:46:07 -0600 received badge ● Student (source) 2013-01-16 02:44:03 -0600 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?