def test_super(): ring = element.Q U = Space(ring, 2, grade=0) # bosonic V = Space(ring, 2, grade=1) # fermionic lhs = (U @ U @ U).get_swap([0, 2, 1]).A rhs = (U @ U @ V).get_swap([0, 2, 1]).A assert eq(lhs, rhs) lhs = (U @ V @ V).get_swap([0, 2, 1]).A rhs = (U @ U @ U).get_swap([0, 2, 1]).A assert eq(lhs, -rhs) lhs = (V @ V @ V).get_swap([1, 2, 0]).A rhs = (U @ U @ U).get_swap([1, 2, 0]).A assert eq(lhs, rhs) n = argv.get("n", 4) part = argv.get("part", (2, )) for a in range(n): for b in range(n): U = Space(ring, a, grade=0, name="U") # bosonic V = Space(ring, b, grade=1, name="V") # fermionic evn, odd = super_young(U, V, part) print((evn, odd), end=" ", flush=True) print()
def __ne__(self, other): assert self.hom == other.hom return not eq(self.A, other.A)
def __eq__(self, other): assert self.hom == other.hom, "%s != %s" % (self.hom, other.hom) return eq(self.A, other.A)
def weak_eq(self, other): assert self.A.shape == other.A.shape return eq(self.A, other.A)
def is_identity(self): assert self.tgt == self.src, "wah?" B = self.tgt.identity() return eq(self.A, B.A)
def is_zero(self): B = Lin.zero(self.tgt, self.src) return eq(self.A, B.A)
def test(): p = argv.get("p", 2) ring = element.FiniteField(p) space = Space(ring) zeros = space.zeros rand = space.rand dot = space.dot kron = space.kron direct_sum = space.direct_sum identity = space.identity coequalizer = space.coequalizer compose = space.compose rank = space.rank pseudo_inverse = space.pseudo_inverse tensor_swap = space.tensor_swap sum_swap = space.sum_swap schur = space.schur is_zero = space.is_zero is_identity = space.is_identity s = tensor_swap(3, 4) si = tensor_swap(4, 3) #print(shortstr(s)) assert eq(dot(si, s), identity(3 * 4)) assert eq(dot(s, si), identity(4 * 3)) m, n = 2, 3 A1 = rand(m, n, 1, 1) A2 = rand(m, n, 1, 1) B = kron(A1, A2) for m in range(1, 5): I = identity(m * m) s = tensor_swap(m, m) f = coequalizer(I, s) assert eq(compose(s, f), f) assert rank(f) == [1, 3, 6, 10][m - 1] # --------------------------------- m = argv.get("m", 3) n = argv.get("n", 4) if argv.toric: A = zeros(m, m) for i in range(m): A[i, i] = ring.one A[i, (i + 1) % m] = -ring.one elif argv.surface: A = zeros(m - 1, m) for i in range(m - 1): A[i, i] = ring.one A[i, (i + 1) % m] = -ring.one else: A = rand(m, n, p - 1, p - 1) if argv.transpose: A = A.transpose() print("A:") print(shortstr(A)) n, m = A.shape In = identity(n) Im = identity(m) H1s = kron(Im, A), -kron(A, Im) H1 = numpy.concatenate(H1s, axis=0) # horizontal concatenate H0s = kron(A, In), kron(In, A) H0 = numpy.concatenate(H0s, axis=1) # horizontal concatenate assert is_zero(dot(H0, H1)) assert H1.shape == (n * m + m * n, m * m) assert H0.shape == (n * n, n * m + m * n) f0 = -tensor_swap(n, n) a = direct_sum(-tensor_swap(m, n), -tensor_swap(n, m)) b = sum_swap(n * m, m * n) assert is_identity(compose(b, b)) f1 = compose(a, b) assert is_identity(compose(f1, f1)) f2 = tensor_swap(m, m) assert eq(compose(f2, H1), compose(H1, f1)) lhs, rhs = ((compose(f1, H0), compose(H0, f0))) #print("lhs:") #print(shortstr(lhs)) #print("rhs:") #print(shortstr(rhs)) assert eq(compose(f1, H0), compose(H0, f0)) g0 = coequalizer(f0, identity(f0.shape[0])) assert eq(compose(H0, g0), compose(f1, H0, g0)) e = compose(H0, g0) g1, J0 = coequalizer(f1, identity(f1.shape[0]), e) assert eq(compose(H0, g0), compose(g1, J0)) e = compose(H1, g1) g2, J1 = coequalizer(f2, identity(f2.shape[0]), e) assert eq(compose(H1, g1), compose(g2, J1)) assert is_zero(compose(J1, J0)) n = J1.shape[0] J1t = J1.transpose() mz = rank(J1t) mx = rank(J0) print("J1t:", J1t.shape, rank(J1t)) print(shortstr(J1t)) print("J0:", J0.shape) print(shortstr(J0)) print("n:", n) print("mz:", mz) print("mx:", mx) print("k =", n - mx - mz)
def is_identity(self, A): return eq(A, self.identity(A.shape[0]))
def is_zero(self, A): return eq(A, self.zeros(*A.shape))