diff --git a/src/AutGroup.jl b/src/AutGroup.jl index d58c2b6..28374bb 100644 --- a/src/AutGroup.jl +++ b/src/AutGroup.jl @@ -54,7 +54,7 @@ export Automorphism, AutGroup, Aut, SAut # ############################################################################### -elem_type(::AutGroup{N}) where N = Automorphism{N} +elem_type(::Type{AutGroup{N}}) where N = Automorphism{N} parent_type(::Automorphism{N}) where N = AutGroup{N} @@ -188,12 +188,6 @@ SAut(G::Group) = AutGroup(G, special=true) Automorphism{N}(s::AutSymbol) where N = Automorphism{N}(AutSymbol[s]) -function Base.one(G::AutGroup{N}) where N - id = Automorphism{N}(id_autsymbol()) - id.parent = G - return id -end - function (G::AutGroup{N})(f::AutSymbol) where N g = Automorphism{N}([f]) g.parent = G diff --git a/src/FPGroups.jl b/src/FPGroups.jl index 878c4ba..0c472cb 100644 --- a/src/FPGroups.jl +++ b/src/FPGroups.jl @@ -30,10 +30,9 @@ export FPGroupElem, FPGroup # ############################################################################### +elem_type(::Type{FPGroup}) = FPGroupElem parent_type(::Type{FPGroupElem}) = FPGroup -elem_type(::FPGroup) = FPGroupElem - ############################################################################### # # FPSymbol constructors @@ -59,12 +58,6 @@ FPGroup(H::FreeGroup) = FPGroup([FPSymbol(s) for s in H.gens]) # ############################################################################### -function Base.one(G::FPGroup) - id = FPGroupElem(FPSymbol[]) - id.parent = G - return id -end - function (G::FPGroup)(w::GWord) if isempty(w) return one(G) diff --git a/src/FreeGroup.jl b/src/FreeGroup.jl index a9b1408..36cf7c0 100644 --- a/src/FreeGroup.jl +++ b/src/FreeGroup.jl @@ -52,12 +52,6 @@ FreeGroup(a::Vector) = FreeGroup(FreeSymbol.(a)) # ############################################################################### -function Base.one(G::FreeGroup) - id = FreeGroupElem(FreeSymbol[]) - id.parent = G - return id -end - function (G::FreeGroup)(w::GroupWord{FreeSymbol}) if length(syllables(w)) > 0 for s in w.symbols diff --git a/src/Groups.jl b/src/Groups.jl index e700437..3fe742d 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -15,13 +15,25 @@ export elements using LinearAlgebra using Markdown -Base.one(G::Generic.PermGroup) = G(collect(1:G.n), false) + +Base.one(G::Generic.PermGroup) = Generic.Perm(G.n) +Base.one(r::NCRingElem) = one(parent(r)) ############################################################################### # # ParentType / ObjectType definition # -############################################################################### + +abstract type AbstractFPGroup <: Group end + +function Base.one(G::Gr) where Gr <: AbstractFPGroup + El = elem_type(G) + id = El(eltype(El)[]) + id.parent = G + return id +end + +elem_type(G::Gr) where Gr <:AbstractFPGroup = elem_type(Gr) # fallback definition @doc doc""" ::GSymbol @@ -46,6 +58,8 @@ hash(s::S, h::UInt) where S<:GSymbol = hash(s.id, hash(s.pow, hash(S, h))) abstract type GWord{T<:GSymbol} <: GroupElem end +# fallback definitions +Base.eltype(w::GW) where GW<:GWord = eltype(GW) @doc doc""" W::GroupWord{T} <: GWord{T<:GSymbol} <:GroupElem > Basic representation of element of a finitely presented group. `W.symbols` @@ -77,8 +91,8 @@ syllables(w::GWord) = w.symbols ismodified(w::GWord) = w.modified setmodified!(w::GWord) = (w.modified = true; w) unsetmodified!(w::GWord) = (w.modified = false; w) +Base.one(w::GWord) = one(parent(w)) -abstract type AbstractFPGroup <: Group end ############################################################################### #