sympy/sympy — pull request #2721 by mrocklin (2014-01-01 04:59:21+00:00)
Title: Set Expressions

### History

In https://github.com/sympy/sympy/pull/2682 @hargup implemented a wonderful interval arithmetic system.

I was curious if we could do this for all of sets, not just Intervals. My solution is `SetExpr`, a class that acts like an `Expr` but carries around a `Set` of possible values. This supports general set arithmetic of which interval arithmetic is a special case.

### How

For scalar functions like exp(x) or x + 1 (where x in some set) we rely on `imageset`.

For set-set functions like x + y + z (where, x, y, z, all come from different sets) we rely on a number of small functions. There is a naive dispatch system to select them. This looks like a possible use case for https://github.com/sympy/sympy/pull/2680

I stole a bit from @hargup 's solution for Interval-Interval interaction.

### Example

```Python

>>> from sympy.sets.setexpr import SetExpr, simplify
>>> a = SetExpr(FiniteSet(1, 10))
>>> b = SetExpr(Interval(0, 5))

>>> simplify(a + b).set
[1, 6] ∪ [10, 15]

>>> simplify(a + b*2).set
[1, 20]

>>> simplify(log(a + b*2)).set
[0, log(20)]
```

### Disclaimer

This doesn't yet have doctests. It's not particularly reader-friendly