program-example-modular.py

back to table · edit · history · where entries came from · files · download

636 bytes, as of the version from 2026-11-19 02:09 (current). Recorded here, not run.

import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
p = ZZ(37)
m = p**3
term = total = ZZ(1)
for n in range(int(p)-1):
    for j in (1, 2, 3, 4):  # upper parameters j/5, template 5
        term = (term*(j+5*n)*ZZ(5).inverse_mod(m)) % m
    term = (term*ZZ(n+1).inverse_mod(m)**4) % m
    total = (total+term) % m
a = total if 2*total <= m else total-m
assert a*a <= 4*p**3
R = PolynomialRing(ZZ, 'T')
R([1, -a, p**3])

assert R([1, -a, p**3]) == R([1, 314, 50653])
print('Fresh-process modular Programs example passed:',R([1, -a, p**3]))