Skip to content

Commit 26074bd

Browse files
fix: fix denominator checking in HomotopyContinuationExt
1 parent 213246e commit 26074bd

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

ext/MTKHomotopyContinuationExt.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,18 @@ function MTK.HomotopyContinuationProblem(
196196
error("Equation $eq is not a polynomial in the unknowns. See warnings for further details.")
197197
end
198198
num, den = handle_rational_polynomials(eq.rhs - eq.lhs, dvs)
199-
push!(denoms, den)
199+
200+
# make factors different elements, otherwise the nonzero factors artificially
201+
# inflate the error of the zero factor.
202+
if iscall(den) && operation(den) == *
203+
for arg in arguments(den)
204+
# ignore constant factors
205+
symbolic_type(arg) == NotSymbolic() && continue
206+
push!(denoms, abs(arg))
207+
end
208+
elseif symbolic_type(den) != NotSymbolic()
209+
push!(denoms, abs(den))
210+
end
200211
return 0 ~ num
201212
end
202213

@@ -232,7 +243,7 @@ Extra keyword arguments:
232243
the denominator to be below `denominator_abstol` will be discarded.
233244
"""
234245
function CommonSolve.solve(prob::MTK.HomotopyContinuationProblem,
235-
alg = nothing; show_progress = false, denominator_abstol = 1e-8, kwargs...)
246+
alg = nothing; show_progress = false, denominator_abstol = 1e-7, kwargs...)
236247
sol = HomotopyContinuation.solve(
237248
prob.homotopy_continuation_system; show_progress, kwargs...)
238249
realsols = HomotopyContinuation.results(sol; only_real = true)

test/extensions/homotopy_continuation.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ end
9898
@test sol[x] 1.0
9999
p = parameter_values(prob)
100100
for invalid in [2.0, 3.0]
101-
@test prob.denominator([invalid], p)[1] <= 1e-8
101+
for err in [-9e-8, 0, 9e-8]
102+
@test any(<=(1e-7), prob.denominator([invalid + err, 2.0], p))
103+
end
102104
end
103105

104106
@named sys = NonlinearSystem(
@@ -115,14 +117,18 @@ end
115117
disallowed_y = [7, 5, 4]
116118
@test all(!isapprox(sol[x]; atol = 1e-8), disallowed_x)
117119
@test all(!isapprox(sol[y]; atol = 1e-8), disallowed_y)
118-
@test sol[x^2 - 4x + y] >= 1e-8
120+
@test abs(sol[x^2 - 4x + y]) >= 1e-8
119121

120122
p = parameter_values(prob)
121123
for val in disallowed_x
122-
@test any(<=(1e-8), prob.denominator([val, 2.0], p))
124+
for err in [-9e-8, 0, 9e-8]
125+
@test any(<=(1e-7), prob.denominator([val + err, 2.0], p))
126+
end
123127
end
124128
for val in disallowed_y
125-
@test any(<=(1e-8), prob.denominator([2.0, val], p))
129+
for err in [-9e-8, 0, 9e-8]
130+
@test any(<=(1e-7), prob.denominator([2.0, val + err], p))
131+
end
126132
end
127133
@test prob.denominator([2.0, 4.0], p)[1] <= 1e-8
128134
end

0 commit comments

Comments
 (0)