Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def test(wordLength, numTrials=10000):
- F.<a,b> = FreeGroup()
- W = FiniteWords('abAB')
- def letterToGroup(c):
- if c == 'a': return a
- if c == 'b': return b
- if c == 'A': return a^(-1)
- if c == 'B': return b^(-1)
- def wordToReln(w):
- return prod([letterToGroup(c) for c in w])
- numPerfect = 0
- numNontrivial = 0
- while numPerfect < numTrials:
- if numPerfect % 1000 == 0: print(numPerfect, "/", numTrials)
- R = W.random_element(length=wordLength)
- S = W.random_element(length=wordLength)
- # Check if the abelianization is trivial by checking
- # if the determinant of (R^ab | S^ab) is +/- 1
- det = (R.count('a') - R.count('A')) * (S.count('b') - S.count('B')) - \
- (R.count('b') - R.count('B')) * (S.count('a') - S.count('A'))
- if abs(det) == 1:
- numPerfect += 1
- G = F / [wordToReln(R), wordToReln(S)]
- # How can I make this line of code time out after 3 seconds
- # so we can move on to another random presentation?
- if G.cardinality() != 1:
- numNontrivial += 1
- return (numNontrivial / numPerfect).n()
Advertisement
Add Comment
Please, Sign In to add comment