Expand description
Level 0 — ℤ. RNS integers over the adaptive Basis, and Garner CRT.
§Balanced residues (no sign-magnitude)
Residues are stored canonically in [0, p) for each prime p, but the value
they encode is the balanced (symmetric) integer in (-M/2, M/2], where
M = ∏ p. Reconstruction folds u ∈ [0, M) to u - M when 2u > M.
There is no negative flag: subtraction is the channel-parallel
(a + p - b) % p, with no magnitude comparison and no BigInt in the loop.
The sign of a value is an Archimedean question — it is answered by the
crate::ball::Ball in the crate::adelic::Adelic carrier, never by the
residues (which are constitutionally blind to size).
All primes are GPU-eligible ((2^15, 2^16)), so every channel op — add, sub,
and even (a*b) — fits in a u32 with no u128 intermediate.
Structs§
- RnsInt
- An exact integer in balanced RNS form (Level 0 of the tower).
Functions§
- add_
channel - One channel’s add:
(a + b) % m. Fitsu32(a, b < 2^16). - crt_
balanced - Garner CRT followed by balanced (symmetric) folding into
(-M/2, M/2]. - garner_
crt - Garner’s algorithm: reconstruct the unsigned integer in
[0, M)from its balanced-canonical residues. All intermediates stay withinu64. - mul_
channel - One channel’s multiply:
(a * b) % m. Fitsu32(a, b < 2^16). - sub_
channel - One channel’s subtract:
(a + m - b) % m. No magnitude comparison.