mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-11-04 02:50:28 +01:00
simplify the constructors of the FreeGroup
This commit is contained in:
parent
efbb4eada8
commit
a33b871754
27
src/types.jl
27
src/types.jl
@ -177,9 +177,16 @@ struct FreeGroup{T,O} <: AbstractFPGroup
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
FreeGroup(gens, A::Alphabet) = FreeGroup(gens, KnuthBendix.LenLex(A))
|
function FreeGroup(n::Integer)
|
||||||
|
symbols =
|
||||||
|
collect(Iterators.flatten((Symbol(:f, i), Symbol(:F, i)) for i in 1:n))
|
||||||
|
inverses = collect(Iterators.flatten((2i, 2i - 1) for i in 1:n))
|
||||||
|
return FreeGroup(Alphabet(symbols, inverses))
|
||||||
|
end
|
||||||
|
|
||||||
function FreeGroup(A::Alphabet)
|
FreeGroup(A::Alphabet) = FreeGroup(KnuthBendix.LenLex(A))
|
||||||
|
|
||||||
|
function __group_gens(A::Alphabet)
|
||||||
@boundscheck @assert all(KnuthBendix.hasinverse(l, A) for l in A)
|
@boundscheck @assert all(KnuthBendix.hasinverse(l, A) for l in A)
|
||||||
gens = Vector{eltype(A)}()
|
gens = Vector{eltype(A)}()
|
||||||
invs = Vector{eltype(A)}()
|
invs = Vector{eltype(A)}()
|
||||||
@ -188,20 +195,12 @@ function FreeGroup(A::Alphabet)
|
|||||||
push!(gens, l)
|
push!(gens, l)
|
||||||
push!(invs, inv(l, A))
|
push!(invs, inv(l, A))
|
||||||
end
|
end
|
||||||
|
return gens
|
||||||
return FreeGroup(gens, A)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function FreeGroup(n::Integer)
|
function FreeGroup(O::KnuthBendix.WordOrdering)
|
||||||
symbols = Symbol[]
|
grp_gens = __group_gens(alphabet(O))
|
||||||
inverses = Int[]
|
return FreeGroup(grp_gens, O)
|
||||||
sizehint!(symbols, 2n)
|
|
||||||
sizehint!(inverses, 2n)
|
|
||||||
for i in 1:n
|
|
||||||
push!(symbols, Symbol(:f, i), Symbol(:F, i))
|
|
||||||
push!(inverses, 2i, 2i - 1)
|
|
||||||
end
|
|
||||||
return FreeGroup(symbols[1:2:2n], Alphabet(symbols, inverses))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.show(io::IO, F::FreeGroup)
|
function Base.show(io::IO, F::FreeGroup)
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
[2, 1, 4, 3, 6, 5, 8, 7, 10, 9]
|
[2, 1, 4, 3, 6, 5, 8, 7, 10, 9]
|
||||||
)
|
)
|
||||||
|
|
||||||
F4 = FreeGroup([:a, :b, :c, :d], A4)
|
F4 = FreeGroup(A4)
|
||||||
a, b, c, d = gens(F4)
|
a, b, c, d = gens(F4)
|
||||||
D = ntuple(i -> gens(F4, i), 4)
|
D = ntuple(i -> gens(F4, i), 4)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
@test FreeGroup(A) isa FreeGroup
|
@test FreeGroup(A) isa FreeGroup
|
||||||
@test sprint(show, FreeGroup(A)) == "free group on 3 generators"
|
@test sprint(show, FreeGroup(A)) == "free group on 3 generators"
|
||||||
|
|
||||||
F = FreeGroup([:a, :b, :c], A)
|
F = FreeGroup([:a, :b, :c], Groups.KnuthBendix.LenLex(A))
|
||||||
@test sprint(show, F) == "free group on 3 generators"
|
@test sprint(show, F) == "free group on 3 generators"
|
||||||
|
|
||||||
a, b, c = gens(F)
|
a, b, c = gens(F)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@testset "FreeGroup" begin
|
@testset "FreeGroup" begin
|
||||||
|
|
||||||
A3 = Alphabet([:a, :b, :c, :A, :B, :C], [4,5,6,1,2,3])
|
A3 = Alphabet([:a, :b, :c, :A, :B, :C], [4,5,6,1,2,3])
|
||||||
F3 = FreeGroup([:a, :b, :c], A3)
|
F3 = FreeGroup(A3)
|
||||||
@test F3 isa FreeGroup
|
@test F3 isa FreeGroup
|
||||||
|
|
||||||
@test gens(F3) isa Vector
|
@test gens(F3) isa Vector
|
||||||
|
Loading…
Reference in New Issue
Block a user