use crate::{
DecimalTranscendental, HostTypes, MetricAxis, PrimitiveOp, VerificationDomain, ViolationKind,
WittLevel,
};
use core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
impl Sealed for super::GroundedCoord {}
impl<const N: usize> Sealed for super::GroundedTuple<N> {}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(clippy::large_enum_variant, dead_code)]
pub(crate) enum DatumInner {
W8([u8; 1]),
W16([u8; 2]),
W24([u8; 3]),
W32([u8; 4]),
W40([u8; 5]),
W48([u8; 6]),
W56([u8; 7]),
W64([u8; 8]),
W72([u8; 9]),
W80([u8; 10]),
W88([u8; 11]),
W96([u8; 12]),
W104([u8; 13]),
W112([u8; 14]),
W120([u8; 15]),
W128([u8; 16]),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Datum {
inner: DatumInner,
}
impl Datum {
#[inline]
#[must_use]
pub const fn level(&self) -> WittLevel {
match self.inner {
DatumInner::W8(_) => WittLevel::W8,
DatumInner::W16(_) => WittLevel::W16,
DatumInner::W24(_) => WittLevel::new(24),
DatumInner::W32(_) => WittLevel::new(32),
DatumInner::W40(_) => WittLevel::new(40),
DatumInner::W48(_) => WittLevel::new(48),
DatumInner::W56(_) => WittLevel::new(56),
DatumInner::W64(_) => WittLevel::new(64),
DatumInner::W72(_) => WittLevel::new(72),
DatumInner::W80(_) => WittLevel::new(80),
DatumInner::W88(_) => WittLevel::new(88),
DatumInner::W96(_) => WittLevel::new(96),
DatumInner::W104(_) => WittLevel::new(104),
DatumInner::W112(_) => WittLevel::new(112),
DatumInner::W120(_) => WittLevel::new(120),
DatumInner::W128(_) => WittLevel::new(128),
}
}
#[inline]
#[must_use]
pub fn as_bytes(&self) -> &[u8] {
match &self.inner {
DatumInner::W8(b) => b,
DatumInner::W16(b) => b,
DatumInner::W24(b) => b,
DatumInner::W32(b) => b,
DatumInner::W40(b) => b,
DatumInner::W48(b) => b,
DatumInner::W56(b) => b,
DatumInner::W64(b) => b,
DatumInner::W72(b) => b,
DatumInner::W80(b) => b,
DatumInner::W88(b) => b,
DatumInner::W96(b) => b,
DatumInner::W104(b) => b,
DatumInner::W112(b) => b,
DatumInner::W120(b) => b,
DatumInner::W128(b) => b,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(clippy::large_enum_variant, dead_code)]
pub(crate) enum GroundedCoordInner {
W8([u8; 1]),
W16([u8; 2]),
W24([u8; 3]),
W32([u8; 4]),
W40([u8; 5]),
W48([u8; 6]),
W56([u8; 7]),
W64([u8; 8]),
W72([u8; 9]),
W80([u8; 10]),
W88([u8; 11]),
W96([u8; 12]),
W104([u8; 13]),
W112([u8; 14]),
W120([u8; 15]),
W128([u8; 16]),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GroundedCoord {
pub(crate) inner: GroundedCoordInner,
}
impl GroundedCoord {
#[inline]
#[must_use]
pub const fn w8(value: u8) -> Self {
Self {
inner: GroundedCoordInner::W8(value.to_le_bytes()),
}
}
#[inline]
#[must_use]
pub const fn w16(value: u16) -> Self {
Self {
inner: GroundedCoordInner::W16(value.to_le_bytes()),
}
}
#[inline]
#[must_use]
pub const fn w24(value: u32) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 3];
let mut i = 0;
while i < 3 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W24(out),
}
}
#[inline]
#[must_use]
pub const fn w32(value: u32) -> Self {
Self {
inner: GroundedCoordInner::W32(value.to_le_bytes()),
}
}
#[inline]
#[must_use]
pub const fn w40(value: u64) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 5];
let mut i = 0;
while i < 5 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W40(out),
}
}
#[inline]
#[must_use]
pub const fn w48(value: u64) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 6];
let mut i = 0;
while i < 6 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W48(out),
}
}
#[inline]
#[must_use]
pub const fn w56(value: u64) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 7];
let mut i = 0;
while i < 7 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W56(out),
}
}
#[inline]
#[must_use]
pub const fn w64(value: u64) -> Self {
Self {
inner: GroundedCoordInner::W64(value.to_le_bytes()),
}
}
#[inline]
#[must_use]
pub const fn w72(value: u128) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 9];
let mut i = 0;
while i < 9 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W72(out),
}
}
#[inline]
#[must_use]
pub const fn w80(value: u128) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 10];
let mut i = 0;
while i < 10 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W80(out),
}
}
#[inline]
#[must_use]
pub const fn w88(value: u128) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 11];
let mut i = 0;
while i < 11 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W88(out),
}
}
#[inline]
#[must_use]
pub const fn w96(value: u128) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 12];
let mut i = 0;
while i < 12 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W96(out),
}
}
#[inline]
#[must_use]
pub const fn w104(value: u128) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 13];
let mut i = 0;
while i < 13 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W104(out),
}
}
#[inline]
#[must_use]
pub const fn w112(value: u128) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 14];
let mut i = 0;
while i < 14 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W112(out),
}
}
#[inline]
#[must_use]
pub const fn w120(value: u128) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 15];
let mut i = 0;
while i < 15 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W120(out),
}
}
#[inline]
#[must_use]
pub const fn w128(value: u128) -> Self {
let full = value.to_le_bytes();
let mut out = [0u8; 16];
let mut i = 0;
while i < 16 {
out[i] = full[i];
i += 1;
}
Self {
inner: GroundedCoordInner::W128(out),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GroundedTuple<const N: usize> {
pub(crate) coords: [GroundedCoord; N],
}
impl<const N: usize> GroundedTuple<N> {
#[inline]
#[must_use]
pub const fn new(coords: [GroundedCoord; N]) -> Self {
Self { coords }
}
}
pub trait GroundedValue: sealed::Sealed {}
impl GroundedValue for GroundedCoord {}
impl<const N: usize> GroundedValue for GroundedTuple<N> {}
pub trait MorphismKind: morphism_kind_sealed::Sealed {
const ONTOLOGY_IRI: &'static str;
}
pub trait GroundingMapKind: MorphismKind + grounding_map_kind_sealed::Sealed {}
pub trait ProjectionMapKind: MorphismKind + projection_map_kind_sealed::Sealed {}
pub trait Total: MorphismKind {}
pub trait Invertible: MorphismKind {}
pub trait PreservesStructure: MorphismKind {}
pub trait PreservesMetric: MorphismKind {}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BinaryGroundingMap;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DigestGroundingMap;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct IntegerGroundingMap;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct JsonGroundingMap;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Utf8GroundingMap;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BinaryProjectionMap;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DigestProjectionMap;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct IntegerProjectionMap;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct JsonProjectionMap;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Utf8ProjectionMap;
mod morphism_kind_sealed {
pub trait Sealed {}
impl Sealed for super::BinaryGroundingMap {}
impl Sealed for super::DigestGroundingMap {}
impl Sealed for super::IntegerGroundingMap {}
impl Sealed for super::JsonGroundingMap {}
impl Sealed for super::Utf8GroundingMap {}
impl Sealed for super::BinaryProjectionMap {}
impl Sealed for super::DigestProjectionMap {}
impl Sealed for super::IntegerProjectionMap {}
impl Sealed for super::JsonProjectionMap {}
impl Sealed for super::Utf8ProjectionMap {}
}
mod grounding_map_kind_sealed {
pub trait Sealed {}
impl Sealed for super::BinaryGroundingMap {}
impl Sealed for super::DigestGroundingMap {}
impl Sealed for super::IntegerGroundingMap {}
impl Sealed for super::JsonGroundingMap {}
impl Sealed for super::Utf8GroundingMap {}
}
mod projection_map_kind_sealed {
pub trait Sealed {}
impl Sealed for super::BinaryProjectionMap {}
impl Sealed for super::DigestProjectionMap {}
impl Sealed for super::IntegerProjectionMap {}
impl Sealed for super::JsonProjectionMap {}
impl Sealed for super::Utf8ProjectionMap {}
}
impl MorphismKind for BinaryGroundingMap {
const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/BinaryGroundingMap";
}
impl MorphismKind for DigestGroundingMap {
const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/DigestGroundingMap";
}
impl MorphismKind for IntegerGroundingMap {
const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/IntegerGroundingMap";
}
impl MorphismKind for JsonGroundingMap {
const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/JsonGroundingMap";
}
impl MorphismKind for Utf8GroundingMap {
const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/Utf8GroundingMap";
}
impl MorphismKind for BinaryProjectionMap {
const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/BinaryProjectionMap";
}
impl MorphismKind for DigestProjectionMap {
const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/DigestProjectionMap";
}
impl MorphismKind for IntegerProjectionMap {
const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/IntegerProjectionMap";
}
impl MorphismKind for JsonProjectionMap {
const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/JsonProjectionMap";
}
impl MorphismKind for Utf8ProjectionMap {
const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/Utf8ProjectionMap";
}
impl GroundingMapKind for BinaryGroundingMap {}
impl GroundingMapKind for DigestGroundingMap {}
impl GroundingMapKind for IntegerGroundingMap {}
impl GroundingMapKind for JsonGroundingMap {}
impl GroundingMapKind for Utf8GroundingMap {}
impl ProjectionMapKind for BinaryProjectionMap {}
impl ProjectionMapKind for DigestProjectionMap {}
impl ProjectionMapKind for IntegerProjectionMap {}
impl ProjectionMapKind for JsonProjectionMap {}
impl ProjectionMapKind for Utf8ProjectionMap {}
impl Total for IntegerGroundingMap {}
impl Invertible for IntegerGroundingMap {}
impl PreservesStructure for IntegerGroundingMap {}
impl Invertible for Utf8GroundingMap {}
impl PreservesStructure for Utf8GroundingMap {}
impl Invertible for JsonGroundingMap {}
impl PreservesStructure for JsonGroundingMap {}
impl Total for DigestGroundingMap {}
impl Total for BinaryGroundingMap {}
impl Invertible for BinaryGroundingMap {}
impl Invertible for IntegerProjectionMap {}
impl PreservesStructure for IntegerProjectionMap {}
impl Invertible for Utf8ProjectionMap {}
impl PreservesStructure for Utf8ProjectionMap {}
impl Invertible for JsonProjectionMap {}
impl PreservesStructure for JsonProjectionMap {}
impl Total for DigestProjectionMap {}
impl Total for BinaryProjectionMap {}
impl Invertible for BinaryProjectionMap {}
pub trait Grounding {
type Output: GroundedValue;
type Map: GroundingMapKind;
fn program(&self) -> GroundingProgram<Self::Output, Self::Map>;
}
mod grounding_ext_sealed {
pub trait Sealed {}
impl<G: super::Grounding> Sealed for G {}
}
pub trait GroundingProgramRun<Out> {
fn run_program(&self, external: &[u8]) -> Option<Out>;
}
impl<Map: GroundingMapKind> GroundingProgramRun<GroundedCoord>
for GroundingProgram<GroundedCoord, Map>
{
#[inline]
fn run_program(&self, external: &[u8]) -> Option<GroundedCoord> {
self.run(external)
}
}
impl<const N: usize, Map: GroundingMapKind> GroundingProgramRun<GroundedTuple<N>>
for GroundingProgram<GroundedTuple<N>, Map>
{
#[inline]
fn run_program(&self, external: &[u8]) -> Option<GroundedTuple<N>> {
self.run(external)
}
}
pub trait GroundingExt: Grounding + grounding_ext_sealed::Sealed {
fn ground(&self, external: &[u8]) -> Option<Self::Output>;
}
impl<G: Grounding> GroundingExt for G
where
GroundingProgram<G::Output, G::Map>: GroundingProgramRun<G::Output>,
{
#[inline]
fn ground(&self, external: &[u8]) -> Option<Self::Output> {
self.program().run_program(external)
}
}
pub trait Sinking {
type Source: GroundedShape;
type ProjectionMap: ProjectionMapKind;
type Output;
fn project(&self, grounded: &Grounded<Self::Source>) -> Self::Output;
}
pub trait EmitThrough<H: crate::HostTypes>: crate::bridge::boundary::EmitEffect<H> {
type Sinking: Sinking;
fn emit(
&self,
grounded: &Grounded<<Self::Sinking as Sinking>::Source>,
) -> <Self::Sinking as Sinking>::Output;
}
pub trait ValidationPhase: validation_phase_sealed::Sealed {}
mod validation_phase_sealed {
pub trait Sealed {}
impl Sealed for super::CompileTime {}
impl Sealed for super::Runtime {}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CompileTime;
impl ValidationPhase for CompileTime {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Runtime;
impl ValidationPhase for Runtime {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Validated<T, Phase: ValidationPhase = Runtime> {
inner: T,
_phase: PhantomData<Phase>,
_sealed: (),
}
impl<T, Phase: ValidationPhase> Validated<T, Phase> {
#[inline]
#[must_use]
pub const fn inner(&self) -> &T {
&self.inner
}
#[inline]
#[allow(dead_code)]
pub(crate) const fn new(inner: T) -> Self {
Self {
inner,
_phase: PhantomData,
_sealed: (),
}
}
}
impl<T> From<Validated<T, CompileTime>> for Validated<T, Runtime> {
#[inline]
fn from(value: Validated<T, CompileTime>) -> Self {
Self {
inner: value.inner,
_phase: PhantomData,
_sealed: (),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Derivation {
step_count: u32,
witt_level_bits: u16,
content_fingerprint: ContentFingerprint,
}
impl Derivation {
#[inline]
#[must_use]
pub const fn step_count(&self) -> u32 {
self.step_count
}
#[inline]
#[must_use]
pub const fn witt_level_bits(&self) -> u16 {
self.witt_level_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(
step_count: u32,
witt_level_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
step_count,
witt_level_bits,
content_fingerprint,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FreeRank {
total: u32,
pinned: u32,
}
impl FreeRank {
#[inline]
#[must_use]
pub const fn total(&self) -> u32 {
self.total
}
#[inline]
#[must_use]
pub const fn pinned(&self) -> u32 {
self.pinned
}
#[inline]
#[must_use]
pub const fn remaining(&self) -> u32 {
self.total - self.pinned
}
#[inline]
#[allow(dead_code)]
pub(crate) const fn new(total: u32, pinned: u32) -> Self {
Self { total, pinned }
}
}
#[derive(Debug)]
pub struct LandauerBudget<H: HostTypes = crate::DefaultHostTypes> {
nats: H::Decimal,
_phantom: core::marker::PhantomData<H>,
_sealed: (),
}
impl<H: HostTypes> LandauerBudget<H> {
#[inline]
#[must_use]
pub const fn nats(&self) -> H::Decimal {
self.nats
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(nats: H::Decimal) -> Self {
Self {
nats,
_phantom: core::marker::PhantomData,
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn zero() -> Self {
Self {
nats: H::EMPTY_DECIMAL,
_phantom: core::marker::PhantomData,
_sealed: (),
}
}
}
impl<H: HostTypes> Copy for LandauerBudget<H> {}
impl<H: HostTypes> Clone for LandauerBudget<H> {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl<H: HostTypes> PartialEq for LandauerBudget<H> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.nats == other.nats
}
}
impl<H: HostTypes> Eq for LandauerBudget<H> {}
impl<H: HostTypes> PartialOrd for LandauerBudget<H> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl<H: HostTypes> Ord for LandauerBudget<H> {
#[inline]
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.nats
.partial_cmp(&other.nats)
.unwrap_or(core::cmp::Ordering::Equal)
}
}
impl<H: HostTypes> core::hash::Hash for LandauerBudget<H> {
#[inline]
fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
self.nats.to_bits().hash(state);
}
}
#[derive(Debug)]
pub struct UorTime<H: HostTypes = crate::DefaultHostTypes> {
landauer_nats: LandauerBudget<H>,
rewrite_steps: u64,
_sealed: (),
}
impl<H: HostTypes> UorTime<H> {
#[inline]
#[must_use]
pub const fn landauer_nats(&self) -> LandauerBudget<H> {
self.landauer_nats
}
#[inline]
#[must_use]
pub const fn rewrite_steps(&self) -> u64 {
self.rewrite_steps
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(landauer_nats: LandauerBudget<H>, rewrite_steps: u64) -> Self {
Self {
landauer_nats,
rewrite_steps,
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn zero() -> Self {
Self {
landauer_nats: LandauerBudget::<H>::zero(),
rewrite_steps: 0,
_sealed: (),
}
}
#[inline]
#[must_use]
pub fn min_wall_clock(&self, cal: &Calibration<H>) -> Nanos {
let landauer_seconds = self.landauer_nats.nats() * cal.k_b_t() / cal.thermal_power();
let pi_times_h_bar =
<H::Decimal as DecimalTranscendental>::from_bits(crate::PI_TIMES_H_BAR_BITS);
let two = <H::Decimal as DecimalTranscendental>::from_u32(2);
let ml_seconds_per_step = pi_times_h_bar / (two * cal.characteristic_energy());
let steps = <H::Decimal as DecimalTranscendental>::from_u64(self.rewrite_steps);
let ml_seconds = ml_seconds_per_step * steps;
let max_seconds = if landauer_seconds > ml_seconds {
landauer_seconds
} else {
ml_seconds
};
let nanos_per_second =
<H::Decimal as DecimalTranscendental>::from_bits(crate::NANOS_PER_SECOND_BITS);
let nanos = max_seconds * nanos_per_second;
Nanos {
ns: <H::Decimal as DecimalTranscendental>::as_u64_saturating(nanos),
_sealed: (),
}
}
}
impl<H: HostTypes> Copy for UorTime<H> {}
impl<H: HostTypes> Clone for UorTime<H> {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl<H: HostTypes> PartialEq for UorTime<H> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.landauer_nats == other.landauer_nats && self.rewrite_steps == other.rewrite_steps
}
}
impl<H: HostTypes> Eq for UorTime<H> {}
impl<H: HostTypes> core::hash::Hash for UorTime<H> {
#[inline]
fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
self.landauer_nats.hash(state);
self.rewrite_steps.hash(state);
}
}
impl<H: HostTypes> PartialOrd for UorTime<H> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
let l = self.landauer_nats.cmp(&other.landauer_nats);
let r = self.rewrite_steps.cmp(&other.rewrite_steps);
match (l, r) {
(core::cmp::Ordering::Equal, core::cmp::Ordering::Equal) => {
Some(core::cmp::Ordering::Equal)
}
(core::cmp::Ordering::Less, core::cmp::Ordering::Less)
| (core::cmp::Ordering::Less, core::cmp::Ordering::Equal)
| (core::cmp::Ordering::Equal, core::cmp::Ordering::Less) => {
Some(core::cmp::Ordering::Less)
}
(core::cmp::Ordering::Greater, core::cmp::Ordering::Greater)
| (core::cmp::Ordering::Greater, core::cmp::Ordering::Equal)
| (core::cmp::Ordering::Equal, core::cmp::Ordering::Greater) => {
Some(core::cmp::Ordering::Greater)
}
_ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Nanos {
ns: u64,
_sealed: (),
}
impl Nanos {
#[inline]
#[must_use]
pub const fn as_u64(self) -> u64 {
self.ns
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CalibrationError {
ThermalEnergy,
ThermalPower,
CharacteristicEnergy,
}
impl core::fmt::Display for CalibrationError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::ThermalEnergy => {
f.write_str("calibration k_b_t out of range (must be in [1e-30, 1e-15] joules)")
}
Self::ThermalPower => {
f.write_str("calibration thermal_power out of range (must be > 0 and <= 1e9 W)")
}
Self::CharacteristicEnergy => f.write_str(
"calibration characteristic_energy out of range (must be > 0 and <= 1e3 J)",
),
}
}
}
impl core::error::Error for CalibrationError {}
#[derive(Debug)]
pub struct Calibration<H: HostTypes = crate::DefaultHostTypes> {
k_b_t: H::Decimal,
thermal_power: H::Decimal,
characteristic_energy: H::Decimal,
_phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for Calibration<H> {}
impl<H: HostTypes> Clone for Calibration<H> {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl<H: HostTypes> PartialEq for Calibration<H> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.k_b_t == other.k_b_t
&& self.thermal_power == other.thermal_power
&& self.characteristic_energy == other.characteristic_energy
}
}
impl<H: HostTypes> Calibration<H> {
#[inline]
pub fn new(
k_b_t: H::Decimal,
thermal_power: H::Decimal,
characteristic_energy: H::Decimal,
) -> Result<Self, CalibrationError> {
let zero = <H::Decimal as Default>::default();
let kbt_lo =
<H::Decimal as DecimalTranscendental>::from_bits(crate::CALIBRATION_KBT_LO_BITS);
let kbt_hi =
<H::Decimal as DecimalTranscendental>::from_bits(crate::CALIBRATION_KBT_HI_BITS);
let tp_hi = <H::Decimal as DecimalTranscendental>::from_bits(
crate::CALIBRATION_THERMAL_POWER_HI_BITS,
);
let ce_hi = <H::Decimal as DecimalTranscendental>::from_bits(
crate::CALIBRATION_CHAR_ENERGY_HI_BITS,
);
#[allow(clippy::eq_op)]
let k_b_t_nan = k_b_t != k_b_t;
if k_b_t_nan || k_b_t <= zero || k_b_t < kbt_lo || k_b_t > kbt_hi {
return Err(CalibrationError::ThermalEnergy);
}
#[allow(clippy::eq_op)]
let tp_nan = thermal_power != thermal_power;
if tp_nan || thermal_power <= zero || thermal_power > tp_hi {
return Err(CalibrationError::ThermalPower);
}
#[allow(clippy::eq_op)]
let ce_nan = characteristic_energy != characteristic_energy;
if ce_nan || characteristic_energy <= zero || characteristic_energy > ce_hi {
return Err(CalibrationError::CharacteristicEnergy);
}
Ok(Self {
k_b_t,
thermal_power,
characteristic_energy,
_phantom: core::marker::PhantomData,
})
}
#[inline]
#[must_use]
pub const fn k_b_t(&self) -> H::Decimal {
self.k_b_t
}
#[inline]
#[must_use]
pub const fn thermal_power(&self) -> H::Decimal {
self.thermal_power
}
#[inline]
#[must_use]
pub const fn characteristic_energy(&self) -> H::Decimal {
self.characteristic_energy
}
pub const ZERO_SENTINEL: Calibration<H> = Self {
k_b_t: H::EMPTY_DECIMAL,
thermal_power: H::EMPTY_DECIMAL,
characteristic_energy: H::EMPTY_DECIMAL,
_phantom: core::marker::PhantomData,
};
}
impl Calibration<crate::DefaultHostTypes> {
#[inline]
#[must_use]
pub(crate) const fn from_f64_unchecked(
k_b_t: <crate::DefaultHostTypes as crate::HostTypes>::Decimal,
thermal_power: <crate::DefaultHostTypes as crate::HostTypes>::Decimal,
characteristic_energy: <crate::DefaultHostTypes as crate::HostTypes>::Decimal,
) -> Self {
Self {
k_b_t,
thermal_power,
characteristic_energy,
_phantom: core::marker::PhantomData,
}
}
}
pub mod calibrations {
use super::Calibration;
use crate::DefaultHostTypes;
pub const X86_SERVER: Calibration<DefaultHostTypes> =
Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 85.0, 1.0e-15);
pub const ARM_MOBILE: Calibration<DefaultHostTypes> =
Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 5.0, 1.0e-16);
pub const CORTEX_M_EMBEDDED: Calibration<DefaultHostTypes> =
Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 0.1, 1.0e-17);
pub const CONSERVATIVE_WORST_CASE: Calibration<DefaultHostTypes> =
Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 1.0e9, 1.0);
}
pub trait TimingPolicy {
const PREFLIGHT_BUDGET_NS: u64;
const RUNTIME_BUDGET_NS: u64;
const CALIBRATION: &'static Calibration<crate::DefaultHostTypes>;
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CanonicalTimingPolicy;
impl TimingPolicy for CanonicalTimingPolicy {
const PREFLIGHT_BUDGET_NS: u64 = 10_000_000;
const RUNTIME_BUDGET_NS: u64 = 10_000_000;
const CALIBRATION: &'static Calibration<crate::DefaultHostTypes> =
&calibrations::CONSERVATIVE_WORST_CASE;
}
pub mod transcendentals {
use crate::DecimalTranscendental;
#[inline]
#[must_use]
pub fn ln<D: DecimalTranscendental>(x: D) -> D {
x.ln()
}
#[inline]
#[must_use]
pub fn exp<D: DecimalTranscendental>(x: D) -> D {
x.exp()
}
#[inline]
#[must_use]
pub fn sqrt<D: DecimalTranscendental>(x: D) -> D {
x.sqrt()
}
#[inline]
#[must_use]
pub fn entropy_term_nats<D: DecimalTranscendental>(p: D) -> D {
let zero = <D as Default>::default();
if p <= zero {
zero
} else {
zero - p * p.ln()
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TermList {
pub start: u32,
pub len: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TermArena<const CAP: usize> {
nodes: [Option<Term>; CAP],
len: u32,
}
impl<const CAP: usize> TermArena<CAP> {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self {
nodes: [None; CAP],
len: 0,
}
}
#[must_use]
pub fn push(&mut self, term: Term) -> Option<u32> {
let idx = self.len;
if (idx as usize) >= CAP {
return None;
}
self.nodes[idx as usize] = Some(term);
self.len = idx + 1;
Some(idx)
}
#[inline]
#[must_use]
pub fn get(&self, index: u32) -> Option<&Term> {
self.nodes
.get(index as usize)
.and_then(|slot| slot.as_ref())
}
#[inline]
#[must_use]
pub const fn len(&self) -> u32 {
self.len
}
#[inline]
#[must_use]
pub const fn is_empty(&self) -> bool {
self.len == 0
}
#[inline]
#[must_use]
pub fn as_slice(&self) -> &[Option<Term>] {
&self.nodes[..self.len as usize]
}
#[inline]
#[must_use]
pub const fn from_slice(slice: &'static [Term]) -> Self {
let mut nodes: [Option<Term>; CAP] = [None; CAP];
let mut i = 0usize;
while i < slice.len() && i < CAP {
nodes[i] = Some(slice[i]);
i += 1;
}
#[allow(clippy::cast_possible_truncation)]
let len = if slice.len() > CAP {
CAP as u32
} else {
slice.len() as u32
};
Self { nodes, len }
}
}
impl<const CAP: usize> Default for TermArena<CAP> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Term {
Literal {
value: u64,
level: WittLevel,
},
Variable {
name_index: u32,
},
Application {
operator: PrimitiveOp,
args: TermList,
},
Lift {
operand_index: u32,
target: WittLevel,
},
Project {
operand_index: u32,
target: WittLevel,
},
Match {
scrutinee_index: u32,
arms: TermList,
},
Recurse {
measure_index: u32,
base_index: u32,
step_index: u32,
},
Unfold {
seed_index: u32,
step_index: u32,
},
Try {
body_index: u32,
handler_index: u32,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TypeDeclaration {
pub name_index: u32,
pub constraints: TermList,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Binding {
pub name_index: u32,
pub type_index: u32,
pub value_index: u32,
pub surface: &'static str,
pub content_address: u64,
}
impl Binding {
#[inline]
#[must_use]
pub const fn to_binding_entry(&self) -> BindingEntry {
BindingEntry {
address: ContentAddress::from_u64_fingerprint(self.content_address),
bytes: self.surface.as_bytes(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Assertion {
pub lhs_index: u32,
pub rhs_index: u32,
pub surface: &'static str,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceDeclaration {
pub name_index: u32,
pub type_index: u32,
pub grounding_name_index: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SinkDeclaration {
pub name_index: u32,
pub type_index: u32,
pub projection_name_index: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ShapeViolation {
pub shape_iri: &'static str,
pub constraint_iri: &'static str,
pub property_iri: &'static str,
pub expected_range: &'static str,
pub min_count: u32,
pub max_count: u32,
pub kind: ViolationKind,
}
impl core::fmt::Display for ShapeViolation {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"shape violation: {} (constraint {}, property {}, kind {:?})",
self.shape_iri, self.constraint_iri, self.property_iri, self.kind,
)
}
}
impl core::error::Error for ShapeViolation {}
impl ShapeViolation {
#[inline]
#[must_use]
pub const fn const_message(&self) -> &'static str {
self.shape_iri
}
}
#[derive(Debug, Clone)]
pub struct CompileUnitBuilder<'a> {
root_term: Option<&'a [Term]>,
bindings: Option<&'a [Binding]>,
witt_level_ceiling: Option<WittLevel>,
thermodynamic_budget: Option<u64>,
target_domains: Option<&'a [VerificationDomain]>,
result_type_iri: Option<&'static str>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CompileUnit<'a> {
level: WittLevel,
budget: u64,
result_type_iri: &'static str,
root_term: &'a [Term],
bindings: &'a [Binding],
target_domains: &'a [VerificationDomain],
}
impl<'a> CompileUnit<'a> {
#[inline]
#[must_use]
pub const fn witt_level(&self) -> WittLevel {
self.level
}
#[inline]
#[must_use]
pub const fn thermodynamic_budget(&self) -> u64 {
self.budget
}
#[inline]
#[must_use]
pub const fn result_type_iri(&self) -> &'static str {
self.result_type_iri
}
#[inline]
#[must_use]
pub const fn root_term(&self) -> &'a [Term] {
self.root_term
}
#[inline]
#[must_use]
pub const fn bindings(&self) -> &'a [Binding] {
self.bindings
}
#[inline]
#[must_use]
pub const fn target_domains(&self) -> &'a [VerificationDomain] {
self.target_domains
}
#[inline]
#[must_use]
pub(crate) const fn from_parts_const(
level: WittLevel,
budget: u64,
result_type_iri: &'static str,
root_term: &'a [Term],
bindings: &'a [Binding],
target_domains: &'a [VerificationDomain],
) -> Self {
Self {
level,
budget,
result_type_iri,
root_term,
bindings,
target_domains,
}
}
}
impl<'a> CompileUnitBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
root_term: None,
bindings: None,
witt_level_ceiling: None,
thermodynamic_budget: None,
target_domains: None,
result_type_iri: None,
}
}
#[must_use]
pub const fn root_term(mut self, terms: &'a [Term]) -> Self {
self.root_term = Some(terms);
self
}
#[must_use]
pub const fn bindings(mut self, bindings: &'a [Binding]) -> Self {
self.bindings = Some(bindings);
self
}
#[must_use]
pub const fn witt_level_ceiling(mut self, level: WittLevel) -> Self {
self.witt_level_ceiling = Some(level);
self
}
#[must_use]
pub const fn thermodynamic_budget(mut self, budget: u64) -> Self {
self.thermodynamic_budget = Some(budget);
self
}
#[must_use]
pub const fn target_domains(mut self, domains: &'a [VerificationDomain]) -> Self {
self.target_domains = Some(domains);
self
}
#[must_use]
pub const fn result_type<T: crate::pipeline::ConstrainedTypeShape>(mut self) -> Self {
self.result_type_iri = Some(T::IRI);
self
}
#[inline]
#[must_use]
pub const fn witt_level_option(&self) -> Option<WittLevel> {
self.witt_level_ceiling
}
#[inline]
#[must_use]
pub const fn budget_option(&self) -> Option<u64> {
self.thermodynamic_budget
}
#[inline]
#[must_use]
pub const fn has_root_term_const(&self) -> bool {
self.root_term.is_some()
}
#[inline]
#[must_use]
pub const fn has_target_domains_const(&self) -> bool {
match self.target_domains {
Some(d) => !d.is_empty(),
None => false,
}
}
#[inline]
#[must_use]
pub const fn result_type_iri_const(&self) -> Option<&'static str> {
self.result_type_iri
}
#[inline]
#[must_use]
pub const fn root_term_slice_const(&self) -> &'a [Term] {
match self.root_term {
Some(terms) => terms,
None => &[],
}
}
#[inline]
#[must_use]
pub const fn bindings_slice_const(&self) -> &'a [Binding] {
match self.bindings {
Some(bindings) => bindings,
None => &[],
}
}
#[inline]
#[must_use]
pub const fn target_domains_slice_const(&self) -> &'a [VerificationDomain] {
match self.target_domains {
Some(d) => d,
None => &[],
}
}
pub fn validate(self) -> Result<Validated<CompileUnit<'a>>, ShapeViolation> {
let root_term = match self.root_term {
Some(terms) => terms,
None => {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
constraint_iri:
"https://uor.foundation/conformance/compileUnit_rootTerm_constraint",
property_iri: "https://uor.foundation/reduction/rootTerm",
expected_range: "https://uor.foundation/schema/Term",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
})
}
};
let level =
match self.witt_level_ceiling {
Some(l) => l,
None => return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
constraint_iri:
"https://uor.foundation/conformance/compileUnit_unitWittLevel_constraint",
property_iri: "https://uor.foundation/reduction/unitWittLevel",
expected_range: "https://uor.foundation/schema/WittLevel",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
}),
};
let budget = match self.thermodynamic_budget {
Some(b) => b,
None => return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
constraint_iri:
"https://uor.foundation/conformance/compileUnit_thermodynamicBudget_constraint",
property_iri: "https://uor.foundation/reduction/thermodynamicBudget",
expected_range: "http://www.w3.org/2001/XMLSchema#decimal",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
}),
};
let target_domains =
match self.target_domains {
Some(d) if !d.is_empty() => d,
_ => return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
constraint_iri:
"https://uor.foundation/conformance/compileUnit_targetDomains_constraint",
property_iri: "https://uor.foundation/reduction/targetDomains",
expected_range: "https://uor.foundation/op/VerificationDomain",
min_count: 1,
max_count: 0,
kind: ViolationKind::Missing,
}),
};
let result_type_iri = match self.result_type_iri {
Some(iri) => iri,
None => {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
constraint_iri:
"https://uor.foundation/conformance/compileUnit_resultType_constraint",
property_iri: "https://uor.foundation/reduction/resultType",
expected_range: "https://uor.foundation/type/ConstrainedType",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
})
}
};
let bindings: &'a [Binding] = match self.bindings {
Some(b) => b,
None => &[],
};
Ok(Validated::new(CompileUnit {
level,
budget,
result_type_iri,
root_term,
bindings,
target_domains,
}))
}
}
impl<'a> Default for CompileUnitBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct EffectDeclarationBuilder<'a> {
name: Option<&'a str>,
target_sites: Option<&'a [u32]>,
budget_delta: Option<i64>,
commutes: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EffectDeclaration {
pub shape_iri: &'static str,
}
impl EffectDeclaration {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
shape_iri: "https://uor.foundation/conformance/EffectShape",
}
}
}
impl<'a> EffectDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
name: None,
target_sites: None,
budget_delta: None,
commutes: None,
}
}
#[must_use]
pub const fn name(mut self, value: &'a str) -> Self {
self.name = Some(value);
self
}
#[must_use]
pub const fn target_sites(mut self, value: &'a [u32]) -> Self {
self.target_sites = Some(value);
self
}
#[must_use]
pub const fn budget_delta(mut self, value: i64) -> Self {
self.budget_delta = Some(value);
self
}
#[must_use]
pub const fn commutes(mut self, value: bool) -> Self {
self.commutes = Some(value);
self
}
pub fn validate(self) -> Result<Validated<EffectDeclaration>, ShapeViolation> {
if self.name.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/name",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.target_sites.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/target_sites",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.budget_delta.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/budget_delta",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.commutes.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/commutes",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(EffectDeclaration {
shape_iri: "https://uor.foundation/conformance/EffectShape",
}))
}
pub const fn validate_const(
&self,
) -> Result<Validated<EffectDeclaration, CompileTime>, ShapeViolation> {
if self.name.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/name",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.target_sites.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/target_sites",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.budget_delta.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/budget_delta",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.commutes.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/EffectShape",
constraint_iri: "https://uor.foundation/conformance/EffectShape",
property_iri: "https://uor.foundation/conformance/commutes",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(EffectDeclaration {
shape_iri: "https://uor.foundation/conformance/EffectShape",
}))
}
}
impl<'a> Default for EffectDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct GroundingDeclarationBuilder<'a> {
source_type: Option<&'a str>,
ring_mapping: Option<&'a str>,
invertibility: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GroundingDeclaration {
pub shape_iri: &'static str,
}
impl GroundingDeclaration {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
}
}
}
impl<'a> GroundingDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
source_type: None,
ring_mapping: None,
invertibility: None,
}
}
#[must_use]
pub const fn source_type(mut self, value: &'a str) -> Self {
self.source_type = Some(value);
self
}
#[must_use]
pub const fn ring_mapping(mut self, value: &'a str) -> Self {
self.ring_mapping = Some(value);
self
}
#[must_use]
pub const fn invertibility(mut self, value: bool) -> Self {
self.invertibility = Some(value);
self
}
pub fn validate(self) -> Result<Validated<GroundingDeclaration>, ShapeViolation> {
if self.source_type.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
constraint_iri: "https://uor.foundation/conformance/GroundingShape",
property_iri: "https://uor.foundation/conformance/source_type",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.ring_mapping.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
constraint_iri: "https://uor.foundation/conformance/GroundingShape",
property_iri: "https://uor.foundation/conformance/ring_mapping",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.invertibility.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
constraint_iri: "https://uor.foundation/conformance/GroundingShape",
property_iri: "https://uor.foundation/conformance/invertibility",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(GroundingDeclaration {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
}))
}
pub const fn validate_const(
&self,
) -> Result<Validated<GroundingDeclaration, CompileTime>, ShapeViolation> {
if self.source_type.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
constraint_iri: "https://uor.foundation/conformance/GroundingShape",
property_iri: "https://uor.foundation/conformance/source_type",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.ring_mapping.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
constraint_iri: "https://uor.foundation/conformance/GroundingShape",
property_iri: "https://uor.foundation/conformance/ring_mapping",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.invertibility.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
constraint_iri: "https://uor.foundation/conformance/GroundingShape",
property_iri: "https://uor.foundation/conformance/invertibility",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(GroundingDeclaration {
shape_iri: "https://uor.foundation/conformance/GroundingShape",
}))
}
}
impl<'a> Default for GroundingDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct DispatchDeclarationBuilder<'a> {
predicate: Option<&'a [Term]>,
target_resolver: Option<&'a str>,
priority: Option<u32>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DispatchDeclaration {
pub shape_iri: &'static str,
}
impl DispatchDeclaration {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
}
}
}
impl<'a> DispatchDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
predicate: None,
target_resolver: None,
priority: None,
}
}
#[must_use]
pub const fn predicate(mut self, value: &'a [Term]) -> Self {
self.predicate = Some(value);
self
}
#[must_use]
pub const fn target_resolver(mut self, value: &'a str) -> Self {
self.target_resolver = Some(value);
self
}
#[must_use]
pub const fn priority(mut self, value: u32) -> Self {
self.priority = Some(value);
self
}
pub fn validate(self) -> Result<Validated<DispatchDeclaration>, ShapeViolation> {
if self.predicate.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
constraint_iri: "https://uor.foundation/conformance/DispatchShape",
property_iri: "https://uor.foundation/conformance/predicate",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.target_resolver.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
constraint_iri: "https://uor.foundation/conformance/DispatchShape",
property_iri: "https://uor.foundation/conformance/target_resolver",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.priority.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
constraint_iri: "https://uor.foundation/conformance/DispatchShape",
property_iri: "https://uor.foundation/conformance/priority",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(DispatchDeclaration {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
}))
}
pub const fn validate_const(
&self,
) -> Result<Validated<DispatchDeclaration, CompileTime>, ShapeViolation> {
if self.predicate.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
constraint_iri: "https://uor.foundation/conformance/DispatchShape",
property_iri: "https://uor.foundation/conformance/predicate",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.target_resolver.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
constraint_iri: "https://uor.foundation/conformance/DispatchShape",
property_iri: "https://uor.foundation/conformance/target_resolver",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.priority.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
constraint_iri: "https://uor.foundation/conformance/DispatchShape",
property_iri: "https://uor.foundation/conformance/priority",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(DispatchDeclaration {
shape_iri: "https://uor.foundation/conformance/DispatchShape",
}))
}
}
impl<'a> Default for DispatchDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct LeaseDeclarationBuilder<'a> {
linear_site: Option<u32>,
scope: Option<&'a str>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LeaseDeclaration {
pub shape_iri: &'static str,
}
impl LeaseDeclaration {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
shape_iri: "https://uor.foundation/conformance/LeaseShape",
}
}
}
impl<'a> LeaseDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
linear_site: None,
scope: None,
}
}
#[must_use]
pub const fn linear_site(mut self, value: u32) -> Self {
self.linear_site = Some(value);
self
}
#[must_use]
pub const fn scope(mut self, value: &'a str) -> Self {
self.scope = Some(value);
self
}
pub fn validate(self) -> Result<Validated<LeaseDeclaration>, ShapeViolation> {
if self.linear_site.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/LeaseShape",
constraint_iri: "https://uor.foundation/conformance/LeaseShape",
property_iri: "https://uor.foundation/conformance/linear_site",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.scope.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/LeaseShape",
constraint_iri: "https://uor.foundation/conformance/LeaseShape",
property_iri: "https://uor.foundation/conformance/scope",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(LeaseDeclaration {
shape_iri: "https://uor.foundation/conformance/LeaseShape",
}))
}
pub const fn validate_const(
&self,
) -> Result<Validated<LeaseDeclaration, CompileTime>, ShapeViolation> {
if self.linear_site.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/LeaseShape",
constraint_iri: "https://uor.foundation/conformance/LeaseShape",
property_iri: "https://uor.foundation/conformance/linear_site",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.scope.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/LeaseShape",
constraint_iri: "https://uor.foundation/conformance/LeaseShape",
property_iri: "https://uor.foundation/conformance/scope",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(LeaseDeclaration {
shape_iri: "https://uor.foundation/conformance/LeaseShape",
}))
}
}
impl<'a> Default for LeaseDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct StreamDeclarationBuilder<'a> {
seed: Option<&'a [Term]>,
step: Option<&'a [Term]>,
productivity_witness: Option<&'a str>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StreamDeclaration {
pub shape_iri: &'static str,
}
impl StreamDeclaration {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
shape_iri: "https://uor.foundation/conformance/StreamShape",
}
}
}
impl<'a> StreamDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
seed: None,
step: None,
productivity_witness: None,
}
}
#[must_use]
pub const fn seed(mut self, value: &'a [Term]) -> Self {
self.seed = Some(value);
self
}
#[must_use]
pub const fn step(mut self, value: &'a [Term]) -> Self {
self.step = Some(value);
self
}
#[must_use]
pub const fn productivity_witness(mut self, value: &'a str) -> Self {
self.productivity_witness = Some(value);
self
}
pub fn validate(self) -> Result<Validated<StreamDeclaration>, ShapeViolation> {
if self.seed.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/StreamShape",
constraint_iri: "https://uor.foundation/conformance/StreamShape",
property_iri: "https://uor.foundation/conformance/seed",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.step.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/StreamShape",
constraint_iri: "https://uor.foundation/conformance/StreamShape",
property_iri: "https://uor.foundation/conformance/step",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.productivity_witness.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/StreamShape",
constraint_iri: "https://uor.foundation/conformance/StreamShape",
property_iri: "https://uor.foundation/conformance/productivity_witness",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(StreamDeclaration {
shape_iri: "https://uor.foundation/conformance/StreamShape",
}))
}
pub const fn validate_const(
&self,
) -> Result<Validated<StreamDeclaration, CompileTime>, ShapeViolation> {
if self.seed.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/StreamShape",
constraint_iri: "https://uor.foundation/conformance/StreamShape",
property_iri: "https://uor.foundation/conformance/seed",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.step.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/StreamShape",
constraint_iri: "https://uor.foundation/conformance/StreamShape",
property_iri: "https://uor.foundation/conformance/step",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.productivity_witness.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/StreamShape",
constraint_iri: "https://uor.foundation/conformance/StreamShape",
property_iri: "https://uor.foundation/conformance/productivity_witness",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(StreamDeclaration {
shape_iri: "https://uor.foundation/conformance/StreamShape",
}))
}
}
impl<'a> Default for StreamDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct PredicateDeclarationBuilder<'a> {
input_type: Option<&'a str>,
evaluator: Option<&'a [Term]>,
termination_witness: Option<&'a str>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PredicateDeclaration {
pub shape_iri: &'static str,
}
impl PredicateDeclaration {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
}
}
}
impl<'a> PredicateDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
input_type: None,
evaluator: None,
termination_witness: None,
}
}
#[must_use]
pub const fn input_type(mut self, value: &'a str) -> Self {
self.input_type = Some(value);
self
}
#[must_use]
pub const fn evaluator(mut self, value: &'a [Term]) -> Self {
self.evaluator = Some(value);
self
}
#[must_use]
pub const fn termination_witness(mut self, value: &'a str) -> Self {
self.termination_witness = Some(value);
self
}
pub fn validate(self) -> Result<Validated<PredicateDeclaration>, ShapeViolation> {
if self.input_type.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
constraint_iri: "https://uor.foundation/conformance/PredicateShape",
property_iri: "https://uor.foundation/conformance/input_type",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.evaluator.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
constraint_iri: "https://uor.foundation/conformance/PredicateShape",
property_iri: "https://uor.foundation/conformance/evaluator",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.termination_witness.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
constraint_iri: "https://uor.foundation/conformance/PredicateShape",
property_iri: "https://uor.foundation/conformance/termination_witness",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(PredicateDeclaration {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
}))
}
pub const fn validate_const(
&self,
) -> Result<Validated<PredicateDeclaration, CompileTime>, ShapeViolation> {
if self.input_type.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
constraint_iri: "https://uor.foundation/conformance/PredicateShape",
property_iri: "https://uor.foundation/conformance/input_type",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.evaluator.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
constraint_iri: "https://uor.foundation/conformance/PredicateShape",
property_iri: "https://uor.foundation/conformance/evaluator",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.termination_witness.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
constraint_iri: "https://uor.foundation/conformance/PredicateShape",
property_iri: "https://uor.foundation/conformance/termination_witness",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(PredicateDeclaration {
shape_iri: "https://uor.foundation/conformance/PredicateShape",
}))
}
}
impl<'a> Default for PredicateDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct ParallelDeclarationBuilder<'a> {
site_partition: Option<&'a [u32]>,
disjointness_witness: Option<&'a str>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParallelDeclaration {
pub shape_iri: &'static str,
}
impl ParallelDeclaration {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
shape_iri: "https://uor.foundation/conformance/ParallelShape",
}
}
}
impl<'a> ParallelDeclarationBuilder<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
site_partition: None,
disjointness_witness: None,
}
}
#[must_use]
pub const fn site_partition(mut self, value: &'a [u32]) -> Self {
self.site_partition = Some(value);
self
}
#[must_use]
pub const fn disjointness_witness(mut self, value: &'a str) -> Self {
self.disjointness_witness = Some(value);
self
}
pub fn validate(self) -> Result<Validated<ParallelDeclaration>, ShapeViolation> {
if self.site_partition.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/ParallelShape",
constraint_iri: "https://uor.foundation/conformance/ParallelShape",
property_iri: "https://uor.foundation/conformance/site_partition",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.disjointness_witness.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/ParallelShape",
constraint_iri: "https://uor.foundation/conformance/ParallelShape",
property_iri: "https://uor.foundation/conformance/disjointness_witness",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(ParallelDeclaration {
shape_iri: "https://uor.foundation/conformance/ParallelShape",
}))
}
pub const fn validate_const(
&self,
) -> Result<Validated<ParallelDeclaration, CompileTime>, ShapeViolation> {
if self.site_partition.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/ParallelShape",
constraint_iri: "https://uor.foundation/conformance/ParallelShape",
property_iri: "https://uor.foundation/conformance/site_partition",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.disjointness_witness.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/ParallelShape",
constraint_iri: "https://uor.foundation/conformance/ParallelShape",
property_iri: "https://uor.foundation/conformance/disjointness_witness",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(ParallelDeclaration {
shape_iri: "https://uor.foundation/conformance/ParallelShape",
}))
}
}
impl<'a> Default for ParallelDeclarationBuilder<'a> {
fn default() -> Self {
Self::new()
}
}
impl<'a> ParallelDeclarationBuilder<'a> {
#[inline]
#[must_use]
pub const fn site_partition_len(&self) -> usize {
match self.site_partition {
Some(p) => p.len(),
None => 0,
}
}
#[inline]
#[must_use]
pub const fn site_partition_slice_const(&self) -> &'a [u32] {
match self.site_partition {
Some(p) => p,
None => &[],
}
}
#[inline]
#[must_use]
pub const fn disjointness_witness_const(&self) -> &'a str {
match self.disjointness_witness {
Some(s) => s,
None => "",
}
}
}
impl<'a> StreamDeclarationBuilder<'a> {
#[inline]
#[must_use]
pub const fn productivity_bound_const(&self) -> u64 {
match self.productivity_witness {
Some(_) => 1,
None => 0,
}
}
#[inline]
#[must_use]
pub const fn seed_slice_const(&self) -> &'a [Term] {
match self.seed {
Some(t) => t,
None => &[],
}
}
#[inline]
#[must_use]
pub const fn step_slice_const(&self) -> &'a [Term] {
match self.step {
Some(t) => t,
None => &[],
}
}
#[inline]
#[must_use]
pub const fn productivity_witness_const(&self) -> &'a str {
match self.productivity_witness {
Some(s) => s,
None => "",
}
}
}
#[derive(Debug, Clone)]
pub struct WittLevelDeclarationBuilder {
bit_width: Option<u32>,
cycle_size: Option<u128>,
predecessor: Option<WittLevel>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WittLevelDeclaration {
pub bit_width: u32,
pub predecessor: WittLevel,
}
impl WittLevelDeclarationBuilder {
#[must_use]
pub const fn new() -> Self {
Self {
bit_width: None,
cycle_size: None,
predecessor: None,
}
}
#[must_use]
pub const fn bit_width(mut self, w: u32) -> Self {
self.bit_width = Some(w);
self
}
#[must_use]
pub const fn cycle_size(mut self, s: u128) -> Self {
self.cycle_size = Some(s);
self
}
#[must_use]
pub const fn predecessor(mut self, level: WittLevel) -> Self {
self.predecessor = Some(level);
self
}
pub fn validate(self) -> Result<Validated<WittLevelDeclaration>, ShapeViolation> {
let bw = match self.bit_width {
Some(w) => w,
None => {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/WittLevelShape",
constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
property_iri: "https://uor.foundation/conformance/declaredBitWidth",
expected_range: "http://www.w3.org/2001/XMLSchema#positiveInteger",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
})
}
};
let pred = match self.predecessor {
Some(p) => p,
None => {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/WittLevelShape",
constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
property_iri: "https://uor.foundation/conformance/predecessorLevel",
expected_range: "https://uor.foundation/schema/WittLevel",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
})
}
};
Ok(Validated::new(WittLevelDeclaration {
bit_width: bw,
predecessor: pred,
}))
}
pub const fn validate_const(
&self,
) -> Result<Validated<WittLevelDeclaration, CompileTime>, ShapeViolation> {
let bw = match self.bit_width {
Some(w) => w,
None => {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/WittLevelShape",
constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
property_iri: "https://uor.foundation/conformance/declaredBitWidth",
expected_range: "http://www.w3.org/2001/XMLSchema#positiveInteger",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
})
}
};
let pred = match self.predecessor {
Some(p) => p,
None => {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/WittLevelShape",
constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
property_iri: "https://uor.foundation/conformance/predecessorLevel",
expected_range: "https://uor.foundation/schema/WittLevel",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
})
}
};
Ok(Validated::new(WittLevelDeclaration {
bit_width: bw,
predecessor: pred,
}))
}
}
impl Default for WittLevelDeclarationBuilder {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BoundarySession {
crossing_count: u32,
is_idempotent: bool,
}
impl BoundarySession {
#[inline]
#[allow(dead_code)]
pub(crate) const fn new(is_idempotent: bool) -> Self {
Self {
crossing_count: 0,
is_idempotent,
}
}
#[inline]
#[must_use]
pub const fn crossing_count(&self) -> u32 {
self.crossing_count
}
#[inline]
#[must_use]
pub const fn is_idempotent(&self) -> bool {
self.is_idempotent
}
}
#[allow(dead_code)]
pub(crate) fn validate_and_mint_coord(
grounded: GroundedCoord,
shape: &Validated<GroundingDeclaration>,
session: &mut BoundarySession,
) -> Result<Datum, ShapeViolation> {
let _ = shape; session.crossing_count += 1;
let inner = match grounded.inner {
GroundedCoordInner::W8(b) => DatumInner::W8(b),
GroundedCoordInner::W16(b) => DatumInner::W16(b),
GroundedCoordInner::W24(b) => DatumInner::W24(b),
GroundedCoordInner::W32(b) => DatumInner::W32(b),
GroundedCoordInner::W40(b) => DatumInner::W40(b),
GroundedCoordInner::W48(b) => DatumInner::W48(b),
GroundedCoordInner::W56(b) => DatumInner::W56(b),
GroundedCoordInner::W64(b) => DatumInner::W64(b),
GroundedCoordInner::W72(b) => DatumInner::W72(b),
GroundedCoordInner::W80(b) => DatumInner::W80(b),
GroundedCoordInner::W88(b) => DatumInner::W88(b),
GroundedCoordInner::W96(b) => DatumInner::W96(b),
GroundedCoordInner::W104(b) => DatumInner::W104(b),
GroundedCoordInner::W112(b) => DatumInner::W112(b),
GroundedCoordInner::W120(b) => DatumInner::W120(b),
GroundedCoordInner::W128(b) => DatumInner::W128(b),
};
Ok(Datum { inner })
}
#[allow(dead_code)]
pub(crate) fn validate_and_mint_tuple<const N: usize>(
grounded: GroundedTuple<N>,
shape: &Validated<GroundingDeclaration>,
session: &mut BoundarySession,
) -> Result<Datum, ShapeViolation> {
if N == 0 {
return Err(ShapeViolation {
shape_iri: shape.inner().shape_iri,
constraint_iri: shape.inner().shape_iri,
property_iri: "https://uor.foundation/conformance/groundingSourceType",
expected_range: "https://uor.foundation/type/TypeDefinition",
min_count: 1,
max_count: 0,
kind: ViolationKind::CardinalityViolation,
});
}
validate_and_mint_coord(grounded.coords[0].clone(), shape, session)
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w8(op: PrimitiveOp, a: u8, b: u8) -> u8 {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::Xor => a ^ b,
PrimitiveOp::And => a & b,
PrimitiveOp::Or => a | b,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w8(op: PrimitiveOp, a: u8) -> u8 {
match op {
PrimitiveOp::Neg => 0u8.wrapping_sub(a),
PrimitiveOp::Bnot => !a,
PrimitiveOp::Succ => a.wrapping_add(1),
PrimitiveOp::Pred => a.wrapping_sub(1),
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w16(op: PrimitiveOp, a: u16, b: u16) -> u16 {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::Xor => a ^ b,
PrimitiveOp::And => a & b,
PrimitiveOp::Or => a | b,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w16(op: PrimitiveOp, a: u16) -> u16 {
match op {
PrimitiveOp::Neg => 0u16.wrapping_sub(a),
PrimitiveOp::Bnot => !a,
PrimitiveOp::Succ => a.wrapping_add(1),
PrimitiveOp::Pred => a.wrapping_sub(1),
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w24(op: PrimitiveOp, a: u32, b: u32) -> u32 {
const MASK: u32 = (u64::MAX >> (64 - 24)) as u32;
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w24(op: PrimitiveOp, a: u32) -> u32 {
const MASK: u32 = (u64::MAX >> (64 - 24)) as u32;
match op {
PrimitiveOp::Neg => (0u32.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w32(op: PrimitiveOp, a: u32, b: u32) -> u32 {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::Xor => a ^ b,
PrimitiveOp::And => a & b,
PrimitiveOp::Or => a | b,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w32(op: PrimitiveOp, a: u32) -> u32 {
match op {
PrimitiveOp::Neg => 0u32.wrapping_sub(a),
PrimitiveOp::Bnot => !a,
PrimitiveOp::Succ => a.wrapping_add(1),
PrimitiveOp::Pred => a.wrapping_sub(1),
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w40(op: PrimitiveOp, a: u64, b: u64) -> u64 {
const MASK: u64 = u64::MAX >> (64 - 40);
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w40(op: PrimitiveOp, a: u64) -> u64 {
const MASK: u64 = u64::MAX >> (64 - 40);
match op {
PrimitiveOp::Neg => (0u64.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w48(op: PrimitiveOp, a: u64, b: u64) -> u64 {
const MASK: u64 = u64::MAX >> (64 - 48);
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w48(op: PrimitiveOp, a: u64) -> u64 {
const MASK: u64 = u64::MAX >> (64 - 48);
match op {
PrimitiveOp::Neg => (0u64.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w56(op: PrimitiveOp, a: u64, b: u64) -> u64 {
const MASK: u64 = u64::MAX >> (64 - 56);
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w56(op: PrimitiveOp, a: u64) -> u64 {
const MASK: u64 = u64::MAX >> (64 - 56);
match op {
PrimitiveOp::Neg => (0u64.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w64(op: PrimitiveOp, a: u64, b: u64) -> u64 {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::Xor => a ^ b,
PrimitiveOp::And => a & b,
PrimitiveOp::Or => a | b,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w64(op: PrimitiveOp, a: u64) -> u64 {
match op {
PrimitiveOp::Neg => 0u64.wrapping_sub(a),
PrimitiveOp::Bnot => !a,
PrimitiveOp::Succ => a.wrapping_add(1),
PrimitiveOp::Pred => a.wrapping_sub(1),
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w72(op: PrimitiveOp, a: u128, b: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 72);
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w72(op: PrimitiveOp, a: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 72);
match op {
PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w80(op: PrimitiveOp, a: u128, b: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 80);
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w80(op: PrimitiveOp, a: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 80);
match op {
PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w88(op: PrimitiveOp, a: u128, b: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 88);
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w88(op: PrimitiveOp, a: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 88);
match op {
PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w96(op: PrimitiveOp, a: u128, b: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 96);
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w96(op: PrimitiveOp, a: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 96);
match op {
PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w104(op: PrimitiveOp, a: u128, b: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 104);
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w104(op: PrimitiveOp, a: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 104);
match op {
PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w112(op: PrimitiveOp, a: u128, b: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 112);
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w112(op: PrimitiveOp, a: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 112);
match op {
PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w120(op: PrimitiveOp, a: u128, b: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 120);
match op {
PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
PrimitiveOp::Xor => (a ^ b) & MASK,
PrimitiveOp::And => (a & b) & MASK,
PrimitiveOp::Or => (a | b) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w120(op: PrimitiveOp, a: u128) -> u128 {
const MASK: u128 = u128::MAX >> (128 - 120);
match op {
PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
PrimitiveOp::Bnot => (!a) & MASK,
PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w128(op: PrimitiveOp, a: u128, b: u128) -> u128 {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::Xor => a ^ b,
PrimitiveOp::And => a & b,
PrimitiveOp::Or => a | b,
_ => 0,
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_unary_w128(op: PrimitiveOp, a: u128) -> u128 {
match op {
PrimitiveOp::Neg => 0u128.wrapping_sub(a),
PrimitiveOp::Bnot => !a,
PrimitiveOp::Succ => a.wrapping_add(1),
PrimitiveOp::Pred => a.wrapping_sub(1),
_ => 0,
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Limbs<const N: usize> {
words: [u64; N],
_sealed: (),
}
impl<const N: usize> Limbs<N> {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn from_words(words: [u64; N]) -> Self {
Self { words, _sealed: () }
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn zero() -> Self {
Self {
words: [0u64; N],
_sealed: (),
}
}
#[inline]
#[must_use]
pub const fn words(&self) -> &[u64; N] {
&self.words
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn wrapping_add(self, other: Self) -> Self {
let mut out = [0u64; N];
let mut carry: u64 = 0;
let mut i = 0;
while i < N {
let (s1, c1) = self.words[i].overflowing_add(other.words[i]);
let (s2, c2) = s1.overflowing_add(carry);
out[i] = s2;
carry = (c1 as u64) | (c2 as u64);
i += 1;
}
Self {
words: out,
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn wrapping_sub(self, other: Self) -> Self {
let mut out = [0u64; N];
let mut borrow: u64 = 0;
let mut i = 0;
while i < N {
let (d1, b1) = self.words[i].overflowing_sub(other.words[i]);
let (d2, b2) = d1.overflowing_sub(borrow);
out[i] = d2;
borrow = (b1 as u64) | (b2 as u64);
i += 1;
}
Self {
words: out,
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn wrapping_mul(self, other: Self) -> Self {
let mut out = [0u64; N];
let mut i = 0;
while i < N {
let mut carry: u128 = 0;
let mut j = 0;
while j < N - i {
let prod = (self.words[i] as u128) * (other.words[j] as u128)
+ (out[i + j] as u128)
+ carry;
out[i + j] = prod as u64;
carry = prod >> 64;
j += 1;
}
i += 1;
}
Self {
words: out,
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn xor(self, other: Self) -> Self {
let mut out = [0u64; N];
let mut i = 0;
while i < N {
out[i] = self.words[i] ^ other.words[i];
i += 1;
}
Self {
words: out,
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn and(self, other: Self) -> Self {
let mut out = [0u64; N];
let mut i = 0;
while i < N {
out[i] = self.words[i] & other.words[i];
i += 1;
}
Self {
words: out,
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn or(self, other: Self) -> Self {
let mut out = [0u64; N];
let mut i = 0;
while i < N {
out[i] = self.words[i] | other.words[i];
i += 1;
}
Self {
words: out,
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn not(self) -> Self {
let mut out = [0u64; N];
let mut i = 0;
while i < N {
out[i] = !self.words[i];
i += 1;
}
Self {
words: out,
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn mask_high_bits(self, bits: u32) -> Self {
let mut out = self.words;
let high_word_idx = (bits / 64) as usize;
let low_bits_in_high_word = bits % 64;
if low_bits_in_high_word != 0 && high_word_idx < N {
let mask = (1u64 << low_bits_in_high_word) - 1;
out[high_word_idx] &= mask;
let mut i = high_word_idx + 1;
while i < N {
out[i] = 0;
i += 1;
}
} else if low_bits_in_high_word == 0 && high_word_idx < N {
let mut i = high_word_idx;
while i < N {
out[i] = 0;
i += 1;
}
}
Self {
words: out,
_sealed: (),
}
}
}
pub trait OntologyTarget: ontology_target_sealed::Sealed {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GroundingCertificate {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
}
impl GroundingCertificate {
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct LiftChainCertificate {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
}
impl LiftChainCertificate {
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct InhabitanceCertificate {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
}
impl InhabitanceCertificate {
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CompletenessCertificate {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
}
impl CompletenessCertificate {
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MultiplicationCertificate {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
}
impl MultiplicationCertificate {
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PartitionCertificate {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
}
impl PartitionCertificate {
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GenericImpossibilityWitness {
identity: Option<&'static str>,
}
impl Default for GenericImpossibilityWitness {
#[inline]
fn default() -> Self {
Self { identity: None }
}
}
impl GenericImpossibilityWitness {
#[inline]
#[must_use]
pub const fn for_identity(identity: &'static str) -> Self {
Self {
identity: Some(identity),
}
}
#[inline]
#[must_use]
pub const fn identity(&self) -> Option<&'static str> {
self.identity
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct InhabitanceImpossibilityWitness {
_private: (),
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ConstrainedTypeInput {
_private: (),
}
impl core::fmt::Display for GenericImpossibilityWitness {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self.identity {
Some(iri) => write!(f, "GenericImpossibilityWitness({iri})"),
None => f.write_str("GenericImpossibilityWitness"),
}
}
}
impl core::error::Error for GenericImpossibilityWitness {}
impl core::fmt::Display for InhabitanceImpossibilityWitness {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("InhabitanceImpossibilityWitness")
}
}
impl core::error::Error for InhabitanceImpossibilityWitness {}
impl LiftChainCertificate {
#[inline]
#[must_use]
pub const fn target_level(&self) -> WittLevel {
WittLevel::new(self.witt_bits as u32)
}
}
impl InhabitanceCertificate {
#[inline]
#[must_use]
pub const fn witness(&self) -> Option<&'static [u8]> {
None
}
}
pub(crate) mod ontology_target_sealed {
pub trait Sealed {}
impl Sealed for super::GroundingCertificate {}
impl Sealed for super::LiftChainCertificate {}
impl Sealed for super::InhabitanceCertificate {}
impl Sealed for super::CompletenessCertificate {}
impl Sealed for super::MultiplicationCertificate {}
impl Sealed for super::PartitionCertificate {}
impl Sealed for super::GenericImpossibilityWitness {}
impl Sealed for super::InhabitanceImpossibilityWitness {}
impl Sealed for super::ConstrainedTypeInput {}
impl Sealed for super::PartitionProductWitness {}
impl Sealed for super::PartitionCoproductWitness {}
impl Sealed for super::CartesianProductWitness {}
impl Sealed for super::CompileUnit<'_> {}
}
impl OntologyTarget for GroundingCertificate {}
impl OntologyTarget for LiftChainCertificate {}
impl OntologyTarget for InhabitanceCertificate {}
impl OntologyTarget for CompletenessCertificate {}
impl OntologyTarget for MultiplicationCertificate {}
impl OntologyTarget for PartitionCertificate {}
impl OntologyTarget for GenericImpossibilityWitness {}
impl OntologyTarget for InhabitanceImpossibilityWitness {}
impl OntologyTarget for ConstrainedTypeInput {}
impl OntologyTarget for PartitionProductWitness {}
impl OntologyTarget for PartitionCoproductWitness {}
impl OntologyTarget for CartesianProductWitness {}
impl OntologyTarget for CompileUnit<'_> {}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CompletenessAuditTrail {
_private: (),
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ChainAuditTrail {
_private: (),
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GeodesicEvidenceBundle {
_private: (),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TransformCertificate {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
_private: (),
}
impl TransformCertificate {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
_private: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
witt_bits: 0,
content_fingerprint: ContentFingerprint::zero(),
_private: (),
}
}
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct IsometryCertificate {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
_private: (),
}
impl IsometryCertificate {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
_private: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
witt_bits: 0,
content_fingerprint: ContentFingerprint::zero(),
_private: (),
}
}
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct InvolutionCertificate {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
_private: (),
}
impl InvolutionCertificate {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
_private: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
witt_bits: 0,
content_fingerprint: ContentFingerprint::zero(),
_private: (),
}
}
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GeodesicCertificate {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
_private: (),
}
impl GeodesicCertificate {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
_private: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
witt_bits: 0,
content_fingerprint: ContentFingerprint::zero(),
_private: (),
}
}
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MeasurementCertificate {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
_private: (),
}
impl MeasurementCertificate {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
_private: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
witt_bits: 0,
content_fingerprint: ContentFingerprint::zero(),
_private: (),
}
}
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BornRuleVerification {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
_private: (),
}
impl BornRuleVerification {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn with_level_and_fingerprint_const(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
witt_bits,
content_fingerprint,
_private: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn empty_const() -> Self {
Self {
witt_bits: 0,
content_fingerprint: ContentFingerprint::zero(),
_private: (),
}
}
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
}
pub trait Certificate: certificate_sealed::Sealed {
const IRI: &'static str;
type Evidence;
}
pub(crate) mod certificate_sealed {
pub trait Sealed {}
impl Sealed for super::GroundingCertificate {}
impl Sealed for super::LiftChainCertificate {}
impl Sealed for super::InhabitanceCertificate {}
impl Sealed for super::CompletenessCertificate {}
impl Sealed for super::TransformCertificate {}
impl Sealed for super::IsometryCertificate {}
impl Sealed for super::InvolutionCertificate {}
impl Sealed for super::GeodesicCertificate {}
impl Sealed for super::MeasurementCertificate {}
impl Sealed for super::BornRuleVerification {}
impl Sealed for super::MultiplicationCertificate {}
impl Sealed for super::PartitionCertificate {}
impl Sealed for super::GenericImpossibilityWitness {}
impl Sealed for super::InhabitanceImpossibilityWitness {}
impl Sealed for super::PartitionProductWitness {}
impl Sealed for super::PartitionCoproductWitness {}
impl Sealed for super::CartesianProductWitness {}
}
impl Certificate for GroundingCertificate {
const IRI: &'static str = "https://uor.foundation/cert/GroundingCertificate";
type Evidence = ();
}
impl Certificate for LiftChainCertificate {
const IRI: &'static str = "https://uor.foundation/cert/LiftChainCertificate";
type Evidence = ChainAuditTrail;
}
impl Certificate for InhabitanceCertificate {
const IRI: &'static str = "https://uor.foundation/cert/InhabitanceCertificate";
type Evidence = ();
}
impl Certificate for CompletenessCertificate {
const IRI: &'static str = "https://uor.foundation/cert/CompletenessCertificate";
type Evidence = CompletenessAuditTrail;
}
impl Certificate for TransformCertificate {
const IRI: &'static str = "https://uor.foundation/cert/TransformCertificate";
type Evidence = ();
}
impl Certificate for IsometryCertificate {
const IRI: &'static str = "https://uor.foundation/cert/IsometryCertificate";
type Evidence = ();
}
impl Certificate for InvolutionCertificate {
const IRI: &'static str = "https://uor.foundation/cert/InvolutionCertificate";
type Evidence = ();
}
impl Certificate for GeodesicCertificate {
const IRI: &'static str = "https://uor.foundation/cert/GeodesicCertificate";
type Evidence = GeodesicEvidenceBundle;
}
impl Certificate for MeasurementCertificate {
const IRI: &'static str = "https://uor.foundation/cert/MeasurementCertificate";
type Evidence = ();
}
impl Certificate for BornRuleVerification {
const IRI: &'static str = "https://uor.foundation/cert/BornRuleVerification";
type Evidence = ();
}
impl Certificate for MultiplicationCertificate {
const IRI: &'static str = "https://uor.foundation/cert/MultiplicationCertificate";
type Evidence = MultiplicationEvidence;
}
impl Certificate for PartitionCertificate {
const IRI: &'static str = "https://uor.foundation/cert/PartitionCertificate";
type Evidence = ();
}
impl Certificate for GenericImpossibilityWitness {
const IRI: &'static str = "https://uor.foundation/cert/GenericImpossibilityCertificate";
type Evidence = ();
}
impl Certificate for InhabitanceImpossibilityWitness {
const IRI: &'static str = "https://uor.foundation/cert/InhabitanceImpossibilityCertificate";
type Evidence = ();
}
pub(crate) mod certify_const_mint {
use super::{Certificate, ContentFingerprint};
pub trait MintWithLevelFingerprint: Certificate {
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self;
}
impl MintWithLevelFingerprint for super::GroundingCertificate {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::GroundingCertificate::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
impl MintWithLevelFingerprint for super::LiftChainCertificate {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::LiftChainCertificate::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
impl MintWithLevelFingerprint for super::InhabitanceCertificate {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::InhabitanceCertificate::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
impl MintWithLevelFingerprint for super::CompletenessCertificate {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::CompletenessCertificate::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
impl MintWithLevelFingerprint for super::MultiplicationCertificate {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::MultiplicationCertificate::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
impl MintWithLevelFingerprint for super::PartitionCertificate {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::PartitionCertificate::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
impl MintWithLevelFingerprint for super::TransformCertificate {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::TransformCertificate::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
impl MintWithLevelFingerprint for super::IsometryCertificate {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::IsometryCertificate::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
impl MintWithLevelFingerprint for super::InvolutionCertificate {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::InvolutionCertificate::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
impl MintWithLevelFingerprint for super::GeodesicCertificate {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::GeodesicCertificate::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
impl MintWithLevelFingerprint for super::MeasurementCertificate {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::MeasurementCertificate::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
impl MintWithLevelFingerprint for super::BornRuleVerification {
#[inline]
fn mint_with_level_fingerprint(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
super::BornRuleVerification::with_level_and_fingerprint_const(
witt_bits,
content_fingerprint,
)
}
}
}
#[derive(Debug, Clone)]
pub struct Certified<C: Certificate> {
inner: C,
uor_time: UorTime,
_private: (),
}
impl<C: Certificate> Certified<C> {
#[inline]
#[must_use]
pub const fn certificate(&self) -> &C {
&self.inner
}
#[inline]
#[must_use]
pub const fn iri(&self) -> &'static str {
C::IRI
}
#[inline]
#[must_use]
pub const fn uor_time(&self) -> UorTime {
self.uor_time
}
#[inline]
#[allow(dead_code)]
pub(crate) const fn new(inner: C) -> Self {
let steps = C::IRI.len() as u64;
let landauer = LandauerBudget::new((steps as f64) * core::f64::consts::LN_2);
let uor_time = UorTime::new(landauer, steps);
Self {
inner,
uor_time,
_private: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MulContext {
pub stack_budget_bytes: u64,
pub const_eval: bool,
pub limb_count: usize,
}
impl MulContext {
#[inline]
#[must_use]
pub const fn new(stack_budget_bytes: u64, const_eval: bool, limb_count: usize) -> Self {
Self {
stack_budget_bytes,
const_eval,
limb_count,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct MultiplicationEvidence {
splitting_factor: u32,
sub_multiplication_count: u32,
landauer_cost_nats_bits: u64,
}
impl MultiplicationEvidence {
#[inline]
#[must_use]
pub const fn splitting_factor(&self) -> u32 {
self.splitting_factor
}
#[inline]
#[must_use]
pub const fn sub_multiplication_count(&self) -> u32 {
self.sub_multiplication_count
}
#[inline]
#[must_use]
pub const fn landauer_cost_nats_bits(&self) -> u64 {
self.landauer_cost_nats_bits
}
}
impl MultiplicationCertificate {
#[inline]
#[must_use]
pub(crate) fn with_evidence(
splitting_factor: u32,
sub_multiplication_count: u32,
landauer_cost_nats_bits: u64,
content_fingerprint: ContentFingerprint,
) -> Self {
let _ = MultiplicationEvidence {
splitting_factor,
sub_multiplication_count,
landauer_cost_nats_bits,
};
Self::with_level_and_fingerprint_const(32, content_fingerprint)
}
}
pub const MAX_BETTI_DIMENSION: usize = 8;
#[derive(Debug)]
pub struct SigmaValue<H: HostTypes = crate::DefaultHostTypes> {
value: H::Decimal,
_phantom: core::marker::PhantomData<H>,
_sealed: (),
}
impl<H: HostTypes> Copy for SigmaValue<H> {}
impl<H: HostTypes> Clone for SigmaValue<H> {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl<H: HostTypes> PartialEq for SigmaValue<H> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.value == other.value
}
}
impl<H: HostTypes> SigmaValue<H> {
#[inline]
#[must_use]
pub const fn value(&self) -> H::Decimal {
self.value
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new_unchecked(value: H::Decimal) -> Self {
Self {
value,
_phantom: core::marker::PhantomData,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Stratum<L> {
value: u32,
_level: PhantomData<L>,
_sealed: (),
}
impl<L> Stratum<L> {
#[inline]
#[must_use]
pub const fn as_u32(&self) -> u32 {
self.value
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(value: u32) -> Self {
Self {
value,
_level: PhantomData,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DDeltaMetric {
value: i64,
_sealed: (),
}
impl DDeltaMetric {
#[inline]
#[must_use]
pub const fn as_i64(&self) -> i64 {
self.value
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(value: i64) -> Self {
Self { value, _sealed: () }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct EulerMetric {
value: i64,
_sealed: (),
}
impl EulerMetric {
#[inline]
#[must_use]
pub const fn as_i64(&self) -> i64 {
self.value
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(value: i64) -> Self {
Self { value, _sealed: () }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ResidualMetric {
value: u32,
_sealed: (),
}
impl ResidualMetric {
#[inline]
#[must_use]
pub const fn as_u32(&self) -> u32 {
self.value
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(value: u32) -> Self {
Self { value, _sealed: () }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BettiMetric {
values: [u32; MAX_BETTI_DIMENSION],
_sealed: (),
}
impl BettiMetric {
#[inline]
#[must_use]
pub const fn as_array(&self) -> &[u32; MAX_BETTI_DIMENSION] {
&self.values
}
#[inline]
#[must_use]
pub const fn beta(&self, k: usize) -> u32 {
if k < MAX_BETTI_DIMENSION {
self.values[k]
} else {
0
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(values: [u32; MAX_BETTI_DIMENSION]) -> Self {
Self {
values,
_sealed: (),
}
}
}
pub const JACOBIAN_MAX_SITES: usize = 8;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct JacobianMetric<L> {
entries: [i64; JACOBIAN_MAX_SITES],
len: u16,
_level: PhantomData<L>,
_sealed: (),
}
impl<L> JacobianMetric<L> {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn zero(len: u16) -> Self {
Self {
entries: [0i64; JACOBIAN_MAX_SITES],
len,
_level: PhantomData,
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn from_entries(entries: [i64; JACOBIAN_MAX_SITES], len: u16) -> Self {
Self {
entries,
len,
_level: PhantomData,
_sealed: (),
}
}
#[inline]
#[must_use]
pub const fn entries(&self) -> &[i64; JACOBIAN_MAX_SITES] {
&self.entries
}
#[inline]
#[must_use]
pub const fn len(&self) -> u16 {
self.len
}
#[inline]
#[must_use]
pub const fn is_empty(&self) -> bool {
self.len == 0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum PartitionComponent {
Irreducible,
Reducible,
Units,
Exterior,
}
mod grounded_shape_sealed {
pub trait Sealed {}
impl Sealed for super::ConstrainedTypeInput {}
}
pub trait GroundedShape: grounded_shape_sealed::Sealed {}
impl GroundedShape for ConstrainedTypeInput {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ContentAddress {
raw: u128,
_sealed: (),
}
impl ContentAddress {
#[inline]
#[must_use]
pub const fn zero() -> Self {
Self {
raw: 0,
_sealed: (),
}
}
#[inline]
#[must_use]
pub const fn as_u128(&self) -> u128 {
self.raw
}
#[inline]
#[must_use]
pub const fn is_zero(&self) -> bool {
self.raw == 0
}
#[inline]
#[must_use]
pub const fn from_u128(raw: u128) -> Self {
Self { raw, _sealed: () }
}
#[inline]
#[must_use]
pub const fn from_u64_fingerprint(fingerprint: u64) -> Self {
Self {
raw: (fingerprint as u128) << 64,
_sealed: (),
}
}
}
impl Default for ContentAddress {
#[inline]
fn default() -> Self {
Self::zero()
}
}
pub const TRACE_REPLAY_FORMAT_VERSION: u16 = 2;
pub trait Hasher<const FP_MAX: usize = 32> {
const OUTPUT_BYTES: usize;
fn initial() -> Self;
#[must_use]
fn fold_byte(self, b: u8) -> Self;
#[inline]
#[must_use]
fn fold_bytes(mut self, bytes: &[u8]) -> Self
where
Self: Sized,
{
let mut i = 0;
while i < bytes.len() {
self = self.fold_byte(bytes[i]);
i += 1;
}
self
}
fn finalize(self) -> [u8; FP_MAX];
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ContentFingerprint<const FP_MAX: usize = 32> {
bytes: [u8; FP_MAX],
width_bytes: u8,
_sealed: (),
}
impl<const FP_MAX: usize> ContentFingerprint<FP_MAX> {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn zero() -> Self {
Self {
bytes: [0u8; FP_MAX],
width_bytes: 0,
_sealed: (),
}
}
#[inline]
#[must_use]
pub const fn is_zero(&self) -> bool {
self.width_bytes == 0
}
#[inline]
#[must_use]
pub const fn width_bytes(&self) -> u8 {
self.width_bytes
}
#[inline]
#[must_use]
pub const fn width_bits(&self) -> u16 {
(self.width_bytes as u16) * 8
}
#[inline]
#[must_use]
pub const fn as_bytes(&self) -> &[u8; FP_MAX] {
&self.bytes
}
#[inline]
#[must_use]
pub const fn from_buffer(bytes: [u8; FP_MAX], width_bytes: u8) -> Self {
Self {
bytes,
width_bytes,
_sealed: (),
}
}
}
impl<const FP_MAX: usize> Default for ContentFingerprint<FP_MAX> {
#[inline]
fn default() -> Self {
Self::zero()
}
}
#[inline]
#[must_use]
pub const fn primitive_op_discriminant(op: crate::PrimitiveOp) -> u8 {
match op {
crate::PrimitiveOp::Neg => 0,
crate::PrimitiveOp::Bnot => 1,
crate::PrimitiveOp::Succ => 2,
crate::PrimitiveOp::Pred => 3,
crate::PrimitiveOp::Add => 4,
crate::PrimitiveOp::Sub => 5,
crate::PrimitiveOp::Mul => 6,
crate::PrimitiveOp::Xor => 7,
crate::PrimitiveOp::And => 8,
crate::PrimitiveOp::Or => 9,
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CertificateKind {
Grounding,
TowerCompleteness,
IncrementalCompleteness,
Inhabitance,
Multiplication,
TwoSat,
HornSat,
ResidualVerdict,
CanonicalForm,
TypeSynthesis,
Homotopy,
Monodromy,
Moduli,
JacobianGuided,
Evaluation,
Session,
Superposition,
Measurement,
WittLevel,
DihedralFactorization,
Completeness,
GeodesicValidator,
}
#[inline]
#[must_use]
pub const fn certificate_kind_discriminant(kind: CertificateKind) -> u8 {
match kind {
CertificateKind::Grounding => 1,
CertificateKind::TowerCompleteness => 2,
CertificateKind::IncrementalCompleteness => 3,
CertificateKind::Inhabitance => 4,
CertificateKind::Multiplication => 5,
CertificateKind::TwoSat => 6,
CertificateKind::HornSat => 7,
CertificateKind::ResidualVerdict => 8,
CertificateKind::CanonicalForm => 9,
CertificateKind::TypeSynthesis => 10,
CertificateKind::Homotopy => 11,
CertificateKind::Monodromy => 12,
CertificateKind::Moduli => 13,
CertificateKind::JacobianGuided => 14,
CertificateKind::Evaluation => 15,
CertificateKind::Session => 16,
CertificateKind::Superposition => 17,
CertificateKind::Measurement => 18,
CertificateKind::WittLevel => 19,
CertificateKind::DihedralFactorization => 20,
CertificateKind::Completeness => 21,
CertificateKind::GeodesicValidator => 22,
}
}
pub fn fold_constraint_ref<H: Hasher>(mut hasher: H, c: &crate::pipeline::ConstraintRef) -> H {
use crate::pipeline::ConstraintRef as C;
match c {
C::Residue { modulus, residue } => {
hasher = hasher.fold_byte(1);
hasher = hasher.fold_bytes(&modulus.to_be_bytes());
hasher = hasher.fold_bytes(&residue.to_be_bytes());
}
C::Hamming { bound } => {
hasher = hasher.fold_byte(2);
hasher = hasher.fold_bytes(&bound.to_be_bytes());
}
C::Depth { min, max } => {
hasher = hasher.fold_byte(3);
hasher = hasher.fold_bytes(&min.to_be_bytes());
hasher = hasher.fold_bytes(&max.to_be_bytes());
}
C::Carry { site } => {
hasher = hasher.fold_byte(4);
hasher = hasher.fold_bytes(&site.to_be_bytes());
}
C::Site { position } => {
hasher = hasher.fold_byte(5);
hasher = hasher.fold_bytes(&position.to_be_bytes());
}
C::Affine {
coefficients,
coefficient_count,
bias,
} => {
hasher = hasher.fold_byte(6);
hasher = hasher.fold_bytes(&coefficient_count.to_be_bytes());
let count = *coefficient_count as usize;
let mut i = 0;
while i < count && i < crate::pipeline::AFFINE_MAX_COEFFS {
hasher = hasher.fold_bytes(&coefficients[i].to_be_bytes());
i += 1;
}
hasher = hasher.fold_bytes(&bias.to_be_bytes());
}
C::SatClauses { clauses, num_vars } => {
hasher = hasher.fold_byte(7);
hasher = hasher.fold_bytes(&num_vars.to_be_bytes());
hasher = hasher.fold_bytes(&(clauses.len() as u32).to_be_bytes());
let mut i = 0;
while i < clauses.len() {
let clause = clauses[i];
hasher = hasher.fold_bytes(&(clause.len() as u32).to_be_bytes());
let mut j = 0;
while j < clause.len() {
let (var, neg) = clause[j];
hasher = hasher.fold_bytes(&var.to_be_bytes());
hasher = hasher.fold_byte(if neg { 1 } else { 0 });
j += 1;
}
i += 1;
}
}
C::Bound {
observable_iri,
bound_shape_iri,
args_repr,
} => {
hasher = hasher.fold_byte(8);
hasher = hasher.fold_bytes(observable_iri.as_bytes());
hasher = hasher.fold_byte(0);
hasher = hasher.fold_bytes(bound_shape_iri.as_bytes());
hasher = hasher.fold_byte(0);
hasher = hasher.fold_bytes(args_repr.as_bytes());
hasher = hasher.fold_byte(0);
}
C::Conjunction {
conjuncts,
conjunct_count,
} => {
hasher = hasher.fold_byte(9);
hasher = hasher.fold_bytes(&conjunct_count.to_be_bytes());
let count = *conjunct_count as usize;
let mut i = 0;
while i < count && i < crate::pipeline::CONJUNCTION_MAX_TERMS {
let lifted = conjuncts[i].into_constraint();
hasher = fold_constraint_ref(hasher, &lifted);
i += 1;
}
}
}
hasher
}
pub fn fold_unit_digest<H: Hasher>(
mut hasher: H,
level_bits: u16,
budget: u64,
iri: &str,
site_count: usize,
constraints: &[crate::pipeline::ConstraintRef],
kind: CertificateKind,
) -> H {
hasher = hasher.fold_bytes(&level_bits.to_be_bytes());
hasher = hasher.fold_bytes(&budget.to_be_bytes());
hasher = hasher.fold_bytes(iri.as_bytes());
hasher = hasher.fold_byte(0);
hasher = hasher.fold_bytes(&(site_count as u64).to_be_bytes());
let mut i = 0;
while i < constraints.len() {
hasher = fold_constraint_ref(hasher, &constraints[i]);
i += 1;
}
hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
hasher
}
pub fn fold_parallel_digest<H: Hasher>(
mut hasher: H,
decl_site_count: u64,
iri: &str,
type_site_count: usize,
constraints: &[crate::pipeline::ConstraintRef],
kind: CertificateKind,
) -> H {
hasher = hasher.fold_bytes(&decl_site_count.to_be_bytes());
hasher = hasher.fold_bytes(iri.as_bytes());
hasher = hasher.fold_byte(0);
hasher = hasher.fold_bytes(&(type_site_count as u64).to_be_bytes());
let mut i = 0;
while i < constraints.len() {
hasher = fold_constraint_ref(hasher, &constraints[i]);
i += 1;
}
hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
hasher
}
pub fn fold_stream_digest<H: Hasher>(
mut hasher: H,
productivity_bound: u64,
iri: &str,
constraints: &[crate::pipeline::ConstraintRef],
kind: CertificateKind,
) -> H {
hasher = hasher.fold_bytes(&productivity_bound.to_be_bytes());
hasher = hasher.fold_bytes(iri.as_bytes());
hasher = hasher.fold_byte(0);
let mut i = 0;
while i < constraints.len() {
hasher = fold_constraint_ref(hasher, &constraints[i]);
i += 1;
}
hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
hasher
}
pub fn fold_interaction_digest<H: Hasher>(
mut hasher: H,
convergence_seed: u64,
iri: &str,
constraints: &[crate::pipeline::ConstraintRef],
kind: CertificateKind,
) -> H {
hasher = hasher.fold_bytes(&convergence_seed.to_be_bytes());
hasher = hasher.fold_bytes(iri.as_bytes());
hasher = hasher.fold_byte(0);
let mut i = 0;
while i < constraints.len() {
hasher = fold_constraint_ref(hasher, &constraints[i]);
i += 1;
}
hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
hasher
}
pub(crate) fn primitive_terminal_reduction<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
witt_bits: u16,
) -> Result<(u16, u32, u8), PipelineFailure> {
let outcome = crate::pipeline::run_reduction_stages::<T>(witt_bits)?;
let satisfiable_bit: u8 = if outcome.satisfiable { 1 } else { 0 };
Ok((
outcome.witt_bits,
T::CONSTRAINTS.len() as u32,
satisfiable_bit,
))
}
pub(crate) fn fold_terminal_reduction<H: Hasher>(
mut hasher: H,
witt_bits: u16,
constraint_count: u32,
satisfiable_bit: u8,
) -> H {
hasher = hasher.fold_bytes(&witt_bits.to_be_bytes());
hasher = hasher.fold_bytes(&constraint_count.to_be_bytes());
hasher = hasher.fold_byte(satisfiable_bit);
hasher
}
pub fn primitive_simplicial_nerve_betti<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
) -> Result<[u32; MAX_BETTI_DIMENSION], GenericImpossibilityWitness> {
let k_all = T::CONSTRAINTS.len();
if k_all > NERVE_CONSTRAINTS_CAP {
return Err(GenericImpossibilityWitness::for_identity(
"NERVE_CAPACITY_EXCEEDED",
));
}
let s_all = T::SITE_COUNT;
if s_all > NERVE_SITES_CAP {
return Err(GenericImpossibilityWitness::for_identity(
"NERVE_CAPACITY_EXCEEDED",
));
}
let n_constraints = k_all;
let n_sites = s_all;
let mut out = [0u32; MAX_BETTI_DIMENSION];
if n_constraints == 0 {
out[0] = 1;
return Ok(out);
}
let mut support = [0u16; NERVE_CONSTRAINTS_CAP];
let mut c = 0;
while c < n_constraints {
support[c] = constraint_site_support_mask::<T>(c, n_sites);
c += 1;
}
let mut c1_pairs_lo = [0u8; NERVE_C1_MAX];
let mut c1_pairs_hi = [0u8; NERVE_C1_MAX];
let mut n_c1: usize = 0;
let mut i = 0;
while i < n_constraints {
let mut j = i + 1;
while j < n_constraints {
if (support[i] & support[j]) != 0 && n_c1 < NERVE_C1_MAX {
c1_pairs_lo[n_c1] = i as u8;
c1_pairs_hi[n_c1] = j as u8;
n_c1 += 1;
}
j += 1;
}
i += 1;
}
let mut c2_i = [0u8; NERVE_C2_MAX];
let mut c2_j = [0u8; NERVE_C2_MAX];
let mut c2_k = [0u8; NERVE_C2_MAX];
let mut n_c2: usize = 0;
let mut i2 = 0;
while i2 < n_constraints {
let mut j2 = i2 + 1;
while j2 < n_constraints {
let mut k2 = j2 + 1;
while k2 < n_constraints {
if (support[i2] & support[j2] & support[k2]) != 0 && n_c2 < NERVE_C2_MAX {
c2_i[n_c2] = i2 as u8;
c2_j[n_c2] = j2 as u8;
c2_k[n_c2] = k2 as u8;
n_c2 += 1;
}
k2 += 1;
}
j2 += 1;
}
i2 += 1;
}
let mut partial_1 = [[0i64; NERVE_C1_MAX]; NERVE_CONSTRAINTS_CAP];
let mut e = 0;
while e < n_c1 {
let lo = c1_pairs_lo[e] as usize;
let hi = c1_pairs_hi[e] as usize;
partial_1[lo][e] = NERVE_RANK_MOD_P - 1; partial_1[hi][e] = 1;
e += 1;
}
let rank_1 = integer_matrix_rank::<NERVE_CONSTRAINTS_CAP, NERVE_C1_MAX>(
&mut partial_1,
n_constraints,
n_c1,
);
let mut partial_2 = [[0i64; NERVE_C2_MAX]; NERVE_C1_MAX];
let mut t = 0;
while t < n_c2 {
let ti = c2_i[t];
let tj = c2_j[t];
let tk = c2_k[t];
let idx_jk = find_pair_index(&c1_pairs_lo, &c1_pairs_hi, n_c1, tj, tk);
let idx_ik = find_pair_index(&c1_pairs_lo, &c1_pairs_hi, n_c1, ti, tk);
let idx_ij = find_pair_index(&c1_pairs_lo, &c1_pairs_hi, n_c1, ti, tj);
if idx_jk < NERVE_C1_MAX {
partial_2[idx_jk][t] = 1;
}
if idx_ik < NERVE_C1_MAX {
partial_2[idx_ik][t] = NERVE_RANK_MOD_P - 1;
}
if idx_ij < NERVE_C1_MAX {
partial_2[idx_ij][t] = 1;
}
t += 1;
}
let rank_2 = integer_matrix_rank::<NERVE_C1_MAX, NERVE_C2_MAX>(&mut partial_2, n_c1, n_c2);
let b0 = (n_constraints - rank_1) as u32;
let cycles_1 = n_c1.saturating_sub(rank_1);
let b1 = cycles_1.saturating_sub(rank_2) as u32;
let b2 = n_c2.saturating_sub(rank_2) as u32;
out[0] = if b0 == 0 { 1 } else { b0 };
if MAX_BETTI_DIMENSION > 1 {
out[1] = b1;
}
if MAX_BETTI_DIMENSION > 2 {
out[2] = b2;
}
Ok(out)
}
pub const NERVE_CONSTRAINTS_CAP: usize = 8;
pub const NERVE_SITES_CAP: usize = 8;
pub const NERVE_C1_MAX: usize = 28;
pub const NERVE_C2_MAX: usize = 56;
pub(crate) const NERVE_RANK_MOD_P: i64 = 1_000_000_007;
pub(crate) const fn constraint_site_support_mask<
T: crate::pipeline::ConstrainedTypeShape + ?Sized,
>(
c: usize,
n_sites: usize,
) -> u16 {
let all_mask: u16 = if n_sites == 0 {
0
} else {
(1u16 << n_sites) - 1
};
match &T::CONSTRAINTS[c] {
crate::pipeline::ConstraintRef::Site { position } => {
if n_sites == 0 {
0
} else {
1u16 << (*position as usize % n_sites)
}
}
crate::pipeline::ConstraintRef::Carry { site } => {
if n_sites == 0 {
0
} else {
1u16 << (*site as usize % n_sites)
}
}
crate::pipeline::ConstraintRef::Affine {
coefficients,
coefficient_count,
..
} => {
if n_sites == 0 {
0
} else {
let mut mask: u16 = 0;
let count = *coefficient_count as usize;
let mut i = 0;
while i < count && i < crate::pipeline::AFFINE_MAX_COEFFS && i < n_sites {
if coefficients[i] != 0 {
mask |= 1u16 << i;
}
i += 1;
}
if mask == 0 {
all_mask
} else {
mask
}
}
}
_ => all_mask,
}
}
pub(crate) const fn find_pair_index(
lo_arr: &[u8; NERVE_C1_MAX],
hi_arr: &[u8; NERVE_C1_MAX],
n_c1: usize,
lo: u8,
hi: u8,
) -> usize {
let mut i = 0;
while i < n_c1 {
if lo_arr[i] == lo && hi_arr[i] == hi {
return i;
}
i += 1;
}
NERVE_C1_MAX
}
pub(crate) const fn integer_matrix_rank<const R: usize, const C: usize>(
matrix: &mut [[i64; C]; R],
rows: usize,
cols: usize,
) -> usize {
let p = NERVE_RANK_MOD_P;
let mut r = 0;
while r < rows {
let mut c = 0;
while c < cols {
let v = matrix[r][c] % p;
matrix[r][c] = if v < 0 { v + p } else { v };
c += 1;
}
r += 1;
}
let mut rank: usize = 0;
let mut col: usize = 0;
while col < cols && rank < rows {
let mut pivot_row = rank;
while pivot_row < rows && matrix[pivot_row][col] == 0 {
pivot_row += 1;
}
if pivot_row == rows {
col += 1;
continue;
}
if pivot_row != rank {
let mut k = 0;
while k < cols {
let tmp = matrix[rank][k];
matrix[rank][k] = matrix[pivot_row][k];
matrix[pivot_row][k] = tmp;
k += 1;
}
}
let pivot = matrix[rank][col];
let pivot_inv = mod_pow(pivot, p - 2, p);
let mut k = 0;
while k < cols {
matrix[rank][k] = (matrix[rank][k] * pivot_inv) % p;
k += 1;
}
let mut r2 = 0;
while r2 < rows {
if r2 != rank {
let factor = matrix[r2][col];
if factor != 0 {
let mut kk = 0;
while kk < cols {
let sub = (matrix[rank][kk] * factor) % p;
let mut v = matrix[r2][kk] - sub;
v %= p;
if v < 0 {
v += p;
}
matrix[r2][kk] = v;
kk += 1;
}
}
}
r2 += 1;
}
rank += 1;
col += 1;
}
rank
}
pub(crate) const fn mod_pow(base: i64, exp: i64, p: i64) -> i64 {
let mut result: i64 = 1;
let mut b = ((base % p) + p) % p;
let mut e = exp;
while e > 0 {
if e & 1 == 1 {
result = (result * b) % p;
}
b = (b * b) % p;
e >>= 1;
}
result
}
pub(crate) fn fold_betti_tuple<H: Hasher>(mut hasher: H, betti: &[u32; MAX_BETTI_DIMENSION]) -> H {
let mut i = 0;
while i < MAX_BETTI_DIMENSION {
hasher = hasher.fold_bytes(&betti[i].to_be_bytes());
i += 1;
}
hasher
}
#[must_use]
pub(crate) fn primitive_euler_characteristic(betti: &[u32; MAX_BETTI_DIMENSION]) -> i64 {
let mut chi: i64 = 0;
let mut k = 0;
while k < MAX_BETTI_DIMENSION {
let term = betti[k] as i64;
if k % 2 == 0 {
chi += term;
} else {
chi -= term;
}
k += 1;
}
chi
}
pub(crate) fn primitive_dihedral_signature<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
) -> (u32, u32) {
let n = T::SITE_COUNT as u32;
let orbit_size = if n < 2 {
if n == 0 {
1
} else {
2
}
} else {
2 * n
};
let mut rep: u32 = 0;
let mut k = 1u32;
while k < n {
let rot = k % n;
let refl = (n - k) % n;
if rot < rep {
rep = rot;
}
if refl < rep {
rep = refl;
}
k += 1;
}
(orbit_size, rep)
}
pub(crate) fn fold_dihedral_signature<H: Hasher>(
mut hasher: H,
orbit_size: u32,
representative: u32,
) -> H {
hasher = hasher.fold_bytes(&orbit_size.to_be_bytes());
hasher = hasher.fold_bytes(&representative.to_be_bytes());
hasher
}
pub(crate) fn primitive_curvature_jacobian<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
) -> [i32; JACOBIAN_MAX_SITES] {
let mut out = [0i32; JACOBIAN_MAX_SITES];
let mut ci = 0;
while ci < T::CONSTRAINTS.len() {
if let crate::pipeline::ConstraintRef::Site { position } = T::CONSTRAINTS[ci] {
let idx = (position as usize) % JACOBIAN_MAX_SITES;
out[idx] = out[idx].saturating_add(1);
}
ci += 1;
}
let total = T::CONSTRAINTS.len() as i32;
out[0] = out[0].saturating_add(total);
out
}
#[must_use]
pub(crate) fn primitive_dc10_select(jac: &[i32; JACOBIAN_MAX_SITES]) -> usize {
let mut best_idx: usize = 0;
let mut best_abs: i32 = jac[0].unsigned_abs() as i32;
let mut i = 1;
while i < JACOBIAN_MAX_SITES {
let a = jac[i].unsigned_abs() as i32;
if a > best_abs {
best_abs = a;
best_idx = i;
}
i += 1;
}
best_idx
}
pub(crate) fn fold_jacobian_profile<H: Hasher>(
mut hasher: H,
jac: &[i32; JACOBIAN_MAX_SITES],
) -> H {
let mut i = 0;
while i < JACOBIAN_MAX_SITES {
hasher = hasher.fold_bytes(&jac[i].to_be_bytes());
i += 1;
}
hasher
}
pub(crate) fn primitive_session_binding_signature(bindings: &[Binding]) -> (u32, u64) {
let mut fold: u64 = 0xcbf2_9ce4_8422_2325;
const FNV_PRIME: u64 = 0x0000_0100_0000_01b3;
let mut i = 0;
while i < bindings.len() {
let b = &bindings[i];
fold = fold.wrapping_mul(FNV_PRIME);
fold ^= b.name_index as u64;
fold = fold.wrapping_mul(FNV_PRIME);
fold ^= b.type_index as u64;
fold = fold.wrapping_mul(FNV_PRIME);
fold ^= b.content_address;
i += 1;
}
(bindings.len() as u32, fold)
}
pub(crate) fn fold_session_signature<H: Hasher>(
mut hasher: H,
binding_count: u32,
fold_address: u64,
) -> H {
hasher = hasher.fold_bytes(&binding_count.to_be_bytes());
hasher = hasher.fold_bytes(&fold_address.to_be_bytes());
hasher
}
pub(crate) fn primitive_measurement_projection(budget: u64) -> (u64, u64) {
let alpha0_bits: u32 = (budget >> 32) as u32;
let alpha1_bits: u32 = (budget & 0xFFFF_FFFF) as u32;
type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
let a0 = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(alpha0_bits)
/ <DefaultDecimal as crate::DecimalTranscendental>::from_u32(u32::MAX);
let a1 = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(alpha1_bits)
/ <DefaultDecimal as crate::DecimalTranscendental>::from_u32(u32::MAX);
let norm = a0 * a0 + a1 * a1;
let zero = <DefaultDecimal as Default>::default();
let half =
<DefaultDecimal as crate::DecimalTranscendental>::from_bits(0x3FE0_0000_0000_0000_u64);
let p0 = if norm > zero { (a0 * a0) / norm } else { half };
let p1 = if norm > zero { (a1 * a1) / norm } else { half };
if p0 >= p1 {
(
0,
<DefaultDecimal as crate::DecimalTranscendental>::to_bits(p0),
)
} else {
(
1,
<DefaultDecimal as crate::DecimalTranscendental>::to_bits(p1),
)
}
}
pub(crate) fn fold_born_outcome<H: Hasher>(
mut hasher: H,
outcome_index: u64,
probability_bits: u64,
) -> H {
hasher = hasher.fold_bytes(&outcome_index.to_be_bytes());
hasher = hasher.fold_bytes(&probability_bits.to_be_bytes());
hasher
}
pub(crate) fn primitive_descent_metrics<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
betti: &[u32; MAX_BETTI_DIMENSION],
) -> (u32, u64) {
let chi = primitive_euler_characteristic(betti);
let n = T::SITE_COUNT as i64;
let residual = if n > chi { (n - chi) as u32 } else { 0u32 };
type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
let residual_d = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(residual);
let ln_2 = <DefaultDecimal as crate::DecimalTranscendental>::from_bits(crate::LN_2_BITS);
let entropy = residual_d * ln_2;
(
residual,
<DefaultDecimal as crate::DecimalTranscendental>::to_bits(entropy),
)
}
pub(crate) fn fold_descent_metrics<H: Hasher>(
mut hasher: H,
residual_count: u32,
entropy_bits: u64,
) -> H {
hasher = hasher.fold_bytes(&residual_count.to_be_bytes());
hasher = hasher.fold_bytes(&entropy_bits.to_be_bytes());
hasher
}
pub const MAX_COHOMOLOGY_DIMENSION: u32 = 32;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CohomologyClass {
dimension: u32,
fingerprint: ContentFingerprint,
_sealed: (),
}
impl CohomologyClass {
#[inline]
pub(crate) const fn with_dimension_and_fingerprint(
dimension: u32,
fingerprint: ContentFingerprint,
) -> Self {
Self {
dimension,
fingerprint,
_sealed: (),
}
}
#[inline]
#[must_use]
pub const fn dimension(&self) -> u32 {
self.dimension
}
#[inline]
#[must_use]
pub const fn fingerprint(&self) -> ContentFingerprint {
self.fingerprint
}
pub fn cup<H: Hasher>(
self,
other: CohomologyClass,
) -> Result<CohomologyClass, CohomologyError> {
let sum = self.dimension.saturating_add(other.dimension);
if sum > MAX_COHOMOLOGY_DIMENSION {
return Err(CohomologyError::DimensionOverflow {
lhs: self.dimension,
rhs: other.dimension,
});
}
let hasher = H::initial();
let hasher = fold_cup_product(
hasher,
self.dimension,
&self.fingerprint,
other.dimension,
&other.fingerprint,
);
let buf = hasher.finalize();
let fp = ContentFingerprint::from_buffer(buf, H::OUTPUT_BYTES as u8);
Ok(Self::with_dimension_and_fingerprint(sum, fp))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CohomologyError {
DimensionOverflow { lhs: u32, rhs: u32 },
}
impl core::fmt::Display for CohomologyError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::DimensionOverflow { lhs, rhs } => write!(
f,
"cup product dimension overflow: {lhs} + {rhs} > MAX_COHOMOLOGY_DIMENSION ({})",
MAX_COHOMOLOGY_DIMENSION
),
}
}
}
impl core::error::Error for CohomologyError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct HomologyClass {
dimension: u32,
fingerprint: ContentFingerprint,
_sealed: (),
}
impl HomologyClass {
#[inline]
pub(crate) const fn with_dimension_and_fingerprint(
dimension: u32,
fingerprint: ContentFingerprint,
) -> Self {
Self {
dimension,
fingerprint,
_sealed: (),
}
}
#[inline]
#[must_use]
pub const fn dimension(&self) -> u32 {
self.dimension
}
#[inline]
#[must_use]
pub const fn fingerprint(&self) -> ContentFingerprint {
self.fingerprint
}
}
pub fn fold_cup_product<H: Hasher>(
mut hasher: H,
lhs_dim: u32,
lhs_fp: &ContentFingerprint,
rhs_dim: u32,
rhs_fp: &ContentFingerprint,
) -> H {
hasher = hasher.fold_bytes(&lhs_dim.to_be_bytes());
hasher = hasher.fold_bytes(lhs_fp.as_bytes());
hasher = hasher.fold_bytes(&rhs_dim.to_be_bytes());
hasher = hasher.fold_bytes(rhs_fp.as_bytes());
hasher
}
pub fn mint_cohomology_class<H: Hasher>(
dimension: u32,
seed: &[u8],
) -> Result<CohomologyClass, CohomologyError> {
if dimension > MAX_COHOMOLOGY_DIMENSION {
return Err(CohomologyError::DimensionOverflow {
lhs: dimension,
rhs: 0,
});
}
let mut hasher = H::initial();
hasher = hasher.fold_bytes(&dimension.to_be_bytes());
hasher = hasher.fold_bytes(seed);
let buf = hasher.finalize();
let fp = ContentFingerprint::from_buffer(buf, H::OUTPUT_BYTES as u8);
Ok(CohomologyClass::with_dimension_and_fingerprint(
dimension, fp,
))
}
pub fn mint_homology_class<H: Hasher>(
dimension: u32,
seed: &[u8],
) -> Result<HomologyClass, CohomologyError> {
if dimension > MAX_COHOMOLOGY_DIMENSION {
return Err(CohomologyError::DimensionOverflow {
lhs: dimension,
rhs: 0,
});
}
let mut hasher = H::initial();
hasher = hasher.fold_bytes(&dimension.to_be_bytes());
hasher = hasher.fold_bytes(seed);
let buf = hasher.finalize();
let fp = ContentFingerprint::from_buffer(buf, H::OUTPUT_BYTES as u8);
Ok(HomologyClass::with_dimension_and_fingerprint(dimension, fp))
}
pub fn fold_stream_step_digest<H: Hasher>(
mut hasher: H,
productivity_remaining: u64,
rewrite_steps: u64,
seed: u64,
iri: &str,
kind: CertificateKind,
) -> H {
hasher = hasher.fold_bytes(&productivity_remaining.to_be_bytes());
hasher = hasher.fold_bytes(&rewrite_steps.to_be_bytes());
hasher = hasher.fold_bytes(&seed.to_be_bytes());
hasher = hasher.fold_bytes(iri.as_bytes());
hasher = hasher.fold_byte(0);
hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
hasher
}
pub fn fold_interaction_step_digest<H: Hasher>(
mut hasher: H,
commutator_acc: &[u64; 4],
peer_step_count: u64,
seed: u64,
iri: &str,
kind: CertificateKind,
) -> H {
let mut i = 0;
while i < 4 {
hasher = hasher.fold_bytes(&commutator_acc[i].to_be_bytes());
i += 1;
}
hasher = hasher.fold_bytes(&peer_step_count.to_be_bytes());
hasher = hasher.fold_bytes(&seed.to_be_bytes());
hasher = hasher.fold_bytes(iri.as_bytes());
hasher = hasher.fold_byte(0);
hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
hasher
}
#[inline]
#[must_use]
pub const fn unit_address_from_buffer<const FP_MAX: usize>(
buffer: &[u8; FP_MAX],
) -> ContentAddress {
let mut bytes = [0u8; 16];
let mut i = 0;
while i < 16 {
bytes[i] = buffer[i];
i += 1;
}
ContentAddress::from_u128(u128::from_be_bytes(bytes))
}
#[inline]
#[must_use]
pub const fn str_eq(a: &str, b: &str) -> bool {
let a = a.as_bytes();
let b = b.as_bytes();
if a.len() != b.len() {
return false;
}
let mut i = 0;
while i < a.len() {
if a[i] != b[i] {
return false;
}
i += 1;
}
true
}
#[derive(Debug, Clone, Copy)]
pub struct BindingEntry {
pub address: ContentAddress,
pub bytes: &'static [u8],
}
#[derive(Debug, Clone, Copy)]
pub struct BindingsTable {
pub entries: &'static [BindingEntry],
}
impl BindingsTable {
pub const fn try_new(entries: &'static [BindingEntry]) -> Result<Self, BindingsTableError> {
let mut i = 1;
while i < entries.len() {
if entries[i].address.as_u128() <= entries[i - 1].address.as_u128() {
return Err(BindingsTableError::Unsorted { at: i });
}
i += 1;
}
Ok(Self { entries })
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum BindingsTableError {
Unsorted {
at: usize,
},
}
impl core::fmt::Display for BindingsTableError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Unsorted { at } => write!(
f,
"BindingsTable entries not sorted: address at index {at} <= address at index {}",
at - 1,
),
}
}
}
impl core::error::Error for BindingsTableError {}
#[derive(Debug, Clone)]
pub struct Grounded<T: GroundedShape, Tag = T> {
validated: Validated<GroundingCertificate>,
bindings: BindingsTable,
witt_level_bits: u16,
unit_address: ContentAddress,
uor_time: UorTime,
sigma_ppm: u32,
d_delta: i64,
euler_characteristic: i64,
residual_count: u32,
jacobian_entries: [i64; JACOBIAN_MAX_SITES],
jacobian_len: u16,
betti_numbers: [u32; MAX_BETTI_DIMENSION],
content_fingerprint: ContentFingerprint,
_phantom: PhantomData<T>,
_tag: PhantomData<Tag>,
}
impl<T: GroundedShape, Tag> Grounded<T, Tag> {
#[inline]
#[must_use]
pub fn get_binding(&self, address: ContentAddress) -> Option<&'static [u8]> {
self.bindings
.entries
.binary_search_by_key(&address.as_u128(), |e| e.address.as_u128())
.ok()
.map(|i| self.bindings.entries[i].bytes)
}
#[inline]
pub fn iter_bindings(&self) -> impl Iterator<Item = &BindingEntry> + '_ {
self.bindings.entries.iter()
}
#[inline]
#[must_use]
pub const fn witt_level_bits(&self) -> u16 {
self.witt_level_bits
}
#[inline]
#[must_use]
pub const fn unit_address(&self) -> ContentAddress {
self.unit_address
}
#[inline]
#[must_use]
pub const fn certificate(&self) -> &Validated<GroundingCertificate> {
&self.validated
}
#[inline]
#[must_use]
pub const fn d_delta(&self) -> DDeltaMetric {
DDeltaMetric::new(self.d_delta)
}
#[inline]
#[must_use]
pub fn sigma(&self) -> SigmaValue<crate::DefaultHostTypes> {
let value = <f64 as crate::DecimalTranscendental>::from_u32(self.sigma_ppm)
/ <f64 as crate::DecimalTranscendental>::from_u32(1_000_000);
SigmaValue::<crate::DefaultHostTypes>::new_unchecked(value)
}
#[inline]
#[must_use]
pub fn jacobian(&self) -> JacobianMetric<T> {
JacobianMetric::from_entries(self.jacobian_entries, self.jacobian_len)
}
#[inline]
#[must_use]
pub const fn betti(&self) -> BettiMetric {
BettiMetric::new(self.betti_numbers)
}
#[inline]
#[must_use]
pub const fn euler(&self) -> EulerMetric {
EulerMetric::new(self.euler_characteristic)
}
#[inline]
#[must_use]
pub const fn residual(&self) -> ResidualMetric {
ResidualMetric::new(self.residual_count)
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
#[inline]
#[must_use]
pub const fn derivation(&self) -> Derivation {
Derivation::new(
(self.jacobian_len as u32) + 1,
self.witt_level_bits,
self.content_fingerprint,
)
}
#[inline]
#[must_use]
pub fn tag<NewTag>(self) -> Grounded<T, NewTag> {
Grounded {
validated: self.validated,
bindings: self.bindings,
witt_level_bits: self.witt_level_bits,
unit_address: self.unit_address,
uor_time: self.uor_time,
sigma_ppm: self.sigma_ppm,
d_delta: self.d_delta,
euler_characteristic: self.euler_characteristic,
residual_count: self.residual_count,
jacobian_entries: self.jacobian_entries,
jacobian_len: self.jacobian_len,
betti_numbers: self.betti_numbers,
content_fingerprint: self.content_fingerprint,
_phantom: PhantomData,
_tag: PhantomData,
}
}
#[inline]
#[must_use]
pub const fn uor_time(&self) -> UorTime {
self.uor_time
}
#[inline]
#[must_use]
pub const fn triad(&self) -> Triad<T> {
let addr = self.unit_address.as_u128();
let addr_lo = addr as u64;
let addr_hi = (addr >> 64) as u64;
let stratum = if addr_lo == 0 {
0u64
} else {
addr_lo.trailing_zeros() as u64
};
Triad::new(stratum, addr_lo, addr_hi)
}
#[inline]
#[allow(dead_code)]
pub(crate) const fn new_internal(
validated: Validated<GroundingCertificate>,
bindings: BindingsTable,
witt_level_bits: u16,
unit_address: ContentAddress,
content_fingerprint: ContentFingerprint,
) -> Self {
let bound_count = bindings.entries.len() as u32;
let declared_sites = if witt_level_bits == 0 {
1u32
} else {
witt_level_bits as u32
};
let sigma_ppm = if bound_count >= declared_sites {
1_000_000u32
} else {
let num = (bound_count as u64) * 1_000_000u64;
(num / (declared_sites as u64)) as u32
};
let residual_count = declared_sites.saturating_sub(bound_count);
let d_delta = (witt_level_bits as i64) - (bound_count as i64);
let mut betti = [0u32; MAX_BETTI_DIMENSION];
betti[0] = 1;
let mut k = 1usize;
while k < MAX_BETTI_DIMENSION {
betti[k] = ((witt_level_bits as u32) >> (k - 1)) & 1;
k += 1;
}
let mut euler: i64 = 0;
let mut k = 0usize;
while k < MAX_BETTI_DIMENSION {
if k & 1 == 0 {
euler += betti[k] as i64;
} else {
euler -= betti[k] as i64;
}
k += 1;
}
let mut jac = [0i64; JACOBIAN_MAX_SITES];
let modulus = (witt_level_bits as i64) + 1;
let ua_lo = unit_address.as_u128() as i64;
let mut i = 0usize;
let jac_len = if (witt_level_bits as usize) < JACOBIAN_MAX_SITES {
witt_level_bits as usize
} else {
JACOBIAN_MAX_SITES
};
while i < jac_len {
let raw = ua_lo ^ (i as i64);
let m = if modulus == 0 { 1 } else { modulus };
jac[i] = ((raw % m) + m) % m;
i += 1;
}
let steps = (witt_level_bits as u64) + (bound_count as u64) + (jac_len as u64);
let landauer = LandauerBudget::new((steps as f64) * core::f64::consts::LN_2);
let uor_time = UorTime::new(landauer, steps);
Self {
validated,
bindings,
witt_level_bits,
unit_address,
uor_time,
sigma_ppm,
d_delta,
euler_characteristic: euler,
residual_count,
jacobian_entries: jac,
jacobian_len: jac_len as u16,
betti_numbers: betti,
content_fingerprint,
_phantom: PhantomData,
_tag: PhantomData,
}
}
#[inline]
#[must_use]
pub fn with_bindings(self, bindings: BindingsTable) -> Self {
Self { bindings, ..self }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Triad<L> {
stratum: u64,
spectrum: u64,
address: u64,
_level: PhantomData<L>,
}
impl<L> Triad<L> {
#[inline]
#[must_use]
pub const fn stratum(&self) -> u64 {
self.stratum
}
#[inline]
#[must_use]
pub const fn spectrum(&self) -> u64 {
self.spectrum
}
#[inline]
#[must_use]
pub const fn address(&self) -> u64 {
self.address
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(stratum: u64, spectrum: u64, address: u64) -> Self {
Self {
stratum,
spectrum,
address,
_level: PhantomData,
}
}
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum PipelineFailure {
DispatchMiss {
query_iri: &'static str,
table_iri: &'static str,
},
GroundingFailure {
reason_iri: &'static str,
},
ConvergenceStall {
stage_iri: &'static str,
angle_milliradians: i64,
},
ContradictionDetected {
at_step: usize,
trace_iri: &'static str,
},
CoherenceViolation {
site_position: usize,
constraint_iri: &'static str,
},
ShapeMismatch {
expected: &'static str,
got: &'static str,
},
LiftObstructionFailure {
site_position: usize,
obstruction_class_iri: &'static str,
},
ShapeViolation {
report: ShapeViolation,
},
}
impl core::fmt::Display for PipelineFailure {
fn fmt(&self, ff: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::DispatchMiss {
query_iri,
table_iri,
} => write!(
ff,
"DispatchMiss(query_iri={:?}, table_iri={:?})",
query_iri, table_iri
),
Self::GroundingFailure { reason_iri } => {
write!(ff, "GroundingFailure(reason_iri={:?})", reason_iri)
}
Self::ConvergenceStall {
stage_iri,
angle_milliradians,
} => write!(
ff,
"ConvergenceStall(stage_iri={:?}, angle_milliradians={:?})",
stage_iri, angle_milliradians
),
Self::ContradictionDetected { at_step, trace_iri } => write!(
ff,
"ContradictionDetected(at_step={:?}, trace_iri={:?})",
at_step, trace_iri
),
Self::CoherenceViolation {
site_position,
constraint_iri,
} => write!(
ff,
"CoherenceViolation(site_position={:?}, constraint_iri={:?})",
site_position, constraint_iri
),
Self::ShapeMismatch { expected, got } => {
write!(ff, "ShapeMismatch(expected={:?}, got={:?})", expected, got)
}
Self::LiftObstructionFailure {
site_position,
obstruction_class_iri,
} => write!(
ff,
"LiftObstructionFailure(site_position={:?}, obstruction_class_iri={:?})",
site_position, obstruction_class_iri
),
Self::ShapeViolation { report } => write!(ff, "ShapeViolation({:?})", report),
}
}
}
impl core::error::Error for PipelineFailure {}
pub trait ImpossibilityWitnessKind: impossibility_witness_kind_sealed::Sealed {}
mod impossibility_witness_kind_sealed {
pub trait Sealed {}
impl Sealed for super::GenericImpossibilityWitness {}
impl Sealed for super::InhabitanceImpossibilityWitness {}
}
impl ImpossibilityWitnessKind for GenericImpossibilityWitness {}
impl ImpossibilityWitnessKind for InhabitanceImpossibilityWitness {}
pub mod resolver {
use super::{
BornRuleVerification,
Certified,
CompileUnit,
CompletenessCertificate,
GenericImpossibilityWitness,
GeodesicCertificate,
GroundingCertificate,
InhabitanceCertificate,
InhabitanceImpossibilityWitness,
InvolutionCertificate,
IsometryCertificate,
LiftChainCertificate,
MeasurementCertificate,
TransformCertificate,
Validated,
WittLevel,
};
pub mod tower_completeness {
use super::*;
pub fn certify<T, P, H>(
input: &Validated<T, P>,
) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
where
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<T, P, H>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
where
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
{
crate::pipeline::run_tower_completeness::<T, H>(input.inner(), level)
.map(|v| Certified::new(*v.inner()))
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
}
}
pub mod incremental_completeness {
use super::*;
pub fn certify<T, P, H>(
input: &Validated<T, P>,
) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
where
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<T, P, H>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
where
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
{
crate::pipeline::run_incremental_completeness::<T, H>(input.inner(), level)
.map(|v| Certified::new(*v.inner()))
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
}
}
pub mod grounding_aware {
use super::*;
pub fn certify<P, H>(
input: &Validated<CompileUnit, P>,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
where
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
{
certify_at::<P, H>(input, WittLevel::W32)
}
pub fn certify_at<P, H>(
input: &Validated<CompileUnit, P>,
level: WittLevel,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
where
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
{
crate::pipeline::run_grounding_aware::<H>(input.inner(), level)
.map(|v| Certified::new(*v.inner()))
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
}
}
pub mod inhabitance {
use super::*;
pub fn certify<T, P, H>(
input: &Validated<T, P>,
) -> Result<Certified<InhabitanceCertificate>, Certified<InhabitanceImpossibilityWitness>>
where
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<T, P, H>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<InhabitanceCertificate>, Certified<InhabitanceImpossibilityWitness>>
where
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
{
crate::pipeline::run_inhabitance::<T, H>(input.inner(), level)
.map(|v: Validated<InhabitanceCertificate>| Certified::new(*v.inner()))
.map_err(|_| Certified::new(InhabitanceImpossibilityWitness::default()))
}
}
pub mod multiplication {
use super::super::{MulContext, MultiplicationCertificate};
use super::*;
pub fn certify<H: crate::enforcement::Hasher>(
context: &MulContext,
) -> Result<Certified<MultiplicationCertificate>, GenericImpossibilityWitness> {
if context.stack_budget_bytes == 0 {
return Err(GenericImpossibilityWitness::default());
}
let limb_count = context.limb_count.max(1);
let karatsuba_stack_need = limb_count * 8 * 6;
let choose_karatsuba = !context.const_eval
&& (context.stack_budget_bytes as usize) >= karatsuba_stack_need;
let mut hasher = H::initial();
hasher = hasher.fold_bytes(&context.stack_budget_bytes.to_be_bytes());
hasher = hasher.fold_byte(if context.const_eval { 1 } else { 0 });
hasher = hasher.fold_bytes(&(limb_count as u64).to_be_bytes());
hasher = hasher.fold_byte(crate::enforcement::certificate_kind_discriminant(
crate::enforcement::CertificateKind::Multiplication,
));
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = if choose_karatsuba {
MultiplicationCertificate::with_evidence(
2,
3,
karatsuba_landauer_cost(limb_count),
fp,
)
} else {
MultiplicationCertificate::with_evidence(
1,
1,
schoolbook_landauer_cost(limb_count),
fp,
)
};
Ok(Certified::new(cert))
}
type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
fn schoolbook_landauer_cost(limb_count: usize) -> u64 {
let n = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(limb_count as u32);
let sixty_four = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(64);
let ln_2 =
<DefaultDecimal as crate::DecimalTranscendental>::from_bits(crate::LN_2_BITS);
(n * n * sixty_four * ln_2).to_bits()
}
fn karatsuba_landauer_cost(limb_count: usize) -> u64 {
let n = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(limb_count as u32);
let two = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(2);
let three = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(3);
let sixty_four = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(64);
let ln_2 =
<DefaultDecimal as crate::DecimalTranscendental>::from_bits(crate::LN_2_BITS);
let n_half = n / two;
(three * n_half * n_half * sixty_four * ln_2).to_bits()
}
}
pub(crate) trait ResolverKernel {
const KIND: crate::enforcement::CertificateKind;
type Cert: crate::enforcement::Certificate;
}
pub mod two_sat_decider {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::GroundingCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::TwoSat;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod horn_sat_decider {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::GroundingCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::HornSat;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod residual_verdict {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::GroundingCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::ResidualVerdict;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod canonical_form {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::TransformCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::CanonicalForm;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
let (tr2_bits, tr2_constraints, tr2_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr2_bits != tr_bits || tr2_constraints != tr_constraints || tr2_sat != tr_sat {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr2_bits,
tr2_constraints,
tr2_sat,
);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod type_synthesis {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::TransformCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::TypeSynthesis;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
.map_err(crate::enforcement::Certified::new)?;
hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
let (residual, entropy) = crate::enforcement::primitive_descent_metrics::<T>(&betti);
hasher = crate::enforcement::fold_descent_metrics(hasher, residual, entropy);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod homotopy {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::TransformCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::Homotopy;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
.map_err(crate::enforcement::Certified::new)?;
hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod monodromy {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::IsometryCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::Monodromy;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<IsometryCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<IsometryCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
.map_err(crate::enforcement::Certified::new)?;
hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
let (orbit_size, representative) =
crate::enforcement::primitive_dihedral_signature::<T>();
hasher =
crate::enforcement::fold_dihedral_signature(hasher, orbit_size, representative);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod moduli {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::TransformCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::Moduli;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
.map_err(crate::enforcement::Certified::new)?;
let automorphisms: u32 = betti[0];
let deformations: u32 = if crate::enforcement::MAX_BETTI_DIMENSION > 1 {
betti[1]
} else {
0
};
let obstructions: u32 = if crate::enforcement::MAX_BETTI_DIMENSION > 2 {
betti[2]
} else {
0
};
hasher = hasher.fold_bytes(&automorphisms.to_be_bytes());
hasher = hasher.fold_bytes(&deformations.to_be_bytes());
hasher = hasher.fold_bytes(&obstructions.to_be_bytes());
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod jacobian_guided {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::GroundingCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::JacobianGuided;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
let jac = crate::enforcement::primitive_curvature_jacobian::<T>();
hasher = crate::enforcement::fold_jacobian_profile(hasher, &jac);
let selected_site = crate::enforcement::primitive_dc10_select(&jac);
hasher = hasher.fold_bytes(&(selected_site as u32).to_be_bytes());
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod evaluation {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::GroundingCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::Evaluation;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod session {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::GroundingCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::Session;
}
pub fn certify<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
input: &Validated<CompileUnit, P>,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<P, H>(input, WittLevel::W32)
}
pub fn certify_at<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
input: &Validated<CompileUnit, P>,
level: WittLevel,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
let unit = input.inner();
let witt_bits = level.witt_length() as u16;
let budget = unit.thermodynamic_budget();
let result_type_iri = unit.result_type_iri();
let mut hasher = H::initial();
let (binding_count, fold_addr) =
crate::enforcement::primitive_session_binding_signature(unit.bindings());
hasher = crate::enforcement::fold_session_signature(hasher, binding_count, fold_addr);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
budget,
result_type_iri,
0usize,
&[],
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod superposition {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::BornRuleVerification;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::Superposition;
}
pub fn certify<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
input: &Validated<CompileUnit, P>,
) -> Result<Certified<BornRuleVerification>, Certified<GenericImpossibilityWitness>>
{
certify_at::<P, H>(input, WittLevel::W32)
}
pub fn certify_at<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
input: &Validated<CompileUnit, P>,
level: WittLevel,
) -> Result<Certified<BornRuleVerification>, Certified<GenericImpossibilityWitness>>
{
let unit = input.inner();
let witt_bits = level.witt_length() as u16;
let budget = unit.thermodynamic_budget();
let result_type_iri = unit.result_type_iri();
let mut hasher = H::initial();
let (binding_count, fold_addr) =
crate::enforcement::primitive_session_binding_signature(unit.bindings());
hasher = crate::enforcement::fold_session_signature(hasher, binding_count, fold_addr);
let (outcome_index, probability) =
crate::enforcement::primitive_measurement_projection(budget);
hasher = crate::enforcement::fold_born_outcome(hasher, outcome_index, probability);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
budget,
result_type_iri,
0usize,
&[],
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod measurement {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::MeasurementCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::Measurement;
}
pub fn certify<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
input: &Validated<CompileUnit, P>,
) -> Result<Certified<MeasurementCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<P, H>(input, WittLevel::W32)
}
pub fn certify_at<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
input: &Validated<CompileUnit, P>,
level: WittLevel,
) -> Result<Certified<MeasurementCertificate>, Certified<GenericImpossibilityWitness>>
{
let unit = input.inner();
let witt_bits = level.witt_length() as u16;
let budget = unit.thermodynamic_budget();
let result_type_iri = unit.result_type_iri();
let mut hasher = H::initial();
let (outcome_index, probability) =
crate::enforcement::primitive_measurement_projection(budget);
hasher = crate::enforcement::fold_born_outcome(hasher, outcome_index, probability);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
budget,
result_type_iri,
0usize,
&[],
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod witt_level_resolver {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::GroundingCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::WittLevel;
}
pub fn certify<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
input: &Validated<CompileUnit, P>,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<P, H>(input, WittLevel::W32)
}
pub fn certify_at<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
input: &Validated<CompileUnit, P>,
level: WittLevel,
) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
{
let unit = input.inner();
let witt_bits = level.witt_length() as u16;
let budget = unit.thermodynamic_budget();
let result_type_iri = unit.result_type_iri();
let mut hasher = H::initial();
hasher = hasher.fold_bytes(&witt_bits.to_be_bytes());
let declared_level_bits = unit.witt_level().witt_length() as u16;
hasher = hasher.fold_bytes(&declared_level_bits.to_be_bytes());
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
budget,
result_type_iri,
0usize,
&[],
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod dihedral_factorization {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::InvolutionCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::DihedralFactorization;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<InvolutionCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<InvolutionCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
let (orbit_size, representative) =
crate::enforcement::primitive_dihedral_signature::<T>();
hasher =
crate::enforcement::fold_dihedral_signature(hasher, orbit_size, representative);
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod completeness {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::CompletenessCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::Completeness;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<CompletenessCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<CompletenessCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
.map_err(crate::enforcement::Certified::new)?;
let chi = crate::enforcement::primitive_euler_characteristic(&betti);
hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
hasher = hasher.fold_bytes(&chi.to_be_bytes());
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
pub mod geodesic_validator {
use super::*;
#[doc(hidden)]
pub struct Kernel;
impl super::ResolverKernel for Kernel {
type Cert = crate::enforcement::GeodesicCertificate;
const KIND: crate::enforcement::CertificateKind =
crate::enforcement::CertificateKind::GeodesicValidator;
}
pub fn certify<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
) -> Result<Certified<GeodesicCertificate>, Certified<GenericImpossibilityWitness>>
{
certify_at::<T, P, H>(input, WittLevel::W32)
}
pub fn certify_at<
T: crate::pipeline::ConstrainedTypeShape,
P: crate::enforcement::ValidationPhase,
H: crate::enforcement::Hasher,
>(
input: &Validated<T, P>,
level: WittLevel,
) -> Result<Certified<GeodesicCertificate>, Certified<GenericImpossibilityWitness>>
{
let _ = input.inner();
let witt_bits = level.witt_length() as u16;
let (tr_bits, tr_constraints, tr_sat) =
crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
.map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
if tr_sat == 0 {
return Err(Certified::new(GenericImpossibilityWitness::default()));
}
let mut hasher = H::initial();
hasher = crate::enforcement::fold_terminal_reduction(
hasher,
tr_bits,
tr_constraints,
tr_sat,
);
let jac = crate::enforcement::primitive_curvature_jacobian::<T>();
hasher = crate::enforcement::fold_jacobian_profile(hasher, &jac);
let selected_site = crate::enforcement::primitive_dc10_select(&jac);
hasher = hasher.fold_bytes(&(selected_site as u32).to_be_bytes());
hasher = crate::enforcement::fold_unit_digest(
hasher,
witt_bits,
witt_bits as u64,
T::IRI,
T::SITE_COUNT,
T::CONSTRAINTS,
<Kernel as super::ResolverKernel>::KIND,
);
let buffer = hasher.finalize();
let fp =
crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
Ok(Certified::new(cert))
}
}
}
pub trait RingOp<L> {
type Operand;
fn apply(a: Self::Operand, b: Self::Operand) -> Self::Operand;
}
pub trait UnaryRingOp<L> {
type Operand;
fn apply(a: Self::Operand) -> Self::Operand;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct Mul<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct Add<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct Sub<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct Xor<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct And<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct Or<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct Neg<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct BNot<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct Succ<L>(PhantomData<L>);
#[derive(Debug, Default, Clone, Copy)]
pub struct W8;
#[derive(Debug, Default, Clone, Copy)]
pub struct W16;
#[derive(Debug, Default, Clone, Copy)]
pub struct W24;
#[derive(Debug, Default, Clone, Copy)]
pub struct W32;
#[derive(Debug, Default, Clone, Copy)]
pub struct W40;
#[derive(Debug, Default, Clone, Copy)]
pub struct W48;
#[derive(Debug, Default, Clone, Copy)]
pub struct W56;
#[derive(Debug, Default, Clone, Copy)]
pub struct W64;
#[derive(Debug, Default, Clone, Copy)]
pub struct W72;
#[derive(Debug, Default, Clone, Copy)]
pub struct W80;
#[derive(Debug, Default, Clone, Copy)]
pub struct W88;
#[derive(Debug, Default, Clone, Copy)]
pub struct W96;
#[derive(Debug, Default, Clone, Copy)]
pub struct W104;
#[derive(Debug, Default, Clone, Copy)]
pub struct W112;
#[derive(Debug, Default, Clone, Copy)]
pub struct W120;
#[derive(Debug, Default, Clone, Copy)]
pub struct W128;
impl RingOp<W8> for Mul<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W8> for Add<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W8> for Sub<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W8> for Xor<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W8> for And<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::And, a, b)
}
}
impl RingOp<W8> for Or<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8, b: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W16> for Mul<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W16> for Add<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W16> for Sub<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W16> for Xor<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W16> for And<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::And, a, b)
}
}
impl RingOp<W16> for Or<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16, b: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W24> for Mul<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W24> for Add<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W24> for Sub<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W24> for Xor<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W24> for And<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::And, a, b)
}
}
impl RingOp<W24> for Or<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W32> for Mul<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W32> for Add<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W32> for Sub<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W32> for Xor<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W32> for And<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::And, a, b)
}
}
impl RingOp<W32> for Or<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32, b: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W40> for Mul<W40> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w40(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W40> for Add<W40> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w40(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W40> for Sub<W40> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w40(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W40> for Xor<W40> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w40(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W40> for And<W40> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w40(PrimitiveOp::And, a, b)
}
}
impl RingOp<W40> for Or<W40> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w40(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W48> for Mul<W48> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w48(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W48> for Add<W48> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w48(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W48> for Sub<W48> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w48(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W48> for Xor<W48> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w48(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W48> for And<W48> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w48(PrimitiveOp::And, a, b)
}
}
impl RingOp<W48> for Or<W48> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w48(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W56> for Mul<W56> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w56(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W56> for Add<W56> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w56(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W56> for Sub<W56> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w56(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W56> for Xor<W56> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w56(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W56> for And<W56> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w56(PrimitiveOp::And, a, b)
}
}
impl RingOp<W56> for Or<W56> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w56(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W64> for Mul<W64> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w64(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W64> for Add<W64> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w64(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W64> for Sub<W64> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w64(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W64> for Xor<W64> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w64(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W64> for And<W64> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w64(PrimitiveOp::And, a, b)
}
}
impl RingOp<W64> for Or<W64> {
type Operand = u64;
#[inline]
fn apply(a: u64, b: u64) -> u64 {
const_ring_eval_w64(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W72> for Mul<W72> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w72(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W72> for Add<W72> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w72(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W72> for Sub<W72> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w72(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W72> for Xor<W72> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w72(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W72> for And<W72> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w72(PrimitiveOp::And, a, b)
}
}
impl RingOp<W72> for Or<W72> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w72(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W80> for Mul<W80> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w80(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W80> for Add<W80> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w80(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W80> for Sub<W80> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w80(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W80> for Xor<W80> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w80(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W80> for And<W80> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w80(PrimitiveOp::And, a, b)
}
}
impl RingOp<W80> for Or<W80> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w80(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W88> for Mul<W88> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w88(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W88> for Add<W88> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w88(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W88> for Sub<W88> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w88(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W88> for Xor<W88> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w88(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W88> for And<W88> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w88(PrimitiveOp::And, a, b)
}
}
impl RingOp<W88> for Or<W88> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w88(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W96> for Mul<W96> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w96(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W96> for Add<W96> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w96(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W96> for Sub<W96> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w96(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W96> for Xor<W96> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w96(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W96> for And<W96> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w96(PrimitiveOp::And, a, b)
}
}
impl RingOp<W96> for Or<W96> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w96(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W104> for Mul<W104> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w104(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W104> for Add<W104> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w104(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W104> for Sub<W104> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w104(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W104> for Xor<W104> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w104(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W104> for And<W104> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w104(PrimitiveOp::And, a, b)
}
}
impl RingOp<W104> for Or<W104> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w104(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W112> for Mul<W112> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w112(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W112> for Add<W112> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w112(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W112> for Sub<W112> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w112(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W112> for Xor<W112> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w112(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W112> for And<W112> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w112(PrimitiveOp::And, a, b)
}
}
impl RingOp<W112> for Or<W112> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w112(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W120> for Mul<W120> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w120(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W120> for Add<W120> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w120(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W120> for Sub<W120> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w120(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W120> for Xor<W120> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w120(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W120> for And<W120> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w120(PrimitiveOp::And, a, b)
}
}
impl RingOp<W120> for Or<W120> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w120(PrimitiveOp::Or, a, b)
}
}
impl RingOp<W128> for Mul<W128> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w128(PrimitiveOp::Mul, a, b)
}
}
impl RingOp<W128> for Add<W128> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w128(PrimitiveOp::Add, a, b)
}
}
impl RingOp<W128> for Sub<W128> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w128(PrimitiveOp::Sub, a, b)
}
}
impl RingOp<W128> for Xor<W128> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w128(PrimitiveOp::Xor, a, b)
}
}
impl RingOp<W128> for And<W128> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w128(PrimitiveOp::And, a, b)
}
}
impl RingOp<W128> for Or<W128> {
type Operand = u128;
#[inline]
fn apply(a: u128, b: u128) -> u128 {
const_ring_eval_w128(PrimitiveOp::Or, a, b)
}
}
impl UnaryRingOp<W8> for Neg<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W8> for BNot<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8) -> u8 {
const_ring_eval_w8(PrimitiveOp::Xor, a, u8::MAX)
}
}
impl UnaryRingOp<W8> for Succ<W8> {
type Operand = u8;
#[inline]
fn apply(a: u8) -> u8 {
<Neg<W8> as UnaryRingOp<W8>>::apply(<BNot<W8> as UnaryRingOp<W8>>::apply(a))
}
}
impl UnaryRingOp<W16> for Neg<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W16> for BNot<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16) -> u16 {
const_ring_eval_w16(PrimitiveOp::Xor, a, u16::MAX)
}
}
impl UnaryRingOp<W16> for Succ<W16> {
type Operand = u16;
#[inline]
fn apply(a: u16) -> u16 {
<Neg<W16> as UnaryRingOp<W16>>::apply(<BNot<W16> as UnaryRingOp<W16>>::apply(a))
}
}
impl UnaryRingOp<W24> for Neg<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W24> for BNot<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32) -> u32 {
const_ring_eval_w24(PrimitiveOp::Xor, a, 0x00FF_FFFFu32)
}
}
impl UnaryRingOp<W24> for Succ<W24> {
type Operand = u32;
#[inline]
fn apply(a: u32) -> u32 {
<Neg<W24> as UnaryRingOp<W24>>::apply(<BNot<W24> as UnaryRingOp<W24>>::apply(a))
}
}
impl UnaryRingOp<W32> for Neg<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W32> for BNot<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32) -> u32 {
const_ring_eval_w32(PrimitiveOp::Xor, a, u32::MAX)
}
}
impl UnaryRingOp<W32> for Succ<W32> {
type Operand = u32;
#[inline]
fn apply(a: u32) -> u32 {
<Neg<W32> as UnaryRingOp<W32>>::apply(<BNot<W32> as UnaryRingOp<W32>>::apply(a))
}
}
impl UnaryRingOp<W40> for Neg<W40> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
const_ring_eval_w40(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W40> for BNot<W40> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
const_ring_eval_w40(PrimitiveOp::Xor, a, 0x0000_00FF_FFFF_FFFFu64)
}
}
impl UnaryRingOp<W40> for Succ<W40> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
<Neg<W40> as UnaryRingOp<W40>>::apply(<BNot<W40> as UnaryRingOp<W40>>::apply(a))
}
}
impl UnaryRingOp<W48> for Neg<W48> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
const_ring_eval_w48(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W48> for BNot<W48> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
const_ring_eval_w48(PrimitiveOp::Xor, a, 0x0000_FFFF_FFFF_FFFFu64)
}
}
impl UnaryRingOp<W48> for Succ<W48> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
<Neg<W48> as UnaryRingOp<W48>>::apply(<BNot<W48> as UnaryRingOp<W48>>::apply(a))
}
}
impl UnaryRingOp<W56> for Neg<W56> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
const_ring_eval_w56(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W56> for BNot<W56> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
const_ring_eval_w56(PrimitiveOp::Xor, a, 0x00FF_FFFF_FFFF_FFFFu64)
}
}
impl UnaryRingOp<W56> for Succ<W56> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
<Neg<W56> as UnaryRingOp<W56>>::apply(<BNot<W56> as UnaryRingOp<W56>>::apply(a))
}
}
impl UnaryRingOp<W64> for Neg<W64> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
const_ring_eval_w64(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W64> for BNot<W64> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
const_ring_eval_w64(PrimitiveOp::Xor, a, u64::MAX)
}
}
impl UnaryRingOp<W64> for Succ<W64> {
type Operand = u64;
#[inline]
fn apply(a: u64) -> u64 {
<Neg<W64> as UnaryRingOp<W64>>::apply(<BNot<W64> as UnaryRingOp<W64>>::apply(a))
}
}
impl UnaryRingOp<W72> for Neg<W72> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w72(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W72> for BNot<W72> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w72(PrimitiveOp::Xor, a, u128::MAX >> (128 - 72))
}
}
impl UnaryRingOp<W72> for Succ<W72> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
<Neg<W72> as UnaryRingOp<W72>>::apply(<BNot<W72> as UnaryRingOp<W72>>::apply(a))
}
}
impl UnaryRingOp<W80> for Neg<W80> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w80(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W80> for BNot<W80> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w80(PrimitiveOp::Xor, a, u128::MAX >> (128 - 80))
}
}
impl UnaryRingOp<W80> for Succ<W80> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
<Neg<W80> as UnaryRingOp<W80>>::apply(<BNot<W80> as UnaryRingOp<W80>>::apply(a))
}
}
impl UnaryRingOp<W88> for Neg<W88> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w88(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W88> for BNot<W88> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w88(PrimitiveOp::Xor, a, u128::MAX >> (128 - 88))
}
}
impl UnaryRingOp<W88> for Succ<W88> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
<Neg<W88> as UnaryRingOp<W88>>::apply(<BNot<W88> as UnaryRingOp<W88>>::apply(a))
}
}
impl UnaryRingOp<W96> for Neg<W96> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w96(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W96> for BNot<W96> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w96(PrimitiveOp::Xor, a, u128::MAX >> (128 - 96))
}
}
impl UnaryRingOp<W96> for Succ<W96> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
<Neg<W96> as UnaryRingOp<W96>>::apply(<BNot<W96> as UnaryRingOp<W96>>::apply(a))
}
}
impl UnaryRingOp<W104> for Neg<W104> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w104(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W104> for BNot<W104> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w104(PrimitiveOp::Xor, a, u128::MAX >> (128 - 104))
}
}
impl UnaryRingOp<W104> for Succ<W104> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
<Neg<W104> as UnaryRingOp<W104>>::apply(<BNot<W104> as UnaryRingOp<W104>>::apply(a))
}
}
impl UnaryRingOp<W112> for Neg<W112> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w112(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W112> for BNot<W112> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w112(PrimitiveOp::Xor, a, u128::MAX >> (128 - 112))
}
}
impl UnaryRingOp<W112> for Succ<W112> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
<Neg<W112> as UnaryRingOp<W112>>::apply(<BNot<W112> as UnaryRingOp<W112>>::apply(a))
}
}
impl UnaryRingOp<W120> for Neg<W120> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w120(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W120> for BNot<W120> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w120(PrimitiveOp::Xor, a, u128::MAX >> (128 - 120))
}
}
impl UnaryRingOp<W120> for Succ<W120> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
<Neg<W120> as UnaryRingOp<W120>>::apply(<BNot<W120> as UnaryRingOp<W120>>::apply(a))
}
}
impl UnaryRingOp<W128> for Neg<W128> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w128(PrimitiveOp::Sub, 0, a)
}
}
impl UnaryRingOp<W128> for BNot<W128> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
const_ring_eval_w128(PrimitiveOp::Xor, a, u128::MAX)
}
}
impl UnaryRingOp<W128> for Succ<W128> {
type Operand = u128;
#[inline]
fn apply(a: u128) -> u128 {
<Neg<W128> as UnaryRingOp<W128>>::apply(<BNot<W128> as UnaryRingOp<W128>>::apply(a))
}
}
pub trait ValidLevelEmbedding: valid_level_embedding_sealed::Sealed {}
mod valid_level_embedding_sealed {
pub trait Sealed {}
impl Sealed for (super::W8, super::W8) {}
impl Sealed for (super::W8, super::W16) {}
impl Sealed for (super::W8, super::W24) {}
impl Sealed for (super::W8, super::W32) {}
impl Sealed for (super::W8, super::W40) {}
impl Sealed for (super::W8, super::W48) {}
impl Sealed for (super::W8, super::W56) {}
impl Sealed for (super::W8, super::W64) {}
impl Sealed for (super::W8, super::W72) {}
impl Sealed for (super::W8, super::W80) {}
impl Sealed for (super::W8, super::W88) {}
impl Sealed for (super::W8, super::W96) {}
impl Sealed for (super::W8, super::W104) {}
impl Sealed for (super::W8, super::W112) {}
impl Sealed for (super::W8, super::W120) {}
impl Sealed for (super::W8, super::W128) {}
impl Sealed for (super::W16, super::W16) {}
impl Sealed for (super::W16, super::W24) {}
impl Sealed for (super::W16, super::W32) {}
impl Sealed for (super::W16, super::W40) {}
impl Sealed for (super::W16, super::W48) {}
impl Sealed for (super::W16, super::W56) {}
impl Sealed for (super::W16, super::W64) {}
impl Sealed for (super::W16, super::W72) {}
impl Sealed for (super::W16, super::W80) {}
impl Sealed for (super::W16, super::W88) {}
impl Sealed for (super::W16, super::W96) {}
impl Sealed for (super::W16, super::W104) {}
impl Sealed for (super::W16, super::W112) {}
impl Sealed for (super::W16, super::W120) {}
impl Sealed for (super::W16, super::W128) {}
impl Sealed for (super::W24, super::W24) {}
impl Sealed for (super::W24, super::W32) {}
impl Sealed for (super::W24, super::W40) {}
impl Sealed for (super::W24, super::W48) {}
impl Sealed for (super::W24, super::W56) {}
impl Sealed for (super::W24, super::W64) {}
impl Sealed for (super::W24, super::W72) {}
impl Sealed for (super::W24, super::W80) {}
impl Sealed for (super::W24, super::W88) {}
impl Sealed for (super::W24, super::W96) {}
impl Sealed for (super::W24, super::W104) {}
impl Sealed for (super::W24, super::W112) {}
impl Sealed for (super::W24, super::W120) {}
impl Sealed for (super::W24, super::W128) {}
impl Sealed for (super::W32, super::W32) {}
impl Sealed for (super::W32, super::W40) {}
impl Sealed for (super::W32, super::W48) {}
impl Sealed for (super::W32, super::W56) {}
impl Sealed for (super::W32, super::W64) {}
impl Sealed for (super::W32, super::W72) {}
impl Sealed for (super::W32, super::W80) {}
impl Sealed for (super::W32, super::W88) {}
impl Sealed for (super::W32, super::W96) {}
impl Sealed for (super::W32, super::W104) {}
impl Sealed for (super::W32, super::W112) {}
impl Sealed for (super::W32, super::W120) {}
impl Sealed for (super::W32, super::W128) {}
impl Sealed for (super::W40, super::W40) {}
impl Sealed for (super::W40, super::W48) {}
impl Sealed for (super::W40, super::W56) {}
impl Sealed for (super::W40, super::W64) {}
impl Sealed for (super::W40, super::W72) {}
impl Sealed for (super::W40, super::W80) {}
impl Sealed for (super::W40, super::W88) {}
impl Sealed for (super::W40, super::W96) {}
impl Sealed for (super::W40, super::W104) {}
impl Sealed for (super::W40, super::W112) {}
impl Sealed for (super::W40, super::W120) {}
impl Sealed for (super::W40, super::W128) {}
impl Sealed for (super::W48, super::W48) {}
impl Sealed for (super::W48, super::W56) {}
impl Sealed for (super::W48, super::W64) {}
impl Sealed for (super::W48, super::W72) {}
impl Sealed for (super::W48, super::W80) {}
impl Sealed for (super::W48, super::W88) {}
impl Sealed for (super::W48, super::W96) {}
impl Sealed for (super::W48, super::W104) {}
impl Sealed for (super::W48, super::W112) {}
impl Sealed for (super::W48, super::W120) {}
impl Sealed for (super::W48, super::W128) {}
impl Sealed for (super::W56, super::W56) {}
impl Sealed for (super::W56, super::W64) {}
impl Sealed for (super::W56, super::W72) {}
impl Sealed for (super::W56, super::W80) {}
impl Sealed for (super::W56, super::W88) {}
impl Sealed for (super::W56, super::W96) {}
impl Sealed for (super::W56, super::W104) {}
impl Sealed for (super::W56, super::W112) {}
impl Sealed for (super::W56, super::W120) {}
impl Sealed for (super::W56, super::W128) {}
impl Sealed for (super::W64, super::W64) {}
impl Sealed for (super::W64, super::W72) {}
impl Sealed for (super::W64, super::W80) {}
impl Sealed for (super::W64, super::W88) {}
impl Sealed for (super::W64, super::W96) {}
impl Sealed for (super::W64, super::W104) {}
impl Sealed for (super::W64, super::W112) {}
impl Sealed for (super::W64, super::W120) {}
impl Sealed for (super::W64, super::W128) {}
impl Sealed for (super::W72, super::W72) {}
impl Sealed for (super::W72, super::W80) {}
impl Sealed for (super::W72, super::W88) {}
impl Sealed for (super::W72, super::W96) {}
impl Sealed for (super::W72, super::W104) {}
impl Sealed for (super::W72, super::W112) {}
impl Sealed for (super::W72, super::W120) {}
impl Sealed for (super::W72, super::W128) {}
impl Sealed for (super::W80, super::W80) {}
impl Sealed for (super::W80, super::W88) {}
impl Sealed for (super::W80, super::W96) {}
impl Sealed for (super::W80, super::W104) {}
impl Sealed for (super::W80, super::W112) {}
impl Sealed for (super::W80, super::W120) {}
impl Sealed for (super::W80, super::W128) {}
impl Sealed for (super::W88, super::W88) {}
impl Sealed for (super::W88, super::W96) {}
impl Sealed for (super::W88, super::W104) {}
impl Sealed for (super::W88, super::W112) {}
impl Sealed for (super::W88, super::W120) {}
impl Sealed for (super::W88, super::W128) {}
impl Sealed for (super::W96, super::W96) {}
impl Sealed for (super::W96, super::W104) {}
impl Sealed for (super::W96, super::W112) {}
impl Sealed for (super::W96, super::W120) {}
impl Sealed for (super::W96, super::W128) {}
impl Sealed for (super::W104, super::W104) {}
impl Sealed for (super::W104, super::W112) {}
impl Sealed for (super::W104, super::W120) {}
impl Sealed for (super::W104, super::W128) {}
impl Sealed for (super::W112, super::W112) {}
impl Sealed for (super::W112, super::W120) {}
impl Sealed for (super::W112, super::W128) {}
impl Sealed for (super::W120, super::W120) {}
impl Sealed for (super::W120, super::W128) {}
impl Sealed for (super::W128, super::W128) {}
}
impl ValidLevelEmbedding for (W8, W8) {}
impl ValidLevelEmbedding for (W8, W16) {}
impl ValidLevelEmbedding for (W8, W24) {}
impl ValidLevelEmbedding for (W8, W32) {}
impl ValidLevelEmbedding for (W8, W40) {}
impl ValidLevelEmbedding for (W8, W48) {}
impl ValidLevelEmbedding for (W8, W56) {}
impl ValidLevelEmbedding for (W8, W64) {}
impl ValidLevelEmbedding for (W8, W72) {}
impl ValidLevelEmbedding for (W8, W80) {}
impl ValidLevelEmbedding for (W8, W88) {}
impl ValidLevelEmbedding for (W8, W96) {}
impl ValidLevelEmbedding for (W8, W104) {}
impl ValidLevelEmbedding for (W8, W112) {}
impl ValidLevelEmbedding for (W8, W120) {}
impl ValidLevelEmbedding for (W8, W128) {}
impl ValidLevelEmbedding for (W16, W16) {}
impl ValidLevelEmbedding for (W16, W24) {}
impl ValidLevelEmbedding for (W16, W32) {}
impl ValidLevelEmbedding for (W16, W40) {}
impl ValidLevelEmbedding for (W16, W48) {}
impl ValidLevelEmbedding for (W16, W56) {}
impl ValidLevelEmbedding for (W16, W64) {}
impl ValidLevelEmbedding for (W16, W72) {}
impl ValidLevelEmbedding for (W16, W80) {}
impl ValidLevelEmbedding for (W16, W88) {}
impl ValidLevelEmbedding for (W16, W96) {}
impl ValidLevelEmbedding for (W16, W104) {}
impl ValidLevelEmbedding for (W16, W112) {}
impl ValidLevelEmbedding for (W16, W120) {}
impl ValidLevelEmbedding for (W16, W128) {}
impl ValidLevelEmbedding for (W24, W24) {}
impl ValidLevelEmbedding for (W24, W32) {}
impl ValidLevelEmbedding for (W24, W40) {}
impl ValidLevelEmbedding for (W24, W48) {}
impl ValidLevelEmbedding for (W24, W56) {}
impl ValidLevelEmbedding for (W24, W64) {}
impl ValidLevelEmbedding for (W24, W72) {}
impl ValidLevelEmbedding for (W24, W80) {}
impl ValidLevelEmbedding for (W24, W88) {}
impl ValidLevelEmbedding for (W24, W96) {}
impl ValidLevelEmbedding for (W24, W104) {}
impl ValidLevelEmbedding for (W24, W112) {}
impl ValidLevelEmbedding for (W24, W120) {}
impl ValidLevelEmbedding for (W24, W128) {}
impl ValidLevelEmbedding for (W32, W32) {}
impl ValidLevelEmbedding for (W32, W40) {}
impl ValidLevelEmbedding for (W32, W48) {}
impl ValidLevelEmbedding for (W32, W56) {}
impl ValidLevelEmbedding for (W32, W64) {}
impl ValidLevelEmbedding for (W32, W72) {}
impl ValidLevelEmbedding for (W32, W80) {}
impl ValidLevelEmbedding for (W32, W88) {}
impl ValidLevelEmbedding for (W32, W96) {}
impl ValidLevelEmbedding for (W32, W104) {}
impl ValidLevelEmbedding for (W32, W112) {}
impl ValidLevelEmbedding for (W32, W120) {}
impl ValidLevelEmbedding for (W32, W128) {}
impl ValidLevelEmbedding for (W40, W40) {}
impl ValidLevelEmbedding for (W40, W48) {}
impl ValidLevelEmbedding for (W40, W56) {}
impl ValidLevelEmbedding for (W40, W64) {}
impl ValidLevelEmbedding for (W40, W72) {}
impl ValidLevelEmbedding for (W40, W80) {}
impl ValidLevelEmbedding for (W40, W88) {}
impl ValidLevelEmbedding for (W40, W96) {}
impl ValidLevelEmbedding for (W40, W104) {}
impl ValidLevelEmbedding for (W40, W112) {}
impl ValidLevelEmbedding for (W40, W120) {}
impl ValidLevelEmbedding for (W40, W128) {}
impl ValidLevelEmbedding for (W48, W48) {}
impl ValidLevelEmbedding for (W48, W56) {}
impl ValidLevelEmbedding for (W48, W64) {}
impl ValidLevelEmbedding for (W48, W72) {}
impl ValidLevelEmbedding for (W48, W80) {}
impl ValidLevelEmbedding for (W48, W88) {}
impl ValidLevelEmbedding for (W48, W96) {}
impl ValidLevelEmbedding for (W48, W104) {}
impl ValidLevelEmbedding for (W48, W112) {}
impl ValidLevelEmbedding for (W48, W120) {}
impl ValidLevelEmbedding for (W48, W128) {}
impl ValidLevelEmbedding for (W56, W56) {}
impl ValidLevelEmbedding for (W56, W64) {}
impl ValidLevelEmbedding for (W56, W72) {}
impl ValidLevelEmbedding for (W56, W80) {}
impl ValidLevelEmbedding for (W56, W88) {}
impl ValidLevelEmbedding for (W56, W96) {}
impl ValidLevelEmbedding for (W56, W104) {}
impl ValidLevelEmbedding for (W56, W112) {}
impl ValidLevelEmbedding for (W56, W120) {}
impl ValidLevelEmbedding for (W56, W128) {}
impl ValidLevelEmbedding for (W64, W64) {}
impl ValidLevelEmbedding for (W64, W72) {}
impl ValidLevelEmbedding for (W64, W80) {}
impl ValidLevelEmbedding for (W64, W88) {}
impl ValidLevelEmbedding for (W64, W96) {}
impl ValidLevelEmbedding for (W64, W104) {}
impl ValidLevelEmbedding for (W64, W112) {}
impl ValidLevelEmbedding for (W64, W120) {}
impl ValidLevelEmbedding for (W64, W128) {}
impl ValidLevelEmbedding for (W72, W72) {}
impl ValidLevelEmbedding for (W72, W80) {}
impl ValidLevelEmbedding for (W72, W88) {}
impl ValidLevelEmbedding for (W72, W96) {}
impl ValidLevelEmbedding for (W72, W104) {}
impl ValidLevelEmbedding for (W72, W112) {}
impl ValidLevelEmbedding for (W72, W120) {}
impl ValidLevelEmbedding for (W72, W128) {}
impl ValidLevelEmbedding for (W80, W80) {}
impl ValidLevelEmbedding for (W80, W88) {}
impl ValidLevelEmbedding for (W80, W96) {}
impl ValidLevelEmbedding for (W80, W104) {}
impl ValidLevelEmbedding for (W80, W112) {}
impl ValidLevelEmbedding for (W80, W120) {}
impl ValidLevelEmbedding for (W80, W128) {}
impl ValidLevelEmbedding for (W88, W88) {}
impl ValidLevelEmbedding for (W88, W96) {}
impl ValidLevelEmbedding for (W88, W104) {}
impl ValidLevelEmbedding for (W88, W112) {}
impl ValidLevelEmbedding for (W88, W120) {}
impl ValidLevelEmbedding for (W88, W128) {}
impl ValidLevelEmbedding for (W96, W96) {}
impl ValidLevelEmbedding for (W96, W104) {}
impl ValidLevelEmbedding for (W96, W112) {}
impl ValidLevelEmbedding for (W96, W120) {}
impl ValidLevelEmbedding for (W96, W128) {}
impl ValidLevelEmbedding for (W104, W104) {}
impl ValidLevelEmbedding for (W104, W112) {}
impl ValidLevelEmbedding for (W104, W120) {}
impl ValidLevelEmbedding for (W104, W128) {}
impl ValidLevelEmbedding for (W112, W112) {}
impl ValidLevelEmbedding for (W112, W120) {}
impl ValidLevelEmbedding for (W112, W128) {}
impl ValidLevelEmbedding for (W120, W120) {}
impl ValidLevelEmbedding for (W120, W128) {}
impl ValidLevelEmbedding for (W128, W128) {}
#[derive(Debug, Default, Clone, Copy)]
pub struct Embed<From, To>(PhantomData<(From, To)>);
impl Embed<W8, W8> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u8 {
value
}
}
impl Embed<W8, W16> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u16 {
value as u16
}
}
impl Embed<W8, W24> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u32 {
value as u32
}
}
impl Embed<W8, W32> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u32 {
value as u32
}
}
impl Embed<W8, W40> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u64 {
value as u64
}
}
impl Embed<W8, W48> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u64 {
value as u64
}
}
impl Embed<W8, W56> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u64 {
value as u64
}
}
impl Embed<W8, W64> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u64 {
value as u64
}
}
impl Embed<W8, W72> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u128 {
value as u128
}
}
impl Embed<W8, W80> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u128 {
value as u128
}
}
impl Embed<W8, W88> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u128 {
value as u128
}
}
impl Embed<W8, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u128 {
value as u128
}
}
impl Embed<W8, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u128 {
value as u128
}
}
impl Embed<W8, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u128 {
value as u128
}
}
impl Embed<W8, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u128 {
value as u128
}
}
impl Embed<W8, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u8) -> u128 {
value as u128
}
}
impl Embed<W16, W16> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u16 {
value
}
}
impl Embed<W16, W24> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u32 {
value as u32
}
}
impl Embed<W16, W32> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u32 {
value as u32
}
}
impl Embed<W16, W40> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u64 {
value as u64
}
}
impl Embed<W16, W48> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u64 {
value as u64
}
}
impl Embed<W16, W56> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u64 {
value as u64
}
}
impl Embed<W16, W64> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u64 {
value as u64
}
}
impl Embed<W16, W72> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u128 {
value as u128
}
}
impl Embed<W16, W80> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u128 {
value as u128
}
}
impl Embed<W16, W88> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u128 {
value as u128
}
}
impl Embed<W16, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u128 {
value as u128
}
}
impl Embed<W16, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u128 {
value as u128
}
}
impl Embed<W16, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u128 {
value as u128
}
}
impl Embed<W16, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u128 {
value as u128
}
}
impl Embed<W16, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u16) -> u128 {
value as u128
}
}
impl Embed<W24, W24> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u32 {
value
}
}
impl Embed<W24, W32> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u32 {
value
}
}
impl Embed<W24, W40> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u64 {
value as u64
}
}
impl Embed<W24, W48> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u64 {
value as u64
}
}
impl Embed<W24, W56> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u64 {
value as u64
}
}
impl Embed<W24, W64> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u64 {
value as u64
}
}
impl Embed<W24, W72> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W24, W80> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W24, W88> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W24, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W24, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W24, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W24, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W24, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W32, W32> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u32 {
value
}
}
impl Embed<W32, W40> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u64 {
value as u64
}
}
impl Embed<W32, W48> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u64 {
value as u64
}
}
impl Embed<W32, W56> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u64 {
value as u64
}
}
impl Embed<W32, W64> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u64 {
value as u64
}
}
impl Embed<W32, W72> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W32, W80> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W32, W88> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W32, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W32, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W32, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W32, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W32, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u32) -> u128 {
value as u128
}
}
impl Embed<W40, W40> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u64 {
value
}
}
impl Embed<W40, W48> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u64 {
value
}
}
impl Embed<W40, W56> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u64 {
value
}
}
impl Embed<W40, W64> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u64 {
value
}
}
impl Embed<W40, W72> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W40, W80> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W40, W88> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W40, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W40, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W40, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W40, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W40, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W48, W48> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u64 {
value
}
}
impl Embed<W48, W56> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u64 {
value
}
}
impl Embed<W48, W64> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u64 {
value
}
}
impl Embed<W48, W72> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W48, W80> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W48, W88> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W48, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W48, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W48, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W48, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W48, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W56, W56> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u64 {
value
}
}
impl Embed<W56, W64> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u64 {
value
}
}
impl Embed<W56, W72> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W56, W80> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W56, W88> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W56, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W56, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W56, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W56, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W56, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W64, W64> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u64 {
value
}
}
impl Embed<W64, W72> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W64, W80> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W64, W88> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W64, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W64, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W64, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W64, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W64, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u64) -> u128 {
value as u128
}
}
impl Embed<W72, W72> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W72, W80> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W72, W88> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W72, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W72, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W72, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W72, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W72, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W80, W80> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W80, W88> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W80, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W80, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W80, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W80, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W80, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W88, W88> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W88, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W88, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W88, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W88, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W88, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W96, W96> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W96, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W96, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W96, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W96, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W104, W104> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W104, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W104, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W104, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W112, W112> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W112, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W112, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W120, W120> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W120, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
impl Embed<W128, W128> {
#[inline]
#[must_use]
pub const fn apply(value: u128) -> u128 {
value
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct W160;
#[derive(Debug, Default, Clone, Copy)]
pub struct W192;
#[derive(Debug, Default, Clone, Copy)]
pub struct W224;
#[derive(Debug, Default, Clone, Copy)]
pub struct W256;
#[derive(Debug, Default, Clone, Copy)]
pub struct W384;
#[derive(Debug, Default, Clone, Copy)]
pub struct W448;
#[derive(Debug, Default, Clone, Copy)]
pub struct W512;
#[derive(Debug, Default, Clone, Copy)]
pub struct W520;
#[derive(Debug, Default, Clone, Copy)]
pub struct W528;
#[derive(Debug, Default, Clone, Copy)]
pub struct W1024;
#[derive(Debug, Default, Clone, Copy)]
pub struct W2048;
#[derive(Debug, Default, Clone, Copy)]
pub struct W4096;
#[derive(Debug, Default, Clone, Copy)]
pub struct W8192;
#[derive(Debug, Default, Clone, Copy)]
pub struct W12288;
#[derive(Debug, Default, Clone, Copy)]
pub struct W16384;
#[derive(Debug, Default, Clone, Copy)]
pub struct W32768;
impl RingOp<W160> for Mul<W160> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.wrapping_mul(b).mask_high_bits(160)
}
}
impl RingOp<W160> for Add<W160> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.wrapping_add(b).mask_high_bits(160)
}
}
impl RingOp<W160> for Sub<W160> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.wrapping_sub(b).mask_high_bits(160)
}
}
impl RingOp<W160> for Xor<W160> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.xor(b).mask_high_bits(160)
}
}
impl RingOp<W160> for And<W160> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.and(b).mask_high_bits(160)
}
}
impl RingOp<W160> for Or<W160> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.or(b).mask_high_bits(160)
}
}
impl UnaryRingOp<W160> for Neg<W160> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>) -> Limbs<3> {
(Limbs::<3>::zero().wrapping_sub(a)).mask_high_bits(160)
}
}
impl UnaryRingOp<W160> for BNot<W160> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>) -> Limbs<3> {
(a.not()).mask_high_bits(160)
}
}
impl UnaryRingOp<W160> for Succ<W160> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>) -> Limbs<3> {
(a.wrapping_add(Limbs::<3>::from_words([1u64, 0u64, 0u64]))).mask_high_bits(160)
}
}
impl RingOp<W192> for Mul<W192> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.wrapping_mul(b)
}
}
impl RingOp<W192> for Add<W192> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.wrapping_add(b)
}
}
impl RingOp<W192> for Sub<W192> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.wrapping_sub(b)
}
}
impl RingOp<W192> for Xor<W192> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.xor(b)
}
}
impl RingOp<W192> for And<W192> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.and(b)
}
}
impl RingOp<W192> for Or<W192> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
a.or(b)
}
}
impl UnaryRingOp<W192> for Neg<W192> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>) -> Limbs<3> {
Limbs::<3>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W192> for BNot<W192> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>) -> Limbs<3> {
a.not()
}
}
impl UnaryRingOp<W192> for Succ<W192> {
type Operand = Limbs<3>;
#[inline]
fn apply(a: Limbs<3>) -> Limbs<3> {
a.wrapping_add(Limbs::<3>::from_words([1u64, 0u64, 0u64]))
}
}
impl RingOp<W224> for Mul<W224> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.wrapping_mul(b).mask_high_bits(224)
}
}
impl RingOp<W224> for Add<W224> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.wrapping_add(b).mask_high_bits(224)
}
}
impl RingOp<W224> for Sub<W224> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.wrapping_sub(b).mask_high_bits(224)
}
}
impl RingOp<W224> for Xor<W224> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.xor(b).mask_high_bits(224)
}
}
impl RingOp<W224> for And<W224> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.and(b).mask_high_bits(224)
}
}
impl RingOp<W224> for Or<W224> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.or(b).mask_high_bits(224)
}
}
impl UnaryRingOp<W224> for Neg<W224> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>) -> Limbs<4> {
(Limbs::<4>::zero().wrapping_sub(a)).mask_high_bits(224)
}
}
impl UnaryRingOp<W224> for BNot<W224> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>) -> Limbs<4> {
(a.not()).mask_high_bits(224)
}
}
impl UnaryRingOp<W224> for Succ<W224> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>) -> Limbs<4> {
(a.wrapping_add(Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64]))).mask_high_bits(224)
}
}
impl RingOp<W256> for Mul<W256> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.wrapping_mul(b)
}
}
impl RingOp<W256> for Add<W256> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.wrapping_add(b)
}
}
impl RingOp<W256> for Sub<W256> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.wrapping_sub(b)
}
}
impl RingOp<W256> for Xor<W256> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.xor(b)
}
}
impl RingOp<W256> for And<W256> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.and(b)
}
}
impl RingOp<W256> for Or<W256> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
a.or(b)
}
}
impl UnaryRingOp<W256> for Neg<W256> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>) -> Limbs<4> {
Limbs::<4>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W256> for BNot<W256> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>) -> Limbs<4> {
a.not()
}
}
impl UnaryRingOp<W256> for Succ<W256> {
type Operand = Limbs<4>;
#[inline]
fn apply(a: Limbs<4>) -> Limbs<4> {
a.wrapping_add(Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64]))
}
}
impl RingOp<W384> for Mul<W384> {
type Operand = Limbs<6>;
#[inline]
fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
a.wrapping_mul(b)
}
}
impl RingOp<W384> for Add<W384> {
type Operand = Limbs<6>;
#[inline]
fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
a.wrapping_add(b)
}
}
impl RingOp<W384> for Sub<W384> {
type Operand = Limbs<6>;
#[inline]
fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
a.wrapping_sub(b)
}
}
impl RingOp<W384> for Xor<W384> {
type Operand = Limbs<6>;
#[inline]
fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
a.xor(b)
}
}
impl RingOp<W384> for And<W384> {
type Operand = Limbs<6>;
#[inline]
fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
a.and(b)
}
}
impl RingOp<W384> for Or<W384> {
type Operand = Limbs<6>;
#[inline]
fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
a.or(b)
}
}
impl UnaryRingOp<W384> for Neg<W384> {
type Operand = Limbs<6>;
#[inline]
fn apply(a: Limbs<6>) -> Limbs<6> {
Limbs::<6>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W384> for BNot<W384> {
type Operand = Limbs<6>;
#[inline]
fn apply(a: Limbs<6>) -> Limbs<6> {
a.not()
}
}
impl UnaryRingOp<W384> for Succ<W384> {
type Operand = Limbs<6>;
#[inline]
fn apply(a: Limbs<6>) -> Limbs<6> {
a.wrapping_add(Limbs::<6>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64]))
}
}
impl RingOp<W448> for Mul<W448> {
type Operand = Limbs<7>;
#[inline]
fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
a.wrapping_mul(b)
}
}
impl RingOp<W448> for Add<W448> {
type Operand = Limbs<7>;
#[inline]
fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
a.wrapping_add(b)
}
}
impl RingOp<W448> for Sub<W448> {
type Operand = Limbs<7>;
#[inline]
fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
a.wrapping_sub(b)
}
}
impl RingOp<W448> for Xor<W448> {
type Operand = Limbs<7>;
#[inline]
fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
a.xor(b)
}
}
impl RingOp<W448> for And<W448> {
type Operand = Limbs<7>;
#[inline]
fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
a.and(b)
}
}
impl RingOp<W448> for Or<W448> {
type Operand = Limbs<7>;
#[inline]
fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
a.or(b)
}
}
impl UnaryRingOp<W448> for Neg<W448> {
type Operand = Limbs<7>;
#[inline]
fn apply(a: Limbs<7>) -> Limbs<7> {
Limbs::<7>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W448> for BNot<W448> {
type Operand = Limbs<7>;
#[inline]
fn apply(a: Limbs<7>) -> Limbs<7> {
a.not()
}
}
impl UnaryRingOp<W448> for Succ<W448> {
type Operand = Limbs<7>;
#[inline]
fn apply(a: Limbs<7>) -> Limbs<7> {
a.wrapping_add(Limbs::<7>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
]))
}
}
impl RingOp<W512> for Mul<W512> {
type Operand = Limbs<8>;
#[inline]
fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
a.wrapping_mul(b)
}
}
impl RingOp<W512> for Add<W512> {
type Operand = Limbs<8>;
#[inline]
fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
a.wrapping_add(b)
}
}
impl RingOp<W512> for Sub<W512> {
type Operand = Limbs<8>;
#[inline]
fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
a.wrapping_sub(b)
}
}
impl RingOp<W512> for Xor<W512> {
type Operand = Limbs<8>;
#[inline]
fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
a.xor(b)
}
}
impl RingOp<W512> for And<W512> {
type Operand = Limbs<8>;
#[inline]
fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
a.and(b)
}
}
impl RingOp<W512> for Or<W512> {
type Operand = Limbs<8>;
#[inline]
fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
a.or(b)
}
}
impl UnaryRingOp<W512> for Neg<W512> {
type Operand = Limbs<8>;
#[inline]
fn apply(a: Limbs<8>) -> Limbs<8> {
Limbs::<8>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W512> for BNot<W512> {
type Operand = Limbs<8>;
#[inline]
fn apply(a: Limbs<8>) -> Limbs<8> {
a.not()
}
}
impl UnaryRingOp<W512> for Succ<W512> {
type Operand = Limbs<8>;
#[inline]
fn apply(a: Limbs<8>) -> Limbs<8> {
a.wrapping_add(Limbs::<8>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
]))
}
}
impl RingOp<W520> for Mul<W520> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.wrapping_mul(b).mask_high_bits(520)
}
}
impl RingOp<W520> for Add<W520> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.wrapping_add(b).mask_high_bits(520)
}
}
impl RingOp<W520> for Sub<W520> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.wrapping_sub(b).mask_high_bits(520)
}
}
impl RingOp<W520> for Xor<W520> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.xor(b).mask_high_bits(520)
}
}
impl RingOp<W520> for And<W520> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.and(b).mask_high_bits(520)
}
}
impl RingOp<W520> for Or<W520> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.or(b).mask_high_bits(520)
}
}
impl UnaryRingOp<W520> for Neg<W520> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>) -> Limbs<9> {
(Limbs::<9>::zero().wrapping_sub(a)).mask_high_bits(520)
}
}
impl UnaryRingOp<W520> for BNot<W520> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>) -> Limbs<9> {
(a.not()).mask_high_bits(520)
}
}
impl UnaryRingOp<W520> for Succ<W520> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>) -> Limbs<9> {
(a.wrapping_add(Limbs::<9>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
])))
.mask_high_bits(520)
}
}
impl RingOp<W528> for Mul<W528> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.wrapping_mul(b).mask_high_bits(528)
}
}
impl RingOp<W528> for Add<W528> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.wrapping_add(b).mask_high_bits(528)
}
}
impl RingOp<W528> for Sub<W528> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.wrapping_sub(b).mask_high_bits(528)
}
}
impl RingOp<W528> for Xor<W528> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.xor(b).mask_high_bits(528)
}
}
impl RingOp<W528> for And<W528> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.and(b).mask_high_bits(528)
}
}
impl RingOp<W528> for Or<W528> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
a.or(b).mask_high_bits(528)
}
}
impl UnaryRingOp<W528> for Neg<W528> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>) -> Limbs<9> {
(Limbs::<9>::zero().wrapping_sub(a)).mask_high_bits(528)
}
}
impl UnaryRingOp<W528> for BNot<W528> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>) -> Limbs<9> {
(a.not()).mask_high_bits(528)
}
}
impl UnaryRingOp<W528> for Succ<W528> {
type Operand = Limbs<9>;
#[inline]
fn apply(a: Limbs<9>) -> Limbs<9> {
(a.wrapping_add(Limbs::<9>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
])))
.mask_high_bits(528)
}
}
impl RingOp<W1024> for Mul<W1024> {
type Operand = Limbs<16>;
#[inline]
fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
a.wrapping_mul(b)
}
}
impl RingOp<W1024> for Add<W1024> {
type Operand = Limbs<16>;
#[inline]
fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
a.wrapping_add(b)
}
}
impl RingOp<W1024> for Sub<W1024> {
type Operand = Limbs<16>;
#[inline]
fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
a.wrapping_sub(b)
}
}
impl RingOp<W1024> for Xor<W1024> {
type Operand = Limbs<16>;
#[inline]
fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
a.xor(b)
}
}
impl RingOp<W1024> for And<W1024> {
type Operand = Limbs<16>;
#[inline]
fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
a.and(b)
}
}
impl RingOp<W1024> for Or<W1024> {
type Operand = Limbs<16>;
#[inline]
fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
a.or(b)
}
}
impl UnaryRingOp<W1024> for Neg<W1024> {
type Operand = Limbs<16>;
#[inline]
fn apply(a: Limbs<16>) -> Limbs<16> {
Limbs::<16>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W1024> for BNot<W1024> {
type Operand = Limbs<16>;
#[inline]
fn apply(a: Limbs<16>) -> Limbs<16> {
a.not()
}
}
impl UnaryRingOp<W1024> for Succ<W1024> {
type Operand = Limbs<16>;
#[inline]
fn apply(a: Limbs<16>) -> Limbs<16> {
a.wrapping_add(Limbs::<16>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64,
]))
}
}
impl RingOp<W2048> for Mul<W2048> {
type Operand = Limbs<32>;
#[inline]
fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
a.wrapping_mul(b)
}
}
impl RingOp<W2048> for Add<W2048> {
type Operand = Limbs<32>;
#[inline]
fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
a.wrapping_add(b)
}
}
impl RingOp<W2048> for Sub<W2048> {
type Operand = Limbs<32>;
#[inline]
fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
a.wrapping_sub(b)
}
}
impl RingOp<W2048> for Xor<W2048> {
type Operand = Limbs<32>;
#[inline]
fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
a.xor(b)
}
}
impl RingOp<W2048> for And<W2048> {
type Operand = Limbs<32>;
#[inline]
fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
a.and(b)
}
}
impl RingOp<W2048> for Or<W2048> {
type Operand = Limbs<32>;
#[inline]
fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
a.or(b)
}
}
impl UnaryRingOp<W2048> for Neg<W2048> {
type Operand = Limbs<32>;
#[inline]
fn apply(a: Limbs<32>) -> Limbs<32> {
Limbs::<32>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W2048> for BNot<W2048> {
type Operand = Limbs<32>;
#[inline]
fn apply(a: Limbs<32>) -> Limbs<32> {
a.not()
}
}
impl UnaryRingOp<W2048> for Succ<W2048> {
type Operand = Limbs<32>;
#[inline]
fn apply(a: Limbs<32>) -> Limbs<32> {
a.wrapping_add(Limbs::<32>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64,
]))
}
}
impl RingOp<W4096> for Mul<W4096> {
type Operand = Limbs<64>;
#[inline]
fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
a.wrapping_mul(b)
}
}
impl RingOp<W4096> for Add<W4096> {
type Operand = Limbs<64>;
#[inline]
fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
a.wrapping_add(b)
}
}
impl RingOp<W4096> for Sub<W4096> {
type Operand = Limbs<64>;
#[inline]
fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
a.wrapping_sub(b)
}
}
impl RingOp<W4096> for Xor<W4096> {
type Operand = Limbs<64>;
#[inline]
fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
a.xor(b)
}
}
impl RingOp<W4096> for And<W4096> {
type Operand = Limbs<64>;
#[inline]
fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
a.and(b)
}
}
impl RingOp<W4096> for Or<W4096> {
type Operand = Limbs<64>;
#[inline]
fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
a.or(b)
}
}
impl UnaryRingOp<W4096> for Neg<W4096> {
type Operand = Limbs<64>;
#[inline]
fn apply(a: Limbs<64>) -> Limbs<64> {
Limbs::<64>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W4096> for BNot<W4096> {
type Operand = Limbs<64>;
#[inline]
fn apply(a: Limbs<64>) -> Limbs<64> {
a.not()
}
}
impl UnaryRingOp<W4096> for Succ<W4096> {
type Operand = Limbs<64>;
#[inline]
fn apply(a: Limbs<64>) -> Limbs<64> {
a.wrapping_add(Limbs::<64>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
]))
}
}
impl RingOp<W8192> for Mul<W8192> {
type Operand = Limbs<128>;
#[inline]
fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
a.wrapping_mul(b)
}
}
impl RingOp<W8192> for Add<W8192> {
type Operand = Limbs<128>;
#[inline]
fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
a.wrapping_add(b)
}
}
impl RingOp<W8192> for Sub<W8192> {
type Operand = Limbs<128>;
#[inline]
fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
a.wrapping_sub(b)
}
}
impl RingOp<W8192> for Xor<W8192> {
type Operand = Limbs<128>;
#[inline]
fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
a.xor(b)
}
}
impl RingOp<W8192> for And<W8192> {
type Operand = Limbs<128>;
#[inline]
fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
a.and(b)
}
}
impl RingOp<W8192> for Or<W8192> {
type Operand = Limbs<128>;
#[inline]
fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
a.or(b)
}
}
impl UnaryRingOp<W8192> for Neg<W8192> {
type Operand = Limbs<128>;
#[inline]
fn apply(a: Limbs<128>) -> Limbs<128> {
Limbs::<128>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W8192> for BNot<W8192> {
type Operand = Limbs<128>;
#[inline]
fn apply(a: Limbs<128>) -> Limbs<128> {
a.not()
}
}
impl UnaryRingOp<W8192> for Succ<W8192> {
type Operand = Limbs<128>;
#[inline]
fn apply(a: Limbs<128>) -> Limbs<128> {
a.wrapping_add(Limbs::<128>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64,
]))
}
}
impl RingOp<W12288> for Mul<W12288> {
type Operand = Limbs<192>;
#[inline]
fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
a.wrapping_mul(b)
}
}
impl RingOp<W12288> for Add<W12288> {
type Operand = Limbs<192>;
#[inline]
fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
a.wrapping_add(b)
}
}
impl RingOp<W12288> for Sub<W12288> {
type Operand = Limbs<192>;
#[inline]
fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
a.wrapping_sub(b)
}
}
impl RingOp<W12288> for Xor<W12288> {
type Operand = Limbs<192>;
#[inline]
fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
a.xor(b)
}
}
impl RingOp<W12288> for And<W12288> {
type Operand = Limbs<192>;
#[inline]
fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
a.and(b)
}
}
impl RingOp<W12288> for Or<W12288> {
type Operand = Limbs<192>;
#[inline]
fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
a.or(b)
}
}
impl UnaryRingOp<W12288> for Neg<W12288> {
type Operand = Limbs<192>;
#[inline]
fn apply(a: Limbs<192>) -> Limbs<192> {
Limbs::<192>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W12288> for BNot<W12288> {
type Operand = Limbs<192>;
#[inline]
fn apply(a: Limbs<192>) -> Limbs<192> {
a.not()
}
}
impl UnaryRingOp<W12288> for Succ<W12288> {
type Operand = Limbs<192>;
#[inline]
fn apply(a: Limbs<192>) -> Limbs<192> {
a.wrapping_add(Limbs::<192>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
]))
}
}
impl RingOp<W16384> for Mul<W16384> {
type Operand = Limbs<256>;
#[inline]
fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
a.wrapping_mul(b)
}
}
impl RingOp<W16384> for Add<W16384> {
type Operand = Limbs<256>;
#[inline]
fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
a.wrapping_add(b)
}
}
impl RingOp<W16384> for Sub<W16384> {
type Operand = Limbs<256>;
#[inline]
fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
a.wrapping_sub(b)
}
}
impl RingOp<W16384> for Xor<W16384> {
type Operand = Limbs<256>;
#[inline]
fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
a.xor(b)
}
}
impl RingOp<W16384> for And<W16384> {
type Operand = Limbs<256>;
#[inline]
fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
a.and(b)
}
}
impl RingOp<W16384> for Or<W16384> {
type Operand = Limbs<256>;
#[inline]
fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
a.or(b)
}
}
impl UnaryRingOp<W16384> for Neg<W16384> {
type Operand = Limbs<256>;
#[inline]
fn apply(a: Limbs<256>) -> Limbs<256> {
Limbs::<256>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W16384> for BNot<W16384> {
type Operand = Limbs<256>;
#[inline]
fn apply(a: Limbs<256>) -> Limbs<256> {
a.not()
}
}
impl UnaryRingOp<W16384> for Succ<W16384> {
type Operand = Limbs<256>;
#[inline]
fn apply(a: Limbs<256>) -> Limbs<256> {
a.wrapping_add(Limbs::<256>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64,
]))
}
}
impl RingOp<W32768> for Mul<W32768> {
type Operand = Limbs<512>;
#[inline]
fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
a.wrapping_mul(b)
}
}
impl RingOp<W32768> for Add<W32768> {
type Operand = Limbs<512>;
#[inline]
fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
a.wrapping_add(b)
}
}
impl RingOp<W32768> for Sub<W32768> {
type Operand = Limbs<512>;
#[inline]
fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
a.wrapping_sub(b)
}
}
impl RingOp<W32768> for Xor<W32768> {
type Operand = Limbs<512>;
#[inline]
fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
a.xor(b)
}
}
impl RingOp<W32768> for And<W32768> {
type Operand = Limbs<512>;
#[inline]
fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
a.and(b)
}
}
impl RingOp<W32768> for Or<W32768> {
type Operand = Limbs<512>;
#[inline]
fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
a.or(b)
}
}
impl UnaryRingOp<W32768> for Neg<W32768> {
type Operand = Limbs<512>;
#[inline]
fn apply(a: Limbs<512>) -> Limbs<512> {
Limbs::<512>::zero().wrapping_sub(a)
}
}
impl UnaryRingOp<W32768> for BNot<W32768> {
type Operand = Limbs<512>;
#[inline]
fn apply(a: Limbs<512>) -> Limbs<512> {
a.not()
}
}
impl UnaryRingOp<W32768> for Succ<W32768> {
type Operand = Limbs<512>;
#[inline]
fn apply(a: Limbs<512>) -> Limbs<512> {
a.wrapping_add(Limbs::<512>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
]))
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w160(op: PrimitiveOp, a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
let raw = match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<3>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_3()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_3()),
};
raw.mask_high_bits(160)
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w192(op: PrimitiveOp, a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<3>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_3()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_3()),
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w224(op: PrimitiveOp, a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
let raw = match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<4>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_4()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_4()),
};
raw.mask_high_bits(224)
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w256(op: PrimitiveOp, a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<4>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_4()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_4()),
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w384(op: PrimitiveOp, a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<6>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_6()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_6()),
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w448(op: PrimitiveOp, a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<7>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_7()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_7()),
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w512(op: PrimitiveOp, a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<8>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_8()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_8()),
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w520(op: PrimitiveOp, a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
let raw = match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<9>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_9()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_9()),
};
raw.mask_high_bits(520)
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w528(op: PrimitiveOp, a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
let raw = match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<9>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_9()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_9()),
};
raw.mask_high_bits(528)
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w1024(op: PrimitiveOp, a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<16>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_16()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_16()),
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w2048(op: PrimitiveOp, a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<32>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_32()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_32()),
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w4096(op: PrimitiveOp, a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<64>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_64()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_64()),
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w8192(op: PrimitiveOp, a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<128>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_128()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_128()),
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w12288(op: PrimitiveOp, a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<192>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_192()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_192()),
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w16384(op: PrimitiveOp, a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<256>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_256()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_256()),
}
}
#[inline]
#[must_use]
pub const fn const_ring_eval_w32768(op: PrimitiveOp, a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
match op {
PrimitiveOp::Add => a.wrapping_add(b),
PrimitiveOp::Sub => a.wrapping_sub(b),
PrimitiveOp::Mul => a.wrapping_mul(b),
PrimitiveOp::And => a.and(b),
PrimitiveOp::Or => a.or(b),
PrimitiveOp::Xor => a.xor(b),
PrimitiveOp::Neg => Limbs::<512>::zero().wrapping_sub(a),
PrimitiveOp::Bnot => a.not(),
PrimitiveOp::Succ => a.wrapping_add(limbs_one_512()),
PrimitiveOp::Pred => a.wrapping_sub(limbs_one_512()),
}
}
#[inline]
#[must_use]
const fn limbs_one_3() -> Limbs<3> {
Limbs::<3>::from_words([1u64, 0u64, 0u64])
}
#[inline]
#[must_use]
const fn limbs_one_4() -> Limbs<4> {
Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64])
}
#[inline]
#[must_use]
const fn limbs_one_6() -> Limbs<6> {
Limbs::<6>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64])
}
#[inline]
#[must_use]
const fn limbs_one_7() -> Limbs<7> {
Limbs::<7>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
}
#[inline]
#[must_use]
const fn limbs_one_8() -> Limbs<8> {
Limbs::<8>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
}
#[inline]
#[must_use]
const fn limbs_one_9() -> Limbs<9> {
Limbs::<9>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
}
#[inline]
#[must_use]
const fn limbs_one_16() -> Limbs<16> {
Limbs::<16>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64,
])
}
#[inline]
#[must_use]
const fn limbs_one_32() -> Limbs<32> {
Limbs::<32>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64,
])
}
#[inline]
#[must_use]
const fn limbs_one_64() -> Limbs<64> {
Limbs::<64>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64,
])
}
#[inline]
#[must_use]
const fn limbs_one_128() -> Limbs<128> {
Limbs::<128>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
])
}
#[inline]
#[must_use]
const fn limbs_one_192() -> Limbs<192> {
Limbs::<192>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
])
}
#[inline]
#[must_use]
const fn limbs_one_256() -> Limbs<256> {
Limbs::<256>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64,
])
}
#[inline]
#[must_use]
const fn limbs_one_512() -> Limbs<512> {
Limbs::<512>::from_words([
1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
0u64, 0u64,
])
}
pub trait FragmentMarker: fragment_sealed::Sealed {}
mod fragment_sealed {
pub trait Sealed {}
impl Sealed for super::Is2SatShape {}
impl Sealed for super::IsHornShape {}
impl Sealed for super::IsResidualFragment {}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct Is2SatShape;
impl FragmentMarker for Is2SatShape {}
#[derive(Debug, Default, Clone, Copy)]
pub struct IsHornShape;
impl FragmentMarker for IsHornShape {}
#[derive(Debug, Default, Clone, Copy)]
pub struct IsResidualFragment;
impl FragmentMarker for IsResidualFragment {}
#[derive(Debug, Clone, Copy)]
pub struct DispatchRule {
pub predicate_iri: &'static str,
pub target_resolver_iri: &'static str,
pub priority: u32,
}
pub type DispatchTable = &'static [DispatchRule];
pub const INHABITANCE_DISPATCH_TABLE: DispatchTable = &[
DispatchRule {
predicate_iri: "https://uor.foundation/predicate/Is2SatShape",
target_resolver_iri: "https://uor.foundation/resolver/TwoSatDecider",
priority: 0,
},
DispatchRule {
predicate_iri: "https://uor.foundation/predicate/IsHornShape",
target_resolver_iri: "https://uor.foundation/resolver/HornSatDecider",
priority: 1,
},
DispatchRule {
predicate_iri: "https://uor.foundation/predicate/IsResidualFragment",
target_resolver_iri: "https://uor.foundation/resolver/ResidualVerdictResolver",
priority: 2,
},
];
impl<T: OntologyTarget> core::ops::Deref for Validated<T> {
type Target = T;
#[inline]
fn deref(&self) -> &T {
&self.inner
}
}
mod bound_constraint_sealed {
pub trait ObservableSealed {}
pub trait BoundShapeSealed {}
}
pub trait Observable: bound_constraint_sealed::ObservableSealed {
const IRI: &'static str;
}
pub trait BoundShape: bound_constraint_sealed::BoundShapeSealed {
const IRI: &'static str;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct ValueModObservable;
impl bound_constraint_sealed::ObservableSealed for ValueModObservable {}
impl Observable for ValueModObservable {
const IRI: &'static str = "https://uor.foundation/observable/ValueModObservable";
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct HammingMetric;
impl bound_constraint_sealed::ObservableSealed for HammingMetric {}
impl Observable for HammingMetric {
const IRI: &'static str = "https://uor.foundation/observable/HammingMetric";
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct DerivationDepthObservable;
impl bound_constraint_sealed::ObservableSealed for DerivationDepthObservable {}
impl Observable for DerivationDepthObservable {
const IRI: &'static str = "https://uor.foundation/derivation/DerivationDepthObservable";
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct CarryDepthObservable;
impl bound_constraint_sealed::ObservableSealed for CarryDepthObservable {}
impl Observable for CarryDepthObservable {
const IRI: &'static str = "https://uor.foundation/carry/CarryDepthObservable";
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct FreeRankObservable;
impl bound_constraint_sealed::ObservableSealed for FreeRankObservable {}
impl Observable for FreeRankObservable {
const IRI: &'static str = "https://uor.foundation/partition/FreeRankObservable";
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct EqualBound;
impl bound_constraint_sealed::BoundShapeSealed for EqualBound {}
impl BoundShape for EqualBound {
const IRI: &'static str = "https://uor.foundation/type/EqualBound";
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct LessEqBound;
impl bound_constraint_sealed::BoundShapeSealed for LessEqBound {}
impl BoundShape for LessEqBound {
const IRI: &'static str = "https://uor.foundation/type/LessEqBound";
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct GreaterEqBound;
impl bound_constraint_sealed::BoundShapeSealed for GreaterEqBound {}
impl BoundShape for GreaterEqBound {
const IRI: &'static str = "https://uor.foundation/type/GreaterEqBound";
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct RangeContainBound;
impl bound_constraint_sealed::BoundShapeSealed for RangeContainBound {}
impl BoundShape for RangeContainBound {
const IRI: &'static str = "https://uor.foundation/type/RangeContainBound";
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct ResidueClassBound;
impl bound_constraint_sealed::BoundShapeSealed for ResidueClassBound {}
impl BoundShape for ResidueClassBound {
const IRI: &'static str = "https://uor.foundation/type/ResidueClassBound";
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct AffineEqualBound;
impl bound_constraint_sealed::BoundShapeSealed for AffineEqualBound {}
impl BoundShape for AffineEqualBound {
const IRI: &'static str = "https://uor.foundation/type/AffineEqualBound";
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BoundArgValue {
U64(u64),
I64(i64),
Bytes32([u8; 32]),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BoundArguments {
entries: [Option<BoundArgEntry>; 8],
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BoundArgEntry {
pub name: &'static str,
pub value: BoundArgValue,
}
impl BoundArguments {
#[inline]
#[must_use]
pub const fn empty() -> Self {
Self { entries: [None; 8] }
}
#[inline]
#[must_use]
pub const fn single(name: &'static str, value: BoundArgValue) -> Self {
let mut entries = [None; 8];
entries[0] = Some(BoundArgEntry { name, value });
Self { entries }
}
#[inline]
#[must_use]
pub const fn pair(
first: (&'static str, BoundArgValue),
second: (&'static str, BoundArgValue),
) -> Self {
let mut entries = [None; 8];
entries[0] = Some(BoundArgEntry {
name: first.0,
value: first.1,
});
entries[1] = Some(BoundArgEntry {
name: second.0,
value: second.1,
});
Self { entries }
}
#[inline]
#[must_use]
pub const fn entries(&self) -> &[Option<BoundArgEntry>; 8] {
&self.entries
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BoundConstraint<O: Observable, B: BoundShape> {
observable: O,
bound: B,
args: BoundArguments,
_sealed: (),
}
impl<O: Observable, B: BoundShape> BoundConstraint<O, B> {
#[inline]
#[must_use]
pub(crate) const fn from_parts(observable: O, bound: B, args: BoundArguments) -> Self {
Self {
observable,
bound,
args,
_sealed: (),
}
}
#[inline]
#[must_use]
pub const fn observable(&self) -> &O {
&self.observable
}
#[inline]
#[must_use]
pub const fn bound(&self) -> &B {
&self.bound
}
#[inline]
#[must_use]
pub const fn args(&self) -> &BoundArguments {
&self.args
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Conjunction<const N: usize> {
len: usize,
_sealed: (),
}
impl<const N: usize> Conjunction<N> {
#[inline]
#[must_use]
pub const fn new(len: usize) -> Self {
Self { len, _sealed: () }
}
#[inline]
#[must_use]
pub const fn len(&self) -> usize {
self.len
}
#[inline]
#[must_use]
pub const fn is_empty(&self) -> bool {
self.len == 0
}
}
pub type ResidueConstraint = BoundConstraint<ValueModObservable, ResidueClassBound>;
impl ResidueConstraint {
#[inline]
#[must_use]
pub const fn new(modulus: u64, residue: u64) -> Self {
let args = BoundArguments::pair(
("modulus", BoundArgValue::U64(modulus)),
("residue", BoundArgValue::U64(residue)),
);
BoundConstraint::from_parts(ValueModObservable, ResidueClassBound, args)
}
}
pub type HammingConstraint = BoundConstraint<HammingMetric, LessEqBound>;
impl HammingConstraint {
#[inline]
#[must_use]
pub const fn new(bound: u64) -> Self {
let args = BoundArguments::single("bound", BoundArgValue::U64(bound));
BoundConstraint::from_parts(HammingMetric, LessEqBound, args)
}
}
pub type DepthConstraint = BoundConstraint<DerivationDepthObservable, LessEqBound>;
impl DepthConstraint {
#[inline]
#[must_use]
pub const fn new(min_depth: u64, max_depth: u64) -> Self {
let args = BoundArguments::pair(
("min_depth", BoundArgValue::U64(min_depth)),
("max_depth", BoundArgValue::U64(max_depth)),
);
BoundConstraint::from_parts(DerivationDepthObservable, LessEqBound, args)
}
}
pub type CarryConstraint = BoundConstraint<CarryDepthObservable, LessEqBound>;
impl CarryConstraint {
#[inline]
#[must_use]
pub const fn new(bound: u64) -> Self {
let args = BoundArguments::single("bound", BoundArgValue::U64(bound));
BoundConstraint::from_parts(CarryDepthObservable, LessEqBound, args)
}
}
pub type SiteConstraint = BoundConstraint<FreeRankObservable, LessEqBound>;
impl SiteConstraint {
#[inline]
#[must_use]
pub const fn new(site_index: u64) -> Self {
let args = BoundArguments::single("site_index", BoundArgValue::U64(site_index));
BoundConstraint::from_parts(FreeRankObservable, LessEqBound, args)
}
}
pub type AffineConstraint = BoundConstraint<ValueModObservable, AffineEqualBound>;
impl AffineConstraint {
#[inline]
#[must_use]
pub const fn new(offset: u64) -> Self {
let args = BoundArguments::single("offset", BoundArgValue::U64(offset));
BoundConstraint::from_parts(ValueModObservable, AffineEqualBound, args)
}
}
pub type CompositeConstraint<const N: usize> = Conjunction<N>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Query {
address: ContentAddress,
_sealed: (),
}
impl Query {
#[inline]
#[must_use]
pub const fn address(&self) -> ContentAddress {
self.address
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(address: ContentAddress) -> Self {
Self {
address,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Coordinate<L> {
stratum: u64,
spectrum: u64,
address: u64,
_level: PhantomData<L>,
_sealed: (),
}
impl<L> Coordinate<L> {
#[inline]
#[must_use]
pub const fn stratum(&self) -> u64 {
self.stratum
}
#[inline]
#[must_use]
pub const fn spectrum(&self) -> u64 {
self.spectrum
}
#[inline]
#[must_use]
pub const fn address(&self) -> u64 {
self.address
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(stratum: u64, spectrum: u64, address: u64) -> Self {
Self {
stratum,
spectrum,
address,
_level: PhantomData,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BindingQuery {
address: ContentAddress,
_sealed: (),
}
impl BindingQuery {
#[inline]
#[must_use]
pub const fn address(&self) -> ContentAddress {
self.address
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(address: ContentAddress) -> Self {
Self {
address,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Partition {
component: PartitionComponent,
_sealed: (),
}
impl Partition {
#[inline]
#[must_use]
pub const fn component(&self) -> PartitionComponent {
self.component
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(component: PartitionComponent) -> Self {
Self {
component,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TraceEvent {
step_index: u32,
op: PrimitiveOp,
target: ContentAddress,
_sealed: (),
}
impl TraceEvent {
#[inline]
#[must_use]
pub const fn step_index(&self) -> u32 {
self.step_index
}
#[inline]
#[must_use]
pub const fn op(&self) -> PrimitiveOp {
self.op
}
#[inline]
#[must_use]
pub const fn target(&self) -> ContentAddress {
self.target
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(step_index: u32, op: PrimitiveOp, target: ContentAddress) -> Self {
Self {
step_index,
op,
target,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct Trace<const TR_MAX: usize = 256> {
events: [Option<TraceEvent>; TR_MAX],
len: u16,
witt_level_bits: u16,
content_fingerprint: ContentFingerprint,
_sealed: (),
}
impl<const TR_MAX: usize> Trace<TR_MAX> {
#[inline]
#[must_use]
pub const fn empty() -> Self {
Self {
events: [None; TR_MAX],
len: 0,
witt_level_bits: 0,
content_fingerprint: ContentFingerprint::zero(),
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn from_replay_events_const(
events: [Option<TraceEvent>; TR_MAX],
len: u16,
witt_level_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Self {
Self {
events,
len,
witt_level_bits,
content_fingerprint,
_sealed: (),
}
}
#[inline]
#[must_use]
pub const fn len(&self) -> u16 {
self.len
}
#[inline]
#[must_use]
pub const fn is_empty(&self) -> bool {
self.len == 0
}
#[inline]
#[must_use]
pub fn event(&self, index: usize) -> Option<&TraceEvent> {
self.events.get(index).and_then(|e| e.as_ref())
}
#[inline]
#[must_use]
pub const fn witt_level_bits(&self) -> u16 {
self.witt_level_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
pub fn try_from_events(
events: &[TraceEvent],
witt_level_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Result<Self, ReplayError> {
if events.is_empty() {
return Err(ReplayError::EmptyTrace);
}
if events.len() > TR_MAX {
return Err(ReplayError::CapacityExceeded {
declared: TR_MAX as u16,
provided: events.len() as u32,
});
}
let mut i = 0usize;
while i < events.len() {
let e = &events[i];
if e.step_index() as usize != i {
return Err(ReplayError::OutOfOrderEvent { index: i });
}
if e.target().is_zero() {
return Err(ReplayError::ZeroTarget { index: i });
}
i += 1;
}
let mut arr = [None; TR_MAX];
let mut j = 0usize;
while j < events.len() {
arr[j] = Some(events[j]);
j += 1;
}
Ok(Self {
events: arr,
len: events.len() as u16,
witt_level_bits,
content_fingerprint,
_sealed: (),
})
}
}
impl<const TR_MAX: usize> Default for Trace<TR_MAX> {
#[inline]
fn default() -> Self {
Self::empty()
}
}
impl Derivation {
#[inline]
#[must_use]
pub fn replay<const TR_MAX: usize>(&self) -> Trace<TR_MAX> {
let steps = self.step_count() as usize;
let len = if steps > TR_MAX { TR_MAX } else { steps };
let mut events = [None; TR_MAX];
let fp = self.content_fingerprint.as_bytes();
let seed =
u64::from_be_bytes([fp[0], fp[1], fp[2], fp[3], fp[4], fp[5], fp[6], fp[7]]) as u128;
let nonzero_seed = seed | 1u128;
let mut i = 0usize;
while i < len {
let target_raw = nonzero_seed ^ ((i as u128) + 1u128);
events[i] = Some(TraceEvent::new(
i as u32,
crate::PrimitiveOp::Add,
ContentAddress::from_u128(target_raw),
));
i += 1;
}
Trace::from_replay_events_const(
events,
len as u16,
self.witt_level_bits,
self.content_fingerprint,
)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ReplayError {
EmptyTrace,
OutOfOrderEvent {
index: usize,
},
ZeroTarget {
index: usize,
},
NonContiguousSteps {
declared: u16,
last_step: u32,
},
CapacityExceeded {
declared: u16,
provided: u32,
},
}
impl core::fmt::Display for ReplayError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::EmptyTrace => f.write_str("trace was empty; nothing to replay"),
Self::OutOfOrderEvent { index } => write!(
f,
"event at index {index} has out-of-order step index",
),
Self::ZeroTarget { index } => write!(
f,
"event at index {index} has a zero ContentAddress target",
),
Self::NonContiguousSteps { declared, last_step } => write!(
f,
"trace declares {declared} events but step indices skip values \
(last step {last_step})",
),
Self::CapacityExceeded { declared, provided } => write!(
f,
"trace capacity exceeded: tried to pack {provided} events into a buffer of {declared}",
),
}
}
}
impl core::error::Error for ReplayError {}
pub mod replay {
use super::{Certified, GroundingCertificate, ReplayError, Trace};
pub fn certify_from_trace<const TR_MAX: usize>(
trace: &Trace<TR_MAX>,
) -> Result<Certified<GroundingCertificate>, ReplayError> {
let len = trace.len() as usize;
if len == 0 {
return Err(ReplayError::EmptyTrace);
}
let mut last_step: i64 = -1;
let mut max_step_index: u32 = 0;
let mut i = 0usize;
while i < len {
let event = match trace.event(i) {
Some(e) => e,
None => return Err(ReplayError::OutOfOrderEvent { index: i }),
};
let step_index = event.step_index();
if (step_index as i64) <= last_step {
return Err(ReplayError::OutOfOrderEvent { index: i });
}
if event.target().is_zero() {
return Err(ReplayError::ZeroTarget { index: i });
}
if step_index > max_step_index {
max_step_index = step_index;
}
last_step = step_index as i64;
i += 1;
}
if (max_step_index as u16).saturating_add(1) != trace.len() {
return Err(ReplayError::NonContiguousSteps {
declared: trace.len(),
last_step: max_step_index,
});
}
Ok(Certified::new(
GroundingCertificate::with_level_and_fingerprint_const(
trace.witt_level_bits(),
trace.content_fingerprint(),
),
))
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct InteractionDeclarationBuilder {
peer_protocol: Option<u128>,
convergence_predicate: Option<u128>,
commutator_state_class: Option<u128>,
}
impl InteractionDeclarationBuilder {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self {
peer_protocol: None,
convergence_predicate: None,
commutator_state_class: None,
}
}
#[inline]
#[must_use]
pub const fn peer_protocol(mut self, address: u128) -> Self {
self.peer_protocol = Some(address);
self
}
#[inline]
#[must_use]
pub const fn convergence_predicate(mut self, address: u128) -> Self {
self.convergence_predicate = Some(address);
self
}
#[inline]
#[must_use]
pub const fn commutator_state_class(mut self, address: u128) -> Self {
self.commutator_state_class = Some(address);
self
}
pub fn validate(&self) -> Result<Validated<InteractionShape>, ShapeViolation> {
self.validate_common().map(|_| {
Validated::new(InteractionShape {
shape_iri: "https://uor.foundation/conformance/InteractionShape",
})
})
}
pub const fn validate_const(
&self,
) -> Result<Validated<InteractionShape, CompileTime>, ShapeViolation> {
if self.peer_protocol.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/InteractionShape",
constraint_iri: "https://uor.foundation/conformance/InteractionShape",
property_iri: "https://uor.foundation/interaction/peerProtocol",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.convergence_predicate.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/InteractionShape",
constraint_iri: "https://uor.foundation/conformance/InteractionShape",
property_iri: "https://uor.foundation/interaction/convergencePredicate",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
if self.commutator_state_class.is_none() {
return Err(ShapeViolation {
shape_iri: "https://uor.foundation/conformance/InteractionShape",
constraint_iri: "https://uor.foundation/conformance/InteractionShape",
property_iri: "https://uor.foundation/interaction/commutatorStateClass",
expected_range: "http://www.w3.org/2002/07/owl#Thing",
min_count: 1,
max_count: 1,
kind: ViolationKind::Missing,
});
}
Ok(Validated::new(InteractionShape {
shape_iri: "https://uor.foundation/conformance/InteractionShape",
}))
}
fn validate_common(&self) -> Result<(), ShapeViolation> {
self.validate_const().map(|_| ())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct InteractionShape {
pub shape_iri: &'static str,
}
#[cfg(feature = "observability")]
pub fn subscribe_trace_events<F>(handler: F) -> ObservabilitySubscription<F>
where
F: FnMut(&TraceEvent),
{
ObservabilitySubscription {
handler,
_sealed: (),
}
}
#[cfg(feature = "observability")]
#[cfg(feature = "observability")]
pub struct ObservabilitySubscription<F: FnMut(&TraceEvent)> {
handler: F,
_sealed: (),
}
#[cfg(feature = "observability")]
impl<F: FnMut(&TraceEvent)> ObservabilitySubscription<F> {
pub fn emit(&mut self, event: &TraceEvent) {
(self.handler)(event);
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ConstraintKind {
Residue,
Carry,
Depth,
Hamming,
Site,
Affine,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CarryProfile {
chain_length: u32,
max_depth: u32,
_sealed: (),
}
impl CarryProfile {
#[inline]
#[must_use]
pub const fn chain_length(&self) -> u32 {
self.chain_length
}
#[inline]
#[must_use]
pub const fn max_depth(&self) -> u32 {
self.max_depth
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(chain_length: u32, max_depth: u32) -> Self {
Self {
chain_length,
max_depth,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CarryEvent {
left_bits: u16,
right_bits: u16,
_sealed: (),
}
impl CarryEvent {
#[inline]
#[must_use]
pub const fn left_bits(&self) -> u16 {
self.left_bits
}
#[inline]
#[must_use]
pub const fn right_bits(&self) -> u16 {
self.right_bits
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(left_bits: u16, right_bits: u16) -> Self {
Self {
left_bits,
right_bits,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ConvergenceLevel<L> {
valuation: u32,
_level: PhantomData<L>,
_sealed: (),
}
impl<L> ConvergenceLevel<L> {
#[inline]
#[must_use]
pub const fn valuation(&self) -> u32 {
self.valuation
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(valuation: u32) -> Self {
Self {
valuation,
_level: PhantomData,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum DivisionAlgebraWitness {
Real,
Complex,
Quaternion,
Octonion,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MonoidalProduct<L, R> {
_left: PhantomData<L>,
_right: PhantomData<R>,
_sealed: (),
}
impl<L, R> MonoidalProduct<L, R> {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new() -> Self {
Self {
_left: PhantomData,
_right: PhantomData,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MonoidalUnit<L> {
_level: PhantomData<L>,
_sealed: (),
}
impl<L> MonoidalUnit<L> {
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new() -> Self {
Self {
_level: PhantomData,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct OperadComposition {
outer_type_iri: &'static str,
inner_type_iri: &'static str,
composed_site_count: u32,
_sealed: (),
}
impl OperadComposition {
#[inline]
#[must_use]
pub const fn outer_type_iri(&self) -> &'static str {
self.outer_type_iri
}
#[inline]
#[must_use]
pub const fn inner_type_iri(&self) -> &'static str {
self.inner_type_iri
}
#[inline]
#[must_use]
pub const fn composed_site_count(&self) -> u32 {
self.composed_site_count
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(
outer_type_iri: &'static str,
inner_type_iri: &'static str,
composed_site_count: u32,
) -> Self {
Self {
outer_type_iri,
inner_type_iri,
composed_site_count,
_sealed: (),
}
}
}
pub const RECURSION_TRACE_MAX_DEPTH: usize = 16;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct RecursionTrace {
depth: u32,
measure: [u32; RECURSION_TRACE_MAX_DEPTH],
_sealed: (),
}
impl RecursionTrace {
#[inline]
#[must_use]
pub const fn depth(&self) -> u32 {
self.depth
}
#[inline]
#[must_use]
pub const fn measure(&self) -> &[u32; RECURSION_TRACE_MAX_DEPTH] {
&self.measure
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(depth: u32, measure: [u32; RECURSION_TRACE_MAX_DEPTH]) -> Self {
Self {
depth,
measure,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct AddressRegion {
base: u128,
extent: u64,
_sealed: (),
}
impl AddressRegion {
#[inline]
#[must_use]
pub const fn base(&self) -> u128 {
self.base
}
#[inline]
#[must_use]
pub const fn extent(&self) -> u64 {
self.extent
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(base: u128, extent: u64) -> Self {
Self {
base,
extent,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct LinearBudget {
sites_remaining: u64,
_sealed: (),
}
impl LinearBudget {
#[inline]
#[must_use]
pub const fn sites_remaining(&self) -> u64 {
self.sites_remaining
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(sites_remaining: u64) -> Self {
Self {
sites_remaining,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct LeaseAllocation {
site_count: u32,
scope_hash: u128,
_sealed: (),
}
impl LeaseAllocation {
#[inline]
#[must_use]
pub const fn site_count(&self) -> u32 {
self.site_count
}
#[inline]
#[must_use]
pub const fn scope_hash(&self) -> u128 {
self.scope_hash
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn new(site_count: u32, scope_hash: u128) -> Self {
Self {
site_count,
scope_hash,
_sealed: (),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct TotalMarker;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct InvertibleMarker;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct PreservesStructureMarker;
mod marker_tuple_sealed {
pub trait Sealed {}
}
pub trait MarkerTuple: marker_tuple_sealed::Sealed {}
impl marker_tuple_sealed::Sealed for () {}
impl MarkerTuple for () {}
impl marker_tuple_sealed::Sealed for (TotalMarker,) {}
impl MarkerTuple for (TotalMarker,) {}
impl marker_tuple_sealed::Sealed for (TotalMarker, InvertibleMarker) {}
impl MarkerTuple for (TotalMarker, InvertibleMarker) {}
impl marker_tuple_sealed::Sealed for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {}
impl MarkerTuple for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {}
impl marker_tuple_sealed::Sealed for (InvertibleMarker,) {}
impl MarkerTuple for (InvertibleMarker,) {}
impl marker_tuple_sealed::Sealed for (InvertibleMarker, PreservesStructureMarker) {}
impl MarkerTuple for (InvertibleMarker, PreservesStructureMarker) {}
pub trait MarkerIntersection<Other: MarkerTuple>: MarkerTuple {
type Output: MarkerTuple;
}
impl MarkerIntersection<()> for () {
type Output = ();
}
impl MarkerIntersection<(TotalMarker,)> for () {
type Output = ();
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for () {
type Output = ();
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)> for () {
type Output = ();
}
impl MarkerIntersection<(InvertibleMarker,)> for () {
type Output = ();
}
impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for () {
type Output = ();
}
impl MarkerIntersection<()> for (TotalMarker,) {
type Output = ();
}
impl MarkerIntersection<(TotalMarker,)> for (TotalMarker,) {
type Output = (TotalMarker,);
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (TotalMarker,) {
type Output = (TotalMarker,);
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
for (TotalMarker,)
{
type Output = (TotalMarker,);
}
impl MarkerIntersection<(InvertibleMarker,)> for (TotalMarker,) {
type Output = ();
}
impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for (TotalMarker,) {
type Output = ();
}
impl MarkerIntersection<()> for (TotalMarker, InvertibleMarker) {
type Output = ();
}
impl MarkerIntersection<(TotalMarker,)> for (TotalMarker, InvertibleMarker) {
type Output = (TotalMarker,);
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (TotalMarker, InvertibleMarker) {
type Output = (TotalMarker, InvertibleMarker);
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
for (TotalMarker, InvertibleMarker)
{
type Output = (TotalMarker, InvertibleMarker);
}
impl MarkerIntersection<(InvertibleMarker,)> for (TotalMarker, InvertibleMarker) {
type Output = (InvertibleMarker,);
}
impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
for (TotalMarker, InvertibleMarker)
{
type Output = (InvertibleMarker,);
}
impl MarkerIntersection<()> for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {
type Output = ();
}
impl MarkerIntersection<(TotalMarker,)>
for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
{
type Output = (TotalMarker,);
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker)>
for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
{
type Output = (TotalMarker, InvertibleMarker);
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
{
type Output = (TotalMarker, InvertibleMarker, PreservesStructureMarker);
}
impl MarkerIntersection<(InvertibleMarker,)>
for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
{
type Output = (InvertibleMarker,);
}
impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
{
type Output = (InvertibleMarker, PreservesStructureMarker);
}
impl MarkerIntersection<()> for (InvertibleMarker,) {
type Output = ();
}
impl MarkerIntersection<(TotalMarker,)> for (InvertibleMarker,) {
type Output = ();
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (InvertibleMarker,) {
type Output = (InvertibleMarker,);
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
for (InvertibleMarker,)
{
type Output = (InvertibleMarker,);
}
impl MarkerIntersection<(InvertibleMarker,)> for (InvertibleMarker,) {
type Output = (InvertibleMarker,);
}
impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for (InvertibleMarker,) {
type Output = (InvertibleMarker,);
}
impl MarkerIntersection<()> for (InvertibleMarker, PreservesStructureMarker) {
type Output = ();
}
impl MarkerIntersection<(TotalMarker,)> for (InvertibleMarker, PreservesStructureMarker) {
type Output = ();
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker)>
for (InvertibleMarker, PreservesStructureMarker)
{
type Output = (InvertibleMarker,);
}
impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
for (InvertibleMarker, PreservesStructureMarker)
{
type Output = (InvertibleMarker, PreservesStructureMarker);
}
impl MarkerIntersection<(InvertibleMarker,)> for (InvertibleMarker, PreservesStructureMarker) {
type Output = (InvertibleMarker,);
}
impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
for (InvertibleMarker, PreservesStructureMarker)
{
type Output = (InvertibleMarker, PreservesStructureMarker);
}
pub trait MarkersImpliedBy<Map: GroundingMapKind>: MarkerTuple {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MarkerBits(u8);
impl MarkerBits {
pub const TOTAL: Self = Self(1);
pub const INVERTIBLE: Self = Self(2);
pub const PRESERVES_STRUCTURE: Self = Self(4);
pub const NONE: Self = Self(0);
#[inline]
#[must_use]
pub const fn from_u8(bits: u8) -> Self {
Self(bits)
}
#[inline]
#[must_use]
pub const fn as_u8(&self) -> u8 {
self.0
}
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0 & other.0)
}
#[inline]
#[must_use]
pub const fn contains(&self, other: Self) -> bool {
(self.0 & other.0) == other.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum GroundingPrimitiveOp {
ReadBytes,
InterpretLeInteger,
InterpretBeInteger,
Digest,
DecodeUtf8,
DecodeJson,
SelectField,
SelectIndex,
ConstValue,
Then,
MapErr,
AndThen,
}
pub const MAX_OP_CHAIN_DEPTH: usize = 8;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GroundingPrimitive<Out, Markers: MarkerTuple = ()> {
op: GroundingPrimitiveOp,
markers: MarkerBits,
chain: [GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH],
chain_len: u8,
_out: PhantomData<Out>,
_markers: PhantomData<Markers>,
_sealed: (),
}
impl<Out, Markers: MarkerTuple> GroundingPrimitive<Out, Markers> {
#[inline]
#[must_use]
pub const fn op(&self) -> GroundingPrimitiveOp {
self.op
}
#[inline]
#[must_use]
pub const fn markers(&self) -> MarkerBits {
self.markers
}
#[inline]
#[must_use]
pub fn chain(&self) -> &[GroundingPrimitiveOp] {
&self.chain[..self.chain_len as usize]
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn from_parts(op: GroundingPrimitiveOp, markers: MarkerBits) -> Self {
Self {
op,
markers,
chain: [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH],
chain_len: 0,
_out: PhantomData,
_markers: PhantomData,
_sealed: (),
}
}
#[inline]
#[must_use]
#[allow(dead_code)]
pub(crate) const fn from_parts_with_chain(
op: GroundingPrimitiveOp,
markers: MarkerBits,
chain: [GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH],
chain_len: u8,
) -> Self {
Self {
op,
markers,
chain,
chain_len,
_out: PhantomData,
_markers: PhantomData,
_sealed: (),
}
}
}
pub mod combinators {
use super::{
GroundingPrimitive, GroundingPrimitiveOp, InvertibleMarker, MarkerBits, MarkerIntersection,
MarkerTuple, PreservesStructureMarker, TotalMarker, MAX_OP_CHAIN_DEPTH,
};
fn compose_chain<A, B, MA: MarkerTuple, MB: MarkerTuple>(
first: &GroundingPrimitive<A, MA>,
second: &GroundingPrimitive<B, MB>,
) -> ([GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH], u8) {
let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
let mut len: usize = 0;
for &op in first.chain() {
if len >= MAX_OP_CHAIN_DEPTH {
return (chain, len as u8);
}
chain[len] = op;
len += 1;
}
if len < MAX_OP_CHAIN_DEPTH {
chain[len] = first.op();
len += 1;
}
for &op in second.chain() {
if len >= MAX_OP_CHAIN_DEPTH {
return (chain, len as u8);
}
chain[len] = op;
len += 1;
}
if len < MAX_OP_CHAIN_DEPTH {
chain[len] = second.op();
len += 1;
}
(chain, len as u8)
}
fn map_err_chain<A, M: MarkerTuple>(
first: &GroundingPrimitive<A, M>,
) -> ([GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH], u8) {
let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
let mut len: usize = 0;
for &op in first.chain() {
if len >= MAX_OP_CHAIN_DEPTH {
return (chain, len as u8);
}
chain[len] = op;
len += 1;
}
if len < MAX_OP_CHAIN_DEPTH {
chain[len] = first.op();
len += 1;
}
(chain, len as u8)
}
#[inline]
#[must_use]
pub const fn read_bytes<Out>() -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker)> {
GroundingPrimitive::from_parts(
GroundingPrimitiveOp::ReadBytes,
MarkerBits::TOTAL.union(MarkerBits::INVERTIBLE),
)
}
#[inline]
#[must_use]
pub const fn interpret_le_integer<Out>(
) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
GroundingPrimitive::from_parts(
GroundingPrimitiveOp::InterpretLeInteger,
MarkerBits::TOTAL
.union(MarkerBits::INVERTIBLE)
.union(MarkerBits::PRESERVES_STRUCTURE),
)
}
#[inline]
#[must_use]
pub const fn interpret_be_integer<Out>(
) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
GroundingPrimitive::from_parts(
GroundingPrimitiveOp::InterpretBeInteger,
MarkerBits::TOTAL
.union(MarkerBits::INVERTIBLE)
.union(MarkerBits::PRESERVES_STRUCTURE),
)
}
#[inline]
#[must_use]
pub const fn digest<Out>() -> GroundingPrimitive<Out, (TotalMarker,)> {
GroundingPrimitive::from_parts(GroundingPrimitiveOp::Digest, MarkerBits::TOTAL)
}
#[inline]
#[must_use]
pub const fn decode_utf8<Out>(
) -> GroundingPrimitive<Out, (InvertibleMarker, PreservesStructureMarker)> {
GroundingPrimitive::from_parts(
GroundingPrimitiveOp::DecodeUtf8,
MarkerBits::INVERTIBLE.union(MarkerBits::PRESERVES_STRUCTURE),
)
}
#[inline]
#[must_use]
pub const fn decode_json<Out>(
) -> GroundingPrimitive<Out, (InvertibleMarker, PreservesStructureMarker)> {
GroundingPrimitive::from_parts(
GroundingPrimitiveOp::DecodeJson,
MarkerBits::INVERTIBLE.union(MarkerBits::PRESERVES_STRUCTURE),
)
}
#[inline]
#[must_use]
pub const fn select_field<Out>() -> GroundingPrimitive<Out, (InvertibleMarker,)> {
GroundingPrimitive::from_parts(GroundingPrimitiveOp::SelectField, MarkerBits::INVERTIBLE)
}
#[inline]
#[must_use]
pub const fn select_index<Out>() -> GroundingPrimitive<Out, (InvertibleMarker,)> {
GroundingPrimitive::from_parts(GroundingPrimitiveOp::SelectIndex, MarkerBits::INVERTIBLE)
}
#[inline]
#[must_use]
pub const fn const_value<Out>(
) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
GroundingPrimitive::from_parts(
GroundingPrimitiveOp::ConstValue,
MarkerBits::TOTAL
.union(MarkerBits::INVERTIBLE)
.union(MarkerBits::PRESERVES_STRUCTURE),
)
}
#[inline]
#[must_use]
pub fn then<A, B, MA, MB>(
first: GroundingPrimitive<A, MA>,
second: GroundingPrimitive<B, MB>,
) -> GroundingPrimitive<B, <MA as MarkerIntersection<MB>>::Output>
where
MA: MarkerTuple + MarkerIntersection<MB>,
MB: MarkerTuple,
{
let (chain, chain_len) = compose_chain(&first, &second);
GroundingPrimitive::from_parts_with_chain(
GroundingPrimitiveOp::Then,
first.markers().intersection(second.markers()),
chain,
chain_len,
)
}
#[inline]
#[must_use]
pub fn map_err<A, M: MarkerTuple>(first: GroundingPrimitive<A, M>) -> GroundingPrimitive<A, M> {
let (chain, chain_len) = map_err_chain(&first);
GroundingPrimitive::from_parts_with_chain(
GroundingPrimitiveOp::MapErr,
first.markers(),
chain,
chain_len,
)
}
#[inline]
#[must_use]
pub fn and_then<A, B, MA, MB>(
first: GroundingPrimitive<A, MA>,
second: GroundingPrimitive<B, MB>,
) -> GroundingPrimitive<B, <MA as MarkerIntersection<MB>>::Output>
where
MA: MarkerTuple + MarkerIntersection<MB>,
MB: MarkerTuple,
{
let (chain, chain_len) = compose_chain(&first, &second);
GroundingPrimitive::from_parts_with_chain(
GroundingPrimitiveOp::AndThen,
first.markers().intersection(second.markers()),
chain,
chain_len,
)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GroundingProgram<Out, Map: GroundingMapKind> {
primitive: GroundingPrimitive<Out>,
_map: PhantomData<Map>,
_sealed: (),
}
impl<Out, Map: GroundingMapKind> GroundingProgram<Out, Map> {
#[inline]
#[must_use]
pub fn from_primitive<Markers>(primitive: GroundingPrimitive<Out, Markers>) -> Self
where
Markers: MarkerTuple + MarkersImpliedBy<Map>,
{
let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
let src = primitive.chain();
let mut i = 0;
while i < src.len() && i < MAX_OP_CHAIN_DEPTH {
chain[i] = src[i];
i += 1;
}
let erased = GroundingPrimitive::<Out, ()>::from_parts_with_chain(
primitive.op(),
primitive.markers(),
chain,
i as u8,
);
Self {
primitive: erased,
_map: PhantomData,
_sealed: (),
}
}
#[inline]
#[must_use]
pub const fn primitive(&self) -> &GroundingPrimitive<Out> {
&self.primitive
}
}
impl<Map: GroundingMapKind> GroundingProgram<GroundedCoord, Map> {
#[inline]
#[must_use]
pub fn run(&self, external: &[u8]) -> Option<GroundedCoord> {
match self.primitive.op() {
GroundingPrimitiveOp::Then | GroundingPrimitiveOp::AndThen => {
let chain = self.primitive.chain();
if chain.is_empty() {
return None;
}
let mut last: Option<GroundedCoord> = None;
for &op in chain {
match interpret_leaf_op(op, external) {
Some(c) => last = Some(c),
None => return None,
}
}
last
}
GroundingPrimitiveOp::MapErr => self
.primitive
.chain()
.first()
.and_then(|&op| interpret_leaf_op(op, external)),
leaf => interpret_leaf_op(leaf, external),
}
}
}
impl<const N: usize, Map: GroundingMapKind> GroundingProgram<GroundedTuple<N>, Map> {
#[inline]
#[must_use]
pub fn run(&self, external: &[u8]) -> Option<GroundedTuple<N>> {
if N == 0 || external.is_empty() || external.len() % N != 0 {
return None;
}
let window = external.len() / N;
let mut coords: [GroundedCoord; N] = [const { GroundedCoord::w8(0) }; N];
let mut i = 0usize;
while i < N {
let start = i * window;
let end = start + window;
let sub = &external[start..end];
let outcome = match self.primitive.op() {
GroundingPrimitiveOp::Then | GroundingPrimitiveOp::AndThen => {
let chain = self.primitive.chain();
if chain.is_empty() {
return None;
}
let mut last: Option<GroundedCoord> = None;
for &op in chain {
match interpret_leaf_op(op, sub) {
Some(c) => last = Some(c),
None => return None,
}
}
last
}
GroundingPrimitiveOp::MapErr => self
.primitive
.chain()
.first()
.and_then(|&op| interpret_leaf_op(op, sub)),
leaf => interpret_leaf_op(leaf, sub),
};
match outcome {
Some(c) => {
coords[i] = c;
}
None => {
return None;
}
}
i += 1;
}
Some(GroundedTuple::new(coords))
}
}
#[inline]
fn interpret_leaf_op(op: GroundingPrimitiveOp, external: &[u8]) -> Option<GroundedCoord> {
match op {
GroundingPrimitiveOp::ReadBytes | GroundingPrimitiveOp::InterpretLeInteger => {
external.first().map(|&b| GroundedCoord::w8(b))
}
GroundingPrimitiveOp::InterpretBeInteger => external.last().map(|&b| GroundedCoord::w8(b)),
GroundingPrimitiveOp::Digest => {
external.first().map(|&b| GroundedCoord::w8(b))
}
GroundingPrimitiveOp::DecodeUtf8 => {
match external.first() {
Some(&b) if b < 0x80 => Some(GroundedCoord::w8(b)),
_ => None,
}
}
GroundingPrimitiveOp::DecodeJson => {
match external.first() {
Some(&b) if b == b'-' || b.is_ascii_digit() => Some(GroundedCoord::w8(b)),
_ => None,
}
}
GroundingPrimitiveOp::ConstValue => Some(GroundedCoord::w8(0)),
GroundingPrimitiveOp::SelectField | GroundingPrimitiveOp::SelectIndex => {
external.first().map(|&b| GroundedCoord::w8(b))
}
GroundingPrimitiveOp::Then
| GroundingPrimitiveOp::AndThen
| GroundingPrimitiveOp::MapErr => {
None
}
}
}
impl MarkersImpliedBy<DigestGroundingMap> for (TotalMarker,) {}
impl MarkersImpliedBy<BinaryGroundingMap> for (TotalMarker, InvertibleMarker) {}
impl MarkersImpliedBy<DigestGroundingMap> for (TotalMarker, InvertibleMarker) {}
impl MarkersImpliedBy<BinaryGroundingMap>
for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
{
}
impl MarkersImpliedBy<DigestGroundingMap>
for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
{
}
impl MarkersImpliedBy<IntegerGroundingMap>
for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
{
}
impl MarkersImpliedBy<JsonGroundingMap>
for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
{
}
impl MarkersImpliedBy<Utf8GroundingMap>
for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
{
}
impl MarkersImpliedBy<JsonGroundingMap> for (InvertibleMarker, PreservesStructureMarker) {}
impl MarkersImpliedBy<Utf8GroundingMap> for (InvertibleMarker, PreservesStructureMarker) {}
#[doc(hidden)]
pub mod __test_helpers {
use super::{ContentAddress, ContentFingerprint, MulContext, Trace, TraceEvent, Validated};
#[must_use]
pub fn trace_from_events<const TR_MAX: usize>(events: &[TraceEvent]) -> Trace<TR_MAX> {
trace_with_fingerprint(events, 0, ContentFingerprint::zero())
}
#[must_use]
pub fn trace_with_fingerprint<const TR_MAX: usize>(
events: &[TraceEvent],
witt_level_bits: u16,
content_fingerprint: ContentFingerprint,
) -> Trace<TR_MAX> {
let mut arr = [None; TR_MAX];
let n = events.len().min(TR_MAX);
let mut i = 0;
while i < n {
arr[i] = Some(events[i]);
i += 1;
}
Trace::from_replay_events_const(arr, n as u16, witt_level_bits, content_fingerprint)
}
#[must_use]
pub fn trace_event(step_index: u32, target: u128) -> TraceEvent {
TraceEvent::new(
step_index,
crate::PrimitiveOp::Add,
ContentAddress::from_u128(target),
)
}
#[must_use]
pub fn mul_context(stack_budget_bytes: u64, const_eval: bool, limb_count: usize) -> MulContext {
MulContext::new(stack_budget_bytes, const_eval, limb_count)
}
#[must_use]
pub fn validated_runtime<T>(inner: T) -> Validated<T> {
Validated::new(inner)
}
}
type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
#[inline]
const fn pc_entropy_tolerance(expected: DefaultDecimal) -> DefaultDecimal {
let magnitude = if expected < 0.0 { -expected } else { expected };
let scale = if magnitude > 1.0 { magnitude } else { 1.0 };
1024.0 * <DefaultDecimal>::EPSILON * scale
}
#[inline]
fn pc_entropy_input_is_valid(value: DefaultDecimal) -> bool {
value.is_finite() && value >= 0.0
}
#[inline]
fn pc_entropy_additivity_holds(actual: DefaultDecimal, expected: DefaultDecimal) -> bool {
if !pc_entropy_input_is_valid(actual) || !pc_entropy_input_is_valid(expected) {
return false;
}
let diff = actual - expected;
let diff_abs = if diff < 0.0 { -diff } else { diff };
diff_abs <= pc_entropy_tolerance(expected)
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PartitionProductEvidence {
pub left_site_budget: u16,
pub right_site_budget: u16,
pub left_total_site_count: u16,
pub right_total_site_count: u16,
pub left_euler: i32,
pub right_euler: i32,
pub left_entropy_nats_bits: u64,
pub right_entropy_nats_bits: u64,
pub source_witness_fingerprint: ContentFingerprint,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PartitionCoproductEvidence {
pub left_site_budget: u16,
pub right_site_budget: u16,
pub left_total_site_count: u16,
pub right_total_site_count: u16,
pub left_euler: i32,
pub right_euler: i32,
pub left_entropy_nats_bits: u64,
pub right_entropy_nats_bits: u64,
pub left_betti: [u32; MAX_BETTI_DIMENSION],
pub right_betti: [u32; MAX_BETTI_DIMENSION],
pub source_witness_fingerprint: ContentFingerprint,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct CartesianProductEvidence {
pub left_site_budget: u16,
pub right_site_budget: u16,
pub left_total_site_count: u16,
pub right_total_site_count: u16,
pub left_euler: i32,
pub right_euler: i32,
pub left_betti: [u32; MAX_BETTI_DIMENSION],
pub right_betti: [u32; MAX_BETTI_DIMENSION],
pub left_entropy_nats_bits: u64,
pub right_entropy_nats_bits: u64,
pub combined_entropy_nats_bits: u64,
pub source_witness_fingerprint: ContentFingerprint,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PartitionProductMintInputs {
pub witt_bits: u16,
pub left_fingerprint: ContentFingerprint,
pub right_fingerprint: ContentFingerprint,
pub left_site_budget: u16,
pub right_site_budget: u16,
pub left_total_site_count: u16,
pub right_total_site_count: u16,
pub left_euler: i32,
pub right_euler: i32,
pub left_entropy_nats_bits: u64,
pub right_entropy_nats_bits: u64,
pub combined_site_budget: u16,
pub combined_site_count: u16,
pub combined_euler: i32,
pub combined_entropy_nats_bits: u64,
pub combined_fingerprint: ContentFingerprint,
}
#[derive(Debug, Clone, Copy)]
pub struct PartitionCoproductMintInputs {
pub witt_bits: u16,
pub left_fingerprint: ContentFingerprint,
pub right_fingerprint: ContentFingerprint,
pub left_site_budget: u16,
pub right_site_budget: u16,
pub left_total_site_count: u16,
pub right_total_site_count: u16,
pub left_euler: i32,
pub right_euler: i32,
pub left_entropy_nats_bits: u64,
pub right_entropy_nats_bits: u64,
pub left_betti: [u32; MAX_BETTI_DIMENSION],
pub right_betti: [u32; MAX_BETTI_DIMENSION],
pub combined_site_budget: u16,
pub combined_site_count: u16,
pub combined_euler: i32,
pub combined_entropy_nats_bits: u64,
pub combined_betti: [u32; MAX_BETTI_DIMENSION],
pub combined_fingerprint: ContentFingerprint,
pub combined_constraints: &'static [crate::pipeline::ConstraintRef],
pub left_constraint_count: usize,
pub tag_site: u16,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct CartesianProductMintInputs {
pub witt_bits: u16,
pub left_fingerprint: ContentFingerprint,
pub right_fingerprint: ContentFingerprint,
pub left_site_budget: u16,
pub right_site_budget: u16,
pub left_total_site_count: u16,
pub right_total_site_count: u16,
pub left_euler: i32,
pub right_euler: i32,
pub left_betti: [u32; MAX_BETTI_DIMENSION],
pub right_betti: [u32; MAX_BETTI_DIMENSION],
pub left_entropy_nats_bits: u64,
pub right_entropy_nats_bits: u64,
pub combined_site_budget: u16,
pub combined_site_count: u16,
pub combined_euler: i32,
pub combined_betti: [u32; MAX_BETTI_DIMENSION],
pub combined_entropy_nats_bits: u64,
pub combined_fingerprint: ContentFingerprint,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PartitionProductWitness {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
left_fingerprint: ContentFingerprint,
right_fingerprint: ContentFingerprint,
combined_site_budget: u16,
combined_site_count: u16,
}
impl PartitionProductWitness {
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
#[inline]
#[must_use]
pub const fn left_fingerprint(&self) -> ContentFingerprint {
self.left_fingerprint
}
#[inline]
#[must_use]
pub const fn right_fingerprint(&self) -> ContentFingerprint {
self.right_fingerprint
}
#[inline]
#[must_use]
pub const fn combined_site_budget(&self) -> u16 {
self.combined_site_budget
}
#[inline]
#[must_use]
pub const fn combined_site_count(&self) -> u16 {
self.combined_site_count
}
#[inline]
#[must_use]
#[allow(clippy::too_many_arguments)]
pub(crate) const fn with_level_fingerprints_and_sites(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
left_fingerprint: ContentFingerprint,
right_fingerprint: ContentFingerprint,
combined_site_budget: u16,
combined_site_count: u16,
) -> Self {
Self {
witt_bits,
content_fingerprint,
left_fingerprint,
right_fingerprint,
combined_site_budget,
combined_site_count,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PartitionCoproductWitness {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
left_fingerprint: ContentFingerprint,
right_fingerprint: ContentFingerprint,
combined_site_budget: u16,
combined_site_count: u16,
tag_site_index: u16,
}
impl PartitionCoproductWitness {
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
#[inline]
#[must_use]
pub const fn left_fingerprint(&self) -> ContentFingerprint {
self.left_fingerprint
}
#[inline]
#[must_use]
pub const fn right_fingerprint(&self) -> ContentFingerprint {
self.right_fingerprint
}
#[inline]
#[must_use]
pub const fn combined_site_budget(&self) -> u16 {
self.combined_site_budget
}
#[inline]
#[must_use]
pub const fn combined_site_count(&self) -> u16 {
self.combined_site_count
}
#[inline]
#[must_use]
pub const fn tag_site_index(&self) -> u16 {
self.tag_site_index
}
#[inline]
#[must_use]
#[allow(clippy::too_many_arguments)]
pub(crate) const fn with_level_fingerprints_sites_and_tag(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
left_fingerprint: ContentFingerprint,
right_fingerprint: ContentFingerprint,
combined_site_budget: u16,
combined_site_count: u16,
tag_site_index: u16,
) -> Self {
Self {
witt_bits,
content_fingerprint,
left_fingerprint,
right_fingerprint,
combined_site_budget,
combined_site_count,
tag_site_index,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CartesianProductWitness {
witt_bits: u16,
content_fingerprint: ContentFingerprint,
left_fingerprint: ContentFingerprint,
right_fingerprint: ContentFingerprint,
combined_site_budget: u16,
combined_site_count: u16,
combined_euler: i32,
combined_betti: [u32; MAX_BETTI_DIMENSION],
}
impl CartesianProductWitness {
#[inline]
#[must_use]
pub const fn witt_bits(&self) -> u16 {
self.witt_bits
}
#[inline]
#[must_use]
pub const fn content_fingerprint(&self) -> ContentFingerprint {
self.content_fingerprint
}
#[inline]
#[must_use]
pub const fn left_fingerprint(&self) -> ContentFingerprint {
self.left_fingerprint
}
#[inline]
#[must_use]
pub const fn right_fingerprint(&self) -> ContentFingerprint {
self.right_fingerprint
}
#[inline]
#[must_use]
pub const fn combined_site_budget(&self) -> u16 {
self.combined_site_budget
}
#[inline]
#[must_use]
pub const fn combined_site_count(&self) -> u16 {
self.combined_site_count
}
#[inline]
#[must_use]
pub const fn combined_euler(&self) -> i32 {
self.combined_euler
}
#[inline]
#[must_use]
pub const fn combined_betti(&self) -> [u32; MAX_BETTI_DIMENSION] {
self.combined_betti
}
#[inline]
#[must_use]
#[allow(clippy::too_many_arguments)]
pub(crate) const fn with_level_fingerprints_and_invariants(
witt_bits: u16,
content_fingerprint: ContentFingerprint,
left_fingerprint: ContentFingerprint,
right_fingerprint: ContentFingerprint,
combined_site_budget: u16,
combined_site_count: u16,
combined_euler: i32,
combined_betti: [u32; MAX_BETTI_DIMENSION],
) -> Self {
Self {
witt_bits,
content_fingerprint,
left_fingerprint,
right_fingerprint,
combined_site_budget,
combined_site_count,
combined_euler,
combined_betti,
}
}
}
impl Certificate for PartitionProductWitness {
const IRI: &'static str = "https://uor.foundation/partition/PartitionProduct";
type Evidence = PartitionProductEvidence;
}
impl Certificate for PartitionCoproductWitness {
const IRI: &'static str = "https://uor.foundation/partition/PartitionCoproduct";
type Evidence = PartitionCoproductEvidence;
}
impl Certificate for CartesianProductWitness {
const IRI: &'static str = "https://uor.foundation/partition/CartesianPartitionProduct";
type Evidence = CartesianProductEvidence;
}
impl core::fmt::Display for PartitionProductWitness {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("PartitionProductWitness")
}
}
impl core::error::Error for PartitionProductWitness {}
impl core::fmt::Display for PartitionCoproductWitness {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("PartitionCoproductWitness")
}
}
impl core::error::Error for PartitionCoproductWitness {}
impl core::fmt::Display for CartesianProductWitness {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("CartesianProductWitness")
}
}
impl core::error::Error for CartesianProductWitness {}
pub trait VerifiedMint: Certificate {
type Inputs;
type Error;
fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error>
where
Self: Sized;
}
#[allow(clippy::too_many_arguments)]
fn pc_classify_constraint(
c: &crate::pipeline::ConstraintRef,
in_left_region: bool,
tag_site: u16,
max_depth: u32,
left_pins: &mut u32,
right_pins: &mut u32,
left_bias_ok: &mut bool,
right_bias_ok: &mut bool,
) -> Result<(), GenericImpossibilityWitness> {
match c {
crate::pipeline::ConstraintRef::Site { position } => {
if (*position as u16) >= tag_site {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/ST_6",
));
}
}
crate::pipeline::ConstraintRef::Carry { site } => {
if (*site as u16) >= tag_site {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/ST_6",
));
}
}
crate::pipeline::ConstraintRef::Affine {
coefficients,
coefficient_count,
bias,
} => {
let count = *coefficient_count as usize;
let mut nonzero_count: u32 = 0;
let mut nonzero_index: usize = 0;
let mut max_nonzero_index: usize = 0;
let mut i: usize = 0;
while i < count && i < crate::pipeline::AFFINE_MAX_COEFFS {
if coefficients[i] != 0 {
nonzero_count = nonzero_count.saturating_add(1);
nonzero_index = i;
if i > max_nonzero_index {
max_nonzero_index = i;
}
}
i += 1;
}
let touches_tag_site = nonzero_count > 0 && (max_nonzero_index as u16) >= tag_site;
let is_canonical_tag_pinner = nonzero_count == 1
&& (nonzero_index as u16) == tag_site
&& coefficients[nonzero_index] == 1;
if is_canonical_tag_pinner {
if *bias != 0 && *bias != -1 {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/foundation/CoproductTagEncoding",
));
}
if in_left_region {
*left_pins = left_pins.saturating_add(1);
if *bias != 0 {
*left_bias_ok = false;
}
} else {
*right_pins = right_pins.saturating_add(1);
if *bias != -1 {
*right_bias_ok = false;
}
}
} else if touches_tag_site {
let nonzero_only_at_tag_site =
nonzero_count == 1 && (nonzero_index as u16) == tag_site;
if nonzero_only_at_tag_site {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/foundation/CoproductTagEncoding",
));
} else {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/ST_6",
));
}
}
}
crate::pipeline::ConstraintRef::Conjunction {
conjuncts,
conjunct_count,
} => {
if max_depth == 0 {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/ST_6",
));
}
let count = *conjunct_count as usize;
let mut idx: usize = 0;
while idx < count && idx < crate::pipeline::CONJUNCTION_MAX_TERMS {
let lifted = conjuncts[idx].into_constraint();
pc_classify_constraint(
&lifted,
in_left_region,
tag_site,
max_depth - 1,
left_pins,
right_pins,
left_bias_ok,
right_bias_ok,
)?;
idx += 1;
}
}
crate::pipeline::ConstraintRef::Residue { .. }
| crate::pipeline::ConstraintRef::Hamming { .. }
| crate::pipeline::ConstraintRef::Depth { .. }
| crate::pipeline::ConstraintRef::SatClauses { .. }
| crate::pipeline::ConstraintRef::Bound { .. } => {
}
}
Ok(())
}
pub(crate) fn validate_coproduct_structure(
combined_constraints: &[crate::pipeline::ConstraintRef],
left_constraint_count: usize,
tag_site: u16,
) -> Result<(), GenericImpossibilityWitness> {
let mut left_pins: u32 = 0;
let mut right_pins: u32 = 0;
let mut left_bias_ok: bool = true;
let mut right_bias_ok: bool = true;
let mut idx: usize = 0;
while idx < combined_constraints.len() {
let in_left_region = idx < left_constraint_count;
pc_classify_constraint(
&combined_constraints[idx],
in_left_region,
tag_site,
NERVE_CONSTRAINTS_CAP as u32,
&mut left_pins,
&mut right_pins,
&mut left_bias_ok,
&mut right_bias_ok,
)?;
idx += 1;
}
if left_pins != 1 || right_pins != 1 {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/ST_6",
));
}
if !left_bias_ok || !right_bias_ok {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/ST_7",
));
}
Ok(())
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn pc_primitive_partition_product(
witt_bits: u16,
left_fingerprint: ContentFingerprint,
right_fingerprint: ContentFingerprint,
left_site_budget: u16,
right_site_budget: u16,
left_total_site_count: u16,
right_total_site_count: u16,
left_euler: i32,
right_euler: i32,
left_entropy_nats_bits: u64,
right_entropy_nats_bits: u64,
combined_site_budget: u16,
combined_site_count: u16,
combined_euler: i32,
combined_entropy_nats_bits: u64,
combined_fingerprint: ContentFingerprint,
) -> Result<PartitionProductWitness, GenericImpossibilityWitness> {
let left_entropy_nats =
<f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
let right_entropy_nats =
<f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
let combined_entropy_nats =
<f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
if combined_site_budget != left_site_budget.saturating_add(right_site_budget) {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/PT_1",
));
}
if combined_site_count != left_total_site_count.saturating_add(right_total_site_count) {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/foundation/ProductLayoutWidth",
));
}
if combined_euler != left_euler.saturating_add(right_euler) {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/PT_3",
));
}
if !pc_entropy_input_is_valid(left_entropy_nats)
|| !pc_entropy_input_is_valid(right_entropy_nats)
|| !pc_entropy_input_is_valid(combined_entropy_nats)
{
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/PT_4",
));
}
let expected_entropy = left_entropy_nats + right_entropy_nats;
if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/PT_4",
));
}
Ok(PartitionProductWitness::with_level_fingerprints_and_sites(
witt_bits,
combined_fingerprint,
left_fingerprint,
right_fingerprint,
combined_site_budget,
combined_site_count,
))
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn pc_primitive_partition_coproduct(
witt_bits: u16,
left_fingerprint: ContentFingerprint,
right_fingerprint: ContentFingerprint,
left_site_budget: u16,
right_site_budget: u16,
left_total_site_count: u16,
right_total_site_count: u16,
left_euler: i32,
right_euler: i32,
left_entropy_nats_bits: u64,
right_entropy_nats_bits: u64,
left_betti: [u32; MAX_BETTI_DIMENSION],
right_betti: [u32; MAX_BETTI_DIMENSION],
combined_site_budget: u16,
combined_site_count: u16,
combined_euler: i32,
combined_entropy_nats_bits: u64,
combined_betti: [u32; MAX_BETTI_DIMENSION],
combined_fingerprint: ContentFingerprint,
combined_constraints: &[crate::pipeline::ConstraintRef],
left_constraint_count: usize,
tag_site: u16,
) -> Result<PartitionCoproductWitness, GenericImpossibilityWitness> {
let left_entropy_nats =
<f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
let right_entropy_nats =
<f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
let combined_entropy_nats =
<f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
let expected_budget = if left_site_budget > right_site_budget {
left_site_budget
} else {
right_site_budget
};
if combined_site_budget != expected_budget {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/ST_1",
));
}
let max_total = if left_total_site_count > right_total_site_count {
left_total_site_count
} else {
right_total_site_count
};
let expected_total = max_total.saturating_add(1);
if combined_site_count != expected_total {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/foundation/CoproductLayoutWidth",
));
}
if !pc_entropy_input_is_valid(left_entropy_nats)
|| !pc_entropy_input_is_valid(right_entropy_nats)
|| !pc_entropy_input_is_valid(combined_entropy_nats)
{
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/ST_2",
));
}
let max_operand_entropy = if left_entropy_nats > right_entropy_nats {
left_entropy_nats
} else {
right_entropy_nats
};
let expected_entropy = core::f64::consts::LN_2 + max_operand_entropy;
if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/ST_2",
));
}
if tag_site != max_total {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/foundation/CoproductLayoutWidth",
));
}
validate_coproduct_structure(combined_constraints, left_constraint_count, tag_site)?;
if combined_euler != left_euler.saturating_add(right_euler) {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/ST_9",
));
}
let mut k: usize = 0;
while k < MAX_BETTI_DIMENSION {
if combined_betti[k] != left_betti[k].saturating_add(right_betti[k]) {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/ST_10",
));
}
k += 1;
}
Ok(
PartitionCoproductWitness::with_level_fingerprints_sites_and_tag(
witt_bits,
combined_fingerprint,
left_fingerprint,
right_fingerprint,
combined_site_budget,
combined_site_count,
max_total,
),
)
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn pc_primitive_cartesian_product(
witt_bits: u16,
left_fingerprint: ContentFingerprint,
right_fingerprint: ContentFingerprint,
left_site_budget: u16,
right_site_budget: u16,
left_total_site_count: u16,
right_total_site_count: u16,
left_euler: i32,
right_euler: i32,
left_betti: [u32; MAX_BETTI_DIMENSION],
right_betti: [u32; MAX_BETTI_DIMENSION],
left_entropy_nats_bits: u64,
right_entropy_nats_bits: u64,
combined_site_budget: u16,
combined_site_count: u16,
combined_euler: i32,
combined_betti: [u32; MAX_BETTI_DIMENSION],
combined_entropy_nats_bits: u64,
combined_fingerprint: ContentFingerprint,
) -> Result<CartesianProductWitness, GenericImpossibilityWitness> {
let left_entropy_nats =
<f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
let right_entropy_nats =
<f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
let combined_entropy_nats =
<f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
if combined_site_budget != left_site_budget.saturating_add(right_site_budget) {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/CPT_1",
));
}
if combined_site_count != left_total_site_count.saturating_add(right_total_site_count) {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/foundation/CartesianLayoutWidth",
));
}
if combined_euler != left_euler.saturating_mul(right_euler) {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/CPT_3",
));
}
let kunneth = crate::pipeline::kunneth_compose(&left_betti, &right_betti);
let mut k: usize = 0;
while k < MAX_BETTI_DIMENSION {
if combined_betti[k] != kunneth[k] {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/CPT_4",
));
}
k += 1;
}
if !pc_entropy_input_is_valid(left_entropy_nats)
|| !pc_entropy_input_is_valid(right_entropy_nats)
|| !pc_entropy_input_is_valid(combined_entropy_nats)
{
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/CPT_5",
));
}
let expected_entropy = left_entropy_nats + right_entropy_nats;
if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
return Err(GenericImpossibilityWitness::for_identity(
"https://uor.foundation/op/CPT_5",
));
}
Ok(
CartesianProductWitness::with_level_fingerprints_and_invariants(
witt_bits,
combined_fingerprint,
left_fingerprint,
right_fingerprint,
combined_site_budget,
combined_site_count,
combined_euler,
combined_betti,
),
)
}
impl VerifiedMint for PartitionProductWitness {
type Inputs = PartitionProductMintInputs;
type Error = GenericImpossibilityWitness;
fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
pc_primitive_partition_product(
inputs.witt_bits,
inputs.left_fingerprint,
inputs.right_fingerprint,
inputs.left_site_budget,
inputs.right_site_budget,
inputs.left_total_site_count,
inputs.right_total_site_count,
inputs.left_euler,
inputs.right_euler,
inputs.left_entropy_nats_bits,
inputs.right_entropy_nats_bits,
inputs.combined_site_budget,
inputs.combined_site_count,
inputs.combined_euler,
inputs.combined_entropy_nats_bits,
inputs.combined_fingerprint,
)
}
}
impl VerifiedMint for PartitionCoproductWitness {
type Inputs = PartitionCoproductMintInputs;
type Error = GenericImpossibilityWitness;
fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
pc_primitive_partition_coproduct(
inputs.witt_bits,
inputs.left_fingerprint,
inputs.right_fingerprint,
inputs.left_site_budget,
inputs.right_site_budget,
inputs.left_total_site_count,
inputs.right_total_site_count,
inputs.left_euler,
inputs.right_euler,
inputs.left_entropy_nats_bits,
inputs.right_entropy_nats_bits,
inputs.left_betti,
inputs.right_betti,
inputs.combined_site_budget,
inputs.combined_site_count,
inputs.combined_euler,
inputs.combined_entropy_nats_bits,
inputs.combined_betti,
inputs.combined_fingerprint,
inputs.combined_constraints,
inputs.left_constraint_count,
inputs.tag_site,
)
}
}
impl VerifiedMint for CartesianProductWitness {
type Inputs = CartesianProductMintInputs;
type Error = GenericImpossibilityWitness;
fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
pc_primitive_cartesian_product(
inputs.witt_bits,
inputs.left_fingerprint,
inputs.right_fingerprint,
inputs.left_site_budget,
inputs.right_site_budget,
inputs.left_total_site_count,
inputs.right_total_site_count,
inputs.left_euler,
inputs.right_euler,
inputs.left_betti,
inputs.right_betti,
inputs.left_entropy_nats_bits,
inputs.right_entropy_nats_bits,
inputs.combined_site_budget,
inputs.combined_site_count,
inputs.combined_euler,
inputs.combined_betti,
inputs.combined_entropy_nats_bits,
inputs.combined_fingerprint,
)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PartitionRecord<H: crate::HostTypes> {
pub site_budget: u16,
pub euler: i32,
pub betti: [u32; MAX_BETTI_DIMENSION],
pub entropy_nats_bits: u64,
_phantom: core::marker::PhantomData<H>,
}
impl<H: crate::HostTypes> PartitionRecord<H> {
#[inline]
#[must_use]
pub const fn new(
site_budget: u16,
euler: i32,
betti: [u32; MAX_BETTI_DIMENSION],
entropy_nats_bits: u64,
) -> Self {
Self {
site_budget,
euler,
betti,
entropy_nats_bits,
_phantom: core::marker::PhantomData,
}
}
}
pub trait PartitionResolver<H: crate::HostTypes> {
fn resolve(&self, fp: ContentFingerprint) -> Option<PartitionRecord<H>>;
}
#[derive(Debug)]
pub struct PartitionHandle<H: crate::HostTypes> {
fingerprint: ContentFingerprint,
_phantom: core::marker::PhantomData<H>,
}
impl<H: crate::HostTypes> Copy for PartitionHandle<H> {}
impl<H: crate::HostTypes> Clone for PartitionHandle<H> {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl<H: crate::HostTypes> PartialEq for PartitionHandle<H> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.fingerprint == other.fingerprint
}
}
impl<H: crate::HostTypes> Eq for PartitionHandle<H> {}
impl<H: crate::HostTypes> core::hash::Hash for PartitionHandle<H> {
#[inline]
fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
self.fingerprint.hash(state);
}
}
impl<H: crate::HostTypes> PartitionHandle<H> {
#[inline]
#[must_use]
pub const fn from_fingerprint(fingerprint: ContentFingerprint) -> Self {
Self {
fingerprint,
_phantom: core::marker::PhantomData,
}
}
#[inline]
#[must_use]
pub const fn fingerprint(&self) -> ContentFingerprint {
self.fingerprint
}
#[inline]
pub fn resolve_with<R: PartitionResolver<H>>(
&self,
resolver: &R,
) -> Option<PartitionRecord<H>> {
resolver.resolve(self.fingerprint)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullElement<H: HostTypes> {
_phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullElement<H> {
fn default() -> Self {
Self {
_phantom: core::marker::PhantomData,
}
}
}
impl<H: HostTypes> crate::kernel::address::Element<H> for NullElement<H> {
fn length(&self) -> u64 {
0
}
fn addresses(&self) -> &H::HostString {
H::EMPTY_HOST_STRING
}
fn digest(&self) -> &H::HostString {
H::EMPTY_HOST_STRING
}
fn digest_algorithm(&self) -> &H::HostString {
H::EMPTY_HOST_STRING
}
fn canonical_bytes(&self) -> &H::WitnessBytes {
H::EMPTY_WITNESS_BYTES
}
fn witt_length(&self) -> u64 {
0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullDatum<H: HostTypes> {
element: NullElement<H>,
_phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullDatum<H> {
fn default() -> Self {
Self {
element: NullElement::default(),
_phantom: core::marker::PhantomData,
}
}
}
impl<H: HostTypes> crate::kernel::schema::Datum<H> for NullDatum<H> {
fn value(&self) -> u64 {
0
}
fn witt_length(&self) -> u64 {
0
}
fn stratum(&self) -> u64 {
0
}
fn spectrum(&self) -> u64 {
0
}
type Element = NullElement<H>;
fn element(&self) -> &Self::Element {
&self.element
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullTermExpression<H: HostTypes> {
_phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullTermExpression<H> {
fn default() -> Self {
Self {
_phantom: core::marker::PhantomData,
}
}
}
impl<H: HostTypes> crate::kernel::schema::TermExpression<H> for NullTermExpression<H> {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullSiteIndex<H: HostTypes> {
_phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullSiteIndex<H> {
fn default() -> Self {
Self {
_phantom: core::marker::PhantomData,
}
}
}
impl<H: HostTypes> crate::bridge::partition::SiteIndex<H> for NullSiteIndex<H> {
fn site_position(&self) -> u64 {
0
}
fn site_state(&self) -> u64 {
0
}
type SiteIndexTarget = NullSiteIndex<H>;
fn ancilla_site(&self) -> &Self::SiteIndexTarget {
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullTagSite<H: HostTypes> {
ancilla: NullSiteIndex<H>,
}
impl<H: HostTypes> Default for NullTagSite<H> {
fn default() -> Self {
Self {
ancilla: NullSiteIndex::default(),
}
}
}
impl<H: HostTypes> crate::bridge::partition::SiteIndex<H> for NullTagSite<H> {
fn site_position(&self) -> u64 {
0
}
fn site_state(&self) -> u64 {
0
}
type SiteIndexTarget = NullSiteIndex<H>;
fn ancilla_site(&self) -> &Self::SiteIndexTarget {
&self.ancilla
}
}
impl<H: HostTypes> crate::bridge::partition::TagSite<H> for NullTagSite<H> {
fn tag_value(&self) -> bool {
false
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullSiteBinding<H: HostTypes> {
constraint: NullConstraint<H>,
site_index: NullSiteIndex<H>,
}
impl<H: HostTypes> Default for NullSiteBinding<H> {
fn default() -> Self {
Self {
constraint: NullConstraint::default(),
site_index: NullSiteIndex::default(),
}
}
}
impl<H: HostTypes> crate::bridge::partition::SiteBinding<H> for NullSiteBinding<H> {
type Constraint = NullConstraint<H>;
fn pinned_by(&self) -> &Self::Constraint {
&self.constraint
}
type SiteIndex = NullSiteIndex<H>;
fn pins_coordinate(&self) -> &Self::SiteIndex {
&self.site_index
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullConstraint<H: HostTypes> {
_phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullConstraint<H> {
fn default() -> Self {
Self {
_phantom: core::marker::PhantomData,
}
}
}
impl<H: HostTypes> crate::user::type_::Constraint<H> for NullConstraint<H> {
fn metric_axis(&self) -> MetricAxis {
MetricAxis::Vertical
}
type SiteIndex = NullSiteIndex<H>;
fn pins_sites(&self) -> &[Self::SiteIndex] {
&[]
}
fn crossing_cost(&self) -> u64 {
0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullFreeRank<H: HostTypes> {
_phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullFreeRank<H> {
fn default() -> Self {
Self {
_phantom: core::marker::PhantomData,
}
}
}
impl<H: HostTypes> crate::bridge::partition::FreeRank<H> for NullFreeRank<H> {
fn total_sites(&self) -> u64 {
0
}
fn pinned_count(&self) -> u64 {
0
}
fn free_rank(&self) -> u64 {
0
}
fn is_closed(&self) -> bool {
true
}
type SiteIndex = NullSiteIndex<H>;
fn has_site(&self) -> &[Self::SiteIndex] {
&[]
}
type SiteBinding = NullSiteBinding<H>;
fn has_binding(&self) -> &[Self::SiteBinding] {
&[]
}
fn reversible_strategy(&self) -> bool {
false
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullIrreducibleSet<H: HostTypes> {
_phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullIrreducibleSet<H> {
fn default() -> Self {
Self {
_phantom: core::marker::PhantomData,
}
}
}
impl<H: HostTypes> crate::bridge::partition::Component<H> for NullIrreducibleSet<H> {
type Datum = NullDatum<H>;
fn member(&self) -> &[Self::Datum] {
&[]
}
fn cardinality(&self) -> u64 {
0
}
}
impl<H: HostTypes> crate::bridge::partition::IrreducibleSet<H> for NullIrreducibleSet<H> {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullReducibleSet<H: HostTypes> {
_phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullReducibleSet<H> {
fn default() -> Self {
Self {
_phantom: core::marker::PhantomData,
}
}
}
impl<H: HostTypes> crate::bridge::partition::Component<H> for NullReducibleSet<H> {
type Datum = NullDatum<H>;
fn member(&self) -> &[Self::Datum] {
&[]
}
fn cardinality(&self) -> u64 {
0
}
}
impl<H: HostTypes> crate::bridge::partition::ReducibleSet<H> for NullReducibleSet<H> {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullUnitGroup<H: HostTypes> {
_phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullUnitGroup<H> {
fn default() -> Self {
Self {
_phantom: core::marker::PhantomData,
}
}
}
impl<H: HostTypes> crate::bridge::partition::Component<H> for NullUnitGroup<H> {
type Datum = NullDatum<H>;
fn member(&self) -> &[Self::Datum] {
&[]
}
fn cardinality(&self) -> u64 {
0
}
}
impl<H: HostTypes> crate::bridge::partition::UnitGroup<H> for NullUnitGroup<H> {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullComplement<H: HostTypes> {
term: NullTermExpression<H>,
}
impl<H: HostTypes> Default for NullComplement<H> {
fn default() -> Self {
Self {
term: NullTermExpression::default(),
}
}
}
impl<H: HostTypes> crate::bridge::partition::Component<H> for NullComplement<H> {
type Datum = NullDatum<H>;
fn member(&self) -> &[Self::Datum] {
&[]
}
fn cardinality(&self) -> u64 {
0
}
}
impl<H: HostTypes> crate::bridge::partition::Complement<H> for NullComplement<H> {
type TermExpression = NullTermExpression<H>;
fn exterior_criteria(&self) -> &Self::TermExpression {
&self.term
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullTypeDefinition<H: HostTypes> {
element: NullElement<H>,
}
impl<H: HostTypes> Default for NullTypeDefinition<H> {
fn default() -> Self {
Self {
element: NullElement::default(),
}
}
}
impl<H: HostTypes> crate::user::type_::TypeDefinition<H> for NullTypeDefinition<H> {
type Element = NullElement<H>;
fn content_address(&self) -> &Self::Element {
&self.element
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullPartition<H: HostTypes> {
irreducibles: NullIrreducibleSet<H>,
reducibles: NullReducibleSet<H>,
units: NullUnitGroup<H>,
exterior: NullComplement<H>,
free_rank: NullFreeRank<H>,
tag_site: NullTagSite<H>,
source_type: NullTypeDefinition<H>,
fingerprint: ContentFingerprint,
}
impl<H: HostTypes> NullPartition<H> {
#[inline]
#[must_use]
pub fn from_fingerprint(fingerprint: ContentFingerprint) -> Self {
Self {
irreducibles: NullIrreducibleSet::default(),
reducibles: NullReducibleSet::default(),
units: NullUnitGroup::default(),
exterior: NullComplement::default(),
free_rank: NullFreeRank::default(),
tag_site: NullTagSite::default(),
source_type: NullTypeDefinition::default(),
fingerprint,
}
}
#[inline]
#[must_use]
pub const fn fingerprint(&self) -> ContentFingerprint {
self.fingerprint
}
pub const ABSENT: NullPartition<H> = NullPartition {
irreducibles: NullIrreducibleSet {
_phantom: core::marker::PhantomData,
},
reducibles: NullReducibleSet {
_phantom: core::marker::PhantomData,
},
units: NullUnitGroup {
_phantom: core::marker::PhantomData,
},
exterior: NullComplement {
term: NullTermExpression {
_phantom: core::marker::PhantomData,
},
},
free_rank: NullFreeRank {
_phantom: core::marker::PhantomData,
},
tag_site: NullTagSite {
ancilla: NullSiteIndex {
_phantom: core::marker::PhantomData,
},
},
source_type: NullTypeDefinition {
element: NullElement {
_phantom: core::marker::PhantomData,
},
},
fingerprint: ContentFingerprint::zero(),
};
}
impl<H: HostTypes> crate::bridge::partition::Partition<H> for NullPartition<H> {
type IrreducibleSet = NullIrreducibleSet<H>;
fn irreducibles(&self) -> &Self::IrreducibleSet {
&self.irreducibles
}
type ReducibleSet = NullReducibleSet<H>;
fn reducibles(&self) -> &Self::ReducibleSet {
&self.reducibles
}
type UnitGroup = NullUnitGroup<H>;
fn units(&self) -> &Self::UnitGroup {
&self.units
}
type Complement = NullComplement<H>;
fn exterior(&self) -> &Self::Complement {
&self.exterior
}
fn density(&self) -> H::Decimal {
H::EMPTY_DECIMAL
}
type TypeDefinition = NullTypeDefinition<H>;
fn source_type(&self) -> &Self::TypeDefinition {
&self.source_type
}
fn witt_length(&self) -> u64 {
0
}
type FreeRank = NullFreeRank<H>;
fn site_budget(&self) -> &Self::FreeRank {
&self.free_rank
}
fn is_exhaustive(&self) -> bool {
true
}
type TagSite = NullTagSite<H>;
fn tag_site_of(&self) -> &Self::TagSite {
&self.tag_site
}
fn product_category_level(&self) -> &H::HostString {
H::EMPTY_HOST_STRING
}
}
impl<H: HostTypes> crate::bridge::partition::PartitionProduct<H> for PartitionProductWitness {
type Partition = NullPartition<H>;
fn left_factor(&self) -> Self::Partition {
NullPartition::from_fingerprint(self.left_fingerprint)
}
fn right_factor(&self) -> Self::Partition {
NullPartition::from_fingerprint(self.right_fingerprint)
}
}
impl<H: HostTypes> crate::bridge::partition::PartitionCoproduct<H> for PartitionCoproductWitness {
type Partition = NullPartition<H>;
fn left_summand(&self) -> Self::Partition {
NullPartition::from_fingerprint(self.left_fingerprint)
}
fn right_summand(&self) -> Self::Partition {
NullPartition::from_fingerprint(self.right_fingerprint)
}
}
impl<H: HostTypes> crate::bridge::partition::CartesianPartitionProduct<H>
for CartesianProductWitness
{
type Partition = NullPartition<H>;
fn left_cartesian_factor(&self) -> Self::Partition {
NullPartition::from_fingerprint(self.left_fingerprint)
}
fn right_cartesian_factor(&self) -> Self::Partition {
NullPartition::from_fingerprint(self.right_fingerprint)
}
}
pub mod prelude {
pub use super::calibrations;
pub use super::Add;
pub use super::And;
pub use super::BNot;
pub use super::BinaryGroundingMap;
pub use super::BindingEntry;
pub use super::BindingsTable;
pub use super::BornRuleVerification;
pub use super::Calibration;
pub use super::CalibrationError;
pub use super::CanonicalTimingPolicy;
pub use super::Certificate;
pub use super::Certified;
pub use super::ChainAuditTrail;
pub use super::CompileTime;
pub use super::CompileUnit;
pub use super::CompileUnitBuilder;
pub use super::CompletenessAuditTrail;
pub use super::CompletenessCertificate;
pub use super::ConstrainedTypeInput;
pub use super::ContentAddress;
pub use super::ContentFingerprint;
pub use super::Datum;
pub use super::DigestGroundingMap;
pub use super::Embed;
pub use super::FragmentMarker;
pub use super::GenericImpossibilityWitness;
pub use super::GeodesicCertificate;
pub use super::GeodesicEvidenceBundle;
pub use super::Grounded;
pub use super::GroundedCoord;
pub use super::GroundedShape;
pub use super::GroundedTuple;
pub use super::GroundedValue;
pub use super::Grounding;
pub use super::GroundingCertificate;
pub use super::GroundingExt;
pub use super::GroundingMapKind;
pub use super::GroundingProgram;
pub use super::Hasher;
pub use super::ImpossibilityWitnessKind;
pub use super::InhabitanceCertificate;
pub use super::InhabitanceImpossibilityWitness;
pub use super::IntegerGroundingMap;
pub use super::Invertible;
pub use super::InvolutionCertificate;
pub use super::IsometryCertificate;
pub use super::JsonGroundingMap;
pub use super::LandauerBudget;
pub use super::LiftChainCertificate;
pub use super::MeasurementCertificate;
pub use super::Mul;
pub use super::Nanos;
pub use super::Neg;
pub use super::OntologyTarget;
pub use super::Or;
pub use super::PipelineFailure;
pub use super::PreservesMetric;
pub use super::PreservesStructure;
pub use super::RingOp;
pub use super::Runtime;
pub use super::ShapeViolation;
pub use super::Sub;
pub use super::Succ;
pub use super::Term;
pub use super::TermArena;
pub use super::TimingPolicy;
pub use super::Total;
pub use super::TransformCertificate;
pub use super::Triad;
pub use super::UnaryRingOp;
pub use super::UorTime;
pub use super::Utf8GroundingMap;
pub use super::ValidLevelEmbedding;
pub use super::Validated;
pub use super::ValidationPhase;
pub use super::Xor;
pub use super::W16;
pub use super::W8;
pub use crate::pipeline::empty_bindings_table;
pub use crate::pipeline::{
validate_constrained_type, validate_constrained_type_const, ConstrainedTypeShape,
ConstraintRef, FragmentKind,
};
pub use crate::{DecimalTranscendental, DefaultHostTypes, HostTypes, WittLevel};
}