Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Re: Interval arithmetic, of a sort

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33765] Re: Interval arithmetic, of a sort
  • From: Erich Mueller <emueller at mps.ohio-state.edu>
  • Date: Thu, 11 Apr 2002 02:14:44 -0400 (EDT)
  • Organization: Ohio State University
  • References: <a90g80$k89$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Here is a rule-based approach.  Might as well work with your notation.
You can overload the Plus operator, but it is clearer to introduce our own
function.

First we define an add function which adds a single interval to
a list of intervals

addstrip[a : {label_, {start_, end_}}, currentlist_List] :=
  Join[Cases[
      currentlist, {l_, {s_?(# < start &), e_}} -> {l, {s,
            Min[e, start - 1]}}], {a},
    Cases[currentlist, {l_, {s_, e_?(# > end &)}} -> {l, {Max[s, end + 1],
            e}}]]


For example

s1 = addstrip[{1, {0, 100}}, {}]

gives

{{1, {0, 100}}}

And

s2 = addstrip[{2, {13, 23}}, s1]

gives

{{1, {0, 12}}, {2, {13, 23}}, {1, {24, 100}}}


Next we add rules so that our function can add two lists of intervals

addstrip[newlist_List, currentlist_List] :=
  Fold[addstrip[#2, #1] &, currentlist, newlist]

Hope that helps.

Erich

On Wed, 10 Apr 2002, DIAMOND Mark R. wrote:

> I cannot find any solution to this problem without using very time consuming
> procedural programming, and yet it seems that it ought to have a reasonably
> simple functional solution. BTW: Even though I don't use it in the
> following, I am familiar with the Interval notation and functions.
>
> The origin of the programming problem is most easily pictured as one of
> laying down numbered strips of cardboard on top of one another within an
> interval. For simplicity, assume that the total interval is
> Interval[{0,100}], which I will just write as {0,100}, and it has the value
> 1, with the notation now being {1,{0,100}}
>
> Uniquely numbered strips of card are put on top of this one; they may or may
> not overlap; I want to be able to obtain a description of the visible bits
> of card at the end. So for example, if "+" indicates laying down a new
> numbered strip, and if we start with
> {{1,{0,100}}}, then {{{1,{0,100}}} + {2,{2,3}} =
> {{1,{0,2}},{2,{2,3}},{1,{3,100}},
>  indicating that the original strip is visible from 0-2, strip 2 is visible
> from 2-3, and the original is again visible from 3-100. Continuing, complete
> occlusion would happen with
> {{1,{0,2}},{2,{2,3}},{1,{3,100}}, + {3,{1,20}} =
> {{1,{0,1}},{3,{1,20}},{1,{20,100}}}; again continuing, overlap would happen
> with
> {{1,{0,1}},{3,{1,20}},{1,{20,100}}}  + {4,{15,30}} =
> {{1,{0,1}},{3,{1,15}},{4,{15,30}},{1,{30,100}}}
>
> Mark R. Diamond
> No spam email ROT13: znexq at cfl.hjn.rqh.nh
> No crawler web page ROT13 uggc://jjj.cfl.hjn.rqh.nh/hfre/znexq
>
>
>
>
>



  • Prev by Date: Re: How to Return from within a Table[]-Command?
  • Next by Date: ascending/decending polynomial order
  • Previous by thread: RE: Interval arithmetic, of a sort
  • Next by thread: Re: Interval arithmetic, of a sort