1
1
"""
2
2
IntervalArithmetic
3
3
4
- Library for validated numerics using interval arithmetic.
4
+ Library for validated numerics using interval arithmetic, offering tools to
5
+ rigorously bound errors in numerical computations by representing values as
6
+ intervals and ensuring that computed results contain the true value. It provides
7
+ accurate, and efficient methods, ideal for scientific computing,
8
+ computer-assisted proofs, and any domain requiring certified numerical results.
9
+
10
+ Key features:
11
+
12
+ - **Bound Type**: The default numerical type used to represent the bounds of the
13
+ intervals. The default is `Float64`, but other subtypes of
14
+ [`IntervalArithmetic.NumTypes`](@ref) can be used to adjust precision.
15
+
16
+ - **Flavor**: The interval representation that adhere to the IEEE Standard
17
+ 1788-2015. By default, it uses the set-based flavor, which excludes infinity
18
+ to be part of an interval. Learn more: [`IntervalArithmetic.Flavor`](@ref).
19
+
20
+ - **Interval Rounding**: Controls the rounding behavior for interval arithmetic
21
+ operations. By default, the library employs correct rounding to ensure that
22
+ bounds are computed as tightly as possible. Learn more:
23
+ [`IntervalArithmetic.IntervalRounding`](@ref).
24
+
25
+ - **Power mode**: A performance setting for power operations. The default mode
26
+ uses an efficient algorithm prioritizing fast computation, but it can be
27
+ adjusted for more precise, slower calculations if needed. Learn more:
28
+ [`IntervalArithmetic.PowerMode`](@ref).
29
+
30
+ - **Matrix Multiplication mode**: A performance setting for matrix
31
+ multiplication operations. The default mode uses an efficient algorithm
32
+ prioritizing fast computation, but it can be changed to use the standard
33
+ definition of matrix multiplication. Learn more:
34
+ [`IntervalArithmetic.MatMulMode`](@ref).
35
+
36
+ The default behaviors described above can be configured via
37
+ [`IntervalArithmetic.configure`](@ref).
38
+
39
+ **Display Settings**: controls how intervals are displayed. By default,
40
+ intervals are shown using the standard mathematical notation ``[a, b]``, along
41
+ with decorations and up to 6 significant digits. Learn more:
42
+ [`setdisplay`](@ref).
43
+
44
+ # Usage
45
+
46
+ ```julia
47
+ using IntervalArithmetic
48
+
49
+ # Create an interval
50
+ x = interval(1.0, 2.0)
51
+
52
+ # Perform a rigorous computation
53
+ x + exp(interval(π))
54
+ ```
5
55
6
56
Learn more: https://github.com/JuliaIntervals/IntervalArithmetic.jl
7
57
"""
@@ -32,10 +82,6 @@ include("display.jl")
32
82
33
83
#
34
84
35
- include (" symbols.jl" )
36
-
37
- #
38
-
39
85
import LinearAlgebra
40
86
import OpenBLASConsistentFPCSR_jll # 32-bit systems are not supported
41
87
@@ -50,6 +96,27 @@ include("matmul.jl")
50
96
51
97
#
52
98
99
+ function configure_numtype (numtype:: Type{<:NumTypes} )
100
+ @eval promote_numtype (:: Type{T} , :: Type{S} ) where {T,S} = promote_type ($ numtype, numtype (T), numtype (S))
101
+ @eval macro interval (expr)
102
+ return _wrap_interval ($ numtype, expr)
103
+ end
104
+ @eval _parse (str:: AbstractString ) = parse (Interval{$ numtype}, str)
105
+ @eval emptyinterval () = emptyinterval (Interval{$ numtype})
106
+ @eval entireinterval () = entireinterval (Interval{$ numtype})
107
+ @eval nai () = nai (Interval{$ numtype})
108
+ return numtype
109
+ end
110
+
111
+ function configure_flavor (flavor:: Symbol )
112
+ flavor == :set_based || return throw (ArgumentError (" only the interval flavor `:set_based` is supported and implemented" ))
113
+ @eval zero_times_infinity (:: Type{T} ) where {T<: NumTypes } = zero_times_infinity (Flavor {$(QuoteNode(flavor))} (), T)
114
+ @eval div_by_thin_zero (x:: BareInterval ) = div_by_thin_zero (Flavor {$(QuoteNode(flavor))} (), x)
115
+ @eval contains_infinity (x:: BareInterval ) = contains_infinity (Flavor {$(QuoteNode(flavor))} (), x)
116
+ @eval is_valid_interval (a:: Real , b:: Real ) = is_valid_interval (Flavor {$(QuoteNode(flavor))} (), a, b)
117
+ return flavor
118
+ end
119
+
53
120
function configure_rounding (rounding:: Symbol )
54
121
rounding ∈ (:correct , :none ) || return throw (ArgumentError (" only the rounding mode `:correct` and `:none` are available" ))
55
122
@@ -86,15 +153,80 @@ function configure_rounding(rounding::Symbol)
86
153
return rounding
87
154
end
88
155
89
- function configure (; rounding:: Symbol = :correct )
156
+ function configure_power (power:: Symbol )
157
+ power ∈ (:slow , :fast ) || return throw (ArgumentError (" only the power mode `:slow` and `:fast` are available" ))
158
+
159
+ for f ∈ (:_select_pow , :_select_pown )
160
+ @eval $ f (x, y) = $ f (PowerMode {$(QuoteNode(power))} (), x, y)
161
+ end
162
+
163
+ return power
164
+ end
165
+
166
+ function configure_matmul (matmul:: Symbol )
167
+ matmul ∈ (:slow , :fast ) || return throw (ArgumentError (" only the matrix multiplication mode `:slow` and `:fast` are available" ))
168
+
169
+ @eval begin
170
+ function LinearAlgebra. mul! (C:: AbstractVector{<:RealOrComplexI} , A:: AbstractVecOrMat , B:: AbstractVector , α:: Number , β:: Number )
171
+ size (A, 2 ) == size (B, 1 ) || return throw (DimensionMismatch (" The number of columns of A must match the number of rows of B." ))
172
+ return _mul! (MatMulMode {$(QuoteNode(matmul))} (), C, A, B, α, β)
173
+ end
174
+
175
+ function LinearAlgebra. mul! (C:: AbstractMatrix{<:RealOrComplexI} , A:: AbstractVecOrMat , B:: AbstractVecOrMat , α:: Number , β:: Number )
176
+ size (A, 2 ) == size (B, 1 ) || return throw (DimensionMismatch (" The number of columns of A must match the number of rows of B." ))
177
+ return _mul! (MatMulMode {$(QuoteNode(matmul))} (), C, A, B, α, β)
178
+ end
179
+ end
180
+
181
+ return matmul
182
+ end
183
+
184
+ """
185
+ configure(; numtype=Float64, flavor=:set_based, rounding=:correct, power=:fast, matmul=:fast)
186
+
187
+ Configure the default behavior for:
188
+
189
+ - **Bound Type**: The default numerical type used to represent the bounds of the
190
+ intervals. The default is `Float64`, but other subtypes of
191
+ [`IntervalArithmetic.NumTypes`](@ref) can be used to adjust precision.
192
+
193
+ - **Flavor**: The interval representation that adhere to the IEEE Standard
194
+ 1788-2015. By default, it uses the set-based flavor, which excludes infinity
195
+ to be part of an interval. Learn more: [`IntervalArithmetic.Flavor`](@ref).
196
+
197
+ - **Interval Rounding**: Controls the rounding behavior for interval arithmetic
198
+ operations. By default, the library employs correct rounding to ensure that
199
+ bounds are computed as tightly as possible. Learn more:
200
+ [`IntervalArithmetic.IntervalRounding`](@ref).
201
+
202
+ - **Power mode**: A performance setting for power operations. The default mode
203
+ uses an efficient algorithm prioritizing fast computation, but it can be
204
+ adjusted for more precise, slower calculations if needed. Learn more:
205
+ [`IntervalArithmetic.PowerMode`](@ref).
206
+
207
+ - **Matrix Multiplication mode**: A performance setting for matrix
208
+ multiplication operations. The default mode uses an efficient algorithm
209
+ prioritizing fast computation, but it can be changed to use the standard
210
+ definition of matrix multiplication. Learn more:
211
+ [`IntervalArithmetic.MatMulMode`](@ref).
212
+ """
213
+ function configure (; numtype:: Type{<:NumTypes} = Float64, flavor:: Symbol = :set_based , rounding:: Symbol = :correct , power:: Symbol = :fast , matmul:: Symbol = :fast )
214
+ configure_numtype (numtype)
215
+ configure_flavor (flavor)
90
216
configure_rounding (rounding)
91
- return rounding
217
+ configure_power (power)
218
+ configure_matmul (matmul)
219
+ return numtype, flavor, rounding, power, matmul
92
220
end
93
221
94
222
configure ()
95
223
96
224
#
97
225
226
+ include (" symbols.jl" )
227
+
228
+ #
229
+
98
230
bareinterval (:: Type{BigFloat} , a:: AbstractIrrational ) = _unsafe_bareinterval (BigFloat, a, a)
99
231
100
232
# Note: generated functions must be defined after all the methods they use
0 commit comments