[Date Index]
[Thread Index]
[Author Index]
Re: Interval arithmetic, of a sort
*To*: mathgroup at smc.vnet.net
*Subject*: [mg33789] Re: [mg33721] Interval arithmetic, of a sort
*From*: "Fred Simons" <f.h.simons at tue.nl>
*Date*: Tue, 16 Apr 2002 03:50:46 -0400 (EDT)
*References*: <20020410163408.46932.qmail@web12405.mail.yahoo.com>
*Sender*: owner-wri-mathgroup at wolfram.com
Mark,
The problem can also be solved recursively. We define a function with two
arguments. The first argument is the interval on which we want to define
which parts of the list of intervals in the second argument are visible. We
construct the (possibly empty) intersection of the first argument with the
highest interval of the second argument, that part is visible. Then to the
left and to the right of this intersection we find two (possibly empty)
intervals on which we have to determine which part of the rest of the second
argument is visible.
Here is an implementation:
In[70]:=
visibleintervals[intervals_] := Module[{f},
f[{a_, b_}, _] /; a\[GreaterEqual]b := Sequence[];
f[{a_, b_}, n_Integer ] := {n, {a, b}};
f[{a_, b_}, {}] := {0, {a, b}};
f[{a_, b_}, {{c_, d_}, e___}] :=
Sequence[f[{a, Max[a,c]}, {e}],
f[{Max[a,c], Min[b, d]}, Length[{e}]+1], f[{Min[b, d],b}, {e}]];
{f[ {Min[First/@intervals], Max[Last/@intervals]}, Reverse[intervals]]}
]
In[71]:=
visibleintervals[{{0, 100}, {2,3}, {1,20}, {15, 30}}]
Out[71]=
{{1,{0,2}},{3,{1,15}},{4,{15,30}},{1,{3,100}}}
In[72]:=
visibleintervals[ {{0,2}, {4, 10}}]
Out[72]=
{{1,{0,2}},{0,{2,4}},{2,{4,10}}}
Regards,
Fred Simons
Eindhoven University of Technology
Prev by Date:
**Re: Subscript[x, y] and the Symbol x**
Next by Date:
**Redefing a Numberedfigure-Style in a MyReport Style Sheet**
Previous by thread:
**Re: Interval arithmetic, of a sort**
Next by thread:
**RE: Interval arithmetic, of a sort**
| |