enumerate group elements
This commit is contained in:
parent
fc4dfa195d
commit
55f0c2d093
133
automaton.py
133
automaton.py
@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
# 0 is infinity
|
# 0 is infinity
|
||||||
coxeter_matrix = [[1, 2, 3],
|
coxeter_matrix = [[1, 5, 5],
|
||||||
[2, 1, 0],
|
[5, 1, 5],
|
||||||
[3, 0, 1]]
|
[5, 5, 1]]
|
||||||
|
|
||||||
import math
|
import math
|
||||||
from copy import copy
|
from copy import copy
|
||||||
@ -26,6 +26,18 @@ class Root:
|
|||||||
def __copy__(self):
|
def __copy__(self):
|
||||||
return Root(self.id, self.rank, self.depth, self.v.copy(), self.neighbors.copy())
|
return Root(self.id, self.rank, self.depth, self.v.copy(), self.neighbors.copy())
|
||||||
|
|
||||||
|
class Groupelement:
|
||||||
|
def __init__(self, id, rank, word):
|
||||||
|
self.id = id
|
||||||
|
self.rank = rank
|
||||||
|
self.word = word
|
||||||
|
self.length = len(word)
|
||||||
|
self.left = [None]*rank
|
||||||
|
self.right = [None]*rank
|
||||||
|
self.node = None
|
||||||
|
self.lex_node = None
|
||||||
|
self.inverse = None
|
||||||
|
|
||||||
# compute <alpha_k, beta> where alpha_k is one of the simple roots and beta any root
|
# compute <alpha_k, beta> where alpha_k is one of the simple roots and beta any root
|
||||||
def form_gen_root(form, k, root):
|
def form_gen_root(form, k, root):
|
||||||
rank = len(form)
|
rank = len(form)
|
||||||
@ -152,71 +164,84 @@ def generate_automaton(small_roots, lex_reduced = False):
|
|||||||
id += 1
|
id += 1
|
||||||
edges.append((nodes[node], nodes[newnode], k))
|
edges.append((nodes[node], nodes[newnode], k))
|
||||||
|
|
||||||
return (nodes, levels, edges)
|
graph = [[None for i in range(rank)] for j in range(len(nodes))]
|
||||||
|
for (fr,to,gen) in edges:
|
||||||
|
graph[fr][gen] = to
|
||||||
|
return graph
|
||||||
|
|
||||||
# main program
|
# main program
|
||||||
|
|
||||||
form = [[-math.cos(math.pi/m) if m > 0 else -1 for m in row] for row in coxeter_matrix]
|
form = [[-math.cos(math.pi/m) if m > 0 else -1 for m in row] for row in coxeter_matrix]
|
||||||
rank = len(coxeter_matrix)
|
rank = len(coxeter_matrix)
|
||||||
small_roots = find_small_roots(form)
|
small_roots = find_small_roots(form)
|
||||||
nodes, levels, edges = generate_automaton(small_roots, lex_reduced = False)
|
graph = generate_automaton(small_roots, lex_reduced = False)
|
||||||
nodes_lex, levels_lex, edges_lex = generate_automaton(small_roots, lex_reduced = True)
|
graph_lex = generate_automaton(small_roots, lex_reduced = True)
|
||||||
|
|
||||||
#for r in small_roots:
|
group = [Groupelement(0, rank, tuple())]
|
||||||
# print((r.id,r.v,[n.id if n else -1 for n in r.neighbors]))
|
group[0].inverse = group[0]
|
||||||
|
group[0].node = group[0].lex_node = 0
|
||||||
|
|
||||||
revedges = sorted(edges, key = lambda x:x[1])
|
|
||||||
|
|
||||||
adjlist = {}
|
|
||||||
revadjlist = {}
|
|
||||||
for efrom, eto, egen in edges:
|
|
||||||
if not efrom in adjlist:
|
|
||||||
adjlist[efrom] = [-1]*rank
|
|
||||||
adjlist[efrom][egen] = eto
|
|
||||||
if not eto in revadjlist:
|
|
||||||
revadjlist[eto] = [-1]*rank
|
|
||||||
revadjlist[eto][egen] = efrom
|
|
||||||
|
|
||||||
words = [([], 0)]
|
|
||||||
depth = 0
|
|
||||||
i = 0
|
i = 0
|
||||||
while len(words[i][0]) < 10:
|
size = 1
|
||||||
curword = words[i][0]
|
while True:
|
||||||
curnode = words[i][1]
|
current = group[i]
|
||||||
for gen, nextnode in enumerate(adjlist[curnode]):
|
|
||||||
if nextnode < 0:
|
|
||||||
continue
|
|
||||||
nextword = curword.copy()
|
|
||||||
nextword.append(gen)
|
|
||||||
words.append((nextword, nextnode))
|
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
#print(sorted([x[1] for x in words]))
|
if current.length >= 10:
|
||||||
#print(["".join([chr(ord('a')+x) for x in w[0]]) for w in words])
|
break
|
||||||
|
|
||||||
levelnodes = []
|
for gen, new_lex_node in enumerate(graph_lex[current.lex_node]):
|
||||||
for n,id in nodes.items():
|
if new_lex_node:
|
||||||
level = levels[n]
|
new_element = Groupelement(size, rank, current.word + (gen,))
|
||||||
if level >= len(levelnodes):
|
new_element.lex_node = new_lex_node
|
||||||
levelnodes.append([])
|
new_element.node = graph[current.node][gen]
|
||||||
levelnodes[level].append(id)
|
group.append(new_element)
|
||||||
|
size += 1
|
||||||
|
|
||||||
print("digraph test123 {")
|
# w = w_1 t, w s = w_1
|
||||||
print('rankdir="TB"')
|
# right multiplication (and left in case it does the same as a right mult)
|
||||||
|
for k in range(rank):
|
||||||
|
|
||||||
for (level,ns) in enumerate(levelnodes):
|
# if right multiplication by k decreases length
|
||||||
print('{rank = "same";', end = ' ')
|
if not graph[new_element.node][k]:
|
||||||
for n in ns:
|
word = list(new_element.word)
|
||||||
print("{id:d};".format(id=n), end = ' ')
|
longer_suffix = group[0]
|
||||||
print('}')
|
while len(word) > 0:
|
||||||
|
letter = word.pop()
|
||||||
|
shorter_suffix = longer_suffix
|
||||||
|
longer_suffix = shorter_suffix.left[letter]
|
||||||
|
|
||||||
|
# w = w_1 t w_2, w_2 s_k = t w_2
|
||||||
|
# in the case word = [] longer_suffix could be None
|
||||||
|
# found it
|
||||||
|
if len(word) == 0 or shorter_suffix.right[k] == longer_suffix:
|
||||||
|
# finish word
|
||||||
|
while len(word) > 0:
|
||||||
|
shorter_suffix = shorter_suffix.left[word.pop()]
|
||||||
|
new_element.right[k] = shorter_suffix
|
||||||
|
shorter_suffix.right[k] = new_element
|
||||||
|
|
||||||
colors = ['red', 'darkgreen', 'blue', 'orange']
|
# find inverse and left multiply
|
||||||
|
inverse = group[0]
|
||||||
|
word = list(new_element.word)
|
||||||
|
while len(word) > 0:
|
||||||
|
inverse = inverse.right[word.pop()]
|
||||||
|
if not inverse:
|
||||||
|
break
|
||||||
|
if inverse:
|
||||||
|
new_element.inverse = inverse
|
||||||
|
inverse.inverse = new_element
|
||||||
|
for k in range(rank):
|
||||||
|
if inverse.right[k]:
|
||||||
|
other = inverse.right[k].inverse
|
||||||
|
new_element.left[k] = other
|
||||||
|
other.left[k] = new_element
|
||||||
|
if new_element.right[k]:
|
||||||
|
other = new_element.right[k].inverse
|
||||||
|
inverse.left[k] = other
|
||||||
|
other.left[k] = inverse
|
||||||
|
|
||||||
for e in edges:
|
length = 0
|
||||||
print("{fr:d} -> {to:d} [color={color}];".format(
|
for i in range(1,len(group)+1):
|
||||||
fr = e[0],
|
if i == len(group) or group[i].length > group[i-1].length:
|
||||||
to = e[1],
|
print("{number:d} elements up to length {length:d}".format(number = i, length = group[i-1].length))
|
||||||
color = colors[e[2]]))
|
|
||||||
|
|
||||||
print("}")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user