Skip to content

Commit

Permalink
Update importing to prevent module conflicts, update require (add Int…
Browse files Browse the repository at this point in the history
…ervalArithmetic.jl), add precompilation.
  • Loading branch information
Unknown committed Apr 3, 2018
1 parent 73843bb commit 9abc286
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 65 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.6
IntervalArithmetic 0.9.1
12 changes: 8 additions & 4 deletions src/EAGOIntervalArithmetic.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#__precompile__(true)
__precompile__(true)

module EAGOIntervalArithmetic

import IntervalArithmetic: mid, isdisjoint, isinterior, mig, mag, precedes,
strictprecedes, sup, inf, hull, diam, pow, dist,
isthin, isentire, radius

import Base:
+, -, *, /, //, fma,
<, >, ==, !=, , ^, <=,
Expand All @@ -22,10 +26,10 @@ import Base:

export
AbstractMCInterval, MCInterval, diam, radius, mid, mag, mig, hull,
emptyinterval, ∅, ∞, isempty, isinterior, isdisjoint, ,
precedes, strictprecedes, , entireinterval, isentire, nai, isnai, isthin,
emptyMCinterval, ∅, ∞, isempty, isinterior, isdisjoint, ,
precedes, strictprecedes, , entireMCinterval, isentire, nai, isnai, isthin,
iscommon, isatomic, widen, inf, sup,parameters, eps, dist,
pi_interval,midpoint_radius, interval_from_midpoint_radius, pow
pi_MCinterval,midpoint_radius, interval_from_midpoint_radius, pow, flttoMCI

include("IntervalArithmetic/intervals.jl")

Expand Down
44 changes: 22 additions & 22 deletions src/IntervalArithmetic/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ one(::Type{MCInterval{T}}) where T<:AbstractFloat = MCInterval(one(T))
-(a::MCInterval) = MCInterval(-a.hi, -a.lo)

function +(a::MCInterval{T}, b::MCInterval{T}) where T<:AbstractFloat
(isempty(a) || isempty(b)) && return emptyinterval(T)
(isempty(a) || isempty(b)) && return emptyMCinterval(T)
MCInterval{T}(a.lo + b.lo, a.hi + b.hi)
end

function -(a::MCInterval{T}, b::MCInterval{T}) where T<:AbstractFloat
(isempty(a) || isempty(b)) && return emptyinterval(T)
(isempty(a) || isempty(b)) && return emptyMCinterval(T)
MCInterval{T}(a.lo - b.hi, a.hi - b.lo)
end


## Multiplication

function *(a::MCInterval{T}, b::MCInterval{T}) where T<:AbstractFloat
(isempty(a) || isempty(b)) && return emptyinterval(T)
(isempty(a) || isempty(b)) && return emptyMCinterval(T)

(iszero(a) || iszero(b)) && return zero(MCInterval{T})

Expand All @@ -104,13 +104,13 @@ end
## Division

function inv(a::MCInterval{T}) where T<:AbstractFloat
isempty(a) && return emptyinterval(T)
isempty(a) && return emptyMCinterval(T)

if zero(T) a
a.lo < zero(T) == a.hi && return MCInterval{T}(-Inf, inv(a.lo))
a.lo == zero(T) < a.hi && return MCInterval{T}((inv(a.hi), Inf))
a.lo < zero(T) < a.hi && return entireinterval(T)
a == zero(a) && return emptyinterval(T)
a.lo < zero(T) < a.hi && return entireMCinterval(T)
a == zero(a) && return emptyMCinterval(T)
end

MCInterval{T}(inv(a.hi), inv(a.lo))
Expand All @@ -119,8 +119,8 @@ end
function /(a::MCInterval{T}, b::MCInterval{T}) where T<:AbstractFloat

S = typeof(a.lo / b.lo)
(isempty(a) || isempty(b)) && return emptyinterval(S)
iszero(b) && return emptyinterval(S)
(isempty(a) || isempty(b)) && return emptyMCinterval(S)
iszero(b) && return emptyMCinterval(S)

if b.lo > zero(T) # b strictly positive

Expand All @@ -142,17 +142,17 @@ function /(a::MCInterval{T}, b::MCInterval{T}) where T<:AbstractFloat

a.lo >= zero(T) && return MCInterval{T}(a.lo/b.hi, Inf)
a.hi <= zero(T) && return MCInterval{T}(-Inf, a.hi/b.hi)
return entireinterval(S)
return entireMCinterval(S)

elseif iszero(b.hi)

a.lo >= zero(T) && return MCInterval{T}(-Inf, a.lo/b.lo)
a.hi <= zero(T) && return MCInterval{T}(a.hi/b.lo, Inf)
return entireinterval(S)
return entireMCinterval(S)

else

return entireinterval(S)
return entireMCinterval(S)

end
end
Expand All @@ -173,15 +173,15 @@ end
function fma(a::MCInterval{T}, b::MCInterval{T}, c::MCInterval{T}) where T
#T = promote_type(eltype(a), eltype(b), eltype(c))

(isempty(a) || isempty(b) || isempty(c)) && return emptyinterval(T)
(isempty(a) || isempty(b) || isempty(c)) && return emptyMCinterval(T)

if isentire(a)
b == zero(b) && return c
return entireinterval(T)
return entireMCinterval(T)

elseif isentire(b)
a == zero(a) && return c
return entireinterval(T)
return entireMCinterval(T)

end

Expand Down Expand Up @@ -225,17 +225,17 @@ sup(a::MCInterval) = a.hi
real(a::MCInterval) = a

function abs(a::MCInterval{T}) where {T<:AbstractFloat}
isempty(a) && return emptyinterval(T)
isempty(a) && return emptyMCinterval(T)
MCInterval{T}(mig(a), mag(a))
end

function min(a::MCInterval{T}, b::MCInterval{T}) where {T<:AbstractFloat}
(isempty(a) || isempty(b)) && return emptyinterval(T)
(isempty(a) || isempty(b)) && return emptyMCinterval(T)
MCInterval{T}( min(a.lo, b.lo), min(a.hi, b.hi))
end

function max(a::MCInterval{T}, b::MCInterval{T}) where {T<:AbstractFloat}
(isempty(a) || isempty(b)) && return emptyinterval(T)
(isempty(a) || isempty(b)) && return emptyMCinterval(T)
MCInterval{T}( max(a.lo, b.lo), max(a.hi, b.hi))
end

Expand All @@ -244,22 +244,22 @@ eps(a::MCInterval) = max(eps(a.lo), eps(a.hi))

## floor, ceil, trunc, sign, roundTiesToEven, roundTiesToAway
function floor(a::MCInterval{T}) where {T<:AbstractFloat}
isempty(a) && return emptyinterval(a)
isempty(a) && return emptyMCinterval(a)
MCInterval{T}(floor(a.lo), floor(a.hi))
end

function ceil(a::MCInterval{T}) where {T<:AbstractFloat}
isempty(a) && return emptyinterval(T)
isempty(a) && return emptyMCinterval(T)
MCInterval{T}(ceil(a.lo), ceil(a.hi))
end

function trunc(a::MCInterval{T}) where {T<:AbstractFloat}
isempty(a) && return emptyinterval(T)
isempty(a) && return emptyMCinterval(T)
MCInterval{T}(trunc(a.lo), trunc(a.hi))
end

function sign(a::MCInterval{T}) where {T<:AbstractFloat}
isempty(a) && return emptyinterval(T)
isempty(a) && return emptyMCinterval(T)
return MCInterval{T}(sign(a.lo), sign(a.hi))
end

Expand Down Expand Up @@ -304,7 +304,7 @@ function radius(a::MCInterval{T}) where {T<:AbstractFloat}
end

function step(x::MCInterval{T}) where {T}
isempty(x) && return emptyinterval(T)
isempty(x) && return emptyMCinterval(T)
xmin::T = ((x.lo)<zero(T)) ? zero(T) : one(T)
xmax::T = ((x.hi)>=zero(T)) ? one(T) : zero(T)
return MCInterval{T}(xmin,xmax)
Expand Down
23 changes: 14 additions & 9 deletions src/IntervalArithmetic/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# multiplication conversion from float to Interval
function *(b::T, a::MCInterval{T}) where {T<:AbstractFloat}
(isempty(a)) && return emptyinterval(T)
(isempty(a)) && return emptyMCinterval(T)
(iszero(a) || iszero(b)) && return MCInterval{T}(zero(T),zero(T))
if b >= zero(T)
a.lo >= zero(T) && return MCInterval{T}(a.lo*b, a.hi*b)
Expand All @@ -42,8 +42,8 @@ end
# division conversion from float to Interval
function /(a::T, b::MCInterval{T}) where {T<:AbstractFloat}

(isempty(b)) && return emptyinterval(T)
iszero(b) && return emptyinterval(T)
(isempty(b)) && return emptyMCinterval(T)
iszero(b) && return emptyMCinterval(T)

if b.lo > zero(T) # b strictly positive
a >= zero(T) && return MCInterval{T}(a/b.hi, a/b.lo)
Expand All @@ -58,13 +58,13 @@ function /(a::T, b::MCInterval{T}) where {T<:AbstractFloat}
if iszero(b.lo)
a >= zero(T) && return MCInterval{T}(a/b.hi, infty(T))
a <= zero(T) && return MCInterval{T}(ninfty(T), a/b.hi)
return entireinterval(T)
return entireMCinterval(T)
elseif iszero(b.hi)
a >= zero(T) && return MCInterval{T}(ninfty(T), a/b.lo)
a <= zero(T) && return MCInterval{T}(a/b.lo, infty(T))
return entireinterval(T)
return entireMCinterval(T)
else
return entireinterval(T)
return entireMCinterval(T)
end
end
end
Expand All @@ -76,7 +76,7 @@ end

# minimization conversion from float to Interval
function min(a::MCInterval{T}, b::T) where {T<:AbstractFloat}
(isempty(a)) && return emptyinterval(T)
(isempty(a)) && return emptyMCinterval(T)
MCInterval{T}( min(a.lo, b), min(a.hi, b))
end
function min(b::T, a::MCInterval{T}) where {T<:AbstractFloat}
Expand All @@ -90,14 +90,19 @@ min(b::S, a::MCInterval{T}) where {S,T<:AbstractFloat} = min(convert(T,b),a)

# maximization conversion from float to Interval
function max(a::MCInterval{T}, b::T) where {T<:AbstractFloat}
(isempty(a)) && return emptyinterval(T)
(isempty(a)) && return emptyMCinterval(T)
MCInterval{T}( max(a.lo, b), max(a.hi, b))
end
function max(b::T, a::MCInterval{T}) where {T<:AbstractFloat}
(isempty(a)) && return emptyinterval(T)
(isempty(a)) && return emptyMCinterval(T)
MCInterval{T}( max(a.lo, b), max(a.hi, b))
end
max(a::MCInterval{T}, b::S) where {S<:AbstractFloat,T<:AbstractFloat} = max(a,convert(T,b))
max(b::S, a::MCInterval{T}) where {S<:AbstractFloat,T<:AbstractFloat} = max(convert(T,b),a)
max(a::MCInterval{T}, b::S) where {S,T<:AbstractFloat} = max(a,convert(T,b))
max(b::S, a::MCInterval{T}) where {S,T<:AbstractFloat} = max(convert(T,b),a)

# nonoverloaded conversion
flttoMCI(x::Float64) = MCInterval{Float64}(x,x)
flttoMCI(x::Float32) = MCInterval{Float32}(x,x)
flttoMCI(x::Float16) = MCInterval{Float16}(x,x)
6 changes: 3 additions & 3 deletions src/IntervalArithmetic/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function ^(a::MCInterval{T}, n::Integer) where {T<:AbstractFloat}
n == 0 && return one(a)
n == 1 && return a
n == 2 && return sqr(a)
n < 0 && a == zero(a) && return emptyinterval(T)
n < 0 && a == zero(a) && return emptyMCinterval(T)

if isodd(n) # odd power
isentire(a) && return a
Expand All @@ -21,7 +21,7 @@ function ^(a::MCInterval{T}, n::Integer) where {T<:AbstractFloat}
a.hi == 0 && return MCInterval{T}(ninfty(T), a.lo^n)
return MCInterval{T}(a.hi^n, a.lo^n)
else
return entireinterval(T)
return entireMCinterval(T)
end
end

Expand Down Expand Up @@ -104,7 +104,7 @@ for f in (:log, :log2, :log10, :log1p)
domain = MCInterval{T}(zero(T), Inf)
a = a domain

(isempty(a) || a.hi zero(T)) && return emptyinterval(a)
(isempty(a) || a.hi zero(T)) && return emptyMCinterval(a)

MCInterval{T}(($f)(a.lo), ($f)(a.hi))

Expand Down
2 changes: 1 addition & 1 deletion src/IntervalArithmetic/hyperbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function atanh(a::MCInterval{T}) where T<:AbstractFloat
res_lo = atanh(a.lo)
res_hi = atanh(a.hi)

(res_lo == res_hi == Inf || res_lo == res_hi == -Inf) && return emptyinterval(T)
(res_lo == res_hi == Inf || res_lo == res_hi == -Inf) && return emptyMCinterval(T)

return MCInterval{T}(res_lo, res_hi)
end
2 changes: 1 addition & 1 deletion src/IntervalArithmetic/set_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function isdisjoint(a::MCInterval{T}, b::MCInterval{T}) where T<:AbstractFloat
end

function intersect(a::MCInterval{T}, b::MCInterval{T}) where T<:AbstractFloat
isdisjoint(a,b) && return emptyinterval(T)
isdisjoint(a,b) && return emptyMCinterval(T)

MCInterval{T}(max(a.lo, b.lo), min(a.hi, b.hi))
end
Expand Down
16 changes: 8 additions & 8 deletions src/IntervalArithmetic/special.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
emptyinterval(::Type{T}) where T<:AbstractFloat = MCInterval{T}(Inf, -Inf)
emptyinterval(x::MCInterval{T}) where T<:AbstractFloat = emptyinterval(T)
const= emptyinterval(Float64)
emptyMCinterval(::Type{T}) where T<:AbstractFloat = MCInterval{T}(Inf, -Inf)
emptyMCinterval(x::MCInterval{T}) where T<:AbstractFloat = emptyMCinterval(T)
#const ∅ = emptyMCinterval(Float64)
isempty(x::MCInterval) = x.lo == Inf && x.hi == -Inf

const= Inf
entireinterval(::Type{T}) where T<:AbstractFloat = MCInterval{T}(-Inf, Inf)
entireinterval(x::MCInterval{T}) where T<:AbstractFloat = entireinterval(T)
entireMCinterval(::Type{T}) where T<:AbstractFloat = MCInterval{T}(-Inf, Inf)
entireMCinterval(x::MCInterval{T}) where T<:AbstractFloat = entireMCinterval(T)
isentire(x::MCInterval) = x.lo == -Inf && x.hi == Inf
isunbounded(x::MCInterval) = x.lo == -Inf || x.hi == Inf

Expand All @@ -16,6 +16,6 @@ Base.iszero(x::MCInterval) = iszero(x.lo) && iszero(x.hi)
const float_interval_pi64 = MCInterval(Float64(pi)) # does not change
const float_interval_pi32 = MCInterval(Float32(pi))
const float_interval_pi16 = MCInterval(Float16(pi))
pi_interval(::Type{Float64}) = float_interval_pi64
pi_interval(::Type{Float32}) = float_interval_pi32
pi_interval(::Type{Float16}) = float_interval_pi16
pi_MCinterval(::Type{Float64}) = float_interval_pi64
pi_MCinterval(::Type{Float32}) = float_interval_pi32
pi_MCinterval(::Type{Float16}) = float_interval_pi16
Loading

0 comments on commit 9abc286

Please sign in to comment.