Suppose that EXP2 is a polynomial expression in the variables X_1,X_2,...,X_n with coefficients that depend on the variables B_1,B_2,...,B_n. Suppose EXP1 is an expression equal to EXP2, but scrambled.
Given EXP1, how can I automatically obtain EXP2?
For example, if I have
a=var('a') b=var('b') c=var('c') d=var('d') e=var('e') eqn=a==bd^2+ce^2+e(b+2c*d),
how can I automatically rewrite a as a polynomial in b and c, so that I get an equation that looks like
a==b(d^2+e)+c(e^2+2ed)?