Hi Akshay! On Wed, Feb 18, 2009 at 7:13 PM, Akshay Srinivasan <[email protected]> wrote: > Hello, > I'm trying to implement a Set Algebra module for sympy. I > started coding a few days ago and it quickly became apparent that I > have to write something completely parallel to the normal algebra, > which is already present in Sympy. I've written a very rough code, > which contains some classes and very liitle operations. > Much of what I could think of with sets is of a form that can > only be simplified by taking two or more terms together - like {(A *U > *B) *^* B = B}. I was thinking of looping through the terms of both, > and then find a match. I think this is a messy and horribly > inefficient way to do this. The "trigsimp" function doesn't seem to > have any way around this either. Any ideas on how to go ahead would be > very helpful. > The attached is archive contains the whole Set module. > > Example of usage: > > A=Set('A') > B=Set('B') > > A.union(B) >> (A | B) > A | B >> (A | B) > A & B >> ( A & B) > A | A >> A > > If you go through the code the analogy becomes even more clear.
Yes, you would have to implement the basic algebra rules for sets again. But it's not difficult. Basicaly use the same approach as we have in sympy, e.g. overload __new__ in your basic class and call .eval(cls, args) from there. Then override .eval() in subclasses that would simplify some basic things and that's it. Here is some docs: http://docs.sympy.org/guide.html#automatic-evaluation-to-canonical-form http://docs.sympy.org/guide.html#functions Note that canonize() was renamed to eval() in the latest sympy 0.6.4beta1. Let us know if you need more help with this. I am very interested in getting sets in sympy. Thanks for any work you do, Ondrej --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
