Never mind, I figured this out myself:

On Mon, Nov 10, 2008 at 1:15 PM, Brian Granger <[EMAIL PROTECTED]> wrote:
> OK, sounds great.  Now a follow on....or two...
>
> * How can I get the non-commuting part of the Mul?  I see that
> Mul.flatten knows about it, but I don't see how to get it back.

Just do

Mul.flatten(o.args) where o is my Mul instance

> * I then need to take an expression, find all the instances of Mul in
> the tree and replace those by something else, one by one.  Is there a
> simple way of doing this?  the most common usage case that I will have
> is a sum of terms;

Use o.atoms(Mul) to get a set of all the Mul instances and then use
o.subs(old, new) to rewrite them all.

Having fun now...

Brian

> 3*A*B*|state1> + 4*C*D*|state>
>
> Thanks!!!
>
> Brian
>
> On Mon, Nov 10, 2008 at 1:08 PM, Ondrej Certik <[EMAIL PROTECTED]> wrote:
>>
>> On Mon, Nov 10, 2008 at 9:57 PM, Brian Granger <[EMAIL PROTECTED]> wrote:
>>>
>>> This is what I was afraid of.  The problem is that the __mul__ that I
>>> need to get rid of is on Basic, which all my classes inherit from.  I
>>> will probably just write a function that takes the flattened args of
>>> the final Mul class and "do the right thing"
>>
>> Exactly, that's the way to go, because we want to be able to
>> manipulate with the state in this form as well:
>>
>> A*B*C*D*|n>
>>
>> and optionally convert it to the form:
>>
>> E*|m>
>>
>> So the only way is to let sympy handle the multiplication (i.e.
>> associative but not commutative) and then apply our own function to
>> actually simplify it.
>>
>> Ondrej
>>
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
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