Try switching to compiled system

This commit is contained in:
Aaron Fenyes 2024-02-10 00:59:50 -05:00
parent 34358a8728
commit becefe0c47
1 changed files with 47 additions and 60 deletions

View File

@ -263,67 +263,54 @@ println("Two points on a sphere: ", freedom, " degrees of freedom")
# --- test rational cut --- # --- test rational cut ---
cut_coeffs = [ coordring = base_ring(ideal_ab_s)
1 1 1 0 0 0 1 1 1 1 1; vbls = Variable.(symbols(coordring))
2 1 1 0 0 0 1 2 1 1 1; ##cut_system = CompiledSystem(System([eqns_ab_s; cut], variables = vbls))
1 2 0 0 0 0 1 1 0 1 2 ##cut_result = HomotopyContinuation.solve(cut_system)
] ##println("non-singular solutions:")
cut = [ ##for soln in solutions(cut_result)
sum(vcat(cf[1:3] .* a.coords, cf[4:6] .* b.coords, cf[7:end] .* (s.coords - [0, 0, 0, 0, 1]))) ## display(soln)
for cf in eachrow(cut_coeffs) ##end
] ##println("singular solutions:")
cut_ideal_ab_s = Generic.Ideal(base_ring(ideal_ab_s), [gens(ideal_ab_s); cut]) ##for sing in singular(cut_result)
cut_freedom = Engine.dimension(cut_ideal_ab_s) ## display(sing.solution)
println("Two points on a sphere, after cut: ", cut_freedom, " degrees of freedom") ##end
if cut_freedom == 0
coordring = base_ring(ideal_ab_s)
vbls = Variable.(symbols(coordring))
cut_system = System([eqns_ab_s; cut], variables = vbls)
##cut_result = HomotopyContinuation.solve(cut_system)
##println("non-singular solutions:")
##for soln in solutions(cut_result)
## display(soln)
##end
##println("singular solutions:")
##for sing in singular(cut_result)
## display(sing.solution)
##end
# test a random witness set # test a random witness set
max_slope = 2 system = CompiledSystem(System(eqns_ab_s, variables = vbls))
binom = Binomial(2max_slope, 1/2) max_slope = 2
Random.seed!(6071) binom = Binomial(2max_slope, 1/2)
samples = [] Random.seed!(6071)
for _ in 1:3 samples = []
cut_matrix = rand(binom, freedom, length(gens(coordring))) .- max_slope for _ in 1:3
##cut_matrix = [ cut_matrix = rand(binom, freedom, length(gens(coordring))) .- max_slope
## 1 1 1 1 0 1 1 0 1 1 0; ##cut_matrix = [
## 1 2 1 2 0 1 1 0 1 1 0; ## 1 1 1 1 0 1 1 0 1 1 0;
## 1 1 0 1 0 1 2 0 2 0 0 ## 1 2 1 2 0 1 1 0 1 1 0;
##] ## 1 1 0 1 0 1 2 0 2 0 0
sph_z_ind = indexin([sph.coords[5] for sph in ctx.spheres], gens(coordring)) ##]
cut_offset = [sum(cf[sph_z_ind]) for cf in eachrow(cut_matrix)] sph_z_ind = indexin([sph.coords[5] for sph in ctx.spheres], gens(coordring))
println("sphere z variables: ", vbls[sph_z_ind]) cut_offset = [sum(cf[sph_z_ind]) for cf in eachrow(cut_matrix)]
display(cut_matrix) println("sphere z variables: ", vbls[sph_z_ind])
display(cut_offset) display(cut_matrix)
cut_subspace = LinearSubspace(cut_matrix, cut_offset) display(cut_offset)
wtns = witness_set(System(eqns_ab_s, variables = vbls), cut_subspace) cut_subspace = LinearSubspace(cut_matrix, cut_offset)
append!(samples, solution.(filter(isreal, results(wtns)))) wtns = witness_set(system, cut_subspace)
end append!(samples, solution.(filter(isreal, results(wtns))))
println("witness solutions:") end
for soln in samples println("witness solutions:")
display([vbls round.(soln, digits = 6)]) for soln in samples
k_sq = abs2(soln[1]) display([vbls round.(soln, digits = 6)])
if abs2(soln[end-2]) > 1e-12 k_sq = abs2(soln[1])
if k_sq < 1e-12 if abs2(soln[end-2]) > 1e-12
println("center at infinity: z coordinates $(round(soln[end], digits = 6)) and $(round(soln[end-1], digits = 6))}") if k_sq < 1e-12
else println("center at infinity: z coordinates $(round(soln[end], digits = 6)) and $(round(soln[end-1], digits = 6))}")
sum_sq = soln[4]^2 + soln[7]^2 + soln[end-2]^2 / k_sq
println("center on z axis: r² = $(round(1/k_sq, digits = 6)), x² + y² + h² = $(round(sum_sq, digits = 6))")
end
else else
sum_sq = sum(soln[[4, 7, 10]] .^ 2) sum_sq = soln[4]^2 + soln[7]^2 + soln[end-2]^2 / k_sq
println("center at origin: r² = $(round(1/k_sq, digits = 6)); x² + y² + z² = $(round(sum_sq, digits = 6))") println("center on z axis: r² = $(round(1/k_sq, digits = 6)), x² + y² + h² = $(round(sum_sq, digits = 6))")
end end
else
sum_sq = sum(soln[[4, 7, 10]] .^ 2)
println("center at origin: r² = $(round(1/k_sq, digits = 6)); x² + y² + z² = $(round(sum_sq, digits = 6))")
end end
end end