uor-foundation 0.2.0

UOR Foundation — typed Rust traits for the complete ontology. Import and implement.
Documentation
// @generated by uor-crate from uor-ontology — do not edit manually

//! `trace/` namespace — Execution traces recording the sequence of kernel operations, intermediate results, and accumulated metrics for a computation..
//!
//! Space: Bridge

use crate::Primitives;

/// A complete record of a kernel computation: the input, output, every operation step, and accumulated metrics.
pub trait ComputationTrace<P: Primitives> {
    /// Associated type for `Datum`.
    type Datum: crate::kernel::schema::Datum<P>;
    /// The input datum of this computation.
    fn input(&self) -> &Self::Datum;
    /// The output datum of this computation.
    fn output(&self) -> &Self::Datum;
    /// Associated type for `ComputationStep`.
    type ComputationStep: ComputationStep<P>;
    /// A computation step in this trace.
    fn step(&self) -> &[Self::ComputationStep];
    /// Associated type for `DihedralElement`.
    type DihedralElement: crate::bridge::observable::DihedralElement<P>;
    /// The monodromy accumulated by this computation: the net dihedral group element produced by the full operation sequence.
    fn monodromy(&self) -> &Self::DihedralElement;
    /// Associated type for `Certificate`.
    type Certificate: crate::bridge::cert::Certificate<P>;
    /// The certificate that attests to the correctness of this computation trace.
    fn certified_by(&self) -> &Self::Certificate;
    /// Associated type for `ResidualEntropy`.
    type ResidualEntropy: crate::bridge::observable::ResidualEntropy<P>;
    /// The residual entropy observable remaining after this computation trace, linking to the ThermoObservable taxonomy (TH_9 connection).
    fn residual_entropy(&self) -> &Self::ResidualEntropy;
    /// Whether this computation trace satisfies the dual geodesic condition (GD_1): AR_1-ordered and DC_10-selected.
    fn is_geodesic(&self) -> P::Boolean;
    /// Associated type for `GeodesicViolation`.
    type GeodesicViolation: GeodesicViolation<P>;
    /// A GeodesicViolation record indicating where the trace deviated from the geodesic condition.
    fn geodesic_violation(&self) -> &[Self::GeodesicViolation];
    /// The total entropy cost accumulated across all steps of a trace. On a geodesic, equals freeRank_initial × ln 2 (GD_3).
    fn cumulative_entropy_cost(&self) -> P::Decimal;
    /// Whether the step sequence of this trace follows the AR_1 adiabatic ordering (decreasing freeRank × cost-per-site).
    fn adiabatically_ordered(&self) -> P::Boolean;
    /// Associated type for `MeasurementEvent`.
    type MeasurementEvent: MeasurementEvent<P>;
    /// A MeasurementEvent step within this computation trace.
    fn measurement_event(&self) -> &[Self::MeasurementEvent];
    /// Whether this computation trace has steps ordered by the AR_1 adiabatic metric (decreasing freeRank × cost-per-site). One of the two sub-predicates of isGeodesic (GD_6).
    fn is_ar1_ordered(&self) -> P::Boolean;
    /// Whether each step of this computation trace was selected by the DC_10 Jacobian criterion (maximal J_k among free sites). One of the two sub-predicates of isGeodesic (GD_6).
    fn is_dc10_selected(&self) -> P::Boolean;
}

/// A single step in a computation trace: one operation applied to produce one output from one or more inputs.
pub trait ComputationStep<P: Primitives> {
    /// Associated type for `Datum`.
    type Datum: crate::kernel::schema::Datum<P>;
    /// The input datum of this computation step.
    fn from(&self) -> &Self::Datum;
    /// The output datum of this computation step.
    fn to(&self) -> &Self::Datum;
    /// Associated type for `Operation`.
    type Operation: crate::kernel::op::Operation<P>;
    /// The operation applied in this computation step.
    fn operation(&self) -> &Self::Operation;
    /// The zero-based sequential index of this step within its trace.
    fn index(&self) -> P::NonNegativeInteger;
    /// The entropy cost of a single computation step. On a geodesic, this equals ln 2 for every step (GD_2).
    fn step_entropy_cost(&self) -> P::Decimal;
    /// The Jacobian value J_k at this step, used by the GeodesicValidator to check DC_10 maximality.
    fn jacobian_at_step(&self) -> P::Decimal;
}

/// Summary metrics for a computation trace: total steps, accumulated ring distance, and accumulated Hamming distance.
pub trait TraceMetrics<P: Primitives> {
    /// Total number of computation steps in this trace.
    fn step_count(&self) -> P::NonNegativeInteger;
    /// Total ring-metric distance accumulated across all steps.
    fn total_ring_distance(&self) -> P::NonNegativeInteger;
    /// Total Hamming-metric distance accumulated across all steps.
    fn total_hamming_distance(&self) -> P::NonNegativeInteger;
}

/// A computation trace that satisfies the dual geodesic condition (GD_1): AR_1-ordered and DC_10-selected. The path of least dissipation through the resolution landscape.
pub trait GeodesicTrace<P: Primitives>: ComputationTrace<P> {
    /// Associated type for `GeodesicCertificate`.
    type GeodesicCertificate: crate::bridge::cert::GeodesicCertificate<P>;
    /// The GeodesicCertificate attesting that this trace satisfied both GD_1 conditions.
    fn geodesic_certificate(&self) -> &Self::GeodesicCertificate;
}

/// A record of a geodesic condition violation at a specific step of a computation trace. Produced by GeodesicValidator when J_k(step_i) < max_\{free\} J_k(state_i).
pub trait GeodesicViolation<P: Primitives> {
    /// Human-readable description of why a geodesic violation occurred, citing the step index and the unused higher-J_k option.
    fn violation_reason(&self) -> &P::String;
}

/// A specialized computation step recording a single projective collapse of a SuperposedSiteState. Carries pre-collapse entropy and post-collapse Landauer cost (QM_1).
pub trait MeasurementEvent<P: Primitives>: ComputationStep<P> {
    /// The von Neumann entropy S_vN of the SuperposedSiteState before projective collapse.
    fn pre_collapse_entropy(&self) -> P::Decimal;
    /// The Landauer cost incurred by the projective collapse. Equals preCollapseEntropy at β* = ln 2 (QM_1).
    fn post_collapse_landauer_cost(&self) -> P::Decimal;
    /// The step index within the enclosing ComputationTrace at which this projective collapse occurred.
    fn collapse_step(&self) -> P::NonNegativeInteger;
    /// The full pre-collapse amplitude vector of all branches at the time of measurement. Enables Born rule verification (QM_5): P(outcome k) = |α_k|² / Σ|αᵢ|².
    fn amplitude_vector(&self) -> P::Decimal;
}

/// A single outcome of a projective measurement on a SuperposedSiteState, recording the classical site index (outcomeValue) and its Born-rule probability |α_k|² (outcomeProbability). Multiple outcomes form the probability distribution of a measurement.
pub trait MeasurementOutcome<P: Primitives> {
    /// The classical site index selected by projective collapse in this measurement outcome.
    fn outcome_value(&self) -> P::NonNegativeInteger;
    /// The Born-rule probability of this measurement outcome: |α_k|² where α_k is the amplitude of the collapsed site.
    fn outcome_probability(&self) -> P::Decimal;
}

/// Canonical geodesic trace at quantum level Q0 (n=8). Demonstrates GD_1 through GD_3 at the base level.
pub mod geodesic_q0 {
    /// `adiabaticallyOrdered`
    pub const ADIABATICALLY_ORDERED: bool = true;
    /// `isGeodesic`
    pub const IS_GEODESIC: bool = true;
}

/// Canonical geodesic trace at quantum level Q1 (n=16). Demonstrates geodesic scaling from Q0 to Q1.
pub mod geodesic_q1 {
    /// `adiabaticallyOrdered`
    pub const ADIABATICALLY_ORDERED: bool = true;
    /// `isGeodesic`
    pub const IS_GEODESIC: bool = true;
}

/// Canonical geodesic trace at quantum level Q2 (n=32). Demonstrates geodesic scaling from Q1 to Q2.
pub mod geodesic_q2 {
    /// `adiabaticallyOrdered`
    pub const ADIABATICALLY_ORDERED: bool = true;
    /// `isGeodesic`
    pub const IS_GEODESIC: bool = true;
}

/// Canonical geodesic trace at quantum level Q3 (n=64). Demonstrates geodesic scaling from Q2 to Q3.
pub mod geodesic_q3 {
    /// `adiabaticallyOrdered`
    pub const ADIABATICALLY_ORDERED: bool = true;
    /// `isGeodesic`
    pub const IS_GEODESIC: bool = true;
}

/// Canonical measurement event: collapse of an equal superposition (|α|² = 0.5). Maximum von Neumann entropy S_vN = ln 2. Maximum Landauer cost per QM_1.
pub mod collapse_equal_superposition {
    /// `postCollapseLandauerCost`
    pub const POST_COLLAPSE_LANDAUER_COST: &str = "0.693147";
    /// `preCollapseEntropy`
    pub const PRE_COLLAPSE_ENTROPY: &str = "0.693147";
}

/// Canonical measurement event: collapse of a biased superposition (|α|² = 0.9). Lower entropy than equal superposition. Demonstrates QM_3 bound.
pub mod collapse_biased {
    /// `postCollapseLandauerCost`
    pub const POST_COLLAPSE_LANDAUER_COST: &str = "0.325083";
    /// `preCollapseEntropy`
    pub const PRE_COLLAPSE_ENTROPY: &str = "0.325083";
}

/// Canonical measurement event: collapse of a classical state (|α|² = 1). Zero entropy, zero Landauer cost. Demonstrates QM_4 idempotence.
pub mod collapse_classical {
    /// `postCollapseLandauerCost`
    pub const POST_COLLAPSE_LANDAUER_COST: &str = "0.0";
    /// `preCollapseEntropy`
    pub const PRE_COLLAPSE_ENTROPY: &str = "0.0";
}