GroupRings.jl/src/GroupRings.jl

605 lines
17 KiB
Julia
Raw Normal View History

2017-05-16 21:06:44 +02:00
module GroupRings
2018-07-27 00:23:19 +02:00
using AbstractAlgebra
import AbstractAlgebra: Group, NCRing, NCRingElem, parent, elem_type, parent_type, addeq!, mul!
2017-05-16 18:27:32 +02:00
2018-09-21 21:11:30 +02:00
using SparseArrays
using LinearAlgebra
using Markdown
2018-10-24 20:29:57 +02:00
import Base: convert, show, hash, ==, +, -, *, ^, //, /, length, getindex, setindex!, eltype, one, zero
GroupOrNCRing = Union{AbstractAlgebra.Group, AbstractAlgebra.NCRing}
GroupOrNCRingElem = Union{AbstractAlgebra.GroupElem, AbstractAlgebra.NCRingElem}
2017-05-16 18:47:34 +02:00
###############################################################################
#
# GroupRings / GroupRingsElem
#
###############################################################################
2017-03-13 19:44:26 +01:00
mutable struct GroupRing{Gr<:GroupOrNCRing, T<:GroupOrNCRingElem} <: NCRing
group::Gr
basis::Vector{T}
basis_dict::Dict{T, Int}
pm::Array{Int,2}
2017-03-13 19:44:26 +01:00
2019-01-09 16:53:44 +01:00
function GroupRing(G::Gr, basis::Vector{T};
cachedmul::Bool=false) where {Gr, T}
2018-09-24 00:30:44 +02:00
RG = new{Gr, T}(G, basis, reverse_dict(basis))
2019-01-09 16:53:44 +01:00
cachedmul && initializepm!(RG)
return RG
end
2018-09-24 00:30:44 +02:00
function GroupRing(G::Gr, b::Vector{T}, b_d::Dict{T, Int}, pm::Array{Int,2}) where {Gr,T}
return new{Gr, T}(G, b, b_d, pm)
end
2018-09-24 00:30:44 +02:00
function GroupRing(G::Gr, pm::Array{Int,2}) where {Gr}
2017-09-13 11:13:53 +02:00
RG = new{Gr, elem_type(G)}(G)
RG.pm = pm
return RG
end
2017-05-16 18:28:32 +02:00
end
2017-03-13 19:44:26 +01:00
mutable struct GroupRingElem{T, A<:AbstractVector, GR<:GroupRing} <: NCRingElem
2017-09-14 17:31:27 +02:00
coeffs::A
parent::GR
function GroupRingElem{T, A, GR}(c::AbstractVector{T}, RG::GR, check=true) where {T, A, GR}
if check
if isdefined(RG, :basis)
length(c) == length(RG.basis) || throw(
"Can't create GroupRingElem -- lengths differ: length(c) =
$(length(c)) != $(length(RG.basis)) = length(RG.basis)")
else
2018-10-01 10:57:55 +02:00
@warn("Basis of the GroupRing is not defined.")
end
end
2018-08-14 20:18:34 +02:00
return new{T, A, GR}(c, RG)
end
2017-03-13 19:44:26 +01:00
end
2018-08-13 19:27:43 +02:00
export GroupRing, GroupRingElem, complete!, create_pm, star, aug, supp
2017-03-13 19:44:26 +01:00
2018-08-14 20:18:34 +02:00
###############################################################################
#
# GroupRing / GroupRingElem constructors
#
###############################################################################
function GroupRingElem(c::AbstractVector, RG::GroupRing)
return GroupRingElem{eltype(c), typeof(c), typeof(RG)}(c, RG)
end
2019-01-09 16:53:44 +01:00
function GroupRing(G::Generic.PermGroup; cachedmul::Bool=false)
return GroupRing(G, vec(collect(G)), cachedmul=cachedmul)
2018-08-14 20:18:34 +02:00
end
function GroupRing(G::Group, basis::Vector, pm::Array{Int,2})
size(pm,1) == size(pm,2) || throw("pm must be square, got $(size(pm))")
eltype(basis) == elem_type(G) || throw("Basis must consist of elements of $G")
return GroupRing(G, basis, reverse_dict(basis), pm)
end
2017-05-16 18:47:34 +02:00
###############################################################################
#
# Type and parent object methods
#
###############################################################################
2017-03-13 19:44:26 +01:00
2017-09-14 17:31:27 +02:00
elem_type(::Type{GroupRing}) = GroupRingElem
2017-05-16 18:34:43 +02:00
2017-11-17 15:25:42 +01:00
eltype(::Type{GroupRingElem{T, A, Gr}}) where {T, A, Gr} = T
parent(g::GroupRingElem) = g.parent
2017-03-13 19:44:26 +01:00
2017-09-14 17:31:27 +02:00
parent_type(X::GroupRingElem) = typeof(parent(X))
import Base.promote_rule
promote_rule(::Type{GroupRingElem{T}}, ::Type{GroupRingElem{S}}) where {T,S} =
GroupRingElem{promote_type(T,S)}
2019-06-28 09:11:26 +02:00
function convert(::Type{T}, X::GroupRingElem) where T<:Number
2018-08-13 20:55:27 +02:00
return GroupRingElem(Vector{T}(X.coeffs), parent(X))
end
2017-03-13 19:44:26 +01:00
2017-05-16 18:47:34 +02:00
###############################################################################
#
# Parent object call overloads
#
###############################################################################
2018-08-14 19:28:24 +02:00
# sparse storage:
2017-07-10 19:26:44 +02:00
zero(RG::GroupRing, T::Type=Int) = RG(T)
one(RG::GroupRing, T::Type=Int) = RG(RG.group(), T)
2019-06-30 18:59:16 +02:00
one(RG::GroupRing{<:AbstractAlgebra.NCRing}, T::Type=Int) = RG(one(RG.group), T)
2017-07-10 19:26:44 +02:00
2018-08-14 19:28:24 +02:00
function (RG::GroupRing)(T::Type=Int)
isdefined(RG, :basis) || throw("Can not coerce without basis of GroupRing")
return GroupRingElem(spzeros(T,length(RG.basis)), RG)
end
2017-07-17 09:32:38 +02:00
function (RG::GroupRing)(i::Int, T::Type=Int)
elt = RG(T)
elt[RG.group()] = i
return elt
end
2017-07-10 19:26:44 +02:00
2019-06-30 18:59:16 +02:00
function (RG::GroupRing{<:AbstractAlgebra.NCRing})(i::Int, T::Type=Int)
elt = RG(T)
2019-02-21 15:03:32 +01:00
elt[one(RG.group)] = i
return elt
end
function (RG::GroupRing)(g::GroupOrNCRingElem, T::Type=Int)
result = RG(T)
2018-08-13 20:55:27 +02:00
result[RG.group(g)] = one(T)
return result
end
function (RG::GroupRing{Gr,T})(V::Vector{T}, S::Type=Int) where {Gr, T}
res = RG(S)
for g in V
2018-08-13 20:55:27 +02:00
res[g] += one(S)
end
return res
end
function (RG::GroupRing)(f::Function, X::GroupRingElem{T}) where T
isdefined(RG, :basis) || throw("Can not coerce without basis of GroupRing")
res = RG(T)
for g in supp(X)
res[f(g)] = X[g]
end
return res
end
2018-08-14 19:28:24 +02:00
# keep storage type
2019-06-28 09:11:26 +02:00
function (RG::GroupRing)(x::AbstractVector{T}) where T
isdefined(RG, :basis) || throw("Basis of GroupRing not defined. For advanced use the direct constructor of GroupRingElem is provided.")
2018-08-14 19:28:24 +02:00
length(x) == length(RG.basis) || throw("Can not coerce to $RG: lengths differ")
return GroupRingElem(x, RG)
end
function (RG::GroupRing)(X::GroupRingElem)
RG == parent(X) || throw("Can not coerce!")
return RG(X.coeffs)
end
2017-05-16 18:47:34 +02:00
###############################################################################
#
# Basic manipulation && Array protocol
2017-05-16 18:47:34 +02:00
#
###############################################################################
2017-05-16 18:35:37 +02:00
function hash(X::GroupRingElem, h::UInt)
return hash(X.coeffs, hash(parent(X), hash(GroupRingElem, h)))
2017-05-16 18:35:37 +02:00
end
function getindex(X::GroupRingElem, n::Int)
return X.coeffs[n]
end
function getindex(X::GroupRingElem, g::GroupOrNCRingElem)
return X.coeffs[parent(X).basis_dict[g]]
end
2017-05-17 12:49:45 +02:00
function setindex!(X::GroupRingElem, value, n::Int)
X.coeffs[n] = value
end
function setindex!(X::GroupRingElem, value, g::GroupOrNCRingElem)
RG = parent(X)
if !(g in keys(RG.basis_dict))
g = (RG.group)(g)
end
X.coeffs[RG.basis_dict[g]] = value
end
Base.size(X::GroupRingElem) = size(X.coeffs)
2018-08-13 20:55:27 +02:00
Base.IndexStyle(::Type{GroupRingElem}) = Base.LinearFast()
2019-01-09 16:52:40 +01:00
dense(X::GroupRingElem{T, A}) where {T, A<:DenseVector} = X
2018-10-01 10:08:40 +02:00
function dense(X::GroupRingElem{T, Sp}) where {T, Sp<:SparseVector}
return parent(X)(Vector(X.coeffs))
end
2019-01-09 16:52:40 +01:00
SparseArrays.sparse(X::GroupRingElem{T, Sp}) where {T, Sp<:SparseVector} = X
function SparseArrays.sparse(X::GroupRingElem{T, A}) where {T, A<:Vector}
return parent(X)(sparse(X.coeffs))
end
2017-05-16 18:47:34 +02:00
###############################################################################
#
# String I/O
#
###############################################################################
2017-05-16 18:34:21 +02:00
function show(io::IO, A::GroupRing)
2017-07-10 19:21:38 +02:00
print(io, "Group Ring of $(A.group)")
2017-05-16 18:34:21 +02:00
end
function show(io::IO, X::GroupRingElem)
2017-05-17 14:38:00 +02:00
RG = parent(X)
2019-01-02 16:13:41 +01:00
T = eltype(X.coeffs)
if X.coeffs == zero(X.coeffs)
2017-05-17 14:38:00 +02:00
print(io, "$(zero(T))*$((RG.group)())")
elseif isdefined(RG, :basis)
2018-09-21 21:11:30 +02:00
non_zeros = ((X.coeffs[i], RG.basis[i]) for i in findall(!iszero, X.coeffs))
2019-01-02 16:13:41 +01:00
elts = String[]
for (c,g) in non_zeros
sgn = (sign(c)>=0 ? " + " : " - ")
if c == T(1)
coeff = ""
else
coeff = "$(abs(c))"
end
push!(elts, sgn*coeff*"$(g)")
end
str = join(elts, "")
2017-07-10 19:21:38 +02:00
if sign(first(non_zeros)[1]) > 0
2019-01-02 16:13:41 +01:00
str = str[4:end]
2017-07-10 19:21:38 +02:00
end
print(io, str)
else
2018-10-01 10:57:55 +02:00
@warn("Basis of the parent Group is not defined, showing coeffs")
2017-07-10 19:21:38 +02:00
show(io, MIME("text/plain"), X.coeffs)
2017-05-17 12:31:04 +02:00
end
2017-05-16 18:34:21 +02:00
end
2017-05-16 18:47:34 +02:00
###############################################################################
#
# Comparison
#
###############################################################################
2017-05-16 18:36:00 +02:00
function (==)(X::GroupRingElem, Y::GroupRingElem)
2017-05-17 11:36:21 +02:00
if eltype(X.coeffs) != eltype(Y.coeffs)
2018-10-01 10:57:55 +02:00
@warn("Comparing elements with different coeffs Rings!")
2017-05-16 18:36:00 +02:00
end
suppX = supp(X)
suppX == supp(Y) || return false
for g in suppX
X[g] == Y[g] || return false
end
2017-05-16 18:36:00 +02:00
return true
end
function (==)(A::GroupRing, B::GroupRing)
A.group == B.group || return false
2019-01-09 16:53:44 +01:00
if isdefined(A, :basis) && isdefined(B, :basis)
A.basis == B.basis || return false
elseif isdefined(A, :pm) && isdefined(B, :pm)
2019-01-02 17:07:46 +01:00
A.pm == B.pm || return false
2018-08-15 19:27:19 +02:00
end
return true
2017-05-16 18:36:00 +02:00
end
2017-05-16 18:47:34 +02:00
###############################################################################
#
# Scalar operators
#
###############################################################################
(-)(X::GroupRingElem) = GroupRingElem(-X.coeffs, parent(X))
2019-06-28 09:11:26 +02:00
function mul!(a::T, X::GroupRingElem{T}) where T
2017-08-04 18:25:44 +02:00
X.coeffs .*= a
return X
end
2019-06-28 09:11:26 +02:00
mul(a::T, X::GroupRingElem{T}) where T = GroupRingElem(a*X.coeffs, parent(X))
2019-06-28 09:11:26 +02:00
function mul(a::T, X::GroupRingElem{S}) where {T<:Number, S}
TT = promote_type(T,S)
2019-01-17 08:32:09 +01:00
TT == S || @warn("Scalar and coeffs are in different rings! Promoting result to $(TT)")
return GroupRingElem(a.*X.coeffs, parent(X))
2017-03-13 19:44:26 +01:00
end
2019-03-15 08:05:14 +01:00
(*)(a::Number, X::GroupRingElem) = mul(a, X)
(*)(X::GroupRingElem, a::Number) = mul(a, X)
2018-07-27 00:23:19 +02:00
# disallow Rings to hijack *(::, ::GroupRingElem)
2019-03-15 08:05:14 +01:00
*(a::Union{AbstractFloat, Integer, RingElem, Rational}, X::GroupRingElem) = mul(a, X)
(/)(X::GroupRingElem, a) = 1/a*X
(//)(X::GroupRingElem, a::Union{Integer, Rational}) = 1//a*X
2017-03-13 19:44:26 +01:00
2018-10-24 20:29:57 +02:00
(^)(X::GroupRingElem, n::Integer) = Base.power_by_squaring(X, n)
2017-05-16 18:47:34 +02:00
###############################################################################
#
# Binary operators
#
###############################################################################
2017-05-16 18:37:55 +02:00
function addeq!(X::GroupRingElem, Y::GroupRingElem)
2018-08-13 19:31:58 +02:00
X.coeffs += Y.coeffs
return X
end
2018-08-13 19:31:58 +02:00
function +(X::GroupRingElem{T}, Y::GroupRingElem{T}) where T
return GroupRingElem(X.coeffs+Y.coeffs, parent(X))
2017-03-13 19:44:26 +01:00
end
function +(X::GroupRingElem{S}, Y::GroupRingElem{T}) where {S, T}
2018-10-01 10:57:55 +02:00
@warn("Adding elements with different coefficient rings, Promoting result to $(promote_type(T,S))")
2018-08-13 19:31:58 +02:00
return GroupRingElem(X.coeffs+Y.coeffs, parent(X))
2017-03-13 19:44:26 +01:00
end
-(X::GroupRingElem{T}, Y::GroupRingElem{T}) where T = addeq!((-Y), X)
function -(X::GroupRingElem{S}, Y::GroupRingElem{T}) where {S, T}
2018-10-01 10:57:55 +02:00
@warn("Adding elements with different coefficient rings, Promoting result to $(promote_type(T,S))")
addeq!((-Y), X)
end
2017-03-13 19:44:26 +01:00
2019-01-09 11:13:11 +01:00
@doc doc"""
fmac!(result::AbstractVector{T},
2018-08-13 20:55:27 +02:00
X::AbstractVector,
Y::AbstractVector,
2019-06-28 09:11:26 +02:00
pm::Array{Int,2}) where T
2018-11-22 19:59:09 +01:00
> Fused multiply-add for group ring coeffs using multiplication table `pm`.
2019-06-28 09:11:26 +02:00
> The result of X*Y in GroupRing is added in-place to `result`.
2017-07-19 23:00:44 +02:00
> Notes:
> * this method will silently produce false results if `X[k]` is non-zero for
> `k > size(pm,1)`.
> * This method will fail if any zeros (i.e. uninitialised entries) are present
> in `pm`.
2018-08-13 20:55:27 +02:00
> Use with extreme care!
2017-07-19 23:00:44 +02:00
"""
2018-11-22 19:59:09 +01:00
function fmac!(result::AbstractVector{T},
2018-08-13 20:55:27 +02:00
X::AbstractVector,
Y::AbstractVector,
2019-06-28 09:11:26 +02:00
pm::Array{Int,2}) where T
2017-07-10 19:25:52 +02:00
z = zero(T)
2018-11-22 19:59:09 +01:00
s1 = size(pm,1)
s2 = size(pm,2)
2019-06-28 09:11:26 +02:00
2018-11-22 19:59:09 +01:00
@inbounds for j in 1:s2
2017-07-12 20:43:12 +02:00
if Y[j] != z
2018-11-22 19:59:09 +01:00
for i in 1:s1
2017-07-10 19:25:52 +02:00
if X[i] != z
2017-07-12 20:43:12 +02:00
result[pm[i,j]] += X[i]*Y[j]
2017-03-13 19:44:26 +01:00
end
end
end
end
2017-07-21 17:15:38 +02:00
return result
2017-03-13 19:44:26 +01:00
end
2019-01-09 11:13:11 +01:00
@doc doc"""
2019-03-15 08:05:14 +01:00
GRmul!(result::AbstractVector{T}, X::AbstractVector, Y::AbstractVector,
2019-06-28 09:11:26 +02:00
pm::Matrix{<:Integer}) where T
2018-11-22 19:59:09 +01:00
> The most specialised multiplication for `X` and `Y` (intended for `coeffs` of
> `GroupRingElems`), using multiplication table `pm`.
> Notes:
> * this method will silently produce false results if `X[k]` is non-zero for
> `k > size(pm,1)`.
> * This method will fail if any zeros (i.e. uninitialised entries) are present
> in `pm`.
> Use with extreme care!
"""
function GRmul!(result::AbstractVector{T},
2018-11-22 19:59:09 +01:00
X::AbstractVector,
Y::AbstractVector,
2019-06-28 09:11:26 +02:00
pm::AbstractMatrix{<:Integer}) where T
2018-11-22 19:59:09 +01:00
z = zero(T)
result .= z
return fmac!(result, X, Y, pm)
2018-11-22 19:59:09 +01:00
end
2019-01-09 11:13:11 +01:00
@doc doc"""
2019-03-15 08:05:14 +01:00
mul!(result::GroupRingElem, X::GroupRingElem, Y::GroupRingElem)
2017-07-19 23:00:44 +02:00
> In-place multiplication for `GroupRingElem`s `X` and `Y`.
> `mul!` will make use the initialised entries of `pm` attribute of
> `parent(X)::GroupRing` (if available), and will compute and store in `pm` the
2017-11-03 16:39:01 +01:00
> remaining products necessary to perform the multiplication.
2017-07-19 23:00:44 +02:00
> The method will fail with `KeyError` if product `X*Y` is not supported on
> `parent(X).basis`.
"""
2018-09-21 21:11:30 +02:00
function mul!(result::GroupRingElem, X::GroupRingElem, Y::GroupRingElem)
if result === X
result = deepcopy(result)
end
2018-09-21 21:11:30 +02:00
T = eltype(result.coeffs)
z = zero(T)
result.coeffs .= z
RG = parent(X)
2017-08-27 20:38:02 +02:00
lX = length(X.coeffs)
lY = length(Y.coeffs)
2017-07-25 14:44:37 +02:00
if isdefined(RG, :pm)
s = size(RG.pm)
2018-09-21 21:11:30 +02:00
k = findprev(!iszero, X.coeffs, lX)
2019-01-08 03:17:56 +01:00
(k == nothing ? 0 : k) <= s[1] || throw("Element in X outside of support of parents product")
2018-09-21 21:11:30 +02:00
k = findprev(!iszero, Y.coeffs, lY)
2019-01-08 03:17:56 +01:00
(k == nothing ? 0 : k) <= s[2] || throw("Element in Y outside of support of parents product")
2017-07-25 14:44:37 +02:00
2017-08-27 20:38:02 +02:00
for j in 1:lY
2017-07-25 14:44:37 +02:00
if Y.coeffs[j] != z
2017-08-27 20:38:02 +02:00
for i in 1:lX
2017-07-25 14:44:37 +02:00
if X.coeffs[i] != z
if RG.pm[i,j] == 0
RG.pm[i,j] = RG.basis_dict[RG.basis[i]*RG.basis[j]]
end
result.coeffs[RG.pm[i,j]] += X[i]*Y[j]
end
end
end
end
else
2017-11-03 16:39:18 +01:00
for j in 1:lY
2017-07-25 14:44:37 +02:00
if Y.coeffs[j] != z
2017-11-03 16:39:18 +01:00
for i in 1:lX
2017-07-25 14:44:37 +02:00
if X.coeffs[i] != z
result[RG.basis[i]*RG.basis[j]] += X[i]*Y[j]
end
end
end
end
end
return result
end
2019-06-28 09:11:26 +02:00
function *(X::GroupRingElem{T}, Y::GroupRingElem{T}, check::Bool=true) where T
if check
parent(X) == parent(Y) || throw("Elements don't seem to belong to the same Group Ring!")
end
if isdefined(parent(X), :basis)
result = parent(X)(similar(X.coeffs))
result = mul!(result, X, Y)
else
result = GRmul!(similar(X.coeffs), X.coeffs, Y.coeffs, parent(X).pm)
result = GroupRingElem(result, parent(X))
end
2017-05-17 12:32:46 +02:00
return result
end
2019-06-28 09:11:26 +02:00
function *(X::GroupRingElem{T}, Y::GroupRingElem{S}, check::Bool=true) where {T,S}
2018-08-13 20:55:27 +02:00
if check
parent(X) == parent(Y) || throw("Elements don't seem to belong to the same Group Ring!")
end
TT = typeof(first(X.coeffs)*first(Y.coeffs))
2018-10-01 10:57:55 +02:00
@warn("Multiplying elements with different base rings! Promoting the result to $TT.")
if isdefined(parent(X), :basis)
result = parent(X)(similar(X.coeffs))
result = convert(TT, result)
result = mul!(result, X, Y)
else
2017-07-21 17:33:29 +02:00
result = convert(TT, similar(X.coeffs))
result = RGmul!(result, X.coeffs, Y.coeffs, parent(X).pm)
result = GroupRingElem(result, parent(X))
end
2017-05-17 12:32:46 +02:00
return result
2017-03-13 19:44:26 +01:00
end
2017-05-17 12:34:24 +02:00
###############################################################################
#
# *-involution
#
###############################################################################
2018-08-13 20:55:27 +02:00
function star(X::GroupRingElem{T}) where T
2017-05-17 12:34:24 +02:00
RG = parent(X)
isdefined(RG, :basis) || throw("*-involution without basis is not possible")
result = RG(T)
2017-05-17 12:34:24 +02:00
for (i,c) in enumerate(X.coeffs)
if c != zero(T)
2017-05-17 12:34:24 +02:00
g = inv(RG.basis[i])
result[g] = c
end
end
return result
end
2017-05-16 18:47:34 +02:00
###############################################################################
#
# Misc
#
###############################################################################
2017-03-13 19:44:26 +01:00
2018-09-21 21:11:30 +02:00
length(X::GroupRingElem) = count(!iszero, X.coeffs)
2017-03-13 19:44:26 +01:00
2019-01-09 16:52:40 +01:00
LinearAlgebra.norm(X::GroupRingElem, p::Int=2) = norm(X.coeffs, p)
2017-03-13 19:44:26 +01:00
2018-08-13 19:27:43 +02:00
aug(X::GroupRingElem) = sum(X.coeffs)
2018-09-21 21:11:30 +02:00
supp(X::GroupRingElem) = parent(X).basis[findall(!iszero, X.coeffs)]
2017-03-13 19:44:26 +01:00
2018-04-09 13:03:10 +02:00
function reverse_dict(::Type{I}, iter) where I<:Integer
length(iter) > typemax(I) && error("Can not produce reverse dict: $(length(iter)) is too large for $T")
return Dict{eltype(iter), I}(x => i for (i,x) in enumerate(iter))
2017-03-13 19:44:26 +01:00
end
2018-07-27 00:23:19 +02:00
reverse_dict(iter) = reverse_dict(Int, iter)
2018-04-09 13:03:10 +02:00
function create_pm(basis::AbstractVector{T}, basis_dict::Dict{T, Int},
limit::Int=length(basis); twisted::Bool=false, check=true) where T
product_matrix = zeros(Int, (limit,limit))
2017-08-04 15:55:46 +02:00
Threads.@threads for i in 1:limit
2017-05-17 11:45:56 +02:00
x = basis[i]
if twisted
x = inv(x)
end
for j in 1:limit
product_matrix[i,j] = basis_dict[x*basis[j]]
end
end
check && check_pm(product_matrix, basis, twisted)
return product_matrix
end
create_pm(b::AbstractVector{<:GroupOrNCRingElem}) = create_pm(b, reverse_dict(b))
2018-09-21 21:11:30 +02:00
function check_pm(product_matrix, basis, twisted=false)
idx = findfirst(product_matrix' .== 0)
2018-09-21 21:11:30 +02:00
if idx != nothing
2018-10-01 10:57:55 +02:00
@warn("Product is not supported on basis")
2018-09-21 21:11:30 +02:00
i,j = Tuple(idx)
x = basis[i]
if twisted
x = inv(x)
end
throw(KeyError(x*basis[j]))
end
return true
end
2017-07-19 22:56:41 +02:00
function complete!(RG::GroupRing)
2018-08-15 19:27:19 +02:00
isdefined(RG, :basis) || throw(ArgumentError("Provide basis for completion first!"))
2019-06-28 09:11:26 +02:00
if !isdefined(RG, :pm)
2019-01-09 16:53:44 +01:00
initializepm!(RG, fill=false)
return RG
end
2017-07-25 14:43:37 +02:00
2017-09-10 21:42:45 +02:00
warning = false
2018-09-21 21:11:30 +02:00
for idx in findall(RG.pm .== 0)
i,j = Tuple(idx)
2017-09-10 21:42:45 +02:00
g = RG.basis[i]*RG.basis[j]
if haskey(RG.basis_dict, g)
RG.pm[i,j] = RG.basis_dict[g]
else
if !warning
warning = true
end
end
2017-05-17 11:47:59 +02:00
end
2018-10-01 10:57:55 +02:00
warning && @warn("Some products were not supported on basis")
return RG
2017-03-13 19:44:26 +01:00
end
2019-01-09 16:53:44 +01:00
function initializepm!(RG::GroupRing; fill::Bool=false)
isdefined(RG, :basis) || throw("For baseless Group Rings You need to provide pm.")
isdefined(RG, :pm) && return RG
if fill
RG.pm = try
create_pm(RG.basis, RG.basis_dict)
catch err
isa(err, KeyError) && throw("Product is not supported on basis, $err.")
throw(err)
end
else
RG.pm = zeros(Int, length(RG.basis), length(RG.basis))
2017-05-17 11:47:59 +02:00
end
return RG
2017-03-13 19:44:26 +01:00
end
2017-05-16 18:49:40 +02:00
end # of module GroupRings