Advertisement
JoelSjogren

drcubic.py

Apr 1st, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. import networkx as nx
  2. import sympy
  3.  
  4. # intersection numbers 'iota'
  5. K4 = [[3], [1]]
  6. K33 = [[3, 2], [1, 3]]
  7. Petersen = [[3, 2], [1, 1]]
  8. Cube = [[3, 2, 1], [1, 2, 3]]
  9. Heawood = [[3, 2, 2], [1, 1, 3]]
  10. Pappus = [[3, 2, 2, 1], [1, 1, 2, 3]]
  11. Coxeter = [[3, 2, 2, 1], [1, 1, 1, 2]]
  12. Tutte = [[3, 2, 2, 2], [1, 1, 1, 3]]
  13. Dodecahedron = [[3, 2, 1, 1, 1], [1, 1, 1, 2, 3]]
  14. Desargues = [[3, 2, 2, 1, 1], [1, 1, 2, 2, 3]]
  15. Biggs = [[3, 2, 2, 2, 1, 1, 1], [1, 1, 1, 1, 1, 1, 3]]
  16. Foster = [[3, 2, 2, 2, 2, 1, 1, 1], [1, 1, 1, 1, 2, 2, 2, 3]]
  17.  
  18. smith1971 = [K4, K33, Petersen, Cube, Heawood, Pappus, Coxeter, Tutte, Dodecahedron, Desargues, Biggs, Foster]
  19.  
  20. """
  21. From Wolfram:
  22.     Given a distance-regular graph G with integers  b_i,c_i,i=0,...,d such that for any two vertices
  23.     x,y in G at distance i=d(x,y), there are exactly c_i neighbors of y in G_(i-1)(x) and b_i neighbors of y in G_(i+1)(x), the sequence
  24.         iota(gamma)={b_0,b_1,...,b_(d-1);c_1,...,c_d}
  25.     is called the intersection array of G.
  26. See also https://en.wikipedia.org/wiki/Distance-regular_graph.
  27. """
  28. def intersection_array_to_L(iota):
  29.     diam = len(iota[0])
  30.     b = lambda i: iota[0][i] if i in range(diam) else 0
  31.     c = lambda i: iota[1][i-1] if i-1 in range(diam) else 0
  32.     a = lambda i: b(0) - b(i) - c(i)
  33.  
  34.     B = sympy.zeros(diam+1)
  35.     B[0,:2] = [[a(0), b(0)]]
  36.     for i in range(1, diam):
  37.         B[i,i-1:i+2] = [[c(i), a(i), b(i)]]
  38.     B[-1,-2:] = [[c(diam), a(diam)]]
  39.  
  40.     R1 = sympy.Matrix([[B[i,j]/sum(B[i,:])  # normalized
  41.         for j in range(diam+1)] for i in range(diam+1)])
  42.     R = [R1**i for i in range(diam+1)]
  43.     for i in range(diam+1):  # gaussian elimination of the "top layer"
  44.         R[i] /= R[i][0,i]
  45.         for j in range(i+1, diam+1):
  46.             R[j] -= R[j][0,i]*R[i]
  47.  
  48.     L = [[[A[j,i] for j in range(diam+1)] for i in range(diam+1)] for A in R]
  49.     return L
  50.  
  51. def demo(which=range(12)):
  52.     for i in which:
  53.         print(intersection_array_to_L(smith1971[i]))
  54.  
  55. if __name__ == '__main__':
  56.     demo()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement