Skip to content

Commit

Permalink
cashes canonical matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelDavidMohr committed Mar 28, 2024
1 parent 0a70798 commit b91308a
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions src/Rings/orderings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1719,34 +1719,40 @@ end

# For ordering the generators (I think)
mutable struct ModOrdering{T} <: AbsModOrdering
gens::T
ord::Symbol
function ModOrdering(u::T, s::Symbol) where {T <: AbstractVector{Int}}
r = new{T}()
r.gens = u
r.ord = s
return r
end
gens::T
ord::Symbol
function ModOrdering(u::T, s::Symbol) where {T <: AbstractVector{Int}}
r = new{T}()
r.gens = u
r.ord = s
return r
end
end

mutable struct ModuleOrdering{S}
M::S
o::AbsModOrdering # must allow gen*mon or mon*gen product ordering
M::S
o::AbsModOrdering # must allow gen*mon or mon*gen product ordering

canonical_matrix::ZZMatrix

function ModuleOrdering(M::S, o::AbsModOrdering) where {S}
return new{S}(M, o)
end
end

base_ring(a::ModuleOrdering) = a.M

mutable struct ModProdOrdering <: AbsModOrdering
a::AbsOrdering
b::AbsOrdering
a::AbsOrdering
b::AbsOrdering
end

Base.:*(a::AbsGenOrdering, b::AbsModOrdering) = ModProdOrdering(a, b)

Base.:*(a::AbsModOrdering, b::AbsGenOrdering) = ModProdOrdering(a, b)

# For equality checking and hashing
# we produce a matrix representation by embedding the module (and its ordering) into a polynomial ring
# we produce a matrix representation by embedding the underlying free module (and its ordering) into a polynomial ring
# then we build the matrix in this ring

function _embedded_ring_ordering(o::ModuleOrdering)
Expand All @@ -1769,18 +1775,25 @@ function _embedded_ring_ordering(o::ModProdOrdering)
return ea*eb
end

function _canonical_matrix(o::ModuleOrdering)
function _canonical_matrix_intern(o::ModuleOrdering)
nvrs = ngens(o.M) + ngens(base_ring(o.M))
eo = _embedded_ring_ordering(o)
return canonical_matrix(nvrs, eo)
end

function canonical_matrix(o::ModuleOrdering)
if !isdefined(o, :canonical_matrix)
o.canonical_matrix = _canonical_matrix_intern(o)
end
return o.canonical_matrix
end

function Base.:(==)(o1::ModuleOrdering, o2::ModuleOrdering)
return _canonical_matrix(o1) == _canonical_matrix(o2)
return canonical_matrix(o1) == canonical_matrix(o2)
end

function Base.hash(o::ModuleOrdering, h::UInt)
return hash(_canonical_matrix(o), h)
return hash(canonical_matrix(o), h)
end

#### _cmp_vector_monomials: cmp f[k]*gen(m) with g[l]*gen(n)
Expand Down

0 comments on commit b91308a

Please sign in to comment.