prism/lib.rs
1//! `prism` — the Prism **standard library** (wiki ADR-031).
2//!
3//! Per [Wiki ADR-031][09-adr-031], the `prism` crate is the standard
4//! library: a **façade** re-exporting [`uor_foundation`]'s substrate
5//! together with the built-in axes and built-in types the Layer-3
6//! sub-crates of the standard library declare. The wiki's user-facing
7//! promise is _"depend on `uor-prism`, write a `prism_model!`, done"_
8//! — application authors do not need to add `uor-foundation`,
9//! `uor-foundation-sdk`, or the individual `uor-prism-<domain>` crates
10//! to their dependency list. Everything composes through
11//! `use prism::*;` (or finer-grained imports like
12//! `use prism::crypto::Sha256Hasher`).
13//!
14//! Per [ADR-024][09-adr-024], the standard library is **Layer 2** of
15//! the three-layer algebraic closure spine: substrate (`uor-foundation`)
16//! is Layer 1; verbs and axes declared by application crates are
17//! Layer 3.
18//!
19//! # Standard-library Layer-3 sub-crate roster
20//!
21//! Per ADR-031's roster commitment, the standard library publishes
22//! four canonical sub-crates from the Prism repository, each consumed
23//! through the façade re-exports below. Every axis impl is parametric
24//! in its natural axis (byte-width, Q-format split, hasher, dimension)
25//! so application authors instantiate the impl their model needs
26//! without re-rolling the kernel body; canonical type aliases (e.g.,
27//! `Sha256Hasher`, `BigInt256Numeric`) name the most common
28//! instantiations, while parametric impls (e.g.,
29//! `CpuI8MatmulSquare<DIM>`) are instantiated at the application's
30//! chosen dimension.
31//!
32//! - **[`crypto`]** — wiki: hashes, curves, signatures, commitments.
33//! `HashAxis` impls: `Sha256Hasher`, `Sha512Hasher`,
34//! `Sha3_256Hasher`, `Keccak256Hasher`, `Blake3Hasher`.
35//! `CommitmentAxis` impl: `MerkleRoot<H, LEAF_BYTES>` (parametric
36//! over `HashAxis`), default alias `MerkleRootCommitment` = SHA-256.
37//! Shapes: `Digest<N>`, `PublicKey<N>`, `Signature<N>`,
38//! `MerkleProofShape<MAX_DEPTH, LEAF_BYTES>`.
39//! - **[`numerics`]** — wiki: integer, fixed-point, prime-field,
40//! GF(2) arithmetic. Parametric: `BigIntModularNumeric<BYTES>`
41//! (8..=512 bits), `FixedPointQNumeric<I, F>` (any Q-format split
42//! ≤ 64 bits total), `Gf2NumericAxisN<BYTES>` (1..=128 bytes).
43//! Concrete: `PrimeFieldNumericSecp256k1`. Shapes: `BigIntShape<N>`,
44//! `FixedPointShape<I, F>`, `FieldElementShape<N>`,
45//! `Gf2RingShape<N>`.
46//! - **[`tensor`]** — wiki: tensor compute + activations. Parametric:
47//! `CpuI8MatmulSquare<DIM>` (1..=16 square `i8`→`i16` matmul),
48//! `CpuI8VectorActivation<N>` (1..=256-length `i8` vector ReLU /
49//! Q1.7 sigmoid). Shapes: `MatrixShape<R, C, ELEM_BYTES>`,
50//! `VectorShape<N, ELEM_BYTES>`.
51//! - **[`fhe`]** — wiki: homomorphic encryption. Parametric reference
52//! impl: `OneTimePadFhe<BLOCK_BYTES>` (1..=256). Shape:
53//! `CiphertextShape<N>`.
54//!
55//! # SDK macros (re-exported)
56//!
57//! Per ADR-031's façade commitment, the SDK macros declared by
58//! `uor-foundation-sdk` are re-exported through [`pipeline`] so a
59//! single `use prism::pipeline::prism_model;` reaches the canonical
60//! application-author surface:
61//!
62//! - `prism_model!` (ADR-020 / ADR-022) — declare a typed route
63//! - `verb!` (ADR-024) — declare a Layer-3 verb (named composition)
64//! - `axis!` (ADR-030) — declare a Layer-3 axis (substrate-extension
65//! vocabulary)
66//! - `resolver!` (ADR-036) — declare a `ResolverTuple` value
67//! - `output_shape!` (ADR-027) — declare a custom Output shape
68//! - `use_verbs!` (ADR-024) — import verbs from another implementation
69//! - `product_shape!`, `coproduct_shape!`, `cartesian_product_shape!`,
70//! `partition_product!`, `partition_coproduct!` (ADR-026 / ADR-033)
71//! — shape constructors
72//!
73//! # See also
74//!
75//! - [Wiki: 01 Introduction and Goals](https://github.com/UOR-Foundation/UOR-Framework/wiki/01-Introduction-and-Goals)
76//! - [Wiki: 04 Solution Strategy](https://github.com/UOR-Foundation/UOR-Framework/wiki/04-Solution-Strategy)
77//! - [Wiki: 05 Building Block View § Whitebox `prism`](https://github.com/UOR-Foundation/UOR-Framework/wiki/05-Building-Block-View#whitebox-prism)
78//! - [Wiki: 06 Runtime View § Scenario 1: Principal Data Path Execution](https://github.com/UOR-Foundation/UOR-Framework/wiki/06-Runtime-View#scenario-1-principal-data-path-execution)
79//! - [Wiki: 09 Architecture Decisions § ADR-024 — Three-layer algebraic closure][09-adr-024]
80//! - [Wiki: 09 Architecture Decisions § ADR-030 — `axis!` SDK macro][09-adr-030]
81//! - [Wiki: 09 Architecture Decisions § ADR-031 — `prism` is the standard library][09-adr-031]
82//! - [Wiki: 10 Quality Requirements § Quality Scenarios](https://github.com/UOR-Foundation/UOR-Framework/wiki/10-Quality-Requirements#quality-scenarios)
83//! - [Wiki: 12 Glossary](https://github.com/UOR-Foundation/UOR-Framework/wiki/12-Glossary)
84//! - [Wiki: Conceptual Model § SD](https://github.com/UOR-Foundation/UOR-Framework/wiki/Conceptual-Model#sd) — OPM (ISO 19450) overall system diagram naming the three actors and Prism as the system-of-interest
85//! - [Wiki: Conceptual Model § SD1 Prism Structure](https://github.com/UOR-Foundation/UOR-Framework/wiki/Conceptual-Model#sd1-prism-structure) — OPM decomposition of Prism into Substrate, Runtime, and Replay Surface
86//!
87//! # Constraints
88//!
89//! This crate is normatively bound by:
90//!
91//! - **TC-01** — zero-cost runtime; no Prism interpreter layer at execution
92//! - **TC-02** — sealing of `Validated`, `Grounded`, `Certified` via the Rust
93//! type system, enforced through `pub(crate)` constructors in the substrate
94//! - **TC-03** — singular principal data path; exactly one constructor for
95//! `Grounded<T>`, reached only through [`pipeline::run`]
96//! - **TC-04** — bilateral compile-time UORassembly enforcement
97//! - **TC-05** — replayability without invoking author deciders or hash
98//! functions; surfaced through [`replay::certify_from_trace`]
99//! - **TC-06** — no application-author infrastructure at runtime
100//! - **ADR-006** — UORassembly is enforced bilaterally at compile time
101//! through the Rust type system; this is the architectural commitment
102//! that makes TC-04 enforceable rather than aspirational
103//!
104//! Substitution axes per ADR-007/030/036: `HostTypes`, `HostBounds`,
105//! `AxisTuple`, `ResolverTuple`, `TypedCommitment`.
106//!
107//! Additionally:
108//!
109//! - **ADR-019** — `uor-foundation`'s vocabulary is the signature
110//! category, `Term` is its initial algebra, [`pipeline::run`] is the
111//! catamorphism.
112//! - **ADR-020** — application authors declare a Prism application by
113//! implementing the sealed [`pipeline::PrismModel`] trait; the
114//! `prism_model!` macro derives `forward`'s body via initiality.
115//! - **ADR-024** — three-layer algebraic closure (substrate, prism,
116//! implementation).
117//! - **ADR-030** — the `axis!` SDK macro is the universal
118//! substrate-extension declaration mechanism.
119//! - **ADR-031** — `prism` IS the standard library: a façade over
120//! `uor-foundation` plus Layer-3 sub-crates published from the
121//! Prism repository.
122//! - **ADR-040** — closed `BoundShape` catalog (7 individuals) with
123//! `type:LexicographicLessEqBound` for byte-sequence-valued
124//! observables; 1:1 correspondence with the foundation-published
125//! `ObservablePredicate` impl surface per ADR-049.
126//! - **ADR-048** — typed-commitment substrate: the `TypedCommitment`
127//! trait with three built-in impls (`EmptyCommitment`,
128//! `SingletonCommitment<P>`, `AndCommitment<A, B>`) and the canonical
129//! `TargetCommitment = SingletonCommitment<LexicographicLessEqThreshold>`
130//! alias. The 5th model-declaration parameter `C` on `PrismModel`.
131//! - **ADR-049** — five foundation-published typed UOR observable
132//! primitives (`Stratum<P>`, `WalshHadamardParity`,
133//! `UltrametricCloseTo<P>`, `AffineParity`,
134//! `LexicographicLessEqThreshold`) realizing the four taxonomy
135//! subclasses of ADR-038's closed observable catalog. Each is
136//! `Copy + Sealed` and consumable as a `SingletonCommitment<P>`
137//! operand per ADR-048.
138//! - **ADR-057** — bounded recursive structural typing via
139//! `ConstraintRef::Recurse { shape_iri, descent_bound }` plus the
140//! foundation shape-IRI registry (`RegisteredShape`,
141//! `ShapeRegistryProvider`, `EmptyShapeRegistry`, `lookup_shape`,
142//! `lookup_shape_in`). Apps emit a registry via the `register_shape!`
143//! SDK macro; `partition_product!` / `partition_coproduct!` operand
144//! grammar admits `recurse[(<bound>)]:T` to declare recursive
145//! references without const-eval cycles. The registry-aware
146//! nerve / Betti substrate primitives shipped in foundation 0.4.15 —
147//! `primitive_simplicial_nerve_betti_in::<T, R>`,
148//! `primitive_cartesian_nerve_betti_in::<S, R>`, and
149//! `expand_constraints_in::<R>` — walk Recurse entries through `R`'s
150//! registry plus foundation's built-in registry, giving the
151//! structurally-correct nerve / Betti reading of recursively-expanded
152//! constraint sets. Wire-format trace events gain a `Recurse`
153//! discriminant; `TRACE_REPLAY_FORMAT_VERSION` bumps to 10.
154//! - **ADR-058** — κ-derivation (the eight-resolver ψ-pipeline composed
155//! with the ψ_9 σ-projection) **is** the framework's
156//! compression-to-canonical-form operator; the κ-label is the
157//! minimum-information canonical-form representation, with a three-tier
158//! closure-lossless taxonomy (T1 byte-identical ⇒ T2 κ-label-identical
159//! ⇒ T3 outcome-coarse-equivalent). A conceptual-reading commitment over
160//! existing constructs — no new substrate surface.
161//! - **ADR-059** — the operator-geometry codomain of κ-derivation is the
162//! Atlas image inside E₈, coarsely stratified by the Hopf convergence
163//! tower (the foundation's [`kernel::convergence`] namespace, surfaced
164//! through [`convergence`]): four `ConvergenceLevel` instances R / C /
165//! H / O at division-algebra dimensions {1, 2, 4, 8}. A
166//! conceptual-reading commitment over the foundation's existing
167//! `kernel::convergence` substrate vocabulary — no new substrate
168//! surface.
169//!
170//! [`kernel::convergence`]: uor_foundation::kernel::convergence
171//!
172//! # C4 placement
173//!
174//! Container `prism` (Level 2) of the Prism system. The submodules
175//! mirror the Level 2 components named in the wiki's
176//! [Building Block View § Whitebox `prism`][05-prism], with the
177//! ADR-031-introduced standard-library Layer-3 sub-crate re-exports
178//! sitting beside the foundation runtime surface:
179//!
180//! - [`pipeline`] — the principal data path + SDK macro re-exports
181//! - [`seal`] — the sealed Prism-mechanism types
182//! - [`replay`] — trace-replay verification surface
183//! - [`operation`] — operation declaration vocabulary
184//! - [`std_types`] — standard type library (baseline primitives)
185//! - [`vocabulary`] — foundation surface re-exports
186//! - [`convergence`] — the Hopf convergence tower: κ-derivation's
187//! operator-geometry codomain (ADR-058 / ADR-059)
188//! - [`crypto`] — standard-library cryptography axes (ADR-031)
189//! - [`numerics`] — standard-library numerics axes (ADR-031)
190//! - [`tensor`] — standard-library tensor-compute axes (ADR-031)
191//! - [`fhe`] — standard-library homomorphic-encryption axes (ADR-031)
192//!
193//! # Behavior
194//!
195//! ```rust
196//! // Given: the substrate dependency `uor-foundation` is in scope
197//! // When: the prism standard-library façade is loaded
198//! // Then: every wiki Level 2 module of `prism` AND every ADR-031
199//! // standard-library sub-crate is reachable through `use prism::*;`
200//! use prism::{convergence as _, operation as _, pipeline as _, replay as _};
201//! use prism::{seal as _, std_types as _, vocabulary as _};
202//! use prism::{crypto as _, fhe as _, numerics as _, tensor as _};
203//! use uor_foundation as _;
204//! assert_eq!(prism::WIKI, "https://github.com/UOR-Foundation/UOR-Framework/wiki");
205//! ```
206//!
207//! [wiki]: https://github.com/UOR-Foundation/UOR-Framework/wiki
208//! [05-prism]: https://github.com/UOR-Foundation/UOR-Framework/wiki/05-Building-Block-View#whitebox-prism
209//! [09-adr-024]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
210//! [09-adr-030]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
211//! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
212
213#![no_std]
214#![cfg_attr(docsrs, feature(doc_cfg))]
215
216pub use uor_foundation;
217
218pub mod convergence;
219pub mod operation;
220pub mod pipeline;
221pub mod replay;
222pub mod seal;
223pub mod std_types;
224pub mod vocabulary;
225
226// Wiki ADR-031: the Prism standard library's Layer-3 sub-crates.
227// Re-exported as `prism::<domain>` so application authors reach them
228// through the single `prism` dependency.
229pub mod crypto {
230 //! Cryptography axes per [Wiki ADR-031][09-adr-031]
231 //! (re-export of `uor-prism-crypto`).
232 //!
233 //! Application authors compose `HashAxis`, `CurveAxis`,
234 //! `SignatureAxis`, and `CommitmentAxis` through their model's
235 //! `AxisTuple` per ADR-030. Five canonical `HashAxis` impls are
236 //! provided as the standard-library reference: SHA-256, SHA-512,
237 //! SHA3-256, Keccak-256, and BLAKE3.
238 //!
239 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
240 pub use prism_crypto::*;
241}
242
243pub mod numerics {
244 //! Numerics axes per [Wiki ADR-031][09-adr-031]
245 //! (re-export of `uor-prism-numerics`).
246 //!
247 //! Provides `BigIntAxis`, `FixedPointAxis`, `FieldAxis`, and
248 //! `RingAxis`. Reference impls cover 256-bit modular arithmetic,
249 //! Q32.32 fixed-point, secp256k1 prime-field arithmetic, and
250 //! GF(2) over 256-bit operands.
251 //!
252 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
253 pub use prism_numerics::*;
254}
255
256pub mod tensor {
257 //! Tensor-compute axes per [Wiki ADR-031][09-adr-031]
258 //! (re-export of `uor-prism-tensor`).
259 //!
260 //! Provides `TensorAxis` and `ActivationAxis` with fixed-shape
261 //! CPU integer-precision reference impls. Variable-rank tensor
262 //! compute composes through verbs over
263 //! `partition_product!`-declared shapes (ADR-033/044).
264 //!
265 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
266 pub use prism_tensor::*;
267}
268
269pub mod fhe {
270 //! Homomorphic-encryption axes per [Wiki ADR-031][09-adr-031]
271 //! (re-export of `uor-prism-fhe`).
272 //!
273 //! Provides `FheAxis` with a reference one-time-pad impl. Production
274 //! FHE schemes (TFHE, BGV, CKKS) are operational policy per ADR-031.
275 //!
276 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
277 pub use prism_fhe::*;
278}
279
280/// Canonical URL of the UOR-Framework wiki, the normative source for the
281/// Prism architecture realized by this crate.
282///
283/// Every public item in `prism` carries a backlink to a wiki section that
284/// roots at this URL. Consumers may reference this constant when surfacing
285/// the same origin programmatically — for example, in error messages that
286/// direct users to the architectural section that defines a violated
287/// invariant.
288///
289/// # See also
290///
291/// - [Wiki: Home](https://github.com/UOR-Foundation/UOR-Framework/wiki)
292///
293/// # Constraints
294///
295/// - **CV-02** — code identifiers appear in monospace without paraphrase;
296/// this constant is the single source of truth for the wiki origin
297///
298/// # Behavior
299///
300/// ```rust
301/// // Given: prism is loaded
302/// // When: the wiki URL constant is read
303/// // Then: it points at the UOR-Framework wiki landing page
304/// assert!(prism::WIKI.starts_with("https://"));
305/// assert!(prism::WIKI.ends_with("/UOR-Framework/wiki"));
306/// ```
307pub const WIKI: &str = "https://github.com/UOR-Foundation/UOR-Framework/wiki";
308
309/// Minimum supported Rust version of this crate.
310///
311/// Pinned to track `uor-foundation`'s effective MSRV so the dependency
312/// graph never imposes a tighter requirement on consumers than the
313/// substrate itself. Bumping this constant requires bumping the workspace
314/// `rust-version` and the `rust-toolchain.toml` channel in lockstep.
315///
316/// # See also
317///
318/// - [Wiki: 02 Architecture Constraints](https://github.com/UOR-Foundation/UOR-Framework/wiki/02-Architecture-Constraints)
319///
320/// # Constraints
321///
322/// - **TC-04** — bilateral compile-time enforcement assumes a single,
323/// declared toolchain version on both sides of the contract
324///
325/// # Behavior
326///
327/// ```rust
328/// // Given: the MSRV constant
329/// // When: parsed into its semver components
330/// // Then: it is at least 1.83 and uses the major.minor form
331/// let parts: Vec<&str> = prism::MSRV.split('.').collect();
332/// assert_eq!(parts.len(), 2);
333/// let major: u32 = parts[0].parse().expect("major version is numeric");
334/// let minor: u32 = parts[1].parse().expect("minor version is numeric");
335/// assert!((major, minor) >= (1, 83));
336/// ```
337pub const MSRV: &str = "1.83";