JuliaIntervals / IntervalContractors.jl
Showing 4 of 14 files from the diff.
src/trig.jl changed.
Newly tracked file
src/decorated.jl created.

@@ -37,10 +37,17 @@
 37 37 38 38 # Reverse function for sin; does not alter y 39 39 """ 40 -  sin_rev(y::Interval, x::Interval) 40 +  sin_rev(c::Interval[, x::Interval]) 41 41 42 - Reverse function for sin: 43 - - find the subset of x such that y = \\sin(x) for the given y. 42 + Reverse sine. Calculates the preimage of a = sin(x). If x is not provided, then 43 + byt default [-∞, ∞] is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic. 44 + 45 + ### Output 46 + 47 + The pair (c, x_new) where 48 + 49 + - c is unchanged 50 + - x_new is the interval hull of the set {x ∈ b : sin(x) ∈ a} 44 51 """ 45 52 function sin_rev(y::Interval, x::Interval) 46 53
@@ -90,10 +97,17 @@
 90 97 91 98 # Reverse function for cos; does not alter y 92 99 """ 93 -  cos_rev(y::Interval, x::Interval) 100 +  cos_rev(c::Interval[, x::Interval]) 101 + 102 + Reverse cosine. Calculates the preimage of a = cos(x). If x is not provided, then 103 + byt default [-∞, ∞] is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic. 104 + 105 + ### Output 94 106 95 - Reverse function for cos: 96 - - find the subset of x such that y = \\cos(x) for the given y. 107 + The pair (c, x_new) where 108 + 109 + - c is unchanged 110 + - x_new is the interval hull of the set {x ∈ b : cos(x) ∈ a} 97 111 """ 98 112 function cos_rev(y::Interval, x::Interval) 99 113
@@ -128,10 +142,17 @@
 128 142 tan!(X::IntervalBox) = periodise(tan_main, Interval{Float64}(π))(X) 129 143 130 144 """ 131 -  tan_rev(y::Interval, x::Interval) 145 +  tan_rev(c::Interval[, x::Interval]) 146 + 147 + Reverse tangent. Calculates the preimage of a = tan(x). If x is not provided, then 148 + byt default [-∞, ∞] is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic. 149 + 150 + ### Output 151 + 152 + The pair (c, x_new) where 132 153 133 - Reverse function for tan: 134 - - find the subset of x such that y = \\tan(x) for the given y. 154 + - c is unchanged 155 + - x_new is the interval hull of the set {x ∈ b : tan(x) ∈ a} 135 156 """ 136 157 function tan_rev(y::Interval, x::Interval) 137 158

@@ -1,6 +1,16 @@
 1 1 2 2 """ 3 - Reverse plus 3 +  plus_rev(a::Interval, b::Interval[, c::Interval]) 4 + 5 + Reverse addition. Calculates the preimage of a = b + c for b and c. 6 + 7 + ### Output 8 + 9 + The triplet (a, b_new, c_new) where 10 + 11 + - a remains unchanged 12 + - b_new is the interval hull of the set {x ∈ b : ∃ y ∈ c, x + y ∈ a} 13 + - c_new is the interval hull of the set {y ∈ c : ∃ x ∈ b, x + y ∈ a} 4 14 """ 5 15 function plus_rev(a::Interval, b::Interval, c::Interval) # a = b + c 6 16  # a = a ∩ (b + c) # add this line for plus contractor (as opposed to reverse function)
@@ -13,7 +23,17 @@
 13 23 plus_rev(a,b,c) = plus_rev(promote(a,b,c)...) 14 24 15 25 """ 16 - Reverse minus 26 +  minus_rev(a::Interval, b::Interval[, c::Interval]) 27 + 28 + Reverse subtraction. Calculates the preimage of a = b - c for b and c. 29 + 30 + ### Output 31 + 32 + The triplet (a, b_new, c_new) where 33 + 34 + - a remains unchanged 35 + - b_new is the interval hull of the set {x ∈ b : ∃ y ∈ c, x - y ∈ a} 36 + - c_new is the interval hull of the set {y ∈ c : ∃ x ∈ b, x - y ∈ a} 17 37 """ 18 38 function minus_rev(a::Interval, b::Interval, c::Interval) # a = b - c 19 39
@@ -76,7 +96,16 @@
 76 96 div_rev(a,b,c) = div_rev(promote(a,b,c)...) 77 97 78 98 """ 79 - Reverse inverse 99 +  inv_rev(a::Interval, b::Interval) 100 + 101 + Reverse inverse. Calculates the interval hull of the preimage of a = b⁻¹ 102 + 103 + ### Output 104 + 105 + Pair (a, b_new) where 106 + 107 + - a is unchanged 108 + - b_new is the interval hull of the set {x ∈ b : x⁻¹ ∈ a} 80 109 """ 81 110 function inv_rev(a::Interval, b::Interval) # a = inv(b) 82 111
@@ -88,9 +117,24 @@
 88 117 inv_rev(a,b) = inv_rev(promote(a,b)...) 89 118 90 119 """ 91 - Reverse power 120 +  power_rev(a::Interval, b::Interval, n::Integer) 121 + 122 + Reverse power. Calculates the preimage of a = bⁿ. See section 10.5.4 of the 123 + IEEE 1788-2015 standard for interval arithmetic. 124 + 125 + ### Output 126 + 127 + The triplet (a, b_new, n) where 128 + 129 + - a and n are unchanged 130 + - b_new is the interval hull of the set {x ∈ b : xⁿ ∈ a} 92 131 """ 93 - function power_rev(a::Interval, b::Interval, n::Integer) # a = b^n, log(a) = n.log(b), b = a^(1/n) 132 + function power_rev(a::Interval{T}, b::Interval{T}, n::Integer) where T # a = b^n, log(a) = n.log(b), b = a^(1/n) 133 + 134 +  if iszero(n) 135 +  1 ∈ a && return (a, entireinterval(T) ∩ b, n) 136 +  return (a, emptyinterval(T), n) 137 +  end 94 138 95 139  if n == 2 # a = b^2 96 140  root = √a
@@ -117,6 +161,7 @@
 117 161  return (a, b, n) 118 162 end 119 163 164 + power_rev(a::Interval{T}, n::Integer) where T = power_rev(a, entireinterval(T), n) 120 165 121 166 function power_rev(a::Interval, b::Interval, c::Interval) # a = b^c 122 167
@@ -135,7 +180,16 @@
 135 180 136 181 137 182 """ 138 - Reverse square root 183 +  sqrt_rev(a::Interval, b::Interval) 184 + 185 + Reverse square root. Calculates the preimage of a = √b. 186 + 187 + ### Output 188 + 189 + The pair (a, b_new) where 190 + 191 + - a is unchanged 192 + - b_new is the interval hull of the set {x ∈ b : √x ∈ a} 139 193 """ 140 194 function sqrt_rev(a::Interval, b::Interval) # a = sqrt(b) 141 195
@@ -150,7 +204,17 @@
 150 204 # IEEE-1788 style 151 205 152 206 """ 153 - Reverse sqr 207 +  sqrt_rev(c::Interval[, x::Interval]) 208 + 209 + Reverse square. Calculates the preimage of a = x². If x is not provided, then 210 + byt default [-∞, ∞] is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic. 211 + 212 + ### Output 213 + 214 + The pair (c, x_new) where 215 + 216 + - c is unchanged 217 + - x_new is the interval hull of the set {x ∈ b : x² ∈ a} 154 218 """ 155 219 function sqr_rev(c, x) # c = x^2; refine x 156 220
@@ -162,10 +226,18 @@
 162 226  return (c, hull(x1, x2)) 163 227 end 164 228 165 - sqr_rev(c) = sqr_rev(c, -∞..∞) 166 - 167 229 """ 168 - Reverse abs 230 +  abs_rev(c::Interval[, x::Interval]) 231 + 232 + Reverse absolute value. Calculates the preimage of a = |x|. If x is not provided, then 233 + byt default [-∞, ∞] is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic. 234 + 235 + ### Output 236 + 237 + The pair (c, x_new) where 238 + 239 + - c is unchanged 240 + - x_new is the interval hull of the set {x ∈ b : |x| ∈ a} 169 241 """ 170 242 function abs_rev(y, x) # y = abs(x); refine x 171 243
@@ -193,22 +265,83 @@
 193 265 ## IEEE-1788 versions: 194 266 195 267 """ 196 - According to the IEEE-1788 standard: 268 +  mul_rev_IEEE1788(b::Interval, c::Interval[, x::Interval]) 269 + 270 + Reverse multiplication. Computes the preimage of c=x * b with respect to x. If x is not provided, 271 + then byt default [-∞, ∞] is used.. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic. 197 272 198 - - ∘_rev1(b, c, x) is the subset of x such that x ∘ b is defined and in c; 199 - - ∘_rev2(a, c, x) is the subset of x such that a ∘ x is defined and in c 273 + ### Output 200 274 201 - When ∘ is commutative, these agree and we write ∘_rev(b, c, x). 275 + - x_new the interval hull of the set {t ∈ x : ∃ y ∈ b, t*y ∈ c} 202 276 """ 277 + mul_rev_IEEE1788(b, c, x) = mul_rev(c, x, b)[2] 203 278 204 - function mul_rev_IEEE1788(b, c, x) # c = b*x 205 -  return x ∩ (c / b) 206 - end 279 + """ 280 +  pow_rev1(b::Interval, c::Interval[, x::Interval]) 207 281 282 + Reverse power 1. Computes the preimage of c=xᵇ with respect to x. If x is not provided, 283 + then byt default [-∞, ∞] is used.. See section 10.5.4 of the 284 + IEEE 1788-2015 standard for interval arithmetic. 285 + 286 + ### Output 287 + 288 + - x_new the interval hull of the set {t ∈ x : ∃ y ∈ b, tʸ ∈ c} 289 + """ 208 290 function pow_rev1(b, c, x) # c = x^b 209 291  return x ∩ c^(1/b) # replace by 1//b 210 292 end 211 293 294 + """ 295 +  pow_rev2(b::Interval, c::Interval[, x::Interval]) 296 + 297 + Reverse power 2. Computes the preimage of c = aˣ with respect to x. If x is not provided, then 298 + byt default [-∞, ∞] is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic. 299 + 300 + ### Output 301 + 302 + - x_new the interval hull of the set {t ∈ x : ∃ y ∈ b, tʸ ∈ c} 303 + """ 212 304 function pow_rev2(a, c, x) # c = a^x 213 -  return x ∩ (log(c) / lob(a)) 305 +  return x ∩ (log(c) / log(a)) 306 + end 307 + 308 + """ 309 +  mul_rev_to_pair(b::Interval, c::Interval) 310 + 311 + Computes the division c/b, but returns a pair of intervals instead of a single interval. 312 + If the set corresponding to c/b is composed by two disjoint intervals, then it returns the 313 + two intervals. If c/b is a single or empty interval, then the second interval in the pair 314 + is set to empty. See section 10.5.5 of the IEEE 1788-2015 standard for interval arithmetic. 315 + 316 + ### Example 317 + 318 + jldoctest 319 + julia> mul_rev_to_pair(-1..1, 1..2) 320 + ([-∞, -1], [1, ∞]) 321 + 322 + julia> mul_rev_to_pair(1..2, 3..4) 323 + ([1.5, 4], ∅) 324 +  325 + 326 + """ 327 + mul_rev_to_pair(b::Interval, c::Interval) = extended_div(c, b) 328 + 329 + function mul_rev_to_pair(b::DecoratedInterval{T}, c::DecoratedInterval{T}) where T 330 +  (isnai(b) || isnai(c)) && return (nai(T), nai(T)) 331 + 332 +  0 ∉ b && return (c/b, DecoratedInterval(emptyinterval(T), trv)) 333 + 334 +  x1, x2 = extended_div(interval(c), interval(b)) 335 +  return (DecoratedInterval(x1, trv), DecoratedInterval(x2, trv)) 336 + end 337 + 338 + mul_rev_to_pair(b::Interval, c::Interval) = extended_div(c, b) 339 + 340 + function mul_rev_to_pair(b::DecoratedInterval{T}, c::DecoratedInterval{T}) where T 341 +  (isnai(b) || isnai(c)) && return (nai(T), nai(T)) 342 + 343 +  0 ∉ b && return (c/b, DecoratedInterval(emptyinterval(T), trv)) 344 + 345 +  x1, x2 = extended_div(interval(c), interval(b)) 346 +  return (DecoratedInterval(x1, trv), DecoratedInterval(x2, trv)) 214 347 end

@@ -0,0 +1,35 @@
 1 + entiredecorated(T) = DecoratedInterval(entireinterval(T)) 2 + 3 + for op in (:sqr_rev, :abs_rev, :sin_rev, :cos_rev, :tan_rev, :cosh_rev, :sinh_rev, :tanh_rev) 4 +  @eval begin  5 +  function $op(a::DecoratedInterval{T}, x::DecoratedInterval{T}) where T  6 +  ( isnai(a) || isnai(x) ) && return nai(T) 7 +  bare =$op(interval(a), interval(x)) 8 +  return (DecoratedInterval(bare[1], trv), DecoratedInterval(bare[2], trv)) 9 +  end 10 +  end  11 +  @eval $op(a::Interval{T}) where T =$op(a, entireinterval(T)) 12 +  @eval $op(a::DecoratedInterval{T}) where T =$op(a, entiredecorated(T))  13 + end 14 + 15 + function power_rev(a::DecoratedInterval{T}, x::DecoratedInterval{T}, n::Integer) where T 16 +  ( isnai(a) || isnai(x) ) && return nai(T) 17 +  bare = power_rev(interval(a), interval(x), n) 18 +  return (DecoratedInterval(bare[1], trv), DecoratedInterval(bare[2], trv), n) 19 + end 20 + 21 + power_rev(a::DecoratedInterval{T}, n::Integer) where T = power_rev(a, entiredecorated(T), n) 22 + 23 + for op in (:mul_rev_IEEE1788, :pow_rev1, :pow_rev2) 24 +  @eval begin 25 +  function $op(b::DecoratedInterval{T}, c::DecoratedInterval{T}, x::DecoratedInterval{T}) where T 26 +  (isnai(b) || isnai(c) || isnai(x) ) && return nai(T) 27 +  bare =$op(interval(b), interval(c), interval(x)) 28 +  return DecoratedInterval(bare, trv) 29 +  end 30 +  end 31 + 32 +  @eval $op(a::Interval{T}, b::Interval{T}) where T =$op(a, b, entireinterval(T)) 33 +  @eval $op(a::DecoratedInterval{T}, b::DecoratedInterval{T}) where T =$op(a, b, entiredecorated(T)) 34 + 35 + end

@@ -1,5 +1,15 @@
 1 1 """ 2 - Reverse function for sinh. 2 +  sinh_rev(c::Interval[, x::Interval]) 3 + 4 + Reverse hyperbolic sine. Calculates the preimage of a = sinh(x). If x is not provided, then 5 + byt default [-∞, ∞] is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic. 6 + 7 + ### Output 8 + 9 + The pair (c, x_new) where 10 + 11 + - c is unchanged 12 + - x_new is the interval hull of the set {x ∈ b : sinh(x) ∈ a} 3 13 """ 4 14 function sinh_rev(y::Interval, x::Interval) 5 15  x = x ∩ asinh(y)
@@ -8,17 +18,37 @@
 8 18 end 9 19 10 20 """ 11 - Reverse function for cosh. 21 +  cosh_rev(c::Interval[, x::Interval]) 22 + 23 + Reverse square root. Calculates the preimage of a = cosh(x). If x is not provided, then 24 + byt default [-∞, ∞] is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic. 25 + 26 + ### Output 27 + 28 + The pair (c, x_new) where 29 + 30 + - c is unchanged 31 + - x_new is the interval hull of the set {x ∈ b : cosh(x) ∈ a} 12 32 """ 13 33 function cosh_rev(y::Interval,x::Interval) 14 34  y_new = y ∩ Interval(1.,∞) 15 -  x = x ∩ acosh(y) 35 +  x = (x ∩ acosh(y)) ∪ (x ∩ -acosh(y)) 16 36 17 37  return y_new, x 18 38 end 19 39 20 40 """ 21 - Reverse function for tanh. 41 +  tanh_rev(c::Interval[, x::Interval]) 42 + 43 + Reverse square root. Calculates the preimage of a = tanh(x). If x is not provided, then 44 + byt default [-∞, ∞] is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic. 45 + 46 + ### Output 47 + 48 + The pair (c, x_new) where 49 + 50 + - c is unchanged 51 + - x_new is the interval hull of the set {x ∈ b : tanh(x) ∈ a} 22 52 """ 23 53 function tanh_rev(y::Interval,x::Interval) 24 54  y_new = y ∩ Interval(-1.,1.)