1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-04 18:11:26 +01:00

Brave new constructors

This commit is contained in:
kalmar 2017-07-12 21:07:05 +02:00
parent 6b84254416
commit 799878ded5

View File

@ -40,30 +40,11 @@ parent(g::DirectProductGroupElem) = DirectProductGroup([parent(h) for h in g.elt
# #
############################################################################### ###############################################################################
DirectProductGroup(G::Group, H::Group) = DirectProductGroup([G, H], Function[(*),(*)])
DirectProductGroup(G::Group, H::Ring) = DirectProductGroup([G, H], Function[(*),(+)])
DirectProductGroup(G::Ring, H::Group) = DirectProductGroup([G, H], Function[(+),(*)])
DirectProductGroup(G::Ring, H::Ring) = DirectProductGroup([G, H], Function[(+),(+)])
DirectProductGroup{T<:Ring}(X::Vector{T}) = DirectProductGroup(Group[X...], Function[(+) for _ in X])
×(G::Group, H::Group) = DirectProductGroup(G,H)
function DirectProductGroup{T<:Group, S<:Group}(G::Tuple{T, Function}, H::Tuple{S, Function})
return DirectProductGroup([G[1], H[1]], Function[G[2],H[2]])
end end
function DirectProductGroup(groups::Vector) DirectProductGroup{T<:Group}(G::T, H::T) = DirectProductGroup{T}([G, H])
for G in groups
typeof(G) <: Group || throw("$G is not a group!")
end
ops = Function[typeof(G) <: Ring ? (+) : (*) for G in groups]
return DirectProductGroup(groups, ops) ×(G::Group, H::Group) = DirectProductGroup([G,H])
end
############################################################################### ###############################################################################
# #
@ -71,16 +52,9 @@ end
# #
############################################################################### ###############################################################################
(G::DirectProductGroup)() = G([H() for H in G.factors]; checked=false) (G::DirectProductGroup)() = G([H() for H in G.factors])
function (G::DirectProductGroup)(g::DirectProductGroupElem; checked=true) (G::DirectProductGroup)(g::DirectProductGroupElem) = G(g.elts)
if checked
return G(g.elts)
else
g.parent = G
return g
end
end
doc""" doc"""
(G::DirectProductGroup)(a::Vector; checked=true) (G::DirectProductGroup)(a::Vector; checked=true)
@ -89,21 +63,11 @@ doc"""
> `false` no checks on the correctness are performed. > `false` no checks on the correctness are performed.
""" """
function (G::DirectProductGroup)(a::Vector; checked=true) function (G::DirectProductGroup){T<:GroupElem}(a::Vector{T})
length(a) == length(G.factors) || throw("Cannot coerce $a to $G: they have length(a) == length(G.factors) || throw("Cannot coerce $a to $G: they have
different number of factors") different number of factors")
if checked @assert elem_type(first(G.factors)) == T
for (F,g) in zip(G.factors, a) return DirectProductGroupElem(a)
try
F(g)
catch
throw("Cannot coerce to $G: $g cannot be coerced to $F.")
end
end
end
elt = DirectProductGroupElem([F(g) for (F,g) in zip(G.factors, a)])
elt.parent = G
return elt
end end
############################################################################### ###############################################################################