Actually, we could give you a set of non-intersecting sets fairly easily. Your problem can be written as follows
In [2]: s = Union(Interval(2, 5)*Interval(-oo, oo), Interval(-oo, oo)*Interval(3, 8)) In [4]: 2.complement.complement Out[4]: (((-∞, 2) ∪ (5, ∞)) × [3, 8]) ∪ ([2, 5] × ((-∞, 3) ∪ (8, ∞))) ∪ ([2, 5] × [3, 8]) Not the prettiest but it should suffice. On Mon, Nov 12, 2012 at 11:46 AM, Matthew Rocklin <mrock...@gmail.com>wrote: > Short answer here is, I think, no. > > The short answer *should be* that sympy.stats should be able to handle > all of this for you at a level higher than sets. It currently errs on this > sort of question unfortunately. It wouldn't be hard to add though. The > infrastructure is there. > > Sets handles this sort of problem while it computes measures. Sadly it > assumes a measure with density that is always equal to 1. It would be nice > if this piece were generalized so that it would integrate a general > function over the domain. In principle this wouldn't be challenging to > add. The tedium that you're looking to automate is already solved in the > various `def _measure` functions in `sympy/core/sets.py`. Unfortunately > it's tangled up with some too-simple assumptions. You would just need to > add an argument to all of the `_measure` methods. Presumably at the > Interval base-layer you would replace `return self.right - self.left` with > `return integrate(f, self)`. > > If you implement this on your own outside of SymPy you might find > Union._measure helpful. It solves the annoying AuBuC == A + B + C - AB - BC > + ABC problem generally. If this code were generalized so that > `blah.measure` were replaced with `foo(blah)` I suspect you would have your > problem 80% solved. > > Your sort of problem is exactly what I would like sympy.stats to be able > to solve with sympy.core.sets. If I ever get more time I'll work on this. > Probably not for a while though. > > I'm happy to help out if you're willing to fix the problem within > SymPy.sets. It'd be a nice contribution. > > > > On Mon, Nov 12, 2012 at 10:59 AM, Simon Clift <sscl...@gmail.com> wrote: > >> Hi folks, >> >> I have a straightforward, but tedious probability problem that I need to >> expand symbolically. Sympy's set and interval material is close, but I >> can't see how it would work in a multidimensional application. I've used >> Sympy for some fairly intricate PDE problems, but never for this sort of >> thing, and I would appreciate any suggestions, please. >> >> I have a number of events that appear as, for example 2 < X < 5 and 3 < >> Y < 8 which have associated probabilities and joint distributions (i.e. are >> not mutually exclusive). From basic probability and set theory >> >> p( 2<X<5 \cup 3<Y<8) = p( 2<X<5 ) + p( 3<Y<8 ) - p( 2<X<5 \cap 3<Y<8 ) >> >> and so on. My problems start with about 6 unions that are intersections >> fo 2 conditions each, all in 3 variables, so requires both the expansion >> above and reduction for intersecting intervals. It isn't difficult, just >> tedious (and error-prone). >> >> I was about to hand-roll the symbolic algebra as Python classes, but I >> was wondering if there was a way to approach this with Sympy's intervals >> module. It's not clear to me, from the docs or from experimentation, that >> it handles multi-dimensional problems. >> >> Best regards >> -- Simon >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sympy" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/sympy/-/qd4-NeUkPzIJ. >> To post to this group, send email to sympy@googlegroups.com. >> To unsubscribe from this group, send email to >> sympy+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/sympy?hl=en. >> > > -- 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 sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.