Re: IntervalComplement
- To: mathgroup at smc.vnet.net
- Subject: [mg70321] Re: IntervalComplement
- From: "Chris Chiasson" <chris at chiasson.name>
- Date: Fri, 13 Oct 2006 01:30:01 -0400 (EDT)
- References: <acbec1a40610120129t65e74a60r8a60a90aa650dd51@mail.gmail.com>
this seems to work okay for numeric intervals
In[1]:=
IntervalComplement[universe:Interval[{__?NumericQ}..],
holes:Interval[{__?NumericQ}..]..]:=
Module[{a,oth,tempResult,universeList=List@@universe,masks,
unifiedHoles=IntervalUnion[holes]},
masks=IntervalIntersection[Interval@#,unifiedHoles]&/@universeList;
tempResult=
IntervalUnion@@
MapThread[
Interval@@
Partition[
Block[{Interval=Sequence},Flatten@{#1[[1]],#2,#1[[-1]]}],
2]&,{universeList,masks}];
DeleteCases[tempResult,
Alternatives@@IntervalIntersection[tempResult,unifiedHoles]]]
In[2]:=
IntervalComplement[Interval[{1,10},{11,12}],Interval[{2,3}],Interval[{4,5}]]
IntervalComplement[Interval[{1,10},{10.5,12}],Interval[{2,3},{4,5}],
Interval[{8,11.5}]]
Out[2]=
Interval[{1,2},{3,4},{5,10},{11,12}]
Out[3]=
Interval[{1,2},{3,4},{5,8},{11.5,12}]
Unfortunately, I am not sure if I am going to use this any more...
On 10/12/06, Chris Chiasson <chris at chiasson.name> 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/
>
--
http://chris.chiasson.name/