11# Philosophy
22
33The goal of the ` Interval ` type is to be directly used to replace floating point
4- number in arbitrary julia code, such that in any calculation,
5- the resulting intervals are guaranteed to bound the true image of the starting
4+ numbers in arbitrary julia code, such that, in any calculation,
5+ the resulting interval is guaranteed to bound the true image of the starting
66intervals.
77
8- So, essentially, we would like ` Interval ` to act as numbers and
9- the julia ecosystem has evolved to use ` Real ` as the default supertype
8+ So, essentially, we would like ` Interval ` to act as numbers.
9+ And the julia ecosystem has evolved to use ` Real ` as the default supertype
1010for numerical types that are not complex.
1111Therefore, to ensure the widest compatiblity,
1212our ` Interval ` type must be a subtype of ` Real ` .
1313
14- Then , for any function ` f(x::Real) ` ,
15- we want the following to hold for all real ` x ` in the interval ` X `
14+ Mathematically , for any function ` f(x::Real) ` ,
15+ we want the following to hold
1616(note that it holds for ** all** real numbers in ` X ` ,
17- even those that can not be represented as floating point numbers):
17+ even those that cannot be represented as floating point numbers):
1818``` math
1919f(x) \in f(X), \qquad \forall x \in X.
2020```
21+ The interval-valued function ` f(X) ` is called
22+ the _ pointwise extension_ of ` f(x) ` (which is defined on real numbers).
2123
2224At first glance, this is reasonable:
2325all arithmetic operations are well-defined for both real numbers and intervals,
@@ -34,7 +36,7 @@ arithmetic operations.
34363 . Act as a container of a single element,
3537 e.g. ` collect(x) ` returns a 0-dimensional array containing ` x ` .
3638
37- Each of those points lead to specific design choice for ` IntervalArithmetic.jl ` ,
39+ Each of those points lead to specific design choices for ` IntervalArithmetic.jl ` ,
3840choices that we detail below.
3941
4042
@@ -46,53 +48,65 @@ to a `Float64` to be able to perform the addition.
4648Following this logic, it means that ` 0.1 + interval(2.2, 2.3) ` should
4749silently promote ` 0.1 ` to an interval.
4850
49- However, in this case we can not guarantee that ` 0.1 ` is known exactly,
50- because we do not know how it was produced in the first place.
51+ However, in this case we cannot guarantee that ` 0.1 ` is known exactly,
52+ because we do not know how it was produced in the first place
53+ (it could be contain numerical inaccuracy from another computation from example).
5154Following the julia convention is thus in contradiction with providing
5255guaranteed result.
5356
5457In this case, we choose to be mostly silent,
5558the information that a non-interval of unknown origin is recorded in the ` NG ` flag,
5659but the calculation is not interrupted, and no warning is printed.
60+ If an interval is flagged with ` NG ` it means that it was produced through
61+ promotion of real numbers from unknown origin, for example
62+ ``` julia
63+ julia> X = interval (1 , 2 )
64+ [1.0 , 2.0 ]_com # The interval is guaranteed because it was explicitly created
65+
66+ julia> X + 0.1
67+ [1.1 , 2.1 ]_com_NG # The NG flag appears, because 0.1 is not provably exact
68+ ```
5769
5870For convenience, we provide the [ ` ExactReal ` ] ( @ref ) and [ ` @exact ` ] ( @ref ) macro
59- to allow to explicitly mark a number as being exact,
71+ to allow explicitly marking a number as being exact,
6072and not produce the ` NG ` flag when mixed with intervals.
6173
74+ Note that this still assume that all interval inputs are correct.
75+ Please see the [ contructors page] ( @ref " Constructing intervals ") for more information
76+ about potential caveats.
6277
6378
6479## Comparison operators
6580
66- We can extend our above definition of the desired behavior for two real numbers
67- ` x ` and ` y ` , and their respective intervals ` X ` and ` Y ` .
68- With this, we want to have, for any function` f ` ,
69- for all ` x ` in ` X ` and all ` y ` in ` Y ` ,
70- ``math
81+ We can extend the definition of the pointwise extension of a function ` f ` for two real numbers
82+ ` x ` and ` y ` , and their respective intervals ` X ` and ` Y ` , as
83+ ``` math
7184f(x, y) \in f(X, Y), \qquad \forall x \in X, y \in Y.
72- ``
85+ ```
7386
7487With this in mind, an operation such as ` == ` can easily be defined for intervals
7588
76891 . If the intervals are disjoints (` X ∩ Y === ∅ ` ), then ` X == Y ` is ` [false] ` .
77- 2 . If the intervals both contain a single element ,
90+ 2 . If the intervals both contain a single floating point number ,
7891 and that element is the same for both,
7992 ` X == Y ` is ` [true] ` .
80933 . Otherwise, we can not conclude anything, and ` X == Y ` must be ` [false, true] ` .
8194
82- Not that we use intervals in all case , because, according to our definition,
95+ Not that we use intervals for all outputs , because, according to our definition,
8396the true result must be contained in the returned interval.
8497However, this is not convenient, as any ` if ` statement would error when used
8598with an interval.
8699Instead, we have opted to return respectively ` false ` and ` true `
87100for cases 1 and 2, and to immediately error otherwise.
88101
89102In this way, we can return a more informative error,
90- but we only do it when the result is ambiguous.
103+ but we only error when the result is ambiguous.
91104
92105This has a clear cost, however, in that some expected behaviors do not hold.
93106For example, an ` Interval ` is not equal to itself.
94107
95- ``` julia> X = interval(1, 2)
108+ ``` julia
109+ julia> X = interval (1 , 2 )
96110[1.0 , 2.0 ]_com
97111
98112julia> X == X
@@ -133,9 +147,10 @@ or error as the result can not be established.
133147To be safe, we decided to go one step further and disable
134148** all** set operations from julia ` Base ` on intervals.
135149These operations can instead be performed with the specific ` *_interval ` function,
136- for example ` in_interval ` as a replacement for ` in ` ,
137- except for ` setdiff ` .
138- We can not meaningfully define the set difference of two intervals,
150+ for example ` in_interval ` as a replacement for ` in ` .
151+
152+ ` setdiff ` is an exception,
153+ as we can not meaningfully define the set difference of two intervals,
139154because our intervals are always closed,
140155while the result of ` setdiff ` can be open.
141156
0 commit comments