# Revision history [back]

### equation not simplifying and substituting properly

I have the following code where I want to substitute t and p expression into my 'a' expression. Unfortunately what I get is a long equation which still have some powers of p and t variable in it. It seems like the substitution did not work properly

a,t,p,l,k,c,b=var('a t p l c k b')
a=(-2*p*t^2-p^2*t)+(2*t*p-p^2)+t+1;a
A=a.subs({t:((c-a)+4*l)/(a+b+c)}).subs({p:((b-c)+4*k)/(a+b+c)});A


This is what I obtained :

-(2*(b + 4*c - k)*t^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - k - 4*l - 2*(b + 4*c - k)*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - (b + 4*c - k)^2*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + t - (b + 4*c - k)^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + 1)/(2*(b + 4*c - k)*t^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) + b + k - 2*(b + 4*c - k)*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - (b + 4*c - k)^2*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + t - (b + 4*c - k)^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + 1) + 2*(2*(b + 4*c - k)*t^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - k - 4*l - 2*(b + 4*c - k)*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - (b + 4*c - k)^2*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + t - (b + 4*c - k)^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + 1)*(b + 4*c - k)/((p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)*(2*(b + 4*c - k)*t^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) + b + k - 2*(b + 4*c - k)*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - (b + 4*c - k)^2*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + t - (b + 4*c - k)^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + 1)) + 2*(2*(b + 4*c - k)*t^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - k - 4*l - 2*(b + 4*c - k)*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - (b + 4*c - k)^2*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + t - (b + 4*c - k)^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + 1)^2*(b + 4*c - k)/((p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)*(2*(b + 4*c - k)*t^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) + b + k - 2*(b + 4*c - k)*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - (b + 4*c - k)^2*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + t - (b + 4*c - k)^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + 1)^2) - (b + 4*c - k)^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + (2*(b + 4*c - k)*t^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - k - 4*l - 2*(b + 4*c - k)*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - (b + 4*c - k)^2*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + t - (b + 4*c - k)^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + 1)*(b + 4*c - k)^2/((p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2*(2*(b + 4*c - k)*t^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) + b + k - 2*(b + 4*c - k)*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1) - (b + 4*c - k)^2*t/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + t - (b + 4*c - k)^2/(p^2*t + 2*p*t^2 + p^2 - 2*p*t - b - k - t - 1)^2 + 1)) + 1


And I also have l^2=2c^2+2a^2-b^2 and k^2=2b^2+2c^2-a^2. Is there a way I can make all this substitution at once. The final answer should simplify down to 'a'.