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 standard unit-duration Brownian meander area."""
if n < 1:
raise ValueError('n must be positive')
k, q = [QQ(-1)/QQ(2)], [QQ(1)]
for j in range(1, n+1):
k.append(QQ(3*j-4)/QQ(4)*k[j-1]
+ sum((k[i]*k[j-i] for i in range(1,j)), QQ(0)))
q.append(QQ(3*j-2)/QQ(2)*q[j-1]
+ 2*sum((k[i]*q[j-i] for i in range(1,j+1)), QQ(0)))
m = n//2
if n%2:
r = RealBallField(513)
factor = QQ(factorial(n))*q[n]/QQ(2**m*factorial(3*m+1))
return r(factor)*(r.pi()/r(2)).sqrt()
return QQ(factorial(n)*4**(3*m)*factorial(3*m))*q[n]/QQ(2**m*factorial(6*m))
# For example, the mean:
print(moment(1))
The recurrences for $K_n$ and $Q_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 an interval within one unit of its last place.
All twelve orders were compared with an independent polynomial solution of the killed-Brownian-motion Feynman-Kac resolvent equation, using the framework of [1], Appendix C.3. The independent computation evaluates Gamma factors directly in Arb at 768 bits. The zeroth moment is a control, and the first four positive moments agree with Table 4 of [1]. The attached checks test the actual written intervals, the recurrence on stored values, and strict log-convexity including $M_0=1$. See checks.py, derivation.md and numerical-evidence.json for methods, controls and measurements.