Sum rules analytically: the Euler-Beta machinery
Every normalization integral derived — the exact algebra our MSHT20 port runs.
Four of MSHT20's normalizations are not fitted — they are computed, exactly, at every single sampler
step, from the other 52 parameters. This chapter derives the machinery that makes that possible: one classical
special function (the Euler Beta function), one master integral, and a pile of careful bookkeeping for the
Chebyshev terms. Everything here is the mathematics behind
msht20_jax.py, the port whose parity gate passed at the $10^{-9}$ level
(PPDF-10).
Why analytic beats penalties
The sum rules of Chapter 1.4 — valence counting $\int_0^1 u_V\,dx = 2$, $\int_0^1 d_V\,dx = 1$, zero net strangeness $\int_0^1 (s - \bar s)\,dx = 0$, and momentum $\int_0^1 x \sum_i f_i(x)\,dx = 1$ — are exact consequences of the proton's quantum numbers. There are two ways to impose them on a parametrized model. The soft way adds a penalty $\lambda\,(\text{sum rule violation})^2$ to the $\chi^2$: now the rules hold only approximately, the answer depends on an arbitrary $\lambda$, and the sampler still wanders the violating directions. The hard way solves the constraints analytically: express $A_{u_V}, A_{d_V}, A_g, x_0$ in closed form in terms of the remaining parameters and substitute. The rules then hold to machine precision at every point ever evaluated; four dimensions vanish from the sampling space (52 instead of 56 — nested sampling cost scales roughly linearly in dimension, and flat normalization directions are exactly the kind that wreck slice-sampler efficiency); and no numerical quadrature runs inside the likelihood. The only requirement is that the parametrization's integrals be doable in closed form. For powers times polynomials in $\sqrt{x}$, they are — that is the Beta function's job.
One more reason, specific to this lab's evidence program: $\log Z$ comparisons require every model to be normalized on the same footing. A penalty term is an ad-hoc modification of the likelihood whose strength $\lambda$ shifts $\log Z$ by an arbitrary amount — two models with different penalty weights are not comparable. Exact constraints change nothing about the likelihood; they only restrict the hypothesis space, which is precisely what a model is. There is also a subtler statistical effect: once $A_{u_V}$ is a derived quantity, its posterior uncertainty comes entirely from the shape parameters it depends on — the sum rules induce exact correlations between normalizations and shapes, which is physics (a harder $u_V$ must be taller to hold two quarks), not an artifact.
The Euler Beta function and the master integral
Start from the product of two Gamma functions and substitute $u = zt$, $v = z(1-t)$ (so $u + v = z$, $du\,dv = z\,dz\,dt$):
$$ \Gamma(a)\Gamma(b) = \int_0^\infty\!\!\int_0^\infty u^{a-1} v^{b-1} e^{-u-v}\, du\, dv = \int_0^\infty e^{-z} z^{a+b-1} dz \int_0^1 t^{a-1}(1-t)^{b-1} dt = \Gamma(a+b)\, B(a,b)\;\;\blacksquare $$
Our code works with the shifted convenience form (FPPDF's I, kept verbatim in the port):
$$ I(a,b) \;\equiv\; \int_0^1 x^{a}(1-x)^{b}\, dx \;=\; B(a+1,\,b+1) \;=\; \frac{\Gamma(a+1)\,\Gamma(b+1)}{\Gamma(a+b+2)} $$
convergent for $a > -1$, $b > -1$ — which is why small-$x$ powers $\delta > 0$ are needed wherever a number integral (one power of $x$ lower, see below) must exist.
The parametrization gives $x u_V$, so the counting rule integrates the shape divided by $x$:
$$ 2 = \int_0^1 u_V\, dx = A_{u_V} \int_0^1 x^{\delta - 1} (1-x)^{\eta}\, dx = A_{u_V}\, I(\delta - 1, \eta) \quad\Longrightarrow\quad A_{u_V} = \frac{2}{I(\delta - 1, \eta)} $$
Note the index shift: number integrals use $\delta - 1$, momentum integrals ($\int x f\,dx =
\int (xf)\,dx$) use $\delta$ itself. This single distinction is the iq=1 / iq=2 switch
in the code's qv_int, and confusing the two is the classic sum-rule bug.
With the series $\mathcal{P} = 1 + \sum_i a_i T_i(y)$, $y = 1 - 2\sqrt{x}$, each term needs $\int x^a (1-x)^b\, y^k\, dx$. Expand $y^k = (1 - 2\sqrt{x})^k$ binomially — every term is again a pure power, just with half-integer shifts of $a$:
$$ Iy_1(a,b) \equiv \int_0^1 x^a (1-x)^b (1 - 2\sqrt{x})\, dx = I(a,b) - 2\, I(a + \tfrac12,\, b) $$
$$ Iy_2(a,b) = \int x^a (1-x)^b \big(1 - 4\sqrt{x} + 4x\big) dx = I(a,b) - 4\, I(a+\tfrac12, b) + 4\, I(a+1, b) $$
and so on up to $Iy_8$ — the rows of binomial coefficients times powers of $-2$ you can read directly in the code.
Write each $T_k$ as its polynomial in $y$ and take the same linear combination of $Iy$'s. For $k = 2$: $T_2(y) = 2y^2 - 1$, so
$$ Ic_2(a,b) \;\equiv\; \int_0^1 x^a (1-x)^b\, T_2(y)\, dx \;=\; 2\, Iy_2(a,b) - I(a,b) $$
and identically $Ic_1 = Iy_1$, $Ic_3 = 4Iy_3 - 3Iy_1$, $Ic_4 = 8Iy_4 - 8Iy_2 + I$, … Every sum-rule integral of the entire MSHT20 form is therefore a finite sum of Beta functions:
$$ \int_0^1 x^a (1-x)^b \Big(1 + \sum_i a_i T_i(y)\Big) dx \;=\; I(a,b) + \sum_i a_i\, Ic_i(a,b) $$
— the code's _cheb_int. The general valence normalization is then
$A_{u_V} = 2 \big/ \big[I(\delta{-}1,\eta) + \sum_i a_i\, Ic_i(\delta{-}1,\eta)\big]$, and likewise
$A_{d_V}$ with 2 → 1.
The momentum sum rule assembles $A_g$
Momentum is carried by all quarks plus the gluon. In the MSHT basis (with the FPPDF convention $S = 2(\bar u + \bar d) + s + \bar s$, so $u_V + d_V + S + c_+$ exhausts the quarks) the pieces are the $\delta$-index momentum integrals, and the two-term gluon contributes two integrals of its own:
with $\langle x \rangle_q = A_q [ I(\delta_q, \eta_q) + \sum_i a_{q,i} Ic_i(\delta_q, \eta_q)]$ — where $A_{u_V}, A_{d_V}$ are themselves the counting-rule outputs, so the order of evaluation matters: valence normalizations first, then momentum. Only the first gluon term's normalization is solved for; the second term (that negative small-$x$ dip) is fitted freely and enters as the constant $g_2$.
Zero strangeness fixes the crossing point $x_0$
$x s_- = A_- x^{\delta_-}(1-x)^{\eta_-}(1 - x/x_0)$ must integrate (as a number density) to zero:
— the crossing point is a pure ratio of two Beta functions (Chebyshev-dressed in general; MSHT freeze those coefficients to zero). At the publication values $\delta_- = 0.0015$, $\eta_- = 7.46$ this gives $x_0 = 1.76 \times 10^{-4}$: with $\delta_-$ that close to zero, $\mathcal{I}_1 = I(-0.9985, 7.46)$ is nearly divergent ($\Gamma(0.0015) \approx 670$), so the number integral is dominated by tiny $x$ and the crossing must sit far down to balance it. The amplitude $A_-$ stays free — the sum rule fixes where $s - \bar s$ changes sign, not how big it is.
Numerical stability: the Stirling branch
One engineering wrinkle. Float64 $\Gamma$ overflows beyond $\Gamma(171.6) \approx 10^{308}$, and even before that, ratios of huge Gammas lose digits. Large $\eta$ is physical (sea $\eta \sim 7$ is fine, but samplers explore, and other FPPDF configurations run $\eta$ large), so the code switches at $b \ge 100$ to a Stirling-type closed form,
which needs only $\Gamma(a+1)$ (small argument) and powers — no overflow, relative error $\sim 10^{-5}$ at the $b = 100$ switch point and shrinking as $b$ grows. Our port reproduces the branch and its threshold verbatim: parity means matching the reference's choices, including its approximations.
FPPDF's $g_1$ routine silently multiplies by the $A_g$ slot of the parameter vector. At publication parameters that slot holds the placeholder 1.0 — so a port that omitted the factor passes every test run at published values, and fails the first time a sampler writes something else there. Our parity gate (PPDF-10) tests at the publication point plus five random $\pm 10\%$ jitters of all 73 slots; the jittered draws exposed the factor within minutes. The general rule: parity-test a numerical port at generic points, never only at the (often special) defaults. Ninety-six checks across four levels — raw integrals, shapes, sum-rule machinery, flavour assembly — all now agree to $\lesssim 10^{-9}$.
Given: $\delta = 0.34$, $\eta = 3.75$ (the publication $u_V$ powers, rounded), and a truncated series $a_1 = -1.45$, $a_2 = 0.74$. Number integrals need $a = \delta - 1 = -0.66$, $b = 3.75$.
Step 1 — the three Beta values. $I(-0.66, 3.75) = \frac{\Gamma(0.34)\,\Gamma(4.75)}{\Gamma(5.09)} = \frac{2.6242 \times 16.586}{27.508} = 1.5822$; the half-integer shifts give $I(-0.16, 3.75) = 0.30734$ and $I(0.34, 3.75) = 0.10569$.
Step 2 — $Iy$'s. $Iy_1 = 1.5822 - 2(0.30734) = 0.96755$; $\;Iy_2 = 1.5822 - 4(0.30734) + 4(0.10569) = 0.77562$.
Step 3 — $Ic$'s. $Ic_1 = Iy_1 = 0.96755$; $\;Ic_2 = 2(0.77562) - 1.5822 = -0.03099$.
Step 4 — assemble and invert. $\mathcal{S} = I + a_1 Ic_1 + a_2 Ic_2 = 1.5822 - 1.45(0.96755) + 0.74(-0.03099) = 0.15635$, so
$$ A_{u_V} = \frac{2}{\mathcal{S}} = \frac{2}{0.15635} = 12.79 $$
Notice the violence of the Chebyshev terms: they cancel 90% of the bare integral (1.58 → 0.156), which the normalization must repay ($A$ jumps from $2/1.58 = 1.26$ to 12.8). With all six publication coefficients the exact answer is $A_{u_V} = 8.363$ — and, as a bonus check, the momentum integral then gives $\langle x \rangle_{u_V} = 0.350$: the two up-valence quarks carry 35% of the proton's momentum at $Q_0$.
Toy 3-flavour set (publication-rounded powers): $u_V$ from example (a) ($A = 12.79$, $\delta = 0.34$, $\eta = 3.75$, $a_1 = -1.45$, $a_2 = 0.74$); pure-power $d_V$ ($\delta = 0.13$, $\eta = 3.98$, $A_{d_V} = 1/I(-0.87, 3.98) = 1/5.9369 = 0.16844$); sea with free normalization $A_S = 2.0$, $\delta_S = -0.01$, $\eta_S = 7.04$; two-term gluon with $\delta_g = 0.67$, $\eta_g = 5.25$ (no Chebyshevs) and second term $A_{g'} = -0.368$, $\delta_{g'} = -0.278$, $\eta_{g'} = 1.345$.
Quark momenta ($\delta$-index integrals): $\langle x \rangle_{u_V} = 12.79 \times [0.10569 - 1.45(0.013322) + 0.74(-0.077741)] = 0.36899$; $\langle x \rangle_{d_V} = 0.16844 \times I(0.13, 3.98) = 0.16844 \times 0.15104 = 0.02544$; $\langle x \rangle_{S} = 2.0 \times I(-0.01, 7.04) = 2.0 \times 0.127821 = 0.25564$. Sum: $\Sigma_q = 0.65007$.
Gluon pieces: $g_1 = I(0.67, 5.25) = 0.0389126$; $\;g_2 = -0.368 \times I(-0.278, 1.345) = -0.368 \times 0.712187 = -0.262085$.
Solve: $$ A_g = \frac{1 - 0.65007 - (-0.262085)}{0.0389126} = \frac{0.61202}{0.0389126} = 15.728 $$
Verify: gluon momentum $= A_g\, g_1 + g_2 = 0.61202 - 0.26209 = 0.34993$, and
$$ 0.36899 + 0.02544 + 0.25564 + 0.34993 = 1.000000 $$
exact to all digits carried — with a physically sensible 35% of momentum in glue. Note the sign choreography:
the fitted second gluon term is negative ($g_2 < 0$), so the solved first term must overshoot
($A_g g_1 = 0.612$) to compensate. This is precisely the arithmetic msum_ag performs at every one
of the sampler's $\sim 10^5$–$10^8$ likelihood calls — for the cost of a dozen Gamma evaluations.