Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/numeric/interval/doc/numbers.htm @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 7.1 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2    "http://www.w3.org/TR/html4/loose.dtd">
3<html>
4<head>
5  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6  <link rel="stylesheet" type="text/css" href="../../../../boost.css">
7  <title>Numbers Requirements</title>
8</head>
9
10<body lang="en">
11<h1>Numbers Requirements</h1>
12
13<p>What we call "number" is the base type of the <code>interval</code> class.
14The interval library expect a lot of properties from this base type in order
15to respect the inclusion property. All these properties are already detailed
16in the other sections of this documentation; but we will try to summarize
17them here.</p>
18
19<h3>Ordering</h3>
20
21<p>The numbers need to be supplied with an ordering. This ordering expresses
22itself by the operators <code>&lt; &lt;= =&gt; &gt; == !=</code>. It must be
23a total order (reflexivity, antisymmetry, transitivity, and each pair of
24numbers is ordered). So <code>complex&lt;T&gt;</code> will not be a good
25candidate for the base type; if you need the inclusion property of interval
26property, you should use <code>complex&lt; interval&lt;T&gt; &gt;</code> in
27place of <code>interval&lt; complex&lt;T&gt; &gt;</code> (but unfortunately,
28<code>complex</code> only provides specialization).</p>
29
30<p>Please note that invalid numbers are not concerned by the order; it can
31even be conceptually better if a comparison with these invalid numbers is
32always <code>false</code> (except for <code>!=</code>). If your checking
33policy uses <code>interval_lib::checking_base</code> and your base type
34contains invalid numbers, then this property is needed: <code>nan!=nan</code>
35(here <code>nan</code> is an invalid number). If this property is not
36present, then you should not use <code>checking_base</code> directly.</p>
37
38<p>Interval arithmetic involves a lot of comparison to zero. By default, they
39are done by comparing the numbers to <code>static_cast&lt;T&gt;(0)</code>.
40However, if the format of the numbers allows some faster comparisons when
41dealing with zero, the template functions in the
42<code>interval_lib::user</code> namespace can be specialized:</p>
43<pre>namespace user {
44template&lt;class T&gt; inline bool is_zero(T const &amp;v) { return v == static_cast&lt;T&gt;(0); }
45template&lt;class T&gt; inline bool is_neg (T const &amp;v) { return v &lt;  static_cast&lt;T&gt;(0); }
46template&lt;class T&gt; inline bool is_pos (T const &amp;v) { return v &gt;  static_cast&lt;T&gt;(0); }
47}</pre>
48
49<h3>Numeric limits</h3>
50
51<p>Another remark about the checking policy. It normally is powerful enough
52to handle the exceptional behavior that the basic type could induce; in
53particular infinite and invalid numbers (thanks to the four functions
54<code>pos_inf</code>, <code>neg_inf</code>, <code>nan</code> and
55<code>is_nan</code>). However, if you use
56<code>interval_lib::checking_base</code> (and the default checking policy
57uses it), your base type should have a correctly specialized
58<code>std::numeric_limits&lt;T&gt;</code>. In particular, the values
59<code>has_infinity</code> and <code>has_quiet_NaN</code>, and the functions
60<code>infinity</code> and <code>quiet_NaN</code> should be accordingly
61defined.</p>
62
63<p>So, to summarize, if you do not rely on the default policy and do not use
64<code>interval_lib::checking_base</code>, it is not necessary to have a
65specialization of the numeric limits for your base type.</p>
66
67<h3>Mathematical properties</h3>
68
69<p>Ensuring the numbers are correctly ordered is not enough. The basic
70operators should also respect some properties depending on the order. Here
71they are:</p>
72<ul>
73  <li>0 &#x2264; <i>x</x>&#x21d2; -<i>x</i> &#x2264; 0</i></li>
74  <li><i>x</i> &#x2264; <i>y</i> &#x21d2; -<i>y</i> &#x2264; -<i>x</i></li>
75  <li><i>x</i> &#x2264; <i>y</i> &#x21d2; <i>x</i>+<i>z</i> &#x2264;
76    <i>y</i>+<i>z</i></li>
77  <li><i>x</i> &#x2264; <i>y</i> and <i>z</i> &#x2265; 0 &#x21d2;
78    <i>x</i>×<i>z</i> &#x2264; <i>y</i>×<i>z</i></li>
79  <li>0 &lt; <i>x</i> &#x2264; <i>y</i> &#x21d2; 0 &lt; 1/<i>y</i> &#x2264;
80    1/<i>x</i></li>
81</ul>
82
83<p>The previous properties are also used (and enough) for <code>abs</code>,
84<code>square</code> and <code>pow</code>. For all the transcendental
85functions (including <code>sqrt</code>), other properties are needed. These
86functions should have the same properties than the corresponding real
87functions. For example, the expected properties for <code>cos</code> are:</p>
88<ul>
89  <li><code>cos</code> is defined for all the valid numbers;</li>
90  <li>it is 2&#x3c0;-periodic;</li>
91  <li><code>cos</code>(2&#x3c0;-<i>x</i>) is equal to
92    <code>cos</code>(<i>x</i>);</li>
93  <li><code>cos</code> is a decreasing function on [0,2&#x3c0;].</li>
94</ul>
95
96<h3>Rounding</h3>
97
98<p>If you work with a base type and no inexact result is ever computed, you
99can skip the rest of this paragraph. You can also skip it if you are not
100interested in the inclusion property (if approximate results are enough). If
101you are still reading, it is probably because you want to know the basic
102properties the rounding policy should validate.</p>
103
104<p>Whichever operation or function you consider, the following property
105should be respected: <code>f_down(x,y) &lt;= f(x,y) &lt;= f_up(x,y)</code>.
106Here, <code>f</code> denotes the infinitely precise function computed and
107<code>f_down</code> and <code>f_up</code> are functions which return possibly
108inexact values but of the correct type (the base type). If possible, they
109should try to return the nearest representable value, but it is not always
110easy.</p>
111
112<h3>Constants</h3>
113
114<p>In order for the trigonometric functions to correctly work, the library
115need to know the value of the &#x3c0; constant (and also &#x3c0;/2 and
1162&#x3c0;). Since these constants may not be representable in the base type,
117the library does not have to know the exact value: a lower bound and an upper
118bound are enough. If these values are not provided by the user, the default
119values will be used: they are integer values (so &#x3c0; is bounded by 3 and
1204).</p>
121
122<h3>Operators and conversions</h3>
123
124<p>As explained at the beginning, the comparison operators should be defined
125for the base type. The rounding policy defines a lot of functions used by the
126interval library. So the arithmetic operators do not need to be defined for
127the base type (unless required by one of the predefined classes). However,
128there is an exception: the unary minus need to be defined. Moreover, this
129operator should only provide exact results; it is the reason why the rounding
130policy does not provide some negation functions.</p>
131
132<p>The conversion from <code>int</code> to the base type needs to be defined
133(only a few values need to be available: -1, 0, 1, 2). The conversion the
134other way around is provided by the rounding policy (<code>int_down</code>
135and <code>int_up</code> members); and no other conversion is strictly needed.
136However, it may be valuable to provide as much conversions as possible in the
137rounding policy (<code>conv_down</code> and <code>conv_up</code> members) in
138order to benefit from interval conversions.</p>
139<hr>
140
141<p>Revised: 2004-02-17<br>
142Copyright (c) Guillaume Melquiond, Sylvain Pion, Hervé Brönnimann, 2002.
143Polytechnic University.<br>
144Copyright (c) Guillaume Melquiond, 2004.</p>
145</body>
146</html>
Note: See TracBrowser for help on using the repository browser.