Skip to content

Commit

Permalink
add Coxeter groups confluent rws to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed Dec 18, 2021
1 parent 5add443 commit e275a07
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 23 deletions.
139 changes: 116 additions & 23 deletions test/rws_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ function RWS_Example_5_1()
KnuthBendix.set_inversion!(Al, 'a', 'A')
KnuthBendix.set_inversion!(Al, 'b', 'B')

a,A,b,B = Word.([i] for i in 1:4)
a, A, b, B = Word.([i] for i in 1:4)
ε = one(a)

R = RewritingSystem([b*a=>a*b], LenLex(Al))
R = RewritingSystem([b * a => a * b], LenLex(Al))

return R
end
Expand All @@ -18,10 +18,10 @@ function RWS_Example_5_2()
KnuthBendix.set_inversion!(Al, 'a', 'A')
KnuthBendix.set_inversion!(Al, 'b', 'B')

a,b,B,A = Word.([i] for i in 1:4)
a, b, B, A = Word.([i] for i in 1:4)
ε = one(a)

R = RewritingSystem([b*a=>a*b], LenLex(Al))
R = RewritingSystem([b * a => a * b], LenLex(Al))

return R
end
Expand All @@ -31,10 +31,10 @@ RWS_ZxZ_nonterminating() = RWS_Example_5_2()
function RWS_Example_5_3()
Al = Alphabet(['a', 'b'])

a,b = Word.([i] for i in 1:2)
a, b = Word.([i] for i in 1:2)
ε = one(a)

R = RewritingSystem([a^2=>ε, b^3=>ε, (a*b)^3=>ε], LenLex(Al))
R = RewritingSystem([a^2 => ε, b^3 => ε, (a * b)^3 => ε], LenLex(Al))

return R
end
Expand All @@ -43,10 +43,10 @@ function RWS_Example_5_4()
Al = Alphabet(['a', 'b', 'B'])
KnuthBendix.set_inversion!(Al, 'b', 'B')

a,b,B = Word.([i] for i in 1:3)
a, b, B = Word.([i] for i in 1:3)
ε = one(a)

R = RewritingSystem([a^2=>ε, b^3=>ε, (a*b)^3=>ε], LenLex(Al))
R = RewritingSystem([a^2 => ε, b^3 => ε, (a * b)^3 => ε], LenLex(Al))

return R
end
Expand All @@ -60,7 +60,7 @@ function RWS_Example_5_5()
c, C, b, B, a, A = Word.([i] for i in 1:6)
ε = one(a)

eqns = [c*a =>a*c, c*b=>b*c, b*a=>a*b*c]
eqns = [c * a => a * c, c * b => b * c, b * a => a * b * c]

R = RewritingSystem(eqns, WreathOrder(Al))
return R
Expand All @@ -72,7 +72,13 @@ function RWS_Example_6_4()

a, b, B = Word.([i] for i in 1:3)
ε = one(a)
eqns = [a*a=>ε, b*B=>ε, b^3=>ε, (a*b)^7=>ε, (a*b*a*B)^4=>ε]
eqns = [
a * a => ε,
b * B => ε,
b^3 => ε,
(a * b)^7 => ε,
(a * b * a * B)^4 => ε,
]

R = RewritingSystem(eqns, LenLex(Al))
return R
Expand All @@ -84,9 +90,14 @@ function RWS_Example_6_5()

a, b, B = Word.([i] for i in 1:3)
ε = one(a)
eqns = KnuthBendix.Rule.(
[a*a=>ε, b*B=>ε, b^2=>B, (B*a)^3*B=>(a*b)^3*a, (b*a*B*a)^2=>(a*b*a*B)^2]
)
eqns =
KnuthBendix.Rule.([
a * a => ε,
b * B => ε,
b^2 => B,
(B * a)^3 * B => (a * b)^3 * a,
(b * a * B * a)^2 => (a * b * a * B)^2,
])

R = RewritingSystem(eqns, LenLex(Al))
return R
Expand All @@ -100,9 +111,16 @@ function RWS_Example_237_abaB(n)
ε = one(a)

# eqns = [a^2=>ε, b^3=>ε, (a*b)^7=>ε, (a*b*a*B)^n=>ε]
eqns = [b*B=>ε, B*b=>ε, a^2=>ε, b^3=>ε, (a*b)^7=>ε, (a*b*a*B)^n=>ε]

R = RewritingSystem(eqns, LenLex(Al), bare=true)
eqns = [
b * B => ε,
B * b => ε,
a^2 => ε,
b^3 => ε,
(a * b)^7 => ε,
(a * b * a * B)^n => ε,
]

R = RewritingSystem(eqns, LenLex(Al), bare = true)
return R
end

Expand All @@ -114,35 +132,110 @@ function RWS_Exercise_6_1(n)
a, b = Word.([i] for i in 1:2)
ε = one(a)

eqns = [a^2=>ε, b^3=>ε, (a*b)^n=>ε]
eqns = [a^2 => ε, b^3 => ε, (a * b)^n => ε]

R = RewritingSystem(eqns, LenLex(Al), bare=true)
R = RewritingSystem(eqns, LenLex(Al), bare = true)
return R
end

function RWS_Closed_Orientable_Surface(n)
ltrs = String[]
for i in 1:n
subscript = join(''+d for d in reverse(digits(i)))
append!(ltrs, ["a" * subscript, "A" * subscript, "b" * subscript, "B" * subscript])
subscript = join('' + d for d in reverse(digits(i)))
append!(
ltrs,
[
"a" * subscript,
"A" * subscript,
"b" * subscript,
"B" * subscript,
],
)
end
Al = Alphabet(reverse!(ltrs))
for i in 1:n
subscript = join(''+d for d in reverse(digits(i)))
subscript = join('' + d for d in reverse(digits(i)))
KnuthBendix.set_inversion!(Al, "a" * subscript, "A" * subscript)
KnuthBendix.set_inversion!(Al, "b" * subscript, "B" * subscript)
end

ε = one(Word{UInt16})
rules = Pair{typeof(ε), typeof(ε)}[]
rules = Pair{typeof(ε),typeof(ε)}[]
word = Int[]

for i in reverse(1:n)
x = 4 * i
append!(word, [x, x-2, x-1, x-3])
append!(word, [x, x - 2, x - 1, x - 3])
end
push!(rules, Word(word) => ε)
R = RewritingSystem(rules, RecursivePathOrder(Al))

return R
end

function RWS_Coxeter_group_cube()
_coxeter_letter(simplex) = Symbol("s", join(simplex, ""))

function coxeter_alphabet(itr)
letters = [_coxeter_letter(v) for v in itr]
inverses = 1:length(letters) # generators are of order 2 i.e. self-inverse
return KnuthBendix.Alphabet(letters, inverses)
end

vertices = [[i,] for i in 1:8]
edges = [
[1, 2],
[1, 3],
[1, 5],
[2, 4],
[2, 6],
[3, 5],
[3, 7],
[4, 8],
[5, 6],
[5, 7],
[6, 8],
[7, 8],
] # 3-cube

A = coxeter_alphabet([edges; vertices])
weights = [fill(2, length(edges)); fill(1, length(vertices))]
wtlex = WeightedLex(A, weights)

S = Dict(v => Word([A[_coxeter_letter(v)]]) for v in vertices)
for σ in edges
S[σ] = Word([A[_coxeter_letter(σ)]])
end

rels = map(edges) do e
v1, v2 = [first(e)], [last(e)]
s1, s2, s12 = S[v1], S[v2], S[e]
return [ # (1)(2) → (12), (2)(1) → (12)
s1 * s2 => s12,
s2 * s1 => s12,
#(1)(12) → (2) (2)(12) → (1) (12)(1) → (2) (12)(2) → (1)
s1 * s12 => s2,
s2 * s12 => s1,
s12 * s1 => s2,
s12 * s2 => s1,
]
end

rels2 = eltype(eltype(rels))[]
for e in edges
for f in edges
if length(intersect(e, f)) == 1
edge = union(setdiff(e, f), setdiff(f, e))
@assert length(edge) == 2
haskey(S, edge) || reverse!(edge)
if haskey(S, edge)
# (12)(13) → (23)
push!(rels2, S[e] * S[f] => S[edge])
end
end
end
end
push!(rels, rels2)

return RewritingSystem(vcat(rels...), wtlex)
end
8 changes: 8 additions & 0 deletions test/test_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ _length(rws) = length(collect(KnuthBendix.rules(rws)))
R = RWS_Closed_Orientable_Surface(3)
rws = KnuthBendix.knuthbendix(R, implementation=:naive_kbs1)
@test _length(rws) == 16

R = RWS_Coxeter_group_cube()
rws = KnuthBendix.knuthbendix(R, implementation=:naive_kbs1, maxrules=300)
@test _length(rws) == 205
end

function test_kbs2_methods(R, methods, len)
Expand Down Expand Up @@ -89,6 +93,10 @@ end
R = RWS_Closed_Orientable_Surface(3)
rws = KnuthBendix.knuthbendix(R, implementation=:naive_kbs2)
@test _length(rws) == 16

R = RWS_Coxeter_group_cube()
rws = KnuthBendix.knuthbendix(R, implementation=:naive_kbs2, maxrules=300)
@test _length(rws) == 205
end

@testset "KBS-automata" begin
Expand Down

0 comments on commit e275a07

Please sign in to comment.