def __init__(self, ring): self.ring = ring self.zero = Space(ring, 0, name="N") # null self.zero._dual = self.zero self.one = Space(ring, 1, name="K") # the underlying field is the tensor unit self.one._dual = self.one
def mk_ising(m, n): U = Space(ring, m, 0, "U") V = Space(ring, n, 1, "V") A = Lin(U, V) # U <--- V for i in range(m): A[i, i] = one if i + 1 < n: A[i, i + 1] = -one return A
def randchain(ring, n, m): V = Space(ring, n, 1, "V") U = Space(ring, m, 0, "U") B = Lin.rand(U, V) A = B.kernel() A = Lin(A.tgt, A.src.asgrade(2), A.A) # yikes assert (B * A).is_zero() C = B.cokernel() C = Lin(C.tgt.asgrade(-1), C.src, C.A) assert (C * B).is_zero() c = Chain([A, B, C]) return c
def test_gf(): ring = GF(4) x = ring.x space = Space(ring) m = argv.get("m", 3) n = argv.get("n", 4) one = ring.one A = elim.zeros(ring, m, n) for i in range(m): for j in range(n): A[i, j] = choice(ring.elements) H = Lin(Space(ring, m, 0), Space(ring, n, 1), A) #print(H) c = Chain([H])
def rand(tgt, src, mindim=0, maxdim=4, name="A"): # tgt <---- src assert tgt.rig == src.rig rig = tgt.rig ring = rig.ring A = numpy.empty((tgt.n, src.n), dtype=object) for row in tgt: for col in src: n = randint(mindim, maxdim) A[row, col] = Space(ring, n, name="%s_%d%d" % (name, row, col)) return Cell1(tgt, src, A)
def test_frobenius(): # ---------------------------------------------------- # Here we construct a Frobenius algebra object # See: https://math.ucr.edu/home/baez/week174.html #ring = element.Z # too slow class Ring(element.Type): one = 1 zero = 0 ring = Ring() rig = Rig(ring) m = Cell0(rig, 2, "m") n = Cell0(rig, 2, "n") #A = Cell1.rand(m, n, name="A") # too slow S = lambda n, name: Space(ring, n, 0, name) A = Cell1(m, n, [[S(2, "A0"), S(1, "A1")], [S(0, "A2"), S(1, "A3")]]) #print(A.dimstr()) make_frobenius(A)
def test_chain_tensor(): #p = argv.get("p", 3) #ring = element.FiniteField(p) ring = element.Q space = Space(ring) m = argv.get("m", 3) n = argv.get("n", 4) one = ring.one if argv.toric: V = Space(ring, n, 1, "V") U = Space(ring, m, 0, "U") A = Lin(U, V) for i in range(m): A[i, i] = one A[i, (i + 1) % m] = -one elif argv.surface: V = Space(ring, m, 1, "V") U = Space(ring, m - 1, 0, "U") A = Lin(U, V) for i in range(m - 1): A[i, i] = one A[i, (i + 1) % m] = -one else: V = Space(ring, n, 1, "V") U = Space(ring, m, 0, "U") A = Lin.rand(U, V) c = Chain([A]) print(c) c.dump()
def test_chainmap(): p = argv.get("p", 2) ring = element.FiniteField(p) #ring = element.Q one = ring.one space = Space(ring) def mk_ising(m, n): U = Space(ring, m, 0, "U") V = Space(ring, n, 1, "V") A = Lin(U, V) # U <--- V for i in range(m): A[i, i] = one if i + 1 < n: A[i, i + 1] = -one return A A = mk_ising(3, 4) c = Chain([A]) f = c.identity() zero = ChainMap(c, c) assert f != zero assert f == f assert f != 2 * f assert f + f == 2 * f assert f - f == zero B = mk_ising(2, 2) d = Chain([B]) fn = Lin(A.src, B.src) for i in range(len(B.src)): fn[i, i] = one fm = Lin(A.tgt, B.tgt) for i in range(len(B.tgt)): fm[i, i] = one f = ChainMap(c, d, [fn, fm]) # ----------------------------------- m, n = 8, 10 V1 = Space(ring, n, 1, "V1") V0 = Space(ring, m, 0, "V0") A = Lin.rand(V0, V1) # V0 <--- V1 c = Chain([A]) U0 = Space(ring, m, 0, "U0") f0 = Lin.rand(V0, U0) f1, B = A.pullback(f0) d = Chain([B]) f = ChainMap(c, d, [f1, f0]) # ----------------------------------- # construct a chain map (and a chain) from a # pullback of a grade zero map. m, n, p = 5, 6, 1 V1 = Space(ring, n, 1, "V1") V0 = Space(ring, m, 0, "V0") #A = Lin.rand(V0, V1) # V0 <--- V1 A = Lin(V0, V1) for i in range(m): A[i, i] = one A[i, (i + 1)] = one a = Chain([A]) #print("A:") #print(A) U0 = Space(ring, p, 0, "U0") f0 = Lin(V0, U0) for i in range(p): f0[i, i] = one f1, B = A.pullback(f0) b = Chain([B]) #print("B:") #print(B) f = ChainMap(a, b, [f1, f0]) #print(f0) #print(f1) g = ChainMap(a, b) h = f.coequalizer(g) #print(h) #print(h[0]) #print(h[1]) c = h.tgt C = c[0] #print(C.shape, C.rank()) #print(C) # ----------------------------------- # construct a 'puncture' of a repitition code # as a cokernel m, n, p = 5, 6, 1 V1 = Space(ring, n, 1, "V1") V0 = Space(ring, m, 0, "V0") #A = Lin.rand(V0, V1) # V0 <--- V1 A = Lin(V0, V1) for i in range(m): A[i, i] = one A[i, (i + 1)] = one a = Chain([A]) U1 = Space(ring, 1, 1, "U1") U0 = Space(ring, 2, 0, "U0") B = Lin(U0, U1) B[0, 0] = one B[1, 0] = one b = Chain([B]) offset = 2 # where to puncture f0 = Lin(V0, U0) f0[0 + offset, 0] = one f0[1 + offset, 1] = one f1 = Lin(V1, U1) f1[offset + 1, 0] = one f = ChainMap(a, b, [f1, f0]) h = f.cokernel() c = h.tgt # ----------------------------------- # Here we puncture a bit from a parity check matrix # by using a cokernel. This deletes that column, # as well as all the rows with support therein. m, n, p = 5, 6, 1 V1 = Space(ring, n, 1, "V1") V0 = Space(ring, m, 0, "V0") A = Lin.rand(V0, V1) # V0 <--- V1 a = Chain([A]) #print(A) col = 0 rows = [] for i in range(V0.n): if A[i, col]: rows.append(i) U1 = Space(ring, 1, 1, "U1") U0 = Space(ring, len(rows), 0, "U0") B = Lin(U0, U1) for i in range(U0.n): B[i, 0] = one b = Chain([B]) #print(B) f0 = Lin(V0, U0) for i, row in enumerate(rows): f0[row, i] = one #print(f0) f1 = Lin(V1, U1) f1[col, 0] = one f = ChainMap(a, b, [f1, f0]) h = f.cokernel() c = h.tgt
def main(): # ---------------------------- # Gaussian integers R = NumberRing((-1, 0)) one = R.one i = R.i assert i * i == -one assert i**3 == -i assert (1 + i)**2 == 2 * i assert (2 + i) * (2 - i) == 5 assert (3 + 2 * i) * (3 - 2 * i) == 13 items = [] i = R.i_find() while len(items) < 20: items.append(i.__next__()) items.sort() #print(' '.join(str(x) for x in items)) # reflection group i = R.i I = Mobius(R) a = Mobius(R, 1, 0, 0, 1, True) b = Mobius(R, i, 0, 0, 1, True) c = Mobius(R, -1, 0, 1, 1, True) d = Mobius(R, 0, 1, 1, 0, True) gens = [a, b, c, d] if 0: # yes, works... G = mulclose(gens, maxsize=100) for f in G: for g in G: for h in G: assert f * (g * h) == (f * g) * h return # Coxeter reflection group: a--4--b--4--c--3--d for g in gens: assert g.order() == 2 assert (a * b).order() == 4 assert (a * c).order() == 2 assert (a * d).order() == 2 assert (b * c).order() == 4 assert (b * d).order() == 2 assert (c * d).order() == 3 # rotation group a = Mobius(R, -i, 0, 0, 1) b = Mobius(R, -i, 0, i, 1) c = Mobius(R, 1, 1, -1, 0) assert a.order() == 4 assert b.order() == 4 assert c.order() == 3 # ---------------------------- # Eisenstein integers R = NumberRing((-1, -1)) one = R.one i = R.i assert i**3 == 1 assert 1 + i + i**2 == 0 # ---------------------------- # Kleinian integers R = NumberRing((-2, -1)) one = R.one i = R.i assert i * (-1 - i) == 2 assert i * (1 + i) == -2 # ---------------------------- # Golden (Fibonacci) integers R = NumberRing((1, 1)) one = R.one i = R.i assert i**2 == i + 1 assert i**3 == 2 * i + 1 assert i**4 == 3 * i + 2 # ---------------------------- R = NumberRing((-1, 0)) I = Ideal(R, 2 - R.i) S = R / I zero, one, i = S.zero, S.one, S.i assert 1 + i != 0 assert 2 - i == 0 assert 2 + i != 0 assert 1 - i == 2 + i V = Space(S, 2) SL = S.get_sl(V) GL = S.get_gl(V) def lin(a, b, c, d): a = S.promote(a) b = S.promote(b) c = S.promote(c) d = S.promote(d) return Lin(V, V, [[a, b], [c, d]]) # generators for SL gen = lin(0, 1, -1, 0), lin(1, 0, 1, 1), lin(1, 0, i, 1) G = mulclose(gen) assert len(G) == 120 i = S.i I = Mobius(S) if 0: # This just does not work over S a = Mobius(S, 1, 0, 0, 1, True) b = Mobius(S, i, 0, 0, 1, True) c = Mobius(S, -1, 0, 1, 1, True) d = Mobius(S, 0, 1, 1, 0, True) gens = [a, b, c, d] G = mulclose(gens) inv = {} for g in G: for h in G: if g * h == I: inv[g] = h inv[h] = g assert (g == h) == (hash(g) == hash(h)) for f in G: print(g) print(h) print(f) assert (g * h) * f == g * (h * f) print() assert len(G) == 240 return G, hom = cayley(G) assert len(G) == 240 G.do_check() return # rotation group gens = [a * b, b * c, c * d]