On 11/09/2010 3:46 PM, Aaron S. Meurer wrote:
I think you want the collect() function and the .as_independent method. The easiest way to manipulate Equalities is to first convert them into regular expressions. Then, you would call collect on the expression using x**2. collect collects all powers of the argument by default, but you can use the exact=False flag to turn this off (see the docstring of collect). Actually, collect is optional, and is only if you want (A + D)*x**2 instead of A*x**2 + D*x**2.

Then, you can gather the independent and dependent parts using as_independent. Here is an example of how you would do it with your expression:

In [1]: var('A B C D E F')
Out[1]: (A, B, C, D, E, F)

In [2]: expr = Eq(A*x**2 + B*y**2 + C*x*y + D*x**2, E*z**2 + F)

In [3]: expr
Out[3]:
           2      2      2          2
C⋅x⋅y + A⋅x  + B⋅y  + D⋅x  = F + E⋅z

In [4]: expr = expr.lhs - expr.rhs

In [5]: expr
Out[5]:
                2      2      2      2
-F + C⋅x⋅y + A⋅x  + B⋅y  + D⋅x  - E⋅z

In [6]: expr = collect(expr, x**2, exact=True)

In [7]: expr
Out[7]:
      2                      2      2
-F + x ⋅(A + D) + C⋅x⋅y + B⋅y  - E⋅z

In [8]: expr.as_independent(x**2, y**2)
Out[8]:
⎛                2   2              2⎞
⎝-F + C⋅x⋅y - E⋅z , x ⋅(A + D) + B⋅y ⎠

In [9]: expr = Eq(*reversed(expr.as_independent(x**2, y**2)))

In [10]: expr
Out[10]:
 2              2                   2
x ⋅(A + D) + B⋅y  = -F + C⋅x⋅y - E⋅z

It shouldn't be too hard to write a simple function that is passed an Equality and some variables and returns the result like in [10].

Aaron Meurer


Thanks, Aaron; that's exactly what I wanted and it is very exciting to realize that this can be done. I've just started playing with sympy and exploring its possibilities, so thank you very much for helping to guide me and for your response!

Nicholas





--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to