2017-03-13 18:03:48 +01:00
|
|
|
module GroupAlgebras
|
|
|
|
|
2017-05-16 18:27:32 +02:00
|
|
|
using Nemo
|
|
|
|
import Nemo: Group, GroupElem, Ring
|
|
|
|
|
2017-03-13 19:44:26 +01:00
|
|
|
import Base: convert, show, isequal, ==
|
|
|
|
import Base: +, -, *, //
|
|
|
|
import Base: size, length, norm, rationalize
|
2017-03-13 18:03:48 +01:00
|
|
|
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-16 18:28:32 +02:00
|
|
|
type GroupRing <: Ring
|
|
|
|
group::Group
|
|
|
|
pm::Array{Int,2}
|
|
|
|
basis::Vector{GroupElem}
|
|
|
|
basis_dict::Dict{GroupElem, Int}
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-16 18:28:32 +02:00
|
|
|
GroupRing(G::Group) = new(G)
|
|
|
|
end
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-16 18:29:14 +02:00
|
|
|
type GroupRingElem{T<:Number}
|
|
|
|
coeffs::AbstractVector{T}
|
|
|
|
parent::GroupRing
|
2017-03-13 19:44:26 +01:00
|
|
|
|
2017-05-16 18:29:14 +02:00
|
|
|
function GroupRingElem(coeffs::AbstractVector)
|
|
|
|
return new(coeffs)
|
|
|
|
end
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-05-16 18:31:45 +02:00
|
|
|
export GroupRing, GroupRingElem
|
2017-03-13 19:44:26 +01:00
|
|
|
|
|
|
|
|
2017-05-16 18:34:43 +02:00
|
|
|
elem_type(::GroupRing) = GroupRingElem
|
|
|
|
|
|
|
|
parent_type(::GroupRingElem) = GroupRing
|
|
|
|
|
|
|
|
parent(g::GroupRingElem) = g.parent
|
2017-03-13 19:44:26 +01:00
|
|
|
|
|
|
|
|
2017-05-16 18:31:26 +02:00
|
|
|
GroupRingElem{T}(c::AbstractVector{T}, A::GroupRing) = GroupRingElem{T}(c,A)
|
|
|
|
|
|
|
|
convert{T<:Number}(::Type{T}, X::GroupRingElem) =
|
|
|
|
GroupRingElem(parent(X), convert(AbstractVector{T}, X.coeffs))
|
2017-05-16 18:32:12 +02:00
|
|
|
|
|
|
|
function GroupRing(G::Group, pm::Array{Int,2})
|
|
|
|
size(pm,1) == size(pm,2) || throw("pm must be of size (n,n), got
|
|
|
|
$(size(pm))")
|
|
|
|
return GroupRing(Group, pm)
|
|
|
|
end
|
|
|
|
|
|
|
|
function GroupRing(G::Group, pm::Array{Int,2}, basis::Vector)
|
|
|
|
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")
|
|
|
|
basis_dict = Dict(g => i for (i,g) in enumerate(basis))
|
|
|
|
return GroupRing(Group, pm, basis, basis_dict)
|
|
|
|
end
|
|
|
|
|
|
|
|
function GroupRing(G::Group; complete=false)
|
|
|
|
A = GroupRing(Group)
|
|
|
|
if complete
|
|
|
|
complete(A)
|
|
|
|
end
|
|
|
|
return A
|
|
|
|
end
|
2017-05-16 18:34:21 +02:00
|
|
|
|
2017-05-16 18:35:20 +02:00
|
|
|
|
|
|
|
function (A::GroupRing)(X::GroupRingElem)
|
|
|
|
length(X) == length(A.basis) || throw("Can not coerce to $A: lengths differ")
|
|
|
|
X.parent = A
|
|
|
|
return X
|
|
|
|
end
|
|
|
|
|
|
|
|
function (A::GroupRing)(x::AbstractVector)
|
|
|
|
length(x) == length(A.basis) || throw("Can not coerce to $A: lengths differ")
|
|
|
|
return GroupRingElem(x, A)
|
|
|
|
end
|
|
|
|
|
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-16 18:34:21 +02:00
|
|
|
function show(io::IO, A::GroupRing)
|
|
|
|
print(io, "GroupRing of $(A.group)")
|
|
|
|
end
|
|
|
|
|
|
|
|
function show(io::IO, X::GroupRingElem)
|
|
|
|
T = eltype(X.coeffs)
|
|
|
|
print(io, "Element of Group Algebra of $(parent(X)) over $T:\n $(X.coeffs)")
|
|
|
|
end
|
|
|
|
|
2017-05-16 18:36:00 +02:00
|
|
|
|
|
|
|
function (==)(X::GroupRingElem, Y::GroupRingElem)
|
|
|
|
parent(X) == parent(Y) || return false
|
|
|
|
if eltype(X.coeffs) != eltype(S.coeffs)
|
|
|
|
warn("Comparing elements with different coeffs Rings!")
|
|
|
|
end
|
|
|
|
X.coeffs == Y.coeffs || return false
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function (==)(A::GroupRing, B::GroupRing)
|
|
|
|
return A.group == B.group
|
|
|
|
end
|
|
|
|
|
2017-05-16 18:41:12 +02:00
|
|
|
|
|
|
|
(-)(X::GroupRingElem) = GroupRingElem(-X.coeffs, parent(X))
|
|
|
|
|
|
|
|
(*){T<:Number}(a::T, X::GroupRingElem{T}) = GroupRingElem(
|
|
|
|
a*X.coeffs, parent(X))
|
|
|
|
|
|
|
|
function scalar_multiplication{T<:Number, S<:Number}(a::T,
|
|
|
|
X::GroupRingElem{S})
|
|
|
|
promote_type(T,S) == S || warn("Scalar and coeffs are in different rings! Promoting result to $(promote_type(T,S))")
|
|
|
|
return GroupRingElem(a*X.coeffs, parent(X))
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-05-16 18:41:12 +02:00
|
|
|
(*){T<:Number}(a::T,X::GroupRingElem) = scalar_multiplication(a, X)
|
|
|
|
|
|
|
|
(/){T<:Number}(a::T, X::GroupRingElem) = scalar_multiplication(1/a, X)
|
|
|
|
|
|
|
|
(//){T<:Rational, S<:Rational}(X::GroupRingElem{T}, a::S) =
|
|
|
|
GroupRingElem(X.coeffs//a, parent(X))
|
|
|
|
|
|
|
|
(//){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:37:55 +02:00
|
|
|
|
|
|
|
function add{T<:Number}(X::GroupRingElem{T}, Y::GroupRingElem{T})
|
|
|
|
parent(X) == parent(Y) || throw(ArgumentError(
|
2017-03-13 19:44:26 +01:00
|
|
|
"Elements don't seem to belong to the same Group Algebra!"))
|
2017-05-16 18:37:55 +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},
|
|
|
|
Y::GroupRingElem{S})
|
|
|
|
parent(X) == parent(Y) || throw(ArgumentError(
|
|
|
|
"Elements don't seem to belong to the same Group Algebra!"))
|
2017-03-13 19:44:26 +01:00
|
|
|
warn("Adding elements with different base rings!")
|
2017-05-16 18:37:55 +02:00
|
|
|
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
|
|
|
|
|
|
|
function algebra_multiplication{T<:Number}(X::AbstractVector{T}, Y::AbstractVector{T}, pm::Array{Int,2})
|
|
|
|
result = zeros(X)
|
|
|
|
for (j,y) in enumerate(Y)
|
|
|
|
if y != zero(T)
|
|
|
|
for (i, index) in enumerate(pm[:,j])
|
|
|
|
if X[i] != zero(T)
|
|
|
|
index == 0 && throw(ArgumentError("The product don't seem to belong to the span of basis!"))
|
|
|
|
result[index] += X[i]*y
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2017-05-16 18:38:37 +02:00
|
|
|
function group_star_multiplication{T<:Number}(X::GroupRingElem{T},
|
|
|
|
Y::GroupRingElem{T})
|
|
|
|
parent(X) == parent(Y) || throw(ArgumentError(
|
|
|
|
"Elements don't seem to belong to the same Group Algebra!"))
|
|
|
|
result = algebra_multiplication(X.coeffs, Y.coeffs, X.pm)
|
|
|
|
return GroupRingElem(result, parent(X))
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function group_star_multiplication{T<:Number, S<:Number}(
|
2017-05-16 18:38:37 +02:00
|
|
|
X::GroupRingElem{T}, Y::GroupRingElem{S})
|
|
|
|
warn("Multiplying elements with different base rings!")
|
|
|
|
return group_star_multiplication(promote(X,Y)...)
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
2017-05-16 18:38:37 +02:00
|
|
|
(*)(X::GroupRingElem, Y::GroupRingElem) = group_star_multiplication(X,Y)
|
2017-03-13 19:44:26 +01:00
|
|
|
|
|
|
|
|
2017-05-16 18:45:31 +02:00
|
|
|
length(X::GroupRingElem) = length(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-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-16 18:46:30 +02:00
|
|
|
function reverse_dict(a::AbstractVector)
|
|
|
|
return Dict{eltype(a), Int}(x => i for (i,x) in enumerate(a))
|
2017-03-13 19:44:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|