import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
def trace_moment(N, K, q):
if not (2 <= N <= K and q >= 2):
raise ValueError("Require 2 <= N <= K and q >= 2")
previous, current = QQ(N), QQ(1)
for j in range(2, q+1):
a = QQ((2*j-1)*(N+K)) / QQ((N*K+j-1)*(j+1))
b = QQ((j-2)*((j-1)**2-(K-N)**2)) / QQ((N*K+j-1)*(N*K+j-2)*(j+1))
previous, current = current, a*current+b*previous
return current
trace_moment(2, 2, 2) # 4/5
Every entry was computed over the rational field with the three-term recurrence and compared with a separate exhaustive Wick-permutation sum. All 217 qubit entries were also checked by exact beta integration of the eigenvalue density. Purity, third and fourth moments, dimension interchange, the recurrence and strict density-matrix bounds were checked across their full stored ranges.
The attached checks.py repeats these tests on generated or stored entries. The finite sum in Nechita equation (36), which fails the qubit purity control, was not used.