Skip to content

Commit

Permalink
Refactor type variables in smash product and deformation (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens authored Aug 31, 2023
1 parent 7a6c4d9 commit 858ed06
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 121 deletions.
26 changes: 13 additions & 13 deletions src/DeformationBases/ArcDiagDeformBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ struct ArcDiagDeformBasis{C <: RingElem} <: DeformBasis{C}
degs::AbstractVector{Int};
no_normalize::Bool=false,
) where {C <: RingElem}
@req get_attribute(lie_algebra(sp), :type, nothing) == :special_orthogonal "Only works for so_n."
@req (is_exterior_power(lie_module(sp)) || is_symmetric_power(lie_module(sp))) &&
is_standard_module(base_module(lie_module(sp))) "Only works for exterior powers of the standard module."
@req get_attribute(base_lie_algebra(sp), :type, nothing) == :special_orthogonal "Only works for so_n."
@req (is_exterior_power(base_module(sp)) || is_symmetric_power(base_module(sp))) &&
is_standard_module(base_module(base_module(sp))) "Only works for exterior powers of the standard module."

extra_data = Dict{DeformationMap{C}, Set{ArcDiagram}}()
normalize = no_normalize ? identity : normalize_default
Expand All @@ -26,7 +26,7 @@ struct ArcDiagDeformBasis{C <: RingElem} <: DeformBasis{C}
iters = []
debug_counter = 0
for d in degs
diag_iter = pbw_arc_diagrams__so(lie_module(sp), d)
diag_iter = pbw_arc_diagrams__so(base_module(sp), d)
len = length(diag_iter)
iter = (
begin
Expand Down Expand Up @@ -184,31 +184,31 @@ end
function arcdiag_to_deformationmap__so(diag::ArcDiagramUndirected, sp::SmashProductLie{C}) where {C <: RingElem}
# TODO: allow for genereal ArcDiagrams
d = div(n_lower_vertices(diag), 2)
dim_stdmod_V = lie_algebra(sp).n
dim_stdmod_V = base_lie_algebra(sp).n

e = arc_diagram_num_points__so(lie_module(sp))
e = arc_diagram_num_points__so(base_module(sp))

iso_wedge2V_g = Dict{Vector{Int}, Int}()
for (i, bs) in enumerate(combinations(lie_algebra(sp).n, 2))
for (i, bs) in enumerate(combinations(base_lie_algebra(sp).n, 2))
iso_wedge2V_g[bs] = i
end

index = Dict{Vector{Int}, Int}()
for (i, is) in enumerate(arc_diagram_label_iterator__so(lie_module(sp), 1:dim_stdmod_V))
for (i, is) in enumerate(arc_diagram_label_iterator__so(base_module(sp), 1:dim_stdmod_V))
index[is] = i
end

kappa = fill(zero(underlying_algebra(sp)), dim(lie_module(sp)), dim(lie_module(sp)))
for is in arc_diagram_label_iterator__so(lie_module(sp), 1:dim_stdmod_V),
js in arc_diagram_label_iterator__so(lie_module(sp), 1:dim_stdmod_V)
kappa = fill(zero(underlying_algebra(sp)), dim(base_module(sp)), dim(base_module(sp)))
for is in arc_diagram_label_iterator__so(base_module(sp), 1:dim_stdmod_V),
js in arc_diagram_label_iterator__so(base_module(sp), 1:dim_stdmod_V)

i = index[is]
j = index[js]
if i >= j
continue
end
for (is, sgn_left) in arc_diagram_label_permutations__so(lie_module(sp), is),
(js, sgn_right) in arc_diagram_label_permutations__so(lie_module(sp), js),
for (is, sgn_left) in arc_diagram_label_permutations__so(base_module(sp), is),
(js, sgn_right) in arc_diagram_label_permutations__so(base_module(sp), js),
swap in [false, true]

sgn_upper_labels = sgn_left * sgn_right
Expand Down
6 changes: 3 additions & 3 deletions src/DeformationBases/PseudographDeformBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ struct PseudographDeformBasis{C <: RingElem} <: DeformBasis{C}
degs::AbstractVector{Int};
no_normalize::Bool=false,
) where {C <: RingElem}
@req get_attribute(lie_algebra(sp), :type, nothing) == :special_orthogonal "Only works for so_n."
@req is_exterior_power(lie_module(sp)) && is_standard_module(base_module(lie_module(sp))) "Only works for exterior powers of the standard module."
@req get_attribute(base_lie_algebra(sp), :type, nothing) == :special_orthogonal "Only works for so_n."
@req is_exterior_power(base_module(sp)) && is_standard_module(base_module(base_module(sp))) "Only works for exterior powers of the standard module."

e = get_attribute(lie_module(sp), :power)
e = get_attribute(base_module(sp), :power)

extra_data = Dict{DeformationMap{C}, Set{Tuple{PseudographLabelled{Int}, Partition{Int}}}}()
normalize = no_normalize ? identity : normalize_default
Expand Down
4 changes: 2 additions & 2 deletions src/DeformationBases/StdDeformBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ struct StdDeformBasis{C <: RingElem} <: DeformBasis{C}
normalize

function StdDeformBasis{C}(sp::SmashProductLie{C}, degs::AbstractVector{Int}) where {C <: RingElem}
dimL = dim(lie_algebra(sp))
dimV = dim(lie_module(sp))
dimL = dim(base_lie_algebra(sp))
dimV = dim(base_module(sp))
iter = (
begin
kappa = fill(zero(underlying_algebra(sp)), dimV, dimV)
Expand Down
8 changes: 4 additions & 4 deletions src/PBWDeformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module PBWDeformations

using Oscar

using Oscar: IntegerUnion

using Oscar.LieAlgebras:
AbstractLieAlgebra,
AbstractLieAlgebraElem,
Expand All @@ -12,7 +14,6 @@ using Oscar.LieAlgebras:
LinearLieAlgebra,
LinearLieAlgebraElem,
abstract_module,
base_lie_algebra,
combinations,
exterior_power,
general_linear_lie_algebra,
Expand All @@ -36,7 +37,7 @@ import AbstractAlgebra: ProductIterator, coefficient_ring, elem_type, gen, gens,

import Oscar: comm, edges, nedges, neighbors, nvertices, simplify, vertices

import Oscar.LieAlgebras: lie_algebra
import Oscar.LieAlgebras: base_lie_algebra, base_module

import Base: deepcopy_internal, hash, isequal, isone, iszero, length, one, parent, show, sum, zero

Expand Down Expand Up @@ -64,6 +65,7 @@ export all_pbwdeformations
export all_pseudographs
export arc_diagram
export base_lie_algebra
export base_module
export deform
export edge_labels
export edges
Expand All @@ -74,8 +76,6 @@ export inneighbor
export inneighbors
export is_crossing_free
export is_pbwdeformation
export lie_algebra
export lie_module
export lookup_data
export lower_vertex, is_lower_vertex
export lower_vertices
Expand Down
102 changes: 64 additions & 38 deletions src/SmashProductLie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@ The struct representing a Lie algebra smash product.
It consists of the underlying FreeAssAlgebra with relations and some metadata.
It gets created by calling [`smash_product`](@ref).
"""
@attributes mutable struct SmashProductLie{C <: RingElem, CL <: RingElem} <: NCRing
@attributes mutable struct SmashProductLie{C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}} <: NCRing
coeff_ring::Ring
L::LieAlgebra{CL}
V::LieAlgebraModule{CL}
L::LieAlgebra{LieC}
V::LieAlgebraModule{LieC}
alg::FreeAssAlgebra{C}
rels::Matrix{Union{Nothing, FreeAssAlgElem{C}}}

# default constructor for @attributes
function SmashProductLie{C, CL}(
function SmashProductLie{C, LieC, LieT}(
coeff_ring::Ring,
L::LieAlgebra{CL},
V::LieAlgebraModule{CL},
L::LieAlgebra{LieC},
V::LieAlgebraModule{LieC},
alg::FreeAssAlgebra{C},
rels::Matrix{Union{Nothing, FreeAssAlgElem{C}}},
) where {C <: RingElem, CL <: RingElem}
new{C, CL}(coeff_ring, L, V, alg, rels)
) where {C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}}
new{C, LieC, LieT}(coeff_ring, L, V, alg, rels)
end
end

mutable struct SmashProductLieElem{C <: RingElem, CL <: RingElem} <: NCRingElem
p::SmashProductLie{C, CL} # parent
mutable struct SmashProductLieElem{C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}} <: NCRingElem
p::SmashProductLie{C, LieC, LieT} # parent
alg_elem::FreeAssAlgElem{C}
simplified::Bool

function SmashProductLieElem(
p::SmashProductLie{C, CL},
p::SmashProductLie{C, LieC, LieT},
alg_elem::FreeAssAlgElem{C};
simplified::Bool=false,
) where {C <: RingElem, CL <: RingElem}
) where {C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}}
@req underlying_algebra(p) === parent(alg_elem) "Incompatible algebras."
return new{C, CL}(p, alg_elem, simplified)
return new{C, LieC, LieT}(p, alg_elem, simplified)
end
end

Expand All @@ -43,41 +43,51 @@ end
#
###############################################################################

parent_type(::Type{SmashProductLieElem{C, CL}}) where {C <: RingElem, CL <: RingElem} = SmashProductLie{C, CL}
parent_type(
::Type{SmashProductLieElem{C, LieC, LieT}},
) where {C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}} = SmashProductLie{C, LieC, LieT}

elem_type(::Type{SmashProductLie{C, CL}}) where {C <: RingElem, CL <: RingElem} = SmashProductLieElem{C, CL}
elem_type(
::Type{SmashProductLie{C, LieC, LieT}},
) where {C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}} = SmashProductLieElem{C, LieC, LieT}

parent(e::SmashProductLieElem) = e.p

coefficient_ring(Sp::SmashProductLie) = Sp.coeff_ring
coefficient_ring(
Sp::SmashProductLie{C, LieC, LieT},
) where {C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}} = Sp.coeff_ring::parent_type(C)

coefficient_ring(e::SmashProductLieElem) = coefficient_ring(parent(e))

lie_algebra(Sp::SmashProductLie) = Sp.L
base_lie_algebra(
Sp::SmashProductLie{C, LieC, LieT},
) where {C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}} = Sp.L::parent_type(LieT)

lie_module(Sp::SmashProductLie) = Sp.V
base_module(Sp::SmashProductLie{C, LieC, LieT}) where {C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}} =
Sp.V::LieAlgebraModule{LieC}

underlying_algebra(Sp::SmashProductLie) = Sp.alg

ngens(Sp::SmashProductLie) = ngens(underlying_algebra(Sp))
function ngens(Sp::SmashProductLie, part::Symbol)
part == :L && return dim(lie_algebra(Sp))
part == :V && return dim(lie_module(Sp))
part == :L && return dim(base_lie_algebra(Sp))
part == :V && return dim(base_module(Sp))
error("Invalid part.")
end

gens(Sp::SmashProductLie) = map(Sp, gens(underlying_algebra(Sp)))
function gens(Sp::SmashProductLie, part::Symbol)
part == :L && return [Sp(gen(underlying_algebra(Sp), i)) for i in 1:dim(lie_algebra(Sp))]
part == :V && return [Sp(gen(underlying_algebra(Sp), i + dim(lie_algebra(Sp)))) for i in 1:dim(lie_module(Sp))]
part == :L && return [Sp(gen(underlying_algebra(Sp), i)) for i in 1:dim(base_lie_algebra(Sp))]
part == :V &&
return [Sp(gen(underlying_algebra(Sp), i + dim(base_lie_algebra(Sp)))) for i in 1:dim(base_module(Sp))]
error("Invalid part.")
end

gen(Sp::SmashProductLie, i::Int) = Sp(gen(underlying_algebra(Sp), i))
function gen(Sp::SmashProductLie, i::Int, part::Symbol)
@req 1 <= i <= ngens(Sp, part) "Invalid generator index."
part == :L && return Sp(gen(underlying_algebra(Sp), i))
part == :V && return Sp(gen(underlying_algebra(Sp), i + dim(lie_algebra(Sp))))
part == :V && return Sp(gen(underlying_algebra(Sp), i + dim(base_lie_algebra(Sp))))
error("Invalid part.")
end

Expand All @@ -101,7 +111,10 @@ function Base.deepcopy_internal(e::SmashProductLieElem, dict::IdDict)
return SmashProductLieElem(parent(e), deepcopy_internal(e.alg_elem, dict); simplified=e.simplified)
end

function check_parent(e1::SmashProductLieElem{C}, e2::SmashProductLieElem{C}) where {C <: RingElem}
function check_parent(
e1::SmashProductLieElem{C, LieC, LieT},
e2::SmashProductLieElem{C, LieC, LieT},
) where {C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}}
parent(e1) != parent(e2) && error("Incompatible smash products.")
end

Expand All @@ -111,16 +124,16 @@ end
#
###############################################################################

function show(io::IO, Sp::SmashProductLie{C, CL}) where {C <: RingElem, CL <: RingElem}
function show(io::IO, Sp::SmashProductLie{C, LieC}) where {C <: RingElem, LieC <: RingElem}
print(io, "Smash Product")
if CL != C
if LieC != C
print(io, " over ")
print(IOContext(io, :supercompact => true), coefficient_ring(underlying_algebra(Sp)))
end
print(io, " of ")
print(IOContext(io, :compact => true), lie_algebra(Sp))
print(IOContext(io, :compact => true), base_lie_algebra(Sp))
print(io, " and ")
print(IOContext(io, :compact => true), lie_module(Sp))
print(IOContext(io, :compact => true), base_module(Sp))
end


Expand All @@ -143,14 +156,16 @@ function (Sp::SmashProductLie)(e::Union{RingElement, NCRingElem})
return Sp(underlying_algebra(Sp)(e))
end

function (Sp::SmashProductLie{C, CL})(e::FreeAssAlgElem{C}) where {C <: RingElem, CL <: RingElem}
function (Sp::SmashProductLie{C})(e::FreeAssAlgElem{C}) where {C <: RingElem}
if underlying_algebra(Sp) !== parent(e)
e = underlying_algebra(Sp)(e)
end
return SmashProductLieElem(Sp, e)
end

function (Sp::SmashProductLie{C, CL})(e::SmashProductLieElem{C, CL}) where {C <: RingElem, CL <: RingElem}
function (Sp::SmashProductLie{C, LieC, LieT})(
e::SmashProductLieElem{C, LieC, LieT},
) where {C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}}
@req parent(e) == Sp "Incompatible smash products."
return e
end
Expand All @@ -165,17 +180,17 @@ function Base.:-(e::SmashProductLieElem)
return parent(e)(-e.alg_elem)
end

function Base.:+(e1::SmashProductLieElem{C}, e2::SmashProductLieElem{C}) where {C <: RingElem}
function Base.:+(e1::SmashProductLieElem, e2::SmashProductLieElem)
check_parent(e1, e2)
return parent(e1)(e1.alg_elem + e2.alg_elem)
end

function Base.:-(e1::SmashProductLieElem{C}, e2::SmashProductLieElem{C}) where {C <: RingElem}
function Base.:-(e1::SmashProductLieElem, e2::SmashProductLieElem)
check_parent(e1, e2)
return parent(e1)(e1.alg_elem - e2.alg_elem)
end

function Base.:*(e1::SmashProductLieElem{C}, e2::SmashProductLieElem{C}) where {C <: RingElem}
function Base.:*(e1::SmashProductLieElem, e2::SmashProductLieElem)
check_parent(e1, e2)
return parent(e1)(e1.alg_elem * e2.alg_elem)
end
Expand All @@ -185,7 +200,11 @@ function Base.:*(e::SmashProductLieElem{C}, c::C) where {C <: RingElem}
return parent(e)(e.alg_elem * c)
end

function Base.:*(e::SmashProductLieElem{C}, c::U) where {C <: RingElem, U <: Union{Rational, Integer}}
function Base.:*(e::SmashProductLieElem, c::U) where {U <: Union{Rational, IntegerUnion}}
return parent(e)(e.alg_elem * c)
end

function Base.:*(e::SmashProductLieElem{ZZRingElem}, c::ZZRingElem)
return parent(e)(e.alg_elem * c)
end

Expand All @@ -194,15 +213,19 @@ function Base.:*(c::C, e::SmashProductLieElem{C}) where {C <: RingElem}
return parent(e)(c * e.alg_elem)
end

function Base.:*(c::U, e::SmashProductLieElem{C}) where {C <: RingElem, U <: Union{Rational, Integer}}
function Base.:*(c::U, e::SmashProductLieElem) where {U <: Union{Rational, IntegerUnion}}
return parent(e)(c * e.alg_elem)
end

function Base.:*(c::ZZRingElem, e::SmashProductLieElem{ZZRingElem})
return parent(e)(c * e.alg_elem)
end

function Base.:^(e::SmashProductLieElem, n::Int)
return parent(e)(e.alg_elem^n)
end

function comm(e1::SmashProductLieElem{C}, e2::SmashProductLieElem{C}) where {C <: RingElem}
function comm(e1::SmashProductLieElem, e2::SmashProductLieElem)
check_parent(e1, e2)
return parent(e1)(e1.alg_elem * e2.alg_elem - e2.alg_elem * e1.alg_elem)
end
Expand All @@ -213,7 +236,10 @@ end
#
###############################################################################

function Base.:(==)(e1::SmashProductLieElem, e2::SmashProductLieElem)
function Base.:(==)(
e1::SmashProductLieElem{C, LieC, LieT},
e2::SmashProductLieElem{C, LieC, LieT},
) where {C <: RingElem, LieC <: RingElem, LieT <: LieAlgebraElem{LieC}}
return parent(e1) === parent(e2) && simplify(e1).alg_elem == simplify(e2).alg_elem
end

Expand Down Expand Up @@ -322,7 +348,7 @@ function smash_product(R::Ring, L::LieAlgebra{C}, V::LieAlgebraModule{C}) where
rels[dimL+j, i] = f_basisL[i] * f_basisV[j] - commutator
end

Sp = SmashProductLie{elem_type(R), C}(R, L, V, f_alg, rels)
Sp = SmashProductLie{elem_type(R), C, elem_type(L)}(R, L, V, f_alg, rels)

return Sp
end
Loading

0 comments on commit 858ed06

Please sign in to comment.