Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update permutation groups etal #13

Merged
merged 9 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
name = "PropertyT"
uuid = "03b72c93-0167-51e2-8a1e-eb4ff1fb940d"
authors = ["Marek Kaluba <[email protected]>"]
version = "0.5.0"
version = "0.6.0"

[deps]
Groups = "5d8bd718-bd84-11e8-3b40-ad14f4a32557"
GroupsCore = "d5909c97-4eac-4ecc-a3dc-fdd0858a4120"
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
IntervalMatrices = "5c1f47dc-42dd-5697-8aaa-4d102d140ba9"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PermutationGroups = "8bc5a954-2dfc-11e9-10e6-cd969bffa420"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StarAlgebras = "0c0c59c1-dc5f-42e9-9a8b-b5dc384a6cd1"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
SymbolicWedderburn = "858aa9a9-4c7c-4c62-b466-2421203962a2"

[compat]
COSMO = "0.8"
Groups = "0.7"
Groups = "0.8"
GroupsCore = "0.5"
IntervalArithmetic = "0.20"
IntervalMatrices = "0.8"
JuMP = "1.3"
IntervalMatrices = "0.10"
JuMP = ">=1.3"
PermutationGroups = "0.6.2"
ProgressMeter = "1.7"
SCS = "1.1"
SCS = "2"
StarAlgebras = "0.2.1"
StaticArrays = "1"
SymbolicWedderburn = "0.3.4"
SymbolicWedderburn = "0.4"
julia = "1.6"

[extras]
Expand Down
12 changes: 6 additions & 6 deletions src/PropertyT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ using SparseArrays
using JuMP

using Groups
import Groups.GroupsCore
using SymbolicWedderburn
import SymbolicWedderburn.StarAlgebras
import SymbolicWedderburn.PermutationGroups
import GroupsCore
import PermutationGroups as PG
import SymbolicWedderburn as SW
import StarAlgebras as SA

include("constraint_matrix.jl")
include("sos_sdps.jl")
Expand All @@ -31,9 +31,9 @@ function group_algebra(G::Groups.Group, S = gens(G); halfradius::Integer)
@time E, sizes = Groups.wlmetric_ball(S; radius = 2halfradius)
@info "sizes = $(sizes)"
@info "computing the *-algebra structure for G"
@time RG = StarAlgebras.StarAlgebra(
@time RG = SA.StarAlgebra(
G,
StarAlgebras.Basis{UInt32}(E),
SA.Basis{UInt32}(E),
(sizes[halfradius], sizes[halfradius]);
precompute = false,
)
Expand Down
21 changes: 8 additions & 13 deletions src/actions/actions.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import SymbolicWedderburn.action

include("alphabet_permutation.jl")

include("sln_conjugation.jl")
include("spn_conjugation.jl")
include("autfn_conjugation.jl")

function SymbolicWedderburn.action(
act::SymbolicWedderburn.ByPermutations,
function SW.action(
act::SW.ByPermutations,
g::Groups.GroupElement,
α::StarAlgebras.AlgebraElement,
α::SA.AlgebraElement,
)
res = StarAlgebras.zero!(similar(α))
B = basis(parent(α))
for (idx, val) in StarAlgebras._nzpairs(StarAlgebras.coeffs(α))
res = SA.zero!(similar(α))
B = SA.basis(parent(α))
for (idx, val) in SA._nzpairs(SA.coeffs(α))
a = B[idx]
a_g = SymbolicWedderburn.action(act, g, a)
a_g = SW.action(act, g, a)
res[a_g] += val
end
return res
end

function Base.:^(
w::W,
p::PermutationGroups.AbstractPerm,
) where {W<:Groups.AbstractWord}
function Base.:^(w::W, p::PG.AbstractPermutation) where {W<:Groups.AbstractWord}
return W([l^p for l in w])
end
22 changes: 8 additions & 14 deletions src/actions/alphabet_permutation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,37 @@

import Groups: Constructions

struct AlphabetPermutation{GEl,I} <: SymbolicWedderburn.ByPermutations
perms::Dict{GEl,PermutationGroups.Perm{I}}
struct AlphabetPermutation{GEl,I} <: SW.ByPermutations
perms::Dict{GEl,PG.Perm{I}}
end

function AlphabetPermutation(
A::Alphabet,
Γ::PermutationGroups.AbstractPermutationGroup,
Γ::PG.AbstractPermutationGroup,
op,
)
return AlphabetPermutation(
Dict(γ => inv(PermutationGroups.Perm([A[op(l, γ)] for l in A])) for γ in Γ),
Dict(γ => inv(PG.Perm([A[op(l, γ)] for l in A])) for γ in Γ),
)
end

function AlphabetPermutation(A::Alphabet, W::Constructions.WreathProduct, op)
return AlphabetPermutation(
Dict(
w => inv(PermutationGroups.Perm([A[op(op(l, w.p), w.n)] for l in A])) for
w => inv(PG.Perm([A[op(op(l, w.p), w.n)] for l in A])) for
w in W
),
)
end

function SymbolicWedderburn.action(
function SW.action(
act::AlphabetPermutation,
γ::Groups.GroupElement,
g::Groups.AbstractFPGroupElement,
)
G = parent(g)
w = SymbolicWedderburn.action(act, γ, word(g))
# w = SW.action(act, γ, word(g))
w = word(g)^(act.perms[γ])
return G(w)
end

function SymbolicWedderburn.action(
act::AlphabetPermutation,
γ::Groups.GroupElement,
w::Groups.AbstractWord,
)
return w^(act.perms[γ])
end
10 changes: 7 additions & 3 deletions src/actions/autfn_conjugation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function _conj(
t::Groups.Transvection,
σ::PermutationGroups.AbstractPerm,
σ::PG.AbstractPermutation,
)
return Groups.Transvection(t.id, t.i^inv(σ), t.j^inv(σ), t.inv)
end
Expand All @@ -22,5 +22,9 @@ function _conj(
return _flip(t, x.elts[i])
end

action_by_conjugation(sautfn::Groups.AutomorphismGroup{<:Groups.FreeGroup}, Σ::Groups.Group) =
AlphabetPermutation(alphabet(sautfn), Σ, _conj)
function action_by_conjugation(
sautfn::Groups.AutomorphismGroup{<:Groups.FreeGroup},
Σ::Groups.Group,
)
return AlphabetPermutation(alphabet(sautfn), Σ, _conj)
end
10 changes: 7 additions & 3 deletions src/actions/sln_conjugation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function _conj(
t::MatrixGroups.ElementaryMatrix{N},
σ::PermutationGroups.AbstractPerm,
σ::PG.AbstractPermutation,
) where {N}
return MatrixGroups.ElementaryMatrix{N}(t.i^inv(σ), t.j^inv(σ), t.val)
end
Expand All @@ -16,5 +16,9 @@ function _conj(
return ifelse(just_one_flips, inv(t), t)
end

action_by_conjugation(sln::Groups.MatrixGroups.SpecialLinearGroup, Σ::Groups.Group) =
AlphabetPermutation(alphabet(sln), Σ, _conj)
function action_by_conjugation(
sln::Groups.MatrixGroups.SpecialLinearGroup,
Σ::Groups.Group,
)
return AlphabetPermutation(alphabet(sln), Σ, _conj)
end
12 changes: 8 additions & 4 deletions src/actions/spn_conjugation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

function _conj(
s::MatrixGroups.ElementarySymplectic{N,T},
σ::PermutationGroups.AbstractPerm,
σ::PG.AbstractPermutation,
) where {N,T}
@assert iseven(N)
@assert PermutationGroups.degree(σ) == N ÷ 2 "Got degree = $(PermutationGroups.degree(σ)); N = $N"
@assert PG.degree(σ) N ÷ 2 "Got degree = $(PG.degree(σ)); N = $N"

Check warning on line 8 in src/actions/spn_conjugation.jl

View check run for this annotation

Codecov / codecov/patch

src/actions/spn_conjugation.jl#L8

Added line #L8 was not covered by tests
n = N ÷ 2
@assert 1 ≤ s.i ≤ N
@assert 1 ≤ s.j ≤ N
Expand Down Expand Up @@ -40,5 +40,9 @@
return ifelse(just_one_flips, inv(s), s)
end

action_by_conjugation(sln::Groups.MatrixGroups.SymplecticGroup, Σ::Groups.Group) =
AlphabetPermutation(alphabet(sln), Σ, _conj)
function action_by_conjugation(

Check warning on line 43 in src/actions/spn_conjugation.jl

View check run for this annotation

Codecov / codecov/patch

src/actions/spn_conjugation.jl#L43

Added line #L43 was not covered by tests
sln::Groups.MatrixGroups.SymplecticGroup,
Σ::Groups.Group,
)
return AlphabetPermutation(alphabet(sln), Σ, _conj)

Check warning on line 47 in src/actions/spn_conjugation.jl

View check run for this annotation

Codecov / codecov/patch

src/actions/spn_conjugation.jl#L47

Added line #L47 was not covered by tests
end
43 changes: 21 additions & 22 deletions src/certify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
end

function __sos_via_sqr!(
res::StarAlgebras.AlgebraElement,
res::SA.AlgebraElement,
P::AbstractMatrix;
augmented::Bool,
id = (b = basis(parent(res)); b[one(first(b))]),
id = (b = SA.basis(parent(res)); b[one(first(b))]),
)
A = parent(res)
mstr = A.mstructure
@assert size(mstr) == size(P)

StarAlgebras.zero!(res)
SA.zero!(res)
for j in axes(mstr, 2)
for i in axes(mstr, 1)
p = P[i, j]
Expand All @@ -39,29 +39,29 @@
end

function __sos_via_cnstr!(
res::StarAlgebras.AlgebraElement,
res::SA.AlgebraElement,
Q²::AbstractMatrix,
cnstrs,
)
StarAlgebras.zero!(res)
SA.zero!(res)

Check warning on line 46 in src/certify.jl

View check run for this annotation

Codecov / codecov/patch

src/certify.jl#L46

Added line #L46 was not covered by tests
for (g, A_g) in cnstrs
res[g] = dot(A_g, Q²)
end
return res
end

function compute_sos(
A::StarAlgebras.StarAlgebra,
A::SA.StarAlgebra,
Q::AbstractMatrix;
augmented::Bool,
)
Q² = Q' * Q
res = StarAlgebras.AlgebraElement(zeros(eltype(Q²), length(basis(A))), A)
res = SA.AlgebraElement(zeros(eltype(Q²), length(SA.basis(A))), A)
res = __sos_via_sqr!(res, Q²; augmented = augmented)
return res
end

function sufficient_λ(residual::StarAlgebras.AlgebraElement, λ; halfradius)
function sufficient_λ(residual::SA.AlgebraElement, λ; halfradius)
L1_norm = norm(residual, 1)
suff_λ = λ - 2.0^(2ceil(log2(halfradius))) * L1_norm

Expand All @@ -77,8 +77,10 @@

info_strs = [
"Numerical metrics of the obtained SOS:",
"ɛ(elt - λu - ∑ξᵢ*ξᵢ) $eq_sign $(StarAlgebras.aug(residual))",
"‖elt - λu - ∑ξᵢ*ξᵢ‖₁ $eq_sign $(L1_norm)",
"ɛ(elt - λu - ∑ξᵢ*ξᵢ) $eq_sign " *
sprint(show, SA.aug(residual); context = :compact => true),
"‖elt - λu - ∑ξᵢ*ξᵢ‖₁ $eq_sign " *
sprint(show, L1_norm; context = :compact => true),
" λ $eq_sign $suff_λ",
]
@info join(info_strs, "\n")
Expand All @@ -87,10 +89,10 @@
end

function sufficient_λ(
elt::StarAlgebras.AlgebraElement,
order_unit::StarAlgebras.AlgebraElement,
elt::SA.AlgebraElement,
order_unit::SA.AlgebraElement,
λ,
sos::StarAlgebras.AlgebraElement;
sos::SA.AlgebraElement;
halfradius,
)
@assert parent(elt) === parent(order_unit) == parent(sos)
Expand All @@ -100,16 +102,15 @@
end

function certify_solution(
elt::StarAlgebras.AlgebraElement,
orderunit::StarAlgebras.AlgebraElement,
elt::SA.AlgebraElement,
orderunit::SA.AlgebraElement,
λ,
Q::AbstractMatrix{<:AbstractFloat};
halfradius,
augmented = iszero(StarAlgebras.aug(elt)) &&
iszero(StarAlgebras.aug(orderunit)),
augmented = iszero(SA.aug(elt)) && iszero(SA.aug(orderunit)),
)
should_we_augment =
!augmented && StarAlgebras.aug(elt) == StarAlgebras.aug(orderunit) == 0
!augmented && SA.aug(elt) == SA.aug(orderunit) == 0

Q = should_we_augment ? augment_columns!(Q) : Q
@time sos = compute_sos(parent(elt), Q; augmented = augmented)
Expand All @@ -122,10 +123,8 @@
return false, λ_flpoint
end

λ_int = IntervalArithmetic.@interval(λ)
Q_int = IntervalMatrices.IntervalMatrix([
IntervalArithmetic.@interval(q) for q in Q
])
λ_int = IntervalArithmetic.interval(λ)
Q_int = IntervalMatrices.IntervalMatrix(IntervalArithmetic.interval.(Q))

check, sos_int = @time if should_we_augment
@info("Projecting columns of Q to the augmentation ideal...")
Expand Down
10 changes: 5 additions & 5 deletions src/constraint_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ function LinearAlgebra.dot(cm::ConstraintMatrix, m::AbstractMatrix{T}) where {T}
return convert(eltype(cm), cm.val) * (pos - neg)
end

function constraints(A::StarAlgebras.StarAlgebra; augmented::Bool)
return constraints(basis(A), A.mstructure; augmented = augmented)
function constraints(A::SA.StarAlgebra; augmented::Bool)
return constraints(SA.basis(A), A.mstructure; augmented = augmented)
end

function constraints(
basis::StarAlgebras.AbstractBasis,
mstr::StarAlgebras.MultiplicativeStructure;
basis::SA.AbstractBasis,
mstr::SA.MultiplicativeStructure;
augmented = false,
)
cnstrs = _constraints(
Expand All @@ -170,7 +170,7 @@ function constraints(
end

function _constraints(
mstr::StarAlgebras.MultiplicativeStructure;
mstr::SA.MultiplicativeStructure;
augmented::Bool = false,
num_constraints = maximum(mstr),
id,
Expand Down
2 changes: 1 addition & 1 deletion src/gradings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function _groupby(keys::AbstractVector{K}, vals::AbstractVector{V}) where {K,V}
return d
end

function laplacians(RG::StarAlgebras.StarAlgebra, S, grading)
function laplacians(RG::SA.StarAlgebra, S, grading)
d = _groupby(grading, S)
Δs = Dict(α => RG(length(Sα)) - sum(RG(s) for s in Sα) for (α, Sα) in d)
return Δs
Expand Down
Loading
Loading