[sympy] Re: R->L operator precedence

2008-11-10 Thread Ondrej Certik
On Mon, Nov 10, 2008 at 8:16 PM, Brian Granger <[EMAIL PROTECTED]> wrote: > > Hi, > > By default, Python's * operator work in L->R order, so: > > a*b*c*d = ((a*b)*c)*d > > But, I am implementing some operators from quantum mechanics that I > want to apply like this: > > a*b*c*d = a*(b*(c*d)) > > I

[sympy] Re: R->L operator precedence

2008-11-10 Thread Ondrej Certik
On Mon, Nov 10, 2008 at 8:31 PM, Ondrej Certik <[EMAIL PROTECTED]> wrote: > On Mon, Nov 10, 2008 at 8:16 PM, Brian Granger <[EMAIL PROTECTED]> wrote: >> >> Hi, >> >> By default, Python's * operator work in L->R order, so: >> >> a*b*c*d = ((a*b)*c)*d >> >> But, I am implementing some operators from

[sympy] Re: R->L operator precedence

2008-11-10 Thread Brian Granger
> Could you please elaborate? What you want is a noncommutative > *nonassociative* algebra. As far as I know, everything in quantum > mechanics is at least associative. Sure, everything in my case is associative. But in practice, it is easier to do the multiplications in a certain order. I end

[sympy] Re: R->L operator precedence

2008-11-10 Thread Robert Kern
On Mon, Nov 10, 2008 at 13:16, Brian Granger <[EMAIL PROTECTED]> wrote: > > Hi, > > By default, Python's * operator work in L->R order, so: > > a*b*c*d = ((a*b)*c)*d > > But, I am implementing some operators from quantum mechanics that I > want to apply like this: > > a*b*c*d = a*(b*(c*d)) > > Is

[sympy] Re: R->L operator precedence

2008-11-10 Thread Brian Granger
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" Cheers, Brian On Mon, Nov 10, 2008 at 12:

[sympy] Re: R->L operator precedence

2008-11-10 Thread Ondrej Certik
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 f

[sympy] Re: R->L operator precedence

2008-11-10 Thread Brian Granger
OK, sounds great. Now a follow onor 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. * I then need to take an expression, find all the instances of Mul in the tree and replace those by something else, one b

[sympy] Re: R->L operator precedence

2008-11-10 Thread Brian Granger
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 onor 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.

[sympy] Re: R->L operator precedence

2008-11-10 Thread Ondrej Certik
On Mon, Nov 10, 2008 at 10:15 PM, Brian Granger <[EMAIL PROTECTED]> wrote: > > OK, sounds great. Now a follow onor 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. You need to do something like: [p fo

[sympy] Re: R->L operator precedence

2008-11-10 Thread Ondrej Certik
On Mon, Nov 10, 2008 at 10:46 PM, Brian Granger <[EMAIL PROTECTED]> wrote: > > 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 onor two... >> >> * How can I get the non-commuting part of the