adele_ring/lib.rs
1//! # adele-ring — exact multi-base arithmetic engine
2//!
3//! `adele-ring` carries every number at **two kinds of place at once**. The
4//! *finite places* (an adaptive residue-number system over a prime [`Basis`])
5//! do all the real arithmetic: carry-free, local, embarrassingly parallel across
6//! CPU lanes and GPU threads, and free of big-integer work. The *infinite place*
7//! (a rigorous real interval, [`Ball`]) answers every question the prime channels
8//! constitutionally cannot — sign, comparison, magnitude, and decimal output — by
9//! refining on demand. Exactness is recovered by reconstructing from the finite
10//! places, with the basis grown to exactly the height the computation provably
11//! needs ([`bounds`]), so a result can never silently exceed its range. Big
12//! integers appear only at that reconstruction boundary, for an instant, on
13//! numbers as large as the answer's own information content — the product formula
14//! reminding us that what we save among the primes we pay, once, at infinity.
15//!
16//! This pairing is the [`Adelic`] carrier, the data-structure form of
17//! `𝔸_ℚ = ℝ × ∏′_p ℚ_p`. On top of the RNS substrate sits a *number tower* that
18//! keeps every value at the cheapest exact level it can.
19//!
20//! On top of the RNS substrate sits a *number tower* that keeps every value at
21//! the cheapest exact level it can:
22//!
23//! | Level | Set | Type |
24//! |-------|----------|------------------------------|
25//! | 0 | ℤ | [`rns::RnsInt`] |
26//! | 1 | ℚ | [`rational::RnsRational`] |
27//! | 2 | ℚ̄ | [`algebraic::AlgebraicNumber`] |
28//! | 3 | ℝ_c | [`computable::ComputableReal`] |
29//! | 4 | 𝒮 | [`symbolic::SymbolicExpr`] |
30//!
31//! The crate name uses a hyphen (`adele-ring`) but the Rust path uses an
32//! underscore (`adele_ring`), per Rust's identifier rules.
33
34/// Channel-count threshold above which single-value operations parallelize over
35/// channels with rayon. Below it, sequential is faster (task overhead ~50ns vs
36/// channel op ~1ns: break-even around 8–16 channels).
37pub const RAYON_CHANNEL_THRESHOLD: usize = 16;
38
39// ── Foundation: the adelic carrier (finite places × the real place) ──────────
40pub mod adelic;
41pub mod ball;
42pub mod basis;
43pub mod bounds;
44pub mod error;
45pub mod reconstruct;
46
47// ── Parallelism foundation ───────────────────────────────────────────────────
48pub mod backend;
49pub mod batch;
50pub mod cpu;
51pub mod gpu;
52pub mod primes;
53pub mod rns;
54
55// ── The number tower ─────────────────────────────────────────────────────────
56pub mod algebraic;
57pub mod computable;
58pub mod dispatch;
59pub mod rational;
60pub mod symbolic;
61pub mod tower;
62
63pub use adelic::{Adelic, AdelicInt, AdelicRat, Finite, RnsFrac};
64pub use algebraic::{AlgebraicNumber, Polynomial};
65pub use backend::{executor, ArithmeticBackend, Executor};
66pub use ball::Ball;
67pub use basis::Basis;
68pub use batch::RnsBatch;
69pub use bounds::{determinant_bits, mignotte_bits, resultant_bits};
70pub use computable::{Computable, ComputableReal};
71pub use dispatch::{DispatchPlan, Dispatcher};
72pub use error::{BasisError, ChannelMismatch, GpuError, RangeError};
73pub use rational::RnsRational;
74pub use reconstruct::rational_reconstruct;
75pub use rns::{crt_balanced, garner_crt, RnsInt};
76pub use symbolic::{IdentityGraph, SymbolicExpr};
77pub use tower::{TowerLevel, TowerValue};