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. > > 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 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 # 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() ############ Note that it's not optimal in many aspects (e.g. the sorting is totally recursive and suboptimal) but it works. 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. 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. Tom --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---