Skip to content

Commit a55dcce

Browse files
authored
Merge pull request #593 from JuliaHomotopyContinuation/nid_bugfixes
NID bug fixes
2 parents 5b5221b + 5db3bbd commit a55dcce

File tree

3 files changed

+53
-15
lines changed

3 files changed

+53
-15
lines changed

docs/src/witness_sets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ NumericalIrreducibleDecomposition
4242
```
4343

4444
```@docs
45-
n_components
45+
ncomponents
4646
witness_sets
4747
degrees
4848
```

src/numerical_irreducible_decomposition.jl

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export NumericalIrreducibleDecomposition,
44
regeneration,
55
witness_sets,
66
decompose,
7+
ncomponents,
78
n_components,
89
seed
910

@@ -104,6 +105,7 @@ function update_progress!(progress::WitnessSetsProgress, W::Union{WitnessPoints,
104105
showvalues = showvalues(progress),
105106
)
106107
end
108+
update_progress!(progress::Union{Nothing,WitnessSetsProgress}, W::Nothing) = nothing
107109
update_progress!(progress::Nothing) = nothing
108110
finish_progress!(progress::Nothing) = nothing
109111
function finish_progress!(progress::WitnessSetsProgress)
@@ -147,7 +149,7 @@ This is the core routine of the regeneration algorithm. It intersects a set of [
147149
"""
148150
function intersect_with_hypersurface!(
149151
W::WitnessPoints{T1,T2,Vector{ComplexF64}},
150-
X::WitnessPoints{T3,T4,Vector{ComplexF64}},
152+
X::Union{WitnessPoints{T3,T4,Vector{ComplexF64}},Nothing},
151153
F::AS,
152154
H::WitnessSet{T5,T6,Vector{ComplexF64}},
153155
u::Variable,
@@ -174,6 +176,11 @@ function intersect_with_hypersurface!(
174176
deleteat!(P, m)
175177
update_progress!(progress, W)
176178

179+
if isnothing(X)
180+
return nothing
181+
end
182+
183+
177184
# Step 2:
178185
# the points in P_next are used as starting points for a homotopy.
179186
# where u^d-1 (u is the extra variable in u-regeneration) is deformed into g
@@ -203,10 +210,12 @@ function intersect_with_hypersurface!(
203210

204211
# here comes the loop for tracking
205212
l_start = length(start)
213+
206214
for (i, s) in enumerate(start)
207215
p = s[1]
208216
p[end] = s[2] # the last entry of s[1] is zero. we replace it with a d-th root of unity.
209217

218+
210219
res = track(tracker, p, 1)
211220
if is_success(res) && is_finite(res) && is_nonsingular(res)
212221
new = copy(tracker.state.solution)
@@ -217,6 +226,7 @@ function intersect_with_hypersurface!(
217226
end
218227

219228

229+
220230
nothing
221231
end
222232

@@ -330,6 +340,7 @@ function is_contained!(
330340
end
331341
# check if x is among the points in U
332342
_, added = add!(U, x, 0)
343+
333344
if added
334345
return false
335346
else
@@ -537,11 +548,14 @@ function regeneration!(
537548
# we have already intersected X ∩ Hᵢ.
538549
update_progress!(progress, true)
539550
for (k, W) in reverse(E) # k = codim(W) for W in Ws
540-
if k < min(i, n)
541-
X = out[k+1]
551+
if k < i
552+
if k < n
553+
X = out[k+1]
554+
else
555+
X = nothing
556+
end
542557
# here is the intersection step
543-
# the next witness superset X is also passed to this function,
544-
# because we add points that do not belong to W∩Hᵢ to X.
558+
# if k < min(i,n), the next witness superset X is also passed to this function, because we add points that do not belong to W∩Hᵢ to X.
545559
# at this point the equation for W is f[1:(i-1)]
546560
intersect_with_hypersurface!(
547561
W,
@@ -559,7 +573,10 @@ function regeneration!(
559573
end
560574
end
561575

576+
577+
562578
Fᵢ = fixed(System(f[1:i], variables = vars), compile = false)
579+
563580
# after the first loop that takes care of intersecting with Hᵢ
564581
# we now check if we have added points that are already contained in
565582
# witness sets of higher dimension.
@@ -1110,13 +1127,13 @@ witness_sets(N::NumericalIrreducibleDecomposition, dim::Int) = witness_sets(N, [
11101127
seed(N::NumericalIrreducibleDecomposition) = N.seed
11111128

11121129
"""
1113-
n_components(N::NumericalIrreducibleDecomposition;
1130+
ncomponents(N::NumericalIrreducibleDecomposition;
11141131
dims::Union{Vector{Int},Nothing} = nothing)
11151132
11161133
Returns the total number of components in `N`.
11171134
`dims` specifies the dimensions that should be considered.
11181135
"""
1119-
function n_components(
1136+
function ncomponents(
11201137
N::NumericalIrreducibleDecomposition;
11211138
dims::Union{Vector{Int},Nothing} = nothing,
11221139
)
@@ -1134,7 +1151,9 @@ function n_components(
11341151

11351152
out
11361153
end
1137-
n_components(N::NumericalIrreducibleDecomposition, dim::Int) = n_components(N, dims = [dim])
1154+
ncomponents(N::NumericalIrreducibleDecomposition, dim::Int) = ncomponents(N; dims = [dim])
1155+
n_components(N; dims = nothing) = ncomponents(N; dims = dims)
1156+
n_components(N, dim) = ncomponents(N; dims = [dim])
11381157

11391158
"""
11401159

test/nid_test.jl

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
@test isa(N3, NumericalIrreducibleDecomposition)
5656

5757
# number of components
58+
@test ncomponents(N3) == 4
59+
@test ncomponents(N3, dims = [1, 2]) == 3
60+
@test ncomponents(N3, 1) == 2
5861
@test n_components(N3) == 4
5962
@test n_components(N3, dims = [1, 2]) == 3
6063
@test n_components(N3, 1) == 2
@@ -67,7 +70,7 @@
6770

6871
N_Hyp = numerical_irreducible_decomposition(Hyp)
6972
@test degrees(N_Hyp) == Dict(3 => [5])
70-
@test n_components(N_Hyp) == 1
73+
@test ncomponents(N_Hyp) == 1
7174
end
7275

7376
@testset "Curve of degree 6" begin
@@ -78,7 +81,7 @@
7881

7982
N_Curve = nid(Curve)
8083
@test degrees(N_Curve) == Dict(1 => [6])
81-
@test n_components(N_Curve) == 1
84+
@test ncomponents(N_Curve) == 1
8285
end
8386

8487
@testset "Overdetermined Test" begin
@@ -88,7 +91,7 @@
8891

8992
N_TwistedCubicSphere = nid(TwistedCubicSphere)
9093
@test degrees(N_TwistedCubicSphere) == Dict(0 => [3])
91-
@test n_components(N_TwistedCubicSphere) == 1
94+
@test ncomponents(N_TwistedCubicSphere) == 1
9295
end
9396

9497
@testset "Three Lines" begin
@@ -101,7 +104,7 @@
101104

102105
N_ThreeLines = nid(ThreeLines)
103106
@test degrees(N_ThreeLines) == Dict(1 => [1; 1; 1])
104-
@test n_components(N_ThreeLines) == 3
107+
@test ncomponents(N_ThreeLines) == 3
105108
end
106109

107110
@testset "Bricard6R" begin
@@ -198,7 +201,7 @@
198201

199202
N_Bricard6R = nid(Bricard6R)
200203
@test degrees(N_Bricard6R) == Dict(1 => [8])
201-
@test n_components(N_Bricard6R) == 1
204+
@test ncomponents(N_Bricard6R) == 1
202205
end
203206

204207
@testset "ACR" begin
@@ -242,6 +245,22 @@
242245
end
243246

244247

248+
@testset "Union of a sphere, a line, and a point" begin
249+
@var x, y, z
250+
251+
S = [x^2 + y^2 + z^2 - 1] #The sphere
252+
L = [2 * x - z, 2 * y - z] #The line (t,t,2t)
253+
P = [x + y + 2 * z - 4, y - z, x - z] #The point (1,1,1)
254+
255+
F = System([s * l * p for s in S for l in L for p in P])
256+
257+
seed = rand(UInt32)
258+
NID = numerical_irreducible_decomposition(F; seed = 0x7a4845b9)
259+
260+
@test ncomponents(NID, 0) == 1
261+
@test degrees(NID)[0] == [1]
262+
end
263+
245264
# @testset "426" begin
246265
# ### Example thanks to Julian Vill
247266
# @var a, b, c, d, e
@@ -304,7 +323,7 @@
304323
# endgame_options = EndgameOptions(; sing_accuracy = 1e-10),
305324
# )
306325

307-
# @test n_components(N) == 1
326+
# @test ncomponents(N) == 1
308327
# @test degrees(N) == Dict(2 => [426])
309328
# end
310329
end

0 commit comments

Comments
 (0)