uor-foundation 0.1.5

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

//! `partition/` namespace — Irreducibility partitions produced by type resolution. A partition divides the ring into four disjoint components: Irreducible, Reducible, Units, and Exterior..
//!
//! Space: Bridge

use crate::Primitives;

/// A four-component partition of R_n produced by resolving a type declaration. The four components — Irreducible, Reducible, Units, Exterior — are mutually disjoint and exhaustive over the carrier.
pub trait Partition<P: Primitives> {
    /// Associated type for `IrreducibleSet`.
    type IrreducibleSet: IrreducibleSet<P>;
    /// The irreducible component of this partition.
    fn irreducibles(&self) -> &Self::IrreducibleSet;
    /// Associated type for `ReducibleSet`.
    type ReducibleSet: ReducibleSet<P>;
    /// The reducible component of this partition.
    fn reducibles(&self) -> &Self::ReducibleSet;
    /// Associated type for `UnitSet`.
    type UnitSet: UnitSet<P>;
    /// The units component of this partition.
    fn units(&self) -> &Self::UnitSet;
    /// Associated type for `ExteriorSet`.
    type ExteriorSet: ExteriorSet<P>;
    /// The exterior component of this partition.
    fn exterior(&self) -> &Self::ExteriorSet;
    /// The irreducible density of this partition: |Irr| / |A|, where A is the active carrier.
    fn density(&self) -> P::Decimal;
    /// Associated type for `TypeDefinition`.
    type TypeDefinition: crate::user::type_::TypeDefinition<P>;
    /// The type declaration that was resolved to produce this partition.
    fn source_type(&self) -> &Self::TypeDefinition;
    /// The quantum level n at which this partition was computed. The ring has 2^n elements at this level.
    fn quantum(&self) -> P::PositiveInteger;
    /// Associated type for `FiberBudget`.
    type FiberBudget: FiberBudget<P>;
    /// The fiber budget associated with this partition.
    fn fiber_budget(&self) -> &Self::FiberBudget;
    /// Whether the four components of this partition are exhaustive over R_n: |Irr| + |Red| + |Unit| + |Ext| = 2^n (FPM_8). Set by the kernel after verification.
    fn is_exhaustive(&self) -> P::Boolean;
}

/// A single component of a partition: a set of datum values belonging to one of the four categories.
/// Disjoint with: FiberCoordinate, FiberBudget.
pub trait Component<P: Primitives> {
    /// Associated type for `Datum`.
    type Datum: crate::kernel::schema::Datum<P>;
    /// A datum value belonging to this partition component.
    fn member(&self) -> &[Self::Datum];
    /// The number of elements in this partition component. The cardinalities of the four components must sum to 2^n.
    fn cardinality(&self) -> P::NonNegativeInteger;
}

/// The set of irreducible elements under the active type: elements whose only factorizations involve units or themselves. Analogous to prime elements in a ring.
/// Disjoint with: ReducibleSet, UnitSet, ExteriorSet.
pub trait IrreducibleSet<P: Primitives>: Component<P> {}

/// The set of reducible non-unit elements: elements that can be expressed as a product of two or more non-unit elements.
/// Disjoint with: IrreducibleSet, UnitSet, ExteriorSet.
pub trait ReducibleSet<P: Primitives>: Component<P> {}

/// The set of invertible elements (units) in the carrier: elements with a multiplicative inverse. In Z/(2^n)Z, the units are the odd integers.
/// Disjoint with: IrreducibleSet, ReducibleSet, ExteriorSet.
pub trait UnitSet<P: Primitives>: Component<P> {}

/// Elements of R_n that fall outside the active carrier — i.e., outside the type's domain. These are ring elements that do not participate in the current type resolution.
/// Disjoint with: IrreducibleSet, ReducibleSet, UnitSet.
pub trait ExteriorSet<P: Primitives>: Component<P> {
    /// Associated type for `TermExpression`.
    type TermExpression: crate::kernel::schema::TermExpression<P>;
    /// The formal membership criterion for this ExteriorSet: x ∈ Ext(T) iff x ∉ carrier(T). The ExteriorSet is context-dependent on the active type T (FPM_9).
    fn exterior_criteria(&self) -> &Self::TermExpression;
}

/// A single fiber coordinate in the iterated Z/2Z fibration. Each fiber represents one binary degree of freedom in the ring's structure. The total number of fibers equals the quantum level n.
/// Disjoint with: FiberBudget, Component.
pub trait FiberCoordinate<P: Primitives> {
    /// The zero-based position of this fiber coordinate within the iterated fibration. Position 0 is the least significant bit; position n-1 is the most significant.
    fn fiber_position(&self) -> P::NonNegativeInteger;
    /// The current state of this fiber coordinate: 'pinned' if determined by a constraint, 'free' if still available for refinement.
    fn fiber_state(&self) -> P::NonNegativeInteger;
    /// Associated type for `FiberCoordinate`.
    type FiberCoordinateTarget: FiberCoordinate<P>;
    /// An ancilla fiber coordinate paired with this fiber for reversible computation (RC_1–RC_4 ancilla model).
    fn ancilla_fiber(&self) -> &Self::FiberCoordinateTarget;
}

/// The fiber budget for a partition: an accounting of how many fibers are pinned (determined by constraints) versus free (still available for further refinement). A closed budget means all fibers are pinned and the type is fully resolved.
/// Disjoint with: FiberCoordinate, Component.
pub trait FiberBudget<P: Primitives> {
    /// The total number of fiber coordinates in this budget, equal to the quantum level n.
    fn total_fibers(&self) -> P::NonNegativeInteger;
    /// The number of fiber coordinates currently pinned by constraints.
    fn pinned_count(&self) -> P::NonNegativeInteger;
    /// The number of fiber coordinates still free (not yet pinned). Equals totalFibers - pinnedCount.
    fn free_count(&self) -> P::NonNegativeInteger;
    /// Whether all fibers in this budget are pinned. A closed budget means the type is fully resolved and the partition is complete.
    fn is_closed(&self) -> P::Boolean;
    /// Associated type for `FiberCoordinate`.
    type FiberCoordinate: FiberCoordinate<P>;
    /// A fiber coordinate belonging to this budget.
    fn has_fiber(&self) -> &[Self::FiberCoordinate];
    /// Associated type for `FiberPinning`.
    type FiberPinning: FiberPinning<P>;
    /// A fiber pinning record in this budget.
    fn has_pinning(&self) -> &[Self::FiberPinning];
    /// True when this fiber budget uses a reversible computation strategy preserving information through ancilla fibers.
    fn reversible_strategy(&self) -> P::Boolean;
}

/// A record of a single fiber being pinned by a constraint. Links a specific fiber coordinate to the constraint that determined its value.
pub trait FiberPinning<P: Primitives> {
    /// Associated type for `Constraint`.
    type Constraint: crate::user::type_::Constraint<P>;
    /// The constraint that pins this fiber coordinate.
    fn pinned_by(&self) -> &Self::Constraint;
    /// Associated type for `FiberCoordinate`.
    type FiberCoordinate: FiberCoordinate<P>;
    /// The fiber coordinate that this pinning determines.
    fn pins_coordinate(&self) -> &Self::FiberCoordinate;
}

/// The tensor product of two partitions: partition(A × B) = partition(A) ⊗ partition(B). The four-component structure combines component-wise under the product type construction (PT_2a). Carries leftFactor and rightFactor links to the operand partitions.
/// Disjoint with: PartitionCoproduct.
pub trait PartitionProduct<P: Primitives> {
    /// Associated type for `Partition`.
    type Partition: Partition<P>;
    /// The left operand partition of this tensor product.
    fn left_factor(&self) -> &Self::Partition;
    /// The right operand partition of this tensor product.
    fn right_factor(&self) -> &Self::Partition;
}

/// The coproduct (disjoint union) of two partitions: partition(A + B) = partition(A) ⊕ partition(B). The four-component structure combines via disjoint union under the sum type construction (PT_2b). Carries leftSummand and rightSummand links to the operand partitions.
/// Disjoint with: PartitionProduct.
pub trait PartitionCoproduct<P: Primitives> {
    /// Associated type for `Partition`.
    type Partition: Partition<P>;
    /// The left operand partition of this coproduct.
    fn left_summand(&self) -> &Self::Partition;
    /// The right operand partition of this coproduct.
    fn right_summand(&self) -> &Self::Partition;
}