Factorials modulo a prime from binary indices #
factorialResidue computes a factorial modulo the supplied modulus without constructing
that factorial. The binary index gives a polynomial-size enumeration width, and the existing
uniform prime-field product evaluator supplies an F_3 certificate. Algebraic correctness
and inversion hold at primes, with invertibility restricted to indices below the prime.
Taking a factorial ratio gives descending factorial residues at the same counting level.
Adapted from
lean-canny's factorial evaluator
and FallingFactorial at the same revision.
A binary-width product with one outside the factorial range.
The argument's binary size bounds the enumeration width; no factorial or exponentially long list is passed to the realizing machine.
The total evaluator is the true factorial residue at every prime.
Factorials below the prime are invertible, including zero factorial.
A descending factorial modulo the supplied modulus, returning zero above its index.
Both factorials and the modular inverse are computed at the same counting level.
Below the prime, the evaluator agrees with the descending factorial for every order.