import numberdb.sage
from math import factorial
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
def moment(n):
"""Raw moment of the unit-duration standard bridge positive-part area."""
if n < 1:
raise ValueError('n must be a positive integer')
k = [QQ(-1)/QQ(2)]
p = [QQ(1)]
for j in range(1, n+1):
k.append(QQ(3*j-4)/QQ(4)*k[j-1]
+ sum((k[a]*k[j-a] for a in range(1,j)), QQ(0)))
p.append(sum((k[a]*p[j-a] for a in range(1,j+1)), QQ(0)))
m = n//2
if n%2:
q = QQ(factorial(n))*p[n]/QQ(2**m*factorial(3*m+1))
r = RealBallField(513)
return r(q)*(r.pi()/r(2)).sqrt()
return QQ(factorial(n)*4**(3*m)*factorial(3*m))*p[n]/QQ(2**m*factorial(6*m))
# For example, moment(1) gives the mean.
The recurrences for $K_n$ and $P_n$ and all rational prefactors were evaluated exactly over $\mathbb Q$. Even moments are stored as exact rational numbers. Odd moments use an Arb enclosure of $\sqrt{\pi/2}$ at 513 bits, with a measured minimum relative accuracy of 509 bits, and are written to 100 significant digits. Each decimal denotes the interval within one unit of its last place.
All twelve orders were compared with an independent polynomial solution of the Brownian Feynman–Kac resolvent equation and with an exact quotient of Airy asymptotic series, using [1], Appendix C.2 and equations (104), (106), (242). Direct Arb Gamma evaluation at 768 bits checks the half-integer simplification and containment within each written decimal interval. The zeroth moment and the first resolvent polynomial serve as controls. The mean also follows by integrating the positive-part Gaussian marginal mean, and the first four moments agree with Table 6 of [1]. The attached checks test strict moment log-convexity with $M_0=1$, the recurrence on database readback, and the one-value program. See checks.py, derivation.md and numerical-evidence.json for methods, controls and measurements.