2024-01-30 07:49:33 +00:00
|
|
|
include("HittingSet.jl")
|
2024-01-30 07:45:14 +00:00
|
|
|
|
2024-01-24 16:16:24 +00:00
|
|
|
module Engine
|
|
|
|
|
2024-02-10 19:50:50 +00:00
|
|
|
include("Engine.Algebraic.jl")
|
|
|
|
include("Engine.Numerical.jl")
|
Order variables by coordinate and then element
In other words, order coordinates like
(rₛ₁, rₛ₂, sₛ₁, sₛ₂, xₛ₁, xₛ₂, xₚ₃, yₛ₁, yₛ₂, yₚ₃, zₛ₁, zₛ₂, zₚ₃)
instead of like
(rₛ₁, sₛ₁, xₛ₁, yₛ₁, zₛ₁, rₛ₂, sₛ₂, xₛ₂, yₛ₂, zₛ₂, xₚ₃, yₚ₃, zₚ₃).
In the test cases, this really cuts down the size of the Gröbner basis.
2024-01-27 19:21:03 +00:00
|
|
|
|
2024-02-10 19:50:50 +00:00
|
|
|
using .Algebraic
|
|
|
|
using .Numerical
|
Order variables by coordinate and then element
In other words, order coordinates like
(rₛ₁, rₛ₂, sₛ₁, sₛ₂, xₛ₁, xₛ₂, xₚ₃, yₛ₁, yₛ₂, yₚ₃, zₛ₁, zₛ₂, zₚ₃)
instead of like
(rₛ₁, sₛ₁, xₛ₁, yₛ₁, zₛ₁, rₛ₂, sₛ₂, xₛ₂, yₛ₂, zₛ₂, xₚ₃, yₚ₃, zₚ₃).
In the test cases, this really cuts down the size of the Gröbner basis.
2024-01-27 19:21:03 +00:00
|
|
|
|
2024-02-10 19:50:50 +00:00
|
|
|
export Construction, mprod, codimension, dimension
|
2024-01-24 16:16:24 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2024-01-26 16:14:32 +00:00
|
|
|
# ~~~ sandbox setup ~~~
|
2024-01-24 16:16:24 +00:00
|
|
|
|
2024-02-10 04:44:10 +00:00
|
|
|
using Random
|
|
|
|
using Distributions
|
2024-02-10 18:46:01 +00:00
|
|
|
using LinearAlgebra
|
2024-02-08 06:53:55 +00:00
|
|
|
using AbstractAlgebra
|
|
|
|
using HomotopyContinuation
|
2024-02-13 01:34:12 +00:00
|
|
|
using GLMakie
|
2024-02-08 06:53:55 +00:00
|
|
|
|
2024-01-29 17:28:45 +00:00
|
|
|
CoeffType = Rational{Int64}
|
|
|
|
|
2024-02-13 02:14:07 +00:00
|
|
|
##a = Engine.Point{CoeffType}()
|
|
|
|
##s = Engine.Sphere{CoeffType}()
|
|
|
|
##a_on_s = Engine.LiesOn{CoeffType}(a, s)
|
|
|
|
##ctx = Engine.Construction{CoeffType}(elements = Set([a]), relations= Set([a_on_s]))
|
2024-02-08 06:53:55 +00:00
|
|
|
##ideal_a_s = Engine.realize(ctx)
|
2024-02-13 02:14:07 +00:00
|
|
|
##println("A point on a sphere: $(Engine.dimension(ideal_a_s)) degrees of freedom")
|
2024-01-27 17:28:29 +00:00
|
|
|
|
2024-02-13 02:14:07 +00:00
|
|
|
##b = Engine.Point{CoeffType}()
|
|
|
|
##b_on_s = Engine.LiesOn{CoeffType}(b, s)
|
|
|
|
##Engine.push!(ctx, b)
|
|
|
|
##Engine.push!(ctx, s)
|
|
|
|
##Engine.push!(ctx, b_on_s)
|
|
|
|
##ideal_ab_s, eqns_ab_s = Engine.realize(ctx)
|
|
|
|
##freedom = Engine.dimension(ideal_ab_s)
|
|
|
|
##println("Two points on a sphere: $freedom degrees of freedom")
|
2024-02-08 06:53:55 +00:00
|
|
|
|
2024-02-15 21:28:01 +00:00
|
|
|
spheres = [Engine.Sphere{CoeffType}() for _ in 1:3]
|
|
|
|
tangencies = [
|
|
|
|
Engine.AlignsWithBy{CoeffType}(
|
|
|
|
spheres[n],
|
|
|
|
spheres[mod1(n+1, length(spheres))],
|
|
|
|
CoeffType(-1)^n
|
|
|
|
)
|
|
|
|
for n in 1:3
|
|
|
|
]
|
2024-02-13 03:48:16 +00:00
|
|
|
##tangencies = [
|
|
|
|
##Engine.LiesOn{CoeffType}(points[1], spheres[2]),
|
|
|
|
##Engine.LiesOn{CoeffType}(points[1], spheres[3]),
|
|
|
|
##Engine.LiesOn{CoeffType}(points[2], spheres[3]),
|
|
|
|
##Engine.LiesOn{CoeffType}(points[2], spheres[1]),
|
|
|
|
##Engine.LiesOn{CoeffType}(points[3], spheres[1]),
|
|
|
|
##Engine.LiesOn{CoeffType}(points[3], spheres[2])
|
|
|
|
##]
|
2024-02-15 22:27:41 +00:00
|
|
|
ctx_tan_sph = Engine.Construction{CoeffType}(elements = spheres, relations = tangencies)
|
2024-02-15 21:28:01 +00:00
|
|
|
ideal_tan_sph, eqns_tan_sph = Engine.realize(ctx_tan_sph)
|
|
|
|
##small_eqns_tan_sph = eqns_tan_sph
|
2024-02-15 22:17:03 +00:00
|
|
|
##small_eqns_tan_sph = [
|
|
|
|
## eqns_tan_sph;
|
|
|
|
## spheres[2].coords - [1, 0, 0, 0, 1];
|
|
|
|
## spheres[3].coords - [1, 0, 0, 0, -1];
|
|
|
|
##]
|
|
|
|
##small_ideal_tan_sph = Generic.Ideal(base_ring(ideal_tan_sph), small_eqns_tan_sph)
|
|
|
|
freedom = Engine.dimension(ideal_tan_sph)
|
2024-02-15 21:28:01 +00:00
|
|
|
println("Three mutually tangent spheres, with two fixed: $freedom degrees of freedom")
|
|
|
|
|
|
|
|
##points = [Engine.Point{CoeffType}() for _ in 1:3]
|
|
|
|
##spheres = [Engine.Sphere{CoeffType}() for _ in 1:2]
|
|
|
|
##ctx_joined = Engine.Construction{CoeffType}(
|
|
|
|
## elements = Set([points; spheres]),
|
|
|
|
## relations= Set([
|
|
|
|
## Engine.LiesOn{CoeffType}(pt, sph)
|
|
|
|
## for pt in points for sph in spheres
|
|
|
|
## ])
|
|
|
|
##)
|
|
|
|
##ideal_joined, eqns_joined = Engine.realize(ctx_joined)
|
|
|
|
##freedom = Engine.dimension(ideal_joined)
|
|
|
|
##println("$(length(points)) points on $(length(spheres)) spheres: $freedom degrees of freedom")
|
2024-02-08 06:53:55 +00:00
|
|
|
|
|
|
|
# --- test rational cut ---
|
|
|
|
|
2024-02-15 22:17:03 +00:00
|
|
|
coordring = base_ring(ideal_tan_sph)
|
2024-02-10 05:59:50 +00:00
|
|
|
vbls = Variable.(symbols(coordring))
|
|
|
|
|
|
|
|
# test a random witness set
|
2024-02-15 22:17:03 +00:00
|
|
|
system = CompiledSystem(System(eqns_tan_sph, variables = vbls))
|
2024-02-10 18:46:01 +00:00
|
|
|
norm2 = vec -> real(dot(conj.(vec), vec))
|
2024-02-15 22:17:03 +00:00
|
|
|
rng = MersenneTwister(6701)
|
|
|
|
n_planes = 6
|
2024-02-13 01:34:12 +00:00
|
|
|
samples = []
|
|
|
|
for _ in 1:n_planes
|
2024-02-15 22:17:03 +00:00
|
|
|
real_solns = solution.(Engine.Numerical.real_samples(system, freedom, rng = rng))
|
2024-02-13 01:34:12 +00:00
|
|
|
for soln in real_solns
|
|
|
|
if all(norm2(soln - samp) > 1e-4*length(gens(coordring)) for samp in samples)
|
|
|
|
push!(samples, soln)
|
2024-02-10 18:46:01 +00:00
|
|
|
end
|
|
|
|
end
|
2024-02-13 01:34:12 +00:00
|
|
|
end
|
|
|
|
println("$(length(samples)) sample solutions:")
|
2024-02-15 21:28:01 +00:00
|
|
|
##for soln in samples
|
|
|
|
## ## display([vbls round.(soln, digits = 6)]) ## [verbose]
|
|
|
|
## k_sq = abs2(soln[1])
|
|
|
|
## if abs2(soln[end-2]) > 1e-12
|
|
|
|
## if k_sq < 1e-12
|
|
|
|
## println(" center at infinity: z coordinates $(round(soln[end], digits = 6)) and $(round(soln[end-1], digits = 6))")
|
|
|
|
## else
|
|
|
|
## 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
|
|
|
|
## 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
|
2024-02-13 01:34:12 +00:00
|
|
|
|
|
|
|
# show a sample solution
|
2024-02-13 02:14:07 +00:00
|
|
|
function show_solution(ctx, vals)
|
2024-02-13 01:34:12 +00:00
|
|
|
# evaluate elements
|
|
|
|
real_vals = real.(vals)
|
|
|
|
disp_points = [Engine.Numerical.evaluate(pt, real_vals) for pt in ctx.points]
|
|
|
|
disp_spheres = [Engine.Numerical.evaluate(sph, real_vals) for sph in ctx.spheres]
|
|
|
|
|
|
|
|
# create scene
|
|
|
|
scene = Scene()
|
|
|
|
cam3d!(scene)
|
|
|
|
scatter!(scene, disp_points, color = :green)
|
|
|
|
for sph in disp_spheres
|
|
|
|
mesh!(scene, sph, color = :gray)
|
2024-02-08 06:53:55 +00:00
|
|
|
end
|
2024-02-13 01:34:12 +00:00
|
|
|
scene
|
2024-02-08 06:53:55 +00:00
|
|
|
end
|