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)
|
|
|
|
|
Base.linearindexing(::Type{DirectProductGroupElem}) = Base.LinearFast()
|
|
|
|
|
Base.getindex(g::DirectProductGroupElem, i::Int) = g.elts[i]
|
|
|
|
|
function Base.setindex!{T<:GroupElem}(g::DirectProductGroupElem{T}, v::T, i::Int)
|
|
|
|
|
p.part[i] = v
|
|
|
|
|
return p
|
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
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
2017-07-12 21:07:05 +02:00
|
|
|
|
(G::DirectProductGroup)(g::DirectProductGroupElem) = G(g.elts)
|
2017-06-22 14:21:25 +02:00
|
|
|
|
|
|
|
|
|
doc"""
|
|
|
|
|
(G::DirectProductGroup)(a::Vector; checked=true)
|
|
|
|
|
> Constructs element of the direct product group `G` by coercing each element
|
|
|
|
|
> of vector `a` to the corresponding factor of `G`. If `checked` flag is set to
|
|
|
|
|
> `false` no checks on the correctness are performed.
|
|
|
|
|
|
|
|
|
|
"""
|
2017-07-12 21:07:05 +02:00
|
|
|
|
function (G::DirectProductGroup){T<:GroupElem}(a::Vector{T})
|
2017-06-22 14:21:25 +02:00
|
|
|
|
length(a) == length(G.factors) || throw("Cannot coerce $a to $G: they have
|
|
|
|
|
different number of factors")
|
2017-07-12 21:07:05 +02:00
|
|
|
|
@assert elem_type(first(G.factors)) == T
|
|
|
|
|
return DirectProductGroupElem(a)
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# 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-12 21:11:12 +02:00
|
|
|
|
return hash(G.factors, 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
|
|
|
|
|
|
|
|
|
|
doc"""
|
|
|
|
|
eye(G::DirectProductGroup)
|
|
|
|
|
> Return the identity element for the given direct product of groups.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
eye(G::DirectProductGroup) = G()
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# String I/O
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
function show(io::IO, G::DirectProductGroup)
|
|
|
|
|
println(io, "Direct product of groups")
|
|
|
|
|
join(io, G.factors, ", ", " and ")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function show(io::IO, g::DirectProductGroupElem)
|
|
|
|
|
print(io, "("*join(g.elts,",")*")")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# Comparison
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
function (==)(G::DirectProductGroup, H::DirectProductGroup)
|
|
|
|
|
G.factors == H.factors || return false
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
doc"""
|
|
|
|
|
==(g::DirectProductGroupElem, h::DirectProductGroupElem)
|
|
|
|
|
> Return `true` if the given elements of direct products are equal, otherwise return `false`.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
function (==)(g::DirectProductGroupElem, h::DirectProductGroupElem)
|
|
|
|
|
parent(g) == parent(h) || return false
|
|
|
|
|
g.elts == h.elts || return false
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# Binary operators
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
function direct_mult(g::DirectProductGroupElem, h::DirectProductGroupElem)
|
2017-07-12 21:11:50 +02:00
|
|
|
|
G = parent(g)
|
|
|
|
|
# G == parent(h) || throw("Can't multiply elements from different groups: $G, $parent(h)")
|
|
|
|
|
if isa(first(G.factors), Ring)
|
|
|
|
|
return G(.+(g.elts,h.elts))
|
|
|
|
|
else
|
|
|
|
|
return G(.*(g.elts,h.elts))
|
|
|
|
|
end
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
(*)(g::DirectProductGroupElem, h::DirectProductGroupElem) = direct_mult(g,h)
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# Inversion
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
doc"""
|
|
|
|
|
inv(g::DirectProductGroupElem)
|
|
|
|
|
> Return the inverse of the given element in the direct product group.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
# TODO: dirty hack around `+` operation
|
|
|
|
|
function inv(g::DirectProductGroupElem)
|
|
|
|
|
G = parent(g)
|
2017-07-12 21:11:50 +02:00
|
|
|
|
if isa(first(G.factors), Ring)
|
|
|
|
|
return DirectProductGroupElem([-a for a in g.elts])
|
|
|
|
|
else
|
|
|
|
|
return DirectProductGroupElem([inv(a) for a in g.elts])
|
|
|
|
|
end
|
2017-06-22 14:21:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
#
|
|
|
|
|
# Misc
|
|
|
|
|
#
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
doc"""
|
|
|
|
|
elements(G::DirectProductGroup)
|
|
|
|
|
> Returns `Task` that produces all elements of group `G` (provided that factors
|
|
|
|
|
> implement the elements function).
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
# TODO: can Base.product handle generators?
|
|
|
|
|
# now it returns nothing's so we have to collect ellements...
|
|
|
|
|
function elements(G::DirectProductGroup)
|
|
|
|
|
cartesian_prod = Base.product([collect(elements(H)) for H in G.factors]...)
|
|
|
|
|
return (G(collect(elt)) for elt in cartesian_prod)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
doc"""
|
|
|
|
|
order(G::DirectProductGroup)
|
|
|
|
|
> Returns the order (number of elements) in the group.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
order(G::DirectProductGroup) = prod([order(H) for H in G.factors])
|