From 3a88728e0ac8ea1ab0f9a4cca8a7b4bbc7096bdb Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Wed, 26 May 2021 12:12:26 +0200 Subject: [PATCH] add New.FreeGroup(n::Integer) method --- src/new_types.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/new_types.jl b/src/new_types.jl index 9057d54..aff0f87 100644 --- a/src/new_types.jl +++ b/src/new_types.jl @@ -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: