"""
The first function: isFullyCommutative
Relies on http://doc.sagemath.org/html/en/reference/categories/sage/categories/coxeter_groups.html#sage.categories.coxeter_groups.CoxeterGroups.ElementMethods.reduced_word_graph
"""
def isFullyCommutative(word):
return all(edge[2] == 2 for edge in word.reduced_word_graph().edges())
#edge[2] is the edge's color, i.e., the length m of the corresponding braid move
"""
TESTS
"""
A5 = CoxeterGroup(["A", 5])
testWord1 = A5.from_reduced_word([1, 2, 1]) #121 should be braidable to 212
assert(not isFullyCommutative(testWord1))
testWord2 = A5.from_reduced_word([1, 2]) #12 should be FC
assert(isFullyCommutative(testWord2))
testWord3 = A5.from_reduced_word([2, 1, 2]) #212 should be braidable to 121
assert(not isFullyCommutative(testWord3))
testWord4 = A5.from_reduced_word([1, 2, 3, 4, 5]) #12345 should be FC
assert(isFullyCommutative(testWord4))
testWord5 = A5.from_reduced_word([1, 2, 3, 4, 5, 4]) #123454 has a '454' braid possibility
assert(not isFullyCommutative(testWord5))
testWord6 = A5.from_reduced_word([1, 3]) #13 should be FC
assert(isFullyCommutative(testWord6))
testWord7 = A5.from_reduced_word([1, 4, 5]) #145 should be FC
assert(isFullyCommutative(testWord7))
testWord8 = A5.from_reduced_word([1, 5, 1]) #reduces to 5
assert(isFullyCommutative(testWord8))
testWord9 = A5.from_reduced_word([4, 2, 3, 4]) #4234 -> 2434 which has a '434' braid possibility
assert(not isFullyCommutative(testWord9))
testWord10 = A5.from_reduced_word([1, 1]) #reduces to the identity
assert(isFullyCommutative(testWord10))
print("If you see this message and no errors, then the tests passed! Nice!")
|
If you see this message and no errors, then the tests passed! Nice!
If you see this message and no errors, then the tests passed! Nice!
|