factorial_mod

std.elementwise.factorial_mod · Level L4

n! mod m, elementwise, multiplying 1 … n and reducing modulo m at every step, so nothing grows past m·n. Wilson's theorem says (p − 1)! ≡ −1 (mod p) exactly when p is prime.

n! mod m

Signature

factorial_mod(n: i64[s], m: i64[s]) → i64[s]

Structure

The function as NOVA stores it: one box per input, operation and output, and arrows that carry values. A double border marks another library function this one runs — called once, or by Scan once per element; select it to open that function.

0ni64[s]mi64[s]1MultiplynilAddk0Modacc0While·factorial_mod_stepk_end, acc_endIdentityrri64[s]
  • input
  • operation
  • constant
  • call
  • output

Verification

  • Signature proven by NOVA’s shape solver, for every size.
  • Equal to the reference math.factorial(n) % m in exact rational arithmetic, on all 40 test cases.
  • All 160 int64 results are exact: the error is zero.
  • Interpreter and NumPy backend return bit-identical results.
  • At float32 too: the 40 test cases rounded to float32, and 40 of them exact, with zero error.
Accuracy in detail
correctly rounded (the int64 nearest the exact value)
100%
bit-equal to the NumPy formula in int64
100%
largest error, in units in the last place
0

Identity

sha256:27b2ccfaeee314a8f82eea19a0b53b12c66ab8be5f17a5f729475f6cdca93ad1

The semantic hash of the graph. It changes when the program changes, and never when only its documentation does.

Control handle

Symbol
Ω:std.elementwise.factorial_mod · Ω:factorial_mod
Pins
sha256:e9aa5a5a5ab98f6881c0e5fc60b3aeb0e4ded61fdc7a7d45d004a901f2012db5this graph and the 2 it reaches through calls
Evidence
sha256:48cc2a9b134da6fd1b4d93539c6b5d6ab29fd2cf64251b9f0659bc5b1a4a07dathe hash of its verification record
Needs
no capability: a pure function

Through NOVA’s control layer, the symbol launches this function only while the program still matches what it pins: a change to this graph, or to any graph it reaches, needs a migration first.

ΣEML 2026

Efficient New Language — a high-density semantic overlay for humans and AI agents.

This site’s demos run on the real EML toolchain, in your browser.

© 2026 EveMissLab (一言諾科技有限公司) / Neo.K. All rights reserved.