George Sakkis wrote: > "Jacob Page" <[EMAIL PROTECTED]> wrote: > >>If the union of two integers yielded a set of integers, then >>it'd make more since for the union of two Intervals to yield an >>IntervalSet. > > AFAIK union is defined over sets, not numbers, so I'm not sure what you > mean by the "union of two integers". What I'm saying is that while the > union of two intervals is always defined (since intervals are sets), > the result set is not guaranteed to be an interval. More specifically, > the result is an interval if and only if the intervals overlap, e.g. > (2,4] | [3,7] = (2,7] > but > (2,4] | [5,7] = { (2,4], [5,7] } > That is, the set of intervals is not closed under union. OTOH, the set > of intervals _is_ closed under intersection; intersecting two > non-overlapping intervals gives the empty interval.
OK, you've convinced me now to support and, or, and xor between every combination of Intervals and IntervalSets, Intervals and IntervalSets, and IntervalSets and Intervals. However, I'm not sure I like the idea of an operation generating either one type or another. Thus, I'll have | and ^ operations between Intervals always return an IntervalSet instead of returning either an IntervalSet or an Interval. & will return an Interval. I suppose that means I should just have + do a union and - return an IntervalSet. It will just have to be documented which types are to be expected for the return values depending on the operands. -- http://mail.python.org/mailman/listinfo/python-list