crt
std.elementwise.crt · Level L4The Chinese remainder theorem: the x in 0 … M − 1, M = m₁·…·mₙ, with x ≡ rᵢ (mod mᵢ) for every i, for pairwise coprime moduli. A Scan of crt_step over the congruences. The solution is unique modulo M, not as an integer.
Signature
crt(r: i64[n], m: i64[n]) → i64[], i64[]
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.
- input
- operation
- constant
- call
- output
Verification
- Signature proven by NOVA’s shape solver, for every size.
- Equal to the reference
x = 0, M = 1; for each (r, m): x += M*((r - x)*pow(M, -1, m) % m); M *= min exact rational arithmetic, on all 40 test cases. - All 80 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.
- correctly rounded (the int64 nearest the exact value)
- 100%
- largest error, in units in the last place
- 0
Note
The moduli must be pairwise coprime; NOVA does not check it, and for moduli that are not, the result need not satisfy the congruences. Exact while M stays below 2⁵³ and every modulus is at most 9·10⁷, so that (mᵢ − 1)², the product of two residues reduced modulo mᵢ that each step forms, stays below 2⁵³. M below 2⁵³ alone is not enough: with r = (1, 10¹⁴) and m = (3, 10¹⁵ + 37) that product overflows int64 and x breaks the second congruence (found in Round 16.3; until then this note gave only the condition on M). The verification multiplies up to eight distinct primes below 100.
Identity
sha256:d1a4c6b0a457c6f3fc2d7c5040b4981e12b1ff3a4bae06993045ec4dfa9a6272The semantic hash of the graph. It changes when the program changes, and never when only its documentation does.
Control handle
- Symbol
- Ω:std.elementwise.crt · Ω:crt
- Pins
sha256:ab94f6476ca315e77ff3665477b9354333ce85eddeef62d63dae48ab448d6cb5this graph and the 4 it reaches through calls- Evidence
sha256:f6b740413539c234fc0897c8788d7c6b6028359f6fe92f0580c402c8fe9683e7the 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.