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-05-17 14:32:17 +02:00
|
|
|
import Nemo: Group, GroupElem, Ring, RingElem, parent, elem_type, parent_type
|
2017-05-16 18:27:32 +02:00
|
|
|
|
2017-05-18 17:57:15 +02:00
|
|
|
import Base: convert, show, hash, ==, +, -, *, //, /, length, norm, rationalize, deepcopy_internal, getindex, setindex!, eltype, one
|
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-06-05 23:50:15 +02:00
|
|
|
function GroupRing(G::Gr; initialise=true)
|
2017-05-17 11:27:25 +02:00
|
|
|
A = new(G)
|
2017-05-19 10:00:41 +02:00
|
|
|
if initialise
|
2017-05-17 11:27:25 +02:00
|
|
|
complete(A)
|
|
|
|
end
|
|
|
|
return A
|
|
|
|
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-05-16 18:28:32 +02:00
|
|
|
end
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-06-05 23:50:15 +02:00
|
|
|
GroupRing{Gr<:Group}(G::Gr;initialise=true) = GroupRing{Gr, elem_type(G)}(G, initialise=initialise)
|
|
|
|
|
|
|
|
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-05-17 14:32:17 +02:00
|
|
|
type GroupRingElem{T<:Number} <: RingElem
|
2017-05-16 18:29:14 +02:00
|
|
|
coeffs::AbstractVector{T}
|
|
|
|
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-05-17 17:45:03 +02:00
|
|
|
export GroupRing, GroupRingElem, complete, create_pm
|
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-05-16 18:34:43 +02:00
|
|
|
elem_type(::GroupRing) = GroupRingElem
|
|
|
|
|
2017-07-06 10:06:17 +02:00
|
|
|
parent_type(::GroupRingElem) = GroupRing
|
|
|
|
parent_type(::Type{GroupRingElem}) = GroupRing
|
2017-05-16 18:34:43 +02:00
|
|
|
|
2017-05-17 11:30:35 +02:00
|
|
|
parent{T}(g::GroupRingElem{T}) = g.parent
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-16 18:47:34 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# GroupRing / GroupRingElem constructors
|
|
|
|
#
|
|
|
|
###############################################################################
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-17 12:30:33 +02:00
|
|
|
function GroupRingElem{T<:Number}(c::AbstractVector{T}, RG::GroupRing)
|
2017-05-17 14:33:49 +02:00
|
|
|
return GroupRingElem{T}(c, RG)
|
2017-05-17 11:32:28 +02:00
|
|
|
end
|
2017-05-16 18:31:26 +02:00
|
|
|
|
2017-05-17 17:43:37 +02:00
|
|
|
function convert{T<:Number}(::Type{T}, X::GroupRingElem)
|
|
|
|
return GroupRingElem(convert(AbstractVector{T}, X.coeffs), parent(X))
|
|
|
|
end
|
2017-05-17 12:28:59 +02:00
|
|
|
|
2017-05-16 18:32:12 +02:00
|
|
|
function GroupRing(G::Group, pm::Array{Int,2})
|
2017-05-17 17:43:37 +02:00
|
|
|
size(pm,1) == size(pm,2) || throw("pm must be square, got $(size(pm))")
|
2017-06-05 11:02:38 +02:00
|
|
|
RG = GroupRing(G, initialise=false)
|
|
|
|
RG.pm = pm
|
|
|
|
return RG
|
2017-05-16 18:32:12 +02:00
|
|
|
end
|
|
|
|
|
2017-05-17 17:40:32 +02:00
|
|
|
function GroupRing(G::Group, basis::Vector)
|
|
|
|
basis_dict = reverse_dict(basis)
|
|
|
|
pm = try
|
|
|
|
create_pm(basis, basis_dict)
|
|
|
|
catch err
|
|
|
|
isa(err, KeyError) && throw("Products are not supported on basis")
|
|
|
|
throw(err)
|
|
|
|
end
|
|
|
|
return GroupRing(G, basis, basis_dict, pm)
|
|
|
|
end
|
|
|
|
|
|
|
|
function GroupRing(G::Group, basis::Vector, pm::Array{Int,2})
|
2017-05-16 18:32:12 +02:00
|
|
|
size(pm,1) == size(pm,2) || throw("pm must be of size (n,n), got
|
|
|
|
$(size(pm))")
|
|
|
|
eltype(basis) == elem_type(G) || throw("basis must consist of elements of $G")
|
2017-05-17 11:34:03 +02:00
|
|
|
basis_dict = reverse_dict(basis)
|
2017-05-17 17:40:32 +02:00
|
|
|
return GroupRing(G, basis, basis_dict, 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-06-06 22:25:01 +02:00
|
|
|
function (RG::GroupRing)(T::Type=Int)
|
2017-05-17 11:34:39 +02:00
|
|
|
isdefined(RG, :basis) || throw("Complete the definition of GroupRing first")
|
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-05-17 17:39:05 +02:00
|
|
|
g = try
|
|
|
|
RG.group(g)
|
|
|
|
catch
|
|
|
|
throw("Can't coerce $g to the underlying group of $RG")
|
|
|
|
end
|
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-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)
|
|
|
|
result = RG(eltype(X.coeffs))
|
|
|
|
for g in parent(X).basis
|
|
|
|
result[emb(g)] = X[g]
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2017-05-16 18:47:34 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Basic manipulation
|
|
|
|
#
|
|
|
|
###############################################################################
|
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)
|
|
|
|
return hash(X.coeffs, hash(parent(X), h))
|
|
|
|
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)
|
|
|
|
else
|
|
|
|
X.coeffs[RG.basis_dict[g]] = value
|
|
|
|
end
|
2017-05-17 11:35:39 +02:00
|
|
|
end
|
|
|
|
|
2017-05-18 12:19:12 +02:00
|
|
|
eltype(X::GroupRingElem) = eltype(X.coeffs)
|
|
|
|
|
2017-05-18 17:57:15 +02:00
|
|
|
one(RG::GroupRing) = RG(RG.group())
|
|
|
|
|
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-05-17 12:31:16 +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)
|
|
|
|
join(io, elts, "")
|
2017-06-05 11:02:38 +02:00
|
|
|
else
|
|
|
|
warn("Basis of the parent Group is not defined, showing coeffs")
|
|
|
|
print(io, 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.")
|
|
|
|
end
|
|
|
|
A.pm == B.pm || return false
|
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
|
|
|
|
|
|
|
function add{T<:Number}(X::GroupRingElem{T}, Y::GroupRingElem{T})
|
2017-05-16 18:51:40 +02:00
|
|
|
parent(X) == parent(Y) || throw(ArgumentError(
|
2017-05-17 12:31:49 +02:00
|
|
|
"Elements don't seem to belong to the same Group Ring!"))
|
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-05-16 18:51:40 +02:00
|
|
|
Y::GroupRingElem{S})
|
|
|
|
parent(X) == parent(Y) || throw(ArgumentError(
|
2017-05-17 12:31:49 +02:00
|
|
|
"Elements don't seem to belong to the same Group Ring!"))
|
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-06-06 11:46:15 +02:00
|
|
|
function mul!{T<:Number}(X::AbstractVector{T}, Y::AbstractVector{T},
|
|
|
|
pm::Array{Int,2}, result::AbstractVector{T})
|
2017-05-16 18:51:40 +02:00
|
|
|
for (j,y) in enumerate(Y)
|
2017-05-17 11:37:48 +02:00
|
|
|
if y != zero(eltype(Y))
|
2017-05-16 18:51:40 +02:00
|
|
|
for (i, index) in enumerate(pm[:,j])
|
2017-05-17 11:37:48 +02:00
|
|
|
if X[i] != zero(eltype(X))
|
2017-05-16 18:51:40 +02:00
|
|
|
index == 0 && throw(ArgumentError("The product don't seem to belong to the span of basis!"))
|
|
|
|
result[index] += X[i]*y
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
2017-05-16 18:51:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-06-06 18:44:53 +02:00
|
|
|
function mul{T<:Number}(X::AbstractVector{T}, Y::AbstractVector{T},
|
2017-05-17 11:39:19 +02:00
|
|
|
pm::Array{Int,2})
|
|
|
|
result = zeros(X)
|
2017-06-06 18:44:53 +02:00
|
|
|
mul!(X,Y,pm,result)
|
2017-05-17 12:33:16 +02:00
|
|
|
return result
|
2017-05-17 11:39:19 +02:00
|
|
|
end
|
|
|
|
|
2017-06-06 18:44:53 +02:00
|
|
|
function mul(X::AbstractVector, Y::AbstractVector, pm::Array{Int,2})
|
2017-05-17 11:39:19 +02:00
|
|
|
T = promote_type(eltype(X), eltype(Y))
|
2017-05-17 12:32:46 +02:00
|
|
|
result = zeros(T, deepcopy(X))
|
2017-06-06 18:44:53 +02:00
|
|
|
mul!(X, Y, pm, result)
|
2017-05-17 12:32:46 +02:00
|
|
|
return result
|
2017-05-17 11:39:19 +02:00
|
|
|
end
|
|
|
|
|
2017-06-05 11:03:23 +02:00
|
|
|
function *{T<:Number}(X::GroupRingElem{T}, Y::GroupRingElem{T})
|
2017-05-16 18:38:37 +02:00
|
|
|
parent(X) == parent(Y) || throw(ArgumentError(
|
2017-05-17 12:31:49 +02:00
|
|
|
"Elements don't seem to belong to the same Group Ring!"))
|
2017-05-17 12:49:12 +02:00
|
|
|
RG = parent(X)
|
|
|
|
isdefined(RG, :pm) || complete(RG)
|
2017-06-06 18:44:53 +02:00
|
|
|
result = mul(X.coeffs, Y.coeffs, RG.pm)
|
2017-05-17 12:49:12 +02:00
|
|
|
return GroupRingElem(result, RG)
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-06-05 11:03:23 +02:00
|
|
|
function *{T<:Number, S<:Number}(X::GroupRingElem{T}, Y::GroupRingElem{S})
|
2017-05-17 11:45:18 +02:00
|
|
|
parent(X) == parent(Y) || throw("Elements don't seem to belong to the same
|
|
|
|
Group Ring!")
|
2017-05-16 18:38:37 +02:00
|
|
|
warn("Multiplying elements with different base rings!")
|
2017-05-17 12:49:12 +02:00
|
|
|
RG = parent(X)
|
|
|
|
isdefined(RG, :pm) || complete(RG)
|
2017-06-06 18:44:53 +02:00
|
|
|
result = mul(X.coeffs, Y.coeffs, RG.pm)
|
2017-05-17 12:49:12 +02:00
|
|
|
return GroupRingElem(result, RG)
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
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-05-17 12:49:12 +02:00
|
|
|
isdefined(RG, :basis) || complete(RG)
|
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-05-16 18:47:22 +02:00
|
|
|
function complete(A::GroupRing)
|
2017-05-17 11:47:59 +02:00
|
|
|
if !isdefined(A, :basis)
|
2017-05-18 21:50:57 +02:00
|
|
|
A.basis = [elements(A.group)...]
|
2017-05-17 11:47:59 +02:00
|
|
|
end
|
|
|
|
if !isdefined(A, :basis_dict)
|
|
|
|
A.basis_dict = reverse_dict(A.basis)
|
|
|
|
end
|
2017-05-16 18:47:22 +02:00
|
|
|
if !isdefined(A, :pm)
|
|
|
|
A.pm = try
|
2017-05-17 11:47:59 +02:00
|
|
|
create_pm(A.basis, A.basis_dict)
|
2017-05-16 18:47:22 +02:00
|
|
|
catch err
|
2017-05-17 11:47:59 +02:00
|
|
|
isa(err, KeyError) && throw("Product is not supported on basis")
|
2017-05-16 18:47:22 +02:00
|
|
|
throw(err)
|
|
|
|
end
|
2017-05-17 11:47:59 +02:00
|
|
|
end
|
2017-05-16 18:47:22 +02:00
|
|
|
return A
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-05-16 18:49:40 +02:00
|
|
|
end # of module GroupRings
|