uor-foundation 0.3.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

//! `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::HostTypes;

/// 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<H: HostTypes> {
    /// Associated type for `IrreducibleSet`.
    type IrreducibleSet: IrreducibleSet<H>;
    /// The irreducible component of this partition.
    fn irreducibles(&self) -> &Self::IrreducibleSet;
    /// Associated type for `ReducibleSet`.
    type ReducibleSet: ReducibleSet<H>;
    /// The reducible component of this partition.
    fn reducibles(&self) -> &Self::ReducibleSet;
    /// Associated type for `UnitGroup`.
    type UnitGroup: UnitGroup<H>;
    /// The units component of this partition.
    fn units(&self) -> &Self::UnitGroup;
    /// Associated type for `Complement`.
    type Complement: Complement<H>;
    /// The exterior component of this partition.
    fn exterior(&self) -> &Self::Complement;
    /// The irreducible density of this partition: |Irr| / |A|, where A is the active carrier.
    fn density(&self) -> H::Decimal;
    /// Associated type for `TypeDefinition`.
    type TypeDefinition: crate::user::type_::TypeDefinition<H>;
    /// The type declaration that was resolved to produce this partition.
    fn source_type(&self) -> &Self::TypeDefinition;
    /// The Witt level n at which this partition was computed. The ring has 2^n elements at this level.
    fn witt_length(&self) -> u64;
    /// Associated type for `FreeRank`.
    type FreeRank: FreeRank<H>;
    /// The site budget associated with this partition.
    fn site_budget(&self) -> &Self::FreeRank;
    /// 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) -> bool;
}

/// A single component of a partition: a set of datum values belonging to one of the four categories.
/// Disjoint with: SiteIndex, FreeRank.
pub trait Component<H: HostTypes> {
    /// Associated type for `Datum`.
    type Datum: crate::kernel::schema::Datum<H>;
    /// 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) -> u64;
}

/// 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, UnitGroup, Complement.
pub trait IrreducibleSet<H: HostTypes>: Component<H> {}

/// 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, UnitGroup, Complement.
pub trait ReducibleSet<H: HostTypes>: Component<H> {}

/// 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, Complement.
pub trait UnitGroup<H: HostTypes>: Component<H> {}

/// 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, UnitGroup.
pub trait Complement<H: HostTypes>: Component<H> {
    /// Associated type for `TermExpression`.
    type TermExpression: crate::kernel::schema::TermExpression<H>;
    /// The formal membership criterion for this Complement: x ∈ Ext(T) iff x ∉ carrier(T). The Complement is context-dependent on the active type T (FPM_9).
    fn exterior_criteria(&self) -> &Self::TermExpression;
}

/// A single site coordinate in the iterated Z/2Z fibration. Each site represents one binary degree of freedom in the ring's structure. The total number of sites equals the quantum level n.
/// Disjoint with: FreeRank, Component.
pub trait SiteIndex<H: HostTypes> {
    /// The zero-based position of this site coordinate within the iterated fibration. Position 0 is the least significant bit; position n-1 is the most significant.
    fn site_position(&self) -> u64;
    /// The current state of this site coordinate: 'pinned' if determined by a constraint, 'free' if still available for refinement.
    fn site_state(&self) -> u64;
    /// Associated type for `SiteIndex`.
    type SiteIndexTarget: SiteIndex<H>;
    /// An ancilla site coordinate paired with this site for reversible computation (RC_1–RC_4 ancilla model).
    fn ancilla_site(&self) -> &Self::SiteIndexTarget;
}

/// The site budget for a partition: an accounting of how many sites are pinned (determined by constraints) versus free (still available for further refinement). A closed budget means all sites are pinned and the type is fully resolved.
/// Disjoint with: SiteIndex, Component.
pub trait FreeRank<H: HostTypes> {
    /// The total number of site coordinates in this budget, equal to the quantum level n.
    fn total_sites(&self) -> u64;
    /// The number of site coordinates currently pinned by constraints.
    fn pinned_count(&self) -> u64;
    /// The number of site coordinates still free (not yet pinned). Equals totalSites - pinnedCount.
    fn free_rank(&self) -> u64;
    /// Whether all sites in this budget are pinned. A closed budget means the type is fully resolved and the partition is complete.
    fn is_closed(&self) -> bool;
    /// Associated type for `SiteIndex`.
    type SiteIndex: SiteIndex<H>;
    /// A site coordinate belonging to this budget.
    fn has_site(&self) -> &[Self::SiteIndex];
    /// Associated type for `SiteBinding`.
    type SiteBinding: SiteBinding<H>;
    /// A site pinning record in this budget.
    fn has_binding(&self) -> &[Self::SiteBinding];
    /// True when this site budget uses a reversible computation strategy preserving information through ancilla sites.
    fn reversible_strategy(&self) -> bool;
}

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

/// 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<H: HostTypes> {
    /// Associated type for `Partition`.
    type Partition: Partition<H>;
    /// 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<H: HostTypes> {
    /// Associated type for `Partition`.
    type Partition: Partition<H>;
    /// 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;
}

/// Observes the free-rank of the partition associated with a Datum's site context, recording the count of unbound sites at the moment of observation. Used as the bound observable for the siteConstraintKind BoundConstraint.
pub trait FreeRankObservable<H: HostTypes>: crate::bridge::observable::Observable<H> {}

/// The irreducible component: elements that admit no non-trivial factorization within the ring.
pub mod irreducible {}

/// The reducible component: elements that factor into non-trivial parts.
pub mod reducible {}

/// The unit component: invertible elements of the ring.
pub mod units {}

/// The exterior component: elements outside the factorization domain (e.g., zero or ring-boundary values).
pub mod exterior {}