mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-25 18:15:29 +01:00
separate GSymbols
This commit is contained in:
parent
5f0a33d335
commit
b92276ade2
@ -22,7 +22,8 @@ Base.one(r::NCRingElem) = one(parent(r))
|
|||||||
# ParentType / ObjectType definition
|
# ParentType / ObjectType definition
|
||||||
#
|
#
|
||||||
|
|
||||||
abstract type AbstractFPGroup <: Group end
|
include("types.jl")
|
||||||
|
include("gsymbols.jl")
|
||||||
|
|
||||||
function Base.one(G::Gr) where Gr <: AbstractFPGroup
|
function Base.one(G::Gr) where Gr <: AbstractFPGroup
|
||||||
El = elem_type(G)
|
El = elem_type(G)
|
||||||
@ -34,25 +35,7 @@ end
|
|||||||
elem_type(G::Gr) where Gr <:AbstractFPGroup = elem_type(Gr) # fallback definition
|
elem_type(G::Gr) where Gr <:AbstractFPGroup = elem_type(Gr) # fallback definition
|
||||||
|
|
||||||
@doc doc"""
|
@doc doc"""
|
||||||
::GSymbol
|
|
||||||
> Abstract type which all group symbols of AbstractFPGroups should subtype. Each
|
|
||||||
> concrete subtype should implement fields:
|
|
||||||
> * `id` which is the `Symbol` representation/identification of a symbol
|
|
||||||
> * `pow` which is the (multiplicative) exponent of a symbol.
|
|
||||||
|
|
||||||
"""
|
|
||||||
abstract type GSymbol end
|
|
||||||
|
|
||||||
Base.iterate(s::GS, i=1) where GS<:GSymbol = i <= abs(s.pow) ? (GS(s.id, sign(s.pow)), i+1) : nothing
|
|
||||||
Base.length(s::GSymbol) = abs(s.pow)
|
|
||||||
Base.size(s::GSymbol) = (length(s), )
|
|
||||||
Base.eltype(s::GS) where GS<:GSymbol = GS
|
|
||||||
Base.isone(s::GSymbol) = iszero(s.pow)
|
|
||||||
|
|
||||||
change_pow(s::S, n::Integer) where S<:GSymbol = S(s.id, n)
|
|
||||||
Base.inv(s::GSymbol) = change_pow(s, -s.pow)
|
|
||||||
|
|
||||||
hash(s::S, h::UInt) where S<:GSymbol = hash(s.id, hash(s.pow, hash(S, h)))
|
|
||||||
|
|
||||||
abstract type GWord{T<:GSymbol} <: GroupElem end
|
abstract type GWord{T<:GSymbol} <: GroupElem end
|
||||||
|
|
||||||
@ -233,13 +216,6 @@ function (==)(W::T, Z::T) where T <: GWord
|
|||||||
hash(W) != hash(Z) && return false
|
hash(W) != hash(Z) && return false
|
||||||
return syllables(W) == syllables(Z)
|
return syllables(W) == syllables(Z)
|
||||||
end
|
end
|
||||||
|
|
||||||
function (==)(s::GSymbol, t::GSymbol)
|
|
||||||
isone(s) && isone(t) && return true
|
|
||||||
s.pow == t.pow && s.id == t.id && return true
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# Binary operators
|
# Binary operators
|
||||||
|
18
src/symbols.jl
Normal file
18
src/symbols.jl
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
change_pow(s::S, n::Integer) where S<:GSymbol = S(s.id, n)
|
||||||
|
|
||||||
|
function Base.iterate(s::GS, i=1) where GS<:GSymbol
|
||||||
|
return i <= abs(s.pow) ? (GS(s.id, sign(s.pow)), i+1) : nothing
|
||||||
|
end
|
||||||
|
Base.length(s::GSymbol) = abs(s.pow)
|
||||||
|
Base.size(s::GSymbol) = (length(s), )
|
||||||
|
Base.eltype(s::GS) where GS<:GSymbol = GS
|
||||||
|
|
||||||
|
Base.isone(s::GSymbol) = iszero(s.pow)
|
||||||
|
Base.inv(s::GSymbol) = change_pow(s, -s.pow)
|
||||||
|
Base.hash(s::S, h::UInt) where S<:GSymbol = hash(s.id, hash(s.pow, hash(S, h)))
|
||||||
|
|
||||||
|
function (==)(s::GSymbol, t::GSymbol)
|
||||||
|
isone(s) && isone(t) && return true
|
||||||
|
s.pow == t.pow && s.id == t.id && return true
|
||||||
|
return false
|
||||||
|
end
|
11
src/types.jl
Normal file
11
src/types.jl
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
abstract type AbstractFPGroup <: Group end
|
||||||
|
|
||||||
|
@doc doc"""
|
||||||
|
::GSymbol
|
||||||
|
> Represents a syllable.
|
||||||
|
> Abstract type which all group symbols of AbstractFPGroups should subtype. Each
|
||||||
|
> concrete subtype should implement fields:
|
||||||
|
> * `id` which is the `Symbol` representation/identification of a symbol
|
||||||
|
> * `pow` which is the (multiplicative) exponent of a symbol.
|
||||||
|
"""
|
||||||
|
abstract type GSymbol end
|
Loading…
Reference in New Issue
Block a user