Compare commits
2 Commits
291d5c8ff6
...
2a505c1f59
Author | SHA1 | Date | |
---|---|---|---|
|
2a505c1f59 | ||
|
a6da6f9925 |
@ -120,11 +120,11 @@ equation(rel::AlignsWithBy) = mprod(rel.elements[1].vec, rel.elements[2].vec) -
|
|||||||
# --- constructions ---
|
# --- constructions ---
|
||||||
|
|
||||||
mutable struct Construction{T}
|
mutable struct Construction{T}
|
||||||
points::Set{Point{T}}
|
points::Vector{Point{T}}
|
||||||
spheres::Set{Sphere{T}}
|
spheres::Vector{Sphere{T}}
|
||||||
relations::Set{Relation{T}}
|
relations::Vector{Relation{T}}
|
||||||
|
|
||||||
function Construction{T}(; elements = Set{Element{T}}(), relations = Set{Relation{T}}()) where T
|
function Construction{T}(; elements = Vector{Element{T}}(), relations = Vector{Relation{T}}()) where T
|
||||||
allelements = union(elements, (rel.elements for rel in relations)...)
|
allelements = union(elements, (rel.elements for rel in relations)...)
|
||||||
new{T}(
|
new{T}(
|
||||||
filter(elt -> isa(elt, Point), allelements),
|
filter(elt -> isa(elt, Point), allelements),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
module Numerical
|
module Numerical
|
||||||
|
|
||||||
|
using Random: default_rng
|
||||||
using LinearAlgebra
|
using LinearAlgebra
|
||||||
using AbstractAlgebra
|
using AbstractAlgebra
|
||||||
using HomotopyContinuation:
|
using HomotopyContinuation:
|
||||||
@ -28,16 +29,18 @@ end
|
|||||||
|
|
||||||
# --- sampling ---
|
# --- sampling ---
|
||||||
|
|
||||||
function real_samples(F::AbstractSystem, dim)
|
function real_samples(F::AbstractSystem, dim; rng = default_rng())
|
||||||
# choose a random real hyperplane of codimension `dim` by intersecting
|
# choose a random real hyperplane of codimension `dim` by intersecting
|
||||||
# hyperplanes whose normal vectors are uniformly distributed over the unit
|
# hyperplanes whose normal vectors are uniformly distributed over the unit
|
||||||
# sphere
|
# sphere
|
||||||
# [to do] guard against the unlikely event that one of the normals is zero
|
# [to do] guard against the unlikely event that one of the normals is zero
|
||||||
normals = transpose(hcat(
|
##normals = transpose(hcat(
|
||||||
(normalize(randn(nvariables(F))) for _ in 1:dim)...
|
## (normalize(randn(rng, nvariables(F))) for _ in 1:dim)...
|
||||||
))
|
##))
|
||||||
cut = LinearSubspace(normals, fill(0., dim))
|
##cut = LinearSubspace(normals, fill(0., dim))
|
||||||
filter(isreal, results(witness_set(F, cut)))
|
##filter(isreal, results(witness_set(F, cut, seed = 0x8af341df)))
|
||||||
|
##filter(isreal, results(witness_set(F, seed = 0x8af341df)))
|
||||||
|
results(witness_set(F, seed = 0x8af341df))
|
||||||
end
|
end
|
||||||
|
|
||||||
AbstractAlgebra.evaluate(pt::Point, vals::Vector{<:RingElement}) =
|
AbstractAlgebra.evaluate(pt::Point, vals::Vector{<:RingElement}) =
|
||||||
|
@ -56,16 +56,16 @@ tangencies = [
|
|||||||
##Engine.LiesOn{CoeffType}(points[3], spheres[1]),
|
##Engine.LiesOn{CoeffType}(points[3], spheres[1]),
|
||||||
##Engine.LiesOn{CoeffType}(points[3], spheres[2])
|
##Engine.LiesOn{CoeffType}(points[3], spheres[2])
|
||||||
##]
|
##]
|
||||||
ctx_tan_sph = Engine.Construction{CoeffType}(elements = Set(spheres), relations = Set(tangencies))
|
ctx_tan_sph = Engine.Construction{CoeffType}(elements = spheres, relations = tangencies)
|
||||||
ideal_tan_sph, eqns_tan_sph = Engine.realize(ctx_tan_sph)
|
ideal_tan_sph, eqns_tan_sph = Engine.realize(ctx_tan_sph)
|
||||||
##small_eqns_tan_sph = eqns_tan_sph
|
##small_eqns_tan_sph = eqns_tan_sph
|
||||||
small_eqns_tan_sph = [
|
##small_eqns_tan_sph = [
|
||||||
eqns_tan_sph;
|
## eqns_tan_sph;
|
||||||
spheres[2].coords - [1, 0, 0, 0, 1];
|
## spheres[2].coords - [1, 0, 0, 0, 1];
|
||||||
spheres[3].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)
|
##small_ideal_tan_sph = Generic.Ideal(base_ring(ideal_tan_sph), small_eqns_tan_sph)
|
||||||
freedom = Engine.dimension(small_ideal_tan_sph)
|
freedom = Engine.dimension(ideal_tan_sph)
|
||||||
println("Three mutually tangent spheres, with two fixed: $freedom degrees of freedom")
|
println("Three mutually tangent spheres, with two fixed: $freedom degrees of freedom")
|
||||||
|
|
||||||
##points = [Engine.Point{CoeffType}() for _ in 1:3]
|
##points = [Engine.Point{CoeffType}() for _ in 1:3]
|
||||||
@ -83,17 +83,17 @@ println("Three mutually tangent spheres, with two fixed: $freedom degrees of fre
|
|||||||
|
|
||||||
# --- test rational cut ---
|
# --- test rational cut ---
|
||||||
|
|
||||||
coordring = base_ring(small_ideal_tan_sph)
|
coordring = base_ring(ideal_tan_sph)
|
||||||
vbls = Variable.(symbols(coordring))
|
vbls = Variable.(symbols(coordring))
|
||||||
|
|
||||||
# test a random witness set
|
# test a random witness set
|
||||||
system = CompiledSystem(System(small_eqns_tan_sph, variables = vbls))
|
system = CompiledSystem(System(eqns_tan_sph, variables = vbls))
|
||||||
norm2 = vec -> real(dot(conj.(vec), vec))
|
norm2 = vec -> real(dot(conj.(vec), vec))
|
||||||
Random.seed!(6071)
|
rng = MersenneTwister(6701)
|
||||||
n_planes = 36
|
n_planes = 6
|
||||||
samples = []
|
samples = []
|
||||||
for _ in 1:n_planes
|
for _ in 1:n_planes
|
||||||
real_solns = solution.(Engine.Numerical.real_samples(system, freedom))
|
real_solns = solution.(Engine.Numerical.real_samples(system, freedom, rng = rng))
|
||||||
for soln in real_solns
|
for soln in real_solns
|
||||||
if all(norm2(soln - samp) > 1e-4*length(gens(coordring)) for samp in samples)
|
if all(norm2(soln - samp) > 1e-4*length(gens(coordring)) for samp in samples)
|
||||||
push!(samples, soln)
|
push!(samples, soln)
|
||||||
|
Loading…
Reference in New Issue
Block a user