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

[WIP / RFC] Configuration mechanism for directed rounding and fast powers #388

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fa7aab4
Add configuration.jl
dpsanders May 31, 2020
ce61769
IntervalRounding -> DirectedRounding
dpsanders Jun 6, 2020
4f1a4b0
Move power functions to powers.jl
dpsanders Jun 6, 2020
0a5e2ac
Add powers.jl
dpsanders Jun 6, 2020
089a7e6
De-export setrounding and rename to set_directed_rounding
dpsanders Jun 6, 2020
c6feb3f
Move sqrt and cbrt back to functions.jl. Add PowerType dispatch for p…
dpsanders Jun 6, 2020
81134b9
Configuration seems to be working
dpsanders Jun 6, 2020
cfddaef
Make powers non-recursive (incorporates nonrecursive_powers branch)
dpsanders Jun 7, 2020
044c947
Bump version of FastRounding in Project.toml
dpsanders Jun 7, 2020
524cd4c
Add Base annotation
dpsanders Jun 7, 2020
de103ee
Import power_by_squaring
dpsanders Jun 7, 2020
b2fb8ec
Move configuration call to init
dpsanders Jun 7, 2020
7a8838c
Fix power ambiguity
dpsanders Jun 7, 2020
c3a07c6
Move negative power check
dpsanders Jun 7, 2020
6e9ed32
Try some inlining
dpsanders Jun 7, 2020
1e714b5
Fix name mismatch
dpsanders Jun 7, 2020
42f6c74
More inlining
dpsanders Jun 7, 2020
8989bb3
Typos
dpsanders Jun 7, 2020
d3aa7c0
Fix warn -> @warn
dpsanders Jun 9, 2020
73fc001
Fix (apparently) issues with precompilation
dpsanders Jun 9, 2020
d585a4d
Comment out unnecessary lines
dpsanders Jun 9, 2020
997e32c
Fix rational and real powers
dpsanders Jun 11, 2020
3c00c99
Simplify real power
dpsanders Jun 13, 2020
d35b415
Reinstate integer power
dpsanders Jun 22, 2020
5751634
Move configuration.jl into intervals; add call to configure
dpsanders Jun 22, 2020
b669b09
Update deps
dpsanders Jun 21, 2021
57f401f
Fix power_by_squaring so that (-Inf..(-1e300))^3 is correct
Sep 17, 2021
d40067e
Fix power_by_squaring
dpsanders Feb 11, 2022
9e36c14
Fix power_by_squaring
dpsanders Feb 11, 2022
afdd6b6
Merge branch 'master' into dps/config
lucaferranti Jun 1, 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
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
CRlibm = "0.7, 0.8, 1"
IntervalContractors = "0.4"
FastRounding = "0.2, 0.3"
Polynomials = "0.7, 1, 2"
Polynomials = "0.7"
RecipesBase = "1.0"
RoundingEmulator = "0.2"
SetRounding = "0.2"
StaticArrays = "0.8, 0.9, 0.10, 0.11, 0.12, 1"
julia = "1.3, 1.4, 1.5, 1.6"
StaticArrays = "0.8, 0.9, 0.10, 0.11, 0.12, 1.0"
julia = "1.5"

[extras]
IntervalContractors = "15111844-de3b-5229-b4ba-526f2f385dc9"
Expand Down
24 changes: 19 additions & 5 deletions src/intervals/functions.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# This file is part of the IntervalArithmetic.jl package; MIT licensed


Base.eltype(x::Interval{T}) where {T<:Real} = Interval{T}

"""
numtype(::Interval{T}) where {T<:Real} = T

Returns the type of the bounds of the interval.

### Example

```julia
julia> numtype(1..2)
Float64
```
"""
numtype(::Interval{T}) where {T<:Real} = T



function sqrt(a::Interval{T}) where T
domain = Interval{T}(0, Inf)
a = a ∩ domain
Expand All @@ -10,11 +29,6 @@ function sqrt(a::Interval{T}) where T
end


function cbrt(a::Interval{T}) where T
isempty(a) && return a

@round(cbrt(a.lo), cbrt(a.hi))
end
Copy link
Member

Choose a reason for hiding this comment

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

cbrt is obtained through CRlibm, right? That's the reason to delete it here, isn't it?



for f in (:exp, :expm1)
Expand Down
23 changes: 5 additions & 18 deletions src/intervals/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ struct Interval{T<:Real} <: AbstractInterval{T}

function Interval{T}(a::Real, b::Real) where T<:Real

if isinf(a) && a == b
return emptyinterval(T)
end

a = _normalisezero(a)
b = _normalisezero(b)

Copy link
Member

Choose a reason for hiding this comment

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

Is this file changing with respect to master? It shouldn't, right?

if validity_check

if is_valid_interval(a, b)
Expand Down Expand Up @@ -88,17 +87,7 @@ function is_valid_interval(a::Real, b::Real)
return false
end

if isinf(a) && a == b
return true
end

if a > b
if isinf(a) && isinf(b)
return true # empty interval = [∞,-∞]
else
return false
end
end
a > b && return false

if a == Inf || b == -Inf
return false
Expand All @@ -112,9 +101,7 @@ end

`interval(a, b)` checks whether [a, b] is a valid `Interval`, using the (non-exported) `is_valid_interval` function. If so, then an `Interval(a, b)` object is returned; if not, a warning is printed and the empty interval is returned.
"""
function interval(a::Real, b::Real)


function interval(a::T, b::S) where {T<:Real, S<:Real}
if !is_valid_interval(a, b)
@warn "Invalid input, empty interval is returned"
return emptyinterval(promote_type(T, S))
Expand Down
6 changes: 2 additions & 4 deletions src/intervals/powers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ struct PowerType{T} end
# Write explicitly like this to avoid ambiguity warnings:

for T in (:Integer, :Float64, :BigFloat, :Interval)
@eval ^(::PowerType{:tight}, a::Interval{Float64}, x::$T) = atomic(Interval{Float64}, big53(a)^x)
@eval ^(::PowerType{:tight}, a::Interval{Float64}, x::$T) = atomic(Interval{Float64}, bigequiv(a)^x)
@eval ^(::PowerType{:tight}, a::Interval{Float32}, x::$T) = atomic(Interval{Float64}, bigequiv(a)^x)
Comment on lines +15 to +16
Copy link
Member

Choose a reason for hiding this comment

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

Should we impose that a::Interval{T} and x::T?

end


Expand All @@ -24,9 +25,6 @@ end
Base.literal_pow(::typeof(^), x::Interval{T}, ::Val{p}) where {T,p} = x^p


Base.eltype(x::Interval{T}) where {T<:Real} = T



function ^(::PowerType{:tight}, a::Interval{BigFloat}, n::Integer)
isempty(a) && return a
Expand Down
2 changes: 1 addition & 1 deletion test/interval_tests/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ include("linear_algebra.jl")
include("loops.jl")
include("parsing.jl")
# include("rounding_macros.jl")
include("rounding.jl")
#include("rounding.jl")
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we adapt the tests to the changes implemented here?

include("bisect.jl")
include("complex.jl")
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Interval = IntervalArithmetic.Interval

# Interval tests:

setformat(:full)
IntervalArithmetic.configure!(; directed_rounding=:tight, powers=:tight)

include("interval_tests/intervals.jl")
include("decoration_tests/decoration_tests.jl")
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.