1<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
2<!-- BEGIN LICENSE BLOCK
3   - Version: CMPL 1.1
4   -
5   - The contents of this file are subject to the Cisco-style Mozilla Public
6   - License Version 1.1 (the "License"); you may not use this file except
7   - in compliance with the License.  You may obtain a copy of the License
8   - at www.eclipse-clp.org/license.
9   - 
10   - Software distributed under the License is distributed on an "AS IS"
11   - basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
12   - the License for the specific language governing rights and limitations
13   - under the License. 
14   - 
15   - The Original Code is  The ECLiPSe Constraint Logic Programming System. 
16   - The Initial Developer of the Original Code is  Cisco Systems, Inc. 
17   - Portions created by the Initial Developer are
18   - Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
19   - 
20   - Contributor(s): 
21   - 
22   - END LICENSE BLOCK -->
23
24<html>
25<head>
26   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
27   <meta name="Author" content="Joachim Schimpf">
28   <meta name="GENERATOR" content="Mozilla/4.76 [en] (X11; U; SunOS 5.7 sun4u) [Netscape]">
29</head>
30<body>
31
32<h1>
33The bounded real (breal) data type</h1>
34Involved: Joachim, Warwick
35<br>&nbsp;
36<h2>
37What is it?</h2>
38A new type of number in Eclipse: a representation of a <b>real</b> as a
39pair of <b>floating point bounds</b>. While a <b>float</b> conceptually
40stands for a real that is somewhere <i>in the vicinity of</i> the float,
41a breal stands for a real that is somewhere <i>between the given bounds</i>.
42To keep terminology precise, we decided on the name <b>bounded real</b>
43rather than <i>interval</i> or <i>ground interval</i> - the latter would
44have invited confusion with interval variables.
45<h2>
46Features</h2>
47Predicates
48<ul>
49<li>
50breal/1 type test</li>
51
52<li>
53breal/2 conversion to breal</li>
54
55<li>
56breal_min/2, breal_max/2, breal_bounds/3 get the bounds as a float</li>
57</ul>
58Syntax
59<ul>
60<li>
61two floats separated by two underscores, e.g. 3.0999999999999996__3.1000000000000005</li>
62</ul>
63
64<p><br>Trick to convert all float constants into breals:
65<blockquote>
66<pre>?- local macro(type(float),breal/2,[]).
67Yes (0.00s cpu)
68
69?- X = 3.4.
70X = 3.3999999999999995__3.4000000000000004
71Yes (0.00s cpu)</pre>
72</blockquote>
73
74<h2>
75Problems</h2>
76There are a number of rather fundamental problems associated to the idea
77of having reals in a programming language. No programming language can
78have exact representations for all reals - they are uncountable. Any one
79program can only deal with a countable subset of them.
80<p>Since there are uncountably many reals but only countably many names/representations,
81an infinite number of reals share the same representation.
82<p>Some of the usual generic Prolog properties are violated:
83<ul>
84<li>
85equality (and unifiability) is not decidable even if the breals look the
86same:</li>
87</ul>
88
89<ul>
90<ul>
91<pre>?- breal(3.1,X), breal(3.1,Y), X==Y.
92exiting to an undefined tag in exit_block('undecidable comparison of bounded reals')</pre>
93
94<pre>?- breal(3.1,X), Y is sin(X), Z is sin(X), Y==Z.&nbsp;&nbsp;
95exiting to an undefined tag in exit_block('undecidable comparison of bounded reals')
96</pre>
97</ul>
98
99<li>
100except in special cases:</li>
101</ul>
102
103<ul>
104<ul>
105<pre>[eclipse 2]: breal(3.1,X), X==X.
106X = 3.0999999999999996__3.1000000000000005
107Yes (0.00s cpu)</pre>
108</ul>
109
110<li>
111the rule that you can writeq a term, read it back, and it will be identical
112to the written one does not hold (because there is no unique finite representation
113for every individual real - we would need a universal dictionary of all
114reals ever written)</li>
115
116<li>
117same holds for storing breals elsewhere:</li>
118
119<ul>
120<pre>?- breal(3.1,X), findall(Y, Y=X, [X]).
121exiting to an undefined tag in exit_block('undecidable comparison of bounded reals')
122</pre>
123</ul>
124
125<li>
126the arithmetic comparisons leave a delayed goal:</li>
127
128<ul>
129<pre>?-&nbsp; breal(3.1,X), breal(3.1,Y), X=:=Y.
130
131X = 3.0999999999999996__3.1000000000000005
132Y = 3.0999999999999996__3.1000000000000005
133
134
135Delayed goals:
136&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.0999999999999996__3.1000000000000005 =:= 3.0999999999999996__3.1000000000000005
137</pre>
138</ul>
139</ul>
140So why do all these problems not occur with floats? They do, of course,
141they are just fudged.
142</body>
143</html>
144