# gram.py # Gram determinants for the pairings. With 2n points, the Gram matrix of the vectors # associated to the pairings is x^loops for the orthogonal group, x being the dimension, # and (-1)^n (-x)^loops for the symplectic group, where loops is the number of blocks of # the supremum of the 2 pairings. We check the following formulas, as polynomial # identities for n <= 3, by evaluating at enough integers, and at a few integers for n = 4: # (1) orthogonal case: the determinant is the product over the Young diagrams with n boxes # of the numbers prod (x + 2j - i - 1), over the boxes (i,j), raised to the number of # standard tableaux of the diagram with doubled rows, # (2) symplectic case: same, with the numbers prod (x + i - 2j + 1), # (3) noncrossing pairings: the 2 Gram matrices are conjugate by a diagonal matrix of # signs, and their common determinant is the meander determinant, namely the product # of U_h(x)^(E(n,h) - E(n,h+1)), with U_h being the monic Chebycheff polynomials, and # E(n,h) = binom(2n, n-h) - binom(2n, n-h-1). # We check as well the contributions of the pairings, whose product is the determinant: # (4) a pairing is a fixed point free involution, and by taking the shape of its insertion # tableau, transposing, and halving the rows, we obtain a Young diagram with n boxes. # The contribution is then prod (x + 2j - i - 1) in the orthogonal case, and # prod (x + i - 2j + 1) in the symplectic case, over the boxes (i,j) of this diagram, # (5) a noncrossing pairing contributes with the product of U_d(x)/U_{d-1}(x) over its # arches, d being the depth of the arch, and these numbers are the squared norms # which appear when orthogonalizing the vectors, ordered by increasing Dyck paths, # (6) unitary case: the pairings matching the colors correspond to the permutations of n # points, the Gram matrix is eps^n (eps x)^cycles, and a permutation contributes with # prod (x + eps (j - i)), over the boxes of the shape of its insertion tableau. import itertools from fractions import Fraction from math import comb, factorial from partitions import set_partitions, is_pairing, is_noncrossing, blocks def loops(p, q): parent = list(range(len(p))) def find(x): while parent[x] != x: x = parent[x] return x for part in (p, q): for b in blocks(part): for x in b[1:]: parent[find(x)] = find(b[0]) return len({find(x) for x in range(len(p))}) def determinant(M): # exact determinant of an integer matrix, by fraction-free elimination M = [row[:] for row in M] n, sign, prev = len(M), 1, 1 for k in range(n - 1): if M[k][k] == 0: swap = next((r for r in range(k + 1, n) if M[r][k] != 0), None) if swap is None: return 0 M[k], M[swap] = M[swap], M[k] sign = -sign for i in range(k + 1, n): for j in range(k + 1, n): M[i][j] = (M[i][j] * M[k][k] - M[i][k] * M[k][j]) // prev prev = M[k][k] return sign * M[-1][-1] def diagrams(n, largest=None): largest = n if largest is None else largest if n == 0: yield () return for a in range(min(n, largest), 0, -1): for rest in diagrams(n - a, a): yield (a,) + rest def tableaux(shape): # number of standard tableaux, by the hook length formula n, h = sum(shape), 1 for i, row in enumerate(shape): for j in range(row): below = sum(1 for r in shape[i + 1:] if r > j) h *= (row - j - 1) + below + 1 return factorial(n) // h def classical_formula(n, x, eps): d = 1 for shape in diagrams(n): c = 1 for i, row in enumerate(shape, start=1): for j in range(1, row + 1): c *= (x + 2 * j - i - 1) if eps == 1 else (x + i - 2 * j + 1) d *= c ** tableaux(tuple(2 * r for r in shape)) return d def chebycheff(h, x): a, b = 1, x if h == 0: return a for _ in range(h - 1): a, b = b, x * b - a return b def meander_formula(n, x): E = lambda h: (comb(2 * n, n - h) - (comb(2 * n, n - h - 1) if n - h - 1 >= 0 else 0)) if h <= n else 0 d = Fraction(1) for h in range(1, n + 1): d *= Fraction(chebycheff(h, x)) ** (E(h) - E(h + 1)) return d def insertion_shape(word): rows = [] for x in word: for r in rows: k = next((t for t in range(len(r)) if r[t] > x), None) if k is None: r.append(x) x = None break r[k], x = x, r[k] if x is not None: rows.append([x]) return tuple(len(r) for r in rows) def diagram(p): # the Young diagram of a pairing word = [0] * len(p) for (a, b) in [tuple(b) for b in blocks(p)]: word[a], word[b] = b, a shape = insertion_shape(word) return tuple(sum(1 for r in shape if r > j) // 2 for j in range(shape[0])) def contribution(p, x, eps): c = 1 for i, row in enumerate(diagram(p), start=1): for j in range(1, row + 1): c *= x + eps * (2 * j - i - 1) return c def depths(arches): return [sum(1 for (c, d) in arches if c <= a and b <= d) for (a, b) in arches] def arch_contribution(p, x): c = Fraction(1) for d in depths([tuple(b) for b in blocks(p)]): c *= Fraction(chebycheff(d, x), chebycheff(d - 1, x)) return c def path_area(p): # sum of the heights of the Dyck path of a noncrossing pairing opening = {min(b) for b in blocks(p)} area = height = 0 for t in range(len(p)): height += 1 if t in opening else -1 area += height return area def squared_norms(G): # squared norms of the vectors obtained by orthogonalizing, from the Gram matrix n = len(G) M = [[Fraction(a) for a in row] for row in G] norms = [] for c in range(n): norms.append(M[c][c]) for r in range(c + 1, n): f = M[r][c] / M[c][c] M[r] = [a - f * b for a, b in zip(M[r], M[c])] return norms def cycles(s, t): inverse = [0] * len(s) for i, v in enumerate(s): inverse[v] = i u, seen, c = [inverse[v] for v in t], set(), 0 for i in range(len(s)): if i not in seen: c += 1 while i not in seen: seen.add(i) i = u[i] return c def permutation_sign(p): image = {} for (a, b) in [tuple(b) for b in blocks(p)]: even, odd = (a, b) if a % 2 == 0 else (b, a) image[even // 2] = odd // 2 s, seen = 1, set() for x in image: length = 0 while x not in seen: seen.add(x) x = image[x] length += 1 if length > 0 and length % 2 == 0: s = -s return s def main(): good = True for n in (1, 2, 3, 4): P = [p for p in set_partitions(2 * n) if is_pairing(p)] NC = [p for p in P if is_noncrossing(p)] L = [[loops(p, q) for q in P] for p in P] LN = [[loops(p, q) for q in NC] for p in NC] points = range(2 * n + 1, 2 * n + 1 + (n * len(P) + 2 if n <= 3 else 3)) ok1 = ok2 = ok3 = True for x in points: ok1 = ok1 and determinant([[x ** l for l in row] for row in L]) == classical_formula(n, x, 1) ok2 = ok2 and determinant([[(-1) ** n * (-x) ** l for l in row] for row in L]) == classical_formula(n, x, -1) ok3 = ok3 and determinant([[x ** l for l in row] for row in LN]) == meander_formula(n, x) s = [permutation_sign(p) for p in NC] ok4 = all((-1) ** n * (-1) ** LN[a][b] == s[a] * s[b] for a in range(len(NC)) for b in range(len(NC))) ok5 = ok6 = True ordered = sorted(NC, key=lambda p: (path_area(p), p)) for x in (2 * n + 1, 2 * n + 2): for eps in (1, -1): product = 1 for p in P: product *= contribution(p, x, eps) ok5 = ok5 and product == classical_formula(n, x, eps) G = [[eps ** n * (eps * x) ** loops(a, b) for b in ordered] for a in ordered] ok6 = ok6 and squared_norms(G) == [arch_contribution(p, x) for p in ordered] product = Fraction(1) for p in NC: product *= arch_contribution(p, x) ok6 = ok6 and product == meander_formula(n, x) S = list(itertools.permutations(range(n))) ok7 = True for x in (n + 1, n + 2): for eps in (1, -1): product = 1 for s in S: for i, row in enumerate(insertion_shape(s), start=1): for j in range(1, row + 1): product *= x + eps * (j - i) ok7 = ok7 and determinant([[eps ** n * (eps * x) ** cycles(s, t) for t in S] for s in S]) == product print('n = %d , pairings %3d , noncrossing %2d , integers tested %3d : orthogonal %s , symplectic %s , meander %s , signs %s , contributions %s , arches %s , unitary %s' % (n, len(P), len(NC), len(points), ok1, ok2, ok3, ok4, ok5, ok6, ok7)) good = good and ok1 and ok2 and ok3 and ok4 and ok5 and ok6 and ok7 print('all checks passed' if good else 'some checks failed') if __name__ == '__main__': main()