def dump(self): G, H = self.G, self.H print("G =") print(shortstr(G)) print("H =") print(shortstr(H))
def main_fail(): print() print("==" * 70) H = """ 012345678901234 0 YXZZ........... 1 X..X.XX.X...... 2 ZZ..ZZ.......Z. 3 .X..Y....XZ.... 4 .ZX....Y.Z..... 5 .....ZZZ.Z....Z 6 ..Z...ZZ....ZZ. 7 ...Z....Y.XX... 8 ..XX.......ZY.. 9 .........ZXX..Y 10 .....X.....XXXX 11 ....X.X.X.X..X. """ H = syparse(H) print() print(shortstr(H)) m = len(H) n = H.shape[1] // 2 assert n == 15 F = symplectic(n) C = dot2(H, dot2(F, H.transpose())) print(C.shape) for i in range(m): for j in range(i + 1, m): if C[i, j]: print("fail:", i, j) print(rank(H)) H = linear_independent(H) print("H=", H.shape) print(shortstr(H)) HF = dot2(H, F) K = array2(find_kernel(HF)) print("K=", K.shape) print(shortstr(K)) HK = numpy.concatenate((H, K)) L = linear_independent(HK) print() print(shortstr(L))
def genus_enum1(code=None, verbose=False): if code is None: code = get_code() G = code.G print(shortstr(G)) m, n = G.shape poly = lambda cs : Poly(cs, 2, "x_0 x_1".split()) #x_1 = poly({(0, 1) : 1}) #x_0 = poly({(1, 0) : 1}) #xs = [x0, x1] cs = {} for v0 in span(G): exp = [0, 0] #vv = numpy.array([2*v0, v1]) for i in range(n): exp[v0[i]] += 1 exp = tuple(exp) cs[exp] = cs.get(exp, 0) + 1 p = poly(cs) if argv.show: if argv.latex: print(p) else: print(p.flatstr()) Z = numpy.array([[1, 0], [0, 1]]) q = p.transform(Z) print("invariant under Z", q==p) S2 = numpy.array([[0, 1], [-1, 0]]) q = p.transform(S2) print("invariant under CS2", q==p)
def main_torus(): n = 8 # ZZZZZZZZ|XXXXXXXX # 12345678|12345678 H = parse(""" 111..1..|........ 1..1....|1.1..... ........|11.11... .1..1...|.1...1.. ..1...1.|...1..1. ...11.11|........ .....1.1|....1..1 ........|..1..111 """.replace("|", "")) print() print("H=") print(shortstr(H)) F = symplectic(n) C = dot2(H, dot2(F, H.transpose())) for i in range(n): for j in range(i + 1, n): if C[i, j]: print("fail:", i + 1, j + 1) print(rank(H)) H = linear_independent(H) print("H=") print(shortstr(H)) HF = dot2(H, F) K = array2(find_kernel(HF)) print("K=") print(shortstr(K)) HK = numpy.concatenate((H, K)) L = linear_independent(HK) print() print(shortstr(L))
def gen(): r = argv.get("r", None) # degree m = argv.get("m", None) if r is not None and m is not None: code = reed_muller(r, m) #print(code) #print("d =", code.get_distance()) #code.dump() #code = code.puncture(3) #print(code) code = code.puncture(0) print(code) for g in code.G: print(shortstr(g), g.sum()) print() #code.dump() #print("d =", code.get_distance()) return for m in range(2, 8): for r in range(0, m+1): code = reed_muller(r, m) print(code, end=" ") if code.is_selfdual(): print("is_selfdual", end=" ") if code.is_morthogonal(2): print("is_biorthogonal", end=" ") if code.is_morthogonal(3): print("is_triorthogonal", end=" ") if dot2(code.H, code.H.transpose()).sum()==0: print("***", end=" ") p = code.puncture(0) if p.is_morthogonal(3): print("puncture.is_triorthogonal", end=" ") if p.is_selfdual(): print("puncture.is_selfdual", end=" ") if dot2(p.H, p.H.transpose()).sum()==0: print("***", end=" ") print() if p.is_triorthogonal() and p.k < 20: G = p.G #print(shortstr(G)) A = list(span(G)) A = array2(A) print(is_morthogonal(A, 3))
def test_rm(): params = [(r, m) for m in range(2, 8) for r in range(1, m)] r = argv.get("r", None) # degree m = argv.get("m", None) if r is not None and m is not None: params = [(r, m)] for (r, m) in params: #code = reed_muller(r, m) # for code in [ reed_muller(r, m), reed_muller(r, m).puncture(0) ]: for code in [reed_muller(r, m)]: if argv.puncture: print(code, end=" ", flush=True) code = code.puncture(0) code = code.get_even() if argv.puncture==2: code = code.puncture(0) code = code.get_even() G = code.G k, n = G.shape #code = Code(G) #d = code.get_distance() d = "." print("puncture [%d, %d, %s]" % (n, k, d), end=" ", flush=True) else: G = code.G print(code, end=" ", flush=True) i = 1 while i<8: if (is_morthogonal(G, i)): print("(%d)"%i, end="", flush=True) i += 1 else: break if i > code.k: print("*", end="") break print() if argv.show: print(G.shape) print(shortstr(G)) print(dot2(G, G.transpose()).sum()) if len(G) >= 14: continue A = array2(list(span(G))) for i in [1, 2, 3]: assert strong_morthogonal(G, i) == strong_morthogonal(A, i)
def test(): for idx, H in enumerate(items): H = array2(H) #print(H.shape) print(names[idx]) print(shortstr(H)) assert (dot2(H, H.transpose()).sum()) == 0 # orthogonal code G = H for genus in range(1, 4): print(strong_morthogonal(G, genus), end=" ") print() keys = [0, 4, 8, 12, 16, 20, 24] counts = {0: 0, 4: 0, 8: 0, 12: 0, 16: 0, 20: 0, 24: 0} for v in span(G): counts[v.sum()] += 1 print([counts[k] for k in keys]) print()
def test_enum(G, verbose=False): w1 = genus_enum1(G) w2 = genus_enum2(G) w3 = genus_enum3(G) if verbose: print(w1.flatstr()) print(w2.flatstr()) print(w3.flatstr()) zero1 = xpoly1({}) zero2 = xpoly2({}) w2_10 = w2.substitute({ "x_00" : x_0, "x_10" : x_1, "x_01":zero1, "x_11":zero1 }) assert w2_10 == w1 w2_01 = w2.substitute({ "x_00" : x_0, "x_10" : zero1, "x_01":x_1, "x_11":zero1 }) assert w2_01 == w1 w2_11 = w2.substitute({ "x_00" : x_0, "x_10" : zero1, "x_01":zero1, "x_11":x_1 }) assert w2_11 == w1 lhs = w2.substitute({ "x_00" : zero1, "x_10" : x_0, "x_01":zero1, "x_11":x_1 }) assert lhs == w1 or lhs == 0 lhs = w2.substitute({ "x_00" : x_0*y_0, "x_10" : x_1*y_0, "x_01" : x_0*y_1, "x_11" : x_1*y_1, }) w1_y = w1.substitute({ "x_0" : y_0, "x_1" : y_1, }) rhs = w1 * w1_y assert lhs == rhs lhs = w3.substitute({ "x_000" : x_00*y_0, "x_010" : x_01*y_0, "x_001" : x_00*y_1, "x_011" : x_01*y_1, "x_100" : x_10*y_0, "x_110" : x_11*y_0, "x_101" : x_10*y_1, "x_111" : x_11*y_1, }) rhs = w2 * w1_y assert lhs == rhs lhs = w3.substitute({ "x_000" : y_0*x_00, "x_010" : y_0*x_10, "x_001" : y_0*x_01, "x_011" : y_0*x_11, "x_100" : y_1*x_00, "x_110" : y_1*x_10, "x_101" : y_1*x_01, "x_111" : y_1*x_11, }) rhs = w2 * w1_y assert lhs == rhs, "%s != %s"%(lhs, rhs) lhs = w3.substitute({ "x_000" : y_0*x_00, "x_010" : y_1*x_00, "x_001" : y_0*x_01, "x_011" : y_1*x_01, "x_100" : y_0*x_10, "x_110" : y_1*x_10, "x_101" : y_0*x_11, "x_111" : y_1*x_11, }) rhs = w2 * w1_y assert lhs == rhs, "%s != %s"%(lhs, rhs) if argv.verbose: print("G =") print(shortstr(G)) print("w1 =", w1) print("w2 =", w2) print("w3 =", w3) print()
def search(): # Bravyi, Haah, 1209.2426v1 sec IX. # https://arxiv.org/pdf/1209.2426.pdf verbose = argv.get("verbose") m = argv.get("m", 6) # _number of rows k = argv.get("k", None) # _number of odd-weight rows # these are the variables N_x xs = list(cross([(0, 1)]*m)) maxweight = argv.maxweight minweight = argv.get("minweight", 1) xs = [x for x in xs if minweight <= sum(x)] if maxweight: xs = [x for x in xs if sum(x) <= maxweight] N = len(xs) lhs = [] rhs = [] # bi-orthogonality for a in range(m): for b in range(a+1, m): v = zeros2(N) for i, x in enumerate(xs): if x[a] == x[b] == 1: v[i] = 1 if v.sum(): lhs.append(v) rhs.append(0) # tri-orthogonality for a in range(m): for b in range(a+1, m): for c in range(b+1, m): v = zeros2(N) for i, x in enumerate(xs): if x[a] == x[b] == x[c] == 1: v[i] = 1 if v.sum(): lhs.append(v) rhs.append(0) # # dissallow columns with weight <= 1 # for i, x in enumerate(xs): # if sum(x)<=1: # v = zeros2(N) # v[i] = 1 # lhs.append(v) # rhs.append(0) if k is not None: # constrain to k _number of odd-weight rows assert 0<=k<m for a in range(m): v = zeros2(N) for i, x in enumerate(xs): if x[a] == 1: v[i] = 1 lhs.append(v) if a<k: rhs.append(1) else: rhs.append(0) A = array2(lhs) rhs = array2(rhs) #print(shortstr(A)) B = pseudo_inverse(A) soln = dot2(B, rhs) if not eq2(dot2(A, soln), rhs): print("no solution") return if verbose: print("soln:") print(shortstr(soln)) soln.shape = (N, 1) rhs.shape = A.shape[0], 1 K = array2(list(find_kernel(A))) #print(K) #print( dot2(A, K.transpose())) #sols = [] #for v in span(K): best = None density = 1.0 size = 99*N trials = argv.get("trials", 1024) count = 0 for trial in range(trials): u = rand2(len(K), 1) v = dot2(K.transpose(), u) #print(v) v = (v+soln)%2 assert eq2(dot2(A, v), rhs) if v.sum() > size: continue size = v.sum() Gt = [] for i, x in enumerate(xs): if v[i]: Gt.append(x) if not Gt: continue Gt = array2(Gt) G = Gt.transpose() assert is_morthogonal(G, 3) if G.shape[1]<m: continue if 0 in G.sum(1): continue if argv.strong_morthogonal and not strong_morthogonal(G, 3): continue #print(shortstr(G)) # for g in G: # print(shortstr(g), g.sum()) # print() _density = float(G.sum()) / (G.shape[0]*G.shape[1]) #if best is None or _density < density: if best is None or G.shape[1] <= size: best = G size = G.shape[1] density = _density if 0: #sols.append(G) Gx = even_rows(G) assert is_morthogonal(Gx, 3) if len(Gx)==0: continue GGx = array2(list(span(Gx))) assert is_morthogonal(GGx, 3) count += 1 print("found %d solutions" % count) if best is None: return G = best #print(shortstr(G)) for g in G: print(shortstr(g), g.sum()) print() print("density:", density) print("shape:", G.shape) G = linear_independent(G) A = list(span(G)) print(strong_morthogonal(A, 1)) print(strong_morthogonal(A, 2)) print(strong_morthogonal(A, 3)) #print(shortstr(dot2(G, G.transpose()))) if 0: B = pseudo_inverse(A) v = dot2(B, rhs) print("B:") print(shortstr(B)) print("v:") print(shortstr(v)) assert eq2(dot2(B, v), rhs)
def genus_enum3(code=None, verbose=False): if code is None: code = get_code() G = code.G print(shortstr(G)) m, n = G.shape rank = 8 poly = lambda cs : Poly(cs, rank, "x_{000} x_{001} x_{010} x_{011} x_{100} x_{101} x_{110} x_{111}".split()) cs = {} assert len(G) < 14 items = list(span(G)) for v0 in items: print(".",end='',flush=True) for v1 in items: for v2 in items: exp = [0, 0, 0, 0, 0, 0, 0, 0] #vv = numpy.array([2*v0, v1]) for i in range(n): exp[4*v0[i] + 2*v1[i] + v2[i]] += 1 exp = tuple(exp) cs[exp] = cs.get(exp, 0) + 1 #break print() p = poly(cs) if argv.latex: print(p) else: print(p.flatstr()) print() CCZ = numpy.array([ [1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, -1]]) q = p.transform(CCZ) print("invariant under CCZ", q==p) CS2 = numpy.array([ [1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, -1, 0]]) q = p.transform(CS2) print("invariant under CS2", q==p) CCX = numpy.array([ [1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 1, 0]]) q = p.transform(CCX) print("invariant under CCX", q==p) T3 = numpy.array([ [1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, -1, 0, 0, 0]]) q = p.transform(T3) print("invariant under T3", q==p) A = numpy.array([ [1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, -1, 0, 0, 0]]) q = p.transform(A) print("invariant under A", q==p)
def genus_enum2(code=None, verbose=False): if code is None: code = get_code() G = code.G print(shortstr(G)) m, n = G.shape poly = lambda cs : Poly(cs, 4, "x_{00} x_{01} x_{10} x_{11}".split()) cs = {} for v0 in span(G): print(".",end='',flush=True) for v1 in span(G): exp = [0, 0, 0, 0] #vv = numpy.array([2*v0, v1]) for i in range(n): exp[2*v0[i] + v1[i]] += 1 exp = tuple(exp) cs[exp] = cs.get(exp, 0) + 1 #break print() p = poly(cs) if argv.latex: print(p) else: print(p.flatstr()) CZ = numpy.array([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, -1]]) q = p.transform(CZ) print("invariant under CZ", q==p) CS2 = numpy.array([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, -1, 0]]) q = p.transform(CS2) print("invariant under CS2", q==p) CX = numpy.array([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]) q = p.transform(CX) print("invariant under CX", q==p) T2 = numpy.array([ [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], [-1, 0, 0, 0]]) q = p.transform(T2) print("invariant under T2", q==p) A = numpy.array([ [0, 0, 1, 0], [0, 0, 0, 1], [0, 1, 0, 0], [-1, 0, 0, 0]]) q = p.transform(A) print("invariant under A", q==p)
def triortho(): code = get_code() code.dump() print(code) Gx = [] for u in code.G: print(shortstr(u), u.sum()%2) parity = u.sum()%2 if parity==0: Gx.append(u) Gx = array2(Gx) print("is_triorthogonal:", code.is_triorthogonal()) A = array2(list(span(Gx))) print("span(Gx) is_morthogonal(2):", is_morthogonal(A, 2)) print("span(Gx) is_morthogonal(3):", is_morthogonal(A, 3)) return G = code.G # A = array2(list(span(G))) # poly = {} # for v in A: # w = v.sum() # poly[w] = poly.get(w, 0) + 1 # print(poly) k, n = G.shape if 0: from comm import Poly a = Poly({(1,0):1}) b = Poly({(0,1):1}) poly = Poly.zero(2) for v in span(G): w = v.sum() term = Poly({(n-w,0) : 1}) * Poly({(0,w) : 1}) poly = poly + term print(poly) # print higher genus weight enumerator genus = argv.get("genus", 1) assert 1<=genus<=4 N = 2**genus idxs = list(cross([(0,1)]*genus)) cs = {} # _coefficients : map exponent to coeff for vs in cross([list(span(G)) for _ in range(genus)]): key = [0]*N for i in range(n): ii = tuple(v[i] for v in vs) idx = idxs.index(ii) key[idx] += 1 key = tuple(key) cs[key] = cs.get(key, 0) + 1 #print(cs) keys = list(cs.keys()) keys.sort() print(idxs) for key in keys: print(key, cs[key])
def search_selfdual(): verbose = argv.get("verbose") m = argv.get("m", 6) # _number of rows k = argv.get("k", None) # _number of odd-weight rows maxweight = argv.get("maxweight", m) minweight = argv.get("minweight", 1) # these are the variables N_x print("building xs...") if 0: xs = cross([(0, 1)]*m) xs = [x for x in xs if minweight <= sum(x) <= maxweight] prune = argv.get("prune", 0.5) xs = [x for x in xs if random() < prune] xs = [] N = argv.get("N", m*100) colweight = argv.get("colweight", maxweight) assert colweight <= m for i in range(N): x = [0]*m total = 0 while total < colweight: idx = randint(0, m-1) if x[idx] == 0: x[idx] = 1 total += 1 xs.append(x) N = len(xs) lhs = [] rhs = [] # bi-orthogonality for a in range(m): for b in range(a+1, m): v = zeros2(N) for i, x in enumerate(xs): if x[a] == x[b] == 1: v[i] = 1 if v.sum(): lhs.append(v) rhs.append(0) k = 0 # all rows must have even weight # constrain to k _number of odd-weight rows assert 0<=k<m for a in range(m): v = zeros2(N) for i, x in enumerate(xs): if x[a] == 1: v[i] = 1 lhs.append(v) if a<k: rhs.append(1) else: rhs.append(0) logops = argv.logops A = array2(lhs) rhs = array2(rhs) #print(shortstr(A)) print("solve...") B = pseudo_inverse(A) soln = dot2(B, rhs) if not eq2(dot2(A, soln), rhs): print("no solution") return if verbose: print("soln:") print(shortstr(soln)) soln.shape = (N, 1) rhs.shape = A.shape[0], 1 K = array2(list(find_kernel(A))) print("kernel:", K.shape) if len(K)==0: return #print(K) #print( dot2(A, K.transpose())) #sols = [] #for v in span(K): best = None density = 1.0 size = 99*N trials = argv.get("trials", 1024) count = 0 print("trials...") for trial in range(trials): u = rand2(len(K), 1) v = dot2(K.transpose(), u) #print(v) v = (v+soln)%2 assert eq2(dot2(A, v), rhs) if v.sum() >= size: continue if v.sum() < m: continue if v.sum(): print(v.sum(), end=" ", flush=True) size = v.sum() if logops is not None and size != 2*m+logops: continue Gt = [] for i, x in enumerate(xs): if v[i]: Gt.append(x) Gt = array2(Gt) G = Gt.transpose() if dot2(G, Gt).sum() != 0: # not self-dual print(shortstr(dot2(G, Gt))) assert 0 return #if G.shape[1]<m: # continue if 0 in G.sum(1): print(".", end="", flush=True) continue #print(shortstr(G)) # for g in G: # print(shortstr(g), g.sum()) # print() _density = float(G.sum()) / (G.shape[0]*G.shape[1]) #if best is None or _density < density: if best is None or G.shape[1] <= size: best = G size = G.shape[1] density = _density if 0: #sols.append(G) Gx = even_rows(G) assert is_morthogonal(Gx, 3) if len(Gx)==0: continue GGx = array2(list(span(Gx))) assert is_morthogonal(GGx, 3) count += 1 print("found %d solutions" % count) if best is None: return G = best #print(shortstr(G)) f = open("selfdual.ldpc", "w") for spec in ["Hx =", "Hz ="]: print(spec, file=f) for g in G: print(shortstr(g), file=f) f.close() print() print("density:", density) print("shape:", G.shape) if 0: B = pseudo_inverse(A) v = dot2(B, rhs) print("B:") print(shortstr(B)) print("v:") print(shortstr(v)) assert eq2(dot2(B, v), rhs)
def search_extend(): # Extend the checks of a random code to make it triorthogonal. # Based on the search function above. verbose = argv.get("verbose") m = argv.get("m", 6) n = argv.get("n", m+2) k = argv.get("k") # odd _numbered rows ( logical operators) code = argv.get("code", "rand") if code == "rand": while 1: G0 = rand2(m, n) counts = G0.sum(0) if min(counts)==2 and rank(G0) == m: cols = set() for i in range(n): cols.add(tuple(G0[:, i])) if len(cols) == n: # no repeated cols break elif code == "toric": G0 = parse(""" 11.11... .111..1. 1...11.1 """) # l=2 toric code X logops + X stabs l = argv.get("l", 3) G0 = build_toric(l) m, n = G0.shape else: return code = Code(G0, check=False) print(shortstr(G0)) print("is_triorthogonal:", code.is_triorthogonal()) # these are the variables N_x xs = list(cross([(0, 1)]*m)) N = len(xs) lookup = {} for i, x in enumerate(xs): lookup[x] = i lhs = [] rhs = [] taken = set() for i in range(n): x = G0[:, i] idx = lookup[tuple(x)] assert idx not in taken taken.add(idx) if verbose: for idx in range(N): print(idx, xs[idx], "*" if idx in taken else "") for idx in taken: v = zeros2(N) v[idx] = 1 lhs.append(v) rhs.append(1) # bi-orthogonality for a in range(m): for b in range(a+1, m): v = zeros2(N) for i, x in enumerate(xs): if x[a] == x[b] == 1: v[i] += 1 assert v.sum() lhs.append(v) rhs.append(0) # tri-orthogonality for a in range(m): for b in range(a+1, m): for c in range(b+1, m): v = zeros2(N) for i, x in enumerate(xs): if x[a] == x[b] == x[c] == 1: v[i] += 1 assert v.sum() lhs.append(v) rhs.append(0) # dissallow columns with weight <= 1 for i, x in enumerate(xs): if sum(x)<=1: v = zeros2(N) v[i] = 1 lhs.append(v) rhs.append(0) if k is not None: # constrain to k _number of odd-weight rows assert 0<=k<m for a in range(m): v = zeros2(N) for i, x in enumerate(xs): if x[a] == 1: v[i] = 1 lhs.append(v) if a<k: rhs.append(1) else: rhs.append(0) A = array2(lhs) rhs = array2(rhs) if verbose: print("lhs:") print(shortstr(A)) print("rhs:") print(shortstr(rhs)) B = pseudo_inverse(A) soln = dot2(B, rhs) if not eq2(dot2(A, soln), rhs): print("no solution") return if verbose: print("soln:") print(shortstr(soln)) soln.shape = (N, 1) rhs.shape = A.shape[0], 1 K = array2(list(find_kernel(A))) best = None density = 1.0 size = 9999*n trials = argv.get("trials", 1024) count = 0 for trial in range(trials): u = rand2(len(K), 1) v = dot2(K.transpose(), u) #print(v) assert dot2(A, v).sum()==0 #if v.sum() != n: # continue assert v[0]==0 v = (v+soln)%2 assert eq2(dot2(A, v), rhs) Gt = list(G0.transpose()) for i, x in enumerate(xs): if v[i] and not i in taken: Gt.append(x) if not Gt: continue Gt = array2(Gt) G = Gt.transpose() if verbose: print("G0") print(shortstr(G0)) print("solution:") print(shortstr(G)) assert is_morthogonal(G, 3) if G.shape[1]<m: continue if 0 in G.sum(1): continue #print(shortstr(G)) # for g in G: # print(shortstr(g), g.sum()) # print() _density = float(G.sum()) / (G.shape[0]*G.shape[1]) #if best is None or _density < density: if best is None or G.shape[1] < size: best = G density = _density size = G.shape[1] if 0: #sols.append(G) Gx = even_rows(G) assert is_morthogonal(Gx, 3) if len(Gx)==0: continue GGx = array2(list(span(Gx))) assert is_morthogonal(GGx, 3) count += 1 print("found %d solutions" % count) G = best #print(shortstr(G)) for g in G: print(shortstr(g), g.sum()) print() print("density:", density)
idx = None items = list(get_all()) def get(dim, idx): for (_dim, _idx, G) in items: if dim == _dim and idx == _idx: return G if 0: for (dim, idx, G) in get_all(): print(dim, idx) print(shortstr(G)) print() maximal = [ (15, 1, "Three copies of RM(1,4)"), (14, 1, "Direct sum of RM(1,4) and doubling of d+16."), (13, 1, "Doubling of g24 of order of Aut is 1002795171840."), (13, 2, "Doubling of (d10e27)+ of order of Aut is 443925135360."), (13, 3, "Doubling of d+24 of order of Aut is 12054469961318400."), (13, 4, "Doubling of d2+12 of order of Aut is 4348654387200."), (13, 5, "Doubling of d6+4 of order of Aut is 36238786560."), (13, 6, "Doubling of d4+6 of order of Aut is 32614907904."), (13, 7, "Doubling of d3+8 of order of Aut is 173946175488."), (9, 1, "The code induced from the triangular graph."), ]
def hecke(self): bag0 = self.get_bag() bag1 = self.get_bag() points = [p for p in bag0 if p.desc == '0'] lines = [p for p in bag0 if p.desc == '1'] print(points) print(lines) flags = [] for p in points: ls = [l for l in p.nbd if l != p] print(p, ls) for l in ls: flags.append((p, l)) print("flags:", len(flags)) # for point in bag0: # print point, repr(point.desc) #items = [(point.idx, line.idx) for point in points for line in lines] #items = [(a.idx, b.idx) for a in points for b in points] items = [(a, b) for a in flags for b in flags] # fixing two points gives the Klein four group, Z_2 x Z_2: #for f in isomorph.search(bag0, bag1): # if f[0]==0 and f[1]==1: # print f perms = [] for f in isomorph.search(bag0, bag1): #print f g = dict((bag0[idx], bag0[f[idx]]) for idx in list(f.keys())) perm = {} for a, b in items: a1 = (g[a[0]], g[a[1]]) b1 = (g[b[0]], g[b[1]]) assert (a1, b1) in items perm[a, b] = a1, b1 perm = Perm(perm, items) perms.append(perm) write('.') print() g = Group(perms, items) print("group:", len(g)) orbits = g.orbits() #print orbits print("orbits:", len(orbits)) eq = numpy.allclose dot = numpy.dot n = len(flags) basis = [] gen = [] I = identity2(n) for orbit in orbits: A = zeros2(n, n) #print orbits for a, b in orbit: A[flags.index(a), flags.index(b)] = 1 print(shortstr(A)) print(A.sum()) #print basis.append(A) if A.sum() == 42: gen.append(A) assert len(gen) == 2 L = gen[0] P = gen[1] q = 2 assert eq(dot(L, L), L + q * I) assert eq(dot(P, P), P + q * I) assert eq(dot(L, dot(P, L)), dot(P, dot(L, P)))