On 14 July 2014 04:47, Jonathan Holmes <freeps...@gmail.com> wrote: > Suppose EXP2 is an expression which happens to be a polynomial in one > collection C of variables C_1,C_2,C_3,...C_n with coefficients depending on > a collection D of variables D_1,D_2,...,D_m > (EXP2=sum_{alpha in > I}[A_alpha(D_1,D_2,...,D_m)*product_{k=1}^n[C_{alpha_k}^{alpha_k}]], where I > is a finite index set in the set of n-tuples of integers and A_alpha is a > coefficient). Suppose EXP1 is an expression which is equal to EXP2, but > which is scrambled. > > If I only have EXP1, how can I automatically rewrite it to be in the form of > EXP2? > > Suppose, for example, that I have the code > > a=var('a') > b=var('b') > c=var('c') > d=var('d') > e=var('e') > eqn=a==b*(d^2)+e*(c+d) + c*(2*b+e) > > How could I rearrage eqn automatically so that I am expressing a as a sum of > b times a coefficent depending on c and d plus e times a coeffient depending > on d and e, such that I get the equation > > a==b*(d^2+2*c)+e*(2*c+d)?
If you set sage: rhs = b*(d^2)+e*(c+d) + c*(2*b+e) then sage: rhs.collect(b).collect(e) (d^2 + 2*c)*b + (2*c + d)*e Alternatively, you could use polynomial rings instead of symbolic expressions, like this: sage: R1.<c,d> = QQ[] sage: R2.<b,e> = R1[] sage: a = b*(d^2)+e*(c+d) + c*(2*b+e) sage: a (d^2 + 2*c)*b + (2*c + d)*e sage: R1 Multivariate Polynomial Ring in c, d over Rational Field sage: R2 Multivariate Polynomial Ring in b, e over Multivariate Polynomial Ring in c, d over Rational Field but I suspect that this is not really what you want. I never use symbolic expressions myself. John Cremona > > -- > You received this message because you are subscribed to the Google Groups > "sage-support" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-support+unsubscr...@googlegroups.com. > To post to this group, send email to sage-support@googlegroups.com. > Visit this group at http://groups.google.com/group/sage-support. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.