On Mon, Oct 6, 2008 at 9:39 PM, glt <[EMAIL PROTECTED]> wrote:
>
> Hi, thank you all for your replies.
>
> On Oct 5, 3:31 pm, "Ondrej Certik" <[EMAIL PROTECTED]> wrote:
>>
>> Thanks for doing it, that's very useful. What other operations would
>> you like to do with it?
>
> For now, essentially use sympy to sort the products properly,
> expanding all the commutators, etc, which is a real pain to do by hand
> for large products.
>
> I would also be interested in defining anticommuting symbols, but I
> guess that's really kind of the same problem.

Right, thanks for the info.

>
>>
>> Looking here, it's just a Lie algebra, right?
>>
>> http://en.wikipedia.org/wiki/Virasoro_algebra
>>
>>
>
> Yes it is. The idea of sorting the product terms by increasing order
> is that it makes it easy to see which terms vanish on a lowest weight
> representation vector of the algebra. You just have to discard all
> products ending with an L_i with i>0.

I see. I had a similar problem with calculating cross-sections in QED
manually using creation and anihilation operators, one also needs to
employ commutation/anticommutation relations to simplify it. So SymPy
should be able to do this kind of manipulations.

>
>>
>> I would suggest you either subclass Mul, or just "fork it", e.g.
>> create VirasoroMul by copying the current Mul and then customizing it
>> to do what you want. If you have problems, just create a function that
>> takes some set of L(n)L(m)...L(p) and returns the simplifications
>> using the algorithm you described. After you have some working
>> prototype, we'll help you integrate it well in sympy, with the patch
>> and getting it in.
>
> What i have done right now is very basic but works and does the job
> (sort of). I've defined an L class which basically defines a product
> L(a)L(b)...L(p)L(q), constructed in python as L(a,b,...,p,q).
>
> Here are a few lines demonstrating how it works:
>
> ############
>
> from sympy import *
>
> class L(Basic):
>    is_commutative = False
>
>    def sort_virasoro(self, c):
>        """Returns the product of Virasoro operators as a sum of
>        products of L operators in order of increasing indices"""
>        idx = self.args
>
>        # Find index of first pair of operators to swap
>        try:
>            iswap = [p>q for p,q in zip(idx[:-1],idx[1:])].index(True)
>        except:
>            return self

^^^ Don't use empty "except:", because this catches all exceptions,
e.g. it hides problems. I guess you are catching the IndexError from
.index()?

>
>        # Split L(a)L(b)...L(m)L(n)...L(p)L(q) into 4 parts:
>        # pre = L(a)L(b)..., L(m), L(n), and post = ...L(p)L(q)
>        pre = idx[:iswap]
>        post = idx[iswap+2:]
>        m = idx[iswap]
>        n = idx[iswap+1]
>
>        # This is the swapped term L(a)L(b)...L(n)L(m)...L(p)L(q)
>        out = L(*(pre + (n,m) + post)).sort_virasoro(c)
>
>        # This is the commutator L(a)L(b)...L(m+n)...L(p)L(q)*(m-n)
>        if m-n!=0:
>            out += (m-n)*L(*(pre+(m+n,)+post)).sort_virasoro(c)
>
>        # This is the central term
>        if m+n==0:
>            if len(pre+post)==0:
>                Lterm = 1
>            else:
>                Lterm = L(*(pre + post)).sort_virasoro(c)
>
>            out +=  Lterm * c/12*(m**3-m)
>
>        return out
>
> if __name__=="__main__":
>    c = Symbol("c")   # The central charge
>    foo = L(-7,3,-3,-4,-5).sort_virasoro(c)
>    print foo.expand()

Otherwise looks good.

>
> ############
>
>
> Note that it's not optimal in many aspects (e.g. the sorting is
> totally recursive and suboptimal) but it works.

Excellent, thanks for the code. I created an issue to get this into sympy:

http://code.google.com/p/sympy/issues/detail?id=1138

>
> I don't know how this kind of code could be integrated tighter with,
> say Mul, so that you could just define L(3)*L(2)*L(1), and have sympy
> automatically put it into this kind of "canonical" ordering for
> example. Do you have insights on this? I've tried to look into the Mul
> code but have not made it very far yet.

Couple questions first:

1) should this happen automatically, or maybe only after calling some
function on the product?

If the latter, then all that is needed is to parse the noncummative
Mul expression, plug it into your function and construct the result
back. And integrate it nicely in sympy somewhere.

2) How is this implemented in other symbolic software, e.g.
Mathematica or Maple? (If you have experience with them.)

I learned it pays off to investigate other systems first, before
trying to come up with something ourselves.




> My education is much more in physics than in programming, but I'm
> quite interested in sympy and its flexible use for this kind of
> symbolic computation.

The same here, I also studied physics and not programming. What is
your application of this? E.g. what kind of stuff do you want to
calculate? My own little aim with SymPy is to be able to do basically
any calculation that one does in theoretical physics, but we still
have a long way to go. So I am glad you need this noncommutative
stuff, because it's just waiting to get polished and more widely used,
so if we can get SymPy do what you want, it will help us a lot.

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