2017-05-16 21:06:44 +02:00
|
|
|
module GroupRings
|
2017-03-13 18:03:48 +01:00
|
|
|
|
2017-05-16 18:27:32 +02:00
|
|
|
using Nemo
|
2017-07-11 15:58:45 +02:00
|
|
|
import Nemo: Group, GroupElem, Ring, RingElem, parent, elem_type, parent_type, mul!, addeq!, divexact
|
2017-05-16 18:27:32 +02:00
|
|
|
|
2017-07-06 10:09:43 +02:00
|
|
|
import Base: convert, show, hash, ==, +, -, *, //, /, length, norm, rationalize, deepcopy_internal, getindex, setindex!, eltype, one, zero
|
2017-03-13 18:03:48 +01:00
|
|
|
|
2017-05-16 18:47:34 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# GroupRings / GroupRingsElem
|
|
|
|
#
|
|
|
|
###############################################################################
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-06-05 23:50:15 +02:00
|
|
|
type GroupRing{Gr<:Group, T<:GroupElem} <: Ring
|
|
|
|
group::Gr
|
|
|
|
basis::Vector{T}
|
|
|
|
basis_dict::Dict{T, Int}
|
2017-05-17 17:36:29 +02:00
|
|
|
pm::Array{Int,2}
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-07-25 14:43:04 +02:00
|
|
|
function GroupRing(G::Group, basis::Vector{T}; fastm::Bool=false)
|
2017-07-19 22:48:17 +02:00
|
|
|
RG = new(G, basis, reverse_dict(basis))
|
2017-07-25 14:43:04 +02:00
|
|
|
fastm && fastm!(RG)
|
2017-07-19 22:48:17 +02:00
|
|
|
return RG
|
2017-05-17 11:27:25 +02:00
|
|
|
end
|
2017-05-17 17:36:29 +02:00
|
|
|
|
2017-06-05 23:50:15 +02:00
|
|
|
function GroupRing(G::Gr, basis::Vector{T}, basis_dict::Dict{T,Int}, pm::Array{Int,2})
|
2017-05-17 17:36:29 +02:00
|
|
|
return new(G, basis, basis_dict, pm)
|
|
|
|
end
|
2017-07-19 22:48:17 +02:00
|
|
|
|
|
|
|
function GroupRing(G::Gr, pm::Array{Int,2})
|
|
|
|
RG = new(G)
|
|
|
|
RG.pm = pm
|
|
|
|
return RG
|
|
|
|
end
|
2017-05-16 18:28:32 +02:00
|
|
|
end
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-07-25 14:43:04 +02:00
|
|
|
GroupRing{Gr<:Group, T<:GroupElem}(G::Gr, basis::Vector{T}; fastm::Bool=true) =
|
|
|
|
GroupRing{Gr, T}(G, basis, fastm=fastm)
|
2017-06-05 23:50:15 +02:00
|
|
|
|
|
|
|
GroupRing{Gr<:Group, T<:GroupElem}(G::Gr, b::Vector{T}, b_d::Dict{T,Int}, pm::Array{Int,2}) = GroupRing{Gr, T}(G, b, b_d, pm)
|
|
|
|
|
2017-07-19 22:48:59 +02:00
|
|
|
GroupRing{Gr<:Group}(G::Gr, pm::Array{Int,2}) =
|
|
|
|
GroupRing{Gr, elem_type(G)}(G, pm)
|
|
|
|
|
2017-07-19 13:33:55 +02:00
|
|
|
type GroupRingElem{T<:Number} <: RingElem
|
2017-05-16 18:29:14 +02:00
|
|
|
coeffs::AbstractVector{T}
|
2017-07-19 13:33:55 +02:00
|
|
|
parent::GroupRing
|
2017-05-17 14:33:49 +02:00
|
|
|
|
2017-05-17 17:39:56 +02:00
|
|
|
function GroupRingElem(c::AbstractVector{T}, RG::GroupRing, check=true)
|
|
|
|
if check
|
2017-06-05 11:02:38 +02:00
|
|
|
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
|
|
|
|
warn("Basis of the GroupRing is not defined.")
|
|
|
|
end
|
2017-05-17 17:39:56 +02:00
|
|
|
end
|
|
|
|
return new(c, RG)
|
2017-05-17 14:33:49 +02:00
|
|
|
end
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-07-21 20:36:48 +02:00
|
|
|
export GroupRing, GroupRingElem, complete!, create_pm, star
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-16 18:47:34 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Type and parent object methods
|
|
|
|
#
|
|
|
|
###############################################################################
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-07-25 14:35:09 +02:00
|
|
|
elem_type(::Type{GroupRing}) = GroupRingElem
|
2017-05-16 18:34:43 +02:00
|
|
|
|
2017-07-06 10:06:17 +02:00
|
|
|
parent_type(::Type{GroupRingElem}) = GroupRing
|
2017-05-16 18:34:43 +02:00
|
|
|
|
2017-07-11 15:58:02 +02:00
|
|
|
eltype(X::GroupRingElem) = eltype(X.coeffs)
|
|
|
|
|
2017-07-25 14:47:59 +02:00
|
|
|
parent(g::GroupRingElem) = g.parent
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-07-11 15:58:02 +02:00
|
|
|
Base.promote_rule{T<:Number,S<:Number}(::Type{GroupRingElem{T}}, ::Type{GroupRingElem{S}}) = GroupRingElem{promote_type(T,S)}
|
|
|
|
|
|
|
|
function convert{T<:Number}(::Type{T}, X::GroupRingElem)
|
|
|
|
return GroupRingElem(convert(AbstractVector{T}, X.coeffs), parent(X))
|
|
|
|
end
|
|
|
|
|
2017-05-16 18:47:34 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# GroupRing / GroupRingElem constructors
|
|
|
|
#
|
|
|
|
###############################################################################
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-07-19 13:33:55 +02:00
|
|
|
function GroupRingElem{T<:Number}(c::AbstractVector{T}, RG::GroupRing)
|
|
|
|
return GroupRingElem{T}(c, RG)
|
2017-05-17 11:32:28 +02:00
|
|
|
end
|
2017-05-16 18:31:26 +02:00
|
|
|
|
2017-07-25 14:43:04 +02:00
|
|
|
function GroupRing(G::Group; fastm::Bool=false)
|
|
|
|
return GroupRing(G, [elements(G)...], fastm=fastm)
|
2017-05-17 17:40:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function GroupRing(G::Group, basis::Vector, pm::Array{Int,2})
|
2017-07-19 22:53:19 +02:00
|
|
|
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")
|
2017-07-25 14:48:48 +02:00
|
|
|
return GroupRing(G, basis, reverse_dict(basis), pm)
|
2017-05-16 18:32:12 +02:00
|
|
|
end
|
|
|
|
|
2017-05-16 18:47:34 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Parent object call overloads
|
|
|
|
#
|
|
|
|
###############################################################################
|
2017-05-16 18:35:20 +02:00
|
|
|
|
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)
|
|
|
|
|
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
|
|
|
|
2017-06-06 22:25:01 +02:00
|
|
|
function (RG::GroupRing)(T::Type=Int)
|
2017-07-19 22:51:56 +02:00
|
|
|
isdefined(RG, :basis) || throw("Can not coerce without basis of GroupRing")
|
2017-06-06 22:25:01 +02:00
|
|
|
return GroupRingElem(spzeros(T,length(RG.basis)), RG)
|
2017-05-17 11:34:39 +02:00
|
|
|
end
|
|
|
|
|
2017-06-06 22:25:01 +02:00
|
|
|
function (RG::GroupRing)(g::GroupElem, T::Type=Int)
|
2017-07-16 21:44:42 +02:00
|
|
|
g = RG.group(g)
|
2017-06-06 22:25:01 +02:00
|
|
|
result = RG(T)
|
|
|
|
result[g] = one(T)
|
2017-05-17 17:39:05 +02:00
|
|
|
return result
|
2017-05-16 18:35:20 +02:00
|
|
|
end
|
|
|
|
|
2017-06-06 22:25:01 +02:00
|
|
|
function (RG::GroupRing)(x::AbstractVector)
|
2017-07-19 22:51:56 +02:00
|
|
|
isdefined(RG, :basis) || throw("Can not coerce without basis of GroupRing")
|
2017-05-18 17:56:46 +02:00
|
|
|
length(x) == length(RG.basis) || throw("Can not coerce to $RG: lengths differ")
|
2017-05-17 17:39:05 +02:00
|
|
|
result = RG(eltype(x))
|
|
|
|
result.coeffs = x
|
|
|
|
return result
|
2017-05-16 18:35:20 +02:00
|
|
|
end
|
|
|
|
|
2017-06-05 21:36:31 +02:00
|
|
|
function (RG::GroupRing)(X::GroupRingElem)
|
|
|
|
RG == parent(X) || throw("Can not coerce!")
|
|
|
|
return RG(X.coeffs)
|
|
|
|
end
|
2017-05-17 17:39:05 +02:00
|
|
|
|
2017-06-05 21:37:11 +02:00
|
|
|
function (RG::GroupRing)(X::GroupRingElem, emb::Function)
|
2017-07-19 22:51:56 +02:00
|
|
|
isdefined(RG, :basis) || throw("Can not coerce without basis of GroupRing")
|
2017-07-12 20:54:20 +02:00
|
|
|
result = RG(eltype(X.coeffs))
|
|
|
|
T = typeof(X.coeffs)
|
|
|
|
result.coeffs = T(result.coeffs)
|
|
|
|
for g in parent(X).basis
|
|
|
|
result[emb(g)] = X[g]
|
|
|
|
end
|
|
|
|
return result
|
2017-06-05 21:37:11 +02:00
|
|
|
end
|
|
|
|
|
2017-05-16 18:47:34 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
2017-07-11 15:59:15 +02:00
|
|
|
# Basic manipulation && Array protocol
|
2017-05-16 18:47:34 +02:00
|
|
|
#
|
|
|
|
###############################################################################
|
2017-05-16 18:35:37 +02:00
|
|
|
|
|
|
|
function deepcopy_internal(X::GroupRingElem, dict::ObjectIdDict)
|
|
|
|
return GroupRingElem(deepcopy(X.coeffs), parent(X))
|
|
|
|
end
|
|
|
|
|
|
|
|
function hash(X::GroupRingElem, h::UInt)
|
2017-07-16 21:45:24 +02:00
|
|
|
return hash(full(X.coeffs), hash(parent(X), hash(GroupRingElem, h)))
|
2017-05-16 18:35:37 +02:00
|
|
|
end
|
|
|
|
|
2017-05-17 11:35:39 +02:00
|
|
|
function getindex(X::GroupRingElem, n::Int)
|
|
|
|
return X.coeffs[n]
|
|
|
|
end
|
|
|
|
|
|
|
|
function getindex(X::GroupRingElem, g::GroupElem)
|
|
|
|
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
|
2017-05-17 11:35:39 +02:00
|
|
|
end
|
|
|
|
|
2017-05-17 12:49:45 +02:00
|
|
|
function setindex!(X::GroupRingElem, value, g::GroupElem)
|
2017-05-17 11:35:39 +02:00
|
|
|
RG = parent(X)
|
|
|
|
typeof(g) == elem_type(RG.group) || throw("$g is not an element of $(RG.group)")
|
2017-06-05 21:38:03 +02:00
|
|
|
if !(g in keys(RG.basis_dict))
|
|
|
|
g = (RG.group)(g)
|
|
|
|
end
|
2017-07-11 18:28:30 +02:00
|
|
|
X.coeffs[RG.basis_dict[g]] = value
|
2017-05-17 11:35:39 +02:00
|
|
|
end
|
|
|
|
|
2017-07-11 15:59:15 +02:00
|
|
|
Base.size(X::GroupRingElem) = size(X.coeffs)
|
|
|
|
Base.linearindexing{T<:GroupRingElem}(::Type{T}) = Base.LinearFast()
|
2017-05-18 12:19:12 +02:00
|
|
|
|
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)
|
2017-06-05 11:02:38 +02:00
|
|
|
if X.coeffs == zero(X.coeffs)
|
|
|
|
T = eltype(X.coeffs)
|
2017-05-17 14:38:00 +02:00
|
|
|
print(io, "$(zero(T))*$((RG.group)())")
|
2017-06-05 11:02:38 +02:00
|
|
|
elseif isdefined(RG, :basis)
|
2017-05-19 10:32:09 +02:00
|
|
|
non_zeros = ((X.coeffs[i], RG.basis[i]) for i in findn(X.coeffs))
|
|
|
|
elts = ("$(sign(c)> 0? " + ": " - ")$(abs(c))*$g" for (c,g) in non_zeros)
|
2017-07-11 18:44:08 +02:00
|
|
|
str = join(elts, "")[2:end]
|
2017-07-10 19:21:38 +02:00
|
|
|
if sign(first(non_zeros)[1]) > 0
|
2017-07-11 18:44:08 +02:00
|
|
|
str = str[3:end]
|
2017-07-10 19:21:38 +02:00
|
|
|
end
|
|
|
|
print(io, str)
|
2017-06-05 11:02:38 +02:00
|
|
|
else
|
|
|
|
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)
|
|
|
|
parent(X) == parent(Y) || return false
|
2017-05-17 11:36:21 +02:00
|
|
|
if eltype(X.coeffs) != eltype(Y.coeffs)
|
2017-05-16 18:36:00 +02:00
|
|
|
warn("Comparing elements with different coeffs Rings!")
|
|
|
|
end
|
2017-05-17 17:41:34 +02:00
|
|
|
all(X.coeffs .== Y.coeffs) || return false
|
2017-05-16 18:36:00 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function (==)(A::GroupRing, B::GroupRing)
|
2017-05-17 17:44:13 +02:00
|
|
|
A.group == B.group || return false
|
2017-06-05 11:02:38 +02:00
|
|
|
if isdefined(A, :basis) && isdefined(B, :basis)
|
|
|
|
A.basis == B.basis || return false
|
|
|
|
else
|
|
|
|
warn("Bases of GroupRings are not defined, comparing products mats.")
|
2017-07-19 22:52:35 +02:00
|
|
|
A.pm == B.pm || return false
|
2017-06-05 11:02:38 +02:00
|
|
|
end
|
2017-05-17 17:44:13 +02:00
|
|
|
return true
|
2017-05-16 18:36:00 +02:00
|
|
|
end
|
|
|
|
|
2017-05-16 18:47:34 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Scalar operators
|
|
|
|
#
|
|
|
|
###############################################################################
|
2017-05-16 18:41:12 +02:00
|
|
|
|
|
|
|
(-)(X::GroupRingElem) = GroupRingElem(-X.coeffs, parent(X))
|
|
|
|
|
2017-06-06 22:29:02 +02:00
|
|
|
mul{T<:Number}(a::T, X::GroupRingElem{T}) = GroupRingElem(a*X.coeffs, parent(X))
|
2017-05-16 18:41:12 +02:00
|
|
|
|
2017-06-06 22:29:02 +02:00
|
|
|
function mul{T<:Number, S<:Number}(a::T, X::GroupRingElem{S})
|
2017-05-17 14:38:00 +02:00
|
|
|
promote_type(T,S) == S || warn("Scalar and coeffs are in different rings! Promoting result to $(promote_type(T,S))")
|
2017-05-17 11:36:47 +02:00
|
|
|
return GroupRingElem(a*X.coeffs, parent(X))
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-06-06 22:29:02 +02:00
|
|
|
(*)(a, X::GroupRingElem) = mul(a,X)
|
|
|
|
(*)(X::GroupRingElem, a) = mul(a,X)
|
2017-05-17 14:36:23 +02:00
|
|
|
|
|
|
|
# disallow Nemo.Rings to hijack *(::Integer, ::RingElem)
|
2017-06-06 22:29:02 +02:00
|
|
|
(*){T<:Integer}(a::T, X::GroupRingElem) = mul(a,X)
|
2017-05-16 18:41:12 +02:00
|
|
|
|
2017-06-06 18:44:00 +02:00
|
|
|
(/)(X::GroupRingElem, a) = 1/a*X
|
2017-05-16 18:41:12 +02:00
|
|
|
|
2017-05-18 12:19:41 +02:00
|
|
|
function (//){T<:Integer, S<:Integer}(X::GroupRingElem{T}, a::S)
|
|
|
|
U = typeof(X[1]//a)
|
|
|
|
warn("Rational division: promoting result to $U")
|
|
|
|
return convert(U, X)//a
|
|
|
|
end
|
|
|
|
|
2017-05-16 18:41:12 +02:00
|
|
|
(//){T<:Rational, S<:Rational}(X::GroupRingElem{T}, a::S) =
|
2017-05-17 11:36:47 +02:00
|
|
|
GroupRingElem(X.coeffs//a, parent(X))
|
2017-05-16 18:41:12 +02:00
|
|
|
|
2017-05-17 11:36:47 +02:00
|
|
|
(//){T<:Rational, S<:Integer}(X::GroupRingElem{T}, a::S) = X//convert(T,a)
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-16 18:47:34 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Binary operators
|
|
|
|
#
|
|
|
|
###############################################################################
|
2017-05-16 18:37:55 +02:00
|
|
|
|
2017-07-09 14:56:11 +02:00
|
|
|
function addeq!{T}(X::GroupRingElem{T}, Y::GroupRingElem{T})
|
|
|
|
X.coeffs .+= Y.coeffs
|
|
|
|
return X
|
|
|
|
end
|
|
|
|
|
2017-07-19 22:15:47 +02:00
|
|
|
function add{T<:Number}(X::GroupRingElem{T}, Y::GroupRingElem{T}, check::Bool=true)
|
|
|
|
if check
|
|
|
|
parent(X) == parent(Y) || throw("Elements don't seem to belong to the same Group Ring!")
|
|
|
|
end
|
2017-05-16 18:51:40 +02:00
|
|
|
return GroupRingElem(X.coeffs+Y.coeffs, parent(X))
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-05-16 18:37:55 +02:00
|
|
|
function add{T<:Number, S<:Number}(X::GroupRingElem{T},
|
2017-07-19 22:15:47 +02:00
|
|
|
Y::GroupRingElem{S}, check::Bool=true)
|
|
|
|
if check
|
|
|
|
parent(X) == parent(Y) || throw("Elements don't seem to belong to the same Group Ring!")
|
|
|
|
end
|
2017-05-16 18:51:40 +02:00
|
|
|
warn("Adding elements with different base rings!")
|
|
|
|
return GroupRingElem(+(promote(X.coeffs, Y.coeffs)...), parent(X))
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-05-16 18:37:55 +02:00
|
|
|
(+)(X::GroupRingElem, Y::GroupRingElem) = add(X,Y)
|
|
|
|
(-)(X::GroupRingElem, Y::GroupRingElem) = add(X,-Y)
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-07-19 23:00:44 +02:00
|
|
|
doc"""
|
|
|
|
mul!{T}(result::AbstractArray{T},
|
|
|
|
X::AbstractVector,
|
|
|
|
Y::AbstractVector,
|
|
|
|
pm::Array{Int,2})
|
|
|
|
> The most specialised multiplication for `X` and `Y` (`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!
|
|
|
|
"""
|
2017-07-19 22:19:58 +02:00
|
|
|
function mul!{T}(result::AbstractVector{T},
|
|
|
|
X::AbstractVector,
|
|
|
|
Y::AbstractVector,
|
|
|
|
pm::Array{Int,2})
|
2017-07-10 19:25:52 +02:00
|
|
|
z = zero(T)
|
2017-07-11 16:00:50 +02:00
|
|
|
result .= z
|
2017-07-25 14:49:17 +02:00
|
|
|
for j in 1:length(Y)
|
2017-07-12 20:43:12 +02:00
|
|
|
if Y[j] != z
|
|
|
|
for i in 1:size(pm,1)
|
2017-07-10 19:25:52 +02:00
|
|
|
if X[i] != z
|
2017-07-12 20:43:12 +02:00
|
|
|
pm[i,j] == 0 && throw(ArgumentError("The product don't seem to be supported on basis!"))
|
|
|
|
result[pm[i,j]] += X[i]*Y[j]
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
2017-05-16 18:51:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-07-21 17:15:38 +02:00
|
|
|
return result
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-07-19 23:00:44 +02:00
|
|
|
doc"""
|
|
|
|
mul!{T}(result::GroupRingElem{T},
|
|
|
|
X::GroupRingElem,
|
|
|
|
Y::GroupRingElem)
|
|
|
|
> 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
|
|
|
|
> remaining products.
|
|
|
|
> The method will fail with `KeyError` if product `X*Y` is not supported on
|
|
|
|
> `parent(X).basis`.
|
|
|
|
"""
|
2017-07-19 22:38:17 +02:00
|
|
|
function mul!{T}(result::GroupRingElem{T}, X::GroupRingElem, Y::GroupRingElem)
|
2017-07-11 16:02:43 +02:00
|
|
|
if result === X
|
|
|
|
result = deepcopy(result)
|
|
|
|
end
|
2017-07-19 22:38:17 +02:00
|
|
|
|
|
|
|
z = zero(T)
|
|
|
|
result.coeffs .= z
|
|
|
|
|
2017-07-21 17:16:38 +02:00
|
|
|
RG = parent(X)
|
|
|
|
|
2017-07-25 14:44:37 +02:00
|
|
|
if isdefined(RG, :pm)
|
|
|
|
s = size(RG.pm)
|
|
|
|
|
|
|
|
for j::Int in 1:length(Y.coeffs)
|
|
|
|
if Y.coeffs[j] != z
|
|
|
|
j <= s[2] || throw("Element in Y outside of support of RG.pm")
|
|
|
|
for i::Int in 1:length(X.coeffs)
|
|
|
|
if X.coeffs[i] != z
|
|
|
|
i <= s[1] || throw("Element in X outside of support of RG.pm")
|
|
|
|
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
|
|
|
|
for j::Int in 1:length(Y.coeffs)
|
|
|
|
if Y.coeffs[j] != z
|
|
|
|
for i::Int in 1:length(X.coeffs)
|
|
|
|
if X.coeffs[i] != z
|
|
|
|
result[RG.basis[i]*RG.basis[j]] += X[i]*Y[j]
|
2017-07-19 22:54:18 +02:00
|
|
|
end
|
2017-07-19 22:38:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-07-09 14:56:11 +02:00
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2017-07-19 22:55:44 +02:00
|
|
|
function *{T<:Number}(X::GroupRingElem{T}, Y::GroupRingElem{T}, check::Bool=true)
|
|
|
|
if check
|
|
|
|
parent(X) == parent(Y) || throw("Elements don't seem to belong to the same Group Ring!")
|
2017-07-12 11:34:43 +02:00
|
|
|
end
|
2017-07-19 22:55:44 +02:00
|
|
|
if isdefined(parent(X), :basis)
|
|
|
|
result = parent(X)(similar(X.coeffs))
|
|
|
|
result = mul!(result, X, Y)
|
|
|
|
else
|
2017-07-21 17:33:29 +02:00
|
|
|
result = mul!(similar(X.coeffs), X.coeffs, Y.coeffs, parent(X).pm)
|
2017-07-19 22:55:44 +02:00
|
|
|
result = GroupRingElem(result, parent(X))
|
2017-07-12 14:31:51 +02:00
|
|
|
end
|
2017-07-11 16:16:41 +02:00
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2017-07-19 22:43:46 +02:00
|
|
|
function *{T<:Number, S<:Number}(X::GroupRingElem{T}, Y::GroupRingElem{S}, check::Bool=true)
|
|
|
|
if true
|
|
|
|
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))
|
|
|
|
warn("Multiplying elements with different base rings! Promoting the result to $TT.")
|
|
|
|
|
2017-07-19 22:55:44 +02:00
|
|
|
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))
|
2017-07-19 22:55:44 +02:00
|
|
|
result = mul!(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-05-17 11:39:19 +02:00
|
|
|
end
|
|
|
|
|
2017-03-13 19:44:26 +01:00
|
|
|
|
|
|
|
|
2017-07-11 15:58:45 +02:00
|
|
|
function divexact{T}(X::GroupRingElem{T}, Y::GroupRingElem{T})
|
|
|
|
if length(Y) != 1
|
2017-07-24 22:50:52 +02:00
|
|
|
throw("Can not divide by a non-primitive element: $(Y)!")
|
2017-07-11 15:58:45 +02:00
|
|
|
else
|
|
|
|
idx = findfirst(Y)
|
|
|
|
c = Y[idx]
|
2017-07-24 22:50:52 +02:00
|
|
|
c != 0 || throw("Can not invert: $c not found in $Y")
|
2017-07-11 15:58:45 +02:00
|
|
|
g = parent(Y).basis[idx]
|
|
|
|
return X*1//c*parent(Y)(inv(g))
|
|
|
|
end
|
|
|
|
end
|
2017-07-11 22:37:53 +02:00
|
|
|
|
2017-05-17 12:34:24 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# *-involution
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
2017-05-17 14:37:22 +02:00
|
|
|
function star{T}(X::GroupRingElem{T})
|
2017-05-17 12:34:24 +02:00
|
|
|
RG = parent(X)
|
2017-07-19 22:51:56 +02:00
|
|
|
isdefined(RG, :basis) || throw("*-involution without basis is not possible")
|
2017-05-17 14:37:22 +02:00
|
|
|
result = RG(T)
|
2017-05-17 12:34:24 +02:00
|
|
|
for (i,c) in enumerate(X.coeffs)
|
2017-05-17 14:37:22 +02:00
|
|
|
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
|
|
|
|
2017-05-18 17:56:46 +02:00
|
|
|
length(X::GroupRingElem) = countnz(X.coeffs)
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-16 18:45:31 +02:00
|
|
|
norm(X::GroupRingElem, p=2) = norm(X.coeffs, p)
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-16 18:45:31 +02:00
|
|
|
augmentation(X::GroupRingElem) = sum(X.coeffs)
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-18 17:58:13 +02:00
|
|
|
function rationalize{T<:Integer, S<:Integer}(::Type{T}, X::GroupRingElem{S})
|
|
|
|
return convert(Rational{T}, X)
|
|
|
|
end
|
|
|
|
|
2017-05-16 18:45:56 +02:00
|
|
|
function rationalize{T<:Integer, S<:Number}(::Type{T}, X::GroupRingElem{S};
|
|
|
|
tol=eps(S))
|
|
|
|
v = rationalize(T, X.coeffs, tol=tol)
|
|
|
|
return GroupRingElem(v, parent(X))
|
|
|
|
end
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-17 17:43:11 +02:00
|
|
|
function reverse_dict(iter)
|
|
|
|
T = eltype(iter)
|
|
|
|
return Dict{T, Int}(x => i for (i,x) in enumerate(iter))
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-05-16 18:47:22 +02:00
|
|
|
function create_pm{T<:GroupElem}(basis::Vector{T}, basis_dict::Dict{T, Int},
|
2017-05-17 11:45:56 +02:00
|
|
|
limit=length(basis); twisted=false)
|
2017-05-16 18:47:22 +02:00
|
|
|
product_matrix = zeros(Int, (limit,limit))
|
|
|
|
for i in 1:limit
|
2017-05-17 11:45:56 +02:00
|
|
|
x = basis[i]
|
2017-05-16 18:47:22 +02:00
|
|
|
if twisted
|
|
|
|
x = inv(x)
|
|
|
|
end
|
|
|
|
for j in 1:limit
|
2017-05-17 11:45:56 +02:00
|
|
|
w = x*(basis[j])
|
2017-05-16 18:47:22 +02:00
|
|
|
product_matrix[i,j] = basis_dict[w]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return product_matrix
|
|
|
|
end
|
|
|
|
|
2017-05-17 17:44:51 +02:00
|
|
|
create_pm{T<:GroupElem}(b::Vector{T}) = create_pm(b, reverse_dict(b))
|
|
|
|
|
2017-07-19 22:56:41 +02:00
|
|
|
function complete!(RG::GroupRing)
|
|
|
|
if !isdefined(RG, :basis)
|
|
|
|
RG.basis = [elements(RG.group)...]
|
2017-05-17 11:47:59 +02:00
|
|
|
end
|
2017-07-25 14:43:37 +02:00
|
|
|
|
|
|
|
fastm!(RG, fill=true)
|
|
|
|
|
2017-07-19 22:57:59 +02:00
|
|
|
for linidx in find(RG.pm .== 0)
|
|
|
|
i,j = ind2sub(size(RG.pm), linidx)
|
|
|
|
RG.pm[i,j] = RG.basis_dict[RG.basis[i]*RG.basis[j]]
|
2017-05-17 11:47:59 +02:00
|
|
|
end
|
2017-07-19 22:57:59 +02:00
|
|
|
return RG
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-07-25 14:43:04 +02:00
|
|
|
function fastm!(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))
|
|
|
|
end
|
|
|
|
return RG
|
|
|
|
end
|
|
|
|
|
2017-05-16 18:49:40 +02:00
|
|
|
end # of module GroupRings
|