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 ...
Note that in
a,t,p,l,k,c,b=var('a t p l c k b')
, the variables $c$ and $k$ seem to be accidentally interchanged. For the substitution into expressions like $p^2 t$ and so on you could use wildcards.