You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/julia/Readme.md
+54-10Lines changed: 54 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,6 @@
3
3
Interval arithmetics on the real line with julia
4
4
5
5
#### Related Work ####
6
-
7
6
-[MPFI.jl][1]: Wrapper of [MPFI library][http://perso.ens-lyon.fr/nathalie.revol/software.html] (multiple precision interval arithmetic library based on MPFR) for julia.
8
7
9
8
#### References ####
@@ -14,11 +13,11 @@ Interval arithmetics on the real line with julia
14
13
- Luis Benet, Instituto de Ciencias Físicas, Universidad Nacional Autónoma de México (UNAM)
15
14
- David P. Sanders, Facultad de Ciencias, Universidad Nacional Autónoma de México (UNAM)
16
15
17
-
## Design and implementation ##
18
16
17
+
## Design and implementation ##
19
18
`Intervals.jl` is a julia module to perform *validated numerics*, i.e. *rigorous* computations with finite-precision floating-point arithmetic.
20
19
21
-
The basic constructor is `Interval`, which takes pairs of `Real`-type values as arguments, or alternatively, single values. The idea of including the latter is to produce *thin intervals*, i.e., intervals which consist of a single real value. Yet, if the number is not exactly representable in base 2, rounding-off errors appear due to the finite precision floating-point arithmetic. Incorporating *directed rounding* may thus create intervals whose *diameter* or *width* is strictly positive. Directed rounding is incorporated for any `Real`-type values *except* for `BigFloat`, since this type includes rounding. Direct access to the`RoundDown` and `RoundUp` modes is obtained through the macros `@roundingDown` and `@roundingUp`.
20
+
The basic constructor is `Interval`, which takes pairs of `Real`-type values as arguments, or alternatively, single values for *thin*intervals. Yet, if the number is not exactly representable in base 2, rounding-off errors appear due to the finite precision floating-point arithmetic. Incorporating *directed rounding* may thus create intervals whose *diameter* or *width* is non-zero, despite of *a priori* being thin intervals. Directed rounding is incorporated for any `Real`-type values *except* for `BigFloat`, since this type implements already rounding. Direct access to `RoundDown` and `RoundUp` modes is obtained through the macros `@roundingDown` and `@roundingUp`.
22
21
23
22
The following provides some examples.
24
23
```julia
@@ -38,19 +37,21 @@ Interval (constructor with 5 methods)
38
37
julia>Interval(1//10)
39
38
[9.9999999999999992e-02, 1.0000000000000001e-01] with 53 bits of precision
40
39
40
+
julia>Interval(0.1,0.1)
41
+
[9.9999999999999992e-02, 1.0000000000000001e-01] with 53 bits of precision
42
+
41
43
julia>Interval(BigFloat(0.1))
42
44
[1.0000000000000001e-01, 1.0000000000000001e-01] with 53 bits of precision
43
45
44
46
julia> b1 =Interval(BigFloat("0.1"))
45
47
[1.0000000000000001e-01, 1.0000000000000001e-01] with 53 bits of precision
[9.9999999999999992e-02, 1.0000000000000001e-01] with 53 bits of precision
49
51
50
52
```
51
53
52
-
Note that all possibilities above yield the same results *except*`Interval(BigFloat(0.1))`, which yields a thin interval, that noticeably *does not* contain the real value 0.1; a way to obtain a non-thin interval using `BigFloat` of strings is illustrated in the last line. It is worth emphasizing that the behavior implemented by the definition of `Interval` above is *not the same* as that implemented by [MPFI][1], which in all cases above
53
-
would yield thin intervals; this is the main design difference.
54
+
Note that all possibilities above yield the same results *except*`Interval(BigFloat(0.1))` and the definition of `b1`, which yield thin intervals that noticeably *do not* contain the real value 0.1; a way to obtain a non-thin interval using `BigFloat` of strings is illustrated by the definition of `b2`. It is worth emphasizing that the behavior implemented by the definition of `Interval` above is *not the same* as that implemented by [MPFI][1], which in all cases above would yield thin intervals. (Using `MPFI`, the behaviour above is obtained with `Interval("0.1")`, which is not defined in our implementation.) This is the main design difference.
54
55
55
56
The limits of the interval are accessed with the fields `lo` and `hi`. These fields are of `BigFloat` type. The diameter is obtained using `diam(a)`; note that for non-exactly representable numbers in base 2 (i.e., whose *binary* expansion is infinite) the diameter corresponds to the local `eps` value.
56
57
```julia
@@ -60,7 +61,7 @@ julia> a.lo
60
61
julia>typeof(a.lo)
61
62
BigFloat (constructor with 14 methods)
62
63
63
-
julia> a.hi.prec ## this displays the precision of the BigFloat number
64
+
julia> a.hi.prec ## this displays the precision of the BigFloat number
64
65
53
65
66
66
67
julia>diam(a) ==eps(0.1)
@@ -74,10 +75,53 @@ true
74
75
75
76
```
76
77
77
-
The basic operations among intervals (`+`, `-`, `*`, `/`, `^`) are included following the usual definitions, and include consisting *directed rounding*. In particular, in the case `^` we have distinguished for non-integer powers, if they define a thin interval or not. Some simple functions (`exp`, `log`, `sin`, `cos`, `tan`) have been incorporated and more will come with time (and patience).
78
+
## Operations and functions ##
79
+
The basic operations among intervals (`+`, `-`, `*`, `/`, `^`) have been implemented following the usual definitions; they are implemented with consisting *directed rounding* mode. That is, the resulting lower (right) edge is systematically rounded down, while the upper (left) one is rounded up. In particular, the implementation for `^` distinguishes whether non-integer powers define a thin interval or not.
80
+
81
+
```julia
82
+
julia> a =Interval(1.1)
83
+
[1.0999999999999999e+00, 1.1000000000000001e+00] with 53 bits of precision
84
+
85
+
julia> b =Interval(1,2)
86
+
[1e+00, 2e+00] with 53 bits of precision
87
+
88
+
julia> a + b
89
+
[2.0999999999999996e+00, 3.1000000000000001e+00] with 53 bits of precision
90
+
91
+
julia> a - b
92
+
[-9.0000000000000013e-01, 1.0000000000000009e-01] with 53 bits of precision
93
+
94
+
julia> a * b
95
+
[1.0999999999999999e+00, 2.2000000000000002e+00] with 53 bits of precision
96
+
97
+
julia> a / b
98
+
[5.4999999999999993e-01, 1.1000000000000001e+00] with 53 bits of precision
99
+
100
+
julia> b/Interval(-1,1)
101
+
WARNING:
102
+
Interval in denominator contains 0.
103
+
[-inf, inf] with 53 bits of precision
104
+
105
+
julia> b/Interval(0,2)
106
+
[5e-01, inf] with 53 bits of precision
107
+
108
+
julia> c =Interval(-0.1, 0.2)
109
+
[-1.0000000000000001e-01, 2.0000000000000001e-01] with 53 bits of precision
110
+
111
+
julia> c*c
112
+
[-2.0000000000000004e-02, 4.0000000000000008e-02] with 53 bits of precision
113
+
114
+
julia> c^2
115
+
[0e+00, 4.0000000000000008e-02] with 53 bits of precision
116
+
117
+
```
118
+
119
+
The last results shows that `^` is implemented independently from the product; this is related to the *dependency problem*.
120
+
121
+
Some simple functions (`exp`, `log`, `sin`, `cos`, `tan`) have also been implemented, and more will come with time (and patience).
78
122
79
123
80
-
###Acknowledgements###
124
+
## Acknowledgements ##
81
125
This project was developed in a masters' course in the postgraduate programs in Physics and in Mathematics at UNAM during the second half of 2013. We thank the participants of the course for putting up with the half-baked material and contributing energy and ideas.
82
126
83
127
Financial support is acknowledged from DGAPA-UNAM PAPIME grants PE-105911 and PE-107114. LB acknowledges support through a *Cátedra Moshinsky* (2013).
0 commit comments