Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is some code that might do the job. Please feel free to test it and let me know if this works.

def directg(g6):
    import subprocess
    sp = subprocess.Popen("directg -o", shell=True,
                          stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE, close_fds=True)
    stdout = sp.communicate(input='{0}\n'.format(g6))[0]
    d6_strings = stdout.split()
    for d6 in d6_strings:
        yield DiGraph(d6[1:])

def A_base(n):
    return graphs.PathGraph(n).graph6_string()

def D_base(n):
    g = graphs.PathGraph(n-1)
    g.add_edge(n-3,n-1)
    return g.graph6_string()

def E_base(n):
    g = graphs.PathGraph(n-1)
    g.add_edge(2,n-1)
    return g.graph6_string()

def generate_DynkinQuivers(n,kind='A'):
    if kind not in 'AED':
        raise ValueError("Invalid type of Dynkin quiver, should be one of 'A', 'D' or 'E'.")
    if kind == 'A':
        g6_base = A_base(n)
    elif kind=='D':
        g6_base = D_base(n)
    elif kind=='E':
        g6_base = E_base(n)
    output_template = 'DynkinQuiver("{kind}",{size},[{orientation}])'

    for digraph in directg(g6_base):
        orientation = []
        for i in range(n-2):
            if digraph.has_edge(i,i+1):
                orientation.append('"r"')
            elif digraph.has_edge(i+1,i):
                orientation.append('"l"')
            else:
                raise ValueError("Format conversion error.")
        if kind in 'AD':
            if kind=='A':
                other = n-2
            else:
                other = n-3
            if digraph.has_edge(other,n-1):
                orientation.append('"r"')
            elif digraph.has_edge(n-1,other):
                orientation.append('"l"')
            else:
                raise ValueError("Format conversion error. Last edge of kind {0} quiver.".format(kind))
        if kind =='E':
            if digraph.has_edge(n-1,2):
                orientation.append('"d"')
            elif digraph.has_edge(2,n-1):
                orientation.append('"u"')
            else:
                raise ValueError("Format conversion error. Last edge of kind E quiver.")
        yield output_template.format(kind=kind,size=n,orientation=','.join(orientation))
def DynkinQuivers(n,kind='A'):
    return '[{0}]'.format(','.join(generate_DynkinQuivers(n,kind)))

Sample usage:

DynkinQuivers(3,'A')

produces

'[DynkinQuiver("A",3,["r","r"]),DynkinQuiver("A",3,["r","l"]),DynkinQuiver("A",3,["l","r"])]'

Which can be saved to a file.

It takes about half a second to go up to n=13

%time
output=DynkinQuivers(13,'E')
CPU time: 0.41 s, Wall time: 0.53 s