Nullius Labs
No. 004◐ REPRODUCED2026-11-25

Disproved: If lambda majorizes mu, the normalized Macdonald difference P_lambda/P_lambda(1) - P_mu/P_mu(1) is Muirhead-positive

A public claim that this conjecture is false. We rebuilt the claimed counterexample from scratch and two separately written checkers confirmed it in exact arithmetic. Both sides of this check came from the same AI model, because the second model was unavailable. Machine-checked; not peer reviewed.

Source paper · original claim

Rerun it yourself: download the certificate and a checker, then

python3 checker_b.py certificate.json

Statement, as tested

Download statement.md
# If lambda majorizes mu, the normalized Macdonald difference P_lambda/P_lambda(1) - P_mu/P_mu(1) is Muirhead-positive

Source: https://arxiv.org/abs/2509.19649


Public claim to check: https://github.com/1337isnot1337/solved-conjectures/tree/main/results/chen-khare-sahi-macdonald

Source: Hong Chen, Apoorva Khare and Siddhartha Sahi, 'Majorization via positivity of Jack and Macdonald polynomial differences', arXiv:2509.19649v2, Section 5, Conjecture 5 ('CGS and Muirhead conjectures for Macdonald polynomials'). Definitions: partitions lambda, mu of the same size with at most n parts; P_lambda(x;q,t) the (monic) Macdonald polynomial in n variables; 1 = (1,...,1). m_nu is the monomial symmetric polynomial, M_nu = m_nu/m_nu(1). The Muirhead semiring M_S(C) over a cone C of coefficients is the set of finite C-linear combinations of finite products of the M_nu and of the differences M_lambda - M_mu with lambda majorizing mu. K_{>=0} is the cone of f in Q(q,t) with f(q,t) >= 0 for q,t in (0,1). Conjecture 5: the following are equivalent for partitions lambda, mu: (1) P_lambda(x;q,t)/P_lambda(1;q,t) - P_mu(x;q,t)/P_mu(1;q,t) lies in M_S(K_{>=0}); (2) that difference lies in K^R_{>=0} for all x in [0,infinity)^n; (2') for every q_0,t_0 in (0,1) the specialized difference lies in M_S(R_{>=0}); (3) for every q_0,t_0 in (0,1) the specialized difference is >= 0 for all x in [0,infinity)^n; (4) for some q_0,t_0 in (0,1) it is >= 0 on (0,1)^n union (1,infinity)^n; (5) lambda majorizes mu. The source shows (1)=>(2),(2')=>(3)=>(4)=>(5), so the conjecture reduces to (5)=>(1); it proves this for mu = (1^{|lambda|}) and for two variables.

What the repository offers as counterexample: n = 3 variables, lambda = (4,2,0), mu = (4,1,1) (lambda majorizes mu), q = 1/10, t = 9/10. results/chen-khare-sahi-macdonald/PROOF.md and verify.py exhibit a rational linear functional on degree-6 symmetric polynomials in 3 variables that is nonnegative on every generator product of the degree-6 part of the real Muirhead semiring (reduced to 38 products and 7 monomials) but takes the value -4538292661539/106631184392870 < 0 on the normalized Macdonald difference, so (2') and hence (1) fail although (5) holds. It also claims all translates (r+4,r+2,r) vs (r+4,r+1,r+1) fail. Only the semiring clauses are refuted; evaluation positivity (3) is not. Caveat recorded by the repository itself: the result uses the standard monic Macdonald convention, and it notes a normalization/Hall-pairing convention conflict with the source's finite-variable formulas; Lean coverage is partial (independent_cone_check.py, independent_orthogonality_check.py are further checks).
{
  "n": 3,
  "lambda": [4, 2, 0],
  "mu": [4, 1, 1],
  "q": "1/10",
  "t": "9/10",
  "L": {
    "6,0,0": "62",
    "5,1,0": "28",
    "4,2,0": "9",
    "4,1,1": "9",
    "3,3,0": "2",
    "3,2,1": "2",
    "2,2,2": "0"
  }
}

Certificate format

Download CERTIFICATE.md
# Certificate format

`certificate.json` describes a counterexample to Conjecture 5 of Chen–Khare–Sahi
(arXiv:2509.19649v2): a pair of partitions with λ majorizing μ (clause (5)) for which, at one
explicit parameter point (q₀,t₀) ∈ (0,1)², the normalized Macdonald difference
P_λ(x;q₀,t₀)/P_λ(1;q₀,t₀) − P_μ(x;q₀,t₀)/P_μ(1;q₀,t₀) is **not** in the Muirhead semiring
M_S(R≥0) (so clause (2′), and therefore clause (1), fails).

## Fields

| key | meaning |
|---|---|
| `n` | number of variables (integer; here 3) |
| `lambda` | the partition λ as a weakly decreasing list of `n` nonnegative integers (here `[4,2,0]`) |
| `mu` | the partition μ, same format (here `[4,1,1]`) |
| `q`, `t` | the parameter point, each a string holding an exact rational `"a/b"` (here `"1/10"`, `"9/10"`) |
| `L` | a linear functional on homogeneous polynomials of degree d = \|λ\| in `n` variables, see below |

`L` is a JSON object. Each key is a partition ν of d with at most `n` parts, written as `n`
comma-separated weakly decreasing nonnegative integers (e.g. `"4,1,1"`); every such partition
occurs exactly once. The value is a string holding an exact rational number, equal to L(M_ν),
where M_ν = m_ν / m_ν(1,…,1) is the normalized monomial symmetric polynomial. Equivalently, L
sends each single monomial x^e of degree d to the value listed under the decreasing
rearrangement of e, and is extended linearly.

Nothing else is in the certificate. In particular the Macdonald polynomials are **not**
supplied; the verifier computes them.

## What the certificate asserts, and why it settles the statement

1. λ majorizes μ, λ ≠ μ, and 0 < q, t < 1.
2. L(Π) ≥ 0 for every product Π of Muirhead-semiring generators that has degree d. The
   generators are M_ν (ν a partition with ≤ n parts) and M_a − M_b (a majorizes b).
3. L(P_λ/P_λ(1) − P_μ/P_μ(1)) < 0 at (q,t), where P is the monic Macdonald polynomial.

Every generator is a homogeneous polynomial, so every product of generators is homogeneous. If
the difference F (homogeneous of degree d) were a finite combination, with nonnegative real
coefficients, of products of generators, then taking degree-d parts would write F as a
nonnegative combination of degree-d products alone; by 2, L(F) ≥ 0, contradicting 3. Hence F is
not in M_S(R≥0) although λ majorizes μ: the equivalence (5) ⇔ (2′) ⇔ (1) is false. (The
pointwise-positivity clauses (2),(3),(4) are not refuted; only the semiring clauses.)

## What `verify.py` recomputes (exact rationals, standard library only)

* Majorization and the range of q, t.
* The monic Macdonald polynomials of degree d from the definition: unitriangular in the
  monomial basis with respect to dominance and orthogonal for the q,t-Hall pairing
  ⟨p_ρ,p_σ⟩ = δ_ρσ z_ρ ∏ (1−q^{ρ_i})/(1−t^{ρ_i}) on symmetric functions (all partitions of d;
  realised in d variables). Pairwise orthogonality of the whole family is checked, then the
  polynomials are restricted to n variables.
* Cross-check by a second characterization: P_λ and P_μ in n variables are eigenfunctions of
  Macdonald's operator D_n¹ = Σ_i ∏_{j≠i} (t x_i − x_j)/(x_i − x_j) T_{q,x_i}, with eigenvalue
  Σ_i q^{ν_i} t^{n−i}, and these eigenvalues are distinct over the partitions of d.
* Item 2 by brute force: all 62 generators of degree 1..6 (every majorizing pair, not just
  covers), all multisets of them of total degree 6 (133 distinct polynomials); L ≥ 0 on each.
* Item 3: the value is −4538292661539/106631184392870.

## Convention note

"Monic Macdonald polynomial" is taken in the standard sense (Macdonald's book, Ch. VI), which is
what the paper cites and uses: the verifier's polynomials reproduce the paper's own formula
(5.3) for P_(d,0) in two variables (checked for d = 2..5 during the search, not part of
verify.py). The paper's Section 2.3 writes the Hall pairing on Λ_n using only power sums p_λ
with λ₁ ≤ n; read literally for n = 3, degree 6, at this (q,t), no triangular orthogonal family
exists for that truncated pairing (the triangular candidates for (4,1,1) and (3,3,0) are not
orthogonal), so that reading does not define polynomials and is not used.

Checker A, written alongside the certificate

Download checker_a.py
#!/usr/bin/env python3
"""Verifier for a counterexample to Conjecture 5 of Chen-Khare-Sahi (arXiv:2509.19649v2).

usage: python3 verify.py certificate.json

Standard library only, exact rational arithmetic only (fractions.Fraction).

What is checked (everything is recomputed here; the certificate supplies only
n, lambda, mu, q, t and the values of a linear functional L):

 A. lambda, mu are partitions of the same size with at most n parts, lambda majorizes mu,
    and q, t are rationals in (0,1).  So clause (5) of the conjecture holds.
 B. The monic Macdonald polynomials P_nu(x; q, t) of degree d = |lambda| are computed from
    the definition: the unique family, unitriangular in the monomial basis w.r.t. dominance,
    orthogonal for the q,t-Hall pairing <p_r, p_s> = delta_rs z_r prod (1-q^{r_i})/(1-t^{r_i}).
    Existence (pairwise orthogonality of ALL partitions of d) is verified, not assumed.
    They are then restricted to n variables.
 C. Independent cross-check: the restricted P_lambda, P_mu are eigenfunctions of Macdonald's
    q-difference operator D_n^1 in n variables with eigenvalues sum_i q^{nu_i} t^{n-i}, and
    those eigenvalues are pairwise distinct over the partitions of d with <= n parts, so the
    monic triangular eigenfunction is unique.
 D. EVERY product of generators of the Muirhead semiring that is homogeneous of degree d is
    enumerated by brute force (no reduction to covers): generators are M_nu (nu a nonzero
    partition with <= n parts) and M_a - M_b (a != b, a majorizes b).  L is checked to be >= 0
    on each such product.
 E. L( P_lambda/P_lambda(1) - P_mu/P_mu(1) ) < 0.

Why this settles the statement: every generator is a homogeneous polynomial, so every product
of generators is homogeneous.  If the degree-d polynomial F = P_lambda/P_lambda(1) -
P_mu/P_mu(1) (at q0,t0) were a finite nonnegative-real combination of products of generators,
then comparing degree-d components, F would be a nonnegative combination of the degree-d
products only (the empty product 1 has degree 0).  By D, L(F) >= 0, contradicting E.  Hence
clause (2') fails at (q0,t0) while clause (5) holds, so the claimed equivalence is false.
"""
import json
import sys
from fractions import Fraction as Fr
from itertools import permutations


def fail(msg):
    print("FAILED:", msg)
    sys.exit(1)


# ---------------------------------------------------------------- partitions
def partitions_of(d, maxparts=None, maxpart=None):
    """Partitions of d as weakly decreasing tuples of positive ints."""
    if maxpart is None:
        maxpart = d
    if d == 0:
        return [()]
    if maxparts == 0:
        return []
    out = []
    for a in range(min(d, maxpart), 0, -1):
        for rest in partitions_of(d - a, None if maxparts is None else maxparts - 1, a):
            out.append((a,) + rest)
    return out


def pad(p, n):
    return tuple(p) + (0,) * (n - len(p))


def majorizes(a, b):
    """a majorizes b: equal size and all partial sums of a >= those of b."""
    L = max(len(a), len(b))
    a, b = pad(a, L), pad(b, L)
    if sum(a) != sum(b):
        return False
    sa = sb = 0
    for x, y in zip(a, b):
        sa += x
        sb += y
        if sa < sb:
            return False
    return True


# ---------------------------------------------------------------- polynomials (dict exponent -> Fraction)
def padd(p, r, c=1):
    out = dict(p)
    for e, v in r.items():
        w = out.get(e, 0) + c * v
        if w:
            out[e] = w
        else:
            out.pop(e, None)
    return out


def pmul(p, r):
    out = {}
    for e, a in p.items():
        for f, b in r.items():
            g = tuple(u + v for u, v in zip(e, f))
            out[g] = out.get(g, 0) + a * b
    return {e: v for e, v in out.items() if v}


def pscale(p, c):
    return {e: c * v for e, v in p.items() if c * v}


def mono(nu, n):
    """monomial symmetric polynomial m_nu in n variables (0 if nu has more than n parts)."""
    if len(nu) > n:
        return {}
    return {e: Fr(1) for e in set(permutations(pad(nu, n)))}


def Mnorm(nu, n):
    m = mono(nu, n)
    return pscale(m, Fr(1, len(m)))  # m_nu(1,...,1) = number of monomials


# ---------------------------------------------------------------- linear algebra over Q
def solve(A, b):
    """Solve A x = b exactly (A square, must be nonsingular)."""
    k = len(A)
    M = [list(A[i]) + [b[i]] for i in range(k)]
    for c in range(k):
        piv = next((r for r in range(c, k) if M[r][c] != 0), None)
        if piv is None:
            fail("singular linear system")
        M[c], M[piv] = M[piv], M[c]
        inv = 1 / M[c][c]
        M[c] = [v * inv for v in M[c]]
        for r in range(k):
            if r != c and M[r][c] != 0:
                f = M[r][c]
                M[r] = [x - f * y for x, y in zip(M[r], M[c])]
    return [M[i][k] for i in range(k)]


def inverse(A):
    k = len(A)
    cols = [solve(A, [Fr(int(i == j)) for i in range(k)]) for j in range(k)]
    return [[cols[j][i] for j in range(k)] for i in range(k)]


# ---------------------------------------------------------------- Macdonald polynomials from the Hall pairing
def macdonald_all(d, q, t):
    """Return (parts, C) with parts = all partitions of d and C[lam] = {nu: coeff of m_nu in P_lam},
    computed in the ring of symmetric functions (realised faithfully in d variables)."""
    parts = partitions_of(d)
    N = d  # d variables: the m_nu, |nu| = d, are linearly independent
    idx = {p: i for i, p in enumerate(parts)}
    k = len(parts)
    # R[r][nu] = coefficient of m_nu in the power sum product p_r
    R = [[Fr(0)] * k for _ in range(k)]
    for r in parts:
        poly = {(0,) * N: Fr(1)}
        for part in r:
            ps = {tuple(part if j == i else 0 for j in range(N)): Fr(1) for i in range(N)}
            poly = pmul(poly, ps)
        # symmetric => constant on orbits; read off the coefficient at the sorted exponent
        for e, v in poly.items():
            if v != poly[pad(tuple(sorted((x for x in e if x), reverse=True)), N)]:
                fail("power sum product not symmetric (internal)")
        for nu in parts:
            R[idx[r]][idx[nu]] = poly.get(pad(nu, N), Fr(0))
    # <p_r,p_r> = z_r * prod (1-q^{r_i})/(1-t^{r_i})
    Z = []
    for r in parts:
        z = Fr(1)
        for i in set(r):
            mlt = r.count(i)
            z *= Fr(i) ** mlt
            for j in range(1, mlt + 1):
                z *= j
        for part in r:
            z *= (1 - q ** part) / (1 - t ** part)
        Z.append(z)
    Rinv = inverse(R)  # m_nu = sum_r Rinv[nu][r] p_r
    G = [[sum(Rinv[a][r] * Z[r] * Rinv[b][r] for r in range(k)) for b in range(k)] for a in range(k)]
    C = {}
    for lam in parts:
        lower = [nu for nu in parts if nu != lam and majorizes(lam, nu)]
        if lower:
            A = [[G[idx[a]][idx[b]] for b in lower] for a in lower]
            rhs = [-G[idx[a]][idx[lam]] for a in lower]
            c = solve(A, rhs)
        else:
            c = []
        co = {lam: Fr(1)}
        for nu, v in zip(lower, c):
            if v:
                co[nu] = v
        C[lam] = co
    # verify the defining properties: orthogonality of every pair, positivity of norms
    def ip(u, v):
        return sum(a * b * G[idx[x]][idx[y]] for x, a in u.items() for y, b in v.items())
    for i, a in enumerate(parts):
        if ip(C[a], C[a]) <= 0:
            fail("nonpositive norm for P_%s" % (a,))
        for b in parts[i + 1:]:
            if ip(C[a], C[b]) != 0:
                fail("P_%s and P_%s are not orthogonal" % (a, b))
    return parts, C


def restrict(co, n):
    out = {}
    for nu, c in co.items():
        out = padd(out, mono(nu, n), c)
    return out


# ---------------------------------------------------------------- Macdonald's operator D_n^1 (cross-check)
def operator_check(P, nu, n, q, t, d):
    """Check  sum_i prod_{j!=i} (t x_i - x_j)/(x_i - x_j) * P(.., q x_i, ..) = eta * P
    after multiplying through by Delta = prod_{i<j} (x_i - x_j)."""
    def var(i):
        return {tuple(int(i == j) for j in range(n)): Fr(1)}
    one = {(0,) * n: Fr(1)}
    delta = one
    for i in range(n):
        for j in range(i + 1, n):
            delta = pmul(delta, padd(var(i), var(j), -1))
    lhs = {}
    for i in range(n):
        # Delta * prod_{j != i} (t x_i - x_j)/(x_i - x_j)
        #   = prod_{j != i} (t x_i - x_j) * prod_{a<b, a,b != i} (x_a - x_b) * sign
        W = one
        sign = 1
        for j in range(n):
            if j != i:
                W = pmul(W, padd(pscale(var(i), t), var(j), -1))
                if j < i:
                    sign = -sign  # (x_j - x_i) = -(x_i - x_j)
        for a in range(n):
            for b in range(a + 1, n):
                if a != i and b != i:
                    W = pmul(W, padd(var(a), var(b), -1))
        shifted = {e: v * q ** e[i] for e, v in P.items()}
        lhs = padd(lhs, pmul(W, shifted), sign)
    eig = lambda p: sum(q ** pad(p, n)[i] * t ** (n - 1 - i) for i in range(n))
    eigs = [eig(p) for p in partitions_of(d, n)]
    if len(set(eigs)) != len(eigs):
        fail("eigenvalues of D_n^1 not distinct")
    rhs = pscale(pmul(delta, P), eig(nu))
    if lhs != rhs:
        fail("P_%s is not an eigenfunction of D_n^1" % (nu,))


# ---------------------------------------------------------------- main
def main():
    if len(sys.argv) != 2:
        fail("usage: python3 verify.py certificate.json")
    with open(sys.argv[1]) as fh:
        cert = json.load(fh)
    n = cert["n"]
    lam = tuple(cert["lambda"])
    mu = tuple(cert["mu"])
    q = Fr(cert["q"])
    t = Fr(cert["t"])
    if not (isinstance(n, int) and 1 <= n <= 4):
        fail("bad n")
    for p in (lam, mu):
        if len(p) != n or any((not isinstance(x, int)) or isinstance(x, bool) or x < 0 for x in p) \
                or list(p) != sorted(p, reverse=True):
            fail("lambda/mu must be weakly decreasing nonnegative integer n-tuples")
    d = sum(lam)
    if not (1 <= d <= 8):
        fail("degree out of supported range")
    # --- A
    if sum(mu) != d or not majorizes(lam, mu) or lam == mu:
        fail("lambda does not (strictly) majorize mu")
    if not (0 < q < 1 and 0 < t < 1):
        fail("q,t must lie in (0,1)")
    strip = lambda p: tuple(x for x in p if x)
    lam_s, mu_s = strip(lam), strip(mu)

    # functional L: value on each normalized monomial symmetric polynomial M_nu of degree d
    target_parts = partitions_of(d, n)
    w = {}
    for key, val in cert["L"].items():
        nu = tuple(int(x) for x in key.split(","))
        if len(nu) != n or list(nu) != sorted(nu, reverse=True) or sum(nu) != d or min(nu) < 0:
            fail("bad key in L: %r" % key)
        w[nu] = Fr(val)
    if set(w) != {pad(p, n) for p in target_parts}:
        fail("L must be given on exactly the partitions of d with at most n parts")

    def L(poly):
        # L(M_nu) = w[nu]  <=>  L gives each monomial x^e the value w[sorted e]
        # (well defined as a linear functional on all degree-d polynomials)
        tot = Fr(0)
        for e, v in poly.items():
            if sum(e) != d:
                fail("L applied to a polynomial of wrong degree (internal)")
            tot += v * w[tuple(sorted(e, reverse=True))]
        return tot

    for p in target_parts:  # sanity: L(M_nu) really equals the stated value
        if L(Mnorm(p, n)) != w[pad(p, n)]:
            fail("internal: L(M_nu) mismatch")

    # --- B
    parts, C = macdonald_all(d, q, t)
    for p in (lam_s, mu_s):
        if C[p][p] != 1 or any(not majorizes(p, nu) for nu in C[p]):
            fail("P not monic/triangular")
    Plam = restrict(C[lam_s], n)
    Pmu = restrict(C[mu_s], n)
    # --- C
    operator_check(Plam, lam, n, q, t, d)
    operator_check(Pmu, mu, n, q, t, d)

    one_lam = sum(Plam.values())  # value at (1,...,1)
    one_mu = sum(Pmu.values())
    if one_lam == 0 or one_mu == 0:
        fail("normalisation P(1) vanishes")
    F = padd(pscale(Plam, 1 / one_lam), pscale(Pmu, 1 / one_mu), -1)

    # --- D: every degree-d product of semiring generators, by brute force
    gens = {}  # degree -> list of polynomials
    n_gen = 0
    for k in range(1, d + 1):
        ps = partitions_of(k, n)
        lst = [Mnorm(p, n) for p in ps]
        for a in ps:
            for b in ps:
                if a != b and majorizes(a, b):
                    lst.append(padd(Mnorm(a, n), Mnorm(b, n), -1))
        gens[k] = lst
        n_gen += len(lst)

    def freeze(p):
        return tuple(sorted(p.items()))

    # prods[k] = set of all distinct polynomials that are products of generators, total degree k.
    # (multiplication is commutative, so building by appending one generator at a time
    #  reaches every multiset of generators)
    prods = {0: {freeze({(0,) * n: Fr(1)})}}
    for k in range(1, d + 1):
        cur = set()
        for g in range(1, k + 1):
            for base in prods[k - g]:
                bp = dict(base)
                for gen in gens[g]:
                    cur.add(freeze(pmul(bp, gen)))
        prods[k] = cur
    n_prod = 0
    min_val = None
    for fz in prods[d]:
        val = L(dict(fz))
        n_prod += 1
        if val < 0:
            fail("L is negative on a degree-%d product of semiring generators" % d)
        min_val = val if min_val is None else min(min_val, val)

    # --- E
    LF = L(F)
    print("n =", n, " lambda =", lam, " mu =", mu, " q =", q, " t =", t)
    print("P_lambda monomial coefficients:", {k_: str(v) for k_, v in C[lam_s].items() if len(k_) <= n})
    print("P_mu     monomial coefficients:", {k_: str(v) for k_, v in C[mu_s].items() if len(k_) <= n})
    print("P_lambda(1) =", one_lam, "  P_mu(1) =", one_mu)
    print("semiring generators of degree 1..%d: %d ; distinct degree-%d products checked: %d ; min L = %s"
          % (d, n_gen, d, n_prod, min_val))
    print("L(normalized Macdonald difference) =", LF)
    if not LF < 0:
        fail("L is not negative on the Macdonald difference")
    print("VERIFIED")


if __name__ == "__main__":
    main()

Checker B, written independently from the certificate alone

Download checker_b.py
#!/usr/bin/env python3
"""Independent checker for the claimed counterexample to Conjecture 5 of
Chen-Khare-Sahi (arXiv:2509.19649v2).  Exact rational arithmetic only.

Usage: python3 checker.py certificate.json
Prints VERIFIED as the last line and exits 0 only if every check passes.
"""
import sys
import json
import re
from fractions import Fraction
from itertools import permutations, combinations_with_replacement
from math import factorial

MAX_D = 12   # safety bounds so the brute force stays tiny
MAX_N = 6


def fail(msg):
    print("REJECTED: " + msg)
    sys.exit(1)


# ----------------------------------------------------------------- parsing
RAT = re.compile(r"^-?(0|[1-9][0-9]*)(/[1-9][0-9]*)?$")


def rat(s, name):
    if not isinstance(s, str) or not RAT.match(s):
        fail("%s is not an exact rational string: %r" % (name, s))
    return Fraction(s)


def no_dups(pairs):
    d = {}
    for k, v in pairs:
        if k in d:
            fail("duplicate JSON key %r" % k)
        d[k] = v
    return d


def is_int(x):
    return isinstance(x, int) and not isinstance(x, bool)


def partitions(d, maxparts, maxpart=None):
    """Partitions of d with at most maxparts parts, as weakly decreasing tuples
    (no padding)."""
    if maxpart is None:
        maxpart = d
    if d == 0:
        yield ()
        return
    if maxparts == 0:
        return
    for first in range(min(d, maxpart), 0, -1):
        for rest in partitions(d - first, maxparts - 1, first):
            yield (first,) + rest


def pad(p, n):
    return tuple(p) + (0,) * (n - len(p))


def majorizes(a, b):
    """a majorizes b (paper Sec. 1.2): equal size and all partial sums of a >= those of b."""
    m = max(len(a), len(b))
    a, b = pad(a, m), pad(b, m)
    if sum(a) != sum(b):
        return False
    sa = sb = 0
    for x, y in zip(a, b):
        sa += x
        sb += y
        if sa < sb:
            return False
    return True


# ------------------------------------------------------------- polynomials
# dict: exponent tuple -> Fraction (nonzero)
def padd(p, q, c=1):
    r = dict(p)
    for e, v in q.items():
        w = r.get(e, 0) + c * v
        if w == 0:
            r.pop(e, None)
        else:
            r[e] = w
    return r


def pmul(p, q):
    r = {}
    for e1, v1 in p.items():
        for e2, v2 in q.items():
            e = tuple(a + b for a, b in zip(e1, e2))
            w = r.get(e, 0) + v1 * v2
            if w == 0:
                r.pop(e, None)
            else:
                r[e] = w
    return r


def pscale(p, c):
    return {e: v * c for e, v in p.items()} if c != 0 else {}


def monomial_sym(nu, n):
    """m_nu in n variables: sum over DISTINCT permutations of nu."""
    return {e: Fraction(1) for e in set(permutations(pad(nu, n)))}


def linear(n, coeffs):
    """sum_i coeffs[i] x_i"""
    r = {}
    for i, c in coeffs.items():
        e = [0] * n
        e[i] = 1
        if c != 0:
            r[tuple(e)] = Fraction(c)
    return r


def div_exact_diff(p, a, b):
    """Exact division of p by (x_a - x_b); fails if not divisible."""
    # group by all exponents except position a, and by (e_a + e_b) handled via synthetic division in x_a
    groups = {}
    for e, v in p.items():
        key = e[:a] + (0,) + e[a + 1:]
        groups.setdefault(key, {})[e[a]] = v
    # p = sum_k x_a^k * c_k(others).  Divide by (x_a - x_b): q_{k-1} = c_k + x_b * q_k
    maxk = max((e[a] for e in p), default=0)
    by_deg = [dict() for _ in range(maxk + 1)]
    for e, v in p.items():
        key = e[:a] + (0,) + e[a + 1:]
        by_deg[e[a]][key] = v
    xb = [0] * len(next(iter(p))) if p else []
    if not p:
        return {}
    xb[b] = 1
    xb = {tuple(xb): Fraction(1)}
    res = {}
    carry = {}
    for k in range(maxk, 0, -1):
        cur = padd(by_deg[k], pmul(carry, xb))      # coefficient q_{k-1}
        for e, v in cur.items():
            ee = e[:a] + (k - 1,) + e[a + 1:]
            res[ee] = v
        carry = cur
    rem = padd(by_deg[0], pmul(carry, xb))
    if rem:
        fail("internal: inexact division by x_%d - x_%d" % (a, b))
    return res


def to_mono_basis(p, n, parts_index):
    """Express symmetric polynomial p in the m-basis; check symmetry."""
    vec = {}
    for e, v in p.items():
        key = tuple(sorted(e, reverse=True))
        if key in vec:
            if vec[key] != v:
                fail("internal: polynomial is not symmetric")
        else:
            vec[key] = v
    # every permutation must be present
    cnt = {}
    for e in p:
        key = tuple(sorted(e, reverse=True))
        cnt[key] = cnt.get(key, 0) + 1
    for key, c in cnt.items():
        if c != len(set(permutations(key))):
            fail("internal: polynomial is not symmetric (missing terms)")
        if key not in parts_index:
            fail("internal: unexpected monomial type")
    return vec


# ------------------------------------------------------ exact linear algebra
def nullspace(M):
    """Nullspace basis of square/rect matrix M (list of rows of Fractions)."""
    rows = [r[:] for r in M]
    ncols = len(rows[0])
    piv = []
    r = 0
    for c in range(ncols):
        p = None
        for i in range(r, len(rows)):
            if rows[i][c] != 0:
                p = i
                break
        if p is None:
            continue
        rows[r], rows[p] = rows[p], rows[r]
        inv = 1 / rows[r][c]
        rows[r] = [x * inv for x in rows[r]]
        for i in range(len(rows)):
            if i != r and rows[i][c] != 0:
                f = rows[i][c]
                rows[i] = [x - f * y for x, y in zip(rows[i], rows[r])]
        piv.append(c)
        r += 1
    free = [c for c in range(ncols) if c not in piv]
    basis = []
    for f in free:
        v = [Fraction(0)] * ncols
        v[f] = Fraction(1)
        for i, c in enumerate(piv):
            v[c] = -rows[i][f]
        basis.append(v)
    return basis


def inverse(M):
    k = len(M)
    A = [list(M[i]) + [Fraction(int(i == j)) for j in range(k)] for i in range(k)]
    for c in range(k):
        p = None
        for i in range(c, k):
            if A[i][c] != 0:
                p = i
                break
        if p is None:
            fail("internal: singular matrix")
        A[c], A[p] = A[p], A[c]
        inv = 1 / A[c][c]
        A[c] = [x * inv for x in A[c]]
        for i in range(k):
            if i != c and A[i][c] != 0:
                f = A[i][c]
                A[i] = [x - f * y for x, y in zip(A[i], A[c])]
    return [row[k:] for row in A]


# ------------------------------------------ Macdonald polynomials, method A
def macdonald_operator(n, d, q, t):
    """P_nu (nu partition of d, <= n parts) in n variables as eigenfunctions of
    Macdonald's operator D_n^1 = sum_i prod_{j!=i} (t x_i - x_j)/(x_i - x_j) T_{q,x_i}
    (Macdonald VI.3-4), unitriangular in the monomial basis w.r.t. dominance.
    Returns dict nu(padded) -> dict(kappa(padded) -> coeff of m_kappa)."""
    parts = [pad(p, n) for p in partitions(d, n)]
    idx = {p: i for i, p in enumerate(parts)}
    k = len(parts)
    pairs = [(a, b) for a in range(n) for b in range(a + 1, n)]
    D = [[Fraction(0)] * k for _ in range(k)]   # D[row][col]: coefficient of m_row in D m_col
    for col, nu in enumerate(parts):
        m = monomial_sym(nu, n)
        num = {}
        for i in range(n):
            Tm = {e: v * q ** e[i] for e, v in m.items()}
            term = Tm
            for j in range(n):
                if j != i:
                    term = pmul(term, linear(n, {i: t, j: -1}))
            # multiply by prod_{a<b} (x_a-x_b) / prod_{j!=i}(x_i-x_j)
            sign = 1
            for (a, b) in pairs:
                if a == i:
                    continue            # factor (x_i - x_b) cancels
                if b == i:
                    sign = -sign        # (x_a - x_i) = -(x_i - x_a) cancels with sign
                    continue
                term = pmul(term, linear(n, {a: 1, b: -1}))
            num = padd(num, term, sign)
        for (a, b) in pairs:
            num = div_exact_diff(num, a, b)
        vec = to_mono_basis(num, n, idx)
        for kappa, v in vec.items():
            D[idx[kappa]][col] = v
    eig = {nu: sum(q ** nu[i] * t ** (n - 1 - i) for i in range(n)) for nu in parts}
    if len(set(eig.values())) != k:
        fail("eigenvalues of D_n^1 are not distinct at this (q,t); operator characterization unusable")
    P = {}
    for nu in parts:
        A = [[D[r][c] - (eig[nu] if r == c else 0) for c in range(k)] for r in range(k)]
        ns = nullspace(A)
        if len(ns) != 1:
            fail("eigenspace of D_n^1 for %s is not one-dimensional" % (nu,))
        v = ns[0]
        lead = v[idx[nu]]
        if lead == 0:
            fail("eigenvector for %s has zero coefficient at m_nu" % (nu,))
        v = [x / lead for x in v]
        coeffs = {}
        for kappa in parts:
            c = v[idx[kappa]]
            if c != 0:
                if not majorizes(nu, kappa):
                    fail("eigenvector for %s is not dominance-triangular" % (nu,))
                coeffs[kappa] = c
        P[nu] = coeffs
    return P


# ------------------------------------------ Macdonald polynomials, method B
def macdonald_hall(d, q, t):
    """Monic Macdonald P_nu for ALL partitions nu of d (as symmetric functions,
    realised in d variables) from the definition: unitriangular in monomials
    w.r.t. dominance, pairwise orthogonal for
    <p_r,p_s> = delta_rs z_r prod_i (1-q^{r_i})/(1-t^{r_i}).
    Returns dict nu -> dict(kappa -> coeff), partitions unpadded tuples."""
    N = d
    parts = list(partitions(d, d))
    idx = {p: i for i, p in enumerate(parts)}
    k = len(parts)
    # power sums expanded in monomials: only the coefficient of x^kappa (kappa a partition) is needed,
    # but compute the full polynomial to stay close to the definition.
    def psum(r):
        out = {}
        for i in range(N):
            e = [0] * N
            e[i] = r
            out[tuple(e)] = Fraction(1)
        return out
    cache = {}
    def ppoly(rho):
        if rho in cache:
            return cache[rho]
        if not rho:
            res = {(0,) * N: Fraction(1)}
        else:
            res = pmul(ppoly(rho[1:]), psum(rho[0]))
        cache[rho] = res
        return res
    # p_rho = sum_kappa T[rho][kappa] m_kappa
    T = []
    for rho in parts:
        pp = ppoly(rho)
        T.append([pp.get(pad(kappa, N), Fraction(0)) for kappa in parts])
    Tinv = inverse(T)        # m_kappa = sum_rho Tinv[kappa][rho] p_rho
    def z(rho):
        out = 1
        for i in set(rho):
            mlt = rho.count(i)
            out *= i ** mlt * factorial(mlt)
        return out
    w = []
    for rho in parts:
        val = Fraction(z(rho))
        for r in rho:
            val *= (1 - q ** r) / (1 - t ** r)
        w.append(val)
    G = [[sum(Tinv[a][r] * Tinv[b][r] * w[r] for r in range(k)) for b in range(k)] for a in range(k)]
    P = {}
    for nu in parts:
        below = [kap for kap in parts if kap != nu and majorizes(nu, kap)]
        # unknown c_kap (kap in below): <m_nu + sum c m_kap, m_j> = 0 for all j in below
        if below:
            A = [[G[idx[kap]][idx[j]] for kap in below] for j in below]
            rhs = [-G[idx[nu]][idx[j]] for j in below]
            Ainv = inverse(A)
            c = [sum(Ainv[i][j] * rhs[j] for j in range(len(below))) for i in range(len(below))]
        else:
            c = []
        coeffs = {nu: Fraction(1)}
        for kap, cv in zip(below, c):
            if cv != 0:
                coeffs[kap] = cv
        P[nu] = coeffs
    # pairwise orthogonality of the whole family (this is what the definition demands)
    for a in parts:
        for b in parts:
            if a < b:
                ip = sum(ca * cb * G[idx[x]][idx[y]] for x, ca in P[a].items() for y, cb in P[b].items())
                if ip != 0:
                    fail("Hall-pairing construction: P_%s and P_%s are not orthogonal" % (a, b))
    return P


def qpoch(a, q, k):
    out = Fraction(1)
    for i in range(k):
        out *= (1 - a * q ** i)
    return out


# -------------------------------------------------------------------- main
def main():
    if len(sys.argv) != 2:
        fail("usage: python3 checker.py certificate.json")
    try:
        with open(sys.argv[1], "r") as f:
            cert = json.load(f, object_pairs_hook=no_dups)
    except SystemExit:
        raise
    except Exception as ex:
        fail("cannot read/parse certificate: %s" % ex)
    if not isinstance(cert, dict) or set(cert.keys()) != {"n", "lambda", "mu", "q", "t", "L"}:
        fail("certificate must be an object with exactly the keys n, lambda, mu, q, t, L")
    n = cert["n"]
    if not is_int(n) or not (1 <= n <= MAX_N):
        fail("n must be an integer in 1..%d" % MAX_N)

    def get_partition(name):
        p = cert[name]
        if not isinstance(p, list) or len(p) != n or not all(is_int(x) and x >= 0 for x in p):
            fail("%s must be a list of n nonnegative integers" % name)
        if any(p[i] < p[i + 1] for i in range(n - 1)):
            fail("%s is not weakly decreasing" % name)
        return tuple(p)
    lam = get_partition("lambda")
    mu = get_partition("mu")
    q = rat(cert["q"], "q")
    t = rat(cert["t"], "t")
    d = sum(lam)
    if not (1 <= d <= MAX_D):
        fail("degree out of supported range")

    # ---- item 1: clause (5) holds, parameters in range
    if sum(mu) != d:
        fail("|lambda| != |mu|")
    if lam == mu:
        fail("lambda == mu")
    if not majorizes(lam, mu):
        fail("lambda does not majorize mu")
    if not (0 < q < 1 and 0 < t < 1):
        fail("q, t must lie in the open interval (0,1)")
    print("ok: n=%d lambda=%s mu=%s, lambda majorizes mu, q=%s t=%s in (0,1)" % (n, lam, mu, q, t))

    # ---- the functional L
    parts_d = [pad(p, n) for p in partitions(d, n)]
    Lraw = cert["L"]
    if not isinstance(Lraw, dict):
        fail("L must be an object")
    expected = {",".join(map(str, p)): p for p in parts_d}
    if set(Lraw.keys()) != set(expected.keys()):
        fail("keys of L are not exactly the partitions of %d with at most %d parts" % (d, n))
    Lval = {expected[k]: rat(v, "L[%s]" % k) for k, v in Lraw.items()}

    def L(poly):
        tot = Fraction(0)
        for e, v in poly.items():
            if sum(e) != d:
                fail("internal: L applied to a polynomial of wrong degree")
            tot += v * Lval[tuple(sorted(e, reverse=True))]
        return tot

    # ---- Macdonald polynomials (two independent constructions)
    PA = macdonald_operator(n, d, q, t)
    PB_full = macdonald_hall(d, q, t)
    for nu in parts_d:
        nu_s = tuple(x for x in nu if x > 0)
        restr = {pad(kap, n): c for kap, c in PB_full[nu_s].items() if len(kap) <= n}
        if restr != PA[nu]:
            fail("Hall-pairing and operator constructions disagree for P_%s" % (nu,))
    print("ok: monic Macdonald P_nu (all %d partitions nu of %d, %d variables): Hall-pairing "
          "definition (pairwise orthogonality checked on all %d partitions) agrees with D_n^1 "
          "eigenfunction characterization" % (len(parts_d), d, n, len(PB_full)))
    # convention sanity check against the paper's formula (5.3): P_(k,0) in two variables
    for k in range(1, d + 1):
        P2 = macdonald_operator(2, k, q, t)[(k, 0)]
        for i in range(k + 1):
            want = (qpoch(q, q, k) / (qpoch(q, q, i) * qpoch(q, q, k - i))
                    * qpoch(t, q, i) * qpoch(t, q, k - i) / qpoch(t, q, k))
            got = P2.get(tuple(sorted((i, k - i), reverse=True)), Fraction(0))
            if want != got:
                fail("convention mismatch with paper formula (5.3) for P_(%d,0)" % k)
    print("ok: convention matches paper formula (5.3) for P_(k,0), k=1..%d, in two variables" % d)

    def as_poly(coeffs):
        out = {}
        for kap, c in coeffs.items():
            out = padd(out, monomial_sym(kap, n), c)
        return out

    def at_one(poly):
        return sum(poly.values(), Fraction(0))

    Plam = as_poly(PA[lam])
    Pmu = as_poly(PA[mu])
    a1, b1 = at_one(Plam), at_one(Pmu)
    if a1 == 0 or b1 == 0:
        fail("P(1,...,1) vanishes; normalization undefined")
    F = padd(pscale(Plam, 1 / a1), pscale(Pmu, 1 / b1), -1)
    if at_one(F) != 0:
        fail("internal: normalized difference does not vanish at 1")
    LF = L(F)
    print("L(P_lambda/P_lambda(1) - P_mu/P_mu(1)) = %s" % LF)
    if not LF < 0:
        fail("L is not negative on the normalized Macdonald difference")

    # ---- item 2: L >= 0 on every degree-d product of Muirhead generators
    gens = {}     # degree -> list of polynomials
    ngen = 0
    for k in range(1, d + 1):
        ps = [pad(p, n) for p in partitions(k, n)]
        g = []
        M = {}
        for p in ps:
            m = monomial_sym(p, n)
            M[p] = pscale(m, Fraction(1, len(m)))      # m_p(1) = number of monomials
            g.append(M[p])
        for a in ps:
            for b in ps:
                if a != b and majorizes(a, b):
                    g.append(padd(M[a], M[b], -1))
        gens[k] = g
        ngen += len(g)
    one = {(0,) * n: Fraction(1)}
    nprod = 0
    worst = None
    for degs in partitions(d, d):       # multiset of generator degrees
        distinct = sorted(set(degs), reverse=True)
        # for each distinct degree choose a multiset of generators of that degree
        def rec(i, acc):
            nonlocal nprod, worst
            if i == len(distinct):
                val = L(acc)
                nprod += 1
                if worst is None or val < worst:
                    worst = val
                if val < 0:
                    fail("L is negative (%s) on a product of Muirhead generators (degrees %s)" % (val, degs))
                return
            k = distinct[i]
            mult = degs.count(k)
            for combo in combinations_with_replacement(range(len(gens[k])), mult):
                cur = acc
                for gi in combo:
                    cur = pmul(cur, gens[k][gi])
                rec(i + 1, cur)
        rec(0, one)
    print("ok: L >= 0 on all %d products (multisets of the %d generators of degree 1..%d) of total "
          "degree %d; minimum value %s" % (nprod, ngen, d, d, worst))

    print("Conclusion: lambda majorizes mu (clause 5) but the specialized normalized Macdonald "
          "difference is not in M_S(R>=0) at (q,t)=(%s,%s), so clause (2') and hence clause (1) fail." % (q, t))
    print("VERIFIED")
    sys.exit(0)


if __name__ == "__main__":
    main()