sympy/sympy — pull request #1133 by mrocklin (2012-03-17 19:43:33+00:00)
Title: Intersection Set Class

Added an Intersection class for sets

This fixes two problems.

Problem 1:
Previously all intersection logic was distributed throughout the set classes in a confusing way. Every class needed to know how every other class worked to ensure all valid intersections could be computed. Now there is a central and distributed method for computing intersections.

Global rules like "intersections containing an empty set are empty" and "distribute unions" are handled in the intersection class.

Additionally, any class can implement a _intersect(self, other) method. If self knows how to intersect itself with other it returns that class, reducing the number of sets in the intersection by one. If self does not know how to intersect itself with other then it returns None. After Intersection finishes with global rules it iterates over the pairs of constituent sets finding simplifications until there is no change

Problem 2:
Sometimes we don't know how to intersect two sets. Previously we would just raise an error in this case. Now we fall back on the Intersection class as an unevaluated object much like Union, Integral, etc....

Issue here:
http://code.google.com/p/sympy/issues/detail?id=3159

There are some other small changes. We've introduced a UniversalSet singleton (to pair with EmptySet).