From c2f66c56af2a13520e7dbcd32079f58a9c98ab89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Mon, 24 Jul 2023 19:28:13 +0200 Subject: [PATCH 1/7] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 1c0522fc984d2631cc777bac0cd891ff2993e23d Merge: 4c239d52 ee93bd43 Author: Benoît Richard Date: Sun Jul 23 23:13:48 2023 +0200 Merge pull request #569 from vaerksted/master fix typos commit ee93bd43ff6f255a046f764afdc229dba33ed844 Author: spaette Date: Sat Jul 22 12:11:01 2023 -0500 typos commit 4c239d5223a6e430c646bdf91b6978aab976c2f0 Author: Benoît Richard Date: Tue Jul 4 00:35:20 2023 +0200 Bump version commit 249040dedd9fa78b348f59241b309e9e2b03e186 Merge: 44046589 7bef23ed Author: Benoît Richard Date: Tue Jul 4 00:34:13 2023 +0200 Merge pull request #525 from petvana/simplified-mod Simplified version of mod(x::Interval, y::Real) commit 44046589ca7c4ffbb662caa4a23852335dc2464c Author: Benoît Richard Date: Wed Jun 14 14:03:14 2023 +0200 Bump version for release commit 7bef23ed8c85ee8c392f8f80e91092e64fc72d63 Author: Petr Vana Date: Fri May 27 11:11:53 2022 +0200 Cleanup commit f9f4733a1134e4ad3a946ddf8023e0d7b5d7fa80 Author: Petr Vana Date: Fri May 27 11:10:05 2022 +0200 Throw ArgumentError for Interval divisor for mod commit 6fdc809a1ba51df6121a9fa39df388fca054132d Merge: 439723f0 d2603d6c Author: Petr Vana Date: Fri May 27 11:01:43 2022 +0200 Merge branch 'simplified-mod' of github.com:petvana/IntervalArithmetic.jl into simplified-mod commit 439723f068feb228e703fb03b20270586c2d83b9 Author: Petr Vana Date: Fri May 27 11:01:27 2022 +0200 Disable divisor for mod to be an interval commit d2603d6c4524ab884aeaabaf2265f8d123b13d28 Author: Petr Vana Date: Thu May 26 11:34:04 2022 +0200 Update docs commit 45abc460ab885ba1648c3b83fb74a96053c169f9 Author: Petr Vana Date: Thu May 26 11:30:14 2022 +0200 Implementation for strictly negative divisors for mod commit ff4791034526c3104889ee7105b7bcfb3809cd93 Author: Petr Vana Date: Thu May 26 11:11:35 2022 +0200 Add todo for mod with between two intervals commit ea00b231585d2307e4b10ba846f83943f0fe68d8 Author: Petr Vana Date: Wed May 25 19:59:30 2022 +0200 Imrpove test coverage + use zero() commit b56f4bec4b77fba85fee6039943542a7a4caa3d7 Author: Petr Vana Date: Wed May 25 13:44:24 2022 +0200 Use ⊇ operator commit d23df89472ae2721abdfbcaf46687efdd4c3890e Author: Petr Vana Date: Tue May 24 21:13:53 2022 +0200 Update src/intervals/functions.jl Co-authored-by: lucaferranti <49938764+lucaferranti@users.noreply.github.com> commit 153d749887a1cfbe5c480c91630116da25bd8020 Author: Petr Vana Date: Tue May 24 20:27:51 2022 +0200 Improve testing commit fea1b3403a5682874b4d42c5c8170f67be71d582 Author: Petr Vana Date: Tue May 24 20:10:05 2022 +0200 Introduce simplified version of mod --- NEWS.md | 4 +- docs/src/input_output.md | 2 +- .../Range of 2-dimensional functions.ipynb | 4 +- src/multidim/intervalbox.jl | 2 +- test/interval_tests/numeric.jl | 41 +++++++++++++++++++ 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7dc672caa..66ae524cb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,7 +6,7 @@ - The package now supports only Julia v1.3 and later. ### Breaking changes -- Changed from using `FastRounding.jl` to `RoundingEmulator.jl` for the defalt rounding mode. [#370](https://github.com/JuliaIntervals/IntervalArithmetic.jl/pull/370) +- Changed from using `FastRounding.jl` to `RoundingEmulator.jl` for the default rounding mode. [#370](https://github.com/JuliaIntervals/IntervalArithmetic.jl/pull/370) ## v0.15 @@ -293,7 +293,7 @@ v0.1 is the first public release of the package. ### Interval arithmetic - Two methods for interval rounding are available: - (i) narrow/slow (which uses hardward rounding mode changes for `Float64` intervals, and (ii) wide/fast (which does not change the rounding mode) + (i) narrow/slow (which uses hardware rounding mode changes for `Float64` intervals, and (ii) wide/fast (which does not change the rounding mode) - The current interval precision and rounding mode are stored in the `parameters` object - The macro `@interval` generates intervals based on the current interval precision - Trigonometric functions are "nearly" rigorous (for `Float64` intervals, correct rounding is not currently guaranteed) diff --git a/docs/src/input_output.md b/docs/src/input_output.md index 8ac10dc3b..bd7874e0d 100644 --- a/docs/src/input_output.md +++ b/docs/src/input_output.md @@ -73,7 +73,7 @@ 'u' Returns the interval with midpoint as lower bound and radius taken in upward direction. 'C' Returns upper case for Empty, Entire and Nai 'c' Returns lower case for Empty, Entire and Nai - '+' Returns postitve numbers with '+' sign before the number + '+' Returns positive numbers with '+' sign before the number '0' Left-pads the numbers with zeros instead of spaces within the field width - The field width specifies the length of midpoint string. diff --git a/examples/Range of 2-dimensional functions.ipynb b/examples/Range of 2-dimensional functions.ipynb index d1827efc9..6c5e83601 100644 --- a/examples/Range of 2-dimensional functions.ipynb +++ b/examples/Range of 2-dimensional functions.ipynb @@ -356,7 +356,7 @@ "\t\tconsole.log.apply(console, arguments);\n", "\t }\n", "\t},\n", - "\t// a central way to initalize communication\n", + "\t// a central way to initialize communication\n", "\t// for widgets.\n", "\tcommInitializer: function (widget) {\n", "\t widget.sendUpdate = function () {};\n", @@ -435,7 +435,7 @@ " });\n", "\t });\n", "\n", - "\t // coordingate with Comm and redraw Signals\n", + "\t // coordinate with Comm and redraw Signals\n", "\t // XXX: Test using Reactive here to improve performance\n", "\t $([IPython.events]).on(\n", "\t\t'output_appended.OutputArea', function (event, type, value, md, toinsert) {\n", diff --git a/src/multidim/intervalbox.jl b/src/multidim/intervalbox.jl index 48179e65e..05cfdbd26 100644 --- a/src/multidim/intervalbox.jl +++ b/src/multidim/intervalbox.jl @@ -61,7 +61,7 @@ length(::IntervalBox{N}) where {N} = N Return a vector of the `mid` of each interval composing the `IntervalBox`. -See `mid(X::Interval, α=0.5)` for more informations. +See `mid(X::Interval, α=0.5)` for more information. """ mid(X::IntervalBox) = mid.(X) scaled_mid(X::IntervalBox, α) = scaled_mid.(X, α) diff --git a/test/interval_tests/numeric.jl b/test/interval_tests/numeric.jl index bcb136075..b688d81f0 100644 --- a/test/interval_tests/numeric.jl +++ b/test/interval_tests/numeric.jl @@ -386,3 +386,44 @@ end @test nthroot(interval(BigFloat, -81, -16), -4) ≛ ∅ @test nthroot(interval(BigFloat, -81, -16), 1) ≛ interval(BigFloat, -81, -16) end + +# approximation used for testing (not to rely on ≈ for intervals) +# ⪆(x, y) = (x ≈ y) && (x ⊇ y) +⪆(x::Interval, y::Interval) = x.lo ≈ y.lo && x.hi ≈ y.hi && x ⊇ y + +@testset "`mod`" begin + r = 0.0625 + x = r..(1+r) + @test mod(x, 1) == mod(x, 1.0) == 0..1 + @test mod(x, 2) == mod(x, 2.0) ⪆ x + @test mod(x, 2.5) ⪆ x + @test mod(x, 0.5) == 0..0.5 + @test mod(x, -1) == mod(x, -1.0) == -1..0 + @test mod(x, -2) == mod(x, -2.0) ⪆ -2+x + @test mod(x, -2.5) ⪆ -2.5+x + @test mod(x, -0.5) == -0.5..0 + + x = (-1+r) .. -r + @test mod(x, 1) == mod(x, 1.0) ⪆ 1+x + @test mod(x, 2) == mod(x, 2.0) ⪆ 2+x + @test mod(x, 2.5) ⪆ 2.5+x + @test mod(x, 0.5) == 0..0.5 + @test mod(x, -1) == mod(x, -1.0) ⪆ x + @test mod(x, -2) == mod(x, -2.0) ⪆ x + @test mod(x, -2.5) ⪆ x + @test mod(x, -0.5) == -0.5..0 + + x = -r .. 1-r + @test mod(x, 1) == mod(x, 1.0) == 0..1 + @test mod(x, 2) == mod(x, 2.0) == 0..2 + @test mod(x, 2.5) == 0..2.5 + @test mod(x, 0.5) == 0..0.5 + @test mod(x, -1) == mod(x, -1.0) == -1..0 + @test mod(x, -2) == mod(x, -2.0) == -2..0 + @test mod(x, -2.5) == -2.5..0 + @test mod(x, -0.5) == -0.5..0 + + # TODO - implement mod for two intervals + @test_throws ArgumentError mod(1..2, 1.4..1.5) + @test_throws ArgumentError mod(1.0, 1.4..1.5) +end From 4646c208058a91971d63aa73f1e4403c577a734a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Mon, 24 Jul 2023 19:28:27 +0200 Subject: [PATCH 2/7] Fix typo --- src/intervals/arithmetic/trigonometric.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intervals/arithmetic/trigonometric.jl b/src/intervals/arithmetic/trigonometric.jl index 25815be07..04ae3250d 100644 --- a/src/intervals/arithmetic/trigonometric.jl +++ b/src/intervals/arithmetic/trigonometric.jl @@ -64,7 +64,7 @@ function sin(a::Interval{T}) where {T<:NumTypes} diam(a) > inf(two_pi(T)) && return whole_range - # The following is equiavlent to doing temp = a / half_pi and + # The following is equivalent to doing temp = a / half_pi and # taking floor(inf(a)), floor(sup(a)) alo, ahi = bounds(a) lo_quadrant = minimum(find_quadrants(T, alo)) From bc2b84337e007997f2975bc2f458b9c1509eab27 Mon Sep 17 00:00:00 2001 From: schillic Date: Sun, 27 Aug 2023 22:08:17 +0200 Subject: [PATCH 3/7] fix iszero -> isone --- src/intervals/arithmetic/basic.jl | 2 +- test/interval_tests/numeric.jl | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/intervals/arithmetic/basic.jl b/src/intervals/arithmetic/basic.jl index fd825384e..9e452f0cd 100644 --- a/src/intervals/arithmetic/basic.jl +++ b/src/intervals/arithmetic/basic.jl @@ -95,7 +95,7 @@ end *(a::Interval, b::Interval) = *(promote(a, b)...) function *(a::Interval{T}, b::T) where {T<:NumTypes} - (isempty(a) || isthinzero(a) || iszero(b)) && return a + (isempty(a) || isthinzero(a) || isone(b)) && return a if b ≥ 0 return @round(T, inf(a) * b, sup(a) * b) else diff --git a/test/interval_tests/numeric.jl b/test/interval_tests/numeric.jl index b688d81f0..b132d2aef 100644 --- a/test/interval_tests/numeric.jl +++ b/test/interval_tests/numeric.jl @@ -79,8 +79,9 @@ end @test 0.1 + x ≛ interval(1.0999999999999999, 2.1) @test 3.0 - x ≛ 1..2 @test 3.1 - x ≛ interval(1.1, 2.1) - @test 0.1 * (1..1) ≛ interval(0.1, 0.1) - @test (1..1) / 10.0 ≛ interval(0.09999999999999999, 0.1) + @test 0.1 * interval(1) ≛ interval(0.1, 0.1) + @test 0.0 * interval(1) ≛ interval(0.0, 0.0) + @test interval(1) / 10.0 ≛ interval(0.09999999999999999, 0.1) end @testset "Arithmetic with irrational" begin From 0121c02bce9cb0a502f3d200af4db52ebaad6e54 Mon Sep 17 00:00:00 2001 From: OlivierHnt <38465572+OlivierHnt@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:05:45 +0200 Subject: [PATCH 4/7] Set version to 0.21.1 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 4e0f34ef4..73751e3d7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "IntervalArithmetic" uuid = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" repo = "https://github.com/JuliaIntervals/IntervalArithmetic.jl.git" -version = "0.21.0" +version = "0.21.1" [deps] CRlibm = "96374032-68de-5a5b-8d9e-752f78720389" From 46f2bfb6344a5a337de2c8f737087baf6769784f Mon Sep 17 00:00:00 2001 From: OlivierHnt <38465572+OlivierHnt@users.noreply.github.com> Date: Mon, 28 Aug 2023 13:48:08 +0200 Subject: [PATCH 5/7] Implement `muladd` --- src/IntervalArithmetic.jl | 7 +++---- src/intervals/arithmetic/basic.jl | 14 ++++++++++++++ test/interval_tests/numeric.jl | 13 ++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/IntervalArithmetic.jl b/src/IntervalArithmetic.jl index ec52d4973..07f19ad38 100644 --- a/src/IntervalArithmetic.jl +++ b/src/IntervalArithmetic.jl @@ -17,10 +17,9 @@ export ×, dot import Base: - +, -, *, /, //, fma, - <, >, ==, !=, ⊆, ^, <=, >=, - in, zero, one, eps, typemin, typemax, abs, abs2, min, max, - sqrt, exp, log, exp2, exp10, log2, log10, inv, cbrt, hypot, + +, -, *, /, //, muladd, fma, + ^, sqrt, exp, log, exp2, exp10, log2, log10, inv, cbrt, hypot, + zero, one, eps, typemin, typemax, abs, abs2, min, max, rad2deg, deg2rad, sin, cos, tan, cot, csc, sec, asin, acos, atan, acot, sinpi, cospi, sincospi, sinh, cosh, tanh, coth, csch, sech, asinh, acosh, atanh, acoth, diff --git a/src/intervals/arithmetic/basic.jl b/src/intervals/arithmetic/basic.jl index 9e452f0cd..2218b3213 100644 --- a/src/intervals/arithmetic/basic.jl +++ b/src/intervals/arithmetic/basic.jl @@ -211,6 +211,20 @@ min_ignore_nans(args...) = minimum(filter(x -> !isnan(x), args)) max_ignore_nans(args...) = maximum(filter(x -> !isnan(x), args)) + + +muladd(a::F, b::F, c::F) where {F<:Interval} = a * b + c + +muladd(a::Interval, b::Interval, c::Interval) = muladd(promote(a, b, c)...) + +muladd(a::Interval{T}, b::Interval{S}, c::Number) where {T<:NumTypes,S<:NumTypes} = muladd(promote(a, b, interval(promote_numtype(T, S), c))...) +muladd(a::Interval{T}, b::Number, c::Interval{S}) where {T<:NumTypes,S<:NumTypes} = muladd(promote(a, interval(promote_numtype(T, S), b), c)...) +muladd(a::Number, b::Interval{T}, c::Interval{S}) where {T<:NumTypes,S<:NumTypes} = muladd(promote(interval(promote_numtype(T, S), a), b, c)...) + +muladd(a::Interval{T}, b::Number, c::Number) where {T<:NumTypes} = muladd(a, interval(T, b), interval(T, c)) +muladd(a::Number, b::Interval{T}, c::Number) where {T<:NumTypes} = muladd(interval(T, a), b, interval(T, c)) +muladd(a::Number, b::Number, c::Interval{T}) where {T<:NumTypes} = muladd(interval(T, a), interval(T, b), c) + """ fma(a::Interval, b::Interval, c::Interval) diff --git a/test/interval_tests/numeric.jl b/test/interval_tests/numeric.jl index b132d2aef..0f31b16b0 100644 --- a/test/interval_tests/numeric.jl +++ b/test/interval_tests/numeric.jl @@ -70,7 +70,18 @@ end @test extended_div(interval(-2.0, -1.0), interval(-2.0, 4.0)) ≛ ((-∞.. -0.25), (0.5..∞)) @test extended_div(interval(0.0, 0.0), interval(-1.0, 1.0)) ≛ (entireinterval(c), emptyinterval(c)) - @test (0..∞) * (-1..∞) ≛ -∞..∞ + @test interval(0, Inf) * interval(-1, Inf) ≛ interval(-Inf, Inf) + + result = interval(1.1) * interval(2) + interval(3) + @test muladd(interval(1.1), interval(2), interval(3)) ≛ result + @test muladd(interval(1.1), interval(Float32, 2), interval(3)) ≛ result + @test muladd(interval(1.1), interval(2), 3) ≛ result + @test muladd(interval(1.1), 2, interval(3)) ≛ result + @test muladd(1.1, interval(2), interval(3)) ≛ result + @test muladd(interval(1.1), 2, 3) ≛ result + @test muladd(1.1, interval(2), 3) ≛ result + @test muladd(1.1, 2, interval(3)) ≛ result + end @testset "Arithmetic with constants" begin From 939e8b0046912302fc842a0e777229e7fdb75a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Mon, 11 Sep 2023 01:46:51 +0200 Subject: [PATCH 6/7] Fix import --- src/IntervalArithmetic.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/IntervalArithmetic.jl b/src/IntervalArithmetic.jl index 07f19ad38..1673b2be2 100644 --- a/src/IntervalArithmetic.jl +++ b/src/IntervalArithmetic.jl @@ -18,8 +18,9 @@ export ×, dot import Base: +, -, *, /, //, muladd, fma, - ^, sqrt, exp, log, exp2, exp10, log2, log10, inv, cbrt, hypot, - zero, one, eps, typemin, typemax, abs, abs2, min, max, + <, >, ==, !=, ⊆, ^, <=, >=, + in, zero, one, eps, typemin, typemax, abs, abs2, min, max, + sqrt, exp, log, exp2, exp10, log2, log10, inv, cbrt, hypot, rad2deg, deg2rad, sin, cos, tan, cot, csc, sec, asin, acos, atan, acot, sinpi, cospi, sincospi, sinh, cosh, tanh, coth, csch, sech, asinh, acosh, atanh, acoth, From ddbafd2e42302c857770011a5dbc8183719a58c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Mon, 11 Sep 2023 01:48:03 +0200 Subject: [PATCH 7/7] Remove mod tests for non existant function --- test/interval_tests/numeric.jl | 43 +--------------------------------- 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/test/interval_tests/numeric.jl b/test/interval_tests/numeric.jl index 0f31b16b0..21bdd6f71 100644 --- a/test/interval_tests/numeric.jl +++ b/test/interval_tests/numeric.jl @@ -397,45 +397,4 @@ end @test nthroot(interval(BigFloat, -27, 27), -3) ≛ interval(BigFloat, -Inf, Inf) @test nthroot(interval(BigFloat, -81, -16), -4) ≛ ∅ @test nthroot(interval(BigFloat, -81, -16), 1) ≛ interval(BigFloat, -81, -16) -end - -# approximation used for testing (not to rely on ≈ for intervals) -# ⪆(x, y) = (x ≈ y) && (x ⊇ y) -⪆(x::Interval, y::Interval) = x.lo ≈ y.lo && x.hi ≈ y.hi && x ⊇ y - -@testset "`mod`" begin - r = 0.0625 - x = r..(1+r) - @test mod(x, 1) == mod(x, 1.0) == 0..1 - @test mod(x, 2) == mod(x, 2.0) ⪆ x - @test mod(x, 2.5) ⪆ x - @test mod(x, 0.5) == 0..0.5 - @test mod(x, -1) == mod(x, -1.0) == -1..0 - @test mod(x, -2) == mod(x, -2.0) ⪆ -2+x - @test mod(x, -2.5) ⪆ -2.5+x - @test mod(x, -0.5) == -0.5..0 - - x = (-1+r) .. -r - @test mod(x, 1) == mod(x, 1.0) ⪆ 1+x - @test mod(x, 2) == mod(x, 2.0) ⪆ 2+x - @test mod(x, 2.5) ⪆ 2.5+x - @test mod(x, 0.5) == 0..0.5 - @test mod(x, -1) == mod(x, -1.0) ⪆ x - @test mod(x, -2) == mod(x, -2.0) ⪆ x - @test mod(x, -2.5) ⪆ x - @test mod(x, -0.5) == -0.5..0 - - x = -r .. 1-r - @test mod(x, 1) == mod(x, 1.0) == 0..1 - @test mod(x, 2) == mod(x, 2.0) == 0..2 - @test mod(x, 2.5) == 0..2.5 - @test mod(x, 0.5) == 0..0.5 - @test mod(x, -1) == mod(x, -1.0) == -1..0 - @test mod(x, -2) == mod(x, -2.0) == -2..0 - @test mod(x, -2.5) == -2.5..0 - @test mod(x, -0.5) == -0.5..0 - - # TODO - implement mod for two intervals - @test_throws ArgumentError mod(1..2, 1.4..1.5) - @test_throws ArgumentError mod(1.0, 1.4..1.5) -end +end \ No newline at end of file