Skip to content

Commit 9330dbd

Browse files
authored
Fix to inverse of negative MC object (#70)
-Inverse of a negative-domain MC object now returns the negative inverse of the negated input. -Add a test for inversion where the domain is negative and the cv/cc relaxations are not identical.
1 parent dbf57e3 commit 9330dbd

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "McCormick"
22
uuid = "53c679d3-6890-5091-8386-c291e8c8aaa1"
33
authors = ["Matthew Wilhelm <[email protected]>"]
4-
version = "0.13.8"
4+
version = "0.13.9"
55

66
[deps]
77
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"

src/forward_operators/power.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ end
260260
return MC{N,Diff}(cv, cc, y, cv_grad, cc_grad, x.cnst)
261261
end
262262

263-
# neg_powneg_odd computes the McComrick relaxation of x^c where x < 0.0 and c is even
263+
# neg_powneg_even computes the McComrick relaxation of x^c where x < 0.0 and c is even
264264
@inline function neg_powneg_even(x::MC{N,T}, c::Z, y::Interval{Float64}) where {N, Z<:Integer, T<:Union{NS,MV}}
265265
xL = x.Intv.lo
266266
xU = x.Intv.hi
@@ -429,7 +429,7 @@ end
429429
return nan(MC{N,T})
430430
end
431431
if x.Intv.hi < 0.0
432-
x = pos_odd(x, -1, y)
432+
x = -inv1(-x, -y)
433433
else x.Intv.lo > 0.0
434434
x = inv1(x, y)
435435
end

test/forward_mccormick.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,18 @@ end
12951295
@test isapprox(out.Intv.lo,-1.33333333,atol=1E-6)
12961296
@test isapprox(out.Intv.hi,-0.39999999999999997,atol=1E-6)
12971297

1298+
X = MC{2,NS}(3.0,3.0,Interval{Float64}(2.0,4.0), seed_gradient(1,Val(2)),seed_gradient(1,Val(2)),false)
1299+
Y = MC{2,NS}(-5.0,-3.0,Interval{Float64}(-5.0,-3.0), seed_gradient(2,Val(2)), seed_gradient(2,Val(2)),false)
1300+
out = X/Y
1301+
@test isapprox(out.cc, -0.6000000000000001,atol=1E-6)
1302+
@test isapprox(out.cv, -0.9999999999999998, atol=1E-6)
1303+
@test isapprox(out.cc_grad[1], -0.19999999999999998, atol=1E-6)
1304+
@test isapprox(out.cc_grad[2], -0.08,atol=1E-6)
1305+
@test isapprox(out.cv_grad[1], -0.33333333333333337, atol=1E-6)
1306+
@test isapprox(out.cv_grad[2], -0.13333333333333333, atol=1E-6)
1307+
@test isapprox(out.Intv.lo, -1.3333333333333335,atol=1E-6)
1308+
@test isapprox(out.Intv.hi, -0.39999999999999997,atol=1E-6)
1309+
12981310
x1a = MC{2,MV}(1.1, 2.3, Interval(0.1,3.3), seed_gradient(2,Val(2)), seed_gradient(2,Val(2)),false)
12991311
x2a = MC{2,MV}(2.1, 3.3, Interval(1.1,4.3), seed_gradient(2,Val(2)), seed_gradient(2,Val(2)),false)
13001312

0 commit comments

Comments
 (0)