1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-25 02:05:30 +01:00

add New.FreeGroup(n::Integer) method

This commit is contained in:
Marek Kaluba 2021-05-26 12:12:26 +02:00
parent c0c688ed2d
commit 3a88728e0a
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15

View File

@ -134,6 +134,18 @@ function FreeGroup(A::Alphabet)
return FreeGroup(KnuthBendix.letters(A), A)
end
function FreeGroup(n::Integer)
symbols = Symbol[]
inverses = Int[]
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
Base.show(io::IO, F::FreeGroup) = print(io, "free group on $(ngens(F)) generators")
# mandatory methods: