mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-25 18:15:29 +01:00
formatting
This commit is contained in:
parent
84bfbd7408
commit
75b7d9fab3
@ -7,6 +7,7 @@ version = "0.5.2"
|
||||
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
|
||||
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
|
||||
GroupsCore = "d5909c97-4eac-4ecc-a3dc-fdd0858a4120"
|
||||
KnuthBendix = "c2604015-7b3d-4a30-8a26-9074551ec60a"
|
||||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
||||
ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d"
|
||||
|
||||
|
@ -13,8 +13,7 @@ end
|
||||
|
||||
object(G::AutomorphismGroup) = G.group
|
||||
|
||||
function SpecialAutomorphismGroup(F::FreeGroup;
|
||||
ordering=KnuthBendix.LenLex, kwargs...)
|
||||
function SpecialAutomorphismGroup(F::FreeGroup; ordering = KnuthBendix.LenLex, kwargs...)
|
||||
|
||||
n = length(KnuthBendix.alphabet(F)) ÷ 2
|
||||
A, rels = gersten_relations(n, commutative = false)
|
||||
@ -35,7 +34,7 @@ end
|
||||
|
||||
equality_data(f::FPGroupElement{<:AutomorphismGroup}) = normalform!.(evaluate(f))
|
||||
|
||||
function Base.:(==)(g::A, h::A) where A<:FPGroupElement{<:AutomorphismGroup}
|
||||
function Base.:(==)(g::A, h::A) where {A<:FPGroupElement{<:AutomorphismGroup}}
|
||||
@assert parent(g) === parent(h)
|
||||
|
||||
if _isvalidhash(g) && _isvalidhash(h)
|
||||
@ -81,15 +80,15 @@ end
|
||||
|
||||
# eye-candy
|
||||
|
||||
Base.show(io::IO, ::Type{<:FPGroupElement{<:AutomorphismGroup{T}}}) where T <: FreeGroup = print(io, "Automorphism{$T}")
|
||||
Base.show(io::IO, ::Type{<:FPGroupElement{<:AutomorphismGroup{T}}}) where {T<:FreeGroup} =
|
||||
print(io, "Automorphism{$T,…}")
|
||||
|
||||
## Automorphism Evaluation
|
||||
|
||||
domain(f::FPGroupElement{<:AutomorphismGroup}) = deepcopy(parent(f).domain)
|
||||
# tuple(gens(object(parent(f)))...)
|
||||
|
||||
evaluate(f::FPGroupElement{<:AutomorphismGroup{<:FreeGroup}}) =
|
||||
evaluate!(domain(f), f)
|
||||
evaluate(f::FPGroupElement{<:AutomorphismGroup{<:FreeGroup}}) = evaluate!(domain(f), f)
|
||||
|
||||
function evaluate!(
|
||||
t::NTuple{N,T},
|
||||
|
@ -20,10 +20,8 @@ _isvalidhash(g::FPGroupElement) = bitget(g.savedhash, 1)
|
||||
_setnormalform(h::UInt, v::Bool) = bitset(h, v, 0)
|
||||
_setvalidhash(h::UInt, v::Bool) = bitset(h, v, 1)
|
||||
|
||||
_setnormalform!(g::FPGroupElement, v::Bool) =
|
||||
g.savedhash = _setnormalform(g.savedhash, v)
|
||||
_setvalidhash!(g::FPGroupElement, v::Bool) =
|
||||
g.savedhash = _setvalidhash(g.savedhash, v)
|
||||
_setnormalform!(g::FPGroupElement, v::Bool) = g.savedhash = _setnormalform(g.savedhash, v)
|
||||
_setvalidhash!(g::FPGroupElement, v::Bool) = g.savedhash = _setvalidhash(g.savedhash, v)
|
||||
|
||||
# To update hash use this internal method, possibly only after computing the
|
||||
# normal form of `g`:
|
||||
|
@ -29,6 +29,7 @@ word_type(G::AbstractFPGroup) = word_type(typeof(G))
|
||||
# the default:
|
||||
word_type(::Type{<:AbstractFPGroup}) = Word{UInt16}
|
||||
|
||||
# the default (results in free rewriting)
|
||||
rewriting(G::AbstractFPGroup) = alphabet(G)
|
||||
|
||||
function (G::AbstractFPGroup)(word::AbstractVector{<:Integer})
|
||||
@ -40,8 +41,7 @@ end
|
||||
|
||||
Base.one(G::AbstractFPGroup) = FPGroupElement(one(word_type(G)), G)
|
||||
|
||||
Base.eltype(::Type{FPG}) where {FPG<:AbstractFPGroup} =
|
||||
FPGroupElement{FPG, word_type(FPG)}
|
||||
Base.eltype(::Type{FPG}) where {FPG<:AbstractFPGroup} = FPGroupElement{FPG,word_type(FPG)}
|
||||
|
||||
include("iteration.jl")
|
||||
|
||||
@ -55,10 +55,7 @@ end
|
||||
GroupsCore.gens(G::AbstractFPGroup) = [gens(G, i) for i in 1:GroupsCore.ngens(G)]
|
||||
|
||||
# TODO: ProductReplacementAlgorithm
|
||||
function Base.rand(
|
||||
rng::Random.AbstractRNG,
|
||||
rs::Random.SamplerTrivial{<:AbstractFPGroup},
|
||||
)
|
||||
function Base.rand(rng::Random.AbstractRNG, rs::Random.SamplerTrivial{<:AbstractFPGroup})
|
||||
l = rand(10:100)
|
||||
G = rs[]
|
||||
nletters = length(alphabet(G))
|
||||
@ -72,10 +69,10 @@ mutable struct FPGroupElement{G<:AbstractFPGroup, W<:AbstractWord} <: GroupEleme
|
||||
savedhash::UInt
|
||||
parent::G
|
||||
|
||||
FPGroupElement(word::W, G::AbstractFPGroup) where W<:AbstractWord =
|
||||
FPGroupElement(word::W, G::AbstractFPGroup) where {W<:AbstractWord} =
|
||||
new{typeof(G),W}(word, UInt(0), G)
|
||||
|
||||
FPGroupElement(word::W, hash::UInt, G::AbstractFPGroup) where W<:AbstractWord =
|
||||
FPGroupElement(word::W, hash::UInt, G::AbstractFPGroup) where {W<:AbstractWord} =
|
||||
new{typeof(G),W}(word, hash, G)
|
||||
end
|
||||
|
||||
@ -92,7 +89,7 @@ end
|
||||
## GroupElement Interface for FPGroupElement
|
||||
|
||||
Base.parent(f::FPGroupElement) = f.parent
|
||||
GroupsCore.parent_type(::Type{<:FPGroupElement{G}}) where G = G
|
||||
GroupsCore.parent_type(::Type{<:FPGroupElement{G}}) where {G} = G
|
||||
|
||||
function Base.:(==)(g::FPGroupElement, h::FPGroupElement)
|
||||
@boundscheck @assert parent(g) === parent(h)
|
||||
@ -106,8 +103,7 @@ function Base.deepcopy_internal(g::FPGroupElement, stackdict::IdDict)
|
||||
return FPGroupElement(copy(word(g)), g.savedhash, parent(g))
|
||||
end
|
||||
|
||||
Base.inv(g::FPGroupElement) =
|
||||
(G = parent(g); FPGroupElement(inv(alphabet(G), word(g)), G))
|
||||
Base.inv(g::FPGroupElement) = (G = parent(g); FPGroupElement(inv(alphabet(G), word(g)), G))
|
||||
|
||||
function Base.:(*)(g::FPGroupElement, h::FPGroupElement)
|
||||
@boundscheck @assert parent(g) === parent(h)
|
||||
@ -125,7 +121,7 @@ struct FreeGroup{T} <: AbstractFPGroup
|
||||
gens::Vector{T}
|
||||
alphabet::KnuthBendix.Alphabet{T}
|
||||
|
||||
function FreeGroup(gens, A::KnuthBendix.Alphabet) where W
|
||||
function FreeGroup(gens, A::KnuthBendix.Alphabet) where {W}
|
||||
@assert length(gens) == length(unique(gens))
|
||||
@assert all(l -> l in KnuthBendix.letters(A), gens)
|
||||
return new{eltype(gens)}(gens, A)
|
||||
@ -133,8 +129,7 @@ struct FreeGroup{T} <: AbstractFPGroup
|
||||
end
|
||||
|
||||
function FreeGroup(A::Alphabet)
|
||||
@boundscheck @assert all(KnuthBendix.hasinverse(l, A)
|
||||
for l in KnuthBendix.letters(A))
|
||||
@boundscheck @assert all(KnuthBendix.hasinverse(l, A) for l in KnuthBendix.letters(A))
|
||||
return FreeGroup(KnuthBendix.letters(A), A)
|
||||
end
|
||||
|
||||
@ -161,7 +156,8 @@ function FPGroup(
|
||||
G::AbstractFPGroup,
|
||||
rels::AbstractVector{<:Pair{GEl,GEl}};
|
||||
ordering = KnuthBendix.LenLex,
|
||||
kwargs...) where GEl<:FPGroupElement
|
||||
kwargs...,
|
||||
) where {GEl<:FPGroupElement}
|
||||
|
||||
O = ordering(alphabet(G))
|
||||
for (lhs, rhs) in rels
|
||||
@ -177,7 +173,7 @@ end
|
||||
|
||||
function Base.show(io::IO, G::FPGroup)
|
||||
print(io, "⟨")
|
||||
Base.print_array(io, reshape(gens(G), (1, New.ngens(G))))
|
||||
Base.print_array(io, reshape(gens(G), (1, ngens(G))))
|
||||
print(io, " | ")
|
||||
Base.print_array(io, relations(G))
|
||||
print(io, "⟩")
|
||||
|
@ -21,7 +21,7 @@ end
|
||||
normalform!(res::GEl, g::GEl) where GEl<:FPGroupElement
|
||||
Compute the normal fom of `g`, storing it in `res`.
|
||||
"""
|
||||
function normalform!(res::GEl, g::GEl) where GEl<:FPGroupElement
|
||||
function normalform!(res::GEl, g::GEl) where {GEl<:FPGroupElement}
|
||||
@boundscheck @assert parent(res) === parent(g)
|
||||
if isnormalform(g)
|
||||
copyto!(res, g)
|
||||
|
Loading…
Reference in New Issue
Block a user