"""Exact checks of the combinatorial identities. Checked statements (labels of nov2026_layered_Grothendieck.tex): eq:pipe_dreams for every subset D of the staircase of size N <= 6, the Demazure product computed by the traversal of the Introduction equals the 0-Hecke product of the word of D (cross at (i,j) = s_{i+j-1}, rows top to bottom, each row right to left); the sum over D with that product gives F(k,n,beta) = Upsilon_{w_0(k,n)}(beta) of eq:F; prop:sites every D in PD(w_0(k,n)) lies in the band B, and every D with D_0 <= D <= B (D_0 the bottom pipe dream) is in it; eq:intro_pd_probability for x != 1; eq:layered_product for every composition b of M <= 6; rmk:usp F(k,n,beta) = sum over lambda in (k^(n-1)) of s_{2 lambda}(1^(n-1)) x^|lambda|, k, n <= 6; eq:F_TH F(k,n,beta) = det[phi_{j-l} - phi_{j+l+2}], k, n <= 6. F(k,n,beta) is taken from the Toda recursion in nonlayered_S17.f_table. All arithmetic is exact (int / Fraction). """ from fractions import Fraction as Fr from itertools import product from math import comb from nonlayered_S17 import f_table BETAS = (Fr(-1, 2), Fr(1, 3), Fr(1), Fr(2)) XS = (Fr(1, 3), Fr(1, 2), Fr(1), Fr(3, 2), Fr(4)) NMAX = 6 def staircase(N): return [(i, j) for i in range(1, N) for j in range(1, N + 1 - i)] def traverse(N, D): """Demazure product as defined in the Introduction: partial D(i) is the column of pipe i.""" east, north, crossed = {}, {}, set() for j in range(1, N + 1): for i in range(N + 1 - j, 0, -1): w = i if j == 1 else east[i, j - 1] if i + j == N + 1: north[i, j] = w continue s = north[i + 1, j] if (i, j) in D and frozenset((w, s)) not in crossed: crossed.add(frozenset((w, s))) east[i, j], north[i, j] = w, s else: east[i, j], north[i, j] = s, w out = [0] * N for j in range(1, N + 1): out[north[1, j] - 1] = j return tuple(out) def hecke(N, D): """0-Hecke product of the word of D in the reading order of Knutson-Miller.""" w = list(range(1, N + 1)) for i in range(1, N): for j in range(N - i, 0, -1): if (i, j) in D: m = i + j - 1 if w[m - 1] < w[m]: w[m - 1], w[m] = w[m], w[m - 1] return tuple(w) def inversions(w): return sum(1 for a in range(len(w)) for b in range(a + 1, len(w)) if w[a] > w[b]) def w0(k, n): return tuple(range(1, k + 1)) + tuple(range(k + n, k, -1)) def layered(blocks_left_to_right): w, top = [], 0 for v in blocks_left_to_right: w += range(top + v, top, -1) top += v return tuple(w) def compositions(M): for cuts in product((0, 1), repeat=M - 1): b, size = [], 1 for c in cuts: if c: b.append(size) size = 1 else: size += 1 b.append(size) yield b def all_pipe_dreams(): """For each N <= NMAX: the list of (D, partial D).""" data = {} for N in range(1, NMAX + 1): cells = staircase(N) rows = [] for mask in range(1 << len(cells)): D = frozenset(c for t, c in enumerate(cells) if mask >> t & 1) p = traverse(N, D) assert p == hecke(N, D), (N, sorted(D)) rows.append((D, p)) assert traverse(N, frozenset()) == tuple(range(1, N + 1)) data[N] = rows print(f"eq:pipe_dreams: traversal = 0-Hecke product of the word, for all" f" {sum(len(r) for r in data.values())} pipe dreams of size N <= {NMAX}") return data def upsilon_polys(data): """Upsilon_w as {w: {|D| - ell(w): count}} for all w in S_N, N <= NMAX.""" U = {} for N, rows in data.items(): for D, p in rows: e = len(D) - inversions(p) assert e >= 0 U.setdefault(p, {}).setdefault(e, 0) U[p][e] += 1 return U def ev(poly, beta): return sum(c * beta ** e for e, c in poly.items()) def check_block_factors(data, U, F): for N, rows in data.items(): for k in range(N): n = N - k w = w0(k, n) assert inversions(w) == comb(n, 2) for beta in BETAS: assert ev(U[w], beta) == F[beta][k, n], ("eq:pipe_dreams", k, n, beta) band = {(i, j) for (i, j) in staircase(N) if k < i + j - 1 < k + n} assert len(band) == k * (n - 1) + comb(n, 2) D0 = {(k + i, j) for i in range(1, n) for j in range(1, n + 1 - i)} assert D0 <= band and len(D0) == comb(n, 2) for D, p in rows: if p == w: assert D <= band, ("prop:sites band", k, n) if D0 <= D <= band: assert p == w, ("prop:sites D_0 <= D <= B", k, n) for x in XS: if x == 1: continue pr = 1 - x if x < 1 else 1 - 1 / x P = sum(pr ** len(D) * (1 - pr) ** (len(band) - len(D)) for D, p in rows if p == w) Xp = max(Fr(1), x) assert F[x - 1][k, n] == Xp ** (k * (n - 1)) * pr ** (-comb(n, 2)) * P, \ ("eq:intro_pd_probability", k, n, x) print(f"eq:pipe_dreams with eq:F for k+n <= {NMAX}, beta in {{-1/2, 1/3, 1, 2}};" " prop:sites band and D_0 <= D <= B; eq:intro_pd_probability, x in {1/3, 1/2, 3/2, 4}") def check_layered(U, F): count = 0 for M in range(1, NMAX + 1): for left_to_right in compositions(M): b = left_to_right[::-1] # b[0] = b_1 is the last block w = layered(left_to_right) for beta in BETAS: prod_, Mi = Fr(1), M for v in b: Mi -= v prod_ *= F[beta][Mi, v] assert ev(U[w], beta) == prod_, ("eq:layered_product", left_to_right, beta) count += 1 print(f"eq:layered_product: all {count} compositions of M <= {NMAX}, beta in {{-1/2, 1/3, 1, 2}}") def schur_ones(mu, m): """s_mu(1^m) by the hook-content formula.""" if len(mu) > m: return 0 conj = [sum(1 for r in mu if r > c) for c in range(mu[0])] if mu else [] val = Fr(1) for r, row in enumerate(mu): for c in range(row): hook = row - c + conj[c] - r - 1 val *= Fr(m + c - r, hook) return val def partitions_in_box(rows, cols): if rows == 0: yield () return def rec(prefix, maxpart, left): if left == 0: yield tuple(v for v in prefix if v > 0) return for v in range(maxpart, -1, -1): yield from rec(prefix + (v,), v, left - 1) yield from rec((), cols, rows) def check_usp(F): for x in XS: for k in range(7): for n in range(1, 7): m = n - 1 total = sum(schur_ones(tuple(2 * v for v in lam), m) * x ** sum(lam) for lam in partitions_in_box(m, k)) assert total == F[x - 1][k, n], ("rmk:usp", k, n, x) print("rmk:usp: dual Cauchy expansion for k, n <= 6, x in {1/3, 1/2, 1, 3/2, 4}") def det(A): A = [row[:] for row in A] n, d = len(A), Fr(1) for c in range(n): piv = next((r for r in range(c, n) if A[r][c] != 0), None) if piv is None: return Fr(0) if piv != c: A[c], A[piv] = A[piv], A[c] d = -d d *= A[c][c] for r in range(c + 1, n): f = A[r][c] / A[c][c] for cc in range(c, n): A[r][cc] -= f * A[c][cc] return d def check_toeplitz_hankel(F): for x in XS: for n in range(1, 7): r = n - 1 P = lambda m: sum(comb(r, a) * comb(r, a + m) * x ** a for a in range(r + 1)) for k in range(7): # phi_m = s^|m| P_|m|, s = sqrt(x); conjugating by diag(s^-j) gives # entries s^(|j-l|+l-j) P_|j-l| - s^(2l+2) P_(j+l+2), all rational. A = [[x ** max(l - j, 0) * P(abs(j - l)) - x ** (l + 1) * P(j + l + 2) for l in range(k)] for j in range(k)] assert det(A) == F[x - 1][k, n], ("eq:F_TH", k, n, x) print("eq:F_TH: Toeplitz-plus-Hankel determinant for k, n <= 6, x in {1/3, 1/2, 1, 3/2, 4}") if __name__ == "__main__": F = {beta: f_table(beta, 2 * NMAX) for beta in set(BETAS) | {x - 1 for x in XS}} data = all_pipe_dreams() U = upsilon_polys(data) check_block_factors(data, U, F) check_layered(U, F) check_usp(F) check_toeplitz_hankel(F)