Advertisement
Guest User

Untitled

a guest
Nov 19th, 2023
106
0
177 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. import numpy as np
  2. import sys
  3.  
  4. count = 0
  5. v = 0
  6. M = np.matrix([[]])
  7.  
  8. def kronecker(n):
  9.     a = np.matrix([[1, 1], [0, 1]])
  10.     if n == 1:
  11.         return a
  12.     return np.kron(a, kronecker(n - 1))
  13.  
  14. def gen(n):
  15.     global count
  16.     count = 1
  17.  
  18.     Max_Dim = pow(2,n)
  19.     f = []
  20.     for i in range(Max_Dim):
  21.         f.append(0)
  22.  
  23.     #if v: print("H: ", f, "i: ", pow(2,n) - 1, "count: ", count)
  24.     if v: print(f"H: {f}, i: {pow(2,n) - 1}, count: {count}")
  25.     for i in reversed(range(0, Max_Dim)):
  26.         gen_i(f, i, n)
  27.  
  28.     print("D" + str(n) + ": " + str(count))
  29.  
  30. def gen_i(G, i, n):
  31.     global M
  32.     H = []
  33.     Max_Dim = pow(2,n)
  34.     for p in range(Max_Dim):
  35.         H.append(0)
  36.  
  37.     M_i = M[i]
  38.     for k in range(Max_Dim):
  39.         H[k] = G[k] or M_i[k]
  40.  
  41.  
  42.     global count
  43.     count += 1
  44.     #if v: print "H: ", H, "i: ", i, "count: ", count
  45.     if v: print(f"H: {H},  i: {i}, count: {count}")
  46.     for j in reversed(range(i+1, Max_Dim)):
  47.         #if v: print "\tH: ", H, "i: ", i, "j: ", j
  48.         if v: print(f"\tH: {H},  i: {i},  j: {j}")
  49.         if H[j] == 0:
  50.             if v: print("--")
  51.             gen_i(H, j, n)
  52.  
  53.  
  54. if __name__ == '__main__':
  55.     n = int(sys.argv[1])
  56.     if len(sys.argv) == 3:
  57.         if sys.argv[2] == '-v':
  58.             v = 1
  59.     M = kronecker(n).tolist()
  60.     for row in M:
  61.         if v: print(row)
  62.     if v: print("\n")
  63.     gen(n)
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement