Commit d6034608 by Adam P. Goucher

### Refactoring of isotropic.py

parent e5ccd0db
Pipeline #55029604 passed with stages
in 7 minutes and 39 seconds
 ... ... @@ -23,6 +23,76 @@ def create_rule(rulestring): f.write('}\n') def squarelord(): lord = "" lord += "_ceaccaieaeaknja_ceaccaieaeaknjaekejanaairerririekejanaairerriri"; lord += "ccknncqnaijaqnwaccknncqnaijaqnwakykkqyqjrtjnzrqakykkqyqjrtjnzrqa"; lord += "ekirkyrtejerkkjnekirkyrtejerkkjnekejjkrnejecjyccekejjkrnejecjycc"; lord += "anriqyzraariqjqaanriqyzraariqjqajkjywkqkrnccqkncjkjywkqkrnccqknc"; lord += "cnkqccnnkqkqyykjcnkqccnnkqkqyykjaqjwinaarzjqtrnaaqjwinaarzjqtrna"; lord += "ccyyccyennkjyekeccyyccyennkjyekenykknejeirykrikenykknejeirykrike"; lord += "aqrznyirjwjqkkykaqrznyirjwjqkkykaqrqajiarqcnnkccaqrqajiarqcnnkcc"; lord += "intrneriaanajekeintrneriaanajekeajnkaeaeiaccaec_ajnkaeaeiaccaec_"; return lord def hexlord(): lord = "" prelord = "___o_moo" + "_pmmomoo" + "_mpmmpmm" + "ommpomo_"; prelord += prelord[::-1]; for i in range(512): j = (i & 3) + ((i & 32) >> 3) + ((i & 256) >> 5) + ((i & 128) >> 3) + ((i & 8) << 2); lord += prelord[j] return lord def tab2str(lord2): lord = squarelord() rule_letters = {} rule_letters[1] = "ce" ; rule_letters[2] = "ceaikn" ; rule_letters[3] = "ceaiknjqry" ; rule_letters[4] = "ceaiknjqrytwz" ; rule_letters[5] = "ceaiknjqry" ; rule_letters[6] = "ceaikn" ; rule_letters[7] = "ce" ; popcounts = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4] canonicals = [['' for i in range(9)] for j in range(2)] canstring = '' for i in range(512): centre = (i >> 4) & 1 ncount = popcounts[i & 15] + popcounts[i >> 5] if (lord2[i] == 1): canonicals[centre][ncount] += lord[i] for (centre, z) in enumerate('bs'): canstring += z for ncount in range(9): goodies = set(canonicals[centre][ncount]) if (len(goodies) == 0): continue canstring += str(ncount) if ncount not in rule_letters: continue a = ''.join(sorted([c for c in rule_letters[ncount] if c in goodies])) b = '-' + (''.join(sorted([c for c in rule_letters[ncount] if c not in goodies]))) if (len(b) == 1): continue elif (len(b) < len(a)): canstring += b else: canstring += a return canstring def str2tab(rulestring, hexagonal='unknown'): if (hexagonal == 'unknown'): ... ... @@ -44,26 +114,13 @@ def str2tab(rulestring, hexagonal='unknown'): elif c in ('omp-' if hexagonal else 'ceaiknjqrytwz-'): isotrans[(centre, lastloc)] += c lord = ""; if not hexagonal: lord += "_ceaccaieaeaknja_ceaccaieaeaknjaekejanaairerririekejanaairerriri"; lord += "ccknncqnaijaqnwaccknncqnaijaqnwakykkqyqjrtjnzrqakykkqyqjrtjnzrqa"; lord += "ekirkyrtejerkkjnekirkyrtejerkkjnekejjkrnejecjyccekejjkrnejecjycc"; lord += "anriqyzraariqjqaanriqyzraariqjqajkjywkqkrnccqkncjkjywkqkrnccqknc"; lord += "cnkqccnnkqkqyykjcnkqccnnkqkqyykjaqjwinaarzjqtrnaaqjwinaarzjqtrna"; lord += "ccyyccyennkjyekeccyyccyennkjyekenykknejeirykrikenykknejeirykrike"; lord += "aqrznyirjwjqkkykaqrznyirjwjqkkykaqrqajiarqcnnkccaqrqajiarqcnnkcc"; lord += "intrneriaanajekeintrneriaanajekeajnkaeaeiaccaec_ajnkaeaeiaccaec_"; lord = squarelord() else: prelord = "___o_moo" + "_pmmomoo" + "_mpmmpmm" + "ommpomo_"; prelord += prelord[::-1]; for i in range(512): j = (i & 3) + ((i & 32) >> 3) + ((i & 256) >> 5) + ((i & 128) >> 3) + ((i & 8) << 2); lord += prelord[j] lord = hexlord() import re ... ... @@ -102,42 +159,7 @@ def str2tab(rulestring, hexagonal='unknown'): if hexagonal: return lord2 rule_letters = {} rule_letters[1] = "ce" ; rule_letters[2] = "ceaikn" ; rule_letters[3] = "ceaiknjqry" ; rule_letters[4] = "ceaiknjqrytwz" ; rule_letters[5] = "ceaiknjqry" ; rule_letters[6] = "ceaikn" ; rule_letters[7] = "ce" ; canonicals = [['' for i in range(9)] for j in range(2)] canstring = '' for i in range(512): centre = (i >> 4) & 1 ncount = popcounts[i & 15] + popcounts[i >> 5] if (lord2[i] == 1): canonicals[centre][ncount] += lord[i] for (centre, z) in enumerate('bs'): canstring += z for ncount in range(9): goodies = set(canonicals[centre][ncount]) if (len(goodies) == 0): continue canstring += str(ncount) if ncount not in rule_letters: continue a = ''.join(sorted([c for c in rule_letters[ncount] if c in goodies])) b = '-' + (''.join(sorted([c for c in rule_letters[ncount] if c not in goodies]))) if (len(b) == 1): continue elif (len(b) < len(a)): canstring += b else: canstring += a canstring = tab2str(lord2) if (rulestring != canstring): raise NonCanonicalError('%s is a non-canonical version of %s' % (rulestring, canstring)) ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!