math-nt-modular
The groupant beside math/src/nt.rs in the Mova repository: what the code computes, what it never does, how to go back from its outputs, its invariants, cost and checks.
Facts
Implementation material. A Mova code model describes this code at one source revision: partial models, finite checks and their stated scope. It is not a reviewed general exposition, and its labels are shown as written, never raised.
Components
| component | label | where |
|---|---|---|
| approximant | partial | approximant |
| ast | partial | ../syntax.json |
| descriptant | present | descriptant |
| invariant | partial | invariant |
| tests | executed bounded checks | tests |
Obernants
The typed relations around the forward model: the behaviour complement (what the code never does), the reverse reconstruction (every input compatible with an output) and specialised views.
| id | type | label | where |
|---|---|---|---|
behavior_complement | behavior_complement | partial source derived model | behavior_complement |
reverse_reconstruction | reverse_reconstruction | partial source derived model | reverse_reconstruction |
bezout_certificate | bezout_certificate | partial source derived model | bezout_certificate |
inverse_domain | inverse_domain | partial source derived model | inverse_domain |
crt_merge | crt_merge | partial source derived model | crt_merge |
checker_shape | checker_shape | partial source derived model | checker_shape |
Model text
descriptant
math-nt-modular
Euclid certificates and normalized modular operations compose through CRT gcd compatibility. Empty/mismatched CRT rejects but check_crt zip-truncates. Antecedents are congruence fibers; bare modulus helpers can panic on zero. Costs depend on bit widths and pairs.
Epoch 2026-10-31: complete source read, parent AST reused; partial finite evidence only.
approximant
Scoped forward and cost
Euclid certificates and normalized modular operations compose through CRT gcd compatibility. Empty/mismatched CRT rejects but check_crt zip-truncates. Antecedents are congruence fibers; bare modulus helpers can panic on zero. Costs depend on bit widths and pairs.
No executable percent surrogate claimed.
Epoch36 boundary: public gcd(0,0)=0 via explicit guard; all other signed operands use the existing dashu gcd. This agrees with ext_gcd/check_gcd. The original wrapper's zero-zero panic was observed before repair; bare modular helpers still retain their separate nonzero-modulus preconditions.
invariant
Scoped invariant
Euclid certificates and normalized modular operations compose through CRT gcd compatibility. Empty/mismatched CRT rejects but check_crt zip-truncates. Antecedents are congruence fibers; bare modulus helpers can panic on zero. Costs depend on bit widths and pairs.
Source range[1492,5396) bound by manifest digest. Parent domain applies, not arbitrary public states.
models
Source-scoped typed relations
behavior_complement
modpow modulus0 excludes Some; modulus1 returnsSome0 even for negative exponent. CRT empty/mismatched vectors or zero modulus excludes a successful pair.
reverse_reconstruction
CRT(x,M) admits all residue/modulus lists with lcm|mi|=M and ri congruent x modulo|mi|. Reordering, redundant congruences and modulus signs are lost; x alone also loses M.
bezout_certificate
ext_gcd returns g>=0 and sa+tb=g. check_gcd also tests divisibility and matching independently computed g; at g=0 both inputs must0.
inverse_domain
modinv requires m!=0 and gcd(a,|m|)=1; modpow negative e delegates inverse except m=1 shortcut. mod_floor alone does not guard m=0.
crt_merge
For accumulated(x,m), g=gcd(m,mi); reject if g does not divide r-x. Solve t modulo mi/g, then x'=x+mt normalized modulo m(mi/g).
checker_shape
check_crt uses zip and does not test counts; empty zip accepts and zero reached modulus panics. Its true result is not proof that producer crt admitted the arrays.
tests
Evidence
See ../tests.md for actual checks and source mutant; this fragment adds no runtime test.
Euclid certificates and normalized modular operations compose through CRT gcd compatibility. Empty/mismatched CRT rejects but check_crt zip-truncates. Antecedents are congruence fibers; bare modulus helpers can panic on zero. Costs depend on bit widths and pairs.
Epoch36 parent evidence: zero_pair_agrees_with_independent_certificate exposed the original public gcd zero-zero panic, then passed with the guard. signed_grid_and_large_operands_preserve_euclid checks1088 signed grid pairs and selected big operands. Both pass debug/release jobs2; parent tests.md records source bindings and external logs. Modular-zero and CRT shape preconditions remain distinct.
This page in Markdown โ https://md.groupants.elamur.ai/free/en/mova/math/src/nt.rs.groupant/modular.groupant/