Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement systems for flavor, pointwise extensions, default bound and rounding mode #271

Closed
wants to merge 94 commits into from
Closed
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
c8ff400
Implement flavors with abstract union supertype
Kolaru Mar 14, 2019
595af4d
Split special.jl between common and flavor dependant
Kolaru Mar 27, 2019
13068ab
Reviewed macros.jl
Kolaru Mar 27, 2019
2bfdc2a
Review rounding.jl
Kolaru Mar 27, 2019
e0a47c4
Review convert.jl (incomplete)
Kolaru Mar 28, 2019
97f5a03
Fix compilation errors
Kolaru Mar 28, 2019
39b86fa
Review precision.jl
Kolaru Apr 16, 2019
eabd93b
Review set_operations.jl
Kolaru Apr 16, 2019
86594e4
Work on comparisons
Kolaru Jun 21, 2019
2819ec8
Continue review of arithmetic operations
Kolaru Aug 15, 2019
c67a0f3
Create file for 9.2 numeric functions
Kolaru Aug 16, 2019
ebde437
Separate basic arithmetic functions (9.1)
Kolaru Aug 17, 2019
de2f573
Review trigonometric.jl
Kolaru Aug 19, 2019
c3eb5fb
Review hyperbolic.jl
Kolaru Aug 19, 2019
4609669
Split power functions into power.jl
Kolaru Aug 19, 2019
74686d4
Document generated functions
Kolaru Aug 19, 2019
4c2b6d2
Rename midrad and mid(a, alpha)
Kolaru Aug 19, 2019
4ae53b7
Review integer.jl
Kolaru Aug 19, 2019
8bcab47
Review absmax functions
Kolaru Aug 19, 2019
33c21b0
Review cancellative functions
Kolaru Aug 19, 2019
bf18a2f
Review set operations and booleans
Kolaru Aug 19, 2019
036a1d8
Rename entireinterval to RR
Kolaru Aug 19, 2019
12cfc39
Separate boolean and set operation
Kolaru Aug 19, 2019
53e4866
Fix typos in precision.jl
Kolaru Aug 19, 2019
ab8fd8b
Split constants in a separate file and document it
Kolaru Aug 20, 2019
89358e6
Document requirement for set-based flavor
Kolaru Aug 20, 2019
80bbaca
Add ref to set-based requirements
Kolaru Aug 22, 2019
7dfb3f5
Review what was left in arithmetic.jl
Kolaru Aug 22, 2019
474f026
Review power.jl
Kolaru Aug 22, 2019
933a89b
Change include statements
Kolaru Aug 22, 2019
cabfeb7
Fix loading bugs
Kolaru Aug 22, 2019
88491f3
Fix several bugs
Kolaru Aug 22, 2019
9c0ee5c
Remove global precision test from test suite
Kolaru Aug 22, 2019
31409c3
Adapt bare interval parsing
Kolaru Aug 23, 2019
9b48379
Fix some bugs erroring/failing construction tests
Kolaru Aug 23, 2019
f932c61
Temporary TODO and changelog files
Kolaru Aug 23, 2019
d6c1e08
Finish fixing "constructing interval" test suite
Kolaru Aug 24, 2019
fb76b31
Delete commented precision test and comment complex tests
Kolaru Aug 24, 2019
09632e8
Fix and complete .. tests
Kolaru Aug 24, 2019
584aba0
Fix "conversion to interval" test suite
Kolaru Aug 24, 2019
dce76b4
Finish replacing == by isidentical for intervals in concstruction tests
Kolaru Aug 24, 2019
cc5694f
Finish fixing test in construction.jl
Kolaru Aug 24, 2019
78980f0
Fix tests
Kolaru Dec 15, 2019
91b9250
Fix most problems in numeric.jl tests
Kolaru Dec 15, 2019
b3091de
Remove setprecision from tests
Kolaru Dec 15, 2019
34568d8
Fix tests for trig functions
Kolaru Dec 15, 2019
3eefa4d
Use scaled_mid in biscet
Kolaru Dec 15, 2019
4661780
Fix multidim tests
Kolaru Dec 15, 2019
63cb3b8
Ignore broken tests
Kolaru Dec 15, 2019
67a1fb2
Refix construction.jl test following rebase
Kolaru Dec 18, 2019
a75eabe
Small test fix
Kolaru Feb 12, 2020
18b3fe2
Fix first tests after rebase
Kolaru Jul 27, 2020
d1dde57
Reintroduce signbit
Kolaru Jul 27, 2020
2fcb8ca
Negative int power fix
Kolaru Jul 27, 2020
9b46da7
Finish fixing tests
Kolaru Jul 28, 2020
766749f
Rename isless to isweaklyless to avoid confusion
Kolaru Aug 4, 2020
1cbdc9b
Fix setrounding and associated tests
Kolaru Aug 9, 2020
8206d52
More consistent notation
Kolaru Aug 9, 2020
7cee9c9
Remove unused file
Kolaru Aug 9, 2020
7435671
Use stareq for more readable tests
Kolaru Aug 9, 2020
6a0dcba
Fix cosh
Kolaru Aug 9, 2020
9a65cb1
Fix more broken tests
Kolaru Aug 9, 2020
43571ba
Clean inline todos and docstrings
Kolaru Aug 12, 2020
bb65c89
Fix eltype according to #397
Kolaru Aug 12, 2020
87781c1
Misc
Kolaru Oct 24, 2020
25110b2
Use generic constructor [unfinished]
Kolaru Oct 25, 2020
9f44928
Fix weird notation in cot
Kolaru Dec 11, 2021
a8b7d5a
Clean up a bit
Kolaru Dec 11, 2021
ac3c35b
Overhaul and constructor simplification
Kolaru Dec 20, 2021
8f6e905
Massive rounding.jl cleanup
Kolaru Dec 24, 2021
0c26577
Make consistency tests pass
Kolaru Dec 25, 2021
f02282e
Power tests pass
Kolaru Dec 25, 2021
15c2c3c
trig.jl tests
Kolaru Dec 25, 2021
1765225
Fix all tests up to rounding.jl
Kolaru Dec 26, 2021
a6eb8ab
Finalize all none IEEE tests
Kolaru Dec 26, 2021
8554f66
Merge branch 'master' into interval_flavors
Kolaru Dec 26, 2021
fc69f93
Merge 2
Kolaru Dec 26, 2021
ef69cc3
New parser
Kolaru Dec 29, 2021
a08cae5
Update the todo file
Kolaru Dec 29, 2021
727aae8
Make all tests pass
Kolaru Dec 31, 2021
3cd5790
Hotfix test erroring on CI
Kolaru Dec 31, 2021
1c51825
Clean up a bit
Kolaru Jan 10, 2022
2fd86c2
Remove manifest
Kolaru Jan 11, 2022
96b090b
Clean up and remove conversion.jl
Kolaru Jan 13, 2022
a993ef8
Remove force_interval
Kolaru Jan 15, 2022
8709e1f
Fix arithmetic bug with irrational
Kolaru Jan 15, 2022
ebb2307
Remove @round_up and @round_down macro
Kolaru Jan 15, 2022
df715e2
Finalize pointwise politic
Kolaru Jan 16, 2022
83d76e9
Go through TODO
Kolaru Jan 16, 2022
2c718e4
Revert RR for entireinterval
Kolaru Jan 16, 2022
d58dfae
Go through inline TODOs
Kolaru Jan 16, 2022
c2b09f9
Update changelog
Kolaru Jan 16, 2022
a9d5acb
First pass on lbenet review
Kolaru Jan 22, 2022
d8e71bb
Merge branch 'master' into interval_flavors
lucaferranti Jan 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
docs/build/

.vscode/
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ the interval, e.g. `convert(Interval{Float64}, 0.1)`

- Improvements towards conformance with the [IEEE-1788](https://standards.ieee.org/findstds/standard/1788-2015.html) standard for Interval Arithmetic:

- New `special_intervals.jl` file, with definitions of `emptyinterval`, `entireinterval`, `nai` and related functions. Add new interval functions (`<=`, `radius`, `precedes`, `strictprecedes`, `≺`, etc).
- New `special_intervals.jl` file, with definitions of `emptyinterval`, `RR`, `nai` and related functions. Add new interval functions (`<=`, `radius`, `precedes`, `strictprecedes`, `≺`, etc).

- Control rounding tighter for arithmetic operations; `*`, `inv` and `/` have been rewritten; this includes changes in `make_interval` and `convert` to get consistent behavior. These functions pass the corresponding tests in the [ITF1788](https://github.com/oheim/ITF1788) test suite.
- Deprecate the use of `⊊` in favor of `isinterior` (`⪽`).
Expand Down
191 changes: 191 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
Review intervals folder:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please gitignore this and the changelog? It adds a lot of noise when browsing the PR from github.

General:
☐ Choose whether to use x == zero(T) or x == 0 across files
☐ Check that default flavor always return safe result
☐ {F <: Type} -> {F<:Type} (remove spaces)
✔ Replace "IEEE standard" -> "IEEE Std 1788-2015" @done(19-08-22 16:13)
✔ "Corresponds to" -> "Implement" in doc @done(19-08-22 16:13)
✔ Rename `RR` -> `RR` @done(19-08-19 19:14)
☐ Investigate compile time warnings
✔ Check if intervals of different flavor type can/should be equal in the sense of `isidentical` @done(19-12-08 01:12)
☐ Operation on different flavors of interval should always error.

Discussion:
☐ Do we want to keep `@floatinterval` and `@biginteral` or use `@interval(F, expr1, expr2)` instead ?

Global precision:
✔ Get rid of it @done(19-08-20 16:49)
✔ Replace pi_interval(T) by Interval{T}(π) everywhere @done(19-12-18 22:59)
✔ Be sure it is done in compliance with #338 @done(19-12-18 22:59)

Flavors:
Implement set based flavor:
☐ Check all requested stuff 10.5.
☐ Error on undefined
☐ Implement cset flavor
☐ Make cset default
☐ Implement all the needed conversions
☐ Automatise with Cassette.jl ?

macros.jl:
✔ Review @done(19-08-23 01:57)
☐ Clean or open issue for cleaning of the file

precision.jl:
✔ Review @done(19-08-19 01:49)

rounding.jl:
✔ Review @done(19-08-19 01:50)

conversion.jl:
✔ Review @done(19-08-23 03:25)
☐ Fix ambiguous errors

complex.jl:
Should we even bother ?
☐ Review

9.1. Arithmetic functions:
☐ Distribute everything from arithmetic.jl in other files
basic.jl:
✔ Split @done(19-08-19 01:14)
✔ Verify all requested functions are there @done(19-08-19 02:01)
✔ Common @done(19-08-19 01:11)
☐ Adapt for the removal of promotion
☐ Make sure all cases are in the test suite
☐ Solve ambiguity error for real flavors
☐ Flavor dependent *
☐ Flavor dependent /
☐ Flavor dependent inv
☐ Flavor dependent fma
power.jl:
✔ Split @done(19-08-19 01:14)
✔ Verify all requested functions are there @done(19-08-19 04:29)
✔ Common @done(19-08-22 16:25)
☐ Add doc to generated funcs
☐ Flavor dependent power (for negative power)
☐ Flavor dependant log
☐ zero(T) or 0 ?
trigonometric.jl:
✔ Split @done(19-08-19 02:00)
✔ Verify all requested functions are there @done(19-08-19 02:00)
✔ Clean constants @done(19-08-19 14:13)
✔ Common @done(19-08-19 15:19)
☐ zero(T) or 0 ?
hyperbolic.jl:
✔ Split @done(19-08-19 15:23)
✔ Verify all requested functions are there @done(19-08-19 15:23)
✔ Common @done(19-08-19 15:31)
✔ Add docstring to generated funcs @done(19-08-19 16:45)
☐ Flavor dependent atanh
integer.jl:
✔ Split @done(19-08-19 17:31)
✔ Verify all requested functions are there @done(19-08-19 17:35)
✔ Common @done(19-08-19 17:43)
absmax.jl:
✔ Split @done(19-08-19 17:46)
✔ Verify all requested functions are there @done(19-08-19 17:46)
✔ Common @done(19-08-19 17:48)

9.2. Cancellative:
✔ Split @done(19-08-19 19:14)
✔ Verify all requested functions are there @done(19-08-19 19:14)
✔ Common @done(19-08-19 19:14)
☐ Check if cancelminus has flavor dependent edge cases

9.3 Set operations:
✔ Split @done(19-08-19 19:31)
✔ Verify all requested functions are there @done(19-08-19 19:31)
✔ Common @done(19-08-19 19:31)

9.4. Numeric functions:
✔ Split @done(19-08-19 01:26)
✔ Common @done(19-08-19 01:11)
☐ Solve mid(a, 0.5) != mid(a) discrepency
☐ Flavor dependent mid

9.5. Boolean functions:
These are in the set_operations.jl file
✔ Split @done(19-08-19 19:30)
✔ Verify all requested functions are there @done(19-08-19 19:31)
✔ Common @done(19-08-19 19:36)
✔ equal is not the same as == @done(19-08-19 19:36)
☐ Check `islessprime`
☐ Flavor dependent issubset/isinterior ?

9.6. Operatons on/with decoration:
☐ Split
☐ Verify all requested functions are there
☐ Review

9.7. Literals:
☐ Review

9.8. Constructor:
☐ Review
☐ Check correctness and tightness for Interval{T}(x)
☐ Document flavors
☐ Document constructors
☐ Make `..` work correctly for all input types
☐ Move `DefaultBound` definition before constructors to be able to use them
✔ Add Interval{T}(π) @done(19-08-19 01:58)
✔ Check performance @done(19-12-18 23:00)

10.5. Required operations in set-based falvor:
10.5.1. Literals:
☐ No idea, but do it
10.5.2. Constants:
✔ Add ref to doc @done(19-08-21 00:09)
☐ Move deprecation warning to a separated file ?
10.5.3. Forward mode elementary functions:
✔ Add ref to doc @done(19-08-21 00:20)
10.5.4. Reverse mode elementary functions:
✔ Open issue about their absence @done(19-08-20 03:16)
They are in IntervalConstraint.jl
10.5.5. Two output division:
✔ Add ref to doc @done(19-08-21 00:23)
☐ Flavor dependent edge case
☐ Recent GH issue
10.5.6. Cancellative:
✔ Add ref to doc @done(19-08-22 15:51)
☐ Check that the set-based follow the required behavior for undbounded intervals
10.5.7. Set opeations:
✔ Add ref to doc @done(19-08-22 15:55)
10.5.8. Constructors:
☐ Review I guess
10.5.9. Numeric functions:
✔ Add ref to doc @done(19-08-22 15:55)
10.5.10. Boolean:
✔ Check everything required is present @done(19-08-22 16:07)
✔ Add ref to doc @done(19-08-22 16:07)
10.6. Recommended operations:
☐ Check all that stuff


Other:
bisect.jl:
☐ Review
display.jl:
☐ Review
InteralArithmetic.jl:
☐ Review
☐ Make sure everything is exported correctly
☐ Check renamed/new functions are exported
parsing.jl:
✔ parsing of bare interval @done(19-08-23 02:28)
☐ parsing of decorated interval
rand.jl:
☐ Review
symbols.jl:
☐ Make sure everything is here


Review other folders:
Check PR #271 for details
☐ Do it

Bugs:
✔ `Int` times `Interval` errors (e.g. `2*a`) @done(19-12-14 23:50)

Tests:
☐ Uncomment complex tests in `construction.jl`
14 changes: 14 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Changelog

- File structure changed to match the IEEE standard
- Symbols that alias another function moved to `symbols.jl`
- Removed global precision
- `make_interval` renamed `wrap_literals`
- Removed `pi_interval(T)` in favor of `Interval{T}(π)`
- Renamed `multiply_by_positive_constant` to `scale`
- `@round` now take the flavor of the returned interval as first argument
- Removed `find_quadrants_tan` as it was a duplicate of `find_quadrants`
- Renamed `mid(a, α)` -> `scaled_mid(a, α)` (to avoid discrepency with default parameter)
- Functions returning intervals based on bound type now required a flavor type as parameter
- Renamed `entireinterval` -> `RR`
- Added check of the "IA_DEFAULT_FLAVOR" and "IA_DEFAULT_BOUND_TYPE" keys in `ENV` to get the flavor (`Interval`) and bound type (`DefaultBound`). The default interval type is thus `Interval{DefaultBound}`.
28 changes: 12 additions & 16 deletions src/IntervalArithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export ×, dot
import Base:
+, -, *, /, //, fma,
<, >, ==, !=, ⊆, ^, <=,
isless,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we import isless, do we also need to import <? Do they behave differently?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isless is for total order and < is for partial order and fall back to isless. Therefore we should only implement < and come up with a better name for the function implementing the less function defined in the standard (isweaklyless seems good to me).

Note that we definitely don't want isweaklyless equal to <, since the former has more or less nothing to do with number comparison.

in, zero, one, eps, typemin, typemax, abs, abs2, real, min, max,
sqrt, exp, log, sin, cos, tan, cot, inv, cbrt, csc, hypot, sec,
exp2, exp10, log2, log10,
Expand Down Expand Up @@ -50,18 +51,19 @@ import Base.MPFR: MPFRRoundUp, MPFRRoundDown, MPFRRoundNearest, MPFRRoundToZero,
import .Broadcast: broadcasted

export
AbstractInterval, Interval,
Interval, DefaultBound,
interval,
@interval, @biginterval, @floatinterval, @make_interval,
diam, radius, mid, mag, mig, hull,
emptyinterval, ∅, ∞, isempty, isinterior, ⪽,
precedes, strictprecedes, ≼, ≺, ⊂, ⊃, ⊇, contains_zero,
entireinterval, isentire, nai, isnai, isthin, iscommon, isatomic,
@interval, @biginterval, @floatinterval,
diam, radius, mid, scaled_mid, mag, mig, hull,
emptyinterval, ∅, ∞, isempty, isinterior, isdisjoint, ⪽,
precedes, strictprecedes, ≺, ⊂, ⊃, ⊇, contains_zero,
isidentical, isdistinct,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe export isstrictless and other such functions, specially if they are included in the IEEE Std 1788-2015.

RR, isentire, nai, isnai, isthin, iscommon, isatomic,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since entireinterval is proposed to be renamed to RR, the alias/synonim isRR of isentire could be added.

widen, inf, sup, bisect, mince,
parameters, eps, dist,
eps, dist,
midpoint_radius, interval_from_midpoint_radius,
RoundTiesToEven, RoundTiesToAway,
cancelminus, cancelplus, isunbounded,
cancelminus, cancelplus, isbounded, isunbounded,
.., @I_str, ±,
pow, extended_div,
setformat, @format
Expand All @@ -76,8 +78,6 @@ end
export
setindex # re-export from StaticArrays for IntervalBox



export showfull

import Base: rounding, setrounding, setprecision
Expand All @@ -102,28 +102,24 @@ export

function __init__()
setrounding(BigFloat, RoundNearest)


setprecision(Interval, 256) # set up pi
setprecision(Interval, Float64)
end


## Includes

include("intervals/intervals.jl")

include("multidim/multidim.jl")
include("bisect.jl")
include("decorations/decorations.jl")

include("rand.jl")
include("parsing.jl")
include("display.jl")
include("symbols.jl")

include("plot_recipes/plot_recipes.jl")

include("deprecated.jl")

"""
Region{T} = Union{Interval{T}, IntervalBox{T}}
"""
Expand Down
37 changes: 36 additions & 1 deletion src/bisect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Returns a tuple of the new intervals.
function bisect(X::Interval, α=where_bisect)
@assert 0 ≤ α ≤ 1

m = mid(X, α)
m = scaled_mid(X, α)

return (Interval(X.lo, m), Interval(m, X.hi))
end
Expand Down Expand Up @@ -40,3 +40,38 @@ function bisect(X::IntervalBox, i::Integer, α=where_bisect)

return (X1, X2)
end

"""
mince(x::Interval, n)

Splits `x` in `n` intervals of the same diameter, which are returned
as a vector.
"""
function mince(x::Interval, n)
nodes = range(x.lo, x.hi, length = n+1)
return [Interval(nodes[i], nodes[i+1]) for i in 1:length(nodes)-1]
end

"""
mince(x::IntervalBox, n)

Splits `x` in `n` intervals in each dimension of the same diameter. These
intervals are combined in all possible `IntervalBox`-es, which are returned
as a vector.
"""
@generated function mince(x::IntervalBox{N,T}, n) where {N,T}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: I just noticed that there is also mince function defined in src/multidim/intervalbox.jl, essentially with the same arguments. I'm not sure which one should be used nor which is faster.

quote
nodes_matrix = Array{Interval{T},2}(undef, n, N)
for i in 1:N
nodes_matrix[1:n,i] .= mince(x[i], n)
end

nodes = IntervalBox{$N,T}[]
Base.Cartesian.@nloops $N i _->(1:n) begin
Base.Cartesian.@nextract $N ival d->nodes_matrix[i_d, d]
ibox = Base.Cartesian.@ncall $N IntervalBox ival
push!(nodes, ibox)
end
nodes
end
end
14 changes: 14 additions & 0 deletions src/decorations/decorations.jl
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
include("intervals.jl")
include("functions.jl")

# TODO Check if it is consistent with #386
isnan(x::AbstractFlavor) = false # NaI is always decorated

# TODO adapt for each flavor
"""`NaI` not-an-interval: [NaN, NaN]."""
nai(::Type{T}) where T = DecoratedInterval(convert(T, NaN), convert(T, NaN), ill)
nai(::Type{F}) where {T, F<:Interval{T}} = nai(T)
nai(::Interval{T}) where T<:Real = nai(T)
nai(::DecoratedInterval{T}) where T<:Real = nai(T)
nai() = nai(Interval{DefaultBound})

isnai(x::Interval) = isnan(x.lo) || isnan(x.hi)
isnai(x::DecoratedInterval) = isnai(interval(x)) && x.decoration == ill
Loading