kalmarek / KnuthBendix.jl

Pure Julia implementation of the Knuth-Bendix completion (focused primarily on groups and monoids)
MIT License
8 stars 2 forks source link

incorporate example Monoid implementation? #45

Open kalmarek opened 3 years ago

kalmarek commented 3 years ago

See: https://gist.github.com/kalmarek/9475f36e768046cd7ef7fc08891bf553

julia> include("Monoids.jl")

julia> using .Monoids

julia> function example_monoid(n::Integer)
           A = Alphabet([[Symbol('a', i) for i in 1:n]; [Symbol('b', i) for i in 1:n]])
           F = FreeMonoid(A)
           rels = let S = gens(F)
               squares = [g^2=>one(g) for g in S]
               @views a, b = S[1:n], S[n+1:end]
               aibj = [a[i]*b[j] => b[j]*a[i] for i in 1:n for j in 1:n]
               [squares; aibj]
           end

           return F/rels
       end
example_monoid (generic function with 1 method)

julia> M = example_monoid(2)
monoid with 8 relations over Alphabet{Symbol}[:a1, :a2, :b1, :b2]

julia> a, b = M(rand(1:4, 20)), M(rand(1:4, 20))
(a1*a2*a1*a2*b1*b2*b1*b2*b1*b2, a2*a1*a2*a1*a2*b2*b1*b2)

julia> a*b
a2*b1*b2*b1

julia> b*a
a2*a1*a2*a1*a2*a1*a2*a1*a2*b2*b1*b2*b1*b2*b1*b2*b1*b2

julia> x = M(rand(1:4, 20)); isreduced(x)
false

julia> y = deepcopy(x); normalform!(y); isreduced(y)
true

julia> x === y
false

julia> x == y
true