Engine prototype #13

Merged
glen merged 133 commits from engine-proto into main 2024-10-21 03:18:48 +00:00
2 changed files with 7 additions and 6 deletions
Showing only changes of commit ae5db0f9ea - Show all commits

View File

@ -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,16 @@ 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 = 0x1974abba)))
end end
AbstractAlgebra.evaluate(pt::Point, vals::Vector{<:RingElement}) = AbstractAlgebra.evaluate(pt::Point, vals::Vector{<:RingElement}) =

View File

@ -89,11 +89,11 @@ 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(small_eqns_tan_sph, variables = vbls))
norm2 = vec -> real(dot(conj.(vec), vec)) norm2 = vec -> real(dot(conj.(vec), vec))
Random.seed!(6071) rng = MersenneTwister(6071)
n_planes = 36 n_planes = 3
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)