From 35509a8304ca1b76c076a4cfc181a8b1dd69786e Mon Sep 17 00:00:00 2001 From: kalmar Date: Mon, 23 Jan 2017 16:53:33 +0100 Subject: [PATCH] create package from existing code --- src/free_groups.jl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/free_groups.jl diff --git a/src/free_groups.jl b/src/free_groups.jl new file mode 100644 index 0000000..8e34932 --- /dev/null +++ b/src/free_groups.jl @@ -0,0 +1,22 @@ +import Base:convert + +export FGSymbol, FGWord + +immutable FGSymbol <: GSymbol + gen::String + pow::Int +end + +(==)(s::FGSymbol, t::FGSymbol) = s.gen == t.gen && s.pow == t.pow +hash(s::FGSymbol, h::UInt) = hash(s.gen, hash(s.pow, hash(:FGSymbol, h))) + +IdSymbol(::Type{FGSymbol}) = FGSymbol("(id)", 0) +FGSymbol(x::String) = FGSymbol(x,1) + +inv(s::FGSymbol) = FGSymbol(s.gen, -s.pow) +convert(::Type{FGSymbol}, x::String) = FGSymbol(x) +change_pow(s::FGSymbol, n::Int) = (n==0 ? i=one(s) : FGSymbol(s.gen, n)) + +typealias FGWord GWord{FGSymbol} + +FGWord(s::FGSymbol) = FGWord([s])