MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Interval arithmetic, of a sort

  • To: mathgroup at
  • Subject: [mg33789] Re: [mg33721] Interval arithmetic, of a sort
  • From: "Fred Simons" <f.h.simons at>
  • Date: Tue, 16 Apr 2002 03:50:46 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at


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:

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]]}

visibleintervals[{{0, 100}, {2,3}, {1,20}, {15, 30}}]


visibleintervals[ {{0,2}, {4, 10}}]



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