2017-06-22 15:04:51 +02:00
|
|
|
|
import Base: ×
|
2017-06-22 14:21:25 +02:00
|
|
|
|
|
|
|
|
|
export DirectProductGroup, DirectProductGroupElem
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# DirectProductGroup / DirectProductGroupElem
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
doc"""
|
2017-07-21 13:19:56 +02:00
|
|
|
|
DirectProductGroup(G::Group, n::Int) <: Group
|
|
|
|
|
Implements `n`-fold direct product of `G`. The group operation is
|
2017-06-22 14:21:25 +02:00
|
|
|
|
`*` distributed component-wise, with component-wise identity as neutral element.
|
|
|
|
|
"""
|
|
|
|
|
|
2017-07-12 21:05:21 +02:00
|
|
|
|
immutable DirectProductGroup{T<:Group} <: Group
|
2017-07-21 13:19:56 +02:00
|
|
|
|
group::T
|
|
|
|
|
n::Int
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-12 21:05:21 +02:00
|
|
|
|
immutable DirectProductGroupElem{T<:GroupElem} <: GroupElem
|
|
|
|
|
elts::Vector{T}
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# Type and parent object methods
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
2017-07-21 13:20:31 +02:00
|
|
|
|
elem_type{T<:Group}(G::DirectProductGroup{T}) =
|
|
|
|
|
DirectProductGroupElem{elem_type(G.group)}
|
2017-06-22 14:21:25 +02:00
|
|
|
|
|
2017-07-21 13:20:31 +02:00
|
|
|
|
parent_type{T<:GroupElem}(::Type{DirectProductGroupElem{T}}) =
|
|
|
|
|
DirectProductGroup{parent_type(T)}
|
2017-06-22 14:21:25 +02:00
|
|
|
|
|
2017-07-21 13:21:38 +02:00
|
|
|
|
parent(g::DirectProductGroupElem) =
|
|
|
|
|
DirectProductGroup(parent(first(g.elts)), length(g.elts))
|
2017-06-22 14:21:25 +02:00
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
2017-07-12 21:10:01 +02:00
|
|
|
|
# AbstractVector interface
|
2017-06-22 14:21:25 +02:00
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
2017-07-12 21:10:01 +02:00
|
|
|
|
Base.size(g::DirectProductGroupElem) = size(g.elts)
|
2017-09-13 15:43:56 +02:00
|
|
|
|
Base.IndexStyle(::Type{DirectProductGroupElem}) = Base.LinearFast()
|
2017-07-12 21:10:01 +02:00
|
|
|
|
Base.getindex(g::DirectProductGroupElem, i::Int) = g.elts[i]
|
|
|
|
|
function Base.setindex!{T<:GroupElem}(g::DirectProductGroupElem{T}, v::T, i::Int)
|
2017-07-23 03:24:05 +02:00
|
|
|
|
parent(v) == parent(first(g.elts)) || throw("$g is not an element of $i-th factor of $(parent(G))")
|
|
|
|
|
g.elts[i] = v
|
|
|
|
|
return g
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-12 21:10:01 +02:00
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# DirectProductGroup / DirectProductGroupElem constructors
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
2017-07-21 13:23:16 +02:00
|
|
|
|
function ×(G::Group, H::Group)
|
|
|
|
|
G == H || throw("Direct products are defined only for the same groups")
|
|
|
|
|
return DirectProductGroup(G,2)
|
|
|
|
|
end
|
2017-06-22 14:21:25 +02:00
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# Parent object call overloads
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
doc"""
|
2017-07-21 13:25:34 +02:00
|
|
|
|
(G::DirectProductGroup)(a::Vector, check::Bool=true)
|
|
|
|
|
> Constructs element of the $n$-fold direct product group `G` by coercing each
|
2017-07-23 17:04:22 +02:00
|
|
|
|
> element of vector `a` to `G.group`. If `check` flag is set to `false` neither
|
|
|
|
|
> check on the correctness nor coercion is performed.
|
2017-06-22 14:21:25 +02:00
|
|
|
|
"""
|
2017-07-21 13:25:34 +02:00
|
|
|
|
function (G::DirectProductGroup)(a::Vector, check::Bool=true)
|
|
|
|
|
if check
|
|
|
|
|
G.n == length(a) || throw("Can not coerce to DirectProductGroup: lengths differ")
|
|
|
|
|
a = G.group.(a)
|
|
|
|
|
end
|
2017-07-12 21:07:05 +02:00
|
|
|
|
return DirectProductGroupElem(a)
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-21 13:27:00 +02:00
|
|
|
|
(G::DirectProductGroup)() = DirectProductGroupElem([G.group() for _ in 1:G.n])
|
|
|
|
|
|
|
|
|
|
(G::DirectProductGroup)(g::DirectProductGroupElem) = G(g.elts)
|
|
|
|
|
|
2017-07-21 13:27:27 +02:00
|
|
|
|
(G::DirectProductGroup){T<:GroupElem, N}(a::Vararg{T, N}) = G([a...])
|
|
|
|
|
|
2017-06-22 14:21:25 +02:00
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# Basic manipulation
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
function deepcopy_internal(g::DirectProductGroupElem, dict::ObjectIdDict)
|
|
|
|
|
G = parent(g)
|
|
|
|
|
return G(deepcopy(g.elts))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function hash(G::DirectProductGroup, h::UInt)
|
2017-07-21 13:27:54 +02:00
|
|
|
|
return hash(G.group, hash(G.n, hash(DirectProductGroup,h)))
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function hash(g::DirectProductGroupElem, h::UInt)
|
2017-07-12 21:10:31 +02:00
|
|
|
|
return hash(g.elts, hash(parent(g), hash(DirectProductGroupElem, h)))
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# String I/O
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
function show(io::IO, G::DirectProductGroup)
|
2017-07-21 13:28:19 +02:00
|
|
|
|
println(io, "$(G.n)-fold direct product of $(G.group)")
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function show(io::IO, g::DirectProductGroupElem)
|
2017-07-21 13:28:19 +02:00
|
|
|
|
print(io, "($(join(g.elts,",")))")
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# Comparison
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
2017-07-21 13:28:19 +02:00
|
|
|
|
doc"""
|
|
|
|
|
==(g::DirectProductGroup, h::DirectProductGroup)
|
|
|
|
|
> Checks if two direct product groups are the same.
|
|
|
|
|
"""
|
2017-06-22 14:21:25 +02:00
|
|
|
|
function (==)(G::DirectProductGroup, H::DirectProductGroup)
|
2017-07-21 13:28:19 +02:00
|
|
|
|
G.group == H.group || return false
|
|
|
|
|
G.n == G.n || return false
|
2017-06-22 14:21:25 +02:00
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
doc"""
|
|
|
|
|
==(g::DirectProductGroupElem, h::DirectProductGroupElem)
|
2017-07-21 13:28:19 +02:00
|
|
|
|
> Checks if two direct product group elements are the same.
|
2017-06-22 14:21:25 +02:00
|
|
|
|
"""
|
|
|
|
|
function (==)(g::DirectProductGroupElem, h::DirectProductGroupElem)
|
|
|
|
|
g.elts == h.elts || return false
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
2017-07-23 03:24:40 +02:00
|
|
|
|
# Group operations
|
2017-06-22 14:21:25 +02:00
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
doc"""
|
|
|
|
|
*(g::DirectProductGroupElem, h::DirectProductGroupElem)
|
|
|
|
|
> Return the direct-product group operation of elements, i.e. component-wise
|
|
|
|
|
> operation as defined by `operations` field of the parent object.
|
|
|
|
|
"""
|
2017-07-21 13:30:35 +02:00
|
|
|
|
# TODO: dirty hack around `+/*` operations
|
|
|
|
|
function *{T<:GroupElem}(g::DirectProductGroupElem{T}, h::DirectProductGroupElem{T}, check::Bool=true)
|
|
|
|
|
if check
|
|
|
|
|
parent(g) == parent(h) || throw("Can not multiply elements of different groups!")
|
|
|
|
|
end
|
|
|
|
|
return DirectProductGroupElem([a*b for (a,b) in zip(g.elts,h.elts)])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function *{T<:RingElem}(g::DirectProductGroupElem{T}, h::DirectProductGroupElem{T}, check::Bool=true)
|
|
|
|
|
if check
|
|
|
|
|
parent(g) == parent(h) || throw("Can not multiply elements of different groups!")
|
|
|
|
|
end
|
2017-07-21 16:04:45 +02:00
|
|
|
|
return DirectProductGroupElem(g.elts + h.elts)
|
2017-07-21 13:30:35 +02:00
|
|
|
|
end
|
2017-06-22 14:21:25 +02:00
|
|
|
|
|
|
|
|
|
doc"""
|
|
|
|
|
inv(g::DirectProductGroupElem)
|
|
|
|
|
> Return the inverse of the given element in the direct product group.
|
|
|
|
|
"""
|
2017-07-21 13:30:35 +02:00
|
|
|
|
# TODO: dirty hack around `+/*` operation
|
|
|
|
|
function inv{T<:GroupElem}(g::DirectProductGroupElem{T})
|
|
|
|
|
return DirectProductGroupElem([inv(a) for a in g.elts])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function inv{T<:RingElem}(g::DirectProductGroupElem{T})
|
2017-07-21 16:04:45 +02:00
|
|
|
|
return DirectProductGroupElem(-g.elts)
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# Misc
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
doc"""
|
|
|
|
|
elements(G::DirectProductGroup)
|
2017-07-21 13:31:42 +02:00
|
|
|
|
> Returns `generator` that produces all elements of group `G` (provided that
|
|
|
|
|
> `G.group` implements the `elements` method).
|
2017-06-22 14:21:25 +02:00
|
|
|
|
"""
|
|
|
|
|
# TODO: can Base.product handle generators?
|
|
|
|
|
# now it returns nothing's so we have to collect ellements...
|
|
|
|
|
function elements(G::DirectProductGroup)
|
2017-07-21 13:31:42 +02:00
|
|
|
|
elts = collect(elements(G.group))
|
|
|
|
|
cartesian_prod = Base.product([elts for _ in 1:G.n]...)
|
|
|
|
|
return (DirectProductGroupElem([elt...]) for elt in cartesian_prod)
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
doc"""
|
|
|
|
|
order(G::DirectProductGroup)
|
|
|
|
|
> Returns the order (number of elements) in the group.
|
|
|
|
|
|
|
|
|
|
"""
|
2017-07-21 13:31:42 +02:00
|
|
|
|
order(G::DirectProductGroup) = order(G.group)^G.n
|