On 02/20/2012 04:35 PM, Chris Smith wrote:


On Tue, Feb 21, 2012 at 3:02 AM, Alan Bromborsky <[email protected] <mailto:[email protected]>> wrote:

    Is there a simple way of extracting the following from  a sympy
    expression -

    expr = expr_0 + expr_1+...+expr_n

    where in each expr_j (j>0) there is a factor a_j which is a symbol
    (in my case noncommuting).  I need to extract the
    parts of expr_j that multiplies a_j for all the expr_1.  Only one
    a_j is a factor in expr_j .  That is if one can rewrite

    expr = expr_0 + expr'_1*a_1+...+expr'_n*a_n

    and then extract (expr_0,expr'_1,...,expr'_n)


Is this different than you were writing about in the "not reinventing" message? I had written

>>> eq=a*A+b*c*B+d
>>> zip(*[arg.args_cnc() for arg in eq.args])
[([a], [d], [b, c]), ([A], [], [B])]

The first list of lists is a list of the factors that are in front of the noncommutative parts of your terms. If you want them as expressions, remultiply them:

>>> eq=a*A+b*c*B+d
>>> co, nc = zip(*[arg.args_cnc() for arg in eq.args])
>>> [Mul(*c) for c in co]
[a, d, b*c]
>>> nc
([A], [], [B])

Can you give a concrete example of input and output that you would like?

/c
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
My problem is that I am a lousy speller and I spelled the commutative keyword in symbol wrong!!!!

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

Reply via email to