Re: IntervalComplement
- To: mathgroup at smc.vnet.net
- Subject: [mg70337] Re: [mg70317] IntervalComplement
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Fri, 13 Oct 2006 01:30:45 -0400 (EDT)
- References: <200610120938.FAA04776@smc.vnet.net>
On 12 Oct 2006, at 18:38, Chris Chiasson wrote: > Has anyone implemented this function before? I need something that > can do this. > > (IntervalComplement is to IntervalUnion as Complement is to Union) > > -- > http://chris.chiasson.name/ > I think this should do it: IntervalComplement[s_Interval, t_Interval] := Module[{FromInterval, y, p}, FromInterval[x_Interval] := Or @@ (x /. {a_?NumericQ, b_?NumericQ} :> LessEqual[a, y, b]); p = ((CylindricalDecomposition [FromInterval[s] && Not[FromInterval[t]], y]) /. HoldPattern[Inequality[a_?NumericQ, Less | LessEqual, y, Less | LessEqual, b_?NumericQ]] :> { a, b}); If[Head[p] === Or, Interval @@ p, Interval[p]]] For example: IntervalComplement[Interval[{2,6}],Interval[{3,4}]] Interval[{2,3},{4,6}] Andrzej Kozlowski Tokyo, Japan
- References:
- IntervalComplement
- From: "Chris Chiasson" <chris@chiasson.name>
- IntervalComplement