[Haskell-cafe] Set of reals...?

Ketil Malde ketil+haskell at ii.uib.no
Thu Oct 28 07:31:56 EDT 2004

Stijn De Saeger <stijndesaeger at gmail.com> writes:

> But, like you mentioned in your post, now I find myself needing a
> notion of subset relations, and since you obviously can't define
> equality over functions, i'm stuck again. 

Perhaps one can define an approximate equality, with an error bound?

Define the sets with a maximal boundary, and check points within the
combined boundary.  You can only be sure about the answer if it is
'False', 'True' should be interpreted as "maybe" :-).  

An inplementation could look something like (untested):

   data RSet = RSet {isin :: Double -> Bool, bounds :: (Double,Double) }

   equals :: Double -> Rset -> RSet -> Bool
   equals epsilon s1 s2 = and (map (equals1 s1 s2) [l,l+epsion..h]
       where l = min (fst $ bounds s1) (fst $ bounds s2)
             h = max (snd $ bounds s1) (snd $ bounds s2)

Or you could use randomly sampled values (and perhaps give a
statistical figure for confidence?), or you could try to identify the
boundaries of each set, or..

> Do you know any way around this problem, or have i hit a dead
> end...?

Simulating real numbers on discrete machinery is a mess.  Join the
club :-) 

If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell-Cafe mailing list