# Section 7: exhaustive search at N=7, the energy -Tr|S| over all the sign matrices S. # Up to signs of rows and columns, the first row and column are positive, # and up to permutations of the rows, the other 6 rows form a multiset of # vectors in {1,-1}^6, so there are binom(69,6)=119877472 cases, counted with # their multiplicities 720/prod(m!), the total being 64^6=2^36. # Output: the density of states, in bins of width 1/100, and the top levels. import numpy as np, itertools, sys, json from multiprocessing import Pool N = 7 P = np.array([[1] + [1 - 2 * ((x >> k) & 1) for k in range(N - 1)] for x in range(64)], dtype=np.float64) T = np.array(list(itertools.combinations_with_replacement(range(64), 4)), dtype=np.int16) START = np.searchsorted(T[:, 0], np.arange(65)) BINS = 1900 CUT = 17.9 def task(pair): i, j = pair tail = T[START[j]:] hist = np.zeros(BINS, dtype=np.int64) top = {} for lo in range(0, len(tail), 200000): t = tail[lo:lo + 200000] b = len(t) idx = np.empty((b, 6), dtype=np.int16) idx[:, 0] = i idx[:, 1] = j idx[:, 2:] = t m = np.empty((b, N, N)) m[:, 0, :] = 1 m[:, 1:, :] = P[idx] v = np.linalg.svd(m, compute_uv=False).sum(axis=1) run = np.ones(b, dtype=np.int64) den = np.ones(b, dtype=np.int64) for k in range(1, 6): run = np.where(idx[:, k] == idx[:, k - 1], run + 1, 1) den *= run w = 720 // den hist += np.bincount((v * 100).astype(np.int64), weights=w, minlength=BINS).astype(np.int64) for q in np.nonzero(v > CUT)[0]: key = "%.7f" % v[q] old = top.get(key, [0, None]) top[key] = [old[0] + int(w[q]), [int(x) for x in idx[q]]] return hist, top if __name__ == "__main__": pairs = [(i, j) for i in range(64) for j in range(i, 64)] hist = np.zeros(BINS, dtype=np.int64) top = {} done = 0 with Pool(int(sys.argv[1]) if len(sys.argv) > 1 else 2) as pool: for h, t in pool.imap_unordered(task, pairs, chunksize=4): hist += h for key, val in t.items(): old = top.get(key, [0, None]) top[key] = [old[0] + val[0], val[1]] done += 1 if done % 100 == 0: print("pairs done", done, "of", len(pairs), flush=True) print("total", int(hist.sum()), "expected", 64 ** 6) for key in sorted(top, reverse=True): print("level", key, "matrices", top[key][0], "example rows", top[key][1]) json.dump({"bins": hist.tolist(), "top": top}, open("seven.json", "w"))