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
1 changed files with 12 additions and 0 deletions

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: