Ask Your Question

Revision history [back]

Simplifying expression by known terms

I have expression that need to be simplified to the known terms. Below are the expression:

var('b0 a1 a2 h v_0 v_1 v_2 u_0 u_1 u_2');
expr = b0 == (16*h^2*v_0^2+(38*h*u_0-38*h*u_1)*v_0+25*u_1^2-50*u_0*u_1+25*u_0^2)/3;
expr.substitute(-h*v_0+2*u_1-2*u_0==a1,-2*(h*v_0-u_1+u_0)==a2)

The expected result is

b0 == c1*(a1)^q1 + c2*(a2)^q2

where c1, c2, q1, q2 are constants.

The output from Sage is

b0 == 16/3*h^2*v_0^2 + 25/3*u_0^2 - 50/3*u_0*u_1 + 25/3*u_1^2 + 38/3*(h*u_0 - h*u_1)*v_0