# Simplifying expression

Hello, 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

edit retag close merge delete

Sort by ยป oldest newest most voted

You'd better employ polynomial machinery here:

R.<b0, h, v_0, v_1, v_2, u_0, u_1, u_2, a1, a2> = PolynomialRing( QQ, order='lex' )
J = R.ideal( [-h*v_0+2*u_1-2*u_0 - a1, -2*(h*v_0-u_1+u_0) - a2] )
J.reduce( 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 ) )


Notice that a0 and a1 comes last in the list of variables in R.<...> and so under the lexicographical order (order='lex') the other variables will be eliminated (by .reduce() function) in favor of using a1 and a2. The result of .redice() function is

b0 - a1^2 - 13/12*a2^2


which you may interpret as b0 == a1^2 + 13/12*a2^2 if you like.

more