Skip to content

Commit

Permalink
Build Nullspace from MomentMatrix (#84)
Browse files Browse the repository at this point in the history
* Build Nullspace from MomentMatrix

* Fix show for ZeroDimensionalIdeal

* Add tests

* Fix

* Fix

* Fix format
  • Loading branch information
blegat authored Jul 2, 2024
1 parent 745c911 commit 8eab7b0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/flat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ end
SemialgebraicSets.is_zero_dimensional(::ZeroDimensionalVariety) = true
Base.length(v::ZeroDimensionalVariety) = length(v.elements)
Base.iterate(v::ZeroDimensionalVariety, args...) = iterate(v.elements, args...)
function Base.show(io::IO, V::ZeroDimensionalVariety)
function Base.show(io::IO, ::MIME"text/plain", V::ZeroDimensionalVariety)
println(io, "ZeroDimensionalVariety with elements:")
return show(io, V.elements)
show(io, V.elements)
return
end
function Base.show(io::IO, V::ZeroDimensionalVariety)
return show(io, MIME"text/plain"(), V)
end

# Decomposition of the pencil of matrices
Expand Down
16 changes: 12 additions & 4 deletions src/null.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ function Base.getindex(
)
end

function MacaulayNullspace(
ν::MomentMatrix,
rank_check::RankCheck,
ldlt::LowRankLDLTAlgorithm = SVDLDLT(),
)
M = value_matrix(ν)
chol = low_rank_ldlt(M, ldlt, rank_check)
@assert size(chol.L, 1) == LinearAlgebra.checksquare(M)
return MacaulayNullspace(chol.L, ν.basis, accuracy(chol))
end

abstract type MacaulayNullspaceSolver end

function solve(null::MacaulayNullspace, solver::MacaulayNullspaceSolver)
Expand All @@ -58,11 +69,8 @@ function compute_support!(
rank_check::RankCheck,
solver::ImageSpaceSolver,
)
M = value_matrix(ν)
chol = low_rank_ldlt(M, solver.ldlt, rank_check)
@assert size(chol.L, 1) == LinearAlgebra.checksquare(M)
ν.support =
solve(MacaulayNullspace(chol.L, ν.basis, accuracy(chol)), solver.null)
solve(MacaulayNullspace(ν, rank_check, solver.ldlt), solver.null)
return
end

Expand Down
1 change: 1 addition & 0 deletions test/commutativetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include("moment_vector.jl")
include("expectation.jl")
include("moment_matrix.jl")
include("rank.jl")
include("flat.jl")
include("extract.jl")
include("atomic.jl")
include("hermitian_poly.jl")
Expand Down
8 changes: 8 additions & 0 deletions test/flat.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Test, MultivariateMoments

@testset "ZeroDimensionalVariety" begin
V = ZeroDimensionalVariety([[1], [2]])
expected = "ZeroDimensionalVariety with elements:\n[[1], [2]]"
@test sprint(show, V) == expected
@test sprint(show, MIME"text/plain"(), V) == expected
end

0 comments on commit 8eab7b0

Please sign in to comment.