1use crate::{
22 DecimalTranscendental, HostTypes, MetricAxis, PrimitiveOp, VerificationDomain, ViolationKind,
23 WittLevel,
24};
25use core::marker::PhantomData;
26
27mod sealed {
30 pub trait Sealed {}
32 impl Sealed for super::GroundedCoord {}
33 impl<const N: usize> Sealed for super::GroundedTuple<N> {}
34}
35
36#[derive(Debug, Clone, PartialEq, Eq)]
41#[allow(clippy::large_enum_variant, dead_code)]
42pub(crate) enum DatumInner {
43 W8([u8; 1]),
45 W16([u8; 2]),
47 W24([u8; 3]),
49 W32([u8; 4]),
51 W40([u8; 5]),
53 W48([u8; 6]),
55 W56([u8; 7]),
57 W64([u8; 8]),
59 W72([u8; 9]),
61 W80([u8; 10]),
63 W88([u8; 11]),
65 W96([u8; 12]),
67 W104([u8; 13]),
69 W112([u8; 14]),
71 W120([u8; 15]),
73 W128([u8; 16]),
75}
76
77#[derive(Debug, Clone, PartialEq, Eq)]
95pub struct Datum {
96 inner: DatumInner,
98}
99
100impl Datum {
101 #[inline]
103 #[must_use]
104 pub const fn level(&self) -> WittLevel {
105 match self.inner {
106 DatumInner::W8(_) => WittLevel::W8,
107 DatumInner::W16(_) => WittLevel::W16,
108 DatumInner::W24(_) => WittLevel::new(24),
109 DatumInner::W32(_) => WittLevel::new(32),
110 DatumInner::W40(_) => WittLevel::new(40),
111 DatumInner::W48(_) => WittLevel::new(48),
112 DatumInner::W56(_) => WittLevel::new(56),
113 DatumInner::W64(_) => WittLevel::new(64),
114 DatumInner::W72(_) => WittLevel::new(72),
115 DatumInner::W80(_) => WittLevel::new(80),
116 DatumInner::W88(_) => WittLevel::new(88),
117 DatumInner::W96(_) => WittLevel::new(96),
118 DatumInner::W104(_) => WittLevel::new(104),
119 DatumInner::W112(_) => WittLevel::new(112),
120 DatumInner::W120(_) => WittLevel::new(120),
121 DatumInner::W128(_) => WittLevel::new(128),
122 }
123 }
124
125 #[inline]
127 #[must_use]
128 pub fn as_bytes(&self) -> &[u8] {
129 match &self.inner {
130 DatumInner::W8(b) => b,
131 DatumInner::W16(b) => b,
132 DatumInner::W24(b) => b,
133 DatumInner::W32(b) => b,
134 DatumInner::W40(b) => b,
135 DatumInner::W48(b) => b,
136 DatumInner::W56(b) => b,
137 DatumInner::W64(b) => b,
138 DatumInner::W72(b) => b,
139 DatumInner::W80(b) => b,
140 DatumInner::W88(b) => b,
141 DatumInner::W96(b) => b,
142 DatumInner::W104(b) => b,
143 DatumInner::W112(b) => b,
144 DatumInner::W120(b) => b,
145 DatumInner::W128(b) => b,
146 }
147 }
148}
149
150#[derive(Debug, Clone, PartialEq, Eq)]
153#[allow(clippy::large_enum_variant, dead_code)]
154pub(crate) enum GroundedCoordInner {
155 W8([u8; 1]),
157 W16([u8; 2]),
159 W24([u8; 3]),
161 W32([u8; 4]),
163 W40([u8; 5]),
165 W48([u8; 6]),
167 W56([u8; 7]),
169 W64([u8; 8]),
171 W72([u8; 9]),
173 W80([u8; 10]),
175 W88([u8; 11]),
177 W96([u8; 12]),
179 W104([u8; 13]),
181 W112([u8; 14]),
183 W120([u8; 15]),
185 W128([u8; 16]),
187}
188
189#[derive(Debug, Clone, PartialEq, Eq)]
208pub struct GroundedCoord {
209 pub(crate) inner: GroundedCoordInner,
211}
212
213impl GroundedCoord {
214 #[inline]
216 #[must_use]
217 pub const fn w8(value: u8) -> Self {
218 Self {
219 inner: GroundedCoordInner::W8(value.to_le_bytes()),
220 }
221 }
222
223 #[inline]
225 #[must_use]
226 pub const fn w16(value: u16) -> Self {
227 Self {
228 inner: GroundedCoordInner::W16(value.to_le_bytes()),
229 }
230 }
231
232 #[inline]
234 #[must_use]
235 pub const fn w24(value: u32) -> Self {
236 let full = value.to_le_bytes();
237 let mut out = [0u8; 3];
238 let mut i = 0;
239 while i < 3 {
240 out[i] = full[i];
241 i += 1;
242 }
243 Self {
244 inner: GroundedCoordInner::W24(out),
245 }
246 }
247
248 #[inline]
250 #[must_use]
251 pub const fn w32(value: u32) -> Self {
252 Self {
253 inner: GroundedCoordInner::W32(value.to_le_bytes()),
254 }
255 }
256
257 #[inline]
259 #[must_use]
260 pub const fn w40(value: u64) -> Self {
261 let full = value.to_le_bytes();
262 let mut out = [0u8; 5];
263 let mut i = 0;
264 while i < 5 {
265 out[i] = full[i];
266 i += 1;
267 }
268 Self {
269 inner: GroundedCoordInner::W40(out),
270 }
271 }
272
273 #[inline]
275 #[must_use]
276 pub const fn w48(value: u64) -> Self {
277 let full = value.to_le_bytes();
278 let mut out = [0u8; 6];
279 let mut i = 0;
280 while i < 6 {
281 out[i] = full[i];
282 i += 1;
283 }
284 Self {
285 inner: GroundedCoordInner::W48(out),
286 }
287 }
288
289 #[inline]
291 #[must_use]
292 pub const fn w56(value: u64) -> Self {
293 let full = value.to_le_bytes();
294 let mut out = [0u8; 7];
295 let mut i = 0;
296 while i < 7 {
297 out[i] = full[i];
298 i += 1;
299 }
300 Self {
301 inner: GroundedCoordInner::W56(out),
302 }
303 }
304
305 #[inline]
307 #[must_use]
308 pub const fn w64(value: u64) -> Self {
309 Self {
310 inner: GroundedCoordInner::W64(value.to_le_bytes()),
311 }
312 }
313
314 #[inline]
316 #[must_use]
317 pub const fn w72(value: u128) -> Self {
318 let full = value.to_le_bytes();
319 let mut out = [0u8; 9];
320 let mut i = 0;
321 while i < 9 {
322 out[i] = full[i];
323 i += 1;
324 }
325 Self {
326 inner: GroundedCoordInner::W72(out),
327 }
328 }
329
330 #[inline]
332 #[must_use]
333 pub const fn w80(value: u128) -> Self {
334 let full = value.to_le_bytes();
335 let mut out = [0u8; 10];
336 let mut i = 0;
337 while i < 10 {
338 out[i] = full[i];
339 i += 1;
340 }
341 Self {
342 inner: GroundedCoordInner::W80(out),
343 }
344 }
345
346 #[inline]
348 #[must_use]
349 pub const fn w88(value: u128) -> Self {
350 let full = value.to_le_bytes();
351 let mut out = [0u8; 11];
352 let mut i = 0;
353 while i < 11 {
354 out[i] = full[i];
355 i += 1;
356 }
357 Self {
358 inner: GroundedCoordInner::W88(out),
359 }
360 }
361
362 #[inline]
364 #[must_use]
365 pub const fn w96(value: u128) -> Self {
366 let full = value.to_le_bytes();
367 let mut out = [0u8; 12];
368 let mut i = 0;
369 while i < 12 {
370 out[i] = full[i];
371 i += 1;
372 }
373 Self {
374 inner: GroundedCoordInner::W96(out),
375 }
376 }
377
378 #[inline]
380 #[must_use]
381 pub const fn w104(value: u128) -> Self {
382 let full = value.to_le_bytes();
383 let mut out = [0u8; 13];
384 let mut i = 0;
385 while i < 13 {
386 out[i] = full[i];
387 i += 1;
388 }
389 Self {
390 inner: GroundedCoordInner::W104(out),
391 }
392 }
393
394 #[inline]
396 #[must_use]
397 pub const fn w112(value: u128) -> Self {
398 let full = value.to_le_bytes();
399 let mut out = [0u8; 14];
400 let mut i = 0;
401 while i < 14 {
402 out[i] = full[i];
403 i += 1;
404 }
405 Self {
406 inner: GroundedCoordInner::W112(out),
407 }
408 }
409
410 #[inline]
412 #[must_use]
413 pub const fn w120(value: u128) -> Self {
414 let full = value.to_le_bytes();
415 let mut out = [0u8; 15];
416 let mut i = 0;
417 while i < 15 {
418 out[i] = full[i];
419 i += 1;
420 }
421 Self {
422 inner: GroundedCoordInner::W120(out),
423 }
424 }
425
426 #[inline]
428 #[must_use]
429 pub const fn w128(value: u128) -> Self {
430 let full = value.to_le_bytes();
431 let mut out = [0u8; 16];
432 let mut i = 0;
433 while i < 16 {
434 out[i] = full[i];
435 i += 1;
436 }
437 Self {
438 inner: GroundedCoordInner::W128(out),
439 }
440 }
441}
442
443#[derive(Debug, Clone, PartialEq, Eq)]
466pub struct GroundedTuple<const N: usize> {
467 pub(crate) coords: [GroundedCoord; N],
469}
470
471impl<const N: usize> GroundedTuple<N> {
472 #[inline]
474 #[must_use]
475 pub const fn new(coords: [GroundedCoord; N]) -> Self {
476 Self { coords }
477 }
478}
479
480pub trait GroundedValue: sealed::Sealed {}
485impl GroundedValue for GroundedCoord {}
486impl<const N: usize> GroundedValue for GroundedTuple<N> {}
487
488pub trait MorphismKind: morphism_kind_sealed::Sealed {
493 const ONTOLOGY_IRI: &'static str;
495}
496
497pub trait GroundingMapKind: MorphismKind + grounding_map_kind_sealed::Sealed {}
501
502pub trait ProjectionMapKind: MorphismKind + projection_map_kind_sealed::Sealed {}
506
507pub trait Total: MorphismKind {}
510
511pub trait Invertible: MorphismKind {}
513
514pub trait PreservesStructure: MorphismKind {}
517
518pub trait PreservesMetric: MorphismKind {}
521
522#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
524pub struct BinaryGroundingMap;
525
526#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
528pub struct DigestGroundingMap;
529
530#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
532pub struct IntegerGroundingMap;
533
534#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
536pub struct JsonGroundingMap;
537
538#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
540pub struct Utf8GroundingMap;
541
542#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
544pub struct BinaryProjectionMap;
545
546#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
548pub struct DigestProjectionMap;
549
550#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
552pub struct IntegerProjectionMap;
553
554#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
556pub struct JsonProjectionMap;
557
558#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
560pub struct Utf8ProjectionMap;
561
562mod morphism_kind_sealed {
563 pub trait Sealed {}
565 impl Sealed for super::BinaryGroundingMap {}
566 impl Sealed for super::DigestGroundingMap {}
567 impl Sealed for super::IntegerGroundingMap {}
568 impl Sealed for super::JsonGroundingMap {}
569 impl Sealed for super::Utf8GroundingMap {}
570 impl Sealed for super::BinaryProjectionMap {}
571 impl Sealed for super::DigestProjectionMap {}
572 impl Sealed for super::IntegerProjectionMap {}
573 impl Sealed for super::JsonProjectionMap {}
574 impl Sealed for super::Utf8ProjectionMap {}
575}
576
577mod grounding_map_kind_sealed {
578 pub trait Sealed {}
580 impl Sealed for super::BinaryGroundingMap {}
581 impl Sealed for super::DigestGroundingMap {}
582 impl Sealed for super::IntegerGroundingMap {}
583 impl Sealed for super::JsonGroundingMap {}
584 impl Sealed for super::Utf8GroundingMap {}
585}
586
587mod projection_map_kind_sealed {
588 pub trait Sealed {}
590 impl Sealed for super::BinaryProjectionMap {}
591 impl Sealed for super::DigestProjectionMap {}
592 impl Sealed for super::IntegerProjectionMap {}
593 impl Sealed for super::JsonProjectionMap {}
594 impl Sealed for super::Utf8ProjectionMap {}
595}
596
597impl MorphismKind for BinaryGroundingMap {
598 const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/BinaryGroundingMap";
599}
600
601impl MorphismKind for DigestGroundingMap {
602 const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/DigestGroundingMap";
603}
604
605impl MorphismKind for IntegerGroundingMap {
606 const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/IntegerGroundingMap";
607}
608
609impl MorphismKind for JsonGroundingMap {
610 const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/JsonGroundingMap";
611}
612
613impl MorphismKind for Utf8GroundingMap {
614 const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/Utf8GroundingMap";
615}
616
617impl MorphismKind for BinaryProjectionMap {
618 const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/BinaryProjectionMap";
619}
620
621impl MorphismKind for DigestProjectionMap {
622 const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/DigestProjectionMap";
623}
624
625impl MorphismKind for IntegerProjectionMap {
626 const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/IntegerProjectionMap";
627}
628
629impl MorphismKind for JsonProjectionMap {
630 const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/JsonProjectionMap";
631}
632
633impl MorphismKind for Utf8ProjectionMap {
634 const ONTOLOGY_IRI: &'static str = "https://uor.foundation/morphism/Utf8ProjectionMap";
635}
636
637impl GroundingMapKind for BinaryGroundingMap {}
638impl GroundingMapKind for DigestGroundingMap {}
639impl GroundingMapKind for IntegerGroundingMap {}
640impl GroundingMapKind for JsonGroundingMap {}
641impl GroundingMapKind for Utf8GroundingMap {}
642
643impl ProjectionMapKind for BinaryProjectionMap {}
644impl ProjectionMapKind for DigestProjectionMap {}
645impl ProjectionMapKind for IntegerProjectionMap {}
646impl ProjectionMapKind for JsonProjectionMap {}
647impl ProjectionMapKind for Utf8ProjectionMap {}
648
649impl Total for IntegerGroundingMap {}
650impl Invertible for IntegerGroundingMap {}
651impl PreservesStructure for IntegerGroundingMap {}
652
653impl Invertible for Utf8GroundingMap {}
654impl PreservesStructure for Utf8GroundingMap {}
655
656impl Invertible for JsonGroundingMap {}
657impl PreservesStructure for JsonGroundingMap {}
658
659impl Total for DigestGroundingMap {}
660
661impl Total for BinaryGroundingMap {}
662impl Invertible for BinaryGroundingMap {}
663
664impl Invertible for IntegerProjectionMap {}
665impl PreservesStructure for IntegerProjectionMap {}
666
667impl Invertible for Utf8ProjectionMap {}
668impl PreservesStructure for Utf8ProjectionMap {}
669
670impl Invertible for JsonProjectionMap {}
671impl PreservesStructure for JsonProjectionMap {}
672
673impl Total for DigestProjectionMap {}
674
675impl Total for BinaryProjectionMap {}
676impl Invertible for BinaryProjectionMap {}
677
678pub trait Grounding {
709 type Output: GroundedValue;
713
714 type Map: GroundingMapKind;
720
721 fn program(&self) -> GroundingProgram<Self::Output, Self::Map>;
728}
729
730mod grounding_ext_sealed {
737 pub trait Sealed {}
739 impl<G: super::Grounding> Sealed for G {}
740}
741
742pub trait GroundingProgramRun<Out> {
747 fn run_program(&self, external: &[u8]) -> Option<Out>;
749}
750
751impl<Map: GroundingMapKind> GroundingProgramRun<GroundedCoord>
752 for GroundingProgram<GroundedCoord, Map>
753{
754 #[inline]
755 fn run_program(&self, external: &[u8]) -> Option<GroundedCoord> {
756 self.run(external)
757 }
758}
759
760impl<const N: usize, Map: GroundingMapKind> GroundingProgramRun<GroundedTuple<N>>
761 for GroundingProgram<GroundedTuple<N>, Map>
762{
763 #[inline]
764 fn run_program(&self, external: &[u8]) -> Option<GroundedTuple<N>> {
765 self.run(external)
766 }
767}
768
769pub trait GroundingExt: Grounding + grounding_ext_sealed::Sealed {
776 fn ground(&self, external: &[u8]) -> Option<Self::Output>;
780}
781
782impl<G: Grounding> GroundingExt for G
783where
784 GroundingProgram<G::Output, G::Map>: GroundingProgramRun<G::Output>,
785{
786 #[inline]
787 fn ground(&self, external: &[u8]) -> Option<Self::Output> {
788 self.program().run_program(external)
789 }
790}
791
792pub trait Sinking<const INLINE_BYTES: usize> {
822 type Source: GroundedShape;
825
826 type ProjectionMap: ProjectionMapKind;
829
830 type Output;
834
835 fn project(&self, grounded: &Grounded<Self::Source, INLINE_BYTES>) -> Self::Output;
839}
840
841pub trait EmitThrough<const INLINE_BYTES: usize, H: crate::HostTypes>:
846 crate::bridge::boundary::EmitEffect<H>
847{
848 type Sinking: Sinking<INLINE_BYTES>;
850
851 fn emit(
855 &self,
856 grounded: &Grounded<<Self::Sinking as Sinking<INLINE_BYTES>>::Source, INLINE_BYTES>,
857 ) -> <Self::Sinking as Sinking<INLINE_BYTES>>::Output;
858}
859
860pub trait ValidationPhase: validation_phase_sealed::Sealed {}
864
865mod validation_phase_sealed {
866 pub trait Sealed {}
868 impl Sealed for super::CompileTime {}
869 impl Sealed for super::Runtime {}
870}
871
872#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
876pub struct CompileTime;
877impl ValidationPhase for CompileTime {}
878
879#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
883pub struct Runtime;
884impl ValidationPhase for Runtime {}
885
886#[derive(Debug, Clone, PartialEq, Eq)]
923pub struct Validated<T, Phase: ValidationPhase = Runtime> {
924 inner: T,
926 _phase: PhantomData<Phase>,
928 _sealed: (),
930}
931
932impl<T, Phase: ValidationPhase> Validated<T, Phase> {
933 #[inline]
935 #[must_use]
936 pub const fn inner(&self) -> &T {
937 &self.inner
938 }
939
940 #[inline]
942 #[allow(dead_code)]
943 pub(crate) const fn new(inner: T) -> Self {
944 Self {
945 inner,
946 _phase: PhantomData,
947 _sealed: (),
948 }
949 }
950}
951
952impl<T> From<Validated<T, CompileTime>> for Validated<T, Runtime> {
954 #[inline]
955 fn from(value: Validated<T, CompileTime>) -> Self {
956 Self {
957 inner: value.inner,
958 _phase: PhantomData,
959 _sealed: (),
960 }
961 }
962}
963
964#[derive(Debug, Clone, PartialEq, Eq)]
971pub struct Derivation {
972 step_count: u32,
974 witt_level_bits: u16,
977 content_fingerprint: ContentFingerprint,
982}
983
984impl Derivation {
985 #[inline]
987 #[must_use]
988 pub const fn step_count(&self) -> u32 {
989 self.step_count
990 }
991
992 #[inline]
994 #[must_use]
995 pub const fn witt_level_bits(&self) -> u16 {
996 self.witt_level_bits
997 }
998
999 #[inline]
1002 #[must_use]
1003 pub const fn content_fingerprint(&self) -> ContentFingerprint {
1004 self.content_fingerprint
1005 }
1006
1007 #[inline]
1009 #[must_use]
1010 #[allow(dead_code)]
1011 pub(crate) const fn new(
1012 step_count: u32,
1013 witt_level_bits: u16,
1014 content_fingerprint: ContentFingerprint,
1015 ) -> Self {
1016 Self {
1017 step_count,
1018 witt_level_bits,
1019 content_fingerprint,
1020 }
1021 }
1022}
1023
1024#[derive(Debug, Clone, PartialEq, Eq)]
1027pub struct FreeRank {
1028 total: u32,
1030 pinned: u32,
1032}
1033
1034impl FreeRank {
1035 #[inline]
1037 #[must_use]
1038 pub const fn total(&self) -> u32 {
1039 self.total
1040 }
1041
1042 #[inline]
1044 #[must_use]
1045 pub const fn pinned(&self) -> u32 {
1046 self.pinned
1047 }
1048
1049 #[inline]
1051 #[must_use]
1052 pub const fn remaining(&self) -> u32 {
1053 self.total - self.pinned
1054 }
1055
1056 #[inline]
1058 #[allow(dead_code)]
1059 pub(crate) const fn new(total: u32, pinned: u32) -> Self {
1060 Self { total, pinned }
1061 }
1062}
1063
1064#[derive(Debug)]
1072pub struct LandauerBudget<H: HostTypes = crate::DefaultHostTypes> {
1073 nats: H::Decimal,
1075 _phantom: core::marker::PhantomData<H>,
1077 _sealed: (),
1079}
1080
1081impl<H: HostTypes> LandauerBudget<H> {
1082 #[inline]
1084 #[must_use]
1085 pub const fn nats(&self) -> H::Decimal {
1086 self.nats
1087 }
1088
1089 #[inline]
1092 #[must_use]
1093 #[allow(dead_code)]
1094 pub(crate) const fn new(nats: H::Decimal) -> Self {
1095 Self {
1096 nats,
1097 _phantom: core::marker::PhantomData,
1098 _sealed: (),
1099 }
1100 }
1101
1102 #[inline]
1104 #[must_use]
1105 #[allow(dead_code)]
1106 pub(crate) const fn zero() -> Self {
1107 Self {
1108 nats: H::EMPTY_DECIMAL,
1109 _phantom: core::marker::PhantomData,
1110 _sealed: (),
1111 }
1112 }
1113}
1114
1115impl<H: HostTypes> Copy for LandauerBudget<H> {}
1116impl<H: HostTypes> Clone for LandauerBudget<H> {
1117 #[inline]
1118 fn clone(&self) -> Self {
1119 *self
1120 }
1121}
1122impl<H: HostTypes> PartialEq for LandauerBudget<H> {
1123 #[inline]
1124 fn eq(&self, other: &Self) -> bool {
1125 self.nats == other.nats
1126 }
1127}
1128impl<H: HostTypes> Eq for LandauerBudget<H> {}
1129impl<H: HostTypes> PartialOrd for LandauerBudget<H> {
1130 #[inline]
1131 fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
1132 Some(self.cmp(other))
1133 }
1134}
1135impl<H: HostTypes> Ord for LandauerBudget<H> {
1136 #[inline]
1137 fn cmp(&self, other: &Self) -> core::cmp::Ordering {
1138 self.nats
1140 .partial_cmp(&other.nats)
1141 .unwrap_or(core::cmp::Ordering::Equal)
1142 }
1143}
1144impl<H: HostTypes> core::hash::Hash for LandauerBudget<H> {
1145 #[inline]
1146 fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
1147 self.nats.to_bits().hash(state);
1150 }
1151}
1152
1153#[derive(Debug)]
1168pub struct UorTime<H: HostTypes = crate::DefaultHostTypes> {
1169 landauer_nats: LandauerBudget<H>,
1171 rewrite_steps: u64,
1173 _sealed: (),
1175}
1176
1177impl<H: HostTypes> UorTime<H> {
1178 #[inline]
1181 #[must_use]
1182 pub const fn landauer_nats(&self) -> LandauerBudget<H> {
1183 self.landauer_nats
1184 }
1185
1186 #[inline]
1189 #[must_use]
1190 pub const fn rewrite_steps(&self) -> u64 {
1191 self.rewrite_steps
1192 }
1193
1194 #[inline]
1196 #[must_use]
1197 #[allow(dead_code)]
1198 pub(crate) const fn new(landauer_nats: LandauerBudget<H>, rewrite_steps: u64) -> Self {
1199 Self {
1200 landauer_nats,
1201 rewrite_steps,
1202 _sealed: (),
1203 }
1204 }
1205
1206 #[inline]
1208 #[must_use]
1209 #[allow(dead_code)]
1210 pub(crate) const fn zero() -> Self {
1211 Self {
1212 landauer_nats: LandauerBudget::<H>::zero(),
1213 rewrite_steps: 0,
1214 _sealed: (),
1215 }
1216 }
1217
1218 #[inline]
1226 #[must_use]
1227 pub fn min_wall_clock(&self, cal: &Calibration<H>) -> Nanos {
1228 let landauer_seconds = self.landauer_nats.nats() * cal.k_b_t() / cal.thermal_power();
1230 let pi_times_h_bar =
1235 <H::Decimal as DecimalTranscendental>::from_bits(crate::PI_TIMES_H_BAR_BITS);
1236 let two = <H::Decimal as DecimalTranscendental>::from_u32(2);
1237 let ml_seconds_per_step = pi_times_h_bar / (two * cal.characteristic_energy());
1238 let steps = <H::Decimal as DecimalTranscendental>::from_u64(self.rewrite_steps);
1239 let ml_seconds = ml_seconds_per_step * steps;
1240 let max_seconds = if landauer_seconds > ml_seconds {
1241 landauer_seconds
1242 } else {
1243 ml_seconds
1244 };
1245 let nanos_per_second =
1247 <H::Decimal as DecimalTranscendental>::from_bits(crate::NANOS_PER_SECOND_BITS);
1248 let nanos = max_seconds * nanos_per_second;
1249 Nanos {
1250 ns: <H::Decimal as DecimalTranscendental>::as_u64_saturating(nanos),
1251 _sealed: (),
1252 }
1253 }
1254}
1255
1256impl<H: HostTypes> Copy for UorTime<H> {}
1257impl<H: HostTypes> Clone for UorTime<H> {
1258 #[inline]
1259 fn clone(&self) -> Self {
1260 *self
1261 }
1262}
1263impl<H: HostTypes> PartialEq for UorTime<H> {
1264 #[inline]
1265 fn eq(&self, other: &Self) -> bool {
1266 self.landauer_nats == other.landauer_nats && self.rewrite_steps == other.rewrite_steps
1267 }
1268}
1269impl<H: HostTypes> Eq for UorTime<H> {}
1270impl<H: HostTypes> core::hash::Hash for UorTime<H> {
1271 #[inline]
1272 fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
1273 self.landauer_nats.hash(state);
1274 self.rewrite_steps.hash(state);
1275 }
1276}
1277impl<H: HostTypes> PartialOrd for UorTime<H> {
1278 #[inline]
1279 fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
1280 let l = self.landauer_nats.cmp(&other.landauer_nats);
1281 let r = self.rewrite_steps.cmp(&other.rewrite_steps);
1282 match (l, r) {
1283 (core::cmp::Ordering::Equal, core::cmp::Ordering::Equal) => {
1284 Some(core::cmp::Ordering::Equal)
1285 }
1286 (core::cmp::Ordering::Less, core::cmp::Ordering::Less)
1287 | (core::cmp::Ordering::Less, core::cmp::Ordering::Equal)
1288 | (core::cmp::Ordering::Equal, core::cmp::Ordering::Less) => {
1289 Some(core::cmp::Ordering::Less)
1290 }
1291 (core::cmp::Ordering::Greater, core::cmp::Ordering::Greater)
1292 | (core::cmp::Ordering::Greater, core::cmp::Ordering::Equal)
1293 | (core::cmp::Ordering::Equal, core::cmp::Ordering::Greater) => {
1294 Some(core::cmp::Ordering::Greater)
1295 }
1296 _ => None,
1297 }
1298 }
1299}
1300
1301#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1309pub struct Nanos {
1310 ns: u64,
1312 _sealed: (),
1314}
1315
1316impl Nanos {
1317 #[inline]
1320 #[must_use]
1321 pub const fn as_u64(self) -> u64 {
1322 self.ns
1323 }
1324}
1325
1326#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1329pub enum CalibrationError {
1330 ThermalEnergy,
1333 ThermalPower,
1335 CharacteristicEnergy,
1338}
1339
1340impl core::fmt::Display for CalibrationError {
1341 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1342 match self {
1343 Self::ThermalEnergy => {
1344 f.write_str("calibration k_b_t out of range (must be in [1e-30, 1e-15] joules)")
1345 }
1346 Self::ThermalPower => {
1347 f.write_str("calibration thermal_power out of range (must be > 0 and <= 1e9 W)")
1348 }
1349 Self::CharacteristicEnergy => f.write_str(
1350 "calibration characteristic_energy out of range (must be > 0 and <= 1e3 J)",
1351 ),
1352 }
1353 }
1354}
1355
1356impl core::error::Error for CalibrationError {}
1357
1358#[derive(Debug)]
1368pub struct Calibration<H: HostTypes = crate::DefaultHostTypes> {
1369 k_b_t: H::Decimal,
1371 thermal_power: H::Decimal,
1373 characteristic_energy: H::Decimal,
1375 _phantom: core::marker::PhantomData<H>,
1377}
1378
1379impl<H: HostTypes> Copy for Calibration<H> {}
1380impl<H: HostTypes> Clone for Calibration<H> {
1381 #[inline]
1382 fn clone(&self) -> Self {
1383 *self
1384 }
1385}
1386impl<H: HostTypes> PartialEq for Calibration<H> {
1387 #[inline]
1388 fn eq(&self, other: &Self) -> bool {
1389 self.k_b_t == other.k_b_t
1390 && self.thermal_power == other.thermal_power
1391 && self.characteristic_energy == other.characteristic_energy
1392 }
1393}
1394
1395impl<H: HostTypes> Calibration<H> {
1396 #[inline]
1421 pub fn new(
1422 k_b_t: H::Decimal,
1423 thermal_power: H::Decimal,
1424 characteristic_energy: H::Decimal,
1425 ) -> Result<Self, CalibrationError> {
1426 let zero = <H::Decimal as Default>::default();
1430 let kbt_lo =
1431 <H::Decimal as DecimalTranscendental>::from_bits(crate::CALIBRATION_KBT_LO_BITS);
1432 let kbt_hi =
1433 <H::Decimal as DecimalTranscendental>::from_bits(crate::CALIBRATION_KBT_HI_BITS);
1434 let tp_hi = <H::Decimal as DecimalTranscendental>::from_bits(
1435 crate::CALIBRATION_THERMAL_POWER_HI_BITS,
1436 );
1437 let ce_hi = <H::Decimal as DecimalTranscendental>::from_bits(
1438 crate::CALIBRATION_CHAR_ENERGY_HI_BITS,
1439 );
1440 #[allow(clippy::eq_op)]
1442 let k_b_t_nan = k_b_t != k_b_t;
1443 if k_b_t_nan || k_b_t <= zero || k_b_t < kbt_lo || k_b_t > kbt_hi {
1444 return Err(CalibrationError::ThermalEnergy);
1445 }
1446 #[allow(clippy::eq_op)]
1447 let tp_nan = thermal_power != thermal_power;
1448 if tp_nan || thermal_power <= zero || thermal_power > tp_hi {
1449 return Err(CalibrationError::ThermalPower);
1450 }
1451 #[allow(clippy::eq_op)]
1452 let ce_nan = characteristic_energy != characteristic_energy;
1453 if ce_nan || characteristic_energy <= zero || characteristic_energy > ce_hi {
1454 return Err(CalibrationError::CharacteristicEnergy);
1455 }
1456 Ok(Self {
1457 k_b_t,
1458 thermal_power,
1459 characteristic_energy,
1460 _phantom: core::marker::PhantomData,
1461 })
1462 }
1463
1464 #[inline]
1466 #[must_use]
1467 pub const fn k_b_t(&self) -> H::Decimal {
1468 self.k_b_t
1469 }
1470
1471 #[inline]
1473 #[must_use]
1474 pub const fn thermal_power(&self) -> H::Decimal {
1475 self.thermal_power
1476 }
1477
1478 #[inline]
1480 #[must_use]
1481 pub const fn characteristic_energy(&self) -> H::Decimal {
1482 self.characteristic_energy
1483 }
1484
1485 pub const ZERO_SENTINEL: Calibration<H> = Self {
1495 k_b_t: H::EMPTY_DECIMAL,
1496 thermal_power: H::EMPTY_DECIMAL,
1497 characteristic_energy: H::EMPTY_DECIMAL,
1498 _phantom: core::marker::PhantomData,
1499 };
1500}
1501
1502impl Calibration<crate::DefaultHostTypes> {
1503 #[inline]
1505 #[must_use]
1506 pub(crate) const fn from_f64_unchecked(
1507 k_b_t: <crate::DefaultHostTypes as crate::HostTypes>::Decimal,
1508 thermal_power: <crate::DefaultHostTypes as crate::HostTypes>::Decimal,
1509 characteristic_energy: <crate::DefaultHostTypes as crate::HostTypes>::Decimal,
1510 ) -> Self {
1511 Self {
1512 k_b_t,
1513 thermal_power,
1514 characteristic_energy,
1515 _phantom: core::marker::PhantomData,
1516 }
1517 }
1518}
1519
1520pub mod calibrations {
1524 use super::Calibration;
1525 use crate::DefaultHostTypes;
1526
1527 pub const X86_SERVER: Calibration<DefaultHostTypes> =
1531 Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 85.0, 1.0e-15);
1532
1533 pub const ARM_MOBILE: Calibration<DefaultHostTypes> =
1536 Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 5.0, 1.0e-16);
1537
1538 pub const CORTEX_M_EMBEDDED: Calibration<DefaultHostTypes> =
1541 Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 0.1, 1.0e-17);
1542
1543 pub const CONSERVATIVE_WORST_CASE: Calibration<DefaultHostTypes> =
1551 Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 1.0e9, 1.0);
1552}
1553
1554pub trait TimingPolicy {
1565 const PREFLIGHT_BUDGET_NS: u64;
1568 const RUNTIME_BUDGET_NS: u64;
1570 const CALIBRATION: &'static Calibration<crate::DefaultHostTypes>;
1573}
1574
1575#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1580pub struct CanonicalTimingPolicy;
1581
1582impl TimingPolicy for CanonicalTimingPolicy {
1583 const PREFLIGHT_BUDGET_NS: u64 = 10_000_000;
1584 const RUNTIME_BUDGET_NS: u64 = 10_000_000;
1585 const CALIBRATION: &'static Calibration<crate::DefaultHostTypes> =
1586 &calibrations::CONSERVATIVE_WORST_CASE;
1587}
1588
1589pub mod transcendentals {
1600 use crate::DecimalTranscendental;
1601
1602 #[inline]
1605 #[must_use]
1606 pub fn ln<D: DecimalTranscendental>(x: D) -> D {
1607 x.ln()
1608 }
1609
1610 #[inline]
1612 #[must_use]
1613 pub fn exp<D: DecimalTranscendental>(x: D) -> D {
1614 x.exp()
1615 }
1616
1617 #[inline]
1619 #[must_use]
1620 pub fn sqrt<D: DecimalTranscendental>(x: D) -> D {
1621 x.sqrt()
1622 }
1623
1624 #[inline]
1627 #[must_use]
1628 pub fn entropy_term_nats<D: DecimalTranscendental>(p: D) -> D {
1629 let zero = <D as Default>::default();
1630 if p <= zero {
1631 zero
1632 } else {
1633 zero - p * p.ln()
1634 }
1635 }
1636}
1637
1638#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1640pub struct TermList {
1641 pub start: u32,
1643 pub len: u32,
1645}
1646
1647#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1679pub struct TermArena<'a, const INLINE_BYTES: usize, const CAP: usize> {
1680 nodes: [Option<Term<'a, INLINE_BYTES>>; CAP],
1682 len: u32,
1684}
1685
1686impl<'a, const INLINE_BYTES: usize, const CAP: usize> TermArena<'a, INLINE_BYTES, CAP> {
1687 #[inline]
1689 #[must_use]
1690 pub const fn new() -> Self {
1691 Self {
1694 nodes: [None; CAP],
1695 len: 0,
1696 }
1697 }
1698
1699 #[must_use]
1703 pub fn push(&mut self, term: Term<'a, INLINE_BYTES>) -> Option<u32> {
1704 let idx = self.len;
1705 if (idx as usize) >= CAP {
1706 return None;
1707 }
1708 self.nodes[idx as usize] = Some(term);
1709 self.len = idx + 1;
1710 Some(idx)
1711 }
1712
1713 #[inline]
1715 #[must_use]
1716 pub fn get(&self, index: u32) -> Option<&Term<'a, INLINE_BYTES>> {
1717 self.nodes
1718 .get(index as usize)
1719 .and_then(|slot| slot.as_ref())
1720 }
1721
1722 #[inline]
1724 #[must_use]
1725 pub const fn len(&self) -> u32 {
1726 self.len
1727 }
1728
1729 #[inline]
1731 #[must_use]
1732 pub const fn is_empty(&self) -> bool {
1733 self.len == 0
1734 }
1735
1736 #[inline]
1741 #[must_use]
1742 pub fn as_slice(&self) -> &[Option<Term<'a, INLINE_BYTES>>] {
1743 &self.nodes[..self.len as usize]
1744 }
1745
1746 #[inline]
1758 #[must_use]
1759 pub const fn from_slice(slice: &'a [Term<'a, INLINE_BYTES>]) -> Self {
1760 let mut nodes: [Option<Term<'a, INLINE_BYTES>>; CAP] = [None; CAP];
1761 let mut i = 0usize;
1762 while i < slice.len() && i < CAP {
1763 nodes[i] = Some(slice[i]);
1764 i += 1;
1765 }
1766 #[allow(clippy::cast_possible_truncation)]
1770 let len = if slice.len() > CAP {
1771 CAP as u32
1772 } else {
1773 slice.len() as u32
1774 };
1775 Self { nodes, len }
1776 }
1777}
1778
1779impl<'a, const INLINE_BYTES: usize, const CAP: usize> Default for TermArena<'a, INLINE_BYTES, CAP> {
1780 fn default() -> Self {
1781 Self::new()
1782 }
1783}
1784
1785#[allow(clippy::large_enum_variant)]
1821#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1822pub enum Term<'a, const INLINE_BYTES: usize> {
1823 Literal {
1828 value: crate::pipeline::TermValue<'a, INLINE_BYTES>,
1833 level: WittLevel,
1835 },
1836 Variable {
1838 name_index: u32,
1840 },
1841 Application {
1843 operator: PrimitiveOp,
1845 args: TermList,
1847 },
1848 Lift {
1850 operand_index: u32,
1852 target: WittLevel,
1854 },
1855 Project {
1857 operand_index: u32,
1859 target: WittLevel,
1861 },
1862 Match {
1864 scrutinee_index: u32,
1866 arms: TermList,
1868 },
1869 Recurse {
1871 measure_index: u32,
1873 base_index: u32,
1875 step_index: u32,
1877 },
1878 Unfold {
1880 seed_index: u32,
1882 step_index: u32,
1884 },
1885 Try {
1887 body_index: u32,
1889 handler_index: u32,
1891 },
1892 AxisInvocation {
1900 axis_index: u32,
1902 kernel_id: u32,
1904 input_index: u32,
1906 },
1907 ProjectField {
1916 source_index: u32,
1918 byte_offset: u32,
1921 byte_length: u32,
1923 },
1924 FirstAdmit {
1936 domain_size_index: u32,
1939 predicate_index: u32,
1943 },
1944 Nerve {
1948 value_index: u32,
1951 },
1952 ChainComplex { simplicial_index: u32 },
1956 HomologyGroups { chain_index: u32 },
1961 Betti { homology_index: u32 },
1965 CochainComplex { chain_index: u32 },
1970 CohomologyGroups { cochain_index: u32 },
1975 PostnikovTower { simplicial_index: u32 },
1982 HomotopyGroups { postnikov_index: u32 },
1987 KInvariants { homotopy_index: u32 },
1992}
1993
1994#[must_use]
2002pub const fn shift_term<'a, const INLINE_BYTES: usize>(
2003 term: Term<'a, INLINE_BYTES>,
2004 offset: u32,
2005) -> Term<'a, INLINE_BYTES> {
2006 match term {
2007 Term::Literal { value, level } => Term::Literal { value, level },
2008 Term::Variable { name_index } => Term::Variable { name_index },
2010 Term::Application { operator, args } => Term::Application {
2011 operator,
2012 args: TermList {
2013 start: args.start + offset,
2014 len: args.len,
2015 },
2016 },
2017 Term::Lift {
2018 operand_index,
2019 target,
2020 } => Term::Lift {
2021 operand_index: operand_index + offset,
2022 target,
2023 },
2024 Term::Project {
2025 operand_index,
2026 target,
2027 } => Term::Project {
2028 operand_index: operand_index + offset,
2029 target,
2030 },
2031 Term::Match {
2032 scrutinee_index,
2033 arms,
2034 } => Term::Match {
2035 scrutinee_index: scrutinee_index + offset,
2036 arms: TermList {
2037 start: arms.start + offset,
2038 len: arms.len,
2039 },
2040 },
2041 Term::Recurse {
2042 measure_index,
2043 base_index,
2044 step_index,
2045 } => Term::Recurse {
2046 measure_index: measure_index + offset,
2047 base_index: base_index + offset,
2048 step_index: step_index + offset,
2049 },
2050 Term::Unfold {
2051 seed_index,
2052 step_index,
2053 } => Term::Unfold {
2054 seed_index: seed_index + offset,
2055 step_index: step_index + offset,
2056 },
2057 Term::Try {
2058 body_index,
2059 handler_index,
2060 } => Term::Try {
2061 body_index: body_index + offset,
2062 handler_index: if handler_index == u32::MAX {
2063 u32::MAX
2064 } else {
2065 handler_index + offset
2066 },
2067 },
2068 Term::AxisInvocation {
2069 axis_index,
2070 kernel_id,
2071 input_index,
2072 } => Term::AxisInvocation {
2073 axis_index,
2074 kernel_id,
2075 input_index: input_index + offset,
2076 },
2077 Term::ProjectField {
2078 source_index,
2079 byte_offset,
2080 byte_length,
2081 } => Term::ProjectField {
2082 source_index: source_index + offset,
2083 byte_offset,
2084 byte_length,
2085 },
2086 Term::FirstAdmit {
2087 domain_size_index,
2088 predicate_index,
2089 } => Term::FirstAdmit {
2090 domain_size_index: domain_size_index + offset,
2091 predicate_index: predicate_index + offset,
2092 },
2093 Term::Nerve { value_index } => Term::Nerve {
2094 value_index: value_index + offset,
2095 },
2096 Term::ChainComplex { simplicial_index } => Term::ChainComplex {
2097 simplicial_index: simplicial_index + offset,
2098 },
2099 Term::HomologyGroups { chain_index } => Term::HomologyGroups {
2100 chain_index: chain_index + offset,
2101 },
2102 Term::Betti { homology_index } => Term::Betti {
2103 homology_index: homology_index + offset,
2104 },
2105 Term::CochainComplex { chain_index } => Term::CochainComplex {
2106 chain_index: chain_index + offset,
2107 },
2108 Term::CohomologyGroups { cochain_index } => Term::CohomologyGroups {
2109 cochain_index: cochain_index + offset,
2110 },
2111 Term::PostnikovTower { simplicial_index } => Term::PostnikovTower {
2112 simplicial_index: simplicial_index + offset,
2113 },
2114 Term::HomotopyGroups { postnikov_index } => Term::HomotopyGroups {
2115 postnikov_index: postnikov_index + offset,
2116 },
2117 Term::KInvariants { homotopy_index } => Term::KInvariants {
2118 homotopy_index: homotopy_index + offset,
2119 },
2120 }
2121}
2122
2123#[must_use]
2139pub const fn inline_verb_fragment<'a, const INLINE_BYTES: usize, const CAP: usize>(
2140 mut buf: [Term<'a, INLINE_BYTES>; CAP],
2141 mut len: usize,
2142 fragment: &[Term<'a, INLINE_BYTES>],
2143 arg_root_idx: u32,
2144) -> ([Term<'a, INLINE_BYTES>; CAP], usize) {
2145 let offset = len as u32;
2146 let arg_root_term = buf[arg_root_idx as usize];
2149 let mut i = 0;
2150 while i < fragment.len() {
2151 let term = fragment[i];
2152 let new_term = match term {
2153 Term::Variable { name_index: 0 } => arg_root_term,
2154 other => shift_term(other, offset),
2155 };
2156 buf[len] = new_term;
2157 len += 1;
2158 i += 1;
2159 }
2160 (buf, len)
2161}
2162
2163#[derive(Debug, Clone, PartialEq, Eq)]
2165pub struct TypeDeclaration {
2166 pub name_index: u32,
2168 pub constraints: TermList,
2170}
2171
2172#[derive(Debug, Clone, PartialEq, Eq)]
2174pub struct Binding {
2175 pub name_index: u32,
2177 pub type_index: u32,
2179 pub value_index: u32,
2181 pub surface: &'static str,
2183 pub content_address: u64,
2185}
2186
2187impl Binding {
2188 #[inline]
2193 #[must_use]
2194 pub const fn to_binding_entry(&self) -> BindingEntry {
2195 BindingEntry {
2196 address: ContentAddress::from_u64_fingerprint(self.content_address),
2197 bytes: self.surface.as_bytes(),
2198 }
2199 }
2200}
2201
2202#[derive(Debug, Clone, PartialEq, Eq)]
2204pub struct Assertion {
2205 pub lhs_index: u32,
2207 pub rhs_index: u32,
2209 pub surface: &'static str,
2211}
2212
2213#[derive(Debug, Clone, PartialEq, Eq)]
2215pub struct SourceDeclaration {
2216 pub name_index: u32,
2218 pub type_index: u32,
2220 pub grounding_name_index: u32,
2222}
2223
2224#[derive(Debug, Clone, PartialEq, Eq)]
2226pub struct SinkDeclaration {
2227 pub name_index: u32,
2229 pub type_index: u32,
2231 pub projection_name_index: u32,
2233}
2234
2235#[derive(Debug, Clone, PartialEq, Eq)]
2260pub struct ShapeViolation {
2261 pub shape_iri: &'static str,
2263 pub constraint_iri: &'static str,
2265 pub property_iri: &'static str,
2267 pub expected_range: &'static str,
2269 pub min_count: u32,
2271 pub max_count: u32,
2273 pub kind: ViolationKind,
2275}
2276
2277impl core::fmt::Display for ShapeViolation {
2278 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2279 write!(
2280 f,
2281 "shape violation: {} (constraint {}, property {}, kind {:?})",
2282 self.shape_iri, self.constraint_iri, self.property_iri, self.kind,
2283 )
2284 }
2285}
2286
2287impl core::error::Error for ShapeViolation {}
2288
2289impl ShapeViolation {
2290 #[inline]
2294 #[must_use]
2295 pub const fn const_message(&self) -> &'static str {
2296 self.shape_iri
2297 }
2298}
2299
2300#[derive(Debug, Clone)]
2343pub struct CompileUnitBuilder<'a, const INLINE_BYTES: usize> {
2344 root_term: Option<&'a [Term<'a, INLINE_BYTES>]>,
2346 bindings: Option<&'a [Binding]>,
2350 witt_level_ceiling: Option<WittLevel>,
2352 thermodynamic_budget: Option<u64>,
2354 target_domains: Option<&'a [VerificationDomain]>,
2356 result_type_iri: Option<&'static str>,
2362}
2363
2364#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2374pub struct CompileUnit<'a, const INLINE_BYTES: usize> {
2375 level: WittLevel,
2377 budget: u64,
2379 result_type_iri: &'static str,
2382 root_term: &'a [Term<'a, INLINE_BYTES>],
2387 bindings: &'a [Binding],
2391 target_domains: &'a [VerificationDomain],
2393}
2394
2395impl<'a, const INLINE_BYTES: usize> CompileUnit<'a, INLINE_BYTES> {
2396 #[inline]
2398 #[must_use]
2399 pub const fn witt_level(&self) -> WittLevel {
2400 self.level
2401 }
2402
2403 #[inline]
2405 #[must_use]
2406 pub const fn thermodynamic_budget(&self) -> u64 {
2407 self.budget
2408 }
2409
2410 #[inline]
2414 #[must_use]
2415 pub const fn result_type_iri(&self) -> &'static str {
2416 self.result_type_iri
2417 }
2418
2419 #[inline]
2422 #[must_use]
2423 pub const fn root_term(&self) -> &'a [Term<'a, INLINE_BYTES>] {
2424 self.root_term
2425 }
2426
2427 #[inline]
2431 #[must_use]
2432 pub const fn bindings(&self) -> &'a [Binding] {
2433 self.bindings
2434 }
2435
2436 #[inline]
2438 #[must_use]
2439 pub const fn target_domains(&self) -> &'a [VerificationDomain] {
2440 self.target_domains
2441 }
2442
2443 #[inline]
2449 #[must_use]
2450 pub(crate) const fn from_parts_const(
2451 level: WittLevel,
2452 budget: u64,
2453 result_type_iri: &'static str,
2454 root_term: &'a [Term<'a, INLINE_BYTES>],
2455 bindings: &'a [Binding],
2456 target_domains: &'a [VerificationDomain],
2457 ) -> Self {
2458 Self {
2459 level,
2460 budget,
2461 result_type_iri,
2462 root_term,
2463 bindings,
2464 target_domains,
2465 }
2466 }
2467}
2468
2469impl<'a, const INLINE_BYTES: usize> CompileUnitBuilder<'a, INLINE_BYTES> {
2470 #[must_use]
2472 pub const fn new() -> Self {
2473 Self {
2474 root_term: None,
2475 bindings: None,
2476 witt_level_ceiling: None,
2477 thermodynamic_budget: None,
2478 target_domains: None,
2479 result_type_iri: None,
2480 }
2481 }
2482
2483 #[must_use]
2485 pub const fn root_term(mut self, terms: &'a [Term<'a, INLINE_BYTES>]) -> Self {
2486 self.root_term = Some(terms);
2487 self
2488 }
2489
2490 #[must_use]
2495 pub const fn bindings(mut self, bindings: &'a [Binding]) -> Self {
2496 self.bindings = Some(bindings);
2497 self
2498 }
2499
2500 #[must_use]
2502 pub const fn witt_level_ceiling(mut self, level: WittLevel) -> Self {
2503 self.witt_level_ceiling = Some(level);
2504 self
2505 }
2506
2507 #[must_use]
2509 pub const fn thermodynamic_budget(mut self, budget: u64) -> Self {
2510 self.thermodynamic_budget = Some(budget);
2511 self
2512 }
2513
2514 #[must_use]
2516 pub const fn target_domains(mut self, domains: &'a [VerificationDomain]) -> Self {
2517 self.target_domains = Some(domains);
2518 self
2519 }
2520
2521 #[must_use]
2528 pub const fn result_type<T: crate::pipeline::ConstrainedTypeShape>(mut self) -> Self {
2529 self.result_type_iri = Some(T::IRI);
2530 self
2531 }
2532
2533 #[inline]
2536 #[must_use]
2537 pub const fn witt_level_option(&self) -> Option<WittLevel> {
2538 self.witt_level_ceiling
2539 }
2540
2541 #[inline]
2544 #[must_use]
2545 pub const fn budget_option(&self) -> Option<u64> {
2546 self.thermodynamic_budget
2547 }
2548
2549 #[inline]
2551 #[must_use]
2552 pub const fn has_root_term_const(&self) -> bool {
2553 self.root_term.is_some()
2554 }
2555
2556 #[inline]
2559 #[must_use]
2560 pub const fn has_target_domains_const(&self) -> bool {
2561 match self.target_domains {
2562 Some(d) => !d.is_empty(),
2563 None => false,
2564 }
2565 }
2566
2567 #[inline]
2570 #[must_use]
2571 pub const fn result_type_iri_const(&self) -> Option<&'static str> {
2572 self.result_type_iri
2573 }
2574
2575 #[inline]
2579 #[must_use]
2580 pub const fn root_term_slice_const(&self) -> &'a [Term<'a, INLINE_BYTES>] {
2581 match self.root_term {
2582 Some(terms) => terms,
2583 None => &[],
2584 }
2585 }
2586
2587 #[inline]
2591 #[must_use]
2592 pub const fn bindings_slice_const(&self) -> &'a [Binding] {
2593 match self.bindings {
2594 Some(bindings) => bindings,
2595 None => &[],
2596 }
2597 }
2598
2599 #[inline]
2602 #[must_use]
2603 pub const fn target_domains_slice_const(&self) -> &'a [VerificationDomain] {
2604 match self.target_domains {
2605 Some(d) => d,
2606 None => &[],
2607 }
2608 }
2609
2610 pub fn validate(self) -> Result<Validated<CompileUnit<'a, INLINE_BYTES>>, ShapeViolation> {
2616 let root_term = match self.root_term {
2617 Some(terms) => terms,
2618 None => {
2619 return Err(ShapeViolation {
2620 shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
2621 constraint_iri:
2622 "https://uor.foundation/conformance/compileUnit_rootTerm_constraint",
2623 property_iri: "https://uor.foundation/reduction/rootTerm",
2624 expected_range: "https://uor.foundation/schema/Term",
2625 min_count: 1,
2626 max_count: 1,
2627 kind: ViolationKind::Missing,
2628 })
2629 }
2630 };
2631 let level =
2632 match self.witt_level_ceiling {
2633 Some(l) => l,
2634 None => return Err(ShapeViolation {
2635 shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
2636 constraint_iri:
2637 "https://uor.foundation/conformance/compileUnit_unitWittLevel_constraint",
2638 property_iri: "https://uor.foundation/reduction/unitWittLevel",
2639 expected_range: "https://uor.foundation/schema/WittLevel",
2640 min_count: 1,
2641 max_count: 1,
2642 kind: ViolationKind::Missing,
2643 }),
2644 };
2645 let budget = match self.thermodynamic_budget {
2646 Some(b) => b,
2647 None => return Err(ShapeViolation {
2648 shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
2649 constraint_iri:
2650 "https://uor.foundation/conformance/compileUnit_thermodynamicBudget_constraint",
2651 property_iri: "https://uor.foundation/reduction/thermodynamicBudget",
2652 expected_range: "http://www.w3.org/2001/XMLSchema#decimal",
2653 min_count: 1,
2654 max_count: 1,
2655 kind: ViolationKind::Missing,
2656 }),
2657 };
2658 let target_domains =
2659 match self.target_domains {
2660 Some(d) if !d.is_empty() => d,
2661 _ => return Err(ShapeViolation {
2662 shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
2663 constraint_iri:
2664 "https://uor.foundation/conformance/compileUnit_targetDomains_constraint",
2665 property_iri: "https://uor.foundation/reduction/targetDomains",
2666 expected_range: "https://uor.foundation/op/VerificationDomain",
2667 min_count: 1,
2668 max_count: 0,
2669 kind: ViolationKind::Missing,
2670 }),
2671 };
2672 let result_type_iri = match self.result_type_iri {
2673 Some(iri) => iri,
2674 None => {
2675 return Err(ShapeViolation {
2676 shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
2677 constraint_iri:
2678 "https://uor.foundation/conformance/compileUnit_resultType_constraint",
2679 property_iri: "https://uor.foundation/reduction/resultType",
2680 expected_range: "https://uor.foundation/type/ConstrainedType",
2681 min_count: 1,
2682 max_count: 1,
2683 kind: ViolationKind::Missing,
2684 })
2685 }
2686 };
2687 let bindings: &'a [Binding] = match self.bindings {
2689 Some(b) => b,
2690 None => &[],
2691 };
2692 Ok(Validated::new(CompileUnit {
2693 level,
2694 budget,
2695 result_type_iri,
2696 root_term,
2697 bindings,
2698 target_domains,
2699 }))
2700 }
2701}
2702
2703impl<'a, const INLINE_BYTES: usize> Default for CompileUnitBuilder<'a, INLINE_BYTES> {
2704 fn default() -> Self {
2705 Self::new()
2706 }
2707}
2708
2709#[derive(Debug, Clone)]
2711pub struct EffectDeclarationBuilder<'a> {
2712 name: Option<&'a str>,
2714 target_sites: Option<&'a [u32]>,
2716 budget_delta: Option<i64>,
2718 commutes: Option<bool>,
2720}
2721
2722#[derive(Debug, Clone, PartialEq, Eq)]
2724pub struct EffectDeclaration {
2725 pub shape_iri: &'static str,
2727}
2728
2729impl EffectDeclaration {
2730 #[inline]
2733 #[must_use]
2734 #[allow(dead_code)]
2735 pub(crate) const fn empty_const() -> Self {
2736 Self {
2737 shape_iri: "https://uor.foundation/conformance/EffectShape",
2738 }
2739 }
2740}
2741
2742impl<'a> EffectDeclarationBuilder<'a> {
2743 #[must_use]
2745 pub const fn new() -> Self {
2746 Self {
2747 name: None,
2748 target_sites: None,
2749 budget_delta: None,
2750 commutes: None,
2751 }
2752 }
2753
2754 #[must_use]
2756 pub const fn name(mut self, value: &'a str) -> Self {
2757 self.name = Some(value);
2758 self
2759 }
2760
2761 #[must_use]
2763 pub const fn target_sites(mut self, value: &'a [u32]) -> Self {
2764 self.target_sites = Some(value);
2765 self
2766 }
2767
2768 #[must_use]
2770 pub const fn budget_delta(mut self, value: i64) -> Self {
2771 self.budget_delta = Some(value);
2772 self
2773 }
2774
2775 #[must_use]
2777 pub const fn commutes(mut self, value: bool) -> Self {
2778 self.commutes = Some(value);
2779 self
2780 }
2781
2782 pub fn validate(self) -> Result<Validated<EffectDeclaration>, ShapeViolation> {
2786 if self.name.is_none() {
2787 return Err(ShapeViolation {
2788 shape_iri: "https://uor.foundation/conformance/EffectShape",
2789 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2790 property_iri: "https://uor.foundation/conformance/name",
2791 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2792 min_count: 1,
2793 max_count: 1,
2794 kind: ViolationKind::Missing,
2795 });
2796 }
2797 if self.target_sites.is_none() {
2798 return Err(ShapeViolation {
2799 shape_iri: "https://uor.foundation/conformance/EffectShape",
2800 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2801 property_iri: "https://uor.foundation/conformance/target_sites",
2802 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2803 min_count: 1,
2804 max_count: 1,
2805 kind: ViolationKind::Missing,
2806 });
2807 }
2808 if self.budget_delta.is_none() {
2809 return Err(ShapeViolation {
2810 shape_iri: "https://uor.foundation/conformance/EffectShape",
2811 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2812 property_iri: "https://uor.foundation/conformance/budget_delta",
2813 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2814 min_count: 1,
2815 max_count: 1,
2816 kind: ViolationKind::Missing,
2817 });
2818 }
2819 if self.commutes.is_none() {
2820 return Err(ShapeViolation {
2821 shape_iri: "https://uor.foundation/conformance/EffectShape",
2822 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2823 property_iri: "https://uor.foundation/conformance/commutes",
2824 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2825 min_count: 1,
2826 max_count: 1,
2827 kind: ViolationKind::Missing,
2828 });
2829 }
2830 Ok(Validated::new(EffectDeclaration {
2831 shape_iri: "https://uor.foundation/conformance/EffectShape",
2832 }))
2833 }
2834
2835 pub const fn validate_const(
2841 &self,
2842 ) -> Result<Validated<EffectDeclaration, CompileTime>, ShapeViolation> {
2843 if self.name.is_none() {
2844 return Err(ShapeViolation {
2845 shape_iri: "https://uor.foundation/conformance/EffectShape",
2846 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2847 property_iri: "https://uor.foundation/conformance/name",
2848 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2849 min_count: 1,
2850 max_count: 1,
2851 kind: ViolationKind::Missing,
2852 });
2853 }
2854 if self.target_sites.is_none() {
2855 return Err(ShapeViolation {
2856 shape_iri: "https://uor.foundation/conformance/EffectShape",
2857 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2858 property_iri: "https://uor.foundation/conformance/target_sites",
2859 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2860 min_count: 1,
2861 max_count: 1,
2862 kind: ViolationKind::Missing,
2863 });
2864 }
2865 if self.budget_delta.is_none() {
2866 return Err(ShapeViolation {
2867 shape_iri: "https://uor.foundation/conformance/EffectShape",
2868 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2869 property_iri: "https://uor.foundation/conformance/budget_delta",
2870 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2871 min_count: 1,
2872 max_count: 1,
2873 kind: ViolationKind::Missing,
2874 });
2875 }
2876 if self.commutes.is_none() {
2877 return Err(ShapeViolation {
2878 shape_iri: "https://uor.foundation/conformance/EffectShape",
2879 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2880 property_iri: "https://uor.foundation/conformance/commutes",
2881 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2882 min_count: 1,
2883 max_count: 1,
2884 kind: ViolationKind::Missing,
2885 });
2886 }
2887 Ok(Validated::new(EffectDeclaration {
2888 shape_iri: "https://uor.foundation/conformance/EffectShape",
2889 }))
2890 }
2891}
2892
2893impl<'a> Default for EffectDeclarationBuilder<'a> {
2894 fn default() -> Self {
2895 Self::new()
2896 }
2897}
2898
2899#[derive(Debug, Clone)]
2901pub struct GroundingDeclarationBuilder<'a> {
2902 source_type: Option<&'a str>,
2904 ring_mapping: Option<&'a str>,
2906 invertibility: Option<bool>,
2908}
2909
2910#[derive(Debug, Clone, PartialEq, Eq)]
2912pub struct GroundingDeclaration {
2913 pub shape_iri: &'static str,
2915}
2916
2917impl GroundingDeclaration {
2918 #[inline]
2921 #[must_use]
2922 #[allow(dead_code)]
2923 pub(crate) const fn empty_const() -> Self {
2924 Self {
2925 shape_iri: "https://uor.foundation/conformance/GroundingShape",
2926 }
2927 }
2928}
2929
2930impl<'a> GroundingDeclarationBuilder<'a> {
2931 #[must_use]
2933 pub const fn new() -> Self {
2934 Self {
2935 source_type: None,
2936 ring_mapping: None,
2937 invertibility: None,
2938 }
2939 }
2940
2941 #[must_use]
2943 pub const fn source_type(mut self, value: &'a str) -> Self {
2944 self.source_type = Some(value);
2945 self
2946 }
2947
2948 #[must_use]
2950 pub const fn ring_mapping(mut self, value: &'a str) -> Self {
2951 self.ring_mapping = Some(value);
2952 self
2953 }
2954
2955 #[must_use]
2957 pub const fn invertibility(mut self, value: bool) -> Self {
2958 self.invertibility = Some(value);
2959 self
2960 }
2961
2962 pub fn validate(self) -> Result<Validated<GroundingDeclaration>, ShapeViolation> {
2966 if self.source_type.is_none() {
2967 return Err(ShapeViolation {
2968 shape_iri: "https://uor.foundation/conformance/GroundingShape",
2969 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
2970 property_iri: "https://uor.foundation/conformance/source_type",
2971 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2972 min_count: 1,
2973 max_count: 1,
2974 kind: ViolationKind::Missing,
2975 });
2976 }
2977 if self.ring_mapping.is_none() {
2978 return Err(ShapeViolation {
2979 shape_iri: "https://uor.foundation/conformance/GroundingShape",
2980 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
2981 property_iri: "https://uor.foundation/conformance/ring_mapping",
2982 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2983 min_count: 1,
2984 max_count: 1,
2985 kind: ViolationKind::Missing,
2986 });
2987 }
2988 if self.invertibility.is_none() {
2989 return Err(ShapeViolation {
2990 shape_iri: "https://uor.foundation/conformance/GroundingShape",
2991 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
2992 property_iri: "https://uor.foundation/conformance/invertibility",
2993 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2994 min_count: 1,
2995 max_count: 1,
2996 kind: ViolationKind::Missing,
2997 });
2998 }
2999 Ok(Validated::new(GroundingDeclaration {
3000 shape_iri: "https://uor.foundation/conformance/GroundingShape",
3001 }))
3002 }
3003
3004 pub const fn validate_const(
3010 &self,
3011 ) -> Result<Validated<GroundingDeclaration, CompileTime>, ShapeViolation> {
3012 if self.source_type.is_none() {
3013 return Err(ShapeViolation {
3014 shape_iri: "https://uor.foundation/conformance/GroundingShape",
3015 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
3016 property_iri: "https://uor.foundation/conformance/source_type",
3017 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3018 min_count: 1,
3019 max_count: 1,
3020 kind: ViolationKind::Missing,
3021 });
3022 }
3023 if self.ring_mapping.is_none() {
3024 return Err(ShapeViolation {
3025 shape_iri: "https://uor.foundation/conformance/GroundingShape",
3026 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
3027 property_iri: "https://uor.foundation/conformance/ring_mapping",
3028 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3029 min_count: 1,
3030 max_count: 1,
3031 kind: ViolationKind::Missing,
3032 });
3033 }
3034 if self.invertibility.is_none() {
3035 return Err(ShapeViolation {
3036 shape_iri: "https://uor.foundation/conformance/GroundingShape",
3037 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
3038 property_iri: "https://uor.foundation/conformance/invertibility",
3039 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3040 min_count: 1,
3041 max_count: 1,
3042 kind: ViolationKind::Missing,
3043 });
3044 }
3045 Ok(Validated::new(GroundingDeclaration {
3046 shape_iri: "https://uor.foundation/conformance/GroundingShape",
3047 }))
3048 }
3049}
3050
3051impl<'a> Default for GroundingDeclarationBuilder<'a> {
3052 fn default() -> Self {
3053 Self::new()
3054 }
3055}
3056
3057#[derive(Debug, Clone)]
3059pub struct DispatchDeclarationBuilder<'a, const INLINE_BYTES: usize> {
3060 predicate: Option<&'a [Term<'a, INLINE_BYTES>]>,
3062 target_resolver: Option<&'a str>,
3064 priority: Option<u32>,
3066}
3067
3068#[derive(Debug, Clone, PartialEq, Eq)]
3070pub struct DispatchDeclaration {
3071 pub shape_iri: &'static str,
3073}
3074
3075impl DispatchDeclaration {
3076 #[inline]
3079 #[must_use]
3080 #[allow(dead_code)]
3081 pub(crate) const fn empty_const() -> Self {
3082 Self {
3083 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3084 }
3085 }
3086}
3087
3088impl<'a, const INLINE_BYTES: usize> DispatchDeclarationBuilder<'a, INLINE_BYTES> {
3089 #[must_use]
3091 pub const fn new() -> Self {
3092 Self {
3093 predicate: None,
3094 target_resolver: None,
3095 priority: None,
3096 }
3097 }
3098
3099 #[must_use]
3101 pub const fn predicate(mut self, value: &'a [Term<'a, INLINE_BYTES>]) -> Self {
3102 self.predicate = Some(value);
3103 self
3104 }
3105
3106 #[must_use]
3108 pub const fn target_resolver(mut self, value: &'a str) -> Self {
3109 self.target_resolver = Some(value);
3110 self
3111 }
3112
3113 #[must_use]
3115 pub const fn priority(mut self, value: u32) -> Self {
3116 self.priority = Some(value);
3117 self
3118 }
3119
3120 pub fn validate(self) -> Result<Validated<DispatchDeclaration>, ShapeViolation> {
3124 if self.predicate.is_none() {
3125 return Err(ShapeViolation {
3126 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3127 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3128 property_iri: "https://uor.foundation/conformance/predicate",
3129 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3130 min_count: 1,
3131 max_count: 1,
3132 kind: ViolationKind::Missing,
3133 });
3134 }
3135 if self.target_resolver.is_none() {
3136 return Err(ShapeViolation {
3137 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3138 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3139 property_iri: "https://uor.foundation/conformance/target_resolver",
3140 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3141 min_count: 1,
3142 max_count: 1,
3143 kind: ViolationKind::Missing,
3144 });
3145 }
3146 if self.priority.is_none() {
3147 return Err(ShapeViolation {
3148 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3149 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3150 property_iri: "https://uor.foundation/conformance/priority",
3151 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3152 min_count: 1,
3153 max_count: 1,
3154 kind: ViolationKind::Missing,
3155 });
3156 }
3157 Ok(Validated::new(DispatchDeclaration {
3158 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3159 }))
3160 }
3161
3162 pub const fn validate_const(
3168 &self,
3169 ) -> Result<Validated<DispatchDeclaration, CompileTime>, ShapeViolation> {
3170 if self.predicate.is_none() {
3171 return Err(ShapeViolation {
3172 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3173 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3174 property_iri: "https://uor.foundation/conformance/predicate",
3175 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3176 min_count: 1,
3177 max_count: 1,
3178 kind: ViolationKind::Missing,
3179 });
3180 }
3181 if self.target_resolver.is_none() {
3182 return Err(ShapeViolation {
3183 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3184 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3185 property_iri: "https://uor.foundation/conformance/target_resolver",
3186 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3187 min_count: 1,
3188 max_count: 1,
3189 kind: ViolationKind::Missing,
3190 });
3191 }
3192 if self.priority.is_none() {
3193 return Err(ShapeViolation {
3194 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3195 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3196 property_iri: "https://uor.foundation/conformance/priority",
3197 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3198 min_count: 1,
3199 max_count: 1,
3200 kind: ViolationKind::Missing,
3201 });
3202 }
3203 Ok(Validated::new(DispatchDeclaration {
3204 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3205 }))
3206 }
3207}
3208
3209impl<'a, const INLINE_BYTES: usize> Default for DispatchDeclarationBuilder<'a, INLINE_BYTES> {
3210 fn default() -> Self {
3211 Self::new()
3212 }
3213}
3214
3215#[derive(Debug, Clone)]
3217pub struct LeaseDeclarationBuilder<'a> {
3218 linear_site: Option<u32>,
3220 scope: Option<&'a str>,
3222}
3223
3224#[derive(Debug, Clone, PartialEq, Eq)]
3226pub struct LeaseDeclaration {
3227 pub shape_iri: &'static str,
3229}
3230
3231impl LeaseDeclaration {
3232 #[inline]
3235 #[must_use]
3236 #[allow(dead_code)]
3237 pub(crate) const fn empty_const() -> Self {
3238 Self {
3239 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3240 }
3241 }
3242}
3243
3244impl<'a> LeaseDeclarationBuilder<'a> {
3245 #[must_use]
3247 pub const fn new() -> Self {
3248 Self {
3249 linear_site: None,
3250 scope: None,
3251 }
3252 }
3253
3254 #[must_use]
3256 pub const fn linear_site(mut self, value: u32) -> Self {
3257 self.linear_site = Some(value);
3258 self
3259 }
3260
3261 #[must_use]
3263 pub const fn scope(mut self, value: &'a str) -> Self {
3264 self.scope = Some(value);
3265 self
3266 }
3267
3268 pub fn validate(self) -> Result<Validated<LeaseDeclaration>, ShapeViolation> {
3272 if self.linear_site.is_none() {
3273 return Err(ShapeViolation {
3274 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3275 constraint_iri: "https://uor.foundation/conformance/LeaseShape",
3276 property_iri: "https://uor.foundation/conformance/linear_site",
3277 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3278 min_count: 1,
3279 max_count: 1,
3280 kind: ViolationKind::Missing,
3281 });
3282 }
3283 if self.scope.is_none() {
3284 return Err(ShapeViolation {
3285 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3286 constraint_iri: "https://uor.foundation/conformance/LeaseShape",
3287 property_iri: "https://uor.foundation/conformance/scope",
3288 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3289 min_count: 1,
3290 max_count: 1,
3291 kind: ViolationKind::Missing,
3292 });
3293 }
3294 Ok(Validated::new(LeaseDeclaration {
3295 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3296 }))
3297 }
3298
3299 pub const fn validate_const(
3305 &self,
3306 ) -> Result<Validated<LeaseDeclaration, CompileTime>, ShapeViolation> {
3307 if self.linear_site.is_none() {
3308 return Err(ShapeViolation {
3309 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3310 constraint_iri: "https://uor.foundation/conformance/LeaseShape",
3311 property_iri: "https://uor.foundation/conformance/linear_site",
3312 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3313 min_count: 1,
3314 max_count: 1,
3315 kind: ViolationKind::Missing,
3316 });
3317 }
3318 if self.scope.is_none() {
3319 return Err(ShapeViolation {
3320 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3321 constraint_iri: "https://uor.foundation/conformance/LeaseShape",
3322 property_iri: "https://uor.foundation/conformance/scope",
3323 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3324 min_count: 1,
3325 max_count: 1,
3326 kind: ViolationKind::Missing,
3327 });
3328 }
3329 Ok(Validated::new(LeaseDeclaration {
3330 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3331 }))
3332 }
3333}
3334
3335impl<'a> Default for LeaseDeclarationBuilder<'a> {
3336 fn default() -> Self {
3337 Self::new()
3338 }
3339}
3340
3341#[derive(Debug, Clone)]
3343pub struct StreamDeclarationBuilder<'a, const INLINE_BYTES: usize> {
3344 seed: Option<&'a [Term<'a, INLINE_BYTES>]>,
3346 step: Option<&'a [Term<'a, INLINE_BYTES>]>,
3348 productivity_witness: Option<&'a str>,
3350}
3351
3352#[derive(Debug, Clone, PartialEq, Eq)]
3354pub struct StreamDeclaration {
3355 pub shape_iri: &'static str,
3357}
3358
3359impl StreamDeclaration {
3360 #[inline]
3363 #[must_use]
3364 #[allow(dead_code)]
3365 pub(crate) const fn empty_const() -> Self {
3366 Self {
3367 shape_iri: "https://uor.foundation/conformance/StreamShape",
3368 }
3369 }
3370}
3371
3372impl<'a, const INLINE_BYTES: usize> StreamDeclarationBuilder<'a, INLINE_BYTES> {
3373 #[must_use]
3375 pub const fn new() -> Self {
3376 Self {
3377 seed: None,
3378 step: None,
3379 productivity_witness: None,
3380 }
3381 }
3382
3383 #[must_use]
3385 pub const fn seed(mut self, value: &'a [Term<'a, INLINE_BYTES>]) -> Self {
3386 self.seed = Some(value);
3387 self
3388 }
3389
3390 #[must_use]
3392 pub const fn step(mut self, value: &'a [Term<'a, INLINE_BYTES>]) -> Self {
3393 self.step = Some(value);
3394 self
3395 }
3396
3397 #[must_use]
3399 pub const fn productivity_witness(mut self, value: &'a str) -> Self {
3400 self.productivity_witness = Some(value);
3401 self
3402 }
3403
3404 pub fn validate(self) -> Result<Validated<StreamDeclaration>, ShapeViolation> {
3408 if self.seed.is_none() {
3409 return Err(ShapeViolation {
3410 shape_iri: "https://uor.foundation/conformance/StreamShape",
3411 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3412 property_iri: "https://uor.foundation/conformance/seed",
3413 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3414 min_count: 1,
3415 max_count: 1,
3416 kind: ViolationKind::Missing,
3417 });
3418 }
3419 if self.step.is_none() {
3420 return Err(ShapeViolation {
3421 shape_iri: "https://uor.foundation/conformance/StreamShape",
3422 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3423 property_iri: "https://uor.foundation/conformance/step",
3424 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3425 min_count: 1,
3426 max_count: 1,
3427 kind: ViolationKind::Missing,
3428 });
3429 }
3430 if self.productivity_witness.is_none() {
3431 return Err(ShapeViolation {
3432 shape_iri: "https://uor.foundation/conformance/StreamShape",
3433 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3434 property_iri: "https://uor.foundation/conformance/productivity_witness",
3435 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3436 min_count: 1,
3437 max_count: 1,
3438 kind: ViolationKind::Missing,
3439 });
3440 }
3441 Ok(Validated::new(StreamDeclaration {
3442 shape_iri: "https://uor.foundation/conformance/StreamShape",
3443 }))
3444 }
3445
3446 pub const fn validate_const(
3452 &self,
3453 ) -> Result<Validated<StreamDeclaration, CompileTime>, ShapeViolation> {
3454 if self.seed.is_none() {
3455 return Err(ShapeViolation {
3456 shape_iri: "https://uor.foundation/conformance/StreamShape",
3457 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3458 property_iri: "https://uor.foundation/conformance/seed",
3459 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3460 min_count: 1,
3461 max_count: 1,
3462 kind: ViolationKind::Missing,
3463 });
3464 }
3465 if self.step.is_none() {
3466 return Err(ShapeViolation {
3467 shape_iri: "https://uor.foundation/conformance/StreamShape",
3468 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3469 property_iri: "https://uor.foundation/conformance/step",
3470 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3471 min_count: 1,
3472 max_count: 1,
3473 kind: ViolationKind::Missing,
3474 });
3475 }
3476 if self.productivity_witness.is_none() {
3477 return Err(ShapeViolation {
3478 shape_iri: "https://uor.foundation/conformance/StreamShape",
3479 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3480 property_iri: "https://uor.foundation/conformance/productivity_witness",
3481 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3482 min_count: 1,
3483 max_count: 1,
3484 kind: ViolationKind::Missing,
3485 });
3486 }
3487 Ok(Validated::new(StreamDeclaration {
3488 shape_iri: "https://uor.foundation/conformance/StreamShape",
3489 }))
3490 }
3491}
3492
3493impl<'a, const INLINE_BYTES: usize> Default for StreamDeclarationBuilder<'a, INLINE_BYTES> {
3494 fn default() -> Self {
3495 Self::new()
3496 }
3497}
3498
3499#[derive(Debug, Clone)]
3501pub struct PredicateDeclarationBuilder<'a, const INLINE_BYTES: usize> {
3502 input_type: Option<&'a str>,
3504 evaluator: Option<&'a [Term<'a, INLINE_BYTES>]>,
3506 termination_witness: Option<&'a str>,
3508}
3509
3510#[derive(Debug, Clone, PartialEq, Eq)]
3512pub struct PredicateDeclaration {
3513 pub shape_iri: &'static str,
3515}
3516
3517impl PredicateDeclaration {
3518 #[inline]
3521 #[must_use]
3522 #[allow(dead_code)]
3523 pub(crate) const fn empty_const() -> Self {
3524 Self {
3525 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3526 }
3527 }
3528}
3529
3530impl<'a, const INLINE_BYTES: usize> PredicateDeclarationBuilder<'a, INLINE_BYTES> {
3531 #[must_use]
3533 pub const fn new() -> Self {
3534 Self {
3535 input_type: None,
3536 evaluator: None,
3537 termination_witness: None,
3538 }
3539 }
3540
3541 #[must_use]
3543 pub const fn input_type(mut self, value: &'a str) -> Self {
3544 self.input_type = Some(value);
3545 self
3546 }
3547
3548 #[must_use]
3550 pub const fn evaluator(mut self, value: &'a [Term<'a, INLINE_BYTES>]) -> Self {
3551 self.evaluator = Some(value);
3552 self
3553 }
3554
3555 #[must_use]
3557 pub const fn termination_witness(mut self, value: &'a str) -> Self {
3558 self.termination_witness = Some(value);
3559 self
3560 }
3561
3562 pub fn validate(self) -> Result<Validated<PredicateDeclaration>, ShapeViolation> {
3566 if self.input_type.is_none() {
3567 return Err(ShapeViolation {
3568 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3569 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3570 property_iri: "https://uor.foundation/conformance/input_type",
3571 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3572 min_count: 1,
3573 max_count: 1,
3574 kind: ViolationKind::Missing,
3575 });
3576 }
3577 if self.evaluator.is_none() {
3578 return Err(ShapeViolation {
3579 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3580 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3581 property_iri: "https://uor.foundation/conformance/evaluator",
3582 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3583 min_count: 1,
3584 max_count: 1,
3585 kind: ViolationKind::Missing,
3586 });
3587 }
3588 if self.termination_witness.is_none() {
3589 return Err(ShapeViolation {
3590 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3591 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3592 property_iri: "https://uor.foundation/conformance/termination_witness",
3593 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3594 min_count: 1,
3595 max_count: 1,
3596 kind: ViolationKind::Missing,
3597 });
3598 }
3599 Ok(Validated::new(PredicateDeclaration {
3600 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3601 }))
3602 }
3603
3604 pub const fn validate_const(
3610 &self,
3611 ) -> Result<Validated<PredicateDeclaration, CompileTime>, ShapeViolation> {
3612 if self.input_type.is_none() {
3613 return Err(ShapeViolation {
3614 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3615 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3616 property_iri: "https://uor.foundation/conformance/input_type",
3617 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3618 min_count: 1,
3619 max_count: 1,
3620 kind: ViolationKind::Missing,
3621 });
3622 }
3623 if self.evaluator.is_none() {
3624 return Err(ShapeViolation {
3625 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3626 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3627 property_iri: "https://uor.foundation/conformance/evaluator",
3628 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3629 min_count: 1,
3630 max_count: 1,
3631 kind: ViolationKind::Missing,
3632 });
3633 }
3634 if self.termination_witness.is_none() {
3635 return Err(ShapeViolation {
3636 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3637 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3638 property_iri: "https://uor.foundation/conformance/termination_witness",
3639 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3640 min_count: 1,
3641 max_count: 1,
3642 kind: ViolationKind::Missing,
3643 });
3644 }
3645 Ok(Validated::new(PredicateDeclaration {
3646 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3647 }))
3648 }
3649}
3650
3651impl<'a, const INLINE_BYTES: usize> Default for PredicateDeclarationBuilder<'a, INLINE_BYTES> {
3652 fn default() -> Self {
3653 Self::new()
3654 }
3655}
3656
3657#[derive(Debug, Clone)]
3659pub struct ParallelDeclarationBuilder<'a> {
3660 site_partition: Option<&'a [u32]>,
3662 disjointness_witness: Option<&'a str>,
3664}
3665
3666#[derive(Debug, Clone, PartialEq, Eq)]
3668pub struct ParallelDeclaration {
3669 pub shape_iri: &'static str,
3671}
3672
3673impl ParallelDeclaration {
3674 #[inline]
3677 #[must_use]
3678 #[allow(dead_code)]
3679 pub(crate) const fn empty_const() -> Self {
3680 Self {
3681 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3682 }
3683 }
3684}
3685
3686impl<'a> ParallelDeclarationBuilder<'a> {
3687 #[must_use]
3689 pub const fn new() -> Self {
3690 Self {
3691 site_partition: None,
3692 disjointness_witness: None,
3693 }
3694 }
3695
3696 #[must_use]
3698 pub const fn site_partition(mut self, value: &'a [u32]) -> Self {
3699 self.site_partition = Some(value);
3700 self
3701 }
3702
3703 #[must_use]
3705 pub const fn disjointness_witness(mut self, value: &'a str) -> Self {
3706 self.disjointness_witness = Some(value);
3707 self
3708 }
3709
3710 pub fn validate(self) -> Result<Validated<ParallelDeclaration>, ShapeViolation> {
3714 if self.site_partition.is_none() {
3715 return Err(ShapeViolation {
3716 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3717 constraint_iri: "https://uor.foundation/conformance/ParallelShape",
3718 property_iri: "https://uor.foundation/conformance/site_partition",
3719 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3720 min_count: 1,
3721 max_count: 1,
3722 kind: ViolationKind::Missing,
3723 });
3724 }
3725 if self.disjointness_witness.is_none() {
3726 return Err(ShapeViolation {
3727 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3728 constraint_iri: "https://uor.foundation/conformance/ParallelShape",
3729 property_iri: "https://uor.foundation/conformance/disjointness_witness",
3730 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3731 min_count: 1,
3732 max_count: 1,
3733 kind: ViolationKind::Missing,
3734 });
3735 }
3736 Ok(Validated::new(ParallelDeclaration {
3737 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3738 }))
3739 }
3740
3741 pub const fn validate_const(
3747 &self,
3748 ) -> Result<Validated<ParallelDeclaration, CompileTime>, ShapeViolation> {
3749 if self.site_partition.is_none() {
3750 return Err(ShapeViolation {
3751 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3752 constraint_iri: "https://uor.foundation/conformance/ParallelShape",
3753 property_iri: "https://uor.foundation/conformance/site_partition",
3754 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3755 min_count: 1,
3756 max_count: 1,
3757 kind: ViolationKind::Missing,
3758 });
3759 }
3760 if self.disjointness_witness.is_none() {
3761 return Err(ShapeViolation {
3762 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3763 constraint_iri: "https://uor.foundation/conformance/ParallelShape",
3764 property_iri: "https://uor.foundation/conformance/disjointness_witness",
3765 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3766 min_count: 1,
3767 max_count: 1,
3768 kind: ViolationKind::Missing,
3769 });
3770 }
3771 Ok(Validated::new(ParallelDeclaration {
3772 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3773 }))
3774 }
3775}
3776
3777impl<'a> Default for ParallelDeclarationBuilder<'a> {
3778 fn default() -> Self {
3779 Self::new()
3780 }
3781}
3782
3783impl<'a> ParallelDeclarationBuilder<'a> {
3784 #[inline]
3787 #[must_use]
3788 pub const fn site_partition_len(&self) -> usize {
3789 match self.site_partition {
3790 Some(p) => p.len(),
3791 None => 0,
3792 }
3793 }
3794
3795 #[inline]
3799 #[must_use]
3800 pub const fn site_partition_slice_const(&self) -> &'a [u32] {
3801 match self.site_partition {
3802 Some(p) => p,
3803 None => &[],
3804 }
3805 }
3806
3807 #[inline]
3810 #[must_use]
3811 pub const fn disjointness_witness_const(&self) -> &'a str {
3812 match self.disjointness_witness {
3813 Some(s) => s,
3814 None => "",
3815 }
3816 }
3817}
3818
3819impl<'a, const INLINE_BYTES: usize> StreamDeclarationBuilder<'a, INLINE_BYTES> {
3820 #[inline]
3827 #[must_use]
3828 pub const fn productivity_bound_const(&self) -> u64 {
3829 match self.productivity_witness {
3830 Some(_) => 1,
3831 None => 0,
3832 }
3833 }
3834
3835 #[inline]
3838 #[must_use]
3839 pub const fn seed_slice_const(&self) -> &'a [Term<'a, INLINE_BYTES>] {
3840 match self.seed {
3841 Some(t) => t,
3842 None => &[],
3843 }
3844 }
3845
3846 #[inline]
3849 #[must_use]
3850 pub const fn step_slice_const(&self) -> &'a [Term<'a, INLINE_BYTES>] {
3851 match self.step {
3852 Some(t) => t,
3853 None => &[],
3854 }
3855 }
3856
3857 #[inline]
3860 #[must_use]
3861 pub const fn productivity_witness_const(&self) -> &'a str {
3862 match self.productivity_witness {
3863 Some(s) => s,
3864 None => "",
3865 }
3866 }
3867}
3868
3869#[derive(Debug, Clone)]
3872pub struct WittLevelDeclarationBuilder {
3873 bit_width: Option<u32>,
3875 cycle_size: Option<u128>,
3877 predecessor: Option<WittLevel>,
3879}
3880
3881#[derive(Debug, Clone, PartialEq, Eq)]
3883pub struct WittLevelDeclaration {
3884 pub bit_width: u32,
3886 pub predecessor: WittLevel,
3888}
3889
3890impl WittLevelDeclarationBuilder {
3891 #[must_use]
3893 pub const fn new() -> Self {
3894 Self {
3895 bit_width: None,
3896 cycle_size: None,
3897 predecessor: None,
3898 }
3899 }
3900
3901 #[must_use]
3903 pub const fn bit_width(mut self, w: u32) -> Self {
3904 self.bit_width = Some(w);
3905 self
3906 }
3907
3908 #[must_use]
3910 pub const fn cycle_size(mut self, s: u128) -> Self {
3911 self.cycle_size = Some(s);
3912 self
3913 }
3914
3915 #[must_use]
3917 pub const fn predecessor(mut self, level: WittLevel) -> Self {
3918 self.predecessor = Some(level);
3919 self
3920 }
3921
3922 pub fn validate(self) -> Result<Validated<WittLevelDeclaration>, ShapeViolation> {
3926 let bw = match self.bit_width {
3927 Some(w) => w,
3928 None => {
3929 return Err(ShapeViolation {
3930 shape_iri: "https://uor.foundation/conformance/WittLevelShape",
3931 constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
3932 property_iri: "https://uor.foundation/conformance/declaredBitWidth",
3933 expected_range: "http://www.w3.org/2001/XMLSchema#positiveInteger",
3934 min_count: 1,
3935 max_count: 1,
3936 kind: ViolationKind::Missing,
3937 })
3938 }
3939 };
3940 let pred = match self.predecessor {
3941 Some(p) => p,
3942 None => {
3943 return Err(ShapeViolation {
3944 shape_iri: "https://uor.foundation/conformance/WittLevelShape",
3945 constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
3946 property_iri: "https://uor.foundation/conformance/predecessorLevel",
3947 expected_range: "https://uor.foundation/schema/WittLevel",
3948 min_count: 1,
3949 max_count: 1,
3950 kind: ViolationKind::Missing,
3951 })
3952 }
3953 };
3954 Ok(Validated::new(WittLevelDeclaration {
3955 bit_width: bw,
3956 predecessor: pred,
3957 }))
3958 }
3959
3960 pub const fn validate_const(
3964 &self,
3965 ) -> Result<Validated<WittLevelDeclaration, CompileTime>, ShapeViolation> {
3966 let bw = match self.bit_width {
3967 Some(w) => w,
3968 None => {
3969 return Err(ShapeViolation {
3970 shape_iri: "https://uor.foundation/conformance/WittLevelShape",
3971 constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
3972 property_iri: "https://uor.foundation/conformance/declaredBitWidth",
3973 expected_range: "http://www.w3.org/2001/XMLSchema#positiveInteger",
3974 min_count: 1,
3975 max_count: 1,
3976 kind: ViolationKind::Missing,
3977 })
3978 }
3979 };
3980 let pred = match self.predecessor {
3981 Some(p) => p,
3982 None => {
3983 return Err(ShapeViolation {
3984 shape_iri: "https://uor.foundation/conformance/WittLevelShape",
3985 constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
3986 property_iri: "https://uor.foundation/conformance/predecessorLevel",
3987 expected_range: "https://uor.foundation/schema/WittLevel",
3988 min_count: 1,
3989 max_count: 1,
3990 kind: ViolationKind::Missing,
3991 })
3992 }
3993 };
3994 Ok(Validated::new(WittLevelDeclaration {
3995 bit_width: bw,
3996 predecessor: pred,
3997 }))
3998 }
3999}
4000
4001impl Default for WittLevelDeclarationBuilder {
4002 fn default() -> Self {
4003 Self::new()
4004 }
4005}
4006
4007#[derive(Debug, Clone, PartialEq, Eq)]
4011pub struct BoundarySession {
4012 crossing_count: u32,
4014 is_idempotent: bool,
4016}
4017
4018impl BoundarySession {
4019 #[inline]
4021 #[allow(dead_code)]
4022 pub(crate) const fn new(is_idempotent: bool) -> Self {
4023 Self {
4024 crossing_count: 0,
4025 is_idempotent,
4026 }
4027 }
4028
4029 #[inline]
4031 #[must_use]
4032 pub const fn crossing_count(&self) -> u32 {
4033 self.crossing_count
4034 }
4035
4036 #[inline]
4038 #[must_use]
4039 pub const fn is_idempotent(&self) -> bool {
4040 self.is_idempotent
4041 }
4042}
4043
4044#[allow(dead_code)]
4049pub(crate) fn validate_and_mint_coord(
4050 grounded: GroundedCoord,
4051 shape: &Validated<GroundingDeclaration>,
4052 session: &mut BoundarySession,
4053) -> Result<Datum, ShapeViolation> {
4054 let _ = shape; session.crossing_count += 1;
4060 let inner = match grounded.inner {
4061 GroundedCoordInner::W8(b) => DatumInner::W8(b),
4062 GroundedCoordInner::W16(b) => DatumInner::W16(b),
4063 GroundedCoordInner::W24(b) => DatumInner::W24(b),
4064 GroundedCoordInner::W32(b) => DatumInner::W32(b),
4065 GroundedCoordInner::W40(b) => DatumInner::W40(b),
4066 GroundedCoordInner::W48(b) => DatumInner::W48(b),
4067 GroundedCoordInner::W56(b) => DatumInner::W56(b),
4068 GroundedCoordInner::W64(b) => DatumInner::W64(b),
4069 GroundedCoordInner::W72(b) => DatumInner::W72(b),
4070 GroundedCoordInner::W80(b) => DatumInner::W80(b),
4071 GroundedCoordInner::W88(b) => DatumInner::W88(b),
4072 GroundedCoordInner::W96(b) => DatumInner::W96(b),
4073 GroundedCoordInner::W104(b) => DatumInner::W104(b),
4074 GroundedCoordInner::W112(b) => DatumInner::W112(b),
4075 GroundedCoordInner::W120(b) => DatumInner::W120(b),
4076 GroundedCoordInner::W128(b) => DatumInner::W128(b),
4077 };
4078 Ok(Datum { inner })
4079}
4080
4081#[allow(dead_code)]
4089pub(crate) fn validate_and_mint_tuple<const N: usize>(
4090 grounded: GroundedTuple<N>,
4091 shape: &Validated<GroundingDeclaration>,
4092 session: &mut BoundarySession,
4093) -> Result<Datum, ShapeViolation> {
4094 if N == 0 {
4095 return Err(ShapeViolation {
4096 shape_iri: shape.inner().shape_iri,
4097 constraint_iri: shape.inner().shape_iri,
4098 property_iri: "https://uor.foundation/conformance/groundingSourceType",
4099 expected_range: "https://uor.foundation/type/TypeDefinition",
4100 min_count: 1,
4101 max_count: 0,
4102 kind: ViolationKind::CardinalityViolation,
4103 });
4104 }
4105 validate_and_mint_coord(grounded.coords[0].clone(), shape, session)
4109}
4110
4111pub fn mint_datum(level: crate::WittLevel, bytes: &[u8]) -> Result<Datum, ShapeViolation> {
4119 let expected_bytes = (level.witt_length() / 8) as usize;
4120 if bytes.len() != expected_bytes {
4121 return Err(ShapeViolation {
4122 shape_iri: "https://uor.foundation/u/Datum",
4123 constraint_iri: "https://uor.foundation/u/DatumByteWidth",
4124 property_iri: "https://uor.foundation/u/datumBytes",
4125 expected_range: "http://www.w3.org/2001/XMLSchema#nonNegativeInteger",
4126 min_count: expected_bytes as u32,
4127 max_count: expected_bytes as u32,
4128 kind: crate::ViolationKind::CardinalityViolation,
4129 });
4130 }
4131 let inner = match level.witt_length() {
4132 8 => {
4133 let mut buf = [0u8; 1];
4134 let mut i = 0;
4135 while i < 1 {
4136 buf[i] = bytes[i];
4137 i += 1;
4138 }
4139 DatumInner::W8(buf)
4140 }
4141 16 => {
4142 let mut buf = [0u8; 2];
4143 let mut i = 0;
4144 while i < 2 {
4145 buf[i] = bytes[i];
4146 i += 1;
4147 }
4148 DatumInner::W16(buf)
4149 }
4150 24 => {
4151 let mut buf = [0u8; 3];
4152 let mut i = 0;
4153 while i < 3 {
4154 buf[i] = bytes[i];
4155 i += 1;
4156 }
4157 DatumInner::W24(buf)
4158 }
4159 32 => {
4160 let mut buf = [0u8; 4];
4161 let mut i = 0;
4162 while i < 4 {
4163 buf[i] = bytes[i];
4164 i += 1;
4165 }
4166 DatumInner::W32(buf)
4167 }
4168 40 => {
4169 let mut buf = [0u8; 5];
4170 let mut i = 0;
4171 while i < 5 {
4172 buf[i] = bytes[i];
4173 i += 1;
4174 }
4175 DatumInner::W40(buf)
4176 }
4177 48 => {
4178 let mut buf = [0u8; 6];
4179 let mut i = 0;
4180 while i < 6 {
4181 buf[i] = bytes[i];
4182 i += 1;
4183 }
4184 DatumInner::W48(buf)
4185 }
4186 56 => {
4187 let mut buf = [0u8; 7];
4188 let mut i = 0;
4189 while i < 7 {
4190 buf[i] = bytes[i];
4191 i += 1;
4192 }
4193 DatumInner::W56(buf)
4194 }
4195 64 => {
4196 let mut buf = [0u8; 8];
4197 let mut i = 0;
4198 while i < 8 {
4199 buf[i] = bytes[i];
4200 i += 1;
4201 }
4202 DatumInner::W64(buf)
4203 }
4204 72 => {
4205 let mut buf = [0u8; 9];
4206 let mut i = 0;
4207 while i < 9 {
4208 buf[i] = bytes[i];
4209 i += 1;
4210 }
4211 DatumInner::W72(buf)
4212 }
4213 80 => {
4214 let mut buf = [0u8; 10];
4215 let mut i = 0;
4216 while i < 10 {
4217 buf[i] = bytes[i];
4218 i += 1;
4219 }
4220 DatumInner::W80(buf)
4221 }
4222 88 => {
4223 let mut buf = [0u8; 11];
4224 let mut i = 0;
4225 while i < 11 {
4226 buf[i] = bytes[i];
4227 i += 1;
4228 }
4229 DatumInner::W88(buf)
4230 }
4231 96 => {
4232 let mut buf = [0u8; 12];
4233 let mut i = 0;
4234 while i < 12 {
4235 buf[i] = bytes[i];
4236 i += 1;
4237 }
4238 DatumInner::W96(buf)
4239 }
4240 104 => {
4241 let mut buf = [0u8; 13];
4242 let mut i = 0;
4243 while i < 13 {
4244 buf[i] = bytes[i];
4245 i += 1;
4246 }
4247 DatumInner::W104(buf)
4248 }
4249 112 => {
4250 let mut buf = [0u8; 14];
4251 let mut i = 0;
4252 while i < 14 {
4253 buf[i] = bytes[i];
4254 i += 1;
4255 }
4256 DatumInner::W112(buf)
4257 }
4258 120 => {
4259 let mut buf = [0u8; 15];
4260 let mut i = 0;
4261 while i < 15 {
4262 buf[i] = bytes[i];
4263 i += 1;
4264 }
4265 DatumInner::W120(buf)
4266 }
4267 128 => {
4268 let mut buf = [0u8; 16];
4269 let mut i = 0;
4270 while i < 16 {
4271 buf[i] = bytes[i];
4272 i += 1;
4273 }
4274 DatumInner::W128(buf)
4275 }
4276 _ => {
4277 return Err(ShapeViolation {
4278 shape_iri: "https://uor.foundation/u/Datum",
4279 constraint_iri: "https://uor.foundation/u/DatumLevel",
4280 property_iri: "https://uor.foundation/u/datumLevel",
4281 expected_range: "https://uor.foundation/schema/WittLevel",
4282 min_count: 1,
4283 max_count: 1,
4284 kind: crate::ViolationKind::ValueCheck,
4285 })
4286 }
4287 };
4288 Ok(Datum { inner })
4289}
4290
4291#[must_use]
4295pub const fn mint_triad<L>(stratum: u64, spectrum: u64, address: u64) -> Triad<L> {
4296 Triad::new(stratum, spectrum, address)
4297}
4298
4299#[must_use]
4303pub const fn mint_derivation(
4304 step_count: u32,
4305 witt_level_bits: u16,
4306 content_fingerprint: ContentFingerprint,
4307) -> Derivation {
4308 Derivation::new(step_count, witt_level_bits, content_fingerprint)
4309}
4310
4311#[must_use]
4315pub const fn mint_freerank(total: u32, pinned: u32) -> FreeRank {
4316 FreeRank::new(total, pinned)
4317}
4318
4319#[inline]
4350#[must_use]
4351#[allow(clippy::manual_checked_ops)]
4352pub const fn const_ring_eval_w8(op: PrimitiveOp, a: u8, b: u8) -> u8 {
4353 match op {
4354 PrimitiveOp::Add => a.wrapping_add(b),
4355 PrimitiveOp::Sub => a.wrapping_sub(b),
4356 PrimitiveOp::Mul => a.wrapping_mul(b),
4357 PrimitiveOp::Xor => a ^ b,
4358 PrimitiveOp::And => a & b,
4359 PrimitiveOp::Or => a | b,
4360 PrimitiveOp::Le => (a <= b) as u8,
4361 PrimitiveOp::Lt => (a < b) as u8,
4362 PrimitiveOp::Ge => (a >= b) as u8,
4363 PrimitiveOp::Gt => (a > b) as u8,
4364 PrimitiveOp::Concat => 0,
4365 PrimitiveOp::Div => {
4366 if b == 0 {
4367 0
4368 } else {
4369 a / b
4370 }
4371 }
4372 PrimitiveOp::Mod => {
4373 if b == 0 {
4374 0
4375 } else {
4376 a % b
4377 }
4378 }
4379 PrimitiveOp::Pow => const_pow_w8(a, b),
4380 _ => 0,
4381 }
4382}
4383
4384#[inline]
4385#[must_use]
4386pub const fn const_pow_w8(base: u8, exp: u8) -> u8 {
4387 let mut result: u8 = 1;
4388 let mut b: u8 = base;
4389 let mut e: u8 = exp;
4390 while e > 0 {
4391 if (e & 1) == 1 {
4392 result = result.wrapping_mul(b);
4393 }
4394 b = b.wrapping_mul(b);
4395 e >>= 1;
4396 }
4397 result
4398}
4399
4400#[inline]
4401#[must_use]
4402pub const fn const_ring_eval_unary_w8(op: PrimitiveOp, a: u8) -> u8 {
4403 match op {
4404 PrimitiveOp::Neg => 0u8.wrapping_sub(a),
4405 PrimitiveOp::Bnot => !a,
4406 PrimitiveOp::Succ => a.wrapping_add(1),
4407 PrimitiveOp::Pred => a.wrapping_sub(1),
4408 _ => 0,
4409 }
4410}
4411
4412#[inline]
4413#[must_use]
4414#[allow(clippy::manual_checked_ops)]
4415pub const fn const_ring_eval_w16(op: PrimitiveOp, a: u16, b: u16) -> u16 {
4416 match op {
4417 PrimitiveOp::Add => a.wrapping_add(b),
4418 PrimitiveOp::Sub => a.wrapping_sub(b),
4419 PrimitiveOp::Mul => a.wrapping_mul(b),
4420 PrimitiveOp::Xor => a ^ b,
4421 PrimitiveOp::And => a & b,
4422 PrimitiveOp::Or => a | b,
4423 PrimitiveOp::Le => (a <= b) as u16,
4424 PrimitiveOp::Lt => (a < b) as u16,
4425 PrimitiveOp::Ge => (a >= b) as u16,
4426 PrimitiveOp::Gt => (a > b) as u16,
4427 PrimitiveOp::Concat => 0,
4428 PrimitiveOp::Div => {
4429 if b == 0 {
4430 0
4431 } else {
4432 a / b
4433 }
4434 }
4435 PrimitiveOp::Mod => {
4436 if b == 0 {
4437 0
4438 } else {
4439 a % b
4440 }
4441 }
4442 PrimitiveOp::Pow => const_pow_w16(a, b),
4443 _ => 0,
4444 }
4445}
4446
4447#[inline]
4448#[must_use]
4449pub const fn const_pow_w16(base: u16, exp: u16) -> u16 {
4450 let mut result: u16 = 1;
4451 let mut b: u16 = base;
4452 let mut e: u16 = exp;
4453 while e > 0 {
4454 if (e & 1) == 1 {
4455 result = result.wrapping_mul(b);
4456 }
4457 b = b.wrapping_mul(b);
4458 e >>= 1;
4459 }
4460 result
4461}
4462
4463#[inline]
4464#[must_use]
4465pub const fn const_ring_eval_unary_w16(op: PrimitiveOp, a: u16) -> u16 {
4466 match op {
4467 PrimitiveOp::Neg => 0u16.wrapping_sub(a),
4468 PrimitiveOp::Bnot => !a,
4469 PrimitiveOp::Succ => a.wrapping_add(1),
4470 PrimitiveOp::Pred => a.wrapping_sub(1),
4471 _ => 0,
4472 }
4473}
4474
4475#[inline]
4476#[must_use]
4477#[allow(clippy::manual_checked_ops)]
4478pub const fn const_ring_eval_w24(op: PrimitiveOp, a: u32, b: u32) -> u32 {
4479 const MASK: u32 = (u64::MAX >> (64 - 24)) as u32;
4480 match op {
4481 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4482 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4483 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4484 PrimitiveOp::Xor => (a ^ b) & MASK,
4485 PrimitiveOp::And => (a & b) & MASK,
4486 PrimitiveOp::Or => (a | b) & MASK,
4487 PrimitiveOp::Le => (a <= b) as u32,
4488 PrimitiveOp::Lt => (a < b) as u32,
4489 PrimitiveOp::Ge => (a >= b) as u32,
4490 PrimitiveOp::Gt => (a > b) as u32,
4491 PrimitiveOp::Concat => 0,
4492 PrimitiveOp::Div => {
4493 if b == 0 {
4494 0
4495 } else {
4496 (a / b) & MASK
4497 }
4498 }
4499 PrimitiveOp::Mod => {
4500 if b == 0 {
4501 0
4502 } else {
4503 (a % b) & MASK
4504 }
4505 }
4506 PrimitiveOp::Pow => (const_pow_w24(a, b)) & MASK,
4507 _ => 0,
4508 }
4509}
4510
4511#[inline]
4512#[must_use]
4513pub const fn const_pow_w24(base: u32, exp: u32) -> u32 {
4514 const MASK: u32 = (u64::MAX >> (64 - 24)) as u32;
4515 let mut result: u32 = 1;
4516 let mut b: u32 = (base) & MASK;
4517 let mut e: u32 = exp;
4518 while e > 0 {
4519 if (e & 1) == 1 {
4520 result = (result.wrapping_mul(b)) & MASK;
4521 }
4522 b = (b.wrapping_mul(b)) & MASK;
4523 e >>= 1;
4524 }
4525 result
4526}
4527
4528#[inline]
4529#[must_use]
4530pub const fn const_ring_eval_unary_w24(op: PrimitiveOp, a: u32) -> u32 {
4531 const MASK: u32 = (u64::MAX >> (64 - 24)) as u32;
4532 match op {
4533 PrimitiveOp::Neg => (0u32.wrapping_sub(a)) & MASK,
4534 PrimitiveOp::Bnot => (!a) & MASK,
4535 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4536 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4537 _ => 0,
4538 }
4539}
4540
4541#[inline]
4542#[must_use]
4543#[allow(clippy::manual_checked_ops)]
4544pub const fn const_ring_eval_w32(op: PrimitiveOp, a: u32, b: u32) -> u32 {
4545 match op {
4546 PrimitiveOp::Add => a.wrapping_add(b),
4547 PrimitiveOp::Sub => a.wrapping_sub(b),
4548 PrimitiveOp::Mul => a.wrapping_mul(b),
4549 PrimitiveOp::Xor => a ^ b,
4550 PrimitiveOp::And => a & b,
4551 PrimitiveOp::Or => a | b,
4552 PrimitiveOp::Le => (a <= b) as u32,
4553 PrimitiveOp::Lt => (a < b) as u32,
4554 PrimitiveOp::Ge => (a >= b) as u32,
4555 PrimitiveOp::Gt => (a > b) as u32,
4556 PrimitiveOp::Concat => 0,
4557 PrimitiveOp::Div => {
4558 if b == 0 {
4559 0
4560 } else {
4561 a / b
4562 }
4563 }
4564 PrimitiveOp::Mod => {
4565 if b == 0 {
4566 0
4567 } else {
4568 a % b
4569 }
4570 }
4571 PrimitiveOp::Pow => const_pow_w32(a, b),
4572 _ => 0,
4573 }
4574}
4575
4576#[inline]
4577#[must_use]
4578pub const fn const_pow_w32(base: u32, exp: u32) -> u32 {
4579 let mut result: u32 = 1;
4580 let mut b: u32 = base;
4581 let mut e: u32 = exp;
4582 while e > 0 {
4583 if (e & 1) == 1 {
4584 result = result.wrapping_mul(b);
4585 }
4586 b = b.wrapping_mul(b);
4587 e >>= 1;
4588 }
4589 result
4590}
4591
4592#[inline]
4593#[must_use]
4594pub const fn const_ring_eval_unary_w32(op: PrimitiveOp, a: u32) -> u32 {
4595 match op {
4596 PrimitiveOp::Neg => 0u32.wrapping_sub(a),
4597 PrimitiveOp::Bnot => !a,
4598 PrimitiveOp::Succ => a.wrapping_add(1),
4599 PrimitiveOp::Pred => a.wrapping_sub(1),
4600 _ => 0,
4601 }
4602}
4603
4604#[inline]
4605#[must_use]
4606#[allow(clippy::manual_checked_ops)]
4607pub const fn const_ring_eval_w40(op: PrimitiveOp, a: u64, b: u64) -> u64 {
4608 const MASK: u64 = u64::MAX >> (64 - 40);
4609 match op {
4610 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4611 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4612 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4613 PrimitiveOp::Xor => (a ^ b) & MASK,
4614 PrimitiveOp::And => (a & b) & MASK,
4615 PrimitiveOp::Or => (a | b) & MASK,
4616 PrimitiveOp::Le => (a <= b) as u64,
4617 PrimitiveOp::Lt => (a < b) as u64,
4618 PrimitiveOp::Ge => (a >= b) as u64,
4619 PrimitiveOp::Gt => (a > b) as u64,
4620 PrimitiveOp::Concat => 0,
4621 PrimitiveOp::Div => {
4622 if b == 0 {
4623 0
4624 } else {
4625 (a / b) & MASK
4626 }
4627 }
4628 PrimitiveOp::Mod => {
4629 if b == 0 {
4630 0
4631 } else {
4632 (a % b) & MASK
4633 }
4634 }
4635 PrimitiveOp::Pow => (const_pow_w40(a, b)) & MASK,
4636 _ => 0,
4637 }
4638}
4639
4640#[inline]
4641#[must_use]
4642pub const fn const_pow_w40(base: u64, exp: u64) -> u64 {
4643 const MASK: u64 = u64::MAX >> (64 - 40);
4644 let mut result: u64 = 1;
4645 let mut b: u64 = (base) & MASK;
4646 let mut e: u64 = exp;
4647 while e > 0 {
4648 if (e & 1) == 1 {
4649 result = (result.wrapping_mul(b)) & MASK;
4650 }
4651 b = (b.wrapping_mul(b)) & MASK;
4652 e >>= 1;
4653 }
4654 result
4655}
4656
4657#[inline]
4658#[must_use]
4659pub const fn const_ring_eval_unary_w40(op: PrimitiveOp, a: u64) -> u64 {
4660 const MASK: u64 = u64::MAX >> (64 - 40);
4661 match op {
4662 PrimitiveOp::Neg => (0u64.wrapping_sub(a)) & MASK,
4663 PrimitiveOp::Bnot => (!a) & MASK,
4664 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4665 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4666 _ => 0,
4667 }
4668}
4669
4670#[inline]
4671#[must_use]
4672#[allow(clippy::manual_checked_ops)]
4673pub const fn const_ring_eval_w48(op: PrimitiveOp, a: u64, b: u64) -> u64 {
4674 const MASK: u64 = u64::MAX >> (64 - 48);
4675 match op {
4676 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4677 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4678 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4679 PrimitiveOp::Xor => (a ^ b) & MASK,
4680 PrimitiveOp::And => (a & b) & MASK,
4681 PrimitiveOp::Or => (a | b) & MASK,
4682 PrimitiveOp::Le => (a <= b) as u64,
4683 PrimitiveOp::Lt => (a < b) as u64,
4684 PrimitiveOp::Ge => (a >= b) as u64,
4685 PrimitiveOp::Gt => (a > b) as u64,
4686 PrimitiveOp::Concat => 0,
4687 PrimitiveOp::Div => {
4688 if b == 0 {
4689 0
4690 } else {
4691 (a / b) & MASK
4692 }
4693 }
4694 PrimitiveOp::Mod => {
4695 if b == 0 {
4696 0
4697 } else {
4698 (a % b) & MASK
4699 }
4700 }
4701 PrimitiveOp::Pow => (const_pow_w48(a, b)) & MASK,
4702 _ => 0,
4703 }
4704}
4705
4706#[inline]
4707#[must_use]
4708pub const fn const_pow_w48(base: u64, exp: u64) -> u64 {
4709 const MASK: u64 = u64::MAX >> (64 - 48);
4710 let mut result: u64 = 1;
4711 let mut b: u64 = (base) & MASK;
4712 let mut e: u64 = exp;
4713 while e > 0 {
4714 if (e & 1) == 1 {
4715 result = (result.wrapping_mul(b)) & MASK;
4716 }
4717 b = (b.wrapping_mul(b)) & MASK;
4718 e >>= 1;
4719 }
4720 result
4721}
4722
4723#[inline]
4724#[must_use]
4725pub const fn const_ring_eval_unary_w48(op: PrimitiveOp, a: u64) -> u64 {
4726 const MASK: u64 = u64::MAX >> (64 - 48);
4727 match op {
4728 PrimitiveOp::Neg => (0u64.wrapping_sub(a)) & MASK,
4729 PrimitiveOp::Bnot => (!a) & MASK,
4730 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4731 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4732 _ => 0,
4733 }
4734}
4735
4736#[inline]
4737#[must_use]
4738#[allow(clippy::manual_checked_ops)]
4739pub const fn const_ring_eval_w56(op: PrimitiveOp, a: u64, b: u64) -> u64 {
4740 const MASK: u64 = u64::MAX >> (64 - 56);
4741 match op {
4742 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4743 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4744 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4745 PrimitiveOp::Xor => (a ^ b) & MASK,
4746 PrimitiveOp::And => (a & b) & MASK,
4747 PrimitiveOp::Or => (a | b) & MASK,
4748 PrimitiveOp::Le => (a <= b) as u64,
4749 PrimitiveOp::Lt => (a < b) as u64,
4750 PrimitiveOp::Ge => (a >= b) as u64,
4751 PrimitiveOp::Gt => (a > b) as u64,
4752 PrimitiveOp::Concat => 0,
4753 PrimitiveOp::Div => {
4754 if b == 0 {
4755 0
4756 } else {
4757 (a / b) & MASK
4758 }
4759 }
4760 PrimitiveOp::Mod => {
4761 if b == 0 {
4762 0
4763 } else {
4764 (a % b) & MASK
4765 }
4766 }
4767 PrimitiveOp::Pow => (const_pow_w56(a, b)) & MASK,
4768 _ => 0,
4769 }
4770}
4771
4772#[inline]
4773#[must_use]
4774pub const fn const_pow_w56(base: u64, exp: u64) -> u64 {
4775 const MASK: u64 = u64::MAX >> (64 - 56);
4776 let mut result: u64 = 1;
4777 let mut b: u64 = (base) & MASK;
4778 let mut e: u64 = exp;
4779 while e > 0 {
4780 if (e & 1) == 1 {
4781 result = (result.wrapping_mul(b)) & MASK;
4782 }
4783 b = (b.wrapping_mul(b)) & MASK;
4784 e >>= 1;
4785 }
4786 result
4787}
4788
4789#[inline]
4790#[must_use]
4791pub const fn const_ring_eval_unary_w56(op: PrimitiveOp, a: u64) -> u64 {
4792 const MASK: u64 = u64::MAX >> (64 - 56);
4793 match op {
4794 PrimitiveOp::Neg => (0u64.wrapping_sub(a)) & MASK,
4795 PrimitiveOp::Bnot => (!a) & MASK,
4796 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4797 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4798 _ => 0,
4799 }
4800}
4801
4802#[inline]
4803#[must_use]
4804#[allow(clippy::manual_checked_ops)]
4805pub const fn const_ring_eval_w64(op: PrimitiveOp, a: u64, b: u64) -> u64 {
4806 match op {
4807 PrimitiveOp::Add => a.wrapping_add(b),
4808 PrimitiveOp::Sub => a.wrapping_sub(b),
4809 PrimitiveOp::Mul => a.wrapping_mul(b),
4810 PrimitiveOp::Xor => a ^ b,
4811 PrimitiveOp::And => a & b,
4812 PrimitiveOp::Or => a | b,
4813 PrimitiveOp::Le => (a <= b) as u64,
4814 PrimitiveOp::Lt => (a < b) as u64,
4815 PrimitiveOp::Ge => (a >= b) as u64,
4816 PrimitiveOp::Gt => (a > b) as u64,
4817 PrimitiveOp::Concat => 0,
4818 PrimitiveOp::Div => {
4819 if b == 0 {
4820 0
4821 } else {
4822 a / b
4823 }
4824 }
4825 PrimitiveOp::Mod => {
4826 if b == 0 {
4827 0
4828 } else {
4829 a % b
4830 }
4831 }
4832 PrimitiveOp::Pow => const_pow_w64(a, b),
4833 _ => 0,
4834 }
4835}
4836
4837#[inline]
4838#[must_use]
4839pub const fn const_pow_w64(base: u64, exp: u64) -> u64 {
4840 let mut result: u64 = 1;
4841 let mut b: u64 = base;
4842 let mut e: u64 = exp;
4843 while e > 0 {
4844 if (e & 1) == 1 {
4845 result = result.wrapping_mul(b);
4846 }
4847 b = b.wrapping_mul(b);
4848 e >>= 1;
4849 }
4850 result
4851}
4852
4853#[inline]
4854#[must_use]
4855pub const fn const_ring_eval_unary_w64(op: PrimitiveOp, a: u64) -> u64 {
4856 match op {
4857 PrimitiveOp::Neg => 0u64.wrapping_sub(a),
4858 PrimitiveOp::Bnot => !a,
4859 PrimitiveOp::Succ => a.wrapping_add(1),
4860 PrimitiveOp::Pred => a.wrapping_sub(1),
4861 _ => 0,
4862 }
4863}
4864
4865#[inline]
4866#[must_use]
4867#[allow(clippy::manual_checked_ops)]
4868pub const fn const_ring_eval_w72(op: PrimitiveOp, a: u128, b: u128) -> u128 {
4869 const MASK: u128 = u128::MAX >> (128 - 72);
4870 match op {
4871 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4872 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4873 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4874 PrimitiveOp::Xor => (a ^ b) & MASK,
4875 PrimitiveOp::And => (a & b) & MASK,
4876 PrimitiveOp::Or => (a | b) & MASK,
4877 PrimitiveOp::Le => (a <= b) as u128,
4878 PrimitiveOp::Lt => (a < b) as u128,
4879 PrimitiveOp::Ge => (a >= b) as u128,
4880 PrimitiveOp::Gt => (a > b) as u128,
4881 PrimitiveOp::Concat => 0,
4882 PrimitiveOp::Div => {
4883 if b == 0 {
4884 0
4885 } else {
4886 (a / b) & MASK
4887 }
4888 }
4889 PrimitiveOp::Mod => {
4890 if b == 0 {
4891 0
4892 } else {
4893 (a % b) & MASK
4894 }
4895 }
4896 PrimitiveOp::Pow => (const_pow_w72(a, b)) & MASK,
4897 _ => 0,
4898 }
4899}
4900
4901#[inline]
4902#[must_use]
4903pub const fn const_pow_w72(base: u128, exp: u128) -> u128 {
4904 const MASK: u128 = u128::MAX >> (128 - 72);
4905 let mut result: u128 = 1;
4906 let mut b: u128 = (base) & MASK;
4907 let mut e: u128 = exp;
4908 while e > 0 {
4909 if (e & 1) == 1 {
4910 result = (result.wrapping_mul(b)) & MASK;
4911 }
4912 b = (b.wrapping_mul(b)) & MASK;
4913 e >>= 1;
4914 }
4915 result
4916}
4917
4918#[inline]
4919#[must_use]
4920pub const fn const_ring_eval_unary_w72(op: PrimitiveOp, a: u128) -> u128 {
4921 const MASK: u128 = u128::MAX >> (128 - 72);
4922 match op {
4923 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
4924 PrimitiveOp::Bnot => (!a) & MASK,
4925 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4926 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4927 _ => 0,
4928 }
4929}
4930
4931#[inline]
4932#[must_use]
4933#[allow(clippy::manual_checked_ops)]
4934pub const fn const_ring_eval_w80(op: PrimitiveOp, a: u128, b: u128) -> u128 {
4935 const MASK: u128 = u128::MAX >> (128 - 80);
4936 match op {
4937 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4938 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4939 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4940 PrimitiveOp::Xor => (a ^ b) & MASK,
4941 PrimitiveOp::And => (a & b) & MASK,
4942 PrimitiveOp::Or => (a | b) & MASK,
4943 PrimitiveOp::Le => (a <= b) as u128,
4944 PrimitiveOp::Lt => (a < b) as u128,
4945 PrimitiveOp::Ge => (a >= b) as u128,
4946 PrimitiveOp::Gt => (a > b) as u128,
4947 PrimitiveOp::Concat => 0,
4948 PrimitiveOp::Div => {
4949 if b == 0 {
4950 0
4951 } else {
4952 (a / b) & MASK
4953 }
4954 }
4955 PrimitiveOp::Mod => {
4956 if b == 0 {
4957 0
4958 } else {
4959 (a % b) & MASK
4960 }
4961 }
4962 PrimitiveOp::Pow => (const_pow_w80(a, b)) & MASK,
4963 _ => 0,
4964 }
4965}
4966
4967#[inline]
4968#[must_use]
4969pub const fn const_pow_w80(base: u128, exp: u128) -> u128 {
4970 const MASK: u128 = u128::MAX >> (128 - 80);
4971 let mut result: u128 = 1;
4972 let mut b: u128 = (base) & MASK;
4973 let mut e: u128 = exp;
4974 while e > 0 {
4975 if (e & 1) == 1 {
4976 result = (result.wrapping_mul(b)) & MASK;
4977 }
4978 b = (b.wrapping_mul(b)) & MASK;
4979 e >>= 1;
4980 }
4981 result
4982}
4983
4984#[inline]
4985#[must_use]
4986pub const fn const_ring_eval_unary_w80(op: PrimitiveOp, a: u128) -> u128 {
4987 const MASK: u128 = u128::MAX >> (128 - 80);
4988 match op {
4989 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
4990 PrimitiveOp::Bnot => (!a) & MASK,
4991 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4992 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4993 _ => 0,
4994 }
4995}
4996
4997#[inline]
4998#[must_use]
4999#[allow(clippy::manual_checked_ops)]
5000pub const fn const_ring_eval_w88(op: PrimitiveOp, a: u128, b: u128) -> u128 {
5001 const MASK: u128 = u128::MAX >> (128 - 88);
5002 match op {
5003 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
5004 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
5005 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
5006 PrimitiveOp::Xor => (a ^ b) & MASK,
5007 PrimitiveOp::And => (a & b) & MASK,
5008 PrimitiveOp::Or => (a | b) & MASK,
5009 PrimitiveOp::Le => (a <= b) as u128,
5010 PrimitiveOp::Lt => (a < b) as u128,
5011 PrimitiveOp::Ge => (a >= b) as u128,
5012 PrimitiveOp::Gt => (a > b) as u128,
5013 PrimitiveOp::Concat => 0,
5014 PrimitiveOp::Div => {
5015 if b == 0 {
5016 0
5017 } else {
5018 (a / b) & MASK
5019 }
5020 }
5021 PrimitiveOp::Mod => {
5022 if b == 0 {
5023 0
5024 } else {
5025 (a % b) & MASK
5026 }
5027 }
5028 PrimitiveOp::Pow => (const_pow_w88(a, b)) & MASK,
5029 _ => 0,
5030 }
5031}
5032
5033#[inline]
5034#[must_use]
5035pub const fn const_pow_w88(base: u128, exp: u128) -> u128 {
5036 const MASK: u128 = u128::MAX >> (128 - 88);
5037 let mut result: u128 = 1;
5038 let mut b: u128 = (base) & MASK;
5039 let mut e: u128 = exp;
5040 while e > 0 {
5041 if (e & 1) == 1 {
5042 result = (result.wrapping_mul(b)) & MASK;
5043 }
5044 b = (b.wrapping_mul(b)) & MASK;
5045 e >>= 1;
5046 }
5047 result
5048}
5049
5050#[inline]
5051#[must_use]
5052pub const fn const_ring_eval_unary_w88(op: PrimitiveOp, a: u128) -> u128 {
5053 const MASK: u128 = u128::MAX >> (128 - 88);
5054 match op {
5055 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
5056 PrimitiveOp::Bnot => (!a) & MASK,
5057 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
5058 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
5059 _ => 0,
5060 }
5061}
5062
5063#[inline]
5064#[must_use]
5065#[allow(clippy::manual_checked_ops)]
5066pub const fn const_ring_eval_w96(op: PrimitiveOp, a: u128, b: u128) -> u128 {
5067 const MASK: u128 = u128::MAX >> (128 - 96);
5068 match op {
5069 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
5070 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
5071 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
5072 PrimitiveOp::Xor => (a ^ b) & MASK,
5073 PrimitiveOp::And => (a & b) & MASK,
5074 PrimitiveOp::Or => (a | b) & MASK,
5075 PrimitiveOp::Le => (a <= b) as u128,
5076 PrimitiveOp::Lt => (a < b) as u128,
5077 PrimitiveOp::Ge => (a >= b) as u128,
5078 PrimitiveOp::Gt => (a > b) as u128,
5079 PrimitiveOp::Concat => 0,
5080 PrimitiveOp::Div => {
5081 if b == 0 {
5082 0
5083 } else {
5084 (a / b) & MASK
5085 }
5086 }
5087 PrimitiveOp::Mod => {
5088 if b == 0 {
5089 0
5090 } else {
5091 (a % b) & MASK
5092 }
5093 }
5094 PrimitiveOp::Pow => (const_pow_w96(a, b)) & MASK,
5095 _ => 0,
5096 }
5097}
5098
5099#[inline]
5100#[must_use]
5101pub const fn const_pow_w96(base: u128, exp: u128) -> u128 {
5102 const MASK: u128 = u128::MAX >> (128 - 96);
5103 let mut result: u128 = 1;
5104 let mut b: u128 = (base) & MASK;
5105 let mut e: u128 = exp;
5106 while e > 0 {
5107 if (e & 1) == 1 {
5108 result = (result.wrapping_mul(b)) & MASK;
5109 }
5110 b = (b.wrapping_mul(b)) & MASK;
5111 e >>= 1;
5112 }
5113 result
5114}
5115
5116#[inline]
5117#[must_use]
5118pub const fn const_ring_eval_unary_w96(op: PrimitiveOp, a: u128) -> u128 {
5119 const MASK: u128 = u128::MAX >> (128 - 96);
5120 match op {
5121 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
5122 PrimitiveOp::Bnot => (!a) & MASK,
5123 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
5124 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
5125 _ => 0,
5126 }
5127}
5128
5129#[inline]
5130#[must_use]
5131#[allow(clippy::manual_checked_ops)]
5132pub const fn const_ring_eval_w104(op: PrimitiveOp, a: u128, b: u128) -> u128 {
5133 const MASK: u128 = u128::MAX >> (128 - 104);
5134 match op {
5135 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
5136 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
5137 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
5138 PrimitiveOp::Xor => (a ^ b) & MASK,
5139 PrimitiveOp::And => (a & b) & MASK,
5140 PrimitiveOp::Or => (a | b) & MASK,
5141 PrimitiveOp::Le => (a <= b) as u128,
5142 PrimitiveOp::Lt => (a < b) as u128,
5143 PrimitiveOp::Ge => (a >= b) as u128,
5144 PrimitiveOp::Gt => (a > b) as u128,
5145 PrimitiveOp::Concat => 0,
5146 PrimitiveOp::Div => {
5147 if b == 0 {
5148 0
5149 } else {
5150 (a / b) & MASK
5151 }
5152 }
5153 PrimitiveOp::Mod => {
5154 if b == 0 {
5155 0
5156 } else {
5157 (a % b) & MASK
5158 }
5159 }
5160 PrimitiveOp::Pow => (const_pow_w104(a, b)) & MASK,
5161 _ => 0,
5162 }
5163}
5164
5165#[inline]
5166#[must_use]
5167pub const fn const_pow_w104(base: u128, exp: u128) -> u128 {
5168 const MASK: u128 = u128::MAX >> (128 - 104);
5169 let mut result: u128 = 1;
5170 let mut b: u128 = (base) & MASK;
5171 let mut e: u128 = exp;
5172 while e > 0 {
5173 if (e & 1) == 1 {
5174 result = (result.wrapping_mul(b)) & MASK;
5175 }
5176 b = (b.wrapping_mul(b)) & MASK;
5177 e >>= 1;
5178 }
5179 result
5180}
5181
5182#[inline]
5183#[must_use]
5184pub const fn const_ring_eval_unary_w104(op: PrimitiveOp, a: u128) -> u128 {
5185 const MASK: u128 = u128::MAX >> (128 - 104);
5186 match op {
5187 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
5188 PrimitiveOp::Bnot => (!a) & MASK,
5189 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
5190 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
5191 _ => 0,
5192 }
5193}
5194
5195#[inline]
5196#[must_use]
5197#[allow(clippy::manual_checked_ops)]
5198pub const fn const_ring_eval_w112(op: PrimitiveOp, a: u128, b: u128) -> u128 {
5199 const MASK: u128 = u128::MAX >> (128 - 112);
5200 match op {
5201 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
5202 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
5203 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
5204 PrimitiveOp::Xor => (a ^ b) & MASK,
5205 PrimitiveOp::And => (a & b) & MASK,
5206 PrimitiveOp::Or => (a | b) & MASK,
5207 PrimitiveOp::Le => (a <= b) as u128,
5208 PrimitiveOp::Lt => (a < b) as u128,
5209 PrimitiveOp::Ge => (a >= b) as u128,
5210 PrimitiveOp::Gt => (a > b) as u128,
5211 PrimitiveOp::Concat => 0,
5212 PrimitiveOp::Div => {
5213 if b == 0 {
5214 0
5215 } else {
5216 (a / b) & MASK
5217 }
5218 }
5219 PrimitiveOp::Mod => {
5220 if b == 0 {
5221 0
5222 } else {
5223 (a % b) & MASK
5224 }
5225 }
5226 PrimitiveOp::Pow => (const_pow_w112(a, b)) & MASK,
5227 _ => 0,
5228 }
5229}
5230
5231#[inline]
5232#[must_use]
5233pub const fn const_pow_w112(base: u128, exp: u128) -> u128 {
5234 const MASK: u128 = u128::MAX >> (128 - 112);
5235 let mut result: u128 = 1;
5236 let mut b: u128 = (base) & MASK;
5237 let mut e: u128 = exp;
5238 while e > 0 {
5239 if (e & 1) == 1 {
5240 result = (result.wrapping_mul(b)) & MASK;
5241 }
5242 b = (b.wrapping_mul(b)) & MASK;
5243 e >>= 1;
5244 }
5245 result
5246}
5247
5248#[inline]
5249#[must_use]
5250pub const fn const_ring_eval_unary_w112(op: PrimitiveOp, a: u128) -> u128 {
5251 const MASK: u128 = u128::MAX >> (128 - 112);
5252 match op {
5253 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
5254 PrimitiveOp::Bnot => (!a) & MASK,
5255 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
5256 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
5257 _ => 0,
5258 }
5259}
5260
5261#[inline]
5262#[must_use]
5263#[allow(clippy::manual_checked_ops)]
5264pub const fn const_ring_eval_w120(op: PrimitiveOp, a: u128, b: u128) -> u128 {
5265 const MASK: u128 = u128::MAX >> (128 - 120);
5266 match op {
5267 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
5268 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
5269 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
5270 PrimitiveOp::Xor => (a ^ b) & MASK,
5271 PrimitiveOp::And => (a & b) & MASK,
5272 PrimitiveOp::Or => (a | b) & MASK,
5273 PrimitiveOp::Le => (a <= b) as u128,
5274 PrimitiveOp::Lt => (a < b) as u128,
5275 PrimitiveOp::Ge => (a >= b) as u128,
5276 PrimitiveOp::Gt => (a > b) as u128,
5277 PrimitiveOp::Concat => 0,
5278 PrimitiveOp::Div => {
5279 if b == 0 {
5280 0
5281 } else {
5282 (a / b) & MASK
5283 }
5284 }
5285 PrimitiveOp::Mod => {
5286 if b == 0 {
5287 0
5288 } else {
5289 (a % b) & MASK
5290 }
5291 }
5292 PrimitiveOp::Pow => (const_pow_w120(a, b)) & MASK,
5293 _ => 0,
5294 }
5295}
5296
5297#[inline]
5298#[must_use]
5299pub const fn const_pow_w120(base: u128, exp: u128) -> u128 {
5300 const MASK: u128 = u128::MAX >> (128 - 120);
5301 let mut result: u128 = 1;
5302 let mut b: u128 = (base) & MASK;
5303 let mut e: u128 = exp;
5304 while e > 0 {
5305 if (e & 1) == 1 {
5306 result = (result.wrapping_mul(b)) & MASK;
5307 }
5308 b = (b.wrapping_mul(b)) & MASK;
5309 e >>= 1;
5310 }
5311 result
5312}
5313
5314#[inline]
5315#[must_use]
5316pub const fn const_ring_eval_unary_w120(op: PrimitiveOp, a: u128) -> u128 {
5317 const MASK: u128 = u128::MAX >> (128 - 120);
5318 match op {
5319 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
5320 PrimitiveOp::Bnot => (!a) & MASK,
5321 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
5322 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
5323 _ => 0,
5324 }
5325}
5326
5327#[inline]
5328#[must_use]
5329#[allow(clippy::manual_checked_ops)]
5330pub const fn const_ring_eval_w128(op: PrimitiveOp, a: u128, b: u128) -> u128 {
5331 match op {
5332 PrimitiveOp::Add => a.wrapping_add(b),
5333 PrimitiveOp::Sub => a.wrapping_sub(b),
5334 PrimitiveOp::Mul => a.wrapping_mul(b),
5335 PrimitiveOp::Xor => a ^ b,
5336 PrimitiveOp::And => a & b,
5337 PrimitiveOp::Or => a | b,
5338 PrimitiveOp::Le => (a <= b) as u128,
5339 PrimitiveOp::Lt => (a < b) as u128,
5340 PrimitiveOp::Ge => (a >= b) as u128,
5341 PrimitiveOp::Gt => (a > b) as u128,
5342 PrimitiveOp::Concat => 0,
5343 PrimitiveOp::Div => {
5344 if b == 0 {
5345 0
5346 } else {
5347 a / b
5348 }
5349 }
5350 PrimitiveOp::Mod => {
5351 if b == 0 {
5352 0
5353 } else {
5354 a % b
5355 }
5356 }
5357 PrimitiveOp::Pow => const_pow_w128(a, b),
5358 _ => 0,
5359 }
5360}
5361
5362#[inline]
5363#[must_use]
5364pub const fn const_pow_w128(base: u128, exp: u128) -> u128 {
5365 let mut result: u128 = 1;
5366 let mut b: u128 = base;
5367 let mut e: u128 = exp;
5368 while e > 0 {
5369 if (e & 1) == 1 {
5370 result = result.wrapping_mul(b);
5371 }
5372 b = b.wrapping_mul(b);
5373 e >>= 1;
5374 }
5375 result
5376}
5377
5378#[inline]
5379#[must_use]
5380pub const fn const_ring_eval_unary_w128(op: PrimitiveOp, a: u128) -> u128 {
5381 match op {
5382 PrimitiveOp::Neg => 0u128.wrapping_sub(a),
5383 PrimitiveOp::Bnot => !a,
5384 PrimitiveOp::Succ => a.wrapping_add(1),
5385 PrimitiveOp::Pred => a.wrapping_sub(1),
5386 _ => 0,
5387 }
5388}
5389
5390#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5399pub struct Limbs<const N: usize> {
5400 words: [u64; N],
5402 _sealed: (),
5404}
5405
5406impl<const N: usize> Limbs<N> {
5407 #[inline]
5409 #[must_use]
5410 #[allow(dead_code)]
5411 pub(crate) const fn from_words(words: [u64; N]) -> Self {
5412 Self { words, _sealed: () }
5413 }
5414
5415 #[inline]
5417 #[must_use]
5418 #[allow(dead_code)]
5419 pub(crate) const fn zero() -> Self {
5420 Self {
5421 words: [0u64; N],
5422 _sealed: (),
5423 }
5424 }
5425
5426 #[inline]
5428 #[must_use]
5429 pub const fn words(&self) -> &[u64; N] {
5430 &self.words
5431 }
5432
5433 #[inline]
5435 #[must_use]
5436 #[allow(dead_code)]
5437 pub(crate) const fn wrapping_add(self, other: Self) -> Self {
5438 let mut out = [0u64; N];
5439 let mut carry: u64 = 0;
5440 let mut i = 0;
5441 while i < N {
5442 let (s1, c1) = self.words[i].overflowing_add(other.words[i]);
5443 let (s2, c2) = s1.overflowing_add(carry);
5444 out[i] = s2;
5445 carry = (c1 as u64) | (c2 as u64);
5446 i += 1;
5447 }
5448 Self {
5449 words: out,
5450 _sealed: (),
5451 }
5452 }
5453
5454 #[inline]
5456 #[must_use]
5457 #[allow(dead_code)]
5458 pub(crate) const fn wrapping_sub(self, other: Self) -> Self {
5459 let mut out = [0u64; N];
5460 let mut borrow: u64 = 0;
5461 let mut i = 0;
5462 while i < N {
5463 let (d1, b1) = self.words[i].overflowing_sub(other.words[i]);
5464 let (d2, b2) = d1.overflowing_sub(borrow);
5465 out[i] = d2;
5466 borrow = (b1 as u64) | (b2 as u64);
5467 i += 1;
5468 }
5469 Self {
5470 words: out,
5471 _sealed: (),
5472 }
5473 }
5474
5475 #[inline]
5480 #[must_use]
5481 #[allow(dead_code)]
5482 pub(crate) const fn wrapping_mul(self, other: Self) -> Self {
5483 let mut out = [0u64; N];
5484 let mut i = 0;
5485 while i < N {
5486 let mut carry: u128 = 0;
5487 let mut j = 0;
5488 while j < N - i {
5489 let prod = (self.words[i] as u128) * (other.words[j] as u128)
5490 + (out[i + j] as u128)
5491 + carry;
5492 out[i + j] = prod as u64;
5493 carry = prod >> 64;
5494 j += 1;
5495 }
5496 i += 1;
5497 }
5498 Self {
5499 words: out,
5500 _sealed: (),
5501 }
5502 }
5503
5504 #[inline]
5506 #[must_use]
5507 #[allow(dead_code)]
5508 pub(crate) const fn xor(self, other: Self) -> Self {
5509 let mut out = [0u64; N];
5510 let mut i = 0;
5511 while i < N {
5512 out[i] = self.words[i] ^ other.words[i];
5513 i += 1;
5514 }
5515 Self {
5516 words: out,
5517 _sealed: (),
5518 }
5519 }
5520
5521 #[inline]
5523 #[must_use]
5524 #[allow(dead_code)]
5525 pub(crate) const fn and(self, other: Self) -> Self {
5526 let mut out = [0u64; N];
5527 let mut i = 0;
5528 while i < N {
5529 out[i] = self.words[i] & other.words[i];
5530 i += 1;
5531 }
5532 Self {
5533 words: out,
5534 _sealed: (),
5535 }
5536 }
5537
5538 #[inline]
5540 #[must_use]
5541 #[allow(dead_code)]
5542 pub(crate) const fn or(self, other: Self) -> Self {
5543 let mut out = [0u64; N];
5544 let mut i = 0;
5545 while i < N {
5546 out[i] = self.words[i] | other.words[i];
5547 i += 1;
5548 }
5549 Self {
5550 words: out,
5551 _sealed: (),
5552 }
5553 }
5554
5555 #[inline]
5557 #[must_use]
5558 #[allow(dead_code)]
5559 pub(crate) const fn not(self) -> Self {
5560 let mut out = [0u64; N];
5561 let mut i = 0;
5562 while i < N {
5563 out[i] = !self.words[i];
5564 i += 1;
5565 }
5566 Self {
5567 words: out,
5568 _sealed: (),
5569 }
5570 }
5571
5572 #[inline]
5576 #[must_use]
5577 #[allow(dead_code)]
5578 pub(crate) const fn mask_high_bits(self, bits: u32) -> Self {
5579 let mut out = self.words;
5580 let high_word_idx = (bits / 64) as usize;
5581 let low_bits_in_high_word = bits % 64;
5582 if low_bits_in_high_word != 0 && high_word_idx < N {
5583 let mask = (1u64 << low_bits_in_high_word) - 1;
5584 out[high_word_idx] &= mask;
5585 let mut i = high_word_idx + 1;
5587 while i < N {
5588 out[i] = 0;
5589 i += 1;
5590 }
5591 } else if low_bits_in_high_word == 0 && high_word_idx < N {
5592 let mut i = high_word_idx;
5594 while i < N {
5595 out[i] = 0;
5596 i += 1;
5597 }
5598 }
5599 Self {
5600 words: out,
5601 _sealed: (),
5602 }
5603 }
5604}
5605
5606pub trait OntologyTarget: ontology_target_sealed::Sealed {}
5611
5612#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5614pub struct GroundingCertificate {
5615 witt_bits: u16,
5616 content_fingerprint: ContentFingerprint,
5621}
5622
5623impl GroundingCertificate {
5624 #[inline]
5627 #[must_use]
5628 pub const fn witt_bits(&self) -> u16 {
5629 self.witt_bits
5630 }
5631
5632 #[inline]
5638 #[must_use]
5639 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5640 self.content_fingerprint
5641 }
5642
5643 #[inline]
5648 #[must_use]
5649 #[allow(dead_code)]
5650 pub(crate) const fn with_level_and_fingerprint_const(
5651 witt_bits: u16,
5652 content_fingerprint: ContentFingerprint,
5653 ) -> Self {
5654 Self {
5655 witt_bits,
5656 content_fingerprint,
5657 }
5658 }
5659}
5660
5661#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5663pub struct LiftChainCertificate {
5664 witt_bits: u16,
5665 content_fingerprint: ContentFingerprint,
5670}
5671
5672impl LiftChainCertificate {
5673 #[inline]
5676 #[must_use]
5677 pub const fn witt_bits(&self) -> u16 {
5678 self.witt_bits
5679 }
5680
5681 #[inline]
5687 #[must_use]
5688 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5689 self.content_fingerprint
5690 }
5691
5692 #[inline]
5697 #[must_use]
5698 #[allow(dead_code)]
5699 pub(crate) const fn with_level_and_fingerprint_const(
5700 witt_bits: u16,
5701 content_fingerprint: ContentFingerprint,
5702 ) -> Self {
5703 Self {
5704 witt_bits,
5705 content_fingerprint,
5706 }
5707 }
5708}
5709
5710#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5712pub struct InhabitanceCertificate {
5713 witt_bits: u16,
5714 content_fingerprint: ContentFingerprint,
5719}
5720
5721impl InhabitanceCertificate {
5722 #[inline]
5725 #[must_use]
5726 pub const fn witt_bits(&self) -> u16 {
5727 self.witt_bits
5728 }
5729
5730 #[inline]
5736 #[must_use]
5737 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5738 self.content_fingerprint
5739 }
5740
5741 #[inline]
5746 #[must_use]
5747 #[allow(dead_code)]
5748 pub(crate) const fn with_level_and_fingerprint_const(
5749 witt_bits: u16,
5750 content_fingerprint: ContentFingerprint,
5751 ) -> Self {
5752 Self {
5753 witt_bits,
5754 content_fingerprint,
5755 }
5756 }
5757}
5758
5759#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5761pub struct CompletenessCertificate {
5762 witt_bits: u16,
5763 content_fingerprint: ContentFingerprint,
5768}
5769
5770impl CompletenessCertificate {
5771 #[inline]
5774 #[must_use]
5775 pub const fn witt_bits(&self) -> u16 {
5776 self.witt_bits
5777 }
5778
5779 #[inline]
5785 #[must_use]
5786 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5787 self.content_fingerprint
5788 }
5789
5790 #[inline]
5795 #[must_use]
5796 #[allow(dead_code)]
5797 pub(crate) const fn with_level_and_fingerprint_const(
5798 witt_bits: u16,
5799 content_fingerprint: ContentFingerprint,
5800 ) -> Self {
5801 Self {
5802 witt_bits,
5803 content_fingerprint,
5804 }
5805 }
5806}
5807
5808#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5810pub struct MultiplicationCertificate {
5811 witt_bits: u16,
5812 content_fingerprint: ContentFingerprint,
5817}
5818
5819impl MultiplicationCertificate {
5820 #[inline]
5823 #[must_use]
5824 pub const fn witt_bits(&self) -> u16 {
5825 self.witt_bits
5826 }
5827
5828 #[inline]
5834 #[must_use]
5835 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5836 self.content_fingerprint
5837 }
5838
5839 #[inline]
5844 #[must_use]
5845 #[allow(dead_code)]
5846 pub(crate) const fn with_level_and_fingerprint_const(
5847 witt_bits: u16,
5848 content_fingerprint: ContentFingerprint,
5849 ) -> Self {
5850 Self {
5851 witt_bits,
5852 content_fingerprint,
5853 }
5854 }
5855}
5856
5857#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5859pub struct PartitionCertificate {
5860 witt_bits: u16,
5861 content_fingerprint: ContentFingerprint,
5866}
5867
5868impl PartitionCertificate {
5869 #[inline]
5872 #[must_use]
5873 pub const fn witt_bits(&self) -> u16 {
5874 self.witt_bits
5875 }
5876
5877 #[inline]
5883 #[must_use]
5884 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5885 self.content_fingerprint
5886 }
5887
5888 #[inline]
5893 #[must_use]
5894 #[allow(dead_code)]
5895 pub(crate) const fn with_level_and_fingerprint_const(
5896 witt_bits: u16,
5897 content_fingerprint: ContentFingerprint,
5898 ) -> Self {
5899 Self {
5900 witt_bits,
5901 content_fingerprint,
5902 }
5903 }
5904}
5905
5906#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5908pub struct GenericImpossibilityWitness {
5909 identity: Option<&'static str>,
5914}
5915
5916impl Default for GenericImpossibilityWitness {
5917 #[inline]
5918 fn default() -> Self {
5919 Self { identity: None }
5920 }
5921}
5922
5923impl GenericImpossibilityWitness {
5924 #[inline]
5929 #[must_use]
5930 pub const fn for_identity(identity: &'static str) -> Self {
5931 Self {
5932 identity: Some(identity),
5933 }
5934 }
5935
5936 #[inline]
5938 #[must_use]
5939 pub const fn identity(&self) -> Option<&'static str> {
5940 self.identity
5941 }
5942}
5943
5944#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
5946pub struct InhabitanceImpossibilityWitness {
5947 _private: (),
5948}
5949
5950#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
5952pub struct ConstrainedTypeInput {
5953 _private: (),
5954}
5955
5956impl core::fmt::Display for GenericImpossibilityWitness {
5957 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
5958 match self.identity {
5959 Some(iri) => write!(f, "GenericImpossibilityWitness({iri})"),
5960 None => f.write_str("GenericImpossibilityWitness"),
5961 }
5962 }
5963}
5964impl core::error::Error for GenericImpossibilityWitness {}
5965
5966impl core::fmt::Display for InhabitanceImpossibilityWitness {
5967 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
5968 f.write_str("InhabitanceImpossibilityWitness")
5969 }
5970}
5971impl core::error::Error for InhabitanceImpossibilityWitness {}
5972
5973impl LiftChainCertificate {
5974 #[inline]
5976 #[must_use]
5977 pub const fn target_level(&self) -> WittLevel {
5978 WittLevel::new(self.witt_bits as u32)
5979 }
5980}
5981
5982impl InhabitanceCertificate {
5983 #[inline]
5987 #[must_use]
5988 pub const fn witness(&self) -> Option<&'static [u8]> {
5989 None
5990 }
5991}
5992
5993pub(crate) mod ontology_target_sealed {
5994 pub trait Sealed {}
5996 impl Sealed for super::GroundingCertificate {}
5997 impl Sealed for super::LiftChainCertificate {}
5998 impl Sealed for super::InhabitanceCertificate {}
5999 impl Sealed for super::CompletenessCertificate {}
6000 impl Sealed for super::MultiplicationCertificate {}
6001 impl Sealed for super::PartitionCertificate {}
6002 impl Sealed for super::GenericImpossibilityWitness {}
6003 impl Sealed for super::InhabitanceImpossibilityWitness {}
6004 impl Sealed for super::ConstrainedTypeInput {}
6005 impl Sealed for super::PartitionProductWitness {}
6006 impl Sealed for super::PartitionCoproductWitness {}
6007 impl Sealed for super::CartesianProductWitness {}
6008 impl<const INLINE_BYTES: usize> Sealed for super::CompileUnit<'_, INLINE_BYTES> {}
6009}
6010
6011impl OntologyTarget for GroundingCertificate {}
6012impl OntologyTarget for LiftChainCertificate {}
6013impl OntologyTarget for InhabitanceCertificate {}
6014impl OntologyTarget for CompletenessCertificate {}
6015impl OntologyTarget for MultiplicationCertificate {}
6016impl OntologyTarget for PartitionCertificate {}
6017impl OntologyTarget for GenericImpossibilityWitness {}
6018impl OntologyTarget for InhabitanceImpossibilityWitness {}
6019impl OntologyTarget for ConstrainedTypeInput {}
6020impl OntologyTarget for PartitionProductWitness {}
6021impl OntologyTarget for PartitionCoproductWitness {}
6022impl OntologyTarget for CartesianProductWitness {}
6023impl<const INLINE_BYTES: usize> OntologyTarget for CompileUnit<'_, INLINE_BYTES> {}
6024
6025#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
6028pub struct CompletenessAuditTrail {
6029 _private: (),
6030}
6031
6032#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
6034pub struct ChainAuditTrail {
6035 _private: (),
6036}
6037
6038#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
6040pub struct GeodesicEvidenceBundle {
6041 _private: (),
6042}
6043
6044#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6050pub struct TransformCertificate {
6051 witt_bits: u16,
6052 content_fingerprint: ContentFingerprint,
6053 _private: (),
6054}
6055
6056impl TransformCertificate {
6057 #[inline]
6061 #[must_use]
6062 #[allow(dead_code)]
6063 pub(crate) const fn with_level_and_fingerprint_const(
6064 witt_bits: u16,
6065 content_fingerprint: ContentFingerprint,
6066 ) -> Self {
6067 Self {
6068 witt_bits,
6069 content_fingerprint,
6070 _private: (),
6071 }
6072 }
6073
6074 #[inline]
6077 #[must_use]
6078 #[allow(dead_code)]
6079 pub(crate) const fn empty_const() -> Self {
6080 Self {
6081 witt_bits: 0,
6082 content_fingerprint: ContentFingerprint::zero(),
6083 _private: (),
6084 }
6085 }
6086
6087 #[inline]
6089 #[must_use]
6090 pub const fn witt_bits(&self) -> u16 {
6091 self.witt_bits
6092 }
6093
6094 #[inline]
6096 #[must_use]
6097 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6098 self.content_fingerprint
6099 }
6100}
6101
6102#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6108pub struct IsometryCertificate {
6109 witt_bits: u16,
6110 content_fingerprint: ContentFingerprint,
6111 _private: (),
6112}
6113
6114impl IsometryCertificate {
6115 #[inline]
6119 #[must_use]
6120 #[allow(dead_code)]
6121 pub(crate) const fn with_level_and_fingerprint_const(
6122 witt_bits: u16,
6123 content_fingerprint: ContentFingerprint,
6124 ) -> Self {
6125 Self {
6126 witt_bits,
6127 content_fingerprint,
6128 _private: (),
6129 }
6130 }
6131
6132 #[inline]
6135 #[must_use]
6136 #[allow(dead_code)]
6137 pub(crate) const fn empty_const() -> Self {
6138 Self {
6139 witt_bits: 0,
6140 content_fingerprint: ContentFingerprint::zero(),
6141 _private: (),
6142 }
6143 }
6144
6145 #[inline]
6147 #[must_use]
6148 pub const fn witt_bits(&self) -> u16 {
6149 self.witt_bits
6150 }
6151
6152 #[inline]
6154 #[must_use]
6155 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6156 self.content_fingerprint
6157 }
6158}
6159
6160#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6166pub struct InvolutionCertificate {
6167 witt_bits: u16,
6168 content_fingerprint: ContentFingerprint,
6169 _private: (),
6170}
6171
6172impl InvolutionCertificate {
6173 #[inline]
6177 #[must_use]
6178 #[allow(dead_code)]
6179 pub(crate) const fn with_level_and_fingerprint_const(
6180 witt_bits: u16,
6181 content_fingerprint: ContentFingerprint,
6182 ) -> Self {
6183 Self {
6184 witt_bits,
6185 content_fingerprint,
6186 _private: (),
6187 }
6188 }
6189
6190 #[inline]
6193 #[must_use]
6194 #[allow(dead_code)]
6195 pub(crate) const fn empty_const() -> Self {
6196 Self {
6197 witt_bits: 0,
6198 content_fingerprint: ContentFingerprint::zero(),
6199 _private: (),
6200 }
6201 }
6202
6203 #[inline]
6205 #[must_use]
6206 pub const fn witt_bits(&self) -> u16 {
6207 self.witt_bits
6208 }
6209
6210 #[inline]
6212 #[must_use]
6213 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6214 self.content_fingerprint
6215 }
6216}
6217
6218#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6224pub struct GeodesicCertificate {
6225 witt_bits: u16,
6226 content_fingerprint: ContentFingerprint,
6227 _private: (),
6228}
6229
6230impl GeodesicCertificate {
6231 #[inline]
6235 #[must_use]
6236 #[allow(dead_code)]
6237 pub(crate) const fn with_level_and_fingerprint_const(
6238 witt_bits: u16,
6239 content_fingerprint: ContentFingerprint,
6240 ) -> Self {
6241 Self {
6242 witt_bits,
6243 content_fingerprint,
6244 _private: (),
6245 }
6246 }
6247
6248 #[inline]
6251 #[must_use]
6252 #[allow(dead_code)]
6253 pub(crate) const fn empty_const() -> Self {
6254 Self {
6255 witt_bits: 0,
6256 content_fingerprint: ContentFingerprint::zero(),
6257 _private: (),
6258 }
6259 }
6260
6261 #[inline]
6263 #[must_use]
6264 pub const fn witt_bits(&self) -> u16 {
6265 self.witt_bits
6266 }
6267
6268 #[inline]
6270 #[must_use]
6271 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6272 self.content_fingerprint
6273 }
6274}
6275
6276#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6282pub struct MeasurementCertificate {
6283 witt_bits: u16,
6284 content_fingerprint: ContentFingerprint,
6285 _private: (),
6286}
6287
6288impl MeasurementCertificate {
6289 #[inline]
6293 #[must_use]
6294 #[allow(dead_code)]
6295 pub(crate) const fn with_level_and_fingerprint_const(
6296 witt_bits: u16,
6297 content_fingerprint: ContentFingerprint,
6298 ) -> Self {
6299 Self {
6300 witt_bits,
6301 content_fingerprint,
6302 _private: (),
6303 }
6304 }
6305
6306 #[inline]
6309 #[must_use]
6310 #[allow(dead_code)]
6311 pub(crate) const fn empty_const() -> Self {
6312 Self {
6313 witt_bits: 0,
6314 content_fingerprint: ContentFingerprint::zero(),
6315 _private: (),
6316 }
6317 }
6318
6319 #[inline]
6321 #[must_use]
6322 pub const fn witt_bits(&self) -> u16 {
6323 self.witt_bits
6324 }
6325
6326 #[inline]
6328 #[must_use]
6329 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6330 self.content_fingerprint
6331 }
6332}
6333
6334#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6340pub struct BornRuleVerification {
6341 witt_bits: u16,
6342 content_fingerprint: ContentFingerprint,
6343 _private: (),
6344}
6345
6346impl BornRuleVerification {
6347 #[inline]
6351 #[must_use]
6352 #[allow(dead_code)]
6353 pub(crate) const fn with_level_and_fingerprint_const(
6354 witt_bits: u16,
6355 content_fingerprint: ContentFingerprint,
6356 ) -> Self {
6357 Self {
6358 witt_bits,
6359 content_fingerprint,
6360 _private: (),
6361 }
6362 }
6363
6364 #[inline]
6367 #[must_use]
6368 #[allow(dead_code)]
6369 pub(crate) const fn empty_const() -> Self {
6370 Self {
6371 witt_bits: 0,
6372 content_fingerprint: ContentFingerprint::zero(),
6373 _private: (),
6374 }
6375 }
6376
6377 #[inline]
6379 #[must_use]
6380 pub const fn witt_bits(&self) -> u16 {
6381 self.witt_bits
6382 }
6383
6384 #[inline]
6386 #[must_use]
6387 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6388 self.content_fingerprint
6389 }
6390}
6391
6392pub trait Certificate: certificate_sealed::Sealed {
6396 const IRI: &'static str;
6398 type Evidence;
6400}
6401
6402pub(crate) mod certificate_sealed {
6403 pub trait Sealed {}
6405 impl Sealed for super::GroundingCertificate {}
6406 impl Sealed for super::LiftChainCertificate {}
6407 impl Sealed for super::InhabitanceCertificate {}
6408 impl Sealed for super::CompletenessCertificate {}
6409 impl Sealed for super::TransformCertificate {}
6410 impl Sealed for super::IsometryCertificate {}
6411 impl Sealed for super::InvolutionCertificate {}
6412 impl Sealed for super::GeodesicCertificate {}
6413 impl Sealed for super::MeasurementCertificate {}
6414 impl Sealed for super::BornRuleVerification {}
6415 impl Sealed for super::MultiplicationCertificate {}
6416 impl Sealed for super::PartitionCertificate {}
6417 impl Sealed for super::GenericImpossibilityWitness {}
6418 impl Sealed for super::InhabitanceImpossibilityWitness {}
6419 impl Sealed for super::PartitionProductWitness {}
6420 impl Sealed for super::PartitionCoproductWitness {}
6421 impl Sealed for super::CartesianProductWitness {}
6422}
6423
6424impl Certificate for GroundingCertificate {
6425 const IRI: &'static str = "https://uor.foundation/cert/GroundingCertificate";
6426 type Evidence = ();
6427}
6428
6429impl Certificate for LiftChainCertificate {
6430 const IRI: &'static str = "https://uor.foundation/cert/LiftChainCertificate";
6431 type Evidence = ChainAuditTrail;
6432}
6433
6434impl Certificate for InhabitanceCertificate {
6435 const IRI: &'static str = "https://uor.foundation/cert/InhabitanceCertificate";
6436 type Evidence = ();
6437}
6438
6439impl Certificate for CompletenessCertificate {
6440 const IRI: &'static str = "https://uor.foundation/cert/CompletenessCertificate";
6441 type Evidence = CompletenessAuditTrail;
6442}
6443
6444impl Certificate for TransformCertificate {
6445 const IRI: &'static str = "https://uor.foundation/cert/TransformCertificate";
6446 type Evidence = ();
6447}
6448
6449impl Certificate for IsometryCertificate {
6450 const IRI: &'static str = "https://uor.foundation/cert/IsometryCertificate";
6451 type Evidence = ();
6452}
6453
6454impl Certificate for InvolutionCertificate {
6455 const IRI: &'static str = "https://uor.foundation/cert/InvolutionCertificate";
6456 type Evidence = ();
6457}
6458
6459impl Certificate for GeodesicCertificate {
6460 const IRI: &'static str = "https://uor.foundation/cert/GeodesicCertificate";
6461 type Evidence = GeodesicEvidenceBundle;
6462}
6463
6464impl Certificate for MeasurementCertificate {
6465 const IRI: &'static str = "https://uor.foundation/cert/MeasurementCertificate";
6466 type Evidence = ();
6467}
6468
6469impl Certificate for BornRuleVerification {
6470 const IRI: &'static str = "https://uor.foundation/cert/BornRuleVerification";
6471 type Evidence = ();
6472}
6473
6474impl Certificate for MultiplicationCertificate {
6475 const IRI: &'static str = "https://uor.foundation/cert/MultiplicationCertificate";
6476 type Evidence = MultiplicationEvidence;
6477}
6478
6479impl Certificate for PartitionCertificate {
6480 const IRI: &'static str = "https://uor.foundation/cert/PartitionCertificate";
6481 type Evidence = ();
6482}
6483
6484impl Certificate for GenericImpossibilityWitness {
6485 const IRI: &'static str = "https://uor.foundation/cert/GenericImpossibilityCertificate";
6486 type Evidence = ();
6487}
6488
6489impl Certificate for InhabitanceImpossibilityWitness {
6490 const IRI: &'static str = "https://uor.foundation/cert/InhabitanceImpossibilityCertificate";
6491 type Evidence = ();
6492}
6493
6494pub(crate) mod certify_const_mint {
6500 use super::{Certificate, ContentFingerprint};
6501 pub trait MintWithLevelFingerprint: Certificate {
6502 fn mint_with_level_fingerprint(
6503 witt_bits: u16,
6504 content_fingerprint: ContentFingerprint,
6505 ) -> Self;
6506 }
6507 impl MintWithLevelFingerprint for super::GroundingCertificate {
6508 #[inline]
6509 fn mint_with_level_fingerprint(
6510 witt_bits: u16,
6511 content_fingerprint: ContentFingerprint,
6512 ) -> Self {
6513 super::GroundingCertificate::with_level_and_fingerprint_const(
6514 witt_bits,
6515 content_fingerprint,
6516 )
6517 }
6518 }
6519 impl MintWithLevelFingerprint for super::LiftChainCertificate {
6520 #[inline]
6521 fn mint_with_level_fingerprint(
6522 witt_bits: u16,
6523 content_fingerprint: ContentFingerprint,
6524 ) -> Self {
6525 super::LiftChainCertificate::with_level_and_fingerprint_const(
6526 witt_bits,
6527 content_fingerprint,
6528 )
6529 }
6530 }
6531 impl MintWithLevelFingerprint for super::InhabitanceCertificate {
6532 #[inline]
6533 fn mint_with_level_fingerprint(
6534 witt_bits: u16,
6535 content_fingerprint: ContentFingerprint,
6536 ) -> Self {
6537 super::InhabitanceCertificate::with_level_and_fingerprint_const(
6538 witt_bits,
6539 content_fingerprint,
6540 )
6541 }
6542 }
6543 impl MintWithLevelFingerprint for super::CompletenessCertificate {
6544 #[inline]
6545 fn mint_with_level_fingerprint(
6546 witt_bits: u16,
6547 content_fingerprint: ContentFingerprint,
6548 ) -> Self {
6549 super::CompletenessCertificate::with_level_and_fingerprint_const(
6550 witt_bits,
6551 content_fingerprint,
6552 )
6553 }
6554 }
6555 impl MintWithLevelFingerprint for super::MultiplicationCertificate {
6556 #[inline]
6557 fn mint_with_level_fingerprint(
6558 witt_bits: u16,
6559 content_fingerprint: ContentFingerprint,
6560 ) -> Self {
6561 super::MultiplicationCertificate::with_level_and_fingerprint_const(
6562 witt_bits,
6563 content_fingerprint,
6564 )
6565 }
6566 }
6567 impl MintWithLevelFingerprint for super::PartitionCertificate {
6568 #[inline]
6569 fn mint_with_level_fingerprint(
6570 witt_bits: u16,
6571 content_fingerprint: ContentFingerprint,
6572 ) -> Self {
6573 super::PartitionCertificate::with_level_and_fingerprint_const(
6574 witt_bits,
6575 content_fingerprint,
6576 )
6577 }
6578 }
6579 impl MintWithLevelFingerprint for super::TransformCertificate {
6580 #[inline]
6581 fn mint_with_level_fingerprint(
6582 witt_bits: u16,
6583 content_fingerprint: ContentFingerprint,
6584 ) -> Self {
6585 super::TransformCertificate::with_level_and_fingerprint_const(
6586 witt_bits,
6587 content_fingerprint,
6588 )
6589 }
6590 }
6591 impl MintWithLevelFingerprint for super::IsometryCertificate {
6592 #[inline]
6593 fn mint_with_level_fingerprint(
6594 witt_bits: u16,
6595 content_fingerprint: ContentFingerprint,
6596 ) -> Self {
6597 super::IsometryCertificate::with_level_and_fingerprint_const(
6598 witt_bits,
6599 content_fingerprint,
6600 )
6601 }
6602 }
6603 impl MintWithLevelFingerprint for super::InvolutionCertificate {
6604 #[inline]
6605 fn mint_with_level_fingerprint(
6606 witt_bits: u16,
6607 content_fingerprint: ContentFingerprint,
6608 ) -> Self {
6609 super::InvolutionCertificate::with_level_and_fingerprint_const(
6610 witt_bits,
6611 content_fingerprint,
6612 )
6613 }
6614 }
6615 impl MintWithLevelFingerprint for super::GeodesicCertificate {
6616 #[inline]
6617 fn mint_with_level_fingerprint(
6618 witt_bits: u16,
6619 content_fingerprint: ContentFingerprint,
6620 ) -> Self {
6621 super::GeodesicCertificate::with_level_and_fingerprint_const(
6622 witt_bits,
6623 content_fingerprint,
6624 )
6625 }
6626 }
6627 impl MintWithLevelFingerprint for super::MeasurementCertificate {
6628 #[inline]
6629 fn mint_with_level_fingerprint(
6630 witt_bits: u16,
6631 content_fingerprint: ContentFingerprint,
6632 ) -> Self {
6633 super::MeasurementCertificate::with_level_and_fingerprint_const(
6634 witt_bits,
6635 content_fingerprint,
6636 )
6637 }
6638 }
6639 impl MintWithLevelFingerprint for super::BornRuleVerification {
6640 #[inline]
6641 fn mint_with_level_fingerprint(
6642 witt_bits: u16,
6643 content_fingerprint: ContentFingerprint,
6644 ) -> Self {
6645 super::BornRuleVerification::with_level_and_fingerprint_const(
6646 witt_bits,
6647 content_fingerprint,
6648 )
6649 }
6650 }
6651}
6652
6653#[derive(Debug, Clone)]
6658pub struct Certified<C: Certificate> {
6659 inner: C,
6661 uor_time: UorTime,
6663 _private: (),
6665}
6666
6667impl<C: Certificate> Certified<C> {
6668 #[inline]
6670 #[must_use]
6671 pub const fn certificate(&self) -> &C {
6672 &self.inner
6673 }
6674
6675 #[inline]
6677 #[must_use]
6678 pub const fn iri(&self) -> &'static str {
6679 C::IRI
6680 }
6681
6682 #[inline]
6688 #[must_use]
6689 pub const fn uor_time(&self) -> UorTime {
6690 self.uor_time
6691 }
6692
6693 #[inline]
6700 #[allow(dead_code)]
6701 pub(crate) const fn new(inner: C) -> Self {
6702 let steps = C::IRI.len() as u64;
6705 let landauer = LandauerBudget::new((steps as f64) * core::f64::consts::LN_2);
6706 let uor_time = UorTime::new(landauer, steps);
6707 Self {
6708 inner,
6709 uor_time,
6710 _private: (),
6711 }
6712 }
6713}
6714
6715#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6721pub struct MulContext {
6722 pub stack_budget_bytes: u64,
6725 pub const_eval: bool,
6729 pub limb_count: usize,
6734}
6735
6736impl MulContext {
6737 #[inline]
6739 #[must_use]
6740 pub const fn new(stack_budget_bytes: u64, const_eval: bool, limb_count: usize) -> Self {
6741 Self {
6742 stack_budget_bytes,
6743 const_eval,
6744 limb_count,
6745 }
6746 }
6747}
6748
6749#[derive(Debug, Clone, Copy, PartialEq)]
6753pub struct MultiplicationEvidence {
6754 splitting_factor: u32,
6755 sub_multiplication_count: u32,
6756 landauer_cost_nats_bits: u64,
6757}
6758
6759impl MultiplicationEvidence {
6760 #[inline]
6762 #[must_use]
6763 pub const fn splitting_factor(&self) -> u32 {
6764 self.splitting_factor
6765 }
6766
6767 #[inline]
6769 #[must_use]
6770 pub const fn sub_multiplication_count(&self) -> u32 {
6771 self.sub_multiplication_count
6772 }
6773
6774 #[inline]
6776 #[must_use]
6777 pub const fn landauer_cost_nats_bits(&self) -> u64 {
6778 self.landauer_cost_nats_bits
6779 }
6780}
6781
6782impl MultiplicationCertificate {
6783 #[inline]
6787 #[must_use]
6788 pub(crate) fn with_evidence(
6789 splitting_factor: u32,
6790 sub_multiplication_count: u32,
6791 landauer_cost_nats_bits: u64,
6792 content_fingerprint: ContentFingerprint,
6793 ) -> Self {
6794 let _ = MultiplicationEvidence {
6795 splitting_factor,
6796 sub_multiplication_count,
6797 landauer_cost_nats_bits,
6798 };
6799 Self::with_level_and_fingerprint_const(32, content_fingerprint)
6800 }
6801}
6802
6803pub const MAX_BETTI_DIMENSION: usize = 8;
6811
6812#[derive(Debug)]
6817pub struct SigmaValue<H: HostTypes = crate::DefaultHostTypes> {
6818 value: H::Decimal,
6819 _phantom: core::marker::PhantomData<H>,
6820 _sealed: (),
6821}
6822
6823impl<H: HostTypes> Copy for SigmaValue<H> {}
6824impl<H: HostTypes> Clone for SigmaValue<H> {
6825 #[inline]
6826 fn clone(&self) -> Self {
6827 *self
6828 }
6829}
6830impl<H: HostTypes> PartialEq for SigmaValue<H> {
6831 #[inline]
6832 fn eq(&self, other: &Self) -> bool {
6833 self.value == other.value
6834 }
6835}
6836
6837impl<H: HostTypes> SigmaValue<H> {
6838 #[inline]
6840 #[must_use]
6841 pub const fn value(&self) -> H::Decimal {
6842 self.value
6843 }
6844
6845 #[inline]
6848 #[must_use]
6849 #[allow(dead_code)]
6850 pub(crate) const fn new_unchecked(value: H::Decimal) -> Self {
6851 Self {
6852 value,
6853 _phantom: core::marker::PhantomData,
6854 _sealed: (),
6855 }
6856 }
6857}
6858
6859#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6865pub struct Stratum<L> {
6866 value: u32,
6867 _level: PhantomData<L>,
6868 _sealed: (),
6869}
6870
6871impl<L> Stratum<L> {
6872 #[inline]
6874 #[must_use]
6875 pub const fn as_u32(&self) -> u32 {
6876 self.value
6877 }
6878
6879 #[inline]
6881 #[must_use]
6882 #[allow(dead_code)]
6883 pub(crate) const fn new(value: u32) -> Self {
6884 Self {
6885 value,
6886 _level: PhantomData,
6887 _sealed: (),
6888 }
6889 }
6890}
6891
6892#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6894pub struct DDeltaMetric {
6895 value: i64,
6896 _sealed: (),
6897}
6898
6899impl DDeltaMetric {
6900 #[inline]
6902 #[must_use]
6903 pub const fn as_i64(&self) -> i64 {
6904 self.value
6905 }
6906
6907 #[inline]
6909 #[must_use]
6910 #[allow(dead_code)]
6911 pub(crate) const fn new(value: i64) -> Self {
6912 Self { value, _sealed: () }
6913 }
6914}
6915
6916#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6918pub struct EulerMetric {
6919 value: i64,
6920 _sealed: (),
6921}
6922
6923impl EulerMetric {
6924 #[inline]
6926 #[must_use]
6927 pub const fn as_i64(&self) -> i64 {
6928 self.value
6929 }
6930
6931 #[inline]
6933 #[must_use]
6934 #[allow(dead_code)]
6935 pub(crate) const fn new(value: i64) -> Self {
6936 Self { value, _sealed: () }
6937 }
6938}
6939
6940#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6942pub struct ResidualMetric {
6943 value: u32,
6944 _sealed: (),
6945}
6946
6947impl ResidualMetric {
6948 #[inline]
6950 #[must_use]
6951 pub const fn as_u32(&self) -> u32 {
6952 self.value
6953 }
6954
6955 #[inline]
6957 #[must_use]
6958 #[allow(dead_code)]
6959 pub(crate) const fn new(value: u32) -> Self {
6960 Self { value, _sealed: () }
6961 }
6962}
6963
6964#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6967pub struct BettiMetric {
6968 values: [u32; MAX_BETTI_DIMENSION],
6969 _sealed: (),
6970}
6971
6972impl BettiMetric {
6973 #[inline]
6975 #[must_use]
6976 pub const fn as_array(&self) -> &[u32; MAX_BETTI_DIMENSION] {
6977 &self.values
6978 }
6979
6980 #[inline]
6983 #[must_use]
6984 pub const fn beta(&self, k: usize) -> u32 {
6985 if k < MAX_BETTI_DIMENSION {
6986 self.values[k]
6987 } else {
6988 0
6989 }
6990 }
6991
6992 #[inline]
6994 #[must_use]
6995 #[allow(dead_code)]
6996 pub(crate) const fn new(values: [u32; MAX_BETTI_DIMENSION]) -> Self {
6997 Self {
6998 values,
6999 _sealed: (),
7000 }
7001 }
7002}
7003
7004pub const JACOBIAN_MAX_SITES: usize = 8;
7012
7013#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7018pub struct JacobianMetric<L> {
7019 entries: [i64; JACOBIAN_MAX_SITES],
7020 len: u16,
7021 _level: PhantomData<L>,
7022 _sealed: (),
7023}
7024
7025impl<L> JacobianMetric<L> {
7026 #[inline]
7028 #[must_use]
7029 #[allow(dead_code)]
7030 pub(crate) const fn zero(len: u16) -> Self {
7031 Self {
7032 entries: [0i64; JACOBIAN_MAX_SITES],
7033 len,
7034 _level: PhantomData,
7035 _sealed: (),
7036 }
7037 }
7038
7039 #[inline]
7043 #[must_use]
7044 #[allow(dead_code)]
7045 pub(crate) const fn from_entries(entries: [i64; JACOBIAN_MAX_SITES], len: u16) -> Self {
7046 Self {
7047 entries,
7048 len,
7049 _level: PhantomData,
7050 _sealed: (),
7051 }
7052 }
7053
7054 #[inline]
7056 #[must_use]
7057 pub const fn entries(&self) -> &[i64; JACOBIAN_MAX_SITES] {
7058 &self.entries
7059 }
7060
7061 #[inline]
7063 #[must_use]
7064 pub const fn len(&self) -> u16 {
7065 self.len
7066 }
7067
7068 #[inline]
7070 #[must_use]
7071 pub const fn is_empty(&self) -> bool {
7072 self.len == 0
7073 }
7074}
7075
7076#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7080#[non_exhaustive]
7081pub enum PartitionComponent {
7082 Irreducible,
7084 Reducible,
7086 Units,
7088 Exterior,
7090}
7091
7092pub trait GroundedShape: crate::pipeline::__sdk_seal::Sealed {}
7103impl GroundedShape for ConstrainedTypeInput {}
7104
7105#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7114pub struct ContentAddress {
7115 raw: u128,
7116 _sealed: (),
7117}
7118
7119impl ContentAddress {
7120 #[inline]
7124 #[must_use]
7125 pub const fn zero() -> Self {
7126 Self {
7127 raw: 0,
7128 _sealed: (),
7129 }
7130 }
7131
7132 #[inline]
7134 #[must_use]
7135 pub const fn as_u128(&self) -> u128 {
7136 self.raw
7137 }
7138
7139 #[inline]
7141 #[must_use]
7142 pub const fn is_zero(&self) -> bool {
7143 self.raw == 0
7144 }
7145
7146 #[inline]
7150 #[must_use]
7151 pub const fn from_u128(raw: u128) -> Self {
7152 Self { raw, _sealed: () }
7153 }
7154
7155 #[inline]
7163 #[must_use]
7164 pub const fn from_u64_fingerprint(fingerprint: u64) -> Self {
7165 Self {
7166 raw: (fingerprint as u128) << 64,
7167 _sealed: (),
7168 }
7169 }
7170}
7171
7172impl Default for ContentAddress {
7173 #[inline]
7174 fn default() -> Self {
7175 Self::zero()
7176 }
7177}
7178
7179pub const TRACE_REPLAY_FORMAT_VERSION: u16 = 10;
7186
7187pub trait Hasher<const FP_MAX: usize = 32> {
7253 const OUTPUT_BYTES: usize;
7257
7258 fn initial() -> Self;
7260
7261 #[must_use]
7263 fn fold_byte(self, b: u8) -> Self;
7264
7265 #[inline]
7267 #[must_use]
7268 fn fold_bytes(mut self, bytes: &[u8]) -> Self
7269 where
7270 Self: Sized,
7271 {
7272 let mut i = 0;
7273 while i < bytes.len() {
7274 self = self.fold_byte(bytes[i]);
7275 i += 1;
7276 }
7277 self
7278 }
7279
7280 fn finalize(self) -> [u8; FP_MAX];
7284}
7285
7286#[derive(Debug, Clone, Copy)]
7292pub struct HashAxis<H: Hasher>(core::marker::PhantomData<H>);
7293
7294impl<H: Hasher> HashAxis<H> {
7295 pub const KERNEL_HASH: u32 = 0;
7299}
7300
7301impl<H: Hasher> crate::pipeline::__sdk_seal::Sealed for HashAxis<H> {}
7302impl<const INLINE_BYTES: usize, H: Hasher> crate::pipeline::SubstrateTermBody<INLINE_BYTES>
7303 for HashAxis<H>
7304{
7305 fn body_arena() -> &'static [Term<'static, INLINE_BYTES>] {
7306 &[]
7307 }
7308}
7309impl<const INLINE_BYTES: usize, H: Hasher> crate::pipeline::AxisExtension<INLINE_BYTES>
7310 for HashAxis<H>
7311{
7312 const AXIS_ADDRESS: &'static str = "https://uor.foundation/axis/HashAxis";
7313 const MAX_OUTPUT_BYTES: usize = <H as Hasher>::OUTPUT_BYTES;
7314 fn dispatch_kernel(
7315 kernel_id: u32,
7316 input: &[u8],
7317 out: &mut [u8],
7318 ) -> Result<usize, ShapeViolation> {
7319 if kernel_id != Self::KERNEL_HASH {
7320 return Err(ShapeViolation {
7321 shape_iri: "https://uor.foundation/axis/HashAxis",
7322 constraint_iri: "https://uor.foundation/axis/HashAxis/kernelId",
7323 property_iri: "https://uor.foundation/axis/kernelId",
7324 expected_range: "https://uor.foundation/axis/HashAxis/KERNEL_HASH",
7325 min_count: 0,
7326 max_count: 1,
7327 kind: crate::ViolationKind::ValueCheck,
7328 });
7329 }
7330 let mut hasher = <H as Hasher>::initial();
7331 hasher = hasher.fold_bytes(input);
7332 let digest = hasher.finalize();
7333 let n = <H as Hasher>::OUTPUT_BYTES.min(out.len()).min(digest.len());
7334 let mut i = 0;
7335 while i < n {
7336 out[i] = digest[i];
7337 i += 1;
7338 }
7339 Ok(n)
7340 }
7341}
7342
7343#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7356pub struct ContentFingerprint<const FP_MAX: usize = 32> {
7357 bytes: [u8; FP_MAX],
7358 width_bytes: u8,
7359 _sealed: (),
7360}
7361
7362impl<const FP_MAX: usize> ContentFingerprint<FP_MAX> {
7363 #[inline]
7368 #[must_use]
7369 #[allow(dead_code)]
7370 pub(crate) const fn zero() -> Self {
7371 Self {
7372 bytes: [0u8; FP_MAX],
7373 width_bytes: 0,
7374 _sealed: (),
7375 }
7376 }
7377
7378 #[inline]
7380 #[must_use]
7381 pub const fn is_zero(&self) -> bool {
7382 self.width_bytes == 0
7383 }
7384
7385 #[inline]
7387 #[must_use]
7388 pub const fn width_bytes(&self) -> u8 {
7389 self.width_bytes
7390 }
7391
7392 #[inline]
7394 #[must_use]
7395 pub const fn width_bits(&self) -> u16 {
7396 (self.width_bytes as u16) * 8
7397 }
7398
7399 #[inline]
7402 #[must_use]
7403 pub const fn as_bytes(&self) -> &[u8; FP_MAX] {
7404 &self.bytes
7405 }
7406
7407 #[inline]
7411 #[must_use]
7412 pub const fn from_buffer(bytes: [u8; FP_MAX], width_bytes: u8) -> Self {
7413 Self {
7414 bytes,
7415 width_bytes,
7416 _sealed: (),
7417 }
7418 }
7419}
7420
7421impl<const FP_MAX: usize> Default for ContentFingerprint<FP_MAX> {
7422 #[inline]
7423 fn default() -> Self {
7424 Self::zero()
7425 }
7426}
7427
7428#[inline]
7434#[must_use]
7435pub const fn primitive_op_discriminant(op: crate::PrimitiveOp) -> u8 {
7436 match op {
7437 crate::PrimitiveOp::Neg => 0,
7438 crate::PrimitiveOp::Bnot => 1,
7439 crate::PrimitiveOp::Succ => 2,
7440 crate::PrimitiveOp::Pred => 3,
7441 crate::PrimitiveOp::Add => 4,
7442 crate::PrimitiveOp::Sub => 5,
7443 crate::PrimitiveOp::Mul => 6,
7444 crate::PrimitiveOp::Xor => 7,
7445 crate::PrimitiveOp::And => 8,
7446 crate::PrimitiveOp::Or => 9,
7447 crate::PrimitiveOp::Le => 10,
7449 crate::PrimitiveOp::Lt => 11,
7450 crate::PrimitiveOp::Ge => 12,
7451 crate::PrimitiveOp::Gt => 13,
7452 crate::PrimitiveOp::Concat => 14,
7453 crate::PrimitiveOp::Div => 15,
7455 crate::PrimitiveOp::Mod => 16,
7456 crate::PrimitiveOp::Pow => 17,
7457 }
7458}
7459
7460#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7467#[non_exhaustive]
7468pub enum CertificateKind {
7469 Grounding,
7472 TowerCompleteness,
7474 IncrementalCompleteness,
7476 Inhabitance,
7478 Multiplication,
7480 TwoSat,
7482 HornSat,
7484 ResidualVerdict,
7486 CanonicalForm,
7488 TypeSynthesis,
7490 Homotopy,
7492 Monodromy,
7494 Moduli,
7496 JacobianGuided,
7498 Evaluation,
7500 Session,
7502 Superposition,
7504 Measurement,
7506 WittLevel,
7508 DihedralFactorization,
7510 Completeness,
7512 GeodesicValidator,
7514}
7515
7516#[inline]
7521#[must_use]
7522pub const fn certificate_kind_discriminant(kind: CertificateKind) -> u8 {
7523 match kind {
7524 CertificateKind::Grounding => 1,
7525 CertificateKind::TowerCompleteness => 2,
7526 CertificateKind::IncrementalCompleteness => 3,
7527 CertificateKind::Inhabitance => 4,
7528 CertificateKind::Multiplication => 5,
7529 CertificateKind::TwoSat => 6,
7530 CertificateKind::HornSat => 7,
7531 CertificateKind::ResidualVerdict => 8,
7532 CertificateKind::CanonicalForm => 9,
7533 CertificateKind::TypeSynthesis => 10,
7534 CertificateKind::Homotopy => 11,
7535 CertificateKind::Monodromy => 12,
7536 CertificateKind::Moduli => 13,
7537 CertificateKind::JacobianGuided => 14,
7538 CertificateKind::Evaluation => 15,
7539 CertificateKind::Session => 16,
7540 CertificateKind::Superposition => 17,
7541 CertificateKind::Measurement => 18,
7542 CertificateKind::WittLevel => 19,
7543 CertificateKind::DihedralFactorization => 20,
7544 CertificateKind::Completeness => 21,
7545 CertificateKind::GeodesicValidator => 22,
7546 }
7547}
7548
7549pub fn fold_constraint_ref<H: Hasher>(mut hasher: H, c: &crate::pipeline::ConstraintRef) -> H {
7556 use crate::pipeline::ConstraintRef as C;
7557 match c {
7558 C::Residue { modulus, residue } => {
7559 hasher = hasher.fold_byte(1);
7560 hasher = hasher.fold_bytes(&modulus.to_be_bytes());
7561 hasher = hasher.fold_bytes(&residue.to_be_bytes());
7562 }
7563 C::Hamming { bound } => {
7564 hasher = hasher.fold_byte(2);
7565 hasher = hasher.fold_bytes(&bound.to_be_bytes());
7566 }
7567 C::Depth { min, max } => {
7568 hasher = hasher.fold_byte(3);
7569 hasher = hasher.fold_bytes(&min.to_be_bytes());
7570 hasher = hasher.fold_bytes(&max.to_be_bytes());
7571 }
7572 C::Carry { site } => {
7573 hasher = hasher.fold_byte(4);
7574 hasher = hasher.fold_bytes(&site.to_be_bytes());
7575 }
7576 C::Site { position } => {
7577 hasher = hasher.fold_byte(5);
7578 hasher = hasher.fold_bytes(&position.to_be_bytes());
7579 }
7580 C::Affine {
7581 coefficients,
7582 coefficient_count,
7583 bias,
7584 } => {
7585 hasher = hasher.fold_byte(6);
7586 hasher = hasher.fold_bytes(&coefficient_count.to_be_bytes());
7587 let count = *coefficient_count as usize;
7588 let mut i = 0;
7589 while i < count && i < crate::pipeline::AFFINE_MAX_COEFFS {
7590 hasher = hasher.fold_bytes(&coefficients[i].to_be_bytes());
7591 i += 1;
7592 }
7593 hasher = hasher.fold_bytes(&bias.to_be_bytes());
7594 }
7595 C::SatClauses { clauses, num_vars } => {
7596 hasher = hasher.fold_byte(7);
7597 hasher = hasher.fold_bytes(&num_vars.to_be_bytes());
7598 hasher = hasher.fold_bytes(&(clauses.len() as u32).to_be_bytes());
7599 let mut i = 0;
7600 while i < clauses.len() {
7601 let clause = clauses[i];
7602 hasher = hasher.fold_bytes(&(clause.len() as u32).to_be_bytes());
7603 let mut j = 0;
7604 while j < clause.len() {
7605 let (var, neg) = clause[j];
7606 hasher = hasher.fold_bytes(&var.to_be_bytes());
7607 hasher = hasher.fold_byte(if neg { 1 } else { 0 });
7608 j += 1;
7609 }
7610 i += 1;
7611 }
7612 }
7613 C::Bound {
7614 observable_iri,
7615 bound_shape_iri,
7616 args_repr,
7617 } => {
7618 hasher = hasher.fold_byte(8);
7619 hasher = hasher.fold_bytes(observable_iri.as_bytes());
7620 hasher = hasher.fold_byte(0);
7621 hasher = hasher.fold_bytes(bound_shape_iri.as_bytes());
7622 hasher = hasher.fold_byte(0);
7623 hasher = hasher.fold_bytes(args_repr.as_bytes());
7624 hasher = hasher.fold_byte(0);
7625 }
7626 C::Conjunction {
7627 conjuncts,
7628 conjunct_count,
7629 } => {
7630 hasher = hasher.fold_byte(9);
7631 hasher = hasher.fold_bytes(&conjunct_count.to_be_bytes());
7632 let count = *conjunct_count as usize;
7633 let mut i = 0;
7634 while i < count && i < crate::pipeline::CONJUNCTION_MAX_TERMS {
7635 let lifted = conjuncts[i].into_constraint();
7636 hasher = fold_constraint_ref(hasher, &lifted);
7637 i += 1;
7638 }
7639 }
7640 C::Recurse {
7644 shape_iri,
7645 descent_bound,
7646 } => {
7647 hasher = hasher.fold_byte(10);
7648 hasher = hasher.fold_bytes(shape_iri.as_bytes());
7649 hasher = hasher.fold_byte(0);
7650 hasher = hasher.fold_bytes(&descent_bound.to_be_bytes());
7651 }
7652 }
7653 hasher
7654}
7655
7656pub fn fold_unit_digest<H: Hasher>(
7664 mut hasher: H,
7665 level_bits: u16,
7666 budget: u64,
7667 iri: &str,
7668 site_count: usize,
7669 constraints: &[crate::pipeline::ConstraintRef],
7670 kind: CertificateKind,
7671) -> H {
7672 hasher = hasher.fold_bytes(&level_bits.to_be_bytes());
7673 hasher = hasher.fold_bytes(&budget.to_be_bytes());
7674 hasher = hasher.fold_bytes(iri.as_bytes());
7675 hasher = hasher.fold_byte(0);
7676 hasher = hasher.fold_bytes(&(site_count as u64).to_be_bytes());
7677 let mut i = 0;
7678 while i < constraints.len() {
7679 hasher = fold_constraint_ref(hasher, &constraints[i]);
7680 i += 1;
7681 }
7682 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
7683 hasher
7684}
7685
7686pub fn fold_parallel_digest<H: Hasher>(
7690 mut hasher: H,
7691 decl_site_count: u64,
7692 iri: &str,
7693 type_site_count: usize,
7694 constraints: &[crate::pipeline::ConstraintRef],
7695 kind: CertificateKind,
7696) -> H {
7697 hasher = hasher.fold_bytes(&decl_site_count.to_be_bytes());
7698 hasher = hasher.fold_bytes(iri.as_bytes());
7699 hasher = hasher.fold_byte(0);
7700 hasher = hasher.fold_bytes(&(type_site_count as u64).to_be_bytes());
7701 let mut i = 0;
7702 while i < constraints.len() {
7703 hasher = fold_constraint_ref(hasher, &constraints[i]);
7704 i += 1;
7705 }
7706 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
7707 hasher
7708}
7709
7710pub fn fold_stream_digest<H: Hasher>(
7712 mut hasher: H,
7713 productivity_bound: u64,
7714 iri: &str,
7715 constraints: &[crate::pipeline::ConstraintRef],
7716 kind: CertificateKind,
7717) -> H {
7718 hasher = hasher.fold_bytes(&productivity_bound.to_be_bytes());
7719 hasher = hasher.fold_bytes(iri.as_bytes());
7720 hasher = hasher.fold_byte(0);
7721 let mut i = 0;
7722 while i < constraints.len() {
7723 hasher = fold_constraint_ref(hasher, &constraints[i]);
7724 i += 1;
7725 }
7726 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
7727 hasher
7728}
7729
7730pub fn fold_interaction_digest<H: Hasher>(
7732 mut hasher: H,
7733 convergence_seed: u64,
7734 iri: &str,
7735 constraints: &[crate::pipeline::ConstraintRef],
7736 kind: CertificateKind,
7737) -> H {
7738 hasher = hasher.fold_bytes(&convergence_seed.to_be_bytes());
7739 hasher = hasher.fold_bytes(iri.as_bytes());
7740 hasher = hasher.fold_byte(0);
7741 let mut i = 0;
7742 while i < constraints.len() {
7743 hasher = fold_constraint_ref(hasher, &constraints[i]);
7744 i += 1;
7745 }
7746 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
7747 hasher
7748}
7749
7750pub(crate) fn primitive_terminal_reduction<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
7753 witt_bits: u16,
7754) -> Result<(u16, u32, u8), PipelineFailure> {
7755 let outcome = crate::pipeline::run_reduction_stages::<T>(witt_bits)?;
7756 let satisfiable_bit: u8 = if outcome.satisfiable { 1 } else { 0 };
7757 Ok((
7758 outcome.witt_bits,
7759 T::CONSTRAINTS.len() as u32,
7760 satisfiable_bit,
7761 ))
7762}
7763
7764pub(crate) fn fold_terminal_reduction<H: Hasher>(
7766 mut hasher: H,
7767 witt_bits: u16,
7768 constraint_count: u32,
7769 satisfiable_bit: u8,
7770) -> H {
7771 hasher = hasher.fold_bytes(&witt_bits.to_be_bytes());
7772 hasher = hasher.fold_bytes(&constraint_count.to_be_bytes());
7773 hasher = hasher.fold_byte(satisfiable_bit);
7774 hasher
7775}
7776
7777pub fn primitive_simplicial_nerve_betti<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
7810) -> Result<[u32; MAX_BETTI_DIMENSION], GenericImpossibilityWitness> {
7811 primitive_simplicial_nerve_betti_in::<T, crate::pipeline::shape_iri_registry::EmptyShapeRegistry>(
7815 )
7816}
7817
7818pub fn primitive_simplicial_nerve_betti_in<
7835 T: crate::pipeline::ConstrainedTypeShape + ?Sized,
7836 R: crate::pipeline::shape_iri_registry::ShapeRegistryProvider,
7837>() -> Result<[u32; MAX_BETTI_DIMENSION], GenericImpossibilityWitness> {
7838 let mut expanded: [crate::pipeline::ConstraintRef; NERVE_CONSTRAINTS_CAP] =
7841 [crate::pipeline::ConstraintRef::Site { position: 0 }; NERVE_CONSTRAINTS_CAP];
7842 let mut n_expanded: usize = 0;
7843 expand_constraints_in::<R>(T::CONSTRAINTS, u32::MAX, &mut expanded, &mut n_expanded)?;
7844 let n_constraints = n_expanded;
7845 if n_constraints > NERVE_CONSTRAINTS_CAP {
7846 return Err(GenericImpossibilityWitness::for_identity(
7847 "NERVE_CAPACITY_EXCEEDED",
7848 ));
7849 }
7850 let s_all = T::SITE_COUNT;
7851 if s_all > NERVE_SITES_CAP {
7852 return Err(GenericImpossibilityWitness::for_identity(
7853 "NERVE_CAPACITY_EXCEEDED",
7854 ));
7855 }
7856 let n_sites = s_all;
7857 let mut out = [0u32; MAX_BETTI_DIMENSION];
7858 if n_constraints == 0 {
7859 out[0] = 1;
7860 return Ok(out);
7861 }
7862 let mut support = [0u16; NERVE_CONSTRAINTS_CAP];
7864 let mut c = 0;
7865 while c < n_constraints {
7866 support[c] = constraint_site_support_mask_of(&expanded[c], n_sites);
7867 c += 1;
7868 }
7869 let mut c1_pairs_lo = [0u8; NERVE_C1_MAX];
7872 let mut c1_pairs_hi = [0u8; NERVE_C1_MAX];
7873 let mut n_c1: usize = 0;
7874 let mut i = 0;
7875 while i < n_constraints {
7876 let mut j = i + 1;
7877 while j < n_constraints {
7878 if (support[i] & support[j]) != 0 && n_c1 < NERVE_C1_MAX {
7879 c1_pairs_lo[n_c1] = i as u8;
7880 c1_pairs_hi[n_c1] = j as u8;
7881 n_c1 += 1;
7882 }
7883 j += 1;
7884 }
7885 i += 1;
7886 }
7887 let mut c2_i = [0u8; NERVE_C2_MAX];
7889 let mut c2_j = [0u8; NERVE_C2_MAX];
7890 let mut c2_k = [0u8; NERVE_C2_MAX];
7891 let mut n_c2: usize = 0;
7892 let mut i2 = 0;
7893 while i2 < n_constraints {
7894 let mut j2 = i2 + 1;
7895 while j2 < n_constraints {
7896 let mut k2 = j2 + 1;
7897 while k2 < n_constraints {
7898 if (support[i2] & support[j2] & support[k2]) != 0 && n_c2 < NERVE_C2_MAX {
7899 c2_i[n_c2] = i2 as u8;
7900 c2_j[n_c2] = j2 as u8;
7901 c2_k[n_c2] = k2 as u8;
7902 n_c2 += 1;
7903 }
7904 k2 += 1;
7905 }
7906 j2 += 1;
7907 }
7908 i2 += 1;
7909 }
7910 let mut partial_1 = [[0i64; NERVE_C1_MAX]; NERVE_CONSTRAINTS_CAP];
7913 let mut e = 0;
7914 while e < n_c1 {
7915 let lo = c1_pairs_lo[e] as usize;
7916 let hi = c1_pairs_hi[e] as usize;
7917 partial_1[lo][e] = NERVE_RANK_MOD_P - 1; partial_1[hi][e] = 1;
7919 e += 1;
7920 }
7921 let rank_1 = integer_matrix_rank::<NERVE_CONSTRAINTS_CAP, NERVE_C1_MAX>(
7922 &mut partial_1,
7923 n_constraints,
7924 n_c1,
7925 );
7926 let mut partial_2 = [[0i64; NERVE_C2_MAX]; NERVE_C1_MAX];
7929 let mut t = 0;
7930 while t < n_c2 {
7931 let ti = c2_i[t];
7932 let tj = c2_j[t];
7933 let tk = c2_k[t];
7934 let idx_jk = find_pair_index(&c1_pairs_lo, &c1_pairs_hi, n_c1, tj, tk);
7935 let idx_ik = find_pair_index(&c1_pairs_lo, &c1_pairs_hi, n_c1, ti, tk);
7936 let idx_ij = find_pair_index(&c1_pairs_lo, &c1_pairs_hi, n_c1, ti, tj);
7937 if idx_jk < NERVE_C1_MAX {
7938 partial_2[idx_jk][t] = 1;
7939 }
7940 if idx_ik < NERVE_C1_MAX {
7941 partial_2[idx_ik][t] = NERVE_RANK_MOD_P - 1;
7942 }
7943 if idx_ij < NERVE_C1_MAX {
7944 partial_2[idx_ij][t] = 1;
7945 }
7946 t += 1;
7947 }
7948 let rank_2 = integer_matrix_rank::<NERVE_C1_MAX, NERVE_C2_MAX>(&mut partial_2, n_c1, n_c2);
7949 let b0 = (n_constraints - rank_1) as u32;
7951 let cycles_1 = n_c1.saturating_sub(rank_1);
7953 let b1 = cycles_1.saturating_sub(rank_2) as u32;
7954 let b2 = n_c2.saturating_sub(rank_2) as u32;
7956 out[0] = if b0 == 0 { 1 } else { b0 };
7957 if MAX_BETTI_DIMENSION > 1 {
7958 out[1] = b1;
7959 }
7960 if MAX_BETTI_DIMENSION > 2 {
7961 out[2] = b2;
7962 }
7963 Ok(out)
7964}
7965
7966pub fn expand_constraints_in<R: crate::pipeline::shape_iri_registry::ShapeRegistryProvider>(
7981 in_constraints: &[crate::pipeline::ConstraintRef],
7982 descent_remaining: u32,
7983 out_arr: &mut [crate::pipeline::ConstraintRef; NERVE_CONSTRAINTS_CAP],
7984 out_n: &mut usize,
7985) -> Result<(), GenericImpossibilityWitness> {
7986 let mut i = 0;
7987 while i < in_constraints.len() {
7988 match in_constraints[i] {
7989 crate::pipeline::ConstraintRef::Recurse {
7990 shape_iri,
7991 descent_bound,
7992 } => {
7993 let budget = if descent_remaining < descent_bound {
7995 descent_remaining
7996 } else {
7997 descent_bound
7998 };
7999 if budget == 0 {
8000 } else {
8002 match crate::pipeline::shape_iri_registry::lookup_shape_in::<R>(shape_iri) {
8003 Some(registered) => {
8004 expand_constraints_in::<R>(
8005 registered.constraints,
8006 budget - 1,
8007 out_arr,
8008 out_n,
8009 )?;
8010 }
8011 None => {
8012 return Err(GenericImpossibilityWitness::for_identity(
8013 "RECURSE_SHAPE_UNREGISTERED",
8014 ));
8015 }
8016 }
8017 }
8018 }
8019 other => {
8020 if *out_n >= NERVE_CONSTRAINTS_CAP {
8021 return Err(GenericImpossibilityWitness::for_identity(
8022 "NERVE_CAPACITY_EXCEEDED",
8023 ));
8024 }
8025 out_arr[*out_n] = other;
8026 *out_n += 1;
8027 }
8028 }
8029 i += 1;
8030 }
8031 Ok(())
8032}
8033
8034pub const NERVE_CONSTRAINTS_CAP: usize = 8;
8040
8041pub const NERVE_SITES_CAP: usize = 8;
8047
8048pub const NERVE_C1_MAX: usize = 28;
8050
8051pub const NERVE_C2_MAX: usize = 56;
8053
8054pub(crate) const NERVE_RANK_MOD_P: i64 = 1_000_000_007;
8058
8059pub(crate) const fn constraint_site_support_mask_of(
8070 c: &crate::pipeline::ConstraintRef,
8071 n_sites: usize,
8072) -> u16 {
8073 let all_mask: u16 = if n_sites == 0 {
8074 0
8075 } else {
8076 (1u16 << n_sites) - 1
8077 };
8078 match c {
8079 crate::pipeline::ConstraintRef::Site { position } => {
8080 if n_sites == 0 {
8081 0
8082 } else {
8083 1u16 << (*position as usize % n_sites)
8084 }
8085 }
8086 crate::pipeline::ConstraintRef::Carry { site } => {
8087 if n_sites == 0 {
8088 0
8089 } else {
8090 1u16 << (*site as usize % n_sites)
8091 }
8092 }
8093 crate::pipeline::ConstraintRef::Affine {
8094 coefficients,
8095 coefficient_count,
8096 ..
8097 } => {
8098 if n_sites == 0 {
8099 0
8100 } else {
8101 let mut mask: u16 = 0;
8102 let count = *coefficient_count as usize;
8103 let mut i = 0;
8104 while i < count && i < crate::pipeline::AFFINE_MAX_COEFFS && i < n_sites {
8105 if coefficients[i] != 0 {
8106 mask |= 1u16 << i;
8107 }
8108 i += 1;
8109 }
8110 if mask == 0 {
8111 all_mask
8112 } else {
8113 mask
8114 }
8115 }
8116 }
8117 _ => all_mask,
8121 }
8122}
8123
8124pub(crate) const fn find_pair_index(
8127 lo_arr: &[u8; NERVE_C1_MAX],
8128 hi_arr: &[u8; NERVE_C1_MAX],
8129 n_c1: usize,
8130 lo: u8,
8131 hi: u8,
8132) -> usize {
8133 let mut i = 0;
8134 while i < n_c1 {
8135 if lo_arr[i] == lo && hi_arr[i] == hi {
8136 return i;
8137 }
8138 i += 1;
8139 }
8140 NERVE_C1_MAX
8141}
8142
8143pub(crate) const fn integer_matrix_rank<const R: usize, const C: usize>(
8148 matrix: &mut [[i64; C]; R],
8149 rows: usize,
8150 cols: usize,
8151) -> usize {
8152 let p = NERVE_RANK_MOD_P;
8153 let mut r = 0;
8155 while r < rows {
8156 let mut c = 0;
8157 while c < cols {
8158 let v = matrix[r][c] % p;
8159 matrix[r][c] = if v < 0 { v + p } else { v };
8160 c += 1;
8161 }
8162 r += 1;
8163 }
8164 let mut rank: usize = 0;
8165 let mut col: usize = 0;
8166 while col < cols && rank < rows {
8167 let mut pivot_row = rank;
8169 while pivot_row < rows && matrix[pivot_row][col] == 0 {
8170 pivot_row += 1;
8171 }
8172 if pivot_row == rows {
8173 col += 1;
8174 continue;
8175 }
8176 if pivot_row != rank {
8178 let mut k = 0;
8179 while k < cols {
8180 let tmp = matrix[rank][k];
8181 matrix[rank][k] = matrix[pivot_row][k];
8182 matrix[pivot_row][k] = tmp;
8183 k += 1;
8184 }
8185 }
8186 let pivot = matrix[rank][col];
8188 let pivot_inv = mod_pow(pivot, p - 2, p);
8189 let mut k = 0;
8190 while k < cols {
8191 matrix[rank][k] = (matrix[rank][k] * pivot_inv) % p;
8192 k += 1;
8193 }
8194 let mut r2 = 0;
8196 while r2 < rows {
8197 if r2 != rank {
8198 let factor = matrix[r2][col];
8199 if factor != 0 {
8200 let mut kk = 0;
8201 while kk < cols {
8202 let sub = (matrix[rank][kk] * factor) % p;
8203 let mut v = matrix[r2][kk] - sub;
8204 v %= p;
8205 if v < 0 {
8206 v += p;
8207 }
8208 matrix[r2][kk] = v;
8209 kk += 1;
8210 }
8211 }
8212 }
8213 r2 += 1;
8214 }
8215 rank += 1;
8216 col += 1;
8217 }
8218 rank
8219}
8220
8221pub(crate) const fn mod_pow(base: i64, exp: i64, p: i64) -> i64 {
8224 let mut result: i64 = 1;
8225 let mut b = ((base % p) + p) % p;
8226 let mut e = exp;
8227 while e > 0 {
8228 if e & 1 == 1 {
8229 result = (result * b) % p;
8230 }
8231 b = (b * b) % p;
8232 e >>= 1;
8233 }
8234 result
8235}
8236
8237pub(crate) fn fold_betti_tuple<H: Hasher>(mut hasher: H, betti: &[u32; MAX_BETTI_DIMENSION]) -> H {
8239 let mut i = 0;
8240 while i < MAX_BETTI_DIMENSION {
8241 hasher = hasher.fold_bytes(&betti[i].to_be_bytes());
8242 i += 1;
8243 }
8244 hasher
8245}
8246
8247#[must_use]
8249pub(crate) fn primitive_euler_characteristic(betti: &[u32; MAX_BETTI_DIMENSION]) -> i64 {
8250 let mut chi: i64 = 0;
8251 let mut k = 0;
8252 while k < MAX_BETTI_DIMENSION {
8253 let term = betti[k] as i64;
8254 if k % 2 == 0 {
8255 chi += term;
8256 } else {
8257 chi -= term;
8258 }
8259 k += 1;
8260 }
8261 chi
8262}
8263
8264pub(crate) fn primitive_dihedral_signature<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
8275) -> (u32, u32) {
8276 let n = T::SITE_COUNT as u32;
8277 let orbit_size = if n < 2 {
8278 if n == 0 {
8279 1
8280 } else {
8281 2
8282 }
8283 } else {
8284 2 * n
8285 };
8286 let mut rep: u32 = 0;
8292 let mut k = 1u32;
8293 while k < n {
8294 let rot = k % n;
8295 let refl = (n - k) % n;
8296 if rot < rep {
8297 rep = rot;
8298 }
8299 if refl < rep {
8300 rep = refl;
8301 }
8302 k += 1;
8303 }
8304 (orbit_size, rep)
8305}
8306
8307pub(crate) fn fold_dihedral_signature<H: Hasher>(
8309 mut hasher: H,
8310 orbit_size: u32,
8311 representative: u32,
8312) -> H {
8313 hasher = hasher.fold_bytes(&orbit_size.to_be_bytes());
8314 hasher = hasher.fold_bytes(&representative.to_be_bytes());
8315 hasher
8316}
8317
8318pub(crate) fn primitive_curvature_jacobian<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
8323) -> [i32; JACOBIAN_MAX_SITES] {
8324 let mut out = [0i32; JACOBIAN_MAX_SITES];
8325 let mut ci = 0;
8326 while ci < T::CONSTRAINTS.len() {
8327 if let crate::pipeline::ConstraintRef::Site { position } = T::CONSTRAINTS[ci] {
8328 let idx = (position as usize) % JACOBIAN_MAX_SITES;
8329 out[idx] = out[idx].saturating_add(1);
8330 }
8331 ci += 1;
8332 }
8333 let total = T::CONSTRAINTS.len() as i32;
8336 out[0] = out[0].saturating_add(total);
8337 out
8338}
8339
8340#[must_use]
8342pub(crate) fn primitive_dc10_select(jac: &[i32; JACOBIAN_MAX_SITES]) -> usize {
8343 let mut best_idx: usize = 0;
8344 let mut best_abs: i32 = jac[0].unsigned_abs() as i32;
8345 let mut i = 1;
8346 while i < JACOBIAN_MAX_SITES {
8347 let a = jac[i].unsigned_abs() as i32;
8348 if a > best_abs {
8349 best_abs = a;
8350 best_idx = i;
8351 }
8352 i += 1;
8353 }
8354 best_idx
8355}
8356
8357pub(crate) fn fold_jacobian_profile<H: Hasher>(
8359 mut hasher: H,
8360 jac: &[i32; JACOBIAN_MAX_SITES],
8361) -> H {
8362 let mut i = 0;
8363 while i < JACOBIAN_MAX_SITES {
8364 hasher = hasher.fold_bytes(&jac[i].to_be_bytes());
8365 i += 1;
8366 }
8367 hasher
8368}
8369
8370pub(crate) fn primitive_session_binding_signature(bindings: &[Binding]) -> (u32, u64) {
8379 let mut fold: u64 = 0xcbf2_9ce4_8422_2325;
8382 const FNV_PRIME: u64 = 0x0000_0100_0000_01b3;
8383 let mut i = 0;
8384 while i < bindings.len() {
8385 let b = &bindings[i];
8386 fold = fold.wrapping_mul(FNV_PRIME);
8388 fold ^= b.name_index as u64;
8389 fold = fold.wrapping_mul(FNV_PRIME);
8390 fold ^= b.type_index as u64;
8391 fold = fold.wrapping_mul(FNV_PRIME);
8392 fold ^= b.content_address;
8393 i += 1;
8394 }
8395 (bindings.len() as u32, fold)
8396}
8397
8398pub(crate) fn fold_session_signature<H: Hasher>(
8400 mut hasher: H,
8401 binding_count: u32,
8402 fold_address: u64,
8403) -> H {
8404 hasher = hasher.fold_bytes(&binding_count.to_be_bytes());
8405 hasher = hasher.fold_bytes(&fold_address.to_be_bytes());
8406 hasher
8407}
8408
8409pub(crate) fn primitive_measurement_projection(budget: u64) -> (u64, u64) {
8424 let alpha0_bits: u32 = (budget >> 32) as u32;
8428 let alpha1_bits: u32 = (budget & 0xFFFF_FFFF) as u32;
8429 type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
8430 let a0 = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(alpha0_bits)
8431 / <DefaultDecimal as crate::DecimalTranscendental>::from_u32(u32::MAX);
8432 let a1 = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(alpha1_bits)
8433 / <DefaultDecimal as crate::DecimalTranscendental>::from_u32(u32::MAX);
8434 let norm = a0 * a0 + a1 * a1;
8435 let zero = <DefaultDecimal as Default>::default();
8436 let half =
8437 <DefaultDecimal as crate::DecimalTranscendental>::from_bits(0x3FE0_0000_0000_0000_u64);
8438 let p0 = if norm > zero { (a0 * a0) / norm } else { half };
8442 let p1 = if norm > zero { (a1 * a1) / norm } else { half };
8443 if p0 >= p1 {
8444 (
8445 0,
8446 <DefaultDecimal as crate::DecimalTranscendental>::to_bits(p0),
8447 )
8448 } else {
8449 (
8450 1,
8451 <DefaultDecimal as crate::DecimalTranscendental>::to_bits(p1),
8452 )
8453 }
8454}
8455
8456pub(crate) fn fold_born_outcome<H: Hasher>(
8460 mut hasher: H,
8461 outcome_index: u64,
8462 probability_bits: u64,
8463) -> H {
8464 hasher = hasher.fold_bytes(&outcome_index.to_be_bytes());
8465 hasher = hasher.fold_bytes(&probability_bits.to_be_bytes());
8466 hasher
8467}
8468
8469pub(crate) fn primitive_descent_metrics<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
8477 betti: &[u32; MAX_BETTI_DIMENSION],
8478) -> (u32, u64) {
8479 let chi = primitive_euler_characteristic(betti);
8480 let n = T::SITE_COUNT as i64;
8481 let residual = if n > chi { (n - chi) as u32 } else { 0u32 };
8482 type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
8483 let residual_d = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(residual);
8484 let ln_2 = <DefaultDecimal as crate::DecimalTranscendental>::from_bits(crate::LN_2_BITS);
8485 let entropy = residual_d * ln_2;
8486 (
8487 residual,
8488 <DefaultDecimal as crate::DecimalTranscendental>::to_bits(entropy),
8489 )
8490}
8491
8492pub(crate) fn fold_descent_metrics<H: Hasher>(
8495 mut hasher: H,
8496 residual_count: u32,
8497 entropy_bits: u64,
8498) -> H {
8499 hasher = hasher.fold_bytes(&residual_count.to_be_bytes());
8500 hasher = hasher.fold_bytes(&entropy_bits.to_be_bytes());
8501 hasher
8502}
8503
8504pub const MAX_COHOMOLOGY_DIMENSION: u32 = 32;
8508
8509#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8514pub struct CohomologyClass {
8515 dimension: u32,
8516 fingerprint: ContentFingerprint,
8517 _sealed: (),
8518}
8519
8520impl CohomologyClass {
8521 #[inline]
8525 pub(crate) const fn with_dimension_and_fingerprint(
8526 dimension: u32,
8527 fingerprint: ContentFingerprint,
8528 ) -> Self {
8529 Self {
8530 dimension,
8531 fingerprint,
8532 _sealed: (),
8533 }
8534 }
8535
8536 #[inline]
8538 #[must_use]
8539 pub const fn dimension(&self) -> u32 {
8540 self.dimension
8541 }
8542
8543 #[inline]
8545 #[must_use]
8546 pub const fn fingerprint(&self) -> ContentFingerprint {
8547 self.fingerprint
8548 }
8549
8550 pub fn cup<H: Hasher>(
8559 self,
8560 other: CohomologyClass,
8561 ) -> Result<CohomologyClass, CohomologyError> {
8562 let sum = self.dimension.saturating_add(other.dimension);
8563 if sum > MAX_COHOMOLOGY_DIMENSION {
8564 return Err(CohomologyError::DimensionOverflow {
8565 lhs: self.dimension,
8566 rhs: other.dimension,
8567 });
8568 }
8569 let hasher = H::initial();
8570 let hasher = fold_cup_product(
8571 hasher,
8572 self.dimension,
8573 &self.fingerprint,
8574 other.dimension,
8575 &other.fingerprint,
8576 );
8577 let buf = hasher.finalize();
8578 let fp = ContentFingerprint::from_buffer(buf, H::OUTPUT_BYTES as u8);
8579 Ok(Self::with_dimension_and_fingerprint(sum, fp))
8580 }
8581}
8582
8583#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8586pub enum CohomologyError {
8587 DimensionOverflow { lhs: u32, rhs: u32 },
8589}
8590
8591impl core::fmt::Display for CohomologyError {
8592 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8593 match self {
8594 Self::DimensionOverflow { lhs, rhs } => write!(
8595 f,
8596 "cup product dimension overflow: {lhs} + {rhs} > MAX_COHOMOLOGY_DIMENSION ({})",
8597 MAX_COHOMOLOGY_DIMENSION
8598 ),
8599 }
8600 }
8601}
8602impl core::error::Error for CohomologyError {}
8603
8604#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8608pub struct HomologyClass {
8609 dimension: u32,
8610 fingerprint: ContentFingerprint,
8611 _sealed: (),
8612}
8613
8614impl HomologyClass {
8615 #[inline]
8618 pub(crate) const fn with_dimension_and_fingerprint(
8619 dimension: u32,
8620 fingerprint: ContentFingerprint,
8621 ) -> Self {
8622 Self {
8623 dimension,
8624 fingerprint,
8625 _sealed: (),
8626 }
8627 }
8628
8629 #[inline]
8631 #[must_use]
8632 pub const fn dimension(&self) -> u32 {
8633 self.dimension
8634 }
8635
8636 #[inline]
8638 #[must_use]
8639 pub const fn fingerprint(&self) -> ContentFingerprint {
8640 self.fingerprint
8641 }
8642}
8643
8644pub fn fold_cup_product<H: Hasher>(
8647 mut hasher: H,
8648 lhs_dim: u32,
8649 lhs_fp: &ContentFingerprint,
8650 rhs_dim: u32,
8651 rhs_fp: &ContentFingerprint,
8652) -> H {
8653 hasher = hasher.fold_bytes(&lhs_dim.to_be_bytes());
8654 hasher = hasher.fold_bytes(lhs_fp.as_bytes());
8655 hasher = hasher.fold_bytes(&rhs_dim.to_be_bytes());
8656 hasher = hasher.fold_bytes(rhs_fp.as_bytes());
8657 hasher
8658}
8659
8660pub fn mint_cohomology_class<H: Hasher>(
8667 dimension: u32,
8668 seed: &[u8],
8669) -> Result<CohomologyClass, CohomologyError> {
8670 if dimension > MAX_COHOMOLOGY_DIMENSION {
8671 return Err(CohomologyError::DimensionOverflow {
8672 lhs: dimension,
8673 rhs: 0,
8674 });
8675 }
8676 let mut hasher = H::initial();
8677 hasher = hasher.fold_bytes(&dimension.to_be_bytes());
8678 hasher = hasher.fold_bytes(seed);
8679 let buf = hasher.finalize();
8680 let fp = ContentFingerprint::from_buffer(buf, H::OUTPUT_BYTES as u8);
8681 Ok(CohomologyClass::with_dimension_and_fingerprint(
8682 dimension, fp,
8683 ))
8684}
8685
8686pub fn mint_homology_class<H: Hasher>(
8692 dimension: u32,
8693 seed: &[u8],
8694) -> Result<HomologyClass, CohomologyError> {
8695 if dimension > MAX_COHOMOLOGY_DIMENSION {
8696 return Err(CohomologyError::DimensionOverflow {
8697 lhs: dimension,
8698 rhs: 0,
8699 });
8700 }
8701 let mut hasher = H::initial();
8702 hasher = hasher.fold_bytes(&dimension.to_be_bytes());
8703 hasher = hasher.fold_bytes(seed);
8704 let buf = hasher.finalize();
8705 let fp = ContentFingerprint::from_buffer(buf, H::OUTPUT_BYTES as u8);
8706 Ok(HomologyClass::with_dimension_and_fingerprint(dimension, fp))
8707}
8708
8709pub fn fold_stream_step_digest<H: Hasher>(
8713 mut hasher: H,
8714 productivity_remaining: u64,
8715 rewrite_steps: u64,
8716 seed: u64,
8717 iri: &str,
8718 kind: CertificateKind,
8719) -> H {
8720 hasher = hasher.fold_bytes(&productivity_remaining.to_be_bytes());
8721 hasher = hasher.fold_bytes(&rewrite_steps.to_be_bytes());
8722 hasher = hasher.fold_bytes(&seed.to_be_bytes());
8723 hasher = hasher.fold_bytes(iri.as_bytes());
8724 hasher = hasher.fold_byte(0);
8725 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
8726 hasher
8727}
8728
8729pub fn fold_interaction_step_digest<H: Hasher>(
8734 mut hasher: H,
8735 commutator_acc: &[u64; 4],
8736 peer_step_count: u64,
8737 seed: u64,
8738 iri: &str,
8739 kind: CertificateKind,
8740) -> H {
8741 let mut i = 0;
8742 while i < 4 {
8743 hasher = hasher.fold_bytes(&commutator_acc[i].to_be_bytes());
8744 i += 1;
8745 }
8746 hasher = hasher.fold_bytes(&peer_step_count.to_be_bytes());
8747 hasher = hasher.fold_bytes(&seed.to_be_bytes());
8748 hasher = hasher.fold_bytes(iri.as_bytes());
8749 hasher = hasher.fold_byte(0);
8750 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
8751 hasher
8752}
8753
8754#[inline]
8764#[must_use]
8765pub const fn unit_address_from_buffer<const FP_MAX: usize>(
8766 buffer: &[u8; FP_MAX],
8767) -> ContentAddress {
8768 let mut bytes = [0u8; 16];
8769 let mut i = 0;
8770 while i < 16 {
8771 bytes[i] = buffer[i];
8772 i += 1;
8773 }
8774 ContentAddress::from_u128(u128::from_be_bytes(bytes))
8775}
8776
8777#[inline]
8782#[must_use]
8783pub const fn str_eq(a: &str, b: &str) -> bool {
8784 let a = a.as_bytes();
8785 let b = b.as_bytes();
8786 if a.len() != b.len() {
8787 return false;
8788 }
8789 let mut i = 0;
8790 while i < a.len() {
8791 if a[i] != b[i] {
8792 return false;
8793 }
8794 i += 1;
8795 }
8796 true
8797}
8798
8799#[derive(Debug, Clone, Copy)]
8802pub struct BindingEntry {
8803 pub address: ContentAddress,
8805 pub bytes: &'static [u8],
8807}
8808
8809#[derive(Debug, Clone, Copy)]
8813pub struct BindingsTable {
8814 pub entries: &'static [BindingEntry],
8816}
8817
8818impl BindingsTable {
8819 pub const fn try_new(entries: &'static [BindingEntry]) -> Result<Self, BindingsTableError> {
8827 let mut i = 1;
8828 while i < entries.len() {
8829 if entries[i].address.as_u128() <= entries[i - 1].address.as_u128() {
8830 return Err(BindingsTableError::Unsorted { at: i });
8831 }
8832 i += 1;
8833 }
8834 Ok(Self { entries })
8835 }
8836}
8837
8838#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8840#[non_exhaustive]
8841pub enum BindingsTableError {
8842 Unsorted {
8845 at: usize,
8847 },
8848}
8849
8850impl core::fmt::Display for BindingsTableError {
8851 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8852 match self {
8853 Self::Unsorted { at } => write!(
8854 f,
8855 "BindingsTable entries not sorted: address at index {at} <= address at index {}",
8856 at - 1,
8857 ),
8858 }
8859 }
8860}
8861
8862impl core::error::Error for BindingsTableError {}
8863
8864#[derive(Debug, Clone)]
8898pub struct Grounded<T: GroundedShape, const INLINE_BYTES: usize, Tag = T> {
8899 validated: Validated<GroundingCertificate>,
8901 bindings: BindingsTable,
8903 witt_level_bits: u16,
8905 unit_address: ContentAddress,
8907 uor_time: UorTime,
8910 sigma_ppm: u32,
8916 d_delta: i64,
8918 euler_characteristic: i64,
8920 residual_count: u32,
8922 jacobian_entries: [i64; JACOBIAN_MAX_SITES],
8924 jacobian_len: u16,
8926 betti_numbers: [u32; MAX_BETTI_DIMENSION],
8928 content_fingerprint: ContentFingerprint,
8934 output_payload: [u8; INLINE_BYTES],
8939 output_len: u16,
8941 _phantom: PhantomData<T>,
8943 _tag: PhantomData<Tag>,
8946}
8947
8948impl<T: GroundedShape, const INLINE_BYTES: usize, Tag> Grounded<T, INLINE_BYTES, Tag> {
8949 #[inline]
8953 #[must_use]
8954 pub fn get_binding(&self, address: ContentAddress) -> Option<&'static [u8]> {
8955 self.bindings
8956 .entries
8957 .binary_search_by_key(&address.as_u128(), |e| e.address.as_u128())
8958 .ok()
8959 .map(|i| self.bindings.entries[i].bytes)
8960 }
8961
8962 #[inline]
8964 pub fn iter_bindings(&self) -> impl Iterator<Item = &BindingEntry> + '_ {
8965 self.bindings.entries.iter()
8966 }
8967
8968 #[inline]
8970 #[must_use]
8971 pub const fn witt_level_bits(&self) -> u16 {
8972 self.witt_level_bits
8973 }
8974
8975 #[inline]
8977 #[must_use]
8978 pub const fn unit_address(&self) -> ContentAddress {
8979 self.unit_address
8980 }
8981
8982 #[inline]
8984 #[must_use]
8985 pub const fn certificate(&self) -> &Validated<GroundingCertificate> {
8986 &self.validated
8987 }
8988
8989 #[inline]
8992 #[must_use]
8993 pub const fn d_delta(&self) -> DDeltaMetric {
8994 DDeltaMetric::new(self.d_delta)
8995 }
8996
8997 #[inline]
8999 #[must_use]
9000 pub fn sigma(&self) -> SigmaValue<crate::DefaultHostTypes> {
9001 let value = <f64 as crate::DecimalTranscendental>::from_u32(self.sigma_ppm)
9004 / <f64 as crate::DecimalTranscendental>::from_u32(1_000_000);
9005 SigmaValue::<crate::DefaultHostTypes>::new_unchecked(value)
9006 }
9007
9008 #[inline]
9010 #[must_use]
9011 pub fn jacobian(&self) -> JacobianMetric<T> {
9012 JacobianMetric::from_entries(self.jacobian_entries, self.jacobian_len)
9013 }
9014
9015 #[inline]
9017 #[must_use]
9018 pub const fn betti(&self) -> BettiMetric {
9019 BettiMetric::new(self.betti_numbers)
9020 }
9021
9022 #[inline]
9025 #[must_use]
9026 pub const fn euler(&self) -> EulerMetric {
9027 EulerMetric::new(self.euler_characteristic)
9028 }
9029
9030 #[inline]
9032 #[must_use]
9033 pub const fn residual(&self) -> ResidualMetric {
9034 ResidualMetric::new(self.residual_count)
9035 }
9036
9037 #[inline]
9043 #[must_use]
9044 pub const fn content_fingerprint(&self) -> ContentFingerprint {
9045 self.content_fingerprint
9046 }
9047
9048 #[inline]
9059 #[must_use]
9060 pub const fn derivation(&self) -> Derivation {
9061 Derivation::new(
9062 (self.jacobian_len as u32) + 1,
9063 self.witt_level_bits,
9064 self.content_fingerprint,
9065 )
9066 }
9067
9068 #[inline]
9077 #[must_use]
9078 pub fn tag<NewTag>(self) -> Grounded<T, INLINE_BYTES, NewTag> {
9079 Grounded {
9080 validated: self.validated,
9081 bindings: self.bindings,
9082 witt_level_bits: self.witt_level_bits,
9083 unit_address: self.unit_address,
9084 uor_time: self.uor_time,
9085 sigma_ppm: self.sigma_ppm,
9086 d_delta: self.d_delta,
9087 euler_characteristic: self.euler_characteristic,
9088 residual_count: self.residual_count,
9089 jacobian_entries: self.jacobian_entries,
9090 jacobian_len: self.jacobian_len,
9091 betti_numbers: self.betti_numbers,
9092 content_fingerprint: self.content_fingerprint,
9093 output_payload: self.output_payload,
9094 output_len: self.output_len,
9095 _phantom: PhantomData,
9096 _tag: PhantomData,
9097 }
9098 }
9099
9100 #[inline]
9108 #[must_use]
9109 pub fn output_bytes(&self) -> &[u8] {
9110 let len = self.output_len as usize;
9111 &self.output_payload[..len]
9112 }
9113
9114 #[inline]
9121 #[must_use]
9122 pub const fn uor_time(&self) -> UorTime {
9123 self.uor_time
9124 }
9125
9126 #[inline]
9133 #[must_use]
9134 pub const fn triad(&self) -> Triad<T> {
9135 let addr = self.unit_address.as_u128();
9136 let addr_lo = addr as u64;
9137 let addr_hi = (addr >> 64) as u64;
9138 let stratum = if addr_lo == 0 {
9139 0u64
9140 } else {
9141 addr_lo.trailing_zeros() as u64
9142 };
9143 Triad::new(stratum, addr_lo, addr_hi)
9144 }
9145
9146 #[inline]
9154 #[allow(dead_code)]
9155 pub(crate) const fn new_internal(
9156 validated: Validated<GroundingCertificate>,
9157 bindings: BindingsTable,
9158 witt_level_bits: u16,
9159 unit_address: ContentAddress,
9160 content_fingerprint: ContentFingerprint,
9161 ) -> Self {
9162 let bound_count = bindings.entries.len() as u32;
9163 let declared_sites = if witt_level_bits == 0 {
9164 1u32
9165 } else {
9166 witt_level_bits as u32
9167 };
9168 let sigma_ppm = if bound_count >= declared_sites {
9170 1_000_000u32
9171 } else {
9172 let num = (bound_count as u64) * 1_000_000u64;
9174 (num / (declared_sites as u64)) as u32
9175 };
9176 let residual_count = declared_sites.saturating_sub(bound_count);
9178 let d_delta = (witt_level_bits as i64) - (bound_count as i64);
9180 let mut betti = [0u32; MAX_BETTI_DIMENSION];
9182 betti[0] = 1;
9183 let mut k = 1usize;
9184 while k < MAX_BETTI_DIMENSION {
9185 betti[k] = ((witt_level_bits as u32) >> (k - 1)) & 1;
9186 k += 1;
9187 }
9188 let mut euler: i64 = 0;
9190 let mut k = 0usize;
9191 while k < MAX_BETTI_DIMENSION {
9192 if k & 1 == 0 {
9193 euler += betti[k] as i64;
9194 } else {
9195 euler -= betti[k] as i64;
9196 }
9197 k += 1;
9198 }
9199 let mut jac = [0i64; JACOBIAN_MAX_SITES];
9201 let modulus = (witt_level_bits as i64) + 1;
9202 let ua_lo = unit_address.as_u128() as i64;
9203 let mut i = 0usize;
9204 let jac_len = if (witt_level_bits as usize) < JACOBIAN_MAX_SITES {
9205 witt_level_bits as usize
9206 } else {
9207 JACOBIAN_MAX_SITES
9208 };
9209 while i < jac_len {
9210 let raw = ua_lo ^ (i as i64);
9211 let m = if modulus == 0 { 1 } else { modulus };
9213 jac[i] = ((raw % m) + m) % m;
9214 i += 1;
9215 }
9216 let steps = (witt_level_bits as u64) + (bound_count as u64) + (jac_len as u64);
9222 let landauer = LandauerBudget::new((steps as f64) * core::f64::consts::LN_2);
9223 let uor_time = UorTime::new(landauer, steps);
9224 Self {
9225 validated,
9226 bindings,
9227 witt_level_bits,
9228 unit_address,
9229 uor_time,
9230 sigma_ppm,
9231 d_delta,
9232 euler_characteristic: euler,
9233 residual_count,
9234 jacobian_entries: jac,
9235 jacobian_len: jac_len as u16,
9236 betti_numbers: betti,
9237 content_fingerprint,
9238 output_payload: [0u8; INLINE_BYTES],
9239 output_len: 0,
9240 _phantom: PhantomData,
9241 _tag: PhantomData,
9242 }
9243 }
9244
9245 #[inline]
9251 #[must_use]
9252 pub(crate) fn with_output_bytes(mut self, bytes: &[u8]) -> Self {
9253 let len = bytes.len();
9254 debug_assert!(len <= INLINE_BYTES);
9255 let copy_len = if len > INLINE_BYTES {
9256 INLINE_BYTES
9257 } else {
9258 len
9259 };
9260 let mut i = 0;
9261 while i < copy_len {
9262 self.output_payload[i] = bytes[i];
9263 i += 1;
9264 }
9265 self.output_len = copy_len as u16;
9266 self
9267 }
9268
9269 #[inline]
9280 #[must_use]
9281 pub fn with_bindings(self, bindings: BindingsTable) -> Self {
9282 Self { bindings, ..self }
9283 }
9284
9285 #[inline]
9293 #[must_use]
9294 pub fn as_inhabitance_certificate(
9295 &self,
9296 ) -> crate::pipeline::InhabitanceCertificateView<'_, T, INLINE_BYTES, Tag> {
9297 crate::pipeline::InhabitanceCertificateView(self)
9298 }
9299}
9300
9301#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9306pub struct Triad<L> {
9307 stratum: u64,
9309 spectrum: u64,
9311 address: u64,
9313 _level: PhantomData<L>,
9315}
9316
9317impl<L> Triad<L> {
9318 #[inline]
9320 #[must_use]
9321 pub const fn stratum(&self) -> u64 {
9322 self.stratum
9323 }
9324
9325 #[inline]
9327 #[must_use]
9328 pub const fn spectrum(&self) -> u64 {
9329 self.spectrum
9330 }
9331
9332 #[inline]
9334 #[must_use]
9335 pub const fn address(&self) -> u64 {
9336 self.address
9337 }
9338
9339 #[inline]
9341 #[must_use]
9342 #[allow(dead_code)]
9343 pub(crate) const fn new(stratum: u64, spectrum: u64, address: u64) -> Self {
9344 Self {
9345 stratum,
9346 spectrum,
9347 address,
9348 _level: PhantomData,
9349 }
9350 }
9351}
9352
9353#[derive(Debug, Clone, PartialEq)]
9373#[non_exhaustive]
9374pub enum PipelineFailure {
9375 DispatchMiss {
9377 query_iri: &'static str,
9379 table_iri: &'static str,
9381 },
9382 GroundingFailure {
9384 reason_iri: &'static str,
9386 },
9387 ConvergenceStall {
9389 stage_iri: &'static str,
9391 angle_milliradians: i64,
9393 },
9394 ContradictionDetected {
9396 at_step: usize,
9398 trace_iri: &'static str,
9400 },
9401 CoherenceViolation {
9403 site_position: usize,
9405 constraint_iri: &'static str,
9407 },
9408 ShapeMismatch {
9410 expected: &'static str,
9412 got: &'static str,
9414 },
9415 LiftObstructionFailure {
9417 site_position: usize,
9419 obstruction_class_iri: &'static str,
9421 },
9422 ShapeViolation {
9424 report: ShapeViolation,
9426 },
9427}
9428
9429impl core::fmt::Display for PipelineFailure {
9430 fn fmt(&self, ff: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
9431 match self {
9432 Self::DispatchMiss {
9433 query_iri,
9434 table_iri,
9435 } => write!(
9436 ff,
9437 "DispatchMiss(query_iri={:?}, table_iri={:?})",
9438 query_iri, table_iri
9439 ),
9440 Self::GroundingFailure { reason_iri } => {
9441 write!(ff, "GroundingFailure(reason_iri={:?})", reason_iri)
9442 }
9443 Self::ConvergenceStall {
9444 stage_iri,
9445 angle_milliradians,
9446 } => write!(
9447 ff,
9448 "ConvergenceStall(stage_iri={:?}, angle_milliradians={:?})",
9449 stage_iri, angle_milliradians
9450 ),
9451 Self::ContradictionDetected { at_step, trace_iri } => write!(
9452 ff,
9453 "ContradictionDetected(at_step={:?}, trace_iri={:?})",
9454 at_step, trace_iri
9455 ),
9456 Self::CoherenceViolation {
9457 site_position,
9458 constraint_iri,
9459 } => write!(
9460 ff,
9461 "CoherenceViolation(site_position={:?}, constraint_iri={:?})",
9462 site_position, constraint_iri
9463 ),
9464 Self::ShapeMismatch { expected, got } => {
9465 write!(ff, "ShapeMismatch(expected={:?}, got={:?})", expected, got)
9466 }
9467 Self::LiftObstructionFailure {
9468 site_position,
9469 obstruction_class_iri,
9470 } => write!(
9471 ff,
9472 "LiftObstructionFailure(site_position={:?}, obstruction_class_iri={:?})",
9473 site_position, obstruction_class_iri
9474 ),
9475 Self::ShapeViolation { report } => write!(ff, "ShapeViolation({:?})", report),
9476 }
9477 }
9478}
9479
9480impl core::error::Error for PipelineFailure {}
9481
9482pub trait ImpossibilityWitnessKind: impossibility_witness_kind_sealed::Sealed {}
9486
9487mod impossibility_witness_kind_sealed {
9488 pub trait Sealed {}
9490 impl Sealed for super::GenericImpossibilityWitness {}
9491 impl Sealed for super::InhabitanceImpossibilityWitness {}
9492}
9493
9494impl ImpossibilityWitnessKind for GenericImpossibilityWitness {}
9495impl ImpossibilityWitnessKind for InhabitanceImpossibilityWitness {}
9496
9497pub mod resolver {
9501 use super::{
9502 BornRuleVerification,
9503 Certified,
9504 CompileUnit,
9505 CompletenessCertificate,
9506 GenericImpossibilityWitness,
9507 GeodesicCertificate,
9508 GroundingCertificate,
9509 InhabitanceCertificate,
9510 InhabitanceImpossibilityWitness,
9511 InvolutionCertificate,
9512 IsometryCertificate,
9513 LiftChainCertificate,
9514 MeasurementCertificate,
9515 TransformCertificate,
9517 Validated,
9518 WittLevel,
9519 };
9520
9521 pub mod tower_completeness {
9531 use super::*;
9532 pub fn certify<T, P, H>(
9538 input: &Validated<T, P>,
9539 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9540 where
9541 T: crate::pipeline::ConstrainedTypeShape,
9542 P: crate::enforcement::ValidationPhase,
9543 H: crate::enforcement::Hasher,
9544 {
9545 certify_at::<T, P, H>(input, WittLevel::W32)
9546 }
9547
9548 pub fn certify_at<T, P, H>(
9554 input: &Validated<T, P>,
9555 level: WittLevel,
9556 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9557 where
9558 T: crate::pipeline::ConstrainedTypeShape,
9559 P: crate::enforcement::ValidationPhase,
9560 H: crate::enforcement::Hasher,
9561 {
9562 crate::pipeline::run_tower_completeness::<T, H>(input.inner(), level)
9563 .map(|v| Certified::new(*v.inner()))
9564 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
9565 }
9566 }
9567
9568 pub mod incremental_completeness {
9570 use super::*;
9571 pub fn certify<T, P, H>(
9577 input: &Validated<T, P>,
9578 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9579 where
9580 T: crate::pipeline::ConstrainedTypeShape,
9581 P: crate::enforcement::ValidationPhase,
9582 H: crate::enforcement::Hasher,
9583 {
9584 certify_at::<T, P, H>(input, WittLevel::W32)
9585 }
9586
9587 pub fn certify_at<T, P, H>(
9593 input: &Validated<T, P>,
9594 level: WittLevel,
9595 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9596 where
9597 T: crate::pipeline::ConstrainedTypeShape,
9598 P: crate::enforcement::ValidationPhase,
9599 H: crate::enforcement::Hasher,
9600 {
9601 crate::pipeline::run_incremental_completeness::<T, H>(input.inner(), level)
9602 .map(|v| Certified::new(*v.inner()))
9603 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
9604 }
9605 }
9606
9607 pub mod grounding_aware {
9609 use super::*;
9610 pub fn certify<P, H, const INLINE_BYTES: usize>(
9616 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
9617 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9618 where
9619 P: crate::enforcement::ValidationPhase,
9620 H: crate::enforcement::Hasher,
9621 {
9622 certify_at::<P, H, INLINE_BYTES>(input, WittLevel::W32)
9623 }
9624
9625 pub fn certify_at<P, H, const INLINE_BYTES: usize>(
9631 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
9632 level: WittLevel,
9633 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9634 where
9635 P: crate::enforcement::ValidationPhase,
9636 H: crate::enforcement::Hasher,
9637 {
9638 crate::pipeline::run_grounding_aware::<INLINE_BYTES, H>(input.inner(), level)
9639 .map(|v| Certified::new(*v.inner()))
9640 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
9641 }
9642 }
9643
9644 pub mod inhabitance {
9646 use super::*;
9647 pub fn certify<T, P, H>(
9653 input: &Validated<T, P>,
9654 ) -> Result<Certified<InhabitanceCertificate>, Certified<InhabitanceImpossibilityWitness>>
9655 where
9656 T: crate::pipeline::ConstrainedTypeShape,
9657 P: crate::enforcement::ValidationPhase,
9658 H: crate::enforcement::Hasher,
9659 {
9660 certify_at::<T, P, H>(input, WittLevel::W32)
9661 }
9662
9663 pub fn certify_at<T, P, H>(
9669 input: &Validated<T, P>,
9670 level: WittLevel,
9671 ) -> Result<Certified<InhabitanceCertificate>, Certified<InhabitanceImpossibilityWitness>>
9672 where
9673 T: crate::pipeline::ConstrainedTypeShape,
9674 P: crate::enforcement::ValidationPhase,
9675 H: crate::enforcement::Hasher,
9676 {
9677 crate::pipeline::run_inhabitance::<T, H>(input.inner(), level)
9678 .map(|v: Validated<InhabitanceCertificate>| Certified::new(*v.inner()))
9679 .map_err(|_| Certified::new(InhabitanceImpossibilityWitness::default()))
9680 }
9681 }
9682
9683 pub mod multiplication {
9694 use super::super::{MulContext, MultiplicationCertificate};
9695 use super::*;
9696
9697 pub fn certify<H: crate::enforcement::Hasher>(
9709 context: &MulContext,
9710 ) -> Result<Certified<MultiplicationCertificate>, GenericImpossibilityWitness> {
9711 if context.stack_budget_bytes == 0 {
9712 return Err(GenericImpossibilityWitness::default());
9713 }
9714 let limb_count = context.limb_count.max(1);
9716 let karatsuba_stack_need = limb_count * 8 * 6;
9717 let choose_karatsuba = !context.const_eval
9718 && (context.stack_budget_bytes as usize) >= karatsuba_stack_need;
9719 let mut hasher = H::initial();
9721 hasher = hasher.fold_bytes(&context.stack_budget_bytes.to_be_bytes());
9722 hasher = hasher.fold_byte(if context.const_eval { 1 } else { 0 });
9723 hasher = hasher.fold_bytes(&(limb_count as u64).to_be_bytes());
9724 hasher = hasher.fold_byte(crate::enforcement::certificate_kind_discriminant(
9725 crate::enforcement::CertificateKind::Multiplication,
9726 ));
9727 let buffer = hasher.finalize();
9728 let fp =
9729 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
9730 let cert = if choose_karatsuba {
9731 MultiplicationCertificate::with_evidence(
9732 2,
9733 3,
9734 karatsuba_landauer_cost(limb_count),
9735 fp,
9736 )
9737 } else {
9738 MultiplicationCertificate::with_evidence(
9739 1,
9740 1,
9741 schoolbook_landauer_cost(limb_count),
9742 fp,
9743 )
9744 };
9745 Ok(Certified::new(cert))
9746 }
9747
9748 type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
9750
9751 fn schoolbook_landauer_cost(limb_count: usize) -> u64 {
9755 let n = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(limb_count as u32);
9756 let sixty_four = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(64);
9757 let ln_2 =
9758 <DefaultDecimal as crate::DecimalTranscendental>::from_bits(crate::LN_2_BITS);
9759 (n * n * sixty_four * ln_2).to_bits()
9760 }
9761
9762 fn karatsuba_landauer_cost(limb_count: usize) -> u64 {
9765 let n = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(limb_count as u32);
9766 let two = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(2);
9767 let three = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(3);
9768 let sixty_four = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(64);
9769 let ln_2 =
9770 <DefaultDecimal as crate::DecimalTranscendental>::from_bits(crate::LN_2_BITS);
9771 let n_half = n / two;
9772 (three * n_half * n_half * sixty_four * ln_2).to_bits()
9773 }
9774 }
9775
9776 pub(crate) trait ResolverKernel {
9783 const KIND: crate::enforcement::CertificateKind;
9784 type Cert: crate::enforcement::Certificate;
9787 }
9788
9789 pub mod two_sat_decider {
9807 use super::*;
9808
9809 #[doc(hidden)]
9810 pub struct Kernel;
9811 impl super::ResolverKernel for Kernel {
9812 type Cert = crate::enforcement::GroundingCertificate;
9813 const KIND: crate::enforcement::CertificateKind =
9814 crate::enforcement::CertificateKind::TwoSat;
9815 }
9816
9817 pub fn certify<
9823 T: crate::pipeline::ConstrainedTypeShape,
9824 P: crate::enforcement::ValidationPhase,
9825 H: crate::enforcement::Hasher,
9826 >(
9827 input: &Validated<T, P>,
9828 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9829 {
9830 certify_at::<T, P, H>(input, WittLevel::W32)
9831 }
9832
9833 pub fn certify_at<
9839 T: crate::pipeline::ConstrainedTypeShape,
9840 P: crate::enforcement::ValidationPhase,
9841 H: crate::enforcement::Hasher,
9842 >(
9843 input: &Validated<T, P>,
9844 level: WittLevel,
9845 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9846 {
9847 let _ = input.inner();
9848 let witt_bits = level.witt_length() as u16;
9849 let (tr_bits, tr_constraints, tr_sat) =
9850 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
9851 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
9852 if tr_sat == 0 {
9853 return Err(Certified::new(GenericImpossibilityWitness::default()));
9854 }
9855 let mut hasher = H::initial();
9856 hasher = crate::enforcement::fold_terminal_reduction(
9857 hasher,
9858 tr_bits,
9859 tr_constraints,
9860 tr_sat,
9861 );
9862 hasher = crate::enforcement::fold_unit_digest(
9863 hasher,
9864 witt_bits,
9865 witt_bits as u64,
9866 T::IRI,
9867 T::SITE_COUNT,
9868 T::CONSTRAINTS,
9869 <Kernel as super::ResolverKernel>::KIND,
9870 );
9871 let buffer = hasher.finalize();
9872 let fp =
9873 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
9874 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
9875 Ok(Certified::new(cert))
9876 }
9877 }
9878
9879 pub mod horn_sat_decider {
9897 use super::*;
9898
9899 #[doc(hidden)]
9900 pub struct Kernel;
9901 impl super::ResolverKernel for Kernel {
9902 type Cert = crate::enforcement::GroundingCertificate;
9903 const KIND: crate::enforcement::CertificateKind =
9904 crate::enforcement::CertificateKind::HornSat;
9905 }
9906
9907 pub fn certify<
9913 T: crate::pipeline::ConstrainedTypeShape,
9914 P: crate::enforcement::ValidationPhase,
9915 H: crate::enforcement::Hasher,
9916 >(
9917 input: &Validated<T, P>,
9918 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9919 {
9920 certify_at::<T, P, H>(input, WittLevel::W32)
9921 }
9922
9923 pub fn certify_at<
9929 T: crate::pipeline::ConstrainedTypeShape,
9930 P: crate::enforcement::ValidationPhase,
9931 H: crate::enforcement::Hasher,
9932 >(
9933 input: &Validated<T, P>,
9934 level: WittLevel,
9935 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9936 {
9937 let _ = input.inner();
9938 let witt_bits = level.witt_length() as u16;
9939 let (tr_bits, tr_constraints, tr_sat) =
9940 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
9941 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
9942 if tr_sat == 0 {
9943 return Err(Certified::new(GenericImpossibilityWitness::default()));
9944 }
9945 let mut hasher = H::initial();
9946 hasher = crate::enforcement::fold_terminal_reduction(
9947 hasher,
9948 tr_bits,
9949 tr_constraints,
9950 tr_sat,
9951 );
9952 hasher = crate::enforcement::fold_unit_digest(
9953 hasher,
9954 witt_bits,
9955 witt_bits as u64,
9956 T::IRI,
9957 T::SITE_COUNT,
9958 T::CONSTRAINTS,
9959 <Kernel as super::ResolverKernel>::KIND,
9960 );
9961 let buffer = hasher.finalize();
9962 let fp =
9963 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
9964 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
9965 Ok(Certified::new(cert))
9966 }
9967 }
9968
9969 pub mod residual_verdict {
9987 use super::*;
9988
9989 #[doc(hidden)]
9990 pub struct Kernel;
9991 impl super::ResolverKernel for Kernel {
9992 type Cert = crate::enforcement::GroundingCertificate;
9993 const KIND: crate::enforcement::CertificateKind =
9994 crate::enforcement::CertificateKind::ResidualVerdict;
9995 }
9996
9997 pub fn certify<
10003 T: crate::pipeline::ConstrainedTypeShape,
10004 P: crate::enforcement::ValidationPhase,
10005 H: crate::enforcement::Hasher,
10006 >(
10007 input: &Validated<T, P>,
10008 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10009 {
10010 certify_at::<T, P, H>(input, WittLevel::W32)
10011 }
10012
10013 pub fn certify_at<
10019 T: crate::pipeline::ConstrainedTypeShape,
10020 P: crate::enforcement::ValidationPhase,
10021 H: crate::enforcement::Hasher,
10022 >(
10023 input: &Validated<T, P>,
10024 level: WittLevel,
10025 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10026 {
10027 let _ = input.inner();
10028 let witt_bits = level.witt_length() as u16;
10029 let (tr_bits, tr_constraints, tr_sat) =
10030 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10031 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10032 if tr_sat == 0 {
10033 return Err(Certified::new(GenericImpossibilityWitness::default()));
10034 }
10035 let mut hasher = H::initial();
10036 hasher = crate::enforcement::fold_terminal_reduction(
10037 hasher,
10038 tr_bits,
10039 tr_constraints,
10040 tr_sat,
10041 );
10042 hasher = crate::enforcement::fold_unit_digest(
10043 hasher,
10044 witt_bits,
10045 witt_bits as u64,
10046 T::IRI,
10047 T::SITE_COUNT,
10048 T::CONSTRAINTS,
10049 <Kernel as super::ResolverKernel>::KIND,
10050 );
10051 let buffer = hasher.finalize();
10052 let fp =
10053 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10054 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10055 Ok(Certified::new(cert))
10056 }
10057 }
10058
10059 pub mod canonical_form {
10077 use super::*;
10078
10079 #[doc(hidden)]
10080 pub struct Kernel;
10081 impl super::ResolverKernel for Kernel {
10082 type Cert = crate::enforcement::TransformCertificate;
10083 const KIND: crate::enforcement::CertificateKind =
10084 crate::enforcement::CertificateKind::CanonicalForm;
10085 }
10086
10087 pub fn certify<
10093 T: crate::pipeline::ConstrainedTypeShape,
10094 P: crate::enforcement::ValidationPhase,
10095 H: crate::enforcement::Hasher,
10096 >(
10097 input: &Validated<T, P>,
10098 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10099 {
10100 certify_at::<T, P, H>(input, WittLevel::W32)
10101 }
10102
10103 pub fn certify_at<
10109 T: crate::pipeline::ConstrainedTypeShape,
10110 P: crate::enforcement::ValidationPhase,
10111 H: crate::enforcement::Hasher,
10112 >(
10113 input: &Validated<T, P>,
10114 level: WittLevel,
10115 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10116 {
10117 let _ = input.inner();
10118 let witt_bits = level.witt_length() as u16;
10119 let (tr_bits, tr_constraints, tr_sat) =
10120 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10121 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10122 if tr_sat == 0 {
10123 return Err(Certified::new(GenericImpossibilityWitness::default()));
10124 }
10125 let mut hasher = H::initial();
10126 hasher = crate::enforcement::fold_terminal_reduction(
10127 hasher,
10128 tr_bits,
10129 tr_constraints,
10130 tr_sat,
10131 );
10132 let (tr2_bits, tr2_constraints, tr2_sat) =
10133 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10134 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10135 if tr2_bits != tr_bits || tr2_constraints != tr_constraints || tr2_sat != tr_sat {
10137 return Err(Certified::new(GenericImpossibilityWitness::default()));
10138 }
10139 hasher = crate::enforcement::fold_terminal_reduction(
10140 hasher,
10141 tr2_bits,
10142 tr2_constraints,
10143 tr2_sat,
10144 );
10145 hasher = crate::enforcement::fold_unit_digest(
10146 hasher,
10147 witt_bits,
10148 witt_bits as u64,
10149 T::IRI,
10150 T::SITE_COUNT,
10151 T::CONSTRAINTS,
10152 <Kernel as super::ResolverKernel>::KIND,
10153 );
10154 let buffer = hasher.finalize();
10155 let fp =
10156 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10157 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10158 Ok(Certified::new(cert))
10159 }
10160 }
10161
10162 pub mod type_synthesis {
10180 use super::*;
10181
10182 #[doc(hidden)]
10183 pub struct Kernel;
10184 impl super::ResolverKernel for Kernel {
10185 type Cert = crate::enforcement::TransformCertificate;
10186 const KIND: crate::enforcement::CertificateKind =
10187 crate::enforcement::CertificateKind::TypeSynthesis;
10188 }
10189
10190 pub fn certify<
10196 T: crate::pipeline::ConstrainedTypeShape,
10197 P: crate::enforcement::ValidationPhase,
10198 H: crate::enforcement::Hasher,
10199 >(
10200 input: &Validated<T, P>,
10201 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10202 {
10203 certify_at::<T, P, H>(input, WittLevel::W32)
10204 }
10205
10206 pub fn certify_at<
10212 T: crate::pipeline::ConstrainedTypeShape,
10213 P: crate::enforcement::ValidationPhase,
10214 H: crate::enforcement::Hasher,
10215 >(
10216 input: &Validated<T, P>,
10217 level: WittLevel,
10218 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10219 {
10220 let _ = input.inner();
10221 let witt_bits = level.witt_length() as u16;
10222 let (tr_bits, tr_constraints, tr_sat) =
10223 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10224 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10225 if tr_sat == 0 {
10226 return Err(Certified::new(GenericImpossibilityWitness::default()));
10227 }
10228 let mut hasher = H::initial();
10229 hasher = crate::enforcement::fold_terminal_reduction(
10230 hasher,
10231 tr_bits,
10232 tr_constraints,
10233 tr_sat,
10234 );
10235 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10236 .map_err(crate::enforcement::Certified::new)?;
10237 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
10238 let (residual, entropy) = crate::enforcement::primitive_descent_metrics::<T>(&betti);
10239 hasher = crate::enforcement::fold_descent_metrics(hasher, residual, entropy);
10240 hasher = crate::enforcement::fold_unit_digest(
10241 hasher,
10242 witt_bits,
10243 witt_bits as u64,
10244 T::IRI,
10245 T::SITE_COUNT,
10246 T::CONSTRAINTS,
10247 <Kernel as super::ResolverKernel>::KIND,
10248 );
10249 let buffer = hasher.finalize();
10250 let fp =
10251 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10252 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10253 Ok(Certified::new(cert))
10254 }
10255 }
10256
10257 pub mod homotopy {
10275 use super::*;
10276
10277 #[doc(hidden)]
10278 pub struct Kernel;
10279 impl super::ResolverKernel for Kernel {
10280 type Cert = crate::enforcement::TransformCertificate;
10281 const KIND: crate::enforcement::CertificateKind =
10282 crate::enforcement::CertificateKind::Homotopy;
10283 }
10284
10285 pub fn certify<
10291 T: crate::pipeline::ConstrainedTypeShape,
10292 P: crate::enforcement::ValidationPhase,
10293 H: crate::enforcement::Hasher,
10294 >(
10295 input: &Validated<T, P>,
10296 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10297 {
10298 certify_at::<T, P, H>(input, WittLevel::W32)
10299 }
10300
10301 pub fn certify_at<
10307 T: crate::pipeline::ConstrainedTypeShape,
10308 P: crate::enforcement::ValidationPhase,
10309 H: crate::enforcement::Hasher,
10310 >(
10311 input: &Validated<T, P>,
10312 level: WittLevel,
10313 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10314 {
10315 let _ = input.inner();
10316 let witt_bits = level.witt_length() as u16;
10317 let (tr_bits, tr_constraints, tr_sat) =
10318 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10319 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10320 if tr_sat == 0 {
10321 return Err(Certified::new(GenericImpossibilityWitness::default()));
10322 }
10323 let mut hasher = H::initial();
10324 hasher = crate::enforcement::fold_terminal_reduction(
10325 hasher,
10326 tr_bits,
10327 tr_constraints,
10328 tr_sat,
10329 );
10330 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10331 .map_err(crate::enforcement::Certified::new)?;
10332 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
10333 hasher = crate::enforcement::fold_unit_digest(
10334 hasher,
10335 witt_bits,
10336 witt_bits as u64,
10337 T::IRI,
10338 T::SITE_COUNT,
10339 T::CONSTRAINTS,
10340 <Kernel as super::ResolverKernel>::KIND,
10341 );
10342 let buffer = hasher.finalize();
10343 let fp =
10344 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10345 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10346 Ok(Certified::new(cert))
10347 }
10348 }
10349
10350 pub mod monodromy {
10368 use super::*;
10369
10370 #[doc(hidden)]
10371 pub struct Kernel;
10372 impl super::ResolverKernel for Kernel {
10373 type Cert = crate::enforcement::IsometryCertificate;
10374 const KIND: crate::enforcement::CertificateKind =
10375 crate::enforcement::CertificateKind::Monodromy;
10376 }
10377
10378 pub fn certify<
10384 T: crate::pipeline::ConstrainedTypeShape,
10385 P: crate::enforcement::ValidationPhase,
10386 H: crate::enforcement::Hasher,
10387 >(
10388 input: &Validated<T, P>,
10389 ) -> Result<Certified<IsometryCertificate>, Certified<GenericImpossibilityWitness>>
10390 {
10391 certify_at::<T, P, H>(input, WittLevel::W32)
10392 }
10393
10394 pub fn certify_at<
10400 T: crate::pipeline::ConstrainedTypeShape,
10401 P: crate::enforcement::ValidationPhase,
10402 H: crate::enforcement::Hasher,
10403 >(
10404 input: &Validated<T, P>,
10405 level: WittLevel,
10406 ) -> Result<Certified<IsometryCertificate>, Certified<GenericImpossibilityWitness>>
10407 {
10408 let _ = input.inner();
10409 let witt_bits = level.witt_length() as u16;
10410 let (tr_bits, tr_constraints, tr_sat) =
10411 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10412 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10413 if tr_sat == 0 {
10414 return Err(Certified::new(GenericImpossibilityWitness::default()));
10415 }
10416 let mut hasher = H::initial();
10417 hasher = crate::enforcement::fold_terminal_reduction(
10418 hasher,
10419 tr_bits,
10420 tr_constraints,
10421 tr_sat,
10422 );
10423 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10424 .map_err(crate::enforcement::Certified::new)?;
10425 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
10426 let (orbit_size, representative) =
10427 crate::enforcement::primitive_dihedral_signature::<T>();
10428 hasher =
10429 crate::enforcement::fold_dihedral_signature(hasher, orbit_size, representative);
10430 hasher = crate::enforcement::fold_unit_digest(
10431 hasher,
10432 witt_bits,
10433 witt_bits as u64,
10434 T::IRI,
10435 T::SITE_COUNT,
10436 T::CONSTRAINTS,
10437 <Kernel as super::ResolverKernel>::KIND,
10438 );
10439 let buffer = hasher.finalize();
10440 let fp =
10441 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10442 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10443 Ok(Certified::new(cert))
10444 }
10445 }
10446
10447 pub mod moduli {
10465 use super::*;
10466
10467 #[doc(hidden)]
10468 pub struct Kernel;
10469 impl super::ResolverKernel for Kernel {
10470 type Cert = crate::enforcement::TransformCertificate;
10471 const KIND: crate::enforcement::CertificateKind =
10472 crate::enforcement::CertificateKind::Moduli;
10473 }
10474
10475 pub fn certify<
10481 T: crate::pipeline::ConstrainedTypeShape,
10482 P: crate::enforcement::ValidationPhase,
10483 H: crate::enforcement::Hasher,
10484 >(
10485 input: &Validated<T, P>,
10486 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10487 {
10488 certify_at::<T, P, H>(input, WittLevel::W32)
10489 }
10490
10491 pub fn certify_at<
10497 T: crate::pipeline::ConstrainedTypeShape,
10498 P: crate::enforcement::ValidationPhase,
10499 H: crate::enforcement::Hasher,
10500 >(
10501 input: &Validated<T, P>,
10502 level: WittLevel,
10503 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10504 {
10505 let _ = input.inner();
10506 let witt_bits = level.witt_length() as u16;
10507 let (tr_bits, tr_constraints, tr_sat) =
10508 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10509 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10510 if tr_sat == 0 {
10511 return Err(Certified::new(GenericImpossibilityWitness::default()));
10512 }
10513 let mut hasher = H::initial();
10514 hasher = crate::enforcement::fold_terminal_reduction(
10515 hasher,
10516 tr_bits,
10517 tr_constraints,
10518 tr_sat,
10519 );
10520 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10521 .map_err(crate::enforcement::Certified::new)?;
10522 let automorphisms: u32 = betti[0];
10523 let deformations: u32 = if crate::enforcement::MAX_BETTI_DIMENSION > 1 {
10524 betti[1]
10525 } else {
10526 0
10527 };
10528 let obstructions: u32 = if crate::enforcement::MAX_BETTI_DIMENSION > 2 {
10529 betti[2]
10530 } else {
10531 0
10532 };
10533 hasher = hasher.fold_bytes(&automorphisms.to_be_bytes());
10534 hasher = hasher.fold_bytes(&deformations.to_be_bytes());
10535 hasher = hasher.fold_bytes(&obstructions.to_be_bytes());
10536 hasher = crate::enforcement::fold_unit_digest(
10537 hasher,
10538 witt_bits,
10539 witt_bits as u64,
10540 T::IRI,
10541 T::SITE_COUNT,
10542 T::CONSTRAINTS,
10543 <Kernel as super::ResolverKernel>::KIND,
10544 );
10545 let buffer = hasher.finalize();
10546 let fp =
10547 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10548 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10549 Ok(Certified::new(cert))
10550 }
10551 }
10552
10553 pub mod jacobian_guided {
10571 use super::*;
10572
10573 #[doc(hidden)]
10574 pub struct Kernel;
10575 impl super::ResolverKernel for Kernel {
10576 type Cert = crate::enforcement::GroundingCertificate;
10577 const KIND: crate::enforcement::CertificateKind =
10578 crate::enforcement::CertificateKind::JacobianGuided;
10579 }
10580
10581 pub fn certify<
10587 T: crate::pipeline::ConstrainedTypeShape,
10588 P: crate::enforcement::ValidationPhase,
10589 H: crate::enforcement::Hasher,
10590 >(
10591 input: &Validated<T, P>,
10592 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10593 {
10594 certify_at::<T, P, H>(input, WittLevel::W32)
10595 }
10596
10597 pub fn certify_at<
10603 T: crate::pipeline::ConstrainedTypeShape,
10604 P: crate::enforcement::ValidationPhase,
10605 H: crate::enforcement::Hasher,
10606 >(
10607 input: &Validated<T, P>,
10608 level: WittLevel,
10609 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10610 {
10611 let _ = input.inner();
10612 let witt_bits = level.witt_length() as u16;
10613 let (tr_bits, tr_constraints, tr_sat) =
10614 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10615 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10616 if tr_sat == 0 {
10617 return Err(Certified::new(GenericImpossibilityWitness::default()));
10618 }
10619 let mut hasher = H::initial();
10620 hasher = crate::enforcement::fold_terminal_reduction(
10621 hasher,
10622 tr_bits,
10623 tr_constraints,
10624 tr_sat,
10625 );
10626 let jac = crate::enforcement::primitive_curvature_jacobian::<T>();
10627 hasher = crate::enforcement::fold_jacobian_profile(hasher, &jac);
10628 let selected_site = crate::enforcement::primitive_dc10_select(&jac);
10629 hasher = hasher.fold_bytes(&(selected_site as u32).to_be_bytes());
10630 hasher = crate::enforcement::fold_unit_digest(
10631 hasher,
10632 witt_bits,
10633 witt_bits as u64,
10634 T::IRI,
10635 T::SITE_COUNT,
10636 T::CONSTRAINTS,
10637 <Kernel as super::ResolverKernel>::KIND,
10638 );
10639 let buffer = hasher.finalize();
10640 let fp =
10641 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10642 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10643 Ok(Certified::new(cert))
10644 }
10645 }
10646
10647 pub mod evaluation {
10665 use super::*;
10666
10667 #[doc(hidden)]
10668 pub struct Kernel;
10669 impl super::ResolverKernel for Kernel {
10670 type Cert = crate::enforcement::GroundingCertificate;
10671 const KIND: crate::enforcement::CertificateKind =
10672 crate::enforcement::CertificateKind::Evaluation;
10673 }
10674
10675 pub fn certify<
10681 T: crate::pipeline::ConstrainedTypeShape,
10682 P: crate::enforcement::ValidationPhase,
10683 H: crate::enforcement::Hasher,
10684 >(
10685 input: &Validated<T, P>,
10686 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10687 {
10688 certify_at::<T, P, H>(input, WittLevel::W32)
10689 }
10690
10691 pub fn certify_at<
10697 T: crate::pipeline::ConstrainedTypeShape,
10698 P: crate::enforcement::ValidationPhase,
10699 H: crate::enforcement::Hasher,
10700 >(
10701 input: &Validated<T, P>,
10702 level: WittLevel,
10703 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10704 {
10705 let _ = input.inner();
10706 let witt_bits = level.witt_length() as u16;
10707 let (tr_bits, tr_constraints, tr_sat) =
10708 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10709 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10710 if tr_sat == 0 {
10711 return Err(Certified::new(GenericImpossibilityWitness::default()));
10712 }
10713 let mut hasher = H::initial();
10714 hasher = crate::enforcement::fold_terminal_reduction(
10715 hasher,
10716 tr_bits,
10717 tr_constraints,
10718 tr_sat,
10719 );
10720 hasher = crate::enforcement::fold_unit_digest(
10721 hasher,
10722 witt_bits,
10723 witt_bits as u64,
10724 T::IRI,
10725 T::SITE_COUNT,
10726 T::CONSTRAINTS,
10727 <Kernel as super::ResolverKernel>::KIND,
10728 );
10729 let buffer = hasher.finalize();
10730 let fp =
10731 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10732 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10733 Ok(Certified::new(cert))
10734 }
10735 }
10736
10737 pub mod session {
10755 use super::*;
10756
10757 #[doc(hidden)]
10758 pub struct Kernel;
10759 impl super::ResolverKernel for Kernel {
10760 type Cert = crate::enforcement::GroundingCertificate;
10761 const KIND: crate::enforcement::CertificateKind =
10762 crate::enforcement::CertificateKind::Session;
10763 }
10764
10765 pub fn certify<
10771 P: crate::enforcement::ValidationPhase,
10772 H: crate::enforcement::Hasher,
10773 const INLINE_BYTES: usize,
10774 >(
10775 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10776 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10777 {
10778 certify_at::<P, H, INLINE_BYTES>(input, WittLevel::W32)
10779 }
10780
10781 pub fn certify_at<
10787 P: crate::enforcement::ValidationPhase,
10788 H: crate::enforcement::Hasher,
10789 const INLINE_BYTES: usize,
10790 >(
10791 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10792 level: WittLevel,
10793 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10794 {
10795 let unit = input.inner();
10796 let witt_bits = level.witt_length() as u16;
10797 let budget = unit.thermodynamic_budget();
10798 let result_type_iri = unit.result_type_iri();
10799 let mut hasher = H::initial();
10800 let (binding_count, fold_addr) =
10801 crate::enforcement::primitive_session_binding_signature(unit.bindings());
10802 hasher = crate::enforcement::fold_session_signature(hasher, binding_count, fold_addr);
10803 hasher = crate::enforcement::fold_unit_digest(
10804 hasher,
10805 witt_bits,
10806 budget,
10807 result_type_iri,
10808 0usize,
10809 &[],
10810 <Kernel as super::ResolverKernel>::KIND,
10811 );
10812 let buffer = hasher.finalize();
10813 let fp =
10814 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10815 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10816 Ok(Certified::new(cert))
10817 }
10818 }
10819
10820 pub mod superposition {
10838 use super::*;
10839
10840 #[doc(hidden)]
10841 pub struct Kernel;
10842 impl super::ResolverKernel for Kernel {
10843 type Cert = crate::enforcement::BornRuleVerification;
10844 const KIND: crate::enforcement::CertificateKind =
10845 crate::enforcement::CertificateKind::Superposition;
10846 }
10847
10848 pub fn certify<
10854 P: crate::enforcement::ValidationPhase,
10855 H: crate::enforcement::Hasher,
10856 const INLINE_BYTES: usize,
10857 >(
10858 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10859 ) -> Result<Certified<BornRuleVerification>, Certified<GenericImpossibilityWitness>>
10860 {
10861 certify_at::<P, H, INLINE_BYTES>(input, WittLevel::W32)
10862 }
10863
10864 pub fn certify_at<
10870 P: crate::enforcement::ValidationPhase,
10871 H: crate::enforcement::Hasher,
10872 const INLINE_BYTES: usize,
10873 >(
10874 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10875 level: WittLevel,
10876 ) -> Result<Certified<BornRuleVerification>, Certified<GenericImpossibilityWitness>>
10877 {
10878 let unit = input.inner();
10879 let witt_bits = level.witt_length() as u16;
10880 let budget = unit.thermodynamic_budget();
10881 let result_type_iri = unit.result_type_iri();
10882 let mut hasher = H::initial();
10883 let (binding_count, fold_addr) =
10884 crate::enforcement::primitive_session_binding_signature(unit.bindings());
10885 hasher = crate::enforcement::fold_session_signature(hasher, binding_count, fold_addr);
10886 let (outcome_index, probability) =
10887 crate::enforcement::primitive_measurement_projection(budget);
10888 hasher = crate::enforcement::fold_born_outcome(hasher, outcome_index, probability);
10889 hasher = crate::enforcement::fold_unit_digest(
10890 hasher,
10891 witt_bits,
10892 budget,
10893 result_type_iri,
10894 0usize,
10895 &[],
10896 <Kernel as super::ResolverKernel>::KIND,
10897 );
10898 let buffer = hasher.finalize();
10899 let fp =
10900 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10901 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10902 Ok(Certified::new(cert))
10903 }
10904 }
10905
10906 pub mod measurement {
10924 use super::*;
10925
10926 #[doc(hidden)]
10927 pub struct Kernel;
10928 impl super::ResolverKernel for Kernel {
10929 type Cert = crate::enforcement::MeasurementCertificate;
10930 const KIND: crate::enforcement::CertificateKind =
10931 crate::enforcement::CertificateKind::Measurement;
10932 }
10933
10934 pub fn certify<
10940 P: crate::enforcement::ValidationPhase,
10941 H: crate::enforcement::Hasher,
10942 const INLINE_BYTES: usize,
10943 >(
10944 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10945 ) -> Result<Certified<MeasurementCertificate>, Certified<GenericImpossibilityWitness>>
10946 {
10947 certify_at::<P, H, INLINE_BYTES>(input, WittLevel::W32)
10948 }
10949
10950 pub fn certify_at<
10956 P: crate::enforcement::ValidationPhase,
10957 H: crate::enforcement::Hasher,
10958 const INLINE_BYTES: usize,
10959 >(
10960 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10961 level: WittLevel,
10962 ) -> Result<Certified<MeasurementCertificate>, Certified<GenericImpossibilityWitness>>
10963 {
10964 let unit = input.inner();
10965 let witt_bits = level.witt_length() as u16;
10966 let budget = unit.thermodynamic_budget();
10967 let result_type_iri = unit.result_type_iri();
10968 let mut hasher = H::initial();
10969 let (outcome_index, probability) =
10970 crate::enforcement::primitive_measurement_projection(budget);
10971 hasher = crate::enforcement::fold_born_outcome(hasher, outcome_index, probability);
10972 hasher = crate::enforcement::fold_unit_digest(
10973 hasher,
10974 witt_bits,
10975 budget,
10976 result_type_iri,
10977 0usize,
10978 &[],
10979 <Kernel as super::ResolverKernel>::KIND,
10980 );
10981 let buffer = hasher.finalize();
10982 let fp =
10983 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10984 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10985 Ok(Certified::new(cert))
10986 }
10987 }
10988
10989 pub mod witt_level_resolver {
11007 use super::*;
11008
11009 #[doc(hidden)]
11010 pub struct Kernel;
11011 impl super::ResolverKernel for Kernel {
11012 type Cert = crate::enforcement::GroundingCertificate;
11013 const KIND: crate::enforcement::CertificateKind =
11014 crate::enforcement::CertificateKind::WittLevel;
11015 }
11016
11017 pub fn certify<
11023 P: crate::enforcement::ValidationPhase,
11024 H: crate::enforcement::Hasher,
11025 const INLINE_BYTES: usize,
11026 >(
11027 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
11028 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
11029 {
11030 certify_at::<P, H, INLINE_BYTES>(input, WittLevel::W32)
11031 }
11032
11033 pub fn certify_at<
11039 P: crate::enforcement::ValidationPhase,
11040 H: crate::enforcement::Hasher,
11041 const INLINE_BYTES: usize,
11042 >(
11043 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
11044 level: WittLevel,
11045 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
11046 {
11047 let unit = input.inner();
11048 let witt_bits = level.witt_length() as u16;
11049 let budget = unit.thermodynamic_budget();
11050 let result_type_iri = unit.result_type_iri();
11051 let mut hasher = H::initial();
11052 hasher = hasher.fold_bytes(&witt_bits.to_be_bytes());
11053 let declared_level_bits = unit.witt_level().witt_length() as u16;
11054 hasher = hasher.fold_bytes(&declared_level_bits.to_be_bytes());
11055 hasher = crate::enforcement::fold_unit_digest(
11056 hasher,
11057 witt_bits,
11058 budget,
11059 result_type_iri,
11060 0usize,
11061 &[],
11062 <Kernel as super::ResolverKernel>::KIND,
11063 );
11064 let buffer = hasher.finalize();
11065 let fp =
11066 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11067 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11068 Ok(Certified::new(cert))
11069 }
11070 }
11071
11072 pub mod dihedral_factorization {
11090 use super::*;
11091
11092 #[doc(hidden)]
11093 pub struct Kernel;
11094 impl super::ResolverKernel for Kernel {
11095 type Cert = crate::enforcement::InvolutionCertificate;
11096 const KIND: crate::enforcement::CertificateKind =
11097 crate::enforcement::CertificateKind::DihedralFactorization;
11098 }
11099
11100 pub fn certify<
11106 T: crate::pipeline::ConstrainedTypeShape,
11107 P: crate::enforcement::ValidationPhase,
11108 H: crate::enforcement::Hasher,
11109 >(
11110 input: &Validated<T, P>,
11111 ) -> Result<Certified<InvolutionCertificate>, Certified<GenericImpossibilityWitness>>
11112 {
11113 certify_at::<T, P, H>(input, WittLevel::W32)
11114 }
11115
11116 pub fn certify_at<
11122 T: crate::pipeline::ConstrainedTypeShape,
11123 P: crate::enforcement::ValidationPhase,
11124 H: crate::enforcement::Hasher,
11125 >(
11126 input: &Validated<T, P>,
11127 level: WittLevel,
11128 ) -> Result<Certified<InvolutionCertificate>, Certified<GenericImpossibilityWitness>>
11129 {
11130 let _ = input.inner();
11131 let witt_bits = level.witt_length() as u16;
11132 let (tr_bits, tr_constraints, tr_sat) =
11133 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
11134 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
11135 if tr_sat == 0 {
11136 return Err(Certified::new(GenericImpossibilityWitness::default()));
11137 }
11138 let mut hasher = H::initial();
11139 hasher = crate::enforcement::fold_terminal_reduction(
11140 hasher,
11141 tr_bits,
11142 tr_constraints,
11143 tr_sat,
11144 );
11145 let (orbit_size, representative) =
11146 crate::enforcement::primitive_dihedral_signature::<T>();
11147 hasher =
11148 crate::enforcement::fold_dihedral_signature(hasher, orbit_size, representative);
11149 hasher = crate::enforcement::fold_unit_digest(
11150 hasher,
11151 witt_bits,
11152 witt_bits as u64,
11153 T::IRI,
11154 T::SITE_COUNT,
11155 T::CONSTRAINTS,
11156 <Kernel as super::ResolverKernel>::KIND,
11157 );
11158 let buffer = hasher.finalize();
11159 let fp =
11160 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11161 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11162 Ok(Certified::new(cert))
11163 }
11164 }
11165
11166 pub mod completeness {
11184 use super::*;
11185
11186 #[doc(hidden)]
11187 pub struct Kernel;
11188 impl super::ResolverKernel for Kernel {
11189 type Cert = crate::enforcement::CompletenessCertificate;
11190 const KIND: crate::enforcement::CertificateKind =
11191 crate::enforcement::CertificateKind::Completeness;
11192 }
11193
11194 pub fn certify<
11200 T: crate::pipeline::ConstrainedTypeShape,
11201 P: crate::enforcement::ValidationPhase,
11202 H: crate::enforcement::Hasher,
11203 >(
11204 input: &Validated<T, P>,
11205 ) -> Result<Certified<CompletenessCertificate>, Certified<GenericImpossibilityWitness>>
11206 {
11207 certify_at::<T, P, H>(input, WittLevel::W32)
11208 }
11209
11210 pub fn certify_at<
11216 T: crate::pipeline::ConstrainedTypeShape,
11217 P: crate::enforcement::ValidationPhase,
11218 H: crate::enforcement::Hasher,
11219 >(
11220 input: &Validated<T, P>,
11221 level: WittLevel,
11222 ) -> Result<Certified<CompletenessCertificate>, Certified<GenericImpossibilityWitness>>
11223 {
11224 let _ = input.inner();
11225 let witt_bits = level.witt_length() as u16;
11226 let (tr_bits, tr_constraints, tr_sat) =
11227 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
11228 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
11229 if tr_sat == 0 {
11230 return Err(Certified::new(GenericImpossibilityWitness::default()));
11231 }
11232 let mut hasher = H::initial();
11233 hasher = crate::enforcement::fold_terminal_reduction(
11234 hasher,
11235 tr_bits,
11236 tr_constraints,
11237 tr_sat,
11238 );
11239 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
11240 .map_err(crate::enforcement::Certified::new)?;
11241 let chi = crate::enforcement::primitive_euler_characteristic(&betti);
11242 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
11243 hasher = hasher.fold_bytes(&chi.to_be_bytes());
11244 hasher = crate::enforcement::fold_unit_digest(
11245 hasher,
11246 witt_bits,
11247 witt_bits as u64,
11248 T::IRI,
11249 T::SITE_COUNT,
11250 T::CONSTRAINTS,
11251 <Kernel as super::ResolverKernel>::KIND,
11252 );
11253 let buffer = hasher.finalize();
11254 let fp =
11255 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11256 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11257 Ok(Certified::new(cert))
11258 }
11259 }
11260
11261 pub mod geodesic_validator {
11279 use super::*;
11280
11281 #[doc(hidden)]
11282 pub struct Kernel;
11283 impl super::ResolverKernel for Kernel {
11284 type Cert = crate::enforcement::GeodesicCertificate;
11285 const KIND: crate::enforcement::CertificateKind =
11286 crate::enforcement::CertificateKind::GeodesicValidator;
11287 }
11288
11289 pub fn certify<
11295 T: crate::pipeline::ConstrainedTypeShape,
11296 P: crate::enforcement::ValidationPhase,
11297 H: crate::enforcement::Hasher,
11298 >(
11299 input: &Validated<T, P>,
11300 ) -> Result<Certified<GeodesicCertificate>, Certified<GenericImpossibilityWitness>>
11301 {
11302 certify_at::<T, P, H>(input, WittLevel::W32)
11303 }
11304
11305 pub fn certify_at<
11311 T: crate::pipeline::ConstrainedTypeShape,
11312 P: crate::enforcement::ValidationPhase,
11313 H: crate::enforcement::Hasher,
11314 >(
11315 input: &Validated<T, P>,
11316 level: WittLevel,
11317 ) -> Result<Certified<GeodesicCertificate>, Certified<GenericImpossibilityWitness>>
11318 {
11319 let _ = input.inner();
11320 let witt_bits = level.witt_length() as u16;
11321 let (tr_bits, tr_constraints, tr_sat) =
11322 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
11323 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
11324 if tr_sat == 0 {
11325 return Err(Certified::new(GenericImpossibilityWitness::default()));
11326 }
11327 let mut hasher = H::initial();
11328 hasher = crate::enforcement::fold_terminal_reduction(
11329 hasher,
11330 tr_bits,
11331 tr_constraints,
11332 tr_sat,
11333 );
11334 let jac = crate::enforcement::primitive_curvature_jacobian::<T>();
11335 hasher = crate::enforcement::fold_jacobian_profile(hasher, &jac);
11336 let selected_site = crate::enforcement::primitive_dc10_select(&jac);
11337 hasher = hasher.fold_bytes(&(selected_site as u32).to_be_bytes());
11338 hasher = crate::enforcement::fold_unit_digest(
11339 hasher,
11340 witt_bits,
11341 witt_bits as u64,
11342 T::IRI,
11343 T::SITE_COUNT,
11344 T::CONSTRAINTS,
11345 <Kernel as super::ResolverKernel>::KIND,
11346 );
11347 let buffer = hasher.finalize();
11348 let fp =
11349 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11350 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11351 Ok(Certified::new(cert))
11352 }
11353 }
11354}
11355
11356pub trait RingOp<L> {
11360 type Operand;
11362 fn apply(a: Self::Operand, b: Self::Operand) -> Self::Operand;
11364}
11365
11366pub trait UnaryRingOp<L> {
11370 type Operand;
11372 fn apply(a: Self::Operand) -> Self::Operand;
11374}
11375
11376#[derive(Debug, Default, Clone, Copy)]
11378pub struct Mul<L>(PhantomData<L>);
11379
11380#[derive(Debug, Default, Clone, Copy)]
11382pub struct Add<L>(PhantomData<L>);
11383
11384#[derive(Debug, Default, Clone, Copy)]
11386pub struct Sub<L>(PhantomData<L>);
11387
11388#[derive(Debug, Default, Clone, Copy)]
11390pub struct Xor<L>(PhantomData<L>);
11391
11392#[derive(Debug, Default, Clone, Copy)]
11394pub struct And<L>(PhantomData<L>);
11395
11396#[derive(Debug, Default, Clone, Copy)]
11398pub struct Or<L>(PhantomData<L>);
11399
11400#[derive(Debug, Default, Clone, Copy)]
11402pub struct Neg<L>(PhantomData<L>);
11403
11404#[derive(Debug, Default, Clone, Copy)]
11406pub struct BNot<L>(PhantomData<L>);
11407
11408#[derive(Debug, Default, Clone, Copy)]
11410pub struct Succ<L>(PhantomData<L>);
11411
11412#[derive(Debug, Default, Clone, Copy)]
11414pub struct W8;
11415
11416#[derive(Debug, Default, Clone, Copy)]
11418pub struct W16;
11419
11420#[derive(Debug, Default, Clone, Copy)]
11422pub struct W24;
11423
11424#[derive(Debug, Default, Clone, Copy)]
11426pub struct W32;
11427
11428#[derive(Debug, Default, Clone, Copy)]
11430pub struct W40;
11431
11432#[derive(Debug, Default, Clone, Copy)]
11434pub struct W48;
11435
11436#[derive(Debug, Default, Clone, Copy)]
11438pub struct W56;
11439
11440#[derive(Debug, Default, Clone, Copy)]
11442pub struct W64;
11443
11444#[derive(Debug, Default, Clone, Copy)]
11446pub struct W72;
11447
11448#[derive(Debug, Default, Clone, Copy)]
11450pub struct W80;
11451
11452#[derive(Debug, Default, Clone, Copy)]
11454pub struct W88;
11455
11456#[derive(Debug, Default, Clone, Copy)]
11458pub struct W96;
11459
11460#[derive(Debug, Default, Clone, Copy)]
11462pub struct W104;
11463
11464#[derive(Debug, Default, Clone, Copy)]
11466pub struct W112;
11467
11468#[derive(Debug, Default, Clone, Copy)]
11470pub struct W120;
11471
11472#[derive(Debug, Default, Clone, Copy)]
11474pub struct W128;
11475
11476impl RingOp<W8> for Mul<W8> {
11477 type Operand = u8;
11478 #[inline]
11479 fn apply(a: u8, b: u8) -> u8 {
11480 const_ring_eval_w8(PrimitiveOp::Mul, a, b)
11481 }
11482}
11483
11484impl RingOp<W8> for Add<W8> {
11485 type Operand = u8;
11486 #[inline]
11487 fn apply(a: u8, b: u8) -> u8 {
11488 const_ring_eval_w8(PrimitiveOp::Add, a, b)
11489 }
11490}
11491
11492impl RingOp<W8> for Sub<W8> {
11493 type Operand = u8;
11494 #[inline]
11495 fn apply(a: u8, b: u8) -> u8 {
11496 const_ring_eval_w8(PrimitiveOp::Sub, a, b)
11497 }
11498}
11499
11500impl RingOp<W8> for Xor<W8> {
11501 type Operand = u8;
11502 #[inline]
11503 fn apply(a: u8, b: u8) -> u8 {
11504 const_ring_eval_w8(PrimitiveOp::Xor, a, b)
11505 }
11506}
11507
11508impl RingOp<W8> for And<W8> {
11509 type Operand = u8;
11510 #[inline]
11511 fn apply(a: u8, b: u8) -> u8 {
11512 const_ring_eval_w8(PrimitiveOp::And, a, b)
11513 }
11514}
11515
11516impl RingOp<W8> for Or<W8> {
11517 type Operand = u8;
11518 #[inline]
11519 fn apply(a: u8, b: u8) -> u8 {
11520 const_ring_eval_w8(PrimitiveOp::Or, a, b)
11521 }
11522}
11523
11524impl RingOp<W16> for Mul<W16> {
11525 type Operand = u16;
11526 #[inline]
11527 fn apply(a: u16, b: u16) -> u16 {
11528 const_ring_eval_w16(PrimitiveOp::Mul, a, b)
11529 }
11530}
11531
11532impl RingOp<W16> for Add<W16> {
11533 type Operand = u16;
11534 #[inline]
11535 fn apply(a: u16, b: u16) -> u16 {
11536 const_ring_eval_w16(PrimitiveOp::Add, a, b)
11537 }
11538}
11539
11540impl RingOp<W16> for Sub<W16> {
11541 type Operand = u16;
11542 #[inline]
11543 fn apply(a: u16, b: u16) -> u16 {
11544 const_ring_eval_w16(PrimitiveOp::Sub, a, b)
11545 }
11546}
11547
11548impl RingOp<W16> for Xor<W16> {
11549 type Operand = u16;
11550 #[inline]
11551 fn apply(a: u16, b: u16) -> u16 {
11552 const_ring_eval_w16(PrimitiveOp::Xor, a, b)
11553 }
11554}
11555
11556impl RingOp<W16> for And<W16> {
11557 type Operand = u16;
11558 #[inline]
11559 fn apply(a: u16, b: u16) -> u16 {
11560 const_ring_eval_w16(PrimitiveOp::And, a, b)
11561 }
11562}
11563
11564impl RingOp<W16> for Or<W16> {
11565 type Operand = u16;
11566 #[inline]
11567 fn apply(a: u16, b: u16) -> u16 {
11568 const_ring_eval_w16(PrimitiveOp::Or, a, b)
11569 }
11570}
11571
11572impl RingOp<W24> for Mul<W24> {
11573 type Operand = u32;
11574 #[inline]
11575 fn apply(a: u32, b: u32) -> u32 {
11576 const_ring_eval_w24(PrimitiveOp::Mul, a, b)
11577 }
11578}
11579
11580impl RingOp<W24> for Add<W24> {
11581 type Operand = u32;
11582 #[inline]
11583 fn apply(a: u32, b: u32) -> u32 {
11584 const_ring_eval_w24(PrimitiveOp::Add, a, b)
11585 }
11586}
11587
11588impl RingOp<W24> for Sub<W24> {
11589 type Operand = u32;
11590 #[inline]
11591 fn apply(a: u32, b: u32) -> u32 {
11592 const_ring_eval_w24(PrimitiveOp::Sub, a, b)
11593 }
11594}
11595
11596impl RingOp<W24> for Xor<W24> {
11597 type Operand = u32;
11598 #[inline]
11599 fn apply(a: u32, b: u32) -> u32 {
11600 const_ring_eval_w24(PrimitiveOp::Xor, a, b)
11601 }
11602}
11603
11604impl RingOp<W24> for And<W24> {
11605 type Operand = u32;
11606 #[inline]
11607 fn apply(a: u32, b: u32) -> u32 {
11608 const_ring_eval_w24(PrimitiveOp::And, a, b)
11609 }
11610}
11611
11612impl RingOp<W24> for Or<W24> {
11613 type Operand = u32;
11614 #[inline]
11615 fn apply(a: u32, b: u32) -> u32 {
11616 const_ring_eval_w24(PrimitiveOp::Or, a, b)
11617 }
11618}
11619
11620impl RingOp<W32> for Mul<W32> {
11621 type Operand = u32;
11622 #[inline]
11623 fn apply(a: u32, b: u32) -> u32 {
11624 const_ring_eval_w32(PrimitiveOp::Mul, a, b)
11625 }
11626}
11627
11628impl RingOp<W32> for Add<W32> {
11629 type Operand = u32;
11630 #[inline]
11631 fn apply(a: u32, b: u32) -> u32 {
11632 const_ring_eval_w32(PrimitiveOp::Add, a, b)
11633 }
11634}
11635
11636impl RingOp<W32> for Sub<W32> {
11637 type Operand = u32;
11638 #[inline]
11639 fn apply(a: u32, b: u32) -> u32 {
11640 const_ring_eval_w32(PrimitiveOp::Sub, a, b)
11641 }
11642}
11643
11644impl RingOp<W32> for Xor<W32> {
11645 type Operand = u32;
11646 #[inline]
11647 fn apply(a: u32, b: u32) -> u32 {
11648 const_ring_eval_w32(PrimitiveOp::Xor, a, b)
11649 }
11650}
11651
11652impl RingOp<W32> for And<W32> {
11653 type Operand = u32;
11654 #[inline]
11655 fn apply(a: u32, b: u32) -> u32 {
11656 const_ring_eval_w32(PrimitiveOp::And, a, b)
11657 }
11658}
11659
11660impl RingOp<W32> for Or<W32> {
11661 type Operand = u32;
11662 #[inline]
11663 fn apply(a: u32, b: u32) -> u32 {
11664 const_ring_eval_w32(PrimitiveOp::Or, a, b)
11665 }
11666}
11667
11668impl RingOp<W40> for Mul<W40> {
11669 type Operand = u64;
11670 #[inline]
11671 fn apply(a: u64, b: u64) -> u64 {
11672 const_ring_eval_w40(PrimitiveOp::Mul, a, b)
11673 }
11674}
11675
11676impl RingOp<W40> for Add<W40> {
11677 type Operand = u64;
11678 #[inline]
11679 fn apply(a: u64, b: u64) -> u64 {
11680 const_ring_eval_w40(PrimitiveOp::Add, a, b)
11681 }
11682}
11683
11684impl RingOp<W40> for Sub<W40> {
11685 type Operand = u64;
11686 #[inline]
11687 fn apply(a: u64, b: u64) -> u64 {
11688 const_ring_eval_w40(PrimitiveOp::Sub, a, b)
11689 }
11690}
11691
11692impl RingOp<W40> for Xor<W40> {
11693 type Operand = u64;
11694 #[inline]
11695 fn apply(a: u64, b: u64) -> u64 {
11696 const_ring_eval_w40(PrimitiveOp::Xor, a, b)
11697 }
11698}
11699
11700impl RingOp<W40> for And<W40> {
11701 type Operand = u64;
11702 #[inline]
11703 fn apply(a: u64, b: u64) -> u64 {
11704 const_ring_eval_w40(PrimitiveOp::And, a, b)
11705 }
11706}
11707
11708impl RingOp<W40> for Or<W40> {
11709 type Operand = u64;
11710 #[inline]
11711 fn apply(a: u64, b: u64) -> u64 {
11712 const_ring_eval_w40(PrimitiveOp::Or, a, b)
11713 }
11714}
11715
11716impl RingOp<W48> for Mul<W48> {
11717 type Operand = u64;
11718 #[inline]
11719 fn apply(a: u64, b: u64) -> u64 {
11720 const_ring_eval_w48(PrimitiveOp::Mul, a, b)
11721 }
11722}
11723
11724impl RingOp<W48> for Add<W48> {
11725 type Operand = u64;
11726 #[inline]
11727 fn apply(a: u64, b: u64) -> u64 {
11728 const_ring_eval_w48(PrimitiveOp::Add, a, b)
11729 }
11730}
11731
11732impl RingOp<W48> for Sub<W48> {
11733 type Operand = u64;
11734 #[inline]
11735 fn apply(a: u64, b: u64) -> u64 {
11736 const_ring_eval_w48(PrimitiveOp::Sub, a, b)
11737 }
11738}
11739
11740impl RingOp<W48> for Xor<W48> {
11741 type Operand = u64;
11742 #[inline]
11743 fn apply(a: u64, b: u64) -> u64 {
11744 const_ring_eval_w48(PrimitiveOp::Xor, a, b)
11745 }
11746}
11747
11748impl RingOp<W48> for And<W48> {
11749 type Operand = u64;
11750 #[inline]
11751 fn apply(a: u64, b: u64) -> u64 {
11752 const_ring_eval_w48(PrimitiveOp::And, a, b)
11753 }
11754}
11755
11756impl RingOp<W48> for Or<W48> {
11757 type Operand = u64;
11758 #[inline]
11759 fn apply(a: u64, b: u64) -> u64 {
11760 const_ring_eval_w48(PrimitiveOp::Or, a, b)
11761 }
11762}
11763
11764impl RingOp<W56> for Mul<W56> {
11765 type Operand = u64;
11766 #[inline]
11767 fn apply(a: u64, b: u64) -> u64 {
11768 const_ring_eval_w56(PrimitiveOp::Mul, a, b)
11769 }
11770}
11771
11772impl RingOp<W56> for Add<W56> {
11773 type Operand = u64;
11774 #[inline]
11775 fn apply(a: u64, b: u64) -> u64 {
11776 const_ring_eval_w56(PrimitiveOp::Add, a, b)
11777 }
11778}
11779
11780impl RingOp<W56> for Sub<W56> {
11781 type Operand = u64;
11782 #[inline]
11783 fn apply(a: u64, b: u64) -> u64 {
11784 const_ring_eval_w56(PrimitiveOp::Sub, a, b)
11785 }
11786}
11787
11788impl RingOp<W56> for Xor<W56> {
11789 type Operand = u64;
11790 #[inline]
11791 fn apply(a: u64, b: u64) -> u64 {
11792 const_ring_eval_w56(PrimitiveOp::Xor, a, b)
11793 }
11794}
11795
11796impl RingOp<W56> for And<W56> {
11797 type Operand = u64;
11798 #[inline]
11799 fn apply(a: u64, b: u64) -> u64 {
11800 const_ring_eval_w56(PrimitiveOp::And, a, b)
11801 }
11802}
11803
11804impl RingOp<W56> for Or<W56> {
11805 type Operand = u64;
11806 #[inline]
11807 fn apply(a: u64, b: u64) -> u64 {
11808 const_ring_eval_w56(PrimitiveOp::Or, a, b)
11809 }
11810}
11811
11812impl RingOp<W64> for Mul<W64> {
11813 type Operand = u64;
11814 #[inline]
11815 fn apply(a: u64, b: u64) -> u64 {
11816 const_ring_eval_w64(PrimitiveOp::Mul, a, b)
11817 }
11818}
11819
11820impl RingOp<W64> for Add<W64> {
11821 type Operand = u64;
11822 #[inline]
11823 fn apply(a: u64, b: u64) -> u64 {
11824 const_ring_eval_w64(PrimitiveOp::Add, a, b)
11825 }
11826}
11827
11828impl RingOp<W64> for Sub<W64> {
11829 type Operand = u64;
11830 #[inline]
11831 fn apply(a: u64, b: u64) -> u64 {
11832 const_ring_eval_w64(PrimitiveOp::Sub, a, b)
11833 }
11834}
11835
11836impl RingOp<W64> for Xor<W64> {
11837 type Operand = u64;
11838 #[inline]
11839 fn apply(a: u64, b: u64) -> u64 {
11840 const_ring_eval_w64(PrimitiveOp::Xor, a, b)
11841 }
11842}
11843
11844impl RingOp<W64> for And<W64> {
11845 type Operand = u64;
11846 #[inline]
11847 fn apply(a: u64, b: u64) -> u64 {
11848 const_ring_eval_w64(PrimitiveOp::And, a, b)
11849 }
11850}
11851
11852impl RingOp<W64> for Or<W64> {
11853 type Operand = u64;
11854 #[inline]
11855 fn apply(a: u64, b: u64) -> u64 {
11856 const_ring_eval_w64(PrimitiveOp::Or, a, b)
11857 }
11858}
11859
11860impl RingOp<W72> for Mul<W72> {
11861 type Operand = u128;
11862 #[inline]
11863 fn apply(a: u128, b: u128) -> u128 {
11864 const_ring_eval_w72(PrimitiveOp::Mul, a, b)
11865 }
11866}
11867
11868impl RingOp<W72> for Add<W72> {
11869 type Operand = u128;
11870 #[inline]
11871 fn apply(a: u128, b: u128) -> u128 {
11872 const_ring_eval_w72(PrimitiveOp::Add, a, b)
11873 }
11874}
11875
11876impl RingOp<W72> for Sub<W72> {
11877 type Operand = u128;
11878 #[inline]
11879 fn apply(a: u128, b: u128) -> u128 {
11880 const_ring_eval_w72(PrimitiveOp::Sub, a, b)
11881 }
11882}
11883
11884impl RingOp<W72> for Xor<W72> {
11885 type Operand = u128;
11886 #[inline]
11887 fn apply(a: u128, b: u128) -> u128 {
11888 const_ring_eval_w72(PrimitiveOp::Xor, a, b)
11889 }
11890}
11891
11892impl RingOp<W72> for And<W72> {
11893 type Operand = u128;
11894 #[inline]
11895 fn apply(a: u128, b: u128) -> u128 {
11896 const_ring_eval_w72(PrimitiveOp::And, a, b)
11897 }
11898}
11899
11900impl RingOp<W72> for Or<W72> {
11901 type Operand = u128;
11902 #[inline]
11903 fn apply(a: u128, b: u128) -> u128 {
11904 const_ring_eval_w72(PrimitiveOp::Or, a, b)
11905 }
11906}
11907
11908impl RingOp<W80> for Mul<W80> {
11909 type Operand = u128;
11910 #[inline]
11911 fn apply(a: u128, b: u128) -> u128 {
11912 const_ring_eval_w80(PrimitiveOp::Mul, a, b)
11913 }
11914}
11915
11916impl RingOp<W80> for Add<W80> {
11917 type Operand = u128;
11918 #[inline]
11919 fn apply(a: u128, b: u128) -> u128 {
11920 const_ring_eval_w80(PrimitiveOp::Add, a, b)
11921 }
11922}
11923
11924impl RingOp<W80> for Sub<W80> {
11925 type Operand = u128;
11926 #[inline]
11927 fn apply(a: u128, b: u128) -> u128 {
11928 const_ring_eval_w80(PrimitiveOp::Sub, a, b)
11929 }
11930}
11931
11932impl RingOp<W80> for Xor<W80> {
11933 type Operand = u128;
11934 #[inline]
11935 fn apply(a: u128, b: u128) -> u128 {
11936 const_ring_eval_w80(PrimitiveOp::Xor, a, b)
11937 }
11938}
11939
11940impl RingOp<W80> for And<W80> {
11941 type Operand = u128;
11942 #[inline]
11943 fn apply(a: u128, b: u128) -> u128 {
11944 const_ring_eval_w80(PrimitiveOp::And, a, b)
11945 }
11946}
11947
11948impl RingOp<W80> for Or<W80> {
11949 type Operand = u128;
11950 #[inline]
11951 fn apply(a: u128, b: u128) -> u128 {
11952 const_ring_eval_w80(PrimitiveOp::Or, a, b)
11953 }
11954}
11955
11956impl RingOp<W88> for Mul<W88> {
11957 type Operand = u128;
11958 #[inline]
11959 fn apply(a: u128, b: u128) -> u128 {
11960 const_ring_eval_w88(PrimitiveOp::Mul, a, b)
11961 }
11962}
11963
11964impl RingOp<W88> for Add<W88> {
11965 type Operand = u128;
11966 #[inline]
11967 fn apply(a: u128, b: u128) -> u128 {
11968 const_ring_eval_w88(PrimitiveOp::Add, a, b)
11969 }
11970}
11971
11972impl RingOp<W88> for Sub<W88> {
11973 type Operand = u128;
11974 #[inline]
11975 fn apply(a: u128, b: u128) -> u128 {
11976 const_ring_eval_w88(PrimitiveOp::Sub, a, b)
11977 }
11978}
11979
11980impl RingOp<W88> for Xor<W88> {
11981 type Operand = u128;
11982 #[inline]
11983 fn apply(a: u128, b: u128) -> u128 {
11984 const_ring_eval_w88(PrimitiveOp::Xor, a, b)
11985 }
11986}
11987
11988impl RingOp<W88> for And<W88> {
11989 type Operand = u128;
11990 #[inline]
11991 fn apply(a: u128, b: u128) -> u128 {
11992 const_ring_eval_w88(PrimitiveOp::And, a, b)
11993 }
11994}
11995
11996impl RingOp<W88> for Or<W88> {
11997 type Operand = u128;
11998 #[inline]
11999 fn apply(a: u128, b: u128) -> u128 {
12000 const_ring_eval_w88(PrimitiveOp::Or, a, b)
12001 }
12002}
12003
12004impl RingOp<W96> for Mul<W96> {
12005 type Operand = u128;
12006 #[inline]
12007 fn apply(a: u128, b: u128) -> u128 {
12008 const_ring_eval_w96(PrimitiveOp::Mul, a, b)
12009 }
12010}
12011
12012impl RingOp<W96> for Add<W96> {
12013 type Operand = u128;
12014 #[inline]
12015 fn apply(a: u128, b: u128) -> u128 {
12016 const_ring_eval_w96(PrimitiveOp::Add, a, b)
12017 }
12018}
12019
12020impl RingOp<W96> for Sub<W96> {
12021 type Operand = u128;
12022 #[inline]
12023 fn apply(a: u128, b: u128) -> u128 {
12024 const_ring_eval_w96(PrimitiveOp::Sub, a, b)
12025 }
12026}
12027
12028impl RingOp<W96> for Xor<W96> {
12029 type Operand = u128;
12030 #[inline]
12031 fn apply(a: u128, b: u128) -> u128 {
12032 const_ring_eval_w96(PrimitiveOp::Xor, a, b)
12033 }
12034}
12035
12036impl RingOp<W96> for And<W96> {
12037 type Operand = u128;
12038 #[inline]
12039 fn apply(a: u128, b: u128) -> u128 {
12040 const_ring_eval_w96(PrimitiveOp::And, a, b)
12041 }
12042}
12043
12044impl RingOp<W96> for Or<W96> {
12045 type Operand = u128;
12046 #[inline]
12047 fn apply(a: u128, b: u128) -> u128 {
12048 const_ring_eval_w96(PrimitiveOp::Or, a, b)
12049 }
12050}
12051
12052impl RingOp<W104> for Mul<W104> {
12053 type Operand = u128;
12054 #[inline]
12055 fn apply(a: u128, b: u128) -> u128 {
12056 const_ring_eval_w104(PrimitiveOp::Mul, a, b)
12057 }
12058}
12059
12060impl RingOp<W104> for Add<W104> {
12061 type Operand = u128;
12062 #[inline]
12063 fn apply(a: u128, b: u128) -> u128 {
12064 const_ring_eval_w104(PrimitiveOp::Add, a, b)
12065 }
12066}
12067
12068impl RingOp<W104> for Sub<W104> {
12069 type Operand = u128;
12070 #[inline]
12071 fn apply(a: u128, b: u128) -> u128 {
12072 const_ring_eval_w104(PrimitiveOp::Sub, a, b)
12073 }
12074}
12075
12076impl RingOp<W104> for Xor<W104> {
12077 type Operand = u128;
12078 #[inline]
12079 fn apply(a: u128, b: u128) -> u128 {
12080 const_ring_eval_w104(PrimitiveOp::Xor, a, b)
12081 }
12082}
12083
12084impl RingOp<W104> for And<W104> {
12085 type Operand = u128;
12086 #[inline]
12087 fn apply(a: u128, b: u128) -> u128 {
12088 const_ring_eval_w104(PrimitiveOp::And, a, b)
12089 }
12090}
12091
12092impl RingOp<W104> for Or<W104> {
12093 type Operand = u128;
12094 #[inline]
12095 fn apply(a: u128, b: u128) -> u128 {
12096 const_ring_eval_w104(PrimitiveOp::Or, a, b)
12097 }
12098}
12099
12100impl RingOp<W112> for Mul<W112> {
12101 type Operand = u128;
12102 #[inline]
12103 fn apply(a: u128, b: u128) -> u128 {
12104 const_ring_eval_w112(PrimitiveOp::Mul, a, b)
12105 }
12106}
12107
12108impl RingOp<W112> for Add<W112> {
12109 type Operand = u128;
12110 #[inline]
12111 fn apply(a: u128, b: u128) -> u128 {
12112 const_ring_eval_w112(PrimitiveOp::Add, a, b)
12113 }
12114}
12115
12116impl RingOp<W112> for Sub<W112> {
12117 type Operand = u128;
12118 #[inline]
12119 fn apply(a: u128, b: u128) -> u128 {
12120 const_ring_eval_w112(PrimitiveOp::Sub, a, b)
12121 }
12122}
12123
12124impl RingOp<W112> for Xor<W112> {
12125 type Operand = u128;
12126 #[inline]
12127 fn apply(a: u128, b: u128) -> u128 {
12128 const_ring_eval_w112(PrimitiveOp::Xor, a, b)
12129 }
12130}
12131
12132impl RingOp<W112> for And<W112> {
12133 type Operand = u128;
12134 #[inline]
12135 fn apply(a: u128, b: u128) -> u128 {
12136 const_ring_eval_w112(PrimitiveOp::And, a, b)
12137 }
12138}
12139
12140impl RingOp<W112> for Or<W112> {
12141 type Operand = u128;
12142 #[inline]
12143 fn apply(a: u128, b: u128) -> u128 {
12144 const_ring_eval_w112(PrimitiveOp::Or, a, b)
12145 }
12146}
12147
12148impl RingOp<W120> for Mul<W120> {
12149 type Operand = u128;
12150 #[inline]
12151 fn apply(a: u128, b: u128) -> u128 {
12152 const_ring_eval_w120(PrimitiveOp::Mul, a, b)
12153 }
12154}
12155
12156impl RingOp<W120> for Add<W120> {
12157 type Operand = u128;
12158 #[inline]
12159 fn apply(a: u128, b: u128) -> u128 {
12160 const_ring_eval_w120(PrimitiveOp::Add, a, b)
12161 }
12162}
12163
12164impl RingOp<W120> for Sub<W120> {
12165 type Operand = u128;
12166 #[inline]
12167 fn apply(a: u128, b: u128) -> u128 {
12168 const_ring_eval_w120(PrimitiveOp::Sub, a, b)
12169 }
12170}
12171
12172impl RingOp<W120> for Xor<W120> {
12173 type Operand = u128;
12174 #[inline]
12175 fn apply(a: u128, b: u128) -> u128 {
12176 const_ring_eval_w120(PrimitiveOp::Xor, a, b)
12177 }
12178}
12179
12180impl RingOp<W120> for And<W120> {
12181 type Operand = u128;
12182 #[inline]
12183 fn apply(a: u128, b: u128) -> u128 {
12184 const_ring_eval_w120(PrimitiveOp::And, a, b)
12185 }
12186}
12187
12188impl RingOp<W120> for Or<W120> {
12189 type Operand = u128;
12190 #[inline]
12191 fn apply(a: u128, b: u128) -> u128 {
12192 const_ring_eval_w120(PrimitiveOp::Or, a, b)
12193 }
12194}
12195
12196impl RingOp<W128> for Mul<W128> {
12197 type Operand = u128;
12198 #[inline]
12199 fn apply(a: u128, b: u128) -> u128 {
12200 const_ring_eval_w128(PrimitiveOp::Mul, a, b)
12201 }
12202}
12203
12204impl RingOp<W128> for Add<W128> {
12205 type Operand = u128;
12206 #[inline]
12207 fn apply(a: u128, b: u128) -> u128 {
12208 const_ring_eval_w128(PrimitiveOp::Add, a, b)
12209 }
12210}
12211
12212impl RingOp<W128> for Sub<W128> {
12213 type Operand = u128;
12214 #[inline]
12215 fn apply(a: u128, b: u128) -> u128 {
12216 const_ring_eval_w128(PrimitiveOp::Sub, a, b)
12217 }
12218}
12219
12220impl RingOp<W128> for Xor<W128> {
12221 type Operand = u128;
12222 #[inline]
12223 fn apply(a: u128, b: u128) -> u128 {
12224 const_ring_eval_w128(PrimitiveOp::Xor, a, b)
12225 }
12226}
12227
12228impl RingOp<W128> for And<W128> {
12229 type Operand = u128;
12230 #[inline]
12231 fn apply(a: u128, b: u128) -> u128 {
12232 const_ring_eval_w128(PrimitiveOp::And, a, b)
12233 }
12234}
12235
12236impl RingOp<W128> for Or<W128> {
12237 type Operand = u128;
12238 #[inline]
12239 fn apply(a: u128, b: u128) -> u128 {
12240 const_ring_eval_w128(PrimitiveOp::Or, a, b)
12241 }
12242}
12243
12244impl UnaryRingOp<W8> for Neg<W8> {
12245 type Operand = u8;
12246 #[inline]
12247 fn apply(a: u8) -> u8 {
12248 const_ring_eval_w8(PrimitiveOp::Sub, 0, a)
12249 }
12250}
12251
12252impl UnaryRingOp<W8> for BNot<W8> {
12253 type Operand = u8;
12254 #[inline]
12255 fn apply(a: u8) -> u8 {
12256 const_ring_eval_w8(PrimitiveOp::Xor, a, u8::MAX)
12257 }
12258}
12259
12260impl UnaryRingOp<W8> for Succ<W8> {
12261 type Operand = u8;
12262 #[inline]
12263 fn apply(a: u8) -> u8 {
12264 <Neg<W8> as UnaryRingOp<W8>>::apply(<BNot<W8> as UnaryRingOp<W8>>::apply(a))
12265 }
12266}
12267
12268impl UnaryRingOp<W16> for Neg<W16> {
12269 type Operand = u16;
12270 #[inline]
12271 fn apply(a: u16) -> u16 {
12272 const_ring_eval_w16(PrimitiveOp::Sub, 0, a)
12273 }
12274}
12275
12276impl UnaryRingOp<W16> for BNot<W16> {
12277 type Operand = u16;
12278 #[inline]
12279 fn apply(a: u16) -> u16 {
12280 const_ring_eval_w16(PrimitiveOp::Xor, a, u16::MAX)
12281 }
12282}
12283
12284impl UnaryRingOp<W16> for Succ<W16> {
12285 type Operand = u16;
12286 #[inline]
12287 fn apply(a: u16) -> u16 {
12288 <Neg<W16> as UnaryRingOp<W16>>::apply(<BNot<W16> as UnaryRingOp<W16>>::apply(a))
12289 }
12290}
12291
12292impl UnaryRingOp<W24> for Neg<W24> {
12293 type Operand = u32;
12294 #[inline]
12295 fn apply(a: u32) -> u32 {
12296 const_ring_eval_w24(PrimitiveOp::Sub, 0, a)
12297 }
12298}
12299
12300impl UnaryRingOp<W24> for BNot<W24> {
12301 type Operand = u32;
12302 #[inline]
12303 fn apply(a: u32) -> u32 {
12304 const_ring_eval_w24(PrimitiveOp::Xor, a, 0x00FF_FFFFu32)
12305 }
12306}
12307
12308impl UnaryRingOp<W24> for Succ<W24> {
12309 type Operand = u32;
12310 #[inline]
12311 fn apply(a: u32) -> u32 {
12312 <Neg<W24> as UnaryRingOp<W24>>::apply(<BNot<W24> as UnaryRingOp<W24>>::apply(a))
12313 }
12314}
12315
12316impl UnaryRingOp<W32> for Neg<W32> {
12317 type Operand = u32;
12318 #[inline]
12319 fn apply(a: u32) -> u32 {
12320 const_ring_eval_w32(PrimitiveOp::Sub, 0, a)
12321 }
12322}
12323
12324impl UnaryRingOp<W32> for BNot<W32> {
12325 type Operand = u32;
12326 #[inline]
12327 fn apply(a: u32) -> u32 {
12328 const_ring_eval_w32(PrimitiveOp::Xor, a, u32::MAX)
12329 }
12330}
12331
12332impl UnaryRingOp<W32> for Succ<W32> {
12333 type Operand = u32;
12334 #[inline]
12335 fn apply(a: u32) -> u32 {
12336 <Neg<W32> as UnaryRingOp<W32>>::apply(<BNot<W32> as UnaryRingOp<W32>>::apply(a))
12337 }
12338}
12339
12340impl UnaryRingOp<W40> for Neg<W40> {
12341 type Operand = u64;
12342 #[inline]
12343 fn apply(a: u64) -> u64 {
12344 const_ring_eval_w40(PrimitiveOp::Sub, 0, a)
12345 }
12346}
12347
12348impl UnaryRingOp<W40> for BNot<W40> {
12349 type Operand = u64;
12350 #[inline]
12351 fn apply(a: u64) -> u64 {
12352 const_ring_eval_w40(PrimitiveOp::Xor, a, 0x0000_00FF_FFFF_FFFFu64)
12353 }
12354}
12355
12356impl UnaryRingOp<W40> for Succ<W40> {
12357 type Operand = u64;
12358 #[inline]
12359 fn apply(a: u64) -> u64 {
12360 <Neg<W40> as UnaryRingOp<W40>>::apply(<BNot<W40> as UnaryRingOp<W40>>::apply(a))
12361 }
12362}
12363
12364impl UnaryRingOp<W48> for Neg<W48> {
12365 type Operand = u64;
12366 #[inline]
12367 fn apply(a: u64) -> u64 {
12368 const_ring_eval_w48(PrimitiveOp::Sub, 0, a)
12369 }
12370}
12371
12372impl UnaryRingOp<W48> for BNot<W48> {
12373 type Operand = u64;
12374 #[inline]
12375 fn apply(a: u64) -> u64 {
12376 const_ring_eval_w48(PrimitiveOp::Xor, a, 0x0000_FFFF_FFFF_FFFFu64)
12377 }
12378}
12379
12380impl UnaryRingOp<W48> for Succ<W48> {
12381 type Operand = u64;
12382 #[inline]
12383 fn apply(a: u64) -> u64 {
12384 <Neg<W48> as UnaryRingOp<W48>>::apply(<BNot<W48> as UnaryRingOp<W48>>::apply(a))
12385 }
12386}
12387
12388impl UnaryRingOp<W56> for Neg<W56> {
12389 type Operand = u64;
12390 #[inline]
12391 fn apply(a: u64) -> u64 {
12392 const_ring_eval_w56(PrimitiveOp::Sub, 0, a)
12393 }
12394}
12395
12396impl UnaryRingOp<W56> for BNot<W56> {
12397 type Operand = u64;
12398 #[inline]
12399 fn apply(a: u64) -> u64 {
12400 const_ring_eval_w56(PrimitiveOp::Xor, a, 0x00FF_FFFF_FFFF_FFFFu64)
12401 }
12402}
12403
12404impl UnaryRingOp<W56> for Succ<W56> {
12405 type Operand = u64;
12406 #[inline]
12407 fn apply(a: u64) -> u64 {
12408 <Neg<W56> as UnaryRingOp<W56>>::apply(<BNot<W56> as UnaryRingOp<W56>>::apply(a))
12409 }
12410}
12411
12412impl UnaryRingOp<W64> for Neg<W64> {
12413 type Operand = u64;
12414 #[inline]
12415 fn apply(a: u64) -> u64 {
12416 const_ring_eval_w64(PrimitiveOp::Sub, 0, a)
12417 }
12418}
12419
12420impl UnaryRingOp<W64> for BNot<W64> {
12421 type Operand = u64;
12422 #[inline]
12423 fn apply(a: u64) -> u64 {
12424 const_ring_eval_w64(PrimitiveOp::Xor, a, u64::MAX)
12425 }
12426}
12427
12428impl UnaryRingOp<W64> for Succ<W64> {
12429 type Operand = u64;
12430 #[inline]
12431 fn apply(a: u64) -> u64 {
12432 <Neg<W64> as UnaryRingOp<W64>>::apply(<BNot<W64> as UnaryRingOp<W64>>::apply(a))
12433 }
12434}
12435
12436impl UnaryRingOp<W72> for Neg<W72> {
12437 type Operand = u128;
12438 #[inline]
12439 fn apply(a: u128) -> u128 {
12440 const_ring_eval_w72(PrimitiveOp::Sub, 0, a)
12441 }
12442}
12443
12444impl UnaryRingOp<W72> for BNot<W72> {
12445 type Operand = u128;
12446 #[inline]
12447 fn apply(a: u128) -> u128 {
12448 const_ring_eval_w72(PrimitiveOp::Xor, a, u128::MAX >> (128 - 72))
12449 }
12450}
12451
12452impl UnaryRingOp<W72> for Succ<W72> {
12453 type Operand = u128;
12454 #[inline]
12455 fn apply(a: u128) -> u128 {
12456 <Neg<W72> as UnaryRingOp<W72>>::apply(<BNot<W72> as UnaryRingOp<W72>>::apply(a))
12457 }
12458}
12459
12460impl UnaryRingOp<W80> for Neg<W80> {
12461 type Operand = u128;
12462 #[inline]
12463 fn apply(a: u128) -> u128 {
12464 const_ring_eval_w80(PrimitiveOp::Sub, 0, a)
12465 }
12466}
12467
12468impl UnaryRingOp<W80> for BNot<W80> {
12469 type Operand = u128;
12470 #[inline]
12471 fn apply(a: u128) -> u128 {
12472 const_ring_eval_w80(PrimitiveOp::Xor, a, u128::MAX >> (128 - 80))
12473 }
12474}
12475
12476impl UnaryRingOp<W80> for Succ<W80> {
12477 type Operand = u128;
12478 #[inline]
12479 fn apply(a: u128) -> u128 {
12480 <Neg<W80> as UnaryRingOp<W80>>::apply(<BNot<W80> as UnaryRingOp<W80>>::apply(a))
12481 }
12482}
12483
12484impl UnaryRingOp<W88> for Neg<W88> {
12485 type Operand = u128;
12486 #[inline]
12487 fn apply(a: u128) -> u128 {
12488 const_ring_eval_w88(PrimitiveOp::Sub, 0, a)
12489 }
12490}
12491
12492impl UnaryRingOp<W88> for BNot<W88> {
12493 type Operand = u128;
12494 #[inline]
12495 fn apply(a: u128) -> u128 {
12496 const_ring_eval_w88(PrimitiveOp::Xor, a, u128::MAX >> (128 - 88))
12497 }
12498}
12499
12500impl UnaryRingOp<W88> for Succ<W88> {
12501 type Operand = u128;
12502 #[inline]
12503 fn apply(a: u128) -> u128 {
12504 <Neg<W88> as UnaryRingOp<W88>>::apply(<BNot<W88> as UnaryRingOp<W88>>::apply(a))
12505 }
12506}
12507
12508impl UnaryRingOp<W96> for Neg<W96> {
12509 type Operand = u128;
12510 #[inline]
12511 fn apply(a: u128) -> u128 {
12512 const_ring_eval_w96(PrimitiveOp::Sub, 0, a)
12513 }
12514}
12515
12516impl UnaryRingOp<W96> for BNot<W96> {
12517 type Operand = u128;
12518 #[inline]
12519 fn apply(a: u128) -> u128 {
12520 const_ring_eval_w96(PrimitiveOp::Xor, a, u128::MAX >> (128 - 96))
12521 }
12522}
12523
12524impl UnaryRingOp<W96> for Succ<W96> {
12525 type Operand = u128;
12526 #[inline]
12527 fn apply(a: u128) -> u128 {
12528 <Neg<W96> as UnaryRingOp<W96>>::apply(<BNot<W96> as UnaryRingOp<W96>>::apply(a))
12529 }
12530}
12531
12532impl UnaryRingOp<W104> for Neg<W104> {
12533 type Operand = u128;
12534 #[inline]
12535 fn apply(a: u128) -> u128 {
12536 const_ring_eval_w104(PrimitiveOp::Sub, 0, a)
12537 }
12538}
12539
12540impl UnaryRingOp<W104> for BNot<W104> {
12541 type Operand = u128;
12542 #[inline]
12543 fn apply(a: u128) -> u128 {
12544 const_ring_eval_w104(PrimitiveOp::Xor, a, u128::MAX >> (128 - 104))
12545 }
12546}
12547
12548impl UnaryRingOp<W104> for Succ<W104> {
12549 type Operand = u128;
12550 #[inline]
12551 fn apply(a: u128) -> u128 {
12552 <Neg<W104> as UnaryRingOp<W104>>::apply(<BNot<W104> as UnaryRingOp<W104>>::apply(a))
12553 }
12554}
12555
12556impl UnaryRingOp<W112> for Neg<W112> {
12557 type Operand = u128;
12558 #[inline]
12559 fn apply(a: u128) -> u128 {
12560 const_ring_eval_w112(PrimitiveOp::Sub, 0, a)
12561 }
12562}
12563
12564impl UnaryRingOp<W112> for BNot<W112> {
12565 type Operand = u128;
12566 #[inline]
12567 fn apply(a: u128) -> u128 {
12568 const_ring_eval_w112(PrimitiveOp::Xor, a, u128::MAX >> (128 - 112))
12569 }
12570}
12571
12572impl UnaryRingOp<W112> for Succ<W112> {
12573 type Operand = u128;
12574 #[inline]
12575 fn apply(a: u128) -> u128 {
12576 <Neg<W112> as UnaryRingOp<W112>>::apply(<BNot<W112> as UnaryRingOp<W112>>::apply(a))
12577 }
12578}
12579
12580impl UnaryRingOp<W120> for Neg<W120> {
12581 type Operand = u128;
12582 #[inline]
12583 fn apply(a: u128) -> u128 {
12584 const_ring_eval_w120(PrimitiveOp::Sub, 0, a)
12585 }
12586}
12587
12588impl UnaryRingOp<W120> for BNot<W120> {
12589 type Operand = u128;
12590 #[inline]
12591 fn apply(a: u128) -> u128 {
12592 const_ring_eval_w120(PrimitiveOp::Xor, a, u128::MAX >> (128 - 120))
12593 }
12594}
12595
12596impl UnaryRingOp<W120> for Succ<W120> {
12597 type Operand = u128;
12598 #[inline]
12599 fn apply(a: u128) -> u128 {
12600 <Neg<W120> as UnaryRingOp<W120>>::apply(<BNot<W120> as UnaryRingOp<W120>>::apply(a))
12601 }
12602}
12603
12604impl UnaryRingOp<W128> for Neg<W128> {
12605 type Operand = u128;
12606 #[inline]
12607 fn apply(a: u128) -> u128 {
12608 const_ring_eval_w128(PrimitiveOp::Sub, 0, a)
12609 }
12610}
12611
12612impl UnaryRingOp<W128> for BNot<W128> {
12613 type Operand = u128;
12614 #[inline]
12615 fn apply(a: u128) -> u128 {
12616 const_ring_eval_w128(PrimitiveOp::Xor, a, u128::MAX)
12617 }
12618}
12619
12620impl UnaryRingOp<W128> for Succ<W128> {
12621 type Operand = u128;
12622 #[inline]
12623 fn apply(a: u128) -> u128 {
12624 <Neg<W128> as UnaryRingOp<W128>>::apply(<BNot<W128> as UnaryRingOp<W128>>::apply(a))
12625 }
12626}
12627
12628pub trait ValidLevelEmbedding: valid_level_embedding_sealed::Sealed {}
12631
12632mod valid_level_embedding_sealed {
12633 pub trait Sealed {}
12635 impl Sealed for (super::W8, super::W8) {}
12636 impl Sealed for (super::W8, super::W16) {}
12637 impl Sealed for (super::W8, super::W24) {}
12638 impl Sealed for (super::W8, super::W32) {}
12639 impl Sealed for (super::W8, super::W40) {}
12640 impl Sealed for (super::W8, super::W48) {}
12641 impl Sealed for (super::W8, super::W56) {}
12642 impl Sealed for (super::W8, super::W64) {}
12643 impl Sealed for (super::W8, super::W72) {}
12644 impl Sealed for (super::W8, super::W80) {}
12645 impl Sealed for (super::W8, super::W88) {}
12646 impl Sealed for (super::W8, super::W96) {}
12647 impl Sealed for (super::W8, super::W104) {}
12648 impl Sealed for (super::W8, super::W112) {}
12649 impl Sealed for (super::W8, super::W120) {}
12650 impl Sealed for (super::W8, super::W128) {}
12651 impl Sealed for (super::W16, super::W16) {}
12652 impl Sealed for (super::W16, super::W24) {}
12653 impl Sealed for (super::W16, super::W32) {}
12654 impl Sealed for (super::W16, super::W40) {}
12655 impl Sealed for (super::W16, super::W48) {}
12656 impl Sealed for (super::W16, super::W56) {}
12657 impl Sealed for (super::W16, super::W64) {}
12658 impl Sealed for (super::W16, super::W72) {}
12659 impl Sealed for (super::W16, super::W80) {}
12660 impl Sealed for (super::W16, super::W88) {}
12661 impl Sealed for (super::W16, super::W96) {}
12662 impl Sealed for (super::W16, super::W104) {}
12663 impl Sealed for (super::W16, super::W112) {}
12664 impl Sealed for (super::W16, super::W120) {}
12665 impl Sealed for (super::W16, super::W128) {}
12666 impl Sealed for (super::W24, super::W24) {}
12667 impl Sealed for (super::W24, super::W32) {}
12668 impl Sealed for (super::W24, super::W40) {}
12669 impl Sealed for (super::W24, super::W48) {}
12670 impl Sealed for (super::W24, super::W56) {}
12671 impl Sealed for (super::W24, super::W64) {}
12672 impl Sealed for (super::W24, super::W72) {}
12673 impl Sealed for (super::W24, super::W80) {}
12674 impl Sealed for (super::W24, super::W88) {}
12675 impl Sealed for (super::W24, super::W96) {}
12676 impl Sealed for (super::W24, super::W104) {}
12677 impl Sealed for (super::W24, super::W112) {}
12678 impl Sealed for (super::W24, super::W120) {}
12679 impl Sealed for (super::W24, super::W128) {}
12680 impl Sealed for (super::W32, super::W32) {}
12681 impl Sealed for (super::W32, super::W40) {}
12682 impl Sealed for (super::W32, super::W48) {}
12683 impl Sealed for (super::W32, super::W56) {}
12684 impl Sealed for (super::W32, super::W64) {}
12685 impl Sealed for (super::W32, super::W72) {}
12686 impl Sealed for (super::W32, super::W80) {}
12687 impl Sealed for (super::W32, super::W88) {}
12688 impl Sealed for (super::W32, super::W96) {}
12689 impl Sealed for (super::W32, super::W104) {}
12690 impl Sealed for (super::W32, super::W112) {}
12691 impl Sealed for (super::W32, super::W120) {}
12692 impl Sealed for (super::W32, super::W128) {}
12693 impl Sealed for (super::W40, super::W40) {}
12694 impl Sealed for (super::W40, super::W48) {}
12695 impl Sealed for (super::W40, super::W56) {}
12696 impl Sealed for (super::W40, super::W64) {}
12697 impl Sealed for (super::W40, super::W72) {}
12698 impl Sealed for (super::W40, super::W80) {}
12699 impl Sealed for (super::W40, super::W88) {}
12700 impl Sealed for (super::W40, super::W96) {}
12701 impl Sealed for (super::W40, super::W104) {}
12702 impl Sealed for (super::W40, super::W112) {}
12703 impl Sealed for (super::W40, super::W120) {}
12704 impl Sealed for (super::W40, super::W128) {}
12705 impl Sealed for (super::W48, super::W48) {}
12706 impl Sealed for (super::W48, super::W56) {}
12707 impl Sealed for (super::W48, super::W64) {}
12708 impl Sealed for (super::W48, super::W72) {}
12709 impl Sealed for (super::W48, super::W80) {}
12710 impl Sealed for (super::W48, super::W88) {}
12711 impl Sealed for (super::W48, super::W96) {}
12712 impl Sealed for (super::W48, super::W104) {}
12713 impl Sealed for (super::W48, super::W112) {}
12714 impl Sealed for (super::W48, super::W120) {}
12715 impl Sealed for (super::W48, super::W128) {}
12716 impl Sealed for (super::W56, super::W56) {}
12717 impl Sealed for (super::W56, super::W64) {}
12718 impl Sealed for (super::W56, super::W72) {}
12719 impl Sealed for (super::W56, super::W80) {}
12720 impl Sealed for (super::W56, super::W88) {}
12721 impl Sealed for (super::W56, super::W96) {}
12722 impl Sealed for (super::W56, super::W104) {}
12723 impl Sealed for (super::W56, super::W112) {}
12724 impl Sealed for (super::W56, super::W120) {}
12725 impl Sealed for (super::W56, super::W128) {}
12726 impl Sealed for (super::W64, super::W64) {}
12727 impl Sealed for (super::W64, super::W72) {}
12728 impl Sealed for (super::W64, super::W80) {}
12729 impl Sealed for (super::W64, super::W88) {}
12730 impl Sealed for (super::W64, super::W96) {}
12731 impl Sealed for (super::W64, super::W104) {}
12732 impl Sealed for (super::W64, super::W112) {}
12733 impl Sealed for (super::W64, super::W120) {}
12734 impl Sealed for (super::W64, super::W128) {}
12735 impl Sealed for (super::W72, super::W72) {}
12736 impl Sealed for (super::W72, super::W80) {}
12737 impl Sealed for (super::W72, super::W88) {}
12738 impl Sealed for (super::W72, super::W96) {}
12739 impl Sealed for (super::W72, super::W104) {}
12740 impl Sealed for (super::W72, super::W112) {}
12741 impl Sealed for (super::W72, super::W120) {}
12742 impl Sealed for (super::W72, super::W128) {}
12743 impl Sealed for (super::W80, super::W80) {}
12744 impl Sealed for (super::W80, super::W88) {}
12745 impl Sealed for (super::W80, super::W96) {}
12746 impl Sealed for (super::W80, super::W104) {}
12747 impl Sealed for (super::W80, super::W112) {}
12748 impl Sealed for (super::W80, super::W120) {}
12749 impl Sealed for (super::W80, super::W128) {}
12750 impl Sealed for (super::W88, super::W88) {}
12751 impl Sealed for (super::W88, super::W96) {}
12752 impl Sealed for (super::W88, super::W104) {}
12753 impl Sealed for (super::W88, super::W112) {}
12754 impl Sealed for (super::W88, super::W120) {}
12755 impl Sealed for (super::W88, super::W128) {}
12756 impl Sealed for (super::W96, super::W96) {}
12757 impl Sealed for (super::W96, super::W104) {}
12758 impl Sealed for (super::W96, super::W112) {}
12759 impl Sealed for (super::W96, super::W120) {}
12760 impl Sealed for (super::W96, super::W128) {}
12761 impl Sealed for (super::W104, super::W104) {}
12762 impl Sealed for (super::W104, super::W112) {}
12763 impl Sealed for (super::W104, super::W120) {}
12764 impl Sealed for (super::W104, super::W128) {}
12765 impl Sealed for (super::W112, super::W112) {}
12766 impl Sealed for (super::W112, super::W120) {}
12767 impl Sealed for (super::W112, super::W128) {}
12768 impl Sealed for (super::W120, super::W120) {}
12769 impl Sealed for (super::W120, super::W128) {}
12770 impl Sealed for (super::W128, super::W128) {}
12771}
12772
12773impl ValidLevelEmbedding for (W8, W8) {}
12774impl ValidLevelEmbedding for (W8, W16) {}
12775impl ValidLevelEmbedding for (W8, W24) {}
12776impl ValidLevelEmbedding for (W8, W32) {}
12777impl ValidLevelEmbedding for (W8, W40) {}
12778impl ValidLevelEmbedding for (W8, W48) {}
12779impl ValidLevelEmbedding for (W8, W56) {}
12780impl ValidLevelEmbedding for (W8, W64) {}
12781impl ValidLevelEmbedding for (W8, W72) {}
12782impl ValidLevelEmbedding for (W8, W80) {}
12783impl ValidLevelEmbedding for (W8, W88) {}
12784impl ValidLevelEmbedding for (W8, W96) {}
12785impl ValidLevelEmbedding for (W8, W104) {}
12786impl ValidLevelEmbedding for (W8, W112) {}
12787impl ValidLevelEmbedding for (W8, W120) {}
12788impl ValidLevelEmbedding for (W8, W128) {}
12789impl ValidLevelEmbedding for (W16, W16) {}
12790impl ValidLevelEmbedding for (W16, W24) {}
12791impl ValidLevelEmbedding for (W16, W32) {}
12792impl ValidLevelEmbedding for (W16, W40) {}
12793impl ValidLevelEmbedding for (W16, W48) {}
12794impl ValidLevelEmbedding for (W16, W56) {}
12795impl ValidLevelEmbedding for (W16, W64) {}
12796impl ValidLevelEmbedding for (W16, W72) {}
12797impl ValidLevelEmbedding for (W16, W80) {}
12798impl ValidLevelEmbedding for (W16, W88) {}
12799impl ValidLevelEmbedding for (W16, W96) {}
12800impl ValidLevelEmbedding for (W16, W104) {}
12801impl ValidLevelEmbedding for (W16, W112) {}
12802impl ValidLevelEmbedding for (W16, W120) {}
12803impl ValidLevelEmbedding for (W16, W128) {}
12804impl ValidLevelEmbedding for (W24, W24) {}
12805impl ValidLevelEmbedding for (W24, W32) {}
12806impl ValidLevelEmbedding for (W24, W40) {}
12807impl ValidLevelEmbedding for (W24, W48) {}
12808impl ValidLevelEmbedding for (W24, W56) {}
12809impl ValidLevelEmbedding for (W24, W64) {}
12810impl ValidLevelEmbedding for (W24, W72) {}
12811impl ValidLevelEmbedding for (W24, W80) {}
12812impl ValidLevelEmbedding for (W24, W88) {}
12813impl ValidLevelEmbedding for (W24, W96) {}
12814impl ValidLevelEmbedding for (W24, W104) {}
12815impl ValidLevelEmbedding for (W24, W112) {}
12816impl ValidLevelEmbedding for (W24, W120) {}
12817impl ValidLevelEmbedding for (W24, W128) {}
12818impl ValidLevelEmbedding for (W32, W32) {}
12819impl ValidLevelEmbedding for (W32, W40) {}
12820impl ValidLevelEmbedding for (W32, W48) {}
12821impl ValidLevelEmbedding for (W32, W56) {}
12822impl ValidLevelEmbedding for (W32, W64) {}
12823impl ValidLevelEmbedding for (W32, W72) {}
12824impl ValidLevelEmbedding for (W32, W80) {}
12825impl ValidLevelEmbedding for (W32, W88) {}
12826impl ValidLevelEmbedding for (W32, W96) {}
12827impl ValidLevelEmbedding for (W32, W104) {}
12828impl ValidLevelEmbedding for (W32, W112) {}
12829impl ValidLevelEmbedding for (W32, W120) {}
12830impl ValidLevelEmbedding for (W32, W128) {}
12831impl ValidLevelEmbedding for (W40, W40) {}
12832impl ValidLevelEmbedding for (W40, W48) {}
12833impl ValidLevelEmbedding for (W40, W56) {}
12834impl ValidLevelEmbedding for (W40, W64) {}
12835impl ValidLevelEmbedding for (W40, W72) {}
12836impl ValidLevelEmbedding for (W40, W80) {}
12837impl ValidLevelEmbedding for (W40, W88) {}
12838impl ValidLevelEmbedding for (W40, W96) {}
12839impl ValidLevelEmbedding for (W40, W104) {}
12840impl ValidLevelEmbedding for (W40, W112) {}
12841impl ValidLevelEmbedding for (W40, W120) {}
12842impl ValidLevelEmbedding for (W40, W128) {}
12843impl ValidLevelEmbedding for (W48, W48) {}
12844impl ValidLevelEmbedding for (W48, W56) {}
12845impl ValidLevelEmbedding for (W48, W64) {}
12846impl ValidLevelEmbedding for (W48, W72) {}
12847impl ValidLevelEmbedding for (W48, W80) {}
12848impl ValidLevelEmbedding for (W48, W88) {}
12849impl ValidLevelEmbedding for (W48, W96) {}
12850impl ValidLevelEmbedding for (W48, W104) {}
12851impl ValidLevelEmbedding for (W48, W112) {}
12852impl ValidLevelEmbedding for (W48, W120) {}
12853impl ValidLevelEmbedding for (W48, W128) {}
12854impl ValidLevelEmbedding for (W56, W56) {}
12855impl ValidLevelEmbedding for (W56, W64) {}
12856impl ValidLevelEmbedding for (W56, W72) {}
12857impl ValidLevelEmbedding for (W56, W80) {}
12858impl ValidLevelEmbedding for (W56, W88) {}
12859impl ValidLevelEmbedding for (W56, W96) {}
12860impl ValidLevelEmbedding for (W56, W104) {}
12861impl ValidLevelEmbedding for (W56, W112) {}
12862impl ValidLevelEmbedding for (W56, W120) {}
12863impl ValidLevelEmbedding for (W56, W128) {}
12864impl ValidLevelEmbedding for (W64, W64) {}
12865impl ValidLevelEmbedding for (W64, W72) {}
12866impl ValidLevelEmbedding for (W64, W80) {}
12867impl ValidLevelEmbedding for (W64, W88) {}
12868impl ValidLevelEmbedding for (W64, W96) {}
12869impl ValidLevelEmbedding for (W64, W104) {}
12870impl ValidLevelEmbedding for (W64, W112) {}
12871impl ValidLevelEmbedding for (W64, W120) {}
12872impl ValidLevelEmbedding for (W64, W128) {}
12873impl ValidLevelEmbedding for (W72, W72) {}
12874impl ValidLevelEmbedding for (W72, W80) {}
12875impl ValidLevelEmbedding for (W72, W88) {}
12876impl ValidLevelEmbedding for (W72, W96) {}
12877impl ValidLevelEmbedding for (W72, W104) {}
12878impl ValidLevelEmbedding for (W72, W112) {}
12879impl ValidLevelEmbedding for (W72, W120) {}
12880impl ValidLevelEmbedding for (W72, W128) {}
12881impl ValidLevelEmbedding for (W80, W80) {}
12882impl ValidLevelEmbedding for (W80, W88) {}
12883impl ValidLevelEmbedding for (W80, W96) {}
12884impl ValidLevelEmbedding for (W80, W104) {}
12885impl ValidLevelEmbedding for (W80, W112) {}
12886impl ValidLevelEmbedding for (W80, W120) {}
12887impl ValidLevelEmbedding for (W80, W128) {}
12888impl ValidLevelEmbedding for (W88, W88) {}
12889impl ValidLevelEmbedding for (W88, W96) {}
12890impl ValidLevelEmbedding for (W88, W104) {}
12891impl ValidLevelEmbedding for (W88, W112) {}
12892impl ValidLevelEmbedding for (W88, W120) {}
12893impl ValidLevelEmbedding for (W88, W128) {}
12894impl ValidLevelEmbedding for (W96, W96) {}
12895impl ValidLevelEmbedding for (W96, W104) {}
12896impl ValidLevelEmbedding for (W96, W112) {}
12897impl ValidLevelEmbedding for (W96, W120) {}
12898impl ValidLevelEmbedding for (W96, W128) {}
12899impl ValidLevelEmbedding for (W104, W104) {}
12900impl ValidLevelEmbedding for (W104, W112) {}
12901impl ValidLevelEmbedding for (W104, W120) {}
12902impl ValidLevelEmbedding for (W104, W128) {}
12903impl ValidLevelEmbedding for (W112, W112) {}
12904impl ValidLevelEmbedding for (W112, W120) {}
12905impl ValidLevelEmbedding for (W112, W128) {}
12906impl ValidLevelEmbedding for (W120, W120) {}
12907impl ValidLevelEmbedding for (W120, W128) {}
12908impl ValidLevelEmbedding for (W128, W128) {}
12909
12910#[derive(Debug, Default, Clone, Copy)]
12916pub struct Embed<From, To>(PhantomData<(From, To)>);
12917
12918impl Embed<W8, W8> {
12919 #[inline]
12921 #[must_use]
12922 pub const fn apply(value: u8) -> u8 {
12923 value
12924 }
12925}
12926
12927impl Embed<W8, W16> {
12928 #[inline]
12930 #[must_use]
12931 pub const fn apply(value: u8) -> u16 {
12932 value as u16
12933 }
12934}
12935
12936impl Embed<W8, W24> {
12937 #[inline]
12939 #[must_use]
12940 pub const fn apply(value: u8) -> u32 {
12941 value as u32
12942 }
12943}
12944
12945impl Embed<W8, W32> {
12946 #[inline]
12948 #[must_use]
12949 pub const fn apply(value: u8) -> u32 {
12950 value as u32
12951 }
12952}
12953
12954impl Embed<W8, W40> {
12955 #[inline]
12957 #[must_use]
12958 pub const fn apply(value: u8) -> u64 {
12959 value as u64
12960 }
12961}
12962
12963impl Embed<W8, W48> {
12964 #[inline]
12966 #[must_use]
12967 pub const fn apply(value: u8) -> u64 {
12968 value as u64
12969 }
12970}
12971
12972impl Embed<W8, W56> {
12973 #[inline]
12975 #[must_use]
12976 pub const fn apply(value: u8) -> u64 {
12977 value as u64
12978 }
12979}
12980
12981impl Embed<W8, W64> {
12982 #[inline]
12984 #[must_use]
12985 pub const fn apply(value: u8) -> u64 {
12986 value as u64
12987 }
12988}
12989
12990impl Embed<W8, W72> {
12991 #[inline]
12993 #[must_use]
12994 pub const fn apply(value: u8) -> u128 {
12995 value as u128
12996 }
12997}
12998
12999impl Embed<W8, W80> {
13000 #[inline]
13002 #[must_use]
13003 pub const fn apply(value: u8) -> u128 {
13004 value as u128
13005 }
13006}
13007
13008impl Embed<W8, W88> {
13009 #[inline]
13011 #[must_use]
13012 pub const fn apply(value: u8) -> u128 {
13013 value as u128
13014 }
13015}
13016
13017impl Embed<W8, W96> {
13018 #[inline]
13020 #[must_use]
13021 pub const fn apply(value: u8) -> u128 {
13022 value as u128
13023 }
13024}
13025
13026impl Embed<W8, W104> {
13027 #[inline]
13029 #[must_use]
13030 pub const fn apply(value: u8) -> u128 {
13031 value as u128
13032 }
13033}
13034
13035impl Embed<W8, W112> {
13036 #[inline]
13038 #[must_use]
13039 pub const fn apply(value: u8) -> u128 {
13040 value as u128
13041 }
13042}
13043
13044impl Embed<W8, W120> {
13045 #[inline]
13047 #[must_use]
13048 pub const fn apply(value: u8) -> u128 {
13049 value as u128
13050 }
13051}
13052
13053impl Embed<W8, W128> {
13054 #[inline]
13056 #[must_use]
13057 pub const fn apply(value: u8) -> u128 {
13058 value as u128
13059 }
13060}
13061
13062impl Embed<W16, W16> {
13063 #[inline]
13065 #[must_use]
13066 pub const fn apply(value: u16) -> u16 {
13067 value
13068 }
13069}
13070
13071impl Embed<W16, W24> {
13072 #[inline]
13074 #[must_use]
13075 pub const fn apply(value: u16) -> u32 {
13076 value as u32
13077 }
13078}
13079
13080impl Embed<W16, W32> {
13081 #[inline]
13083 #[must_use]
13084 pub const fn apply(value: u16) -> u32 {
13085 value as u32
13086 }
13087}
13088
13089impl Embed<W16, W40> {
13090 #[inline]
13092 #[must_use]
13093 pub const fn apply(value: u16) -> u64 {
13094 value as u64
13095 }
13096}
13097
13098impl Embed<W16, W48> {
13099 #[inline]
13101 #[must_use]
13102 pub const fn apply(value: u16) -> u64 {
13103 value as u64
13104 }
13105}
13106
13107impl Embed<W16, W56> {
13108 #[inline]
13110 #[must_use]
13111 pub const fn apply(value: u16) -> u64 {
13112 value as u64
13113 }
13114}
13115
13116impl Embed<W16, W64> {
13117 #[inline]
13119 #[must_use]
13120 pub const fn apply(value: u16) -> u64 {
13121 value as u64
13122 }
13123}
13124
13125impl Embed<W16, W72> {
13126 #[inline]
13128 #[must_use]
13129 pub const fn apply(value: u16) -> u128 {
13130 value as u128
13131 }
13132}
13133
13134impl Embed<W16, W80> {
13135 #[inline]
13137 #[must_use]
13138 pub const fn apply(value: u16) -> u128 {
13139 value as u128
13140 }
13141}
13142
13143impl Embed<W16, W88> {
13144 #[inline]
13146 #[must_use]
13147 pub const fn apply(value: u16) -> u128 {
13148 value as u128
13149 }
13150}
13151
13152impl Embed<W16, W96> {
13153 #[inline]
13155 #[must_use]
13156 pub const fn apply(value: u16) -> u128 {
13157 value as u128
13158 }
13159}
13160
13161impl Embed<W16, W104> {
13162 #[inline]
13164 #[must_use]
13165 pub const fn apply(value: u16) -> u128 {
13166 value as u128
13167 }
13168}
13169
13170impl Embed<W16, W112> {
13171 #[inline]
13173 #[must_use]
13174 pub const fn apply(value: u16) -> u128 {
13175 value as u128
13176 }
13177}
13178
13179impl Embed<W16, W120> {
13180 #[inline]
13182 #[must_use]
13183 pub const fn apply(value: u16) -> u128 {
13184 value as u128
13185 }
13186}
13187
13188impl Embed<W16, W128> {
13189 #[inline]
13191 #[must_use]
13192 pub const fn apply(value: u16) -> u128 {
13193 value as u128
13194 }
13195}
13196
13197impl Embed<W24, W24> {
13198 #[inline]
13200 #[must_use]
13201 pub const fn apply(value: u32) -> u32 {
13202 value
13203 }
13204}
13205
13206impl Embed<W24, W32> {
13207 #[inline]
13209 #[must_use]
13210 pub const fn apply(value: u32) -> u32 {
13211 value
13212 }
13213}
13214
13215impl Embed<W24, W40> {
13216 #[inline]
13218 #[must_use]
13219 pub const fn apply(value: u32) -> u64 {
13220 value as u64
13221 }
13222}
13223
13224impl Embed<W24, W48> {
13225 #[inline]
13227 #[must_use]
13228 pub const fn apply(value: u32) -> u64 {
13229 value as u64
13230 }
13231}
13232
13233impl Embed<W24, W56> {
13234 #[inline]
13236 #[must_use]
13237 pub const fn apply(value: u32) -> u64 {
13238 value as u64
13239 }
13240}
13241
13242impl Embed<W24, W64> {
13243 #[inline]
13245 #[must_use]
13246 pub const fn apply(value: u32) -> u64 {
13247 value as u64
13248 }
13249}
13250
13251impl Embed<W24, W72> {
13252 #[inline]
13254 #[must_use]
13255 pub const fn apply(value: u32) -> u128 {
13256 value as u128
13257 }
13258}
13259
13260impl Embed<W24, W80> {
13261 #[inline]
13263 #[must_use]
13264 pub const fn apply(value: u32) -> u128 {
13265 value as u128
13266 }
13267}
13268
13269impl Embed<W24, W88> {
13270 #[inline]
13272 #[must_use]
13273 pub const fn apply(value: u32) -> u128 {
13274 value as u128
13275 }
13276}
13277
13278impl Embed<W24, W96> {
13279 #[inline]
13281 #[must_use]
13282 pub const fn apply(value: u32) -> u128 {
13283 value as u128
13284 }
13285}
13286
13287impl Embed<W24, W104> {
13288 #[inline]
13290 #[must_use]
13291 pub const fn apply(value: u32) -> u128 {
13292 value as u128
13293 }
13294}
13295
13296impl Embed<W24, W112> {
13297 #[inline]
13299 #[must_use]
13300 pub const fn apply(value: u32) -> u128 {
13301 value as u128
13302 }
13303}
13304
13305impl Embed<W24, W120> {
13306 #[inline]
13308 #[must_use]
13309 pub const fn apply(value: u32) -> u128 {
13310 value as u128
13311 }
13312}
13313
13314impl Embed<W24, W128> {
13315 #[inline]
13317 #[must_use]
13318 pub const fn apply(value: u32) -> u128 {
13319 value as u128
13320 }
13321}
13322
13323impl Embed<W32, W32> {
13324 #[inline]
13326 #[must_use]
13327 pub const fn apply(value: u32) -> u32 {
13328 value
13329 }
13330}
13331
13332impl Embed<W32, W40> {
13333 #[inline]
13335 #[must_use]
13336 pub const fn apply(value: u32) -> u64 {
13337 value as u64
13338 }
13339}
13340
13341impl Embed<W32, W48> {
13342 #[inline]
13344 #[must_use]
13345 pub const fn apply(value: u32) -> u64 {
13346 value as u64
13347 }
13348}
13349
13350impl Embed<W32, W56> {
13351 #[inline]
13353 #[must_use]
13354 pub const fn apply(value: u32) -> u64 {
13355 value as u64
13356 }
13357}
13358
13359impl Embed<W32, W64> {
13360 #[inline]
13362 #[must_use]
13363 pub const fn apply(value: u32) -> u64 {
13364 value as u64
13365 }
13366}
13367
13368impl Embed<W32, W72> {
13369 #[inline]
13371 #[must_use]
13372 pub const fn apply(value: u32) -> u128 {
13373 value as u128
13374 }
13375}
13376
13377impl Embed<W32, W80> {
13378 #[inline]
13380 #[must_use]
13381 pub const fn apply(value: u32) -> u128 {
13382 value as u128
13383 }
13384}
13385
13386impl Embed<W32, W88> {
13387 #[inline]
13389 #[must_use]
13390 pub const fn apply(value: u32) -> u128 {
13391 value as u128
13392 }
13393}
13394
13395impl Embed<W32, W96> {
13396 #[inline]
13398 #[must_use]
13399 pub const fn apply(value: u32) -> u128 {
13400 value as u128
13401 }
13402}
13403
13404impl Embed<W32, W104> {
13405 #[inline]
13407 #[must_use]
13408 pub const fn apply(value: u32) -> u128 {
13409 value as u128
13410 }
13411}
13412
13413impl Embed<W32, W112> {
13414 #[inline]
13416 #[must_use]
13417 pub const fn apply(value: u32) -> u128 {
13418 value as u128
13419 }
13420}
13421
13422impl Embed<W32, W120> {
13423 #[inline]
13425 #[must_use]
13426 pub const fn apply(value: u32) -> u128 {
13427 value as u128
13428 }
13429}
13430
13431impl Embed<W32, W128> {
13432 #[inline]
13434 #[must_use]
13435 pub const fn apply(value: u32) -> u128 {
13436 value as u128
13437 }
13438}
13439
13440impl Embed<W40, W40> {
13441 #[inline]
13443 #[must_use]
13444 pub const fn apply(value: u64) -> u64 {
13445 value
13446 }
13447}
13448
13449impl Embed<W40, W48> {
13450 #[inline]
13452 #[must_use]
13453 pub const fn apply(value: u64) -> u64 {
13454 value
13455 }
13456}
13457
13458impl Embed<W40, W56> {
13459 #[inline]
13461 #[must_use]
13462 pub const fn apply(value: u64) -> u64 {
13463 value
13464 }
13465}
13466
13467impl Embed<W40, W64> {
13468 #[inline]
13470 #[must_use]
13471 pub const fn apply(value: u64) -> u64 {
13472 value
13473 }
13474}
13475
13476impl Embed<W40, W72> {
13477 #[inline]
13479 #[must_use]
13480 pub const fn apply(value: u64) -> u128 {
13481 value as u128
13482 }
13483}
13484
13485impl Embed<W40, W80> {
13486 #[inline]
13488 #[must_use]
13489 pub const fn apply(value: u64) -> u128 {
13490 value as u128
13491 }
13492}
13493
13494impl Embed<W40, W88> {
13495 #[inline]
13497 #[must_use]
13498 pub const fn apply(value: u64) -> u128 {
13499 value as u128
13500 }
13501}
13502
13503impl Embed<W40, W96> {
13504 #[inline]
13506 #[must_use]
13507 pub const fn apply(value: u64) -> u128 {
13508 value as u128
13509 }
13510}
13511
13512impl Embed<W40, W104> {
13513 #[inline]
13515 #[must_use]
13516 pub const fn apply(value: u64) -> u128 {
13517 value as u128
13518 }
13519}
13520
13521impl Embed<W40, W112> {
13522 #[inline]
13524 #[must_use]
13525 pub const fn apply(value: u64) -> u128 {
13526 value as u128
13527 }
13528}
13529
13530impl Embed<W40, W120> {
13531 #[inline]
13533 #[must_use]
13534 pub const fn apply(value: u64) -> u128 {
13535 value as u128
13536 }
13537}
13538
13539impl Embed<W40, W128> {
13540 #[inline]
13542 #[must_use]
13543 pub const fn apply(value: u64) -> u128 {
13544 value as u128
13545 }
13546}
13547
13548impl Embed<W48, W48> {
13549 #[inline]
13551 #[must_use]
13552 pub const fn apply(value: u64) -> u64 {
13553 value
13554 }
13555}
13556
13557impl Embed<W48, W56> {
13558 #[inline]
13560 #[must_use]
13561 pub const fn apply(value: u64) -> u64 {
13562 value
13563 }
13564}
13565
13566impl Embed<W48, W64> {
13567 #[inline]
13569 #[must_use]
13570 pub const fn apply(value: u64) -> u64 {
13571 value
13572 }
13573}
13574
13575impl Embed<W48, W72> {
13576 #[inline]
13578 #[must_use]
13579 pub const fn apply(value: u64) -> u128 {
13580 value as u128
13581 }
13582}
13583
13584impl Embed<W48, W80> {
13585 #[inline]
13587 #[must_use]
13588 pub const fn apply(value: u64) -> u128 {
13589 value as u128
13590 }
13591}
13592
13593impl Embed<W48, W88> {
13594 #[inline]
13596 #[must_use]
13597 pub const fn apply(value: u64) -> u128 {
13598 value as u128
13599 }
13600}
13601
13602impl Embed<W48, W96> {
13603 #[inline]
13605 #[must_use]
13606 pub const fn apply(value: u64) -> u128 {
13607 value as u128
13608 }
13609}
13610
13611impl Embed<W48, W104> {
13612 #[inline]
13614 #[must_use]
13615 pub const fn apply(value: u64) -> u128 {
13616 value as u128
13617 }
13618}
13619
13620impl Embed<W48, W112> {
13621 #[inline]
13623 #[must_use]
13624 pub const fn apply(value: u64) -> u128 {
13625 value as u128
13626 }
13627}
13628
13629impl Embed<W48, W120> {
13630 #[inline]
13632 #[must_use]
13633 pub const fn apply(value: u64) -> u128 {
13634 value as u128
13635 }
13636}
13637
13638impl Embed<W48, W128> {
13639 #[inline]
13641 #[must_use]
13642 pub const fn apply(value: u64) -> u128 {
13643 value as u128
13644 }
13645}
13646
13647impl Embed<W56, W56> {
13648 #[inline]
13650 #[must_use]
13651 pub const fn apply(value: u64) -> u64 {
13652 value
13653 }
13654}
13655
13656impl Embed<W56, W64> {
13657 #[inline]
13659 #[must_use]
13660 pub const fn apply(value: u64) -> u64 {
13661 value
13662 }
13663}
13664
13665impl Embed<W56, W72> {
13666 #[inline]
13668 #[must_use]
13669 pub const fn apply(value: u64) -> u128 {
13670 value as u128
13671 }
13672}
13673
13674impl Embed<W56, W80> {
13675 #[inline]
13677 #[must_use]
13678 pub const fn apply(value: u64) -> u128 {
13679 value as u128
13680 }
13681}
13682
13683impl Embed<W56, W88> {
13684 #[inline]
13686 #[must_use]
13687 pub const fn apply(value: u64) -> u128 {
13688 value as u128
13689 }
13690}
13691
13692impl Embed<W56, W96> {
13693 #[inline]
13695 #[must_use]
13696 pub const fn apply(value: u64) -> u128 {
13697 value as u128
13698 }
13699}
13700
13701impl Embed<W56, W104> {
13702 #[inline]
13704 #[must_use]
13705 pub const fn apply(value: u64) -> u128 {
13706 value as u128
13707 }
13708}
13709
13710impl Embed<W56, W112> {
13711 #[inline]
13713 #[must_use]
13714 pub const fn apply(value: u64) -> u128 {
13715 value as u128
13716 }
13717}
13718
13719impl Embed<W56, W120> {
13720 #[inline]
13722 #[must_use]
13723 pub const fn apply(value: u64) -> u128 {
13724 value as u128
13725 }
13726}
13727
13728impl Embed<W56, W128> {
13729 #[inline]
13731 #[must_use]
13732 pub const fn apply(value: u64) -> u128 {
13733 value as u128
13734 }
13735}
13736
13737impl Embed<W64, W64> {
13738 #[inline]
13740 #[must_use]
13741 pub const fn apply(value: u64) -> u64 {
13742 value
13743 }
13744}
13745
13746impl Embed<W64, W72> {
13747 #[inline]
13749 #[must_use]
13750 pub const fn apply(value: u64) -> u128 {
13751 value as u128
13752 }
13753}
13754
13755impl Embed<W64, W80> {
13756 #[inline]
13758 #[must_use]
13759 pub const fn apply(value: u64) -> u128 {
13760 value as u128
13761 }
13762}
13763
13764impl Embed<W64, W88> {
13765 #[inline]
13767 #[must_use]
13768 pub const fn apply(value: u64) -> u128 {
13769 value as u128
13770 }
13771}
13772
13773impl Embed<W64, W96> {
13774 #[inline]
13776 #[must_use]
13777 pub const fn apply(value: u64) -> u128 {
13778 value as u128
13779 }
13780}
13781
13782impl Embed<W64, W104> {
13783 #[inline]
13785 #[must_use]
13786 pub const fn apply(value: u64) -> u128 {
13787 value as u128
13788 }
13789}
13790
13791impl Embed<W64, W112> {
13792 #[inline]
13794 #[must_use]
13795 pub const fn apply(value: u64) -> u128 {
13796 value as u128
13797 }
13798}
13799
13800impl Embed<W64, W120> {
13801 #[inline]
13803 #[must_use]
13804 pub const fn apply(value: u64) -> u128 {
13805 value as u128
13806 }
13807}
13808
13809impl Embed<W64, W128> {
13810 #[inline]
13812 #[must_use]
13813 pub const fn apply(value: u64) -> u128 {
13814 value as u128
13815 }
13816}
13817
13818impl Embed<W72, W72> {
13819 #[inline]
13821 #[must_use]
13822 pub const fn apply(value: u128) -> u128 {
13823 value
13824 }
13825}
13826
13827impl Embed<W72, W80> {
13828 #[inline]
13830 #[must_use]
13831 pub const fn apply(value: u128) -> u128 {
13832 value
13833 }
13834}
13835
13836impl Embed<W72, W88> {
13837 #[inline]
13839 #[must_use]
13840 pub const fn apply(value: u128) -> u128 {
13841 value
13842 }
13843}
13844
13845impl Embed<W72, W96> {
13846 #[inline]
13848 #[must_use]
13849 pub const fn apply(value: u128) -> u128 {
13850 value
13851 }
13852}
13853
13854impl Embed<W72, W104> {
13855 #[inline]
13857 #[must_use]
13858 pub const fn apply(value: u128) -> u128 {
13859 value
13860 }
13861}
13862
13863impl Embed<W72, W112> {
13864 #[inline]
13866 #[must_use]
13867 pub const fn apply(value: u128) -> u128 {
13868 value
13869 }
13870}
13871
13872impl Embed<W72, W120> {
13873 #[inline]
13875 #[must_use]
13876 pub const fn apply(value: u128) -> u128 {
13877 value
13878 }
13879}
13880
13881impl Embed<W72, W128> {
13882 #[inline]
13884 #[must_use]
13885 pub const fn apply(value: u128) -> u128 {
13886 value
13887 }
13888}
13889
13890impl Embed<W80, W80> {
13891 #[inline]
13893 #[must_use]
13894 pub const fn apply(value: u128) -> u128 {
13895 value
13896 }
13897}
13898
13899impl Embed<W80, W88> {
13900 #[inline]
13902 #[must_use]
13903 pub const fn apply(value: u128) -> u128 {
13904 value
13905 }
13906}
13907
13908impl Embed<W80, W96> {
13909 #[inline]
13911 #[must_use]
13912 pub const fn apply(value: u128) -> u128 {
13913 value
13914 }
13915}
13916
13917impl Embed<W80, W104> {
13918 #[inline]
13920 #[must_use]
13921 pub const fn apply(value: u128) -> u128 {
13922 value
13923 }
13924}
13925
13926impl Embed<W80, W112> {
13927 #[inline]
13929 #[must_use]
13930 pub const fn apply(value: u128) -> u128 {
13931 value
13932 }
13933}
13934
13935impl Embed<W80, W120> {
13936 #[inline]
13938 #[must_use]
13939 pub const fn apply(value: u128) -> u128 {
13940 value
13941 }
13942}
13943
13944impl Embed<W80, W128> {
13945 #[inline]
13947 #[must_use]
13948 pub const fn apply(value: u128) -> u128 {
13949 value
13950 }
13951}
13952
13953impl Embed<W88, W88> {
13954 #[inline]
13956 #[must_use]
13957 pub const fn apply(value: u128) -> u128 {
13958 value
13959 }
13960}
13961
13962impl Embed<W88, W96> {
13963 #[inline]
13965 #[must_use]
13966 pub const fn apply(value: u128) -> u128 {
13967 value
13968 }
13969}
13970
13971impl Embed<W88, W104> {
13972 #[inline]
13974 #[must_use]
13975 pub const fn apply(value: u128) -> u128 {
13976 value
13977 }
13978}
13979
13980impl Embed<W88, W112> {
13981 #[inline]
13983 #[must_use]
13984 pub const fn apply(value: u128) -> u128 {
13985 value
13986 }
13987}
13988
13989impl Embed<W88, W120> {
13990 #[inline]
13992 #[must_use]
13993 pub const fn apply(value: u128) -> u128 {
13994 value
13995 }
13996}
13997
13998impl Embed<W88, W128> {
13999 #[inline]
14001 #[must_use]
14002 pub const fn apply(value: u128) -> u128 {
14003 value
14004 }
14005}
14006
14007impl Embed<W96, W96> {
14008 #[inline]
14010 #[must_use]
14011 pub const fn apply(value: u128) -> u128 {
14012 value
14013 }
14014}
14015
14016impl Embed<W96, W104> {
14017 #[inline]
14019 #[must_use]
14020 pub const fn apply(value: u128) -> u128 {
14021 value
14022 }
14023}
14024
14025impl Embed<W96, W112> {
14026 #[inline]
14028 #[must_use]
14029 pub const fn apply(value: u128) -> u128 {
14030 value
14031 }
14032}
14033
14034impl Embed<W96, W120> {
14035 #[inline]
14037 #[must_use]
14038 pub const fn apply(value: u128) -> u128 {
14039 value
14040 }
14041}
14042
14043impl Embed<W96, W128> {
14044 #[inline]
14046 #[must_use]
14047 pub const fn apply(value: u128) -> u128 {
14048 value
14049 }
14050}
14051
14052impl Embed<W104, W104> {
14053 #[inline]
14055 #[must_use]
14056 pub const fn apply(value: u128) -> u128 {
14057 value
14058 }
14059}
14060
14061impl Embed<W104, W112> {
14062 #[inline]
14064 #[must_use]
14065 pub const fn apply(value: u128) -> u128 {
14066 value
14067 }
14068}
14069
14070impl Embed<W104, W120> {
14071 #[inline]
14073 #[must_use]
14074 pub const fn apply(value: u128) -> u128 {
14075 value
14076 }
14077}
14078
14079impl Embed<W104, W128> {
14080 #[inline]
14082 #[must_use]
14083 pub const fn apply(value: u128) -> u128 {
14084 value
14085 }
14086}
14087
14088impl Embed<W112, W112> {
14089 #[inline]
14091 #[must_use]
14092 pub const fn apply(value: u128) -> u128 {
14093 value
14094 }
14095}
14096
14097impl Embed<W112, W120> {
14098 #[inline]
14100 #[must_use]
14101 pub const fn apply(value: u128) -> u128 {
14102 value
14103 }
14104}
14105
14106impl Embed<W112, W128> {
14107 #[inline]
14109 #[must_use]
14110 pub const fn apply(value: u128) -> u128 {
14111 value
14112 }
14113}
14114
14115impl Embed<W120, W120> {
14116 #[inline]
14118 #[must_use]
14119 pub const fn apply(value: u128) -> u128 {
14120 value
14121 }
14122}
14123
14124impl Embed<W120, W128> {
14125 #[inline]
14127 #[must_use]
14128 pub const fn apply(value: u128) -> u128 {
14129 value
14130 }
14131}
14132
14133impl Embed<W128, W128> {
14134 #[inline]
14136 #[must_use]
14137 pub const fn apply(value: u128) -> u128 {
14138 value
14139 }
14140}
14141
14142#[derive(Debug, Default, Clone, Copy)]
14146pub struct W160;
14147
14148#[derive(Debug, Default, Clone, Copy)]
14150pub struct W192;
14151
14152#[derive(Debug, Default, Clone, Copy)]
14154pub struct W224;
14155
14156#[derive(Debug, Default, Clone, Copy)]
14158pub struct W256;
14159
14160#[derive(Debug, Default, Clone, Copy)]
14162pub struct W384;
14163
14164#[derive(Debug, Default, Clone, Copy)]
14166pub struct W448;
14167
14168#[derive(Debug, Default, Clone, Copy)]
14170pub struct W512;
14171
14172#[derive(Debug, Default, Clone, Copy)]
14174pub struct W520;
14175
14176#[derive(Debug, Default, Clone, Copy)]
14178pub struct W528;
14179
14180#[derive(Debug, Default, Clone, Copy)]
14182pub struct W1024;
14183
14184#[derive(Debug, Default, Clone, Copy)]
14186pub struct W2048;
14187
14188#[derive(Debug, Default, Clone, Copy)]
14190pub struct W4096;
14191
14192#[derive(Debug, Default, Clone, Copy)]
14194pub struct W8192;
14195
14196#[derive(Debug, Default, Clone, Copy)]
14198pub struct W12288;
14199
14200#[derive(Debug, Default, Clone, Copy)]
14202pub struct W16384;
14203
14204#[derive(Debug, Default, Clone, Copy)]
14206pub struct W32768;
14207
14208impl RingOp<W160> for Mul<W160> {
14209 type Operand = Limbs<3>;
14210 #[inline]
14211 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14212 a.wrapping_mul(b).mask_high_bits(160)
14213 }
14214}
14215
14216impl RingOp<W160> for Add<W160> {
14217 type Operand = Limbs<3>;
14218 #[inline]
14219 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14220 a.wrapping_add(b).mask_high_bits(160)
14221 }
14222}
14223
14224impl RingOp<W160> for Sub<W160> {
14225 type Operand = Limbs<3>;
14226 #[inline]
14227 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14228 a.wrapping_sub(b).mask_high_bits(160)
14229 }
14230}
14231
14232impl RingOp<W160> for Xor<W160> {
14233 type Operand = Limbs<3>;
14234 #[inline]
14235 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14236 a.xor(b).mask_high_bits(160)
14237 }
14238}
14239
14240impl RingOp<W160> for And<W160> {
14241 type Operand = Limbs<3>;
14242 #[inline]
14243 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14244 a.and(b).mask_high_bits(160)
14245 }
14246}
14247
14248impl RingOp<W160> for Or<W160> {
14249 type Operand = Limbs<3>;
14250 #[inline]
14251 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14252 a.or(b).mask_high_bits(160)
14253 }
14254}
14255
14256impl UnaryRingOp<W160> for Neg<W160> {
14257 type Operand = Limbs<3>;
14258 #[inline]
14259 fn apply(a: Limbs<3>) -> Limbs<3> {
14260 (Limbs::<3>::zero().wrapping_sub(a)).mask_high_bits(160)
14261 }
14262}
14263
14264impl UnaryRingOp<W160> for BNot<W160> {
14265 type Operand = Limbs<3>;
14266 #[inline]
14267 fn apply(a: Limbs<3>) -> Limbs<3> {
14268 (a.not()).mask_high_bits(160)
14269 }
14270}
14271
14272impl UnaryRingOp<W160> for Succ<W160> {
14273 type Operand = Limbs<3>;
14274 #[inline]
14275 fn apply(a: Limbs<3>) -> Limbs<3> {
14276 (a.wrapping_add(Limbs::<3>::from_words([1u64, 0u64, 0u64]))).mask_high_bits(160)
14277 }
14278}
14279
14280impl RingOp<W192> for Mul<W192> {
14281 type Operand = Limbs<3>;
14282 #[inline]
14283 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14284 a.wrapping_mul(b)
14285 }
14286}
14287
14288impl RingOp<W192> for Add<W192> {
14289 type Operand = Limbs<3>;
14290 #[inline]
14291 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14292 a.wrapping_add(b)
14293 }
14294}
14295
14296impl RingOp<W192> for Sub<W192> {
14297 type Operand = Limbs<3>;
14298 #[inline]
14299 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14300 a.wrapping_sub(b)
14301 }
14302}
14303
14304impl RingOp<W192> for Xor<W192> {
14305 type Operand = Limbs<3>;
14306 #[inline]
14307 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14308 a.xor(b)
14309 }
14310}
14311
14312impl RingOp<W192> for And<W192> {
14313 type Operand = Limbs<3>;
14314 #[inline]
14315 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14316 a.and(b)
14317 }
14318}
14319
14320impl RingOp<W192> for Or<W192> {
14321 type Operand = Limbs<3>;
14322 #[inline]
14323 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14324 a.or(b)
14325 }
14326}
14327
14328impl UnaryRingOp<W192> for Neg<W192> {
14329 type Operand = Limbs<3>;
14330 #[inline]
14331 fn apply(a: Limbs<3>) -> Limbs<3> {
14332 Limbs::<3>::zero().wrapping_sub(a)
14333 }
14334}
14335
14336impl UnaryRingOp<W192> for BNot<W192> {
14337 type Operand = Limbs<3>;
14338 #[inline]
14339 fn apply(a: Limbs<3>) -> Limbs<3> {
14340 a.not()
14341 }
14342}
14343
14344impl UnaryRingOp<W192> for Succ<W192> {
14345 type Operand = Limbs<3>;
14346 #[inline]
14347 fn apply(a: Limbs<3>) -> Limbs<3> {
14348 a.wrapping_add(Limbs::<3>::from_words([1u64, 0u64, 0u64]))
14349 }
14350}
14351
14352impl RingOp<W224> for Mul<W224> {
14353 type Operand = Limbs<4>;
14354 #[inline]
14355 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14356 a.wrapping_mul(b).mask_high_bits(224)
14357 }
14358}
14359
14360impl RingOp<W224> for Add<W224> {
14361 type Operand = Limbs<4>;
14362 #[inline]
14363 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14364 a.wrapping_add(b).mask_high_bits(224)
14365 }
14366}
14367
14368impl RingOp<W224> for Sub<W224> {
14369 type Operand = Limbs<4>;
14370 #[inline]
14371 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14372 a.wrapping_sub(b).mask_high_bits(224)
14373 }
14374}
14375
14376impl RingOp<W224> for Xor<W224> {
14377 type Operand = Limbs<4>;
14378 #[inline]
14379 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14380 a.xor(b).mask_high_bits(224)
14381 }
14382}
14383
14384impl RingOp<W224> for And<W224> {
14385 type Operand = Limbs<4>;
14386 #[inline]
14387 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14388 a.and(b).mask_high_bits(224)
14389 }
14390}
14391
14392impl RingOp<W224> for Or<W224> {
14393 type Operand = Limbs<4>;
14394 #[inline]
14395 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14396 a.or(b).mask_high_bits(224)
14397 }
14398}
14399
14400impl UnaryRingOp<W224> for Neg<W224> {
14401 type Operand = Limbs<4>;
14402 #[inline]
14403 fn apply(a: Limbs<4>) -> Limbs<4> {
14404 (Limbs::<4>::zero().wrapping_sub(a)).mask_high_bits(224)
14405 }
14406}
14407
14408impl UnaryRingOp<W224> for BNot<W224> {
14409 type Operand = Limbs<4>;
14410 #[inline]
14411 fn apply(a: Limbs<4>) -> Limbs<4> {
14412 (a.not()).mask_high_bits(224)
14413 }
14414}
14415
14416impl UnaryRingOp<W224> for Succ<W224> {
14417 type Operand = Limbs<4>;
14418 #[inline]
14419 fn apply(a: Limbs<4>) -> Limbs<4> {
14420 (a.wrapping_add(Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64]))).mask_high_bits(224)
14421 }
14422}
14423
14424impl RingOp<W256> for Mul<W256> {
14425 type Operand = Limbs<4>;
14426 #[inline]
14427 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14428 a.wrapping_mul(b)
14429 }
14430}
14431
14432impl RingOp<W256> for Add<W256> {
14433 type Operand = Limbs<4>;
14434 #[inline]
14435 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14436 a.wrapping_add(b)
14437 }
14438}
14439
14440impl RingOp<W256> for Sub<W256> {
14441 type Operand = Limbs<4>;
14442 #[inline]
14443 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14444 a.wrapping_sub(b)
14445 }
14446}
14447
14448impl RingOp<W256> for Xor<W256> {
14449 type Operand = Limbs<4>;
14450 #[inline]
14451 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14452 a.xor(b)
14453 }
14454}
14455
14456impl RingOp<W256> for And<W256> {
14457 type Operand = Limbs<4>;
14458 #[inline]
14459 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14460 a.and(b)
14461 }
14462}
14463
14464impl RingOp<W256> for Or<W256> {
14465 type Operand = Limbs<4>;
14466 #[inline]
14467 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14468 a.or(b)
14469 }
14470}
14471
14472impl UnaryRingOp<W256> for Neg<W256> {
14473 type Operand = Limbs<4>;
14474 #[inline]
14475 fn apply(a: Limbs<4>) -> Limbs<4> {
14476 Limbs::<4>::zero().wrapping_sub(a)
14477 }
14478}
14479
14480impl UnaryRingOp<W256> for BNot<W256> {
14481 type Operand = Limbs<4>;
14482 #[inline]
14483 fn apply(a: Limbs<4>) -> Limbs<4> {
14484 a.not()
14485 }
14486}
14487
14488impl UnaryRingOp<W256> for Succ<W256> {
14489 type Operand = Limbs<4>;
14490 #[inline]
14491 fn apply(a: Limbs<4>) -> Limbs<4> {
14492 a.wrapping_add(Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64]))
14493 }
14494}
14495
14496impl RingOp<W384> for Mul<W384> {
14497 type Operand = Limbs<6>;
14498 #[inline]
14499 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14500 a.wrapping_mul(b)
14501 }
14502}
14503
14504impl RingOp<W384> for Add<W384> {
14505 type Operand = Limbs<6>;
14506 #[inline]
14507 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14508 a.wrapping_add(b)
14509 }
14510}
14511
14512impl RingOp<W384> for Sub<W384> {
14513 type Operand = Limbs<6>;
14514 #[inline]
14515 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14516 a.wrapping_sub(b)
14517 }
14518}
14519
14520impl RingOp<W384> for Xor<W384> {
14521 type Operand = Limbs<6>;
14522 #[inline]
14523 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14524 a.xor(b)
14525 }
14526}
14527
14528impl RingOp<W384> for And<W384> {
14529 type Operand = Limbs<6>;
14530 #[inline]
14531 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14532 a.and(b)
14533 }
14534}
14535
14536impl RingOp<W384> for Or<W384> {
14537 type Operand = Limbs<6>;
14538 #[inline]
14539 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14540 a.or(b)
14541 }
14542}
14543
14544impl UnaryRingOp<W384> for Neg<W384> {
14545 type Operand = Limbs<6>;
14546 #[inline]
14547 fn apply(a: Limbs<6>) -> Limbs<6> {
14548 Limbs::<6>::zero().wrapping_sub(a)
14549 }
14550}
14551
14552impl UnaryRingOp<W384> for BNot<W384> {
14553 type Operand = Limbs<6>;
14554 #[inline]
14555 fn apply(a: Limbs<6>) -> Limbs<6> {
14556 a.not()
14557 }
14558}
14559
14560impl UnaryRingOp<W384> for Succ<W384> {
14561 type Operand = Limbs<6>;
14562 #[inline]
14563 fn apply(a: Limbs<6>) -> Limbs<6> {
14564 a.wrapping_add(Limbs::<6>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64]))
14565 }
14566}
14567
14568impl RingOp<W448> for Mul<W448> {
14569 type Operand = Limbs<7>;
14570 #[inline]
14571 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14572 a.wrapping_mul(b)
14573 }
14574}
14575
14576impl RingOp<W448> for Add<W448> {
14577 type Operand = Limbs<7>;
14578 #[inline]
14579 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14580 a.wrapping_add(b)
14581 }
14582}
14583
14584impl RingOp<W448> for Sub<W448> {
14585 type Operand = Limbs<7>;
14586 #[inline]
14587 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14588 a.wrapping_sub(b)
14589 }
14590}
14591
14592impl RingOp<W448> for Xor<W448> {
14593 type Operand = Limbs<7>;
14594 #[inline]
14595 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14596 a.xor(b)
14597 }
14598}
14599
14600impl RingOp<W448> for And<W448> {
14601 type Operand = Limbs<7>;
14602 #[inline]
14603 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14604 a.and(b)
14605 }
14606}
14607
14608impl RingOp<W448> for Or<W448> {
14609 type Operand = Limbs<7>;
14610 #[inline]
14611 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14612 a.or(b)
14613 }
14614}
14615
14616impl UnaryRingOp<W448> for Neg<W448> {
14617 type Operand = Limbs<7>;
14618 #[inline]
14619 fn apply(a: Limbs<7>) -> Limbs<7> {
14620 Limbs::<7>::zero().wrapping_sub(a)
14621 }
14622}
14623
14624impl UnaryRingOp<W448> for BNot<W448> {
14625 type Operand = Limbs<7>;
14626 #[inline]
14627 fn apply(a: Limbs<7>) -> Limbs<7> {
14628 a.not()
14629 }
14630}
14631
14632impl UnaryRingOp<W448> for Succ<W448> {
14633 type Operand = Limbs<7>;
14634 #[inline]
14635 fn apply(a: Limbs<7>) -> Limbs<7> {
14636 a.wrapping_add(Limbs::<7>::from_words([
14637 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14638 ]))
14639 }
14640}
14641
14642impl RingOp<W512> for Mul<W512> {
14643 type Operand = Limbs<8>;
14644 #[inline]
14645 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14646 a.wrapping_mul(b)
14647 }
14648}
14649
14650impl RingOp<W512> for Add<W512> {
14651 type Operand = Limbs<8>;
14652 #[inline]
14653 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14654 a.wrapping_add(b)
14655 }
14656}
14657
14658impl RingOp<W512> for Sub<W512> {
14659 type Operand = Limbs<8>;
14660 #[inline]
14661 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14662 a.wrapping_sub(b)
14663 }
14664}
14665
14666impl RingOp<W512> for Xor<W512> {
14667 type Operand = Limbs<8>;
14668 #[inline]
14669 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14670 a.xor(b)
14671 }
14672}
14673
14674impl RingOp<W512> for And<W512> {
14675 type Operand = Limbs<8>;
14676 #[inline]
14677 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14678 a.and(b)
14679 }
14680}
14681
14682impl RingOp<W512> for Or<W512> {
14683 type Operand = Limbs<8>;
14684 #[inline]
14685 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14686 a.or(b)
14687 }
14688}
14689
14690impl UnaryRingOp<W512> for Neg<W512> {
14691 type Operand = Limbs<8>;
14692 #[inline]
14693 fn apply(a: Limbs<8>) -> Limbs<8> {
14694 Limbs::<8>::zero().wrapping_sub(a)
14695 }
14696}
14697
14698impl UnaryRingOp<W512> for BNot<W512> {
14699 type Operand = Limbs<8>;
14700 #[inline]
14701 fn apply(a: Limbs<8>) -> Limbs<8> {
14702 a.not()
14703 }
14704}
14705
14706impl UnaryRingOp<W512> for Succ<W512> {
14707 type Operand = Limbs<8>;
14708 #[inline]
14709 fn apply(a: Limbs<8>) -> Limbs<8> {
14710 a.wrapping_add(Limbs::<8>::from_words([
14711 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14712 ]))
14713 }
14714}
14715
14716impl RingOp<W520> for Mul<W520> {
14717 type Operand = Limbs<9>;
14718 #[inline]
14719 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14720 a.wrapping_mul(b).mask_high_bits(520)
14721 }
14722}
14723
14724impl RingOp<W520> for Add<W520> {
14725 type Operand = Limbs<9>;
14726 #[inline]
14727 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14728 a.wrapping_add(b).mask_high_bits(520)
14729 }
14730}
14731
14732impl RingOp<W520> for Sub<W520> {
14733 type Operand = Limbs<9>;
14734 #[inline]
14735 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14736 a.wrapping_sub(b).mask_high_bits(520)
14737 }
14738}
14739
14740impl RingOp<W520> for Xor<W520> {
14741 type Operand = Limbs<9>;
14742 #[inline]
14743 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14744 a.xor(b).mask_high_bits(520)
14745 }
14746}
14747
14748impl RingOp<W520> for And<W520> {
14749 type Operand = Limbs<9>;
14750 #[inline]
14751 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14752 a.and(b).mask_high_bits(520)
14753 }
14754}
14755
14756impl RingOp<W520> for Or<W520> {
14757 type Operand = Limbs<9>;
14758 #[inline]
14759 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14760 a.or(b).mask_high_bits(520)
14761 }
14762}
14763
14764impl UnaryRingOp<W520> for Neg<W520> {
14765 type Operand = Limbs<9>;
14766 #[inline]
14767 fn apply(a: Limbs<9>) -> Limbs<9> {
14768 (Limbs::<9>::zero().wrapping_sub(a)).mask_high_bits(520)
14769 }
14770}
14771
14772impl UnaryRingOp<W520> for BNot<W520> {
14773 type Operand = Limbs<9>;
14774 #[inline]
14775 fn apply(a: Limbs<9>) -> Limbs<9> {
14776 (a.not()).mask_high_bits(520)
14777 }
14778}
14779
14780impl UnaryRingOp<W520> for Succ<W520> {
14781 type Operand = Limbs<9>;
14782 #[inline]
14783 fn apply(a: Limbs<9>) -> Limbs<9> {
14784 (a.wrapping_add(Limbs::<9>::from_words([
14785 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14786 ])))
14787 .mask_high_bits(520)
14788 }
14789}
14790
14791impl RingOp<W528> for Mul<W528> {
14792 type Operand = Limbs<9>;
14793 #[inline]
14794 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14795 a.wrapping_mul(b).mask_high_bits(528)
14796 }
14797}
14798
14799impl RingOp<W528> for Add<W528> {
14800 type Operand = Limbs<9>;
14801 #[inline]
14802 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14803 a.wrapping_add(b).mask_high_bits(528)
14804 }
14805}
14806
14807impl RingOp<W528> for Sub<W528> {
14808 type Operand = Limbs<9>;
14809 #[inline]
14810 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14811 a.wrapping_sub(b).mask_high_bits(528)
14812 }
14813}
14814
14815impl RingOp<W528> for Xor<W528> {
14816 type Operand = Limbs<9>;
14817 #[inline]
14818 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14819 a.xor(b).mask_high_bits(528)
14820 }
14821}
14822
14823impl RingOp<W528> for And<W528> {
14824 type Operand = Limbs<9>;
14825 #[inline]
14826 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14827 a.and(b).mask_high_bits(528)
14828 }
14829}
14830
14831impl RingOp<W528> for Or<W528> {
14832 type Operand = Limbs<9>;
14833 #[inline]
14834 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14835 a.or(b).mask_high_bits(528)
14836 }
14837}
14838
14839impl UnaryRingOp<W528> for Neg<W528> {
14840 type Operand = Limbs<9>;
14841 #[inline]
14842 fn apply(a: Limbs<9>) -> Limbs<9> {
14843 (Limbs::<9>::zero().wrapping_sub(a)).mask_high_bits(528)
14844 }
14845}
14846
14847impl UnaryRingOp<W528> for BNot<W528> {
14848 type Operand = Limbs<9>;
14849 #[inline]
14850 fn apply(a: Limbs<9>) -> Limbs<9> {
14851 (a.not()).mask_high_bits(528)
14852 }
14853}
14854
14855impl UnaryRingOp<W528> for Succ<W528> {
14856 type Operand = Limbs<9>;
14857 #[inline]
14858 fn apply(a: Limbs<9>) -> Limbs<9> {
14859 (a.wrapping_add(Limbs::<9>::from_words([
14860 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14861 ])))
14862 .mask_high_bits(528)
14863 }
14864}
14865
14866impl RingOp<W1024> for Mul<W1024> {
14867 type Operand = Limbs<16>;
14868 #[inline]
14869 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14870 a.wrapping_mul(b)
14871 }
14872}
14873
14874impl RingOp<W1024> for Add<W1024> {
14875 type Operand = Limbs<16>;
14876 #[inline]
14877 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14878 a.wrapping_add(b)
14879 }
14880}
14881
14882impl RingOp<W1024> for Sub<W1024> {
14883 type Operand = Limbs<16>;
14884 #[inline]
14885 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14886 a.wrapping_sub(b)
14887 }
14888}
14889
14890impl RingOp<W1024> for Xor<W1024> {
14891 type Operand = Limbs<16>;
14892 #[inline]
14893 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14894 a.xor(b)
14895 }
14896}
14897
14898impl RingOp<W1024> for And<W1024> {
14899 type Operand = Limbs<16>;
14900 #[inline]
14901 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14902 a.and(b)
14903 }
14904}
14905
14906impl RingOp<W1024> for Or<W1024> {
14907 type Operand = Limbs<16>;
14908 #[inline]
14909 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14910 a.or(b)
14911 }
14912}
14913
14914impl UnaryRingOp<W1024> for Neg<W1024> {
14915 type Operand = Limbs<16>;
14916 #[inline]
14917 fn apply(a: Limbs<16>) -> Limbs<16> {
14918 Limbs::<16>::zero().wrapping_sub(a)
14919 }
14920}
14921
14922impl UnaryRingOp<W1024> for BNot<W1024> {
14923 type Operand = Limbs<16>;
14924 #[inline]
14925 fn apply(a: Limbs<16>) -> Limbs<16> {
14926 a.not()
14927 }
14928}
14929
14930impl UnaryRingOp<W1024> for Succ<W1024> {
14931 type Operand = Limbs<16>;
14932 #[inline]
14933 fn apply(a: Limbs<16>) -> Limbs<16> {
14934 a.wrapping_add(Limbs::<16>::from_words([
14935 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14936 0u64, 0u64,
14937 ]))
14938 }
14939}
14940
14941impl RingOp<W2048> for Mul<W2048> {
14942 type Operand = Limbs<32>;
14943 #[inline]
14944 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14945 a.wrapping_mul(b)
14946 }
14947}
14948
14949impl RingOp<W2048> for Add<W2048> {
14950 type Operand = Limbs<32>;
14951 #[inline]
14952 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14953 a.wrapping_add(b)
14954 }
14955}
14956
14957impl RingOp<W2048> for Sub<W2048> {
14958 type Operand = Limbs<32>;
14959 #[inline]
14960 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14961 a.wrapping_sub(b)
14962 }
14963}
14964
14965impl RingOp<W2048> for Xor<W2048> {
14966 type Operand = Limbs<32>;
14967 #[inline]
14968 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14969 a.xor(b)
14970 }
14971}
14972
14973impl RingOp<W2048> for And<W2048> {
14974 type Operand = Limbs<32>;
14975 #[inline]
14976 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14977 a.and(b)
14978 }
14979}
14980
14981impl RingOp<W2048> for Or<W2048> {
14982 type Operand = Limbs<32>;
14983 #[inline]
14984 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14985 a.or(b)
14986 }
14987}
14988
14989impl UnaryRingOp<W2048> for Neg<W2048> {
14990 type Operand = Limbs<32>;
14991 #[inline]
14992 fn apply(a: Limbs<32>) -> Limbs<32> {
14993 Limbs::<32>::zero().wrapping_sub(a)
14994 }
14995}
14996
14997impl UnaryRingOp<W2048> for BNot<W2048> {
14998 type Operand = Limbs<32>;
14999 #[inline]
15000 fn apply(a: Limbs<32>) -> Limbs<32> {
15001 a.not()
15002 }
15003}
15004
15005impl UnaryRingOp<W2048> for Succ<W2048> {
15006 type Operand = Limbs<32>;
15007 #[inline]
15008 fn apply(a: Limbs<32>) -> Limbs<32> {
15009 a.wrapping_add(Limbs::<32>::from_words([
15010 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15011 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15012 0u64, 0u64, 0u64, 0u64,
15013 ]))
15014 }
15015}
15016
15017impl RingOp<W4096> for Mul<W4096> {
15018 type Operand = Limbs<64>;
15019 #[inline]
15020 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15021 a.wrapping_mul(b)
15022 }
15023}
15024
15025impl RingOp<W4096> for Add<W4096> {
15026 type Operand = Limbs<64>;
15027 #[inline]
15028 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15029 a.wrapping_add(b)
15030 }
15031}
15032
15033impl RingOp<W4096> for Sub<W4096> {
15034 type Operand = Limbs<64>;
15035 #[inline]
15036 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15037 a.wrapping_sub(b)
15038 }
15039}
15040
15041impl RingOp<W4096> for Xor<W4096> {
15042 type Operand = Limbs<64>;
15043 #[inline]
15044 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15045 a.xor(b)
15046 }
15047}
15048
15049impl RingOp<W4096> for And<W4096> {
15050 type Operand = Limbs<64>;
15051 #[inline]
15052 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15053 a.and(b)
15054 }
15055}
15056
15057impl RingOp<W4096> for Or<W4096> {
15058 type Operand = Limbs<64>;
15059 #[inline]
15060 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15061 a.or(b)
15062 }
15063}
15064
15065impl UnaryRingOp<W4096> for Neg<W4096> {
15066 type Operand = Limbs<64>;
15067 #[inline]
15068 fn apply(a: Limbs<64>) -> Limbs<64> {
15069 Limbs::<64>::zero().wrapping_sub(a)
15070 }
15071}
15072
15073impl UnaryRingOp<W4096> for BNot<W4096> {
15074 type Operand = Limbs<64>;
15075 #[inline]
15076 fn apply(a: Limbs<64>) -> Limbs<64> {
15077 a.not()
15078 }
15079}
15080
15081impl UnaryRingOp<W4096> for Succ<W4096> {
15082 type Operand = Limbs<64>;
15083 #[inline]
15084 fn apply(a: Limbs<64>) -> Limbs<64> {
15085 a.wrapping_add(Limbs::<64>::from_words([
15086 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15087 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15088 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15089 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15090 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15091 ]))
15092 }
15093}
15094
15095impl RingOp<W8192> for Mul<W8192> {
15096 type Operand = Limbs<128>;
15097 #[inline]
15098 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15099 a.wrapping_mul(b)
15100 }
15101}
15102
15103impl RingOp<W8192> for Add<W8192> {
15104 type Operand = Limbs<128>;
15105 #[inline]
15106 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15107 a.wrapping_add(b)
15108 }
15109}
15110
15111impl RingOp<W8192> for Sub<W8192> {
15112 type Operand = Limbs<128>;
15113 #[inline]
15114 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15115 a.wrapping_sub(b)
15116 }
15117}
15118
15119impl RingOp<W8192> for Xor<W8192> {
15120 type Operand = Limbs<128>;
15121 #[inline]
15122 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15123 a.xor(b)
15124 }
15125}
15126
15127impl RingOp<W8192> for And<W8192> {
15128 type Operand = Limbs<128>;
15129 #[inline]
15130 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15131 a.and(b)
15132 }
15133}
15134
15135impl RingOp<W8192> for Or<W8192> {
15136 type Operand = Limbs<128>;
15137 #[inline]
15138 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15139 a.or(b)
15140 }
15141}
15142
15143impl UnaryRingOp<W8192> for Neg<W8192> {
15144 type Operand = Limbs<128>;
15145 #[inline]
15146 fn apply(a: Limbs<128>) -> Limbs<128> {
15147 Limbs::<128>::zero().wrapping_sub(a)
15148 }
15149}
15150
15151impl UnaryRingOp<W8192> for BNot<W8192> {
15152 type Operand = Limbs<128>;
15153 #[inline]
15154 fn apply(a: Limbs<128>) -> Limbs<128> {
15155 a.not()
15156 }
15157}
15158
15159impl UnaryRingOp<W8192> for Succ<W8192> {
15160 type Operand = Limbs<128>;
15161 #[inline]
15162 fn apply(a: Limbs<128>) -> Limbs<128> {
15163 a.wrapping_add(Limbs::<128>::from_words([
15164 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15165 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15166 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15167 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15168 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15169 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15170 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15171 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15172 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15173 0u64, 0u64,
15174 ]))
15175 }
15176}
15177
15178impl RingOp<W12288> for Mul<W12288> {
15179 type Operand = Limbs<192>;
15180 #[inline]
15181 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15182 a.wrapping_mul(b)
15183 }
15184}
15185
15186impl RingOp<W12288> for Add<W12288> {
15187 type Operand = Limbs<192>;
15188 #[inline]
15189 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15190 a.wrapping_add(b)
15191 }
15192}
15193
15194impl RingOp<W12288> for Sub<W12288> {
15195 type Operand = Limbs<192>;
15196 #[inline]
15197 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15198 a.wrapping_sub(b)
15199 }
15200}
15201
15202impl RingOp<W12288> for Xor<W12288> {
15203 type Operand = Limbs<192>;
15204 #[inline]
15205 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15206 a.xor(b)
15207 }
15208}
15209
15210impl RingOp<W12288> for And<W12288> {
15211 type Operand = Limbs<192>;
15212 #[inline]
15213 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15214 a.and(b)
15215 }
15216}
15217
15218impl RingOp<W12288> for Or<W12288> {
15219 type Operand = Limbs<192>;
15220 #[inline]
15221 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15222 a.or(b)
15223 }
15224}
15225
15226impl UnaryRingOp<W12288> for Neg<W12288> {
15227 type Operand = Limbs<192>;
15228 #[inline]
15229 fn apply(a: Limbs<192>) -> Limbs<192> {
15230 Limbs::<192>::zero().wrapping_sub(a)
15231 }
15232}
15233
15234impl UnaryRingOp<W12288> for BNot<W12288> {
15235 type Operand = Limbs<192>;
15236 #[inline]
15237 fn apply(a: Limbs<192>) -> Limbs<192> {
15238 a.not()
15239 }
15240}
15241
15242impl UnaryRingOp<W12288> for Succ<W12288> {
15243 type Operand = Limbs<192>;
15244 #[inline]
15245 fn apply(a: Limbs<192>) -> Limbs<192> {
15246 a.wrapping_add(Limbs::<192>::from_words([
15247 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15248 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15249 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15250 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15251 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15252 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15253 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15254 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15255 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15256 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15257 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15258 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15259 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15260 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15261 ]))
15262 }
15263}
15264
15265impl RingOp<W16384> for Mul<W16384> {
15266 type Operand = Limbs<256>;
15267 #[inline]
15268 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15269 a.wrapping_mul(b)
15270 }
15271}
15272
15273impl RingOp<W16384> for Add<W16384> {
15274 type Operand = Limbs<256>;
15275 #[inline]
15276 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15277 a.wrapping_add(b)
15278 }
15279}
15280
15281impl RingOp<W16384> for Sub<W16384> {
15282 type Operand = Limbs<256>;
15283 #[inline]
15284 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15285 a.wrapping_sub(b)
15286 }
15287}
15288
15289impl RingOp<W16384> for Xor<W16384> {
15290 type Operand = Limbs<256>;
15291 #[inline]
15292 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15293 a.xor(b)
15294 }
15295}
15296
15297impl RingOp<W16384> for And<W16384> {
15298 type Operand = Limbs<256>;
15299 #[inline]
15300 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15301 a.and(b)
15302 }
15303}
15304
15305impl RingOp<W16384> for Or<W16384> {
15306 type Operand = Limbs<256>;
15307 #[inline]
15308 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15309 a.or(b)
15310 }
15311}
15312
15313impl UnaryRingOp<W16384> for Neg<W16384> {
15314 type Operand = Limbs<256>;
15315 #[inline]
15316 fn apply(a: Limbs<256>) -> Limbs<256> {
15317 Limbs::<256>::zero().wrapping_sub(a)
15318 }
15319}
15320
15321impl UnaryRingOp<W16384> for BNot<W16384> {
15322 type Operand = Limbs<256>;
15323 #[inline]
15324 fn apply(a: Limbs<256>) -> Limbs<256> {
15325 a.not()
15326 }
15327}
15328
15329impl UnaryRingOp<W16384> for Succ<W16384> {
15330 type Operand = Limbs<256>;
15331 #[inline]
15332 fn apply(a: Limbs<256>) -> Limbs<256> {
15333 a.wrapping_add(Limbs::<256>::from_words([
15334 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15335 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15336 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15337 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15338 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15339 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15340 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15341 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15342 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15343 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15344 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15345 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15346 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15347 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15348 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15349 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15350 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15351 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15352 0u64, 0u64, 0u64, 0u64,
15353 ]))
15354 }
15355}
15356
15357impl RingOp<W32768> for Mul<W32768> {
15358 type Operand = Limbs<512>;
15359 #[inline]
15360 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15361 a.wrapping_mul(b)
15362 }
15363}
15364
15365impl RingOp<W32768> for Add<W32768> {
15366 type Operand = Limbs<512>;
15367 #[inline]
15368 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15369 a.wrapping_add(b)
15370 }
15371}
15372
15373impl RingOp<W32768> for Sub<W32768> {
15374 type Operand = Limbs<512>;
15375 #[inline]
15376 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15377 a.wrapping_sub(b)
15378 }
15379}
15380
15381impl RingOp<W32768> for Xor<W32768> {
15382 type Operand = Limbs<512>;
15383 #[inline]
15384 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15385 a.xor(b)
15386 }
15387}
15388
15389impl RingOp<W32768> for And<W32768> {
15390 type Operand = Limbs<512>;
15391 #[inline]
15392 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15393 a.and(b)
15394 }
15395}
15396
15397impl RingOp<W32768> for Or<W32768> {
15398 type Operand = Limbs<512>;
15399 #[inline]
15400 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15401 a.or(b)
15402 }
15403}
15404
15405impl UnaryRingOp<W32768> for Neg<W32768> {
15406 type Operand = Limbs<512>;
15407 #[inline]
15408 fn apply(a: Limbs<512>) -> Limbs<512> {
15409 Limbs::<512>::zero().wrapping_sub(a)
15410 }
15411}
15412
15413impl UnaryRingOp<W32768> for BNot<W32768> {
15414 type Operand = Limbs<512>;
15415 #[inline]
15416 fn apply(a: Limbs<512>) -> Limbs<512> {
15417 a.not()
15418 }
15419}
15420
15421impl UnaryRingOp<W32768> for Succ<W32768> {
15422 type Operand = Limbs<512>;
15423 #[inline]
15424 fn apply(a: Limbs<512>) -> Limbs<512> {
15425 a.wrapping_add(Limbs::<512>::from_words([
15426 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15427 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15428 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15429 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15430 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15431 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15432 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15433 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15434 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15435 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15436 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15437 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15438 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15439 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15440 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15441 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15442 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15443 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15444 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15445 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15446 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15447 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15448 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15449 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15450 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15451 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15452 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15453 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15454 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15455 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15456 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15457 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15458 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15459 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15460 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15461 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15462 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15463 ]))
15464 }
15465}
15466
15467#[inline]
15474#[must_use]
15475pub const fn const_ring_eval_w160(op: PrimitiveOp, a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
15476 let raw = match op {
15477 PrimitiveOp::Add => a.wrapping_add(b),
15478 PrimitiveOp::Sub => a.wrapping_sub(b),
15479 PrimitiveOp::Mul => a.wrapping_mul(b),
15480 PrimitiveOp::And => a.and(b),
15481 PrimitiveOp::Or => a.or(b),
15482 PrimitiveOp::Xor => a.xor(b),
15483 PrimitiveOp::Neg => Limbs::<3>::zero().wrapping_sub(a),
15484 PrimitiveOp::Bnot => a.not(),
15485 PrimitiveOp::Succ => a.wrapping_add(limbs_one_3()),
15486 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_3()),
15487 PrimitiveOp::Le => {
15488 if limbs_le_3(a, b) {
15489 limbs_one_3()
15490 } else {
15491 Limbs::<3>::zero()
15492 }
15493 }
15494 PrimitiveOp::Lt => {
15495 if limbs_lt_3(a, b) {
15496 limbs_one_3()
15497 } else {
15498 Limbs::<3>::zero()
15499 }
15500 }
15501 PrimitiveOp::Ge => {
15502 if limbs_le_3(b, a) {
15503 limbs_one_3()
15504 } else {
15505 Limbs::<3>::zero()
15506 }
15507 }
15508 PrimitiveOp::Gt => {
15509 if limbs_lt_3(b, a) {
15510 limbs_one_3()
15511 } else {
15512 Limbs::<3>::zero()
15513 }
15514 }
15515 PrimitiveOp::Concat => Limbs::<3>::zero(),
15516 PrimitiveOp::Div => {
15517 if limbs_is_zero_3(b) {
15518 Limbs::<3>::zero()
15519 } else {
15520 limbs_div_3(a, b)
15521 }
15522 }
15523 PrimitiveOp::Mod => {
15524 if limbs_is_zero_3(b) {
15525 Limbs::<3>::zero()
15526 } else {
15527 limbs_mod_3(a, b)
15528 }
15529 }
15530 PrimitiveOp::Pow => limbs_pow_3(a, b),
15531 };
15532 raw.mask_high_bits(160)
15533}
15534
15535#[inline]
15536#[must_use]
15537pub const fn const_ring_eval_w192(op: PrimitiveOp, a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
15538 match op {
15539 PrimitiveOp::Add => a.wrapping_add(b),
15540 PrimitiveOp::Sub => a.wrapping_sub(b),
15541 PrimitiveOp::Mul => a.wrapping_mul(b),
15542 PrimitiveOp::And => a.and(b),
15543 PrimitiveOp::Or => a.or(b),
15544 PrimitiveOp::Xor => a.xor(b),
15545 PrimitiveOp::Neg => Limbs::<3>::zero().wrapping_sub(a),
15546 PrimitiveOp::Bnot => a.not(),
15547 PrimitiveOp::Succ => a.wrapping_add(limbs_one_3()),
15548 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_3()),
15549 PrimitiveOp::Le => {
15550 if limbs_le_3(a, b) {
15551 limbs_one_3()
15552 } else {
15553 Limbs::<3>::zero()
15554 }
15555 }
15556 PrimitiveOp::Lt => {
15557 if limbs_lt_3(a, b) {
15558 limbs_one_3()
15559 } else {
15560 Limbs::<3>::zero()
15561 }
15562 }
15563 PrimitiveOp::Ge => {
15564 if limbs_le_3(b, a) {
15565 limbs_one_3()
15566 } else {
15567 Limbs::<3>::zero()
15568 }
15569 }
15570 PrimitiveOp::Gt => {
15571 if limbs_lt_3(b, a) {
15572 limbs_one_3()
15573 } else {
15574 Limbs::<3>::zero()
15575 }
15576 }
15577 PrimitiveOp::Concat => Limbs::<3>::zero(),
15578 PrimitiveOp::Div => {
15579 if limbs_is_zero_3(b) {
15580 Limbs::<3>::zero()
15581 } else {
15582 limbs_div_3(a, b)
15583 }
15584 }
15585 PrimitiveOp::Mod => {
15586 if limbs_is_zero_3(b) {
15587 Limbs::<3>::zero()
15588 } else {
15589 limbs_mod_3(a, b)
15590 }
15591 }
15592 PrimitiveOp::Pow => limbs_pow_3(a, b),
15593 }
15594}
15595
15596#[inline]
15597#[must_use]
15598pub const fn const_ring_eval_w224(op: PrimitiveOp, a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
15599 let raw = match op {
15600 PrimitiveOp::Add => a.wrapping_add(b),
15601 PrimitiveOp::Sub => a.wrapping_sub(b),
15602 PrimitiveOp::Mul => a.wrapping_mul(b),
15603 PrimitiveOp::And => a.and(b),
15604 PrimitiveOp::Or => a.or(b),
15605 PrimitiveOp::Xor => a.xor(b),
15606 PrimitiveOp::Neg => Limbs::<4>::zero().wrapping_sub(a),
15607 PrimitiveOp::Bnot => a.not(),
15608 PrimitiveOp::Succ => a.wrapping_add(limbs_one_4()),
15609 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_4()),
15610 PrimitiveOp::Le => {
15611 if limbs_le_4(a, b) {
15612 limbs_one_4()
15613 } else {
15614 Limbs::<4>::zero()
15615 }
15616 }
15617 PrimitiveOp::Lt => {
15618 if limbs_lt_4(a, b) {
15619 limbs_one_4()
15620 } else {
15621 Limbs::<4>::zero()
15622 }
15623 }
15624 PrimitiveOp::Ge => {
15625 if limbs_le_4(b, a) {
15626 limbs_one_4()
15627 } else {
15628 Limbs::<4>::zero()
15629 }
15630 }
15631 PrimitiveOp::Gt => {
15632 if limbs_lt_4(b, a) {
15633 limbs_one_4()
15634 } else {
15635 Limbs::<4>::zero()
15636 }
15637 }
15638 PrimitiveOp::Concat => Limbs::<4>::zero(),
15639 PrimitiveOp::Div => {
15640 if limbs_is_zero_4(b) {
15641 Limbs::<4>::zero()
15642 } else {
15643 limbs_div_4(a, b)
15644 }
15645 }
15646 PrimitiveOp::Mod => {
15647 if limbs_is_zero_4(b) {
15648 Limbs::<4>::zero()
15649 } else {
15650 limbs_mod_4(a, b)
15651 }
15652 }
15653 PrimitiveOp::Pow => limbs_pow_4(a, b),
15654 };
15655 raw.mask_high_bits(224)
15656}
15657
15658#[inline]
15659#[must_use]
15660pub const fn const_ring_eval_w256(op: PrimitiveOp, a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
15661 match op {
15662 PrimitiveOp::Add => a.wrapping_add(b),
15663 PrimitiveOp::Sub => a.wrapping_sub(b),
15664 PrimitiveOp::Mul => a.wrapping_mul(b),
15665 PrimitiveOp::And => a.and(b),
15666 PrimitiveOp::Or => a.or(b),
15667 PrimitiveOp::Xor => a.xor(b),
15668 PrimitiveOp::Neg => Limbs::<4>::zero().wrapping_sub(a),
15669 PrimitiveOp::Bnot => a.not(),
15670 PrimitiveOp::Succ => a.wrapping_add(limbs_one_4()),
15671 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_4()),
15672 PrimitiveOp::Le => {
15673 if limbs_le_4(a, b) {
15674 limbs_one_4()
15675 } else {
15676 Limbs::<4>::zero()
15677 }
15678 }
15679 PrimitiveOp::Lt => {
15680 if limbs_lt_4(a, b) {
15681 limbs_one_4()
15682 } else {
15683 Limbs::<4>::zero()
15684 }
15685 }
15686 PrimitiveOp::Ge => {
15687 if limbs_le_4(b, a) {
15688 limbs_one_4()
15689 } else {
15690 Limbs::<4>::zero()
15691 }
15692 }
15693 PrimitiveOp::Gt => {
15694 if limbs_lt_4(b, a) {
15695 limbs_one_4()
15696 } else {
15697 Limbs::<4>::zero()
15698 }
15699 }
15700 PrimitiveOp::Concat => Limbs::<4>::zero(),
15701 PrimitiveOp::Div => {
15702 if limbs_is_zero_4(b) {
15703 Limbs::<4>::zero()
15704 } else {
15705 limbs_div_4(a, b)
15706 }
15707 }
15708 PrimitiveOp::Mod => {
15709 if limbs_is_zero_4(b) {
15710 Limbs::<4>::zero()
15711 } else {
15712 limbs_mod_4(a, b)
15713 }
15714 }
15715 PrimitiveOp::Pow => limbs_pow_4(a, b),
15716 }
15717}
15718
15719#[inline]
15720#[must_use]
15721pub const fn const_ring_eval_w384(op: PrimitiveOp, a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
15722 match op {
15723 PrimitiveOp::Add => a.wrapping_add(b),
15724 PrimitiveOp::Sub => a.wrapping_sub(b),
15725 PrimitiveOp::Mul => a.wrapping_mul(b),
15726 PrimitiveOp::And => a.and(b),
15727 PrimitiveOp::Or => a.or(b),
15728 PrimitiveOp::Xor => a.xor(b),
15729 PrimitiveOp::Neg => Limbs::<6>::zero().wrapping_sub(a),
15730 PrimitiveOp::Bnot => a.not(),
15731 PrimitiveOp::Succ => a.wrapping_add(limbs_one_6()),
15732 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_6()),
15733 PrimitiveOp::Le => {
15734 if limbs_le_6(a, b) {
15735 limbs_one_6()
15736 } else {
15737 Limbs::<6>::zero()
15738 }
15739 }
15740 PrimitiveOp::Lt => {
15741 if limbs_lt_6(a, b) {
15742 limbs_one_6()
15743 } else {
15744 Limbs::<6>::zero()
15745 }
15746 }
15747 PrimitiveOp::Ge => {
15748 if limbs_le_6(b, a) {
15749 limbs_one_6()
15750 } else {
15751 Limbs::<6>::zero()
15752 }
15753 }
15754 PrimitiveOp::Gt => {
15755 if limbs_lt_6(b, a) {
15756 limbs_one_6()
15757 } else {
15758 Limbs::<6>::zero()
15759 }
15760 }
15761 PrimitiveOp::Concat => Limbs::<6>::zero(),
15762 PrimitiveOp::Div => {
15763 if limbs_is_zero_6(b) {
15764 Limbs::<6>::zero()
15765 } else {
15766 limbs_div_6(a, b)
15767 }
15768 }
15769 PrimitiveOp::Mod => {
15770 if limbs_is_zero_6(b) {
15771 Limbs::<6>::zero()
15772 } else {
15773 limbs_mod_6(a, b)
15774 }
15775 }
15776 PrimitiveOp::Pow => limbs_pow_6(a, b),
15777 }
15778}
15779
15780#[inline]
15781#[must_use]
15782pub const fn const_ring_eval_w448(op: PrimitiveOp, a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
15783 match op {
15784 PrimitiveOp::Add => a.wrapping_add(b),
15785 PrimitiveOp::Sub => a.wrapping_sub(b),
15786 PrimitiveOp::Mul => a.wrapping_mul(b),
15787 PrimitiveOp::And => a.and(b),
15788 PrimitiveOp::Or => a.or(b),
15789 PrimitiveOp::Xor => a.xor(b),
15790 PrimitiveOp::Neg => Limbs::<7>::zero().wrapping_sub(a),
15791 PrimitiveOp::Bnot => a.not(),
15792 PrimitiveOp::Succ => a.wrapping_add(limbs_one_7()),
15793 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_7()),
15794 PrimitiveOp::Le => {
15795 if limbs_le_7(a, b) {
15796 limbs_one_7()
15797 } else {
15798 Limbs::<7>::zero()
15799 }
15800 }
15801 PrimitiveOp::Lt => {
15802 if limbs_lt_7(a, b) {
15803 limbs_one_7()
15804 } else {
15805 Limbs::<7>::zero()
15806 }
15807 }
15808 PrimitiveOp::Ge => {
15809 if limbs_le_7(b, a) {
15810 limbs_one_7()
15811 } else {
15812 Limbs::<7>::zero()
15813 }
15814 }
15815 PrimitiveOp::Gt => {
15816 if limbs_lt_7(b, a) {
15817 limbs_one_7()
15818 } else {
15819 Limbs::<7>::zero()
15820 }
15821 }
15822 PrimitiveOp::Concat => Limbs::<7>::zero(),
15823 PrimitiveOp::Div => {
15824 if limbs_is_zero_7(b) {
15825 Limbs::<7>::zero()
15826 } else {
15827 limbs_div_7(a, b)
15828 }
15829 }
15830 PrimitiveOp::Mod => {
15831 if limbs_is_zero_7(b) {
15832 Limbs::<7>::zero()
15833 } else {
15834 limbs_mod_7(a, b)
15835 }
15836 }
15837 PrimitiveOp::Pow => limbs_pow_7(a, b),
15838 }
15839}
15840
15841#[inline]
15842#[must_use]
15843pub const fn const_ring_eval_w512(op: PrimitiveOp, a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
15844 match op {
15845 PrimitiveOp::Add => a.wrapping_add(b),
15846 PrimitiveOp::Sub => a.wrapping_sub(b),
15847 PrimitiveOp::Mul => a.wrapping_mul(b),
15848 PrimitiveOp::And => a.and(b),
15849 PrimitiveOp::Or => a.or(b),
15850 PrimitiveOp::Xor => a.xor(b),
15851 PrimitiveOp::Neg => Limbs::<8>::zero().wrapping_sub(a),
15852 PrimitiveOp::Bnot => a.not(),
15853 PrimitiveOp::Succ => a.wrapping_add(limbs_one_8()),
15854 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_8()),
15855 PrimitiveOp::Le => {
15856 if limbs_le_8(a, b) {
15857 limbs_one_8()
15858 } else {
15859 Limbs::<8>::zero()
15860 }
15861 }
15862 PrimitiveOp::Lt => {
15863 if limbs_lt_8(a, b) {
15864 limbs_one_8()
15865 } else {
15866 Limbs::<8>::zero()
15867 }
15868 }
15869 PrimitiveOp::Ge => {
15870 if limbs_le_8(b, a) {
15871 limbs_one_8()
15872 } else {
15873 Limbs::<8>::zero()
15874 }
15875 }
15876 PrimitiveOp::Gt => {
15877 if limbs_lt_8(b, a) {
15878 limbs_one_8()
15879 } else {
15880 Limbs::<8>::zero()
15881 }
15882 }
15883 PrimitiveOp::Concat => Limbs::<8>::zero(),
15884 PrimitiveOp::Div => {
15885 if limbs_is_zero_8(b) {
15886 Limbs::<8>::zero()
15887 } else {
15888 limbs_div_8(a, b)
15889 }
15890 }
15891 PrimitiveOp::Mod => {
15892 if limbs_is_zero_8(b) {
15893 Limbs::<8>::zero()
15894 } else {
15895 limbs_mod_8(a, b)
15896 }
15897 }
15898 PrimitiveOp::Pow => limbs_pow_8(a, b),
15899 }
15900}
15901
15902#[inline]
15903#[must_use]
15904pub const fn const_ring_eval_w520(op: PrimitiveOp, a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
15905 let raw = match op {
15906 PrimitiveOp::Add => a.wrapping_add(b),
15907 PrimitiveOp::Sub => a.wrapping_sub(b),
15908 PrimitiveOp::Mul => a.wrapping_mul(b),
15909 PrimitiveOp::And => a.and(b),
15910 PrimitiveOp::Or => a.or(b),
15911 PrimitiveOp::Xor => a.xor(b),
15912 PrimitiveOp::Neg => Limbs::<9>::zero().wrapping_sub(a),
15913 PrimitiveOp::Bnot => a.not(),
15914 PrimitiveOp::Succ => a.wrapping_add(limbs_one_9()),
15915 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_9()),
15916 PrimitiveOp::Le => {
15917 if limbs_le_9(a, b) {
15918 limbs_one_9()
15919 } else {
15920 Limbs::<9>::zero()
15921 }
15922 }
15923 PrimitiveOp::Lt => {
15924 if limbs_lt_9(a, b) {
15925 limbs_one_9()
15926 } else {
15927 Limbs::<9>::zero()
15928 }
15929 }
15930 PrimitiveOp::Ge => {
15931 if limbs_le_9(b, a) {
15932 limbs_one_9()
15933 } else {
15934 Limbs::<9>::zero()
15935 }
15936 }
15937 PrimitiveOp::Gt => {
15938 if limbs_lt_9(b, a) {
15939 limbs_one_9()
15940 } else {
15941 Limbs::<9>::zero()
15942 }
15943 }
15944 PrimitiveOp::Concat => Limbs::<9>::zero(),
15945 PrimitiveOp::Div => {
15946 if limbs_is_zero_9(b) {
15947 Limbs::<9>::zero()
15948 } else {
15949 limbs_div_9(a, b)
15950 }
15951 }
15952 PrimitiveOp::Mod => {
15953 if limbs_is_zero_9(b) {
15954 Limbs::<9>::zero()
15955 } else {
15956 limbs_mod_9(a, b)
15957 }
15958 }
15959 PrimitiveOp::Pow => limbs_pow_9(a, b),
15960 };
15961 raw.mask_high_bits(520)
15962}
15963
15964#[inline]
15965#[must_use]
15966pub const fn const_ring_eval_w528(op: PrimitiveOp, a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
15967 let raw = match op {
15968 PrimitiveOp::Add => a.wrapping_add(b),
15969 PrimitiveOp::Sub => a.wrapping_sub(b),
15970 PrimitiveOp::Mul => a.wrapping_mul(b),
15971 PrimitiveOp::And => a.and(b),
15972 PrimitiveOp::Or => a.or(b),
15973 PrimitiveOp::Xor => a.xor(b),
15974 PrimitiveOp::Neg => Limbs::<9>::zero().wrapping_sub(a),
15975 PrimitiveOp::Bnot => a.not(),
15976 PrimitiveOp::Succ => a.wrapping_add(limbs_one_9()),
15977 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_9()),
15978 PrimitiveOp::Le => {
15979 if limbs_le_9(a, b) {
15980 limbs_one_9()
15981 } else {
15982 Limbs::<9>::zero()
15983 }
15984 }
15985 PrimitiveOp::Lt => {
15986 if limbs_lt_9(a, b) {
15987 limbs_one_9()
15988 } else {
15989 Limbs::<9>::zero()
15990 }
15991 }
15992 PrimitiveOp::Ge => {
15993 if limbs_le_9(b, a) {
15994 limbs_one_9()
15995 } else {
15996 Limbs::<9>::zero()
15997 }
15998 }
15999 PrimitiveOp::Gt => {
16000 if limbs_lt_9(b, a) {
16001 limbs_one_9()
16002 } else {
16003 Limbs::<9>::zero()
16004 }
16005 }
16006 PrimitiveOp::Concat => Limbs::<9>::zero(),
16007 PrimitiveOp::Div => {
16008 if limbs_is_zero_9(b) {
16009 Limbs::<9>::zero()
16010 } else {
16011 limbs_div_9(a, b)
16012 }
16013 }
16014 PrimitiveOp::Mod => {
16015 if limbs_is_zero_9(b) {
16016 Limbs::<9>::zero()
16017 } else {
16018 limbs_mod_9(a, b)
16019 }
16020 }
16021 PrimitiveOp::Pow => limbs_pow_9(a, b),
16022 };
16023 raw.mask_high_bits(528)
16024}
16025
16026#[inline]
16027#[must_use]
16028pub const fn const_ring_eval_w1024(op: PrimitiveOp, a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
16029 match op {
16030 PrimitiveOp::Add => a.wrapping_add(b),
16031 PrimitiveOp::Sub => a.wrapping_sub(b),
16032 PrimitiveOp::Mul => a.wrapping_mul(b),
16033 PrimitiveOp::And => a.and(b),
16034 PrimitiveOp::Or => a.or(b),
16035 PrimitiveOp::Xor => a.xor(b),
16036 PrimitiveOp::Neg => Limbs::<16>::zero().wrapping_sub(a),
16037 PrimitiveOp::Bnot => a.not(),
16038 PrimitiveOp::Succ => a.wrapping_add(limbs_one_16()),
16039 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_16()),
16040 PrimitiveOp::Le => {
16041 if limbs_le_16(a, b) {
16042 limbs_one_16()
16043 } else {
16044 Limbs::<16>::zero()
16045 }
16046 }
16047 PrimitiveOp::Lt => {
16048 if limbs_lt_16(a, b) {
16049 limbs_one_16()
16050 } else {
16051 Limbs::<16>::zero()
16052 }
16053 }
16054 PrimitiveOp::Ge => {
16055 if limbs_le_16(b, a) {
16056 limbs_one_16()
16057 } else {
16058 Limbs::<16>::zero()
16059 }
16060 }
16061 PrimitiveOp::Gt => {
16062 if limbs_lt_16(b, a) {
16063 limbs_one_16()
16064 } else {
16065 Limbs::<16>::zero()
16066 }
16067 }
16068 PrimitiveOp::Concat => Limbs::<16>::zero(),
16069 PrimitiveOp::Div => {
16070 if limbs_is_zero_16(b) {
16071 Limbs::<16>::zero()
16072 } else {
16073 limbs_div_16(a, b)
16074 }
16075 }
16076 PrimitiveOp::Mod => {
16077 if limbs_is_zero_16(b) {
16078 Limbs::<16>::zero()
16079 } else {
16080 limbs_mod_16(a, b)
16081 }
16082 }
16083 PrimitiveOp::Pow => limbs_pow_16(a, b),
16084 }
16085}
16086
16087#[inline]
16088#[must_use]
16089pub const fn const_ring_eval_w2048(op: PrimitiveOp, a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
16090 match op {
16091 PrimitiveOp::Add => a.wrapping_add(b),
16092 PrimitiveOp::Sub => a.wrapping_sub(b),
16093 PrimitiveOp::Mul => a.wrapping_mul(b),
16094 PrimitiveOp::And => a.and(b),
16095 PrimitiveOp::Or => a.or(b),
16096 PrimitiveOp::Xor => a.xor(b),
16097 PrimitiveOp::Neg => Limbs::<32>::zero().wrapping_sub(a),
16098 PrimitiveOp::Bnot => a.not(),
16099 PrimitiveOp::Succ => a.wrapping_add(limbs_one_32()),
16100 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_32()),
16101 PrimitiveOp::Le => {
16102 if limbs_le_32(a, b) {
16103 limbs_one_32()
16104 } else {
16105 Limbs::<32>::zero()
16106 }
16107 }
16108 PrimitiveOp::Lt => {
16109 if limbs_lt_32(a, b) {
16110 limbs_one_32()
16111 } else {
16112 Limbs::<32>::zero()
16113 }
16114 }
16115 PrimitiveOp::Ge => {
16116 if limbs_le_32(b, a) {
16117 limbs_one_32()
16118 } else {
16119 Limbs::<32>::zero()
16120 }
16121 }
16122 PrimitiveOp::Gt => {
16123 if limbs_lt_32(b, a) {
16124 limbs_one_32()
16125 } else {
16126 Limbs::<32>::zero()
16127 }
16128 }
16129 PrimitiveOp::Concat => Limbs::<32>::zero(),
16130 PrimitiveOp::Div => {
16131 if limbs_is_zero_32(b) {
16132 Limbs::<32>::zero()
16133 } else {
16134 limbs_div_32(a, b)
16135 }
16136 }
16137 PrimitiveOp::Mod => {
16138 if limbs_is_zero_32(b) {
16139 Limbs::<32>::zero()
16140 } else {
16141 limbs_mod_32(a, b)
16142 }
16143 }
16144 PrimitiveOp::Pow => limbs_pow_32(a, b),
16145 }
16146}
16147
16148#[inline]
16149#[must_use]
16150pub const fn const_ring_eval_w4096(op: PrimitiveOp, a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
16151 match op {
16152 PrimitiveOp::Add => a.wrapping_add(b),
16153 PrimitiveOp::Sub => a.wrapping_sub(b),
16154 PrimitiveOp::Mul => a.wrapping_mul(b),
16155 PrimitiveOp::And => a.and(b),
16156 PrimitiveOp::Or => a.or(b),
16157 PrimitiveOp::Xor => a.xor(b),
16158 PrimitiveOp::Neg => Limbs::<64>::zero().wrapping_sub(a),
16159 PrimitiveOp::Bnot => a.not(),
16160 PrimitiveOp::Succ => a.wrapping_add(limbs_one_64()),
16161 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_64()),
16162 PrimitiveOp::Le => {
16163 if limbs_le_64(a, b) {
16164 limbs_one_64()
16165 } else {
16166 Limbs::<64>::zero()
16167 }
16168 }
16169 PrimitiveOp::Lt => {
16170 if limbs_lt_64(a, b) {
16171 limbs_one_64()
16172 } else {
16173 Limbs::<64>::zero()
16174 }
16175 }
16176 PrimitiveOp::Ge => {
16177 if limbs_le_64(b, a) {
16178 limbs_one_64()
16179 } else {
16180 Limbs::<64>::zero()
16181 }
16182 }
16183 PrimitiveOp::Gt => {
16184 if limbs_lt_64(b, a) {
16185 limbs_one_64()
16186 } else {
16187 Limbs::<64>::zero()
16188 }
16189 }
16190 PrimitiveOp::Concat => Limbs::<64>::zero(),
16191 PrimitiveOp::Div => {
16192 if limbs_is_zero_64(b) {
16193 Limbs::<64>::zero()
16194 } else {
16195 limbs_div_64(a, b)
16196 }
16197 }
16198 PrimitiveOp::Mod => {
16199 if limbs_is_zero_64(b) {
16200 Limbs::<64>::zero()
16201 } else {
16202 limbs_mod_64(a, b)
16203 }
16204 }
16205 PrimitiveOp::Pow => limbs_pow_64(a, b),
16206 }
16207}
16208
16209#[inline]
16210#[must_use]
16211pub const fn const_ring_eval_w8192(op: PrimitiveOp, a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
16212 match op {
16213 PrimitiveOp::Add => a.wrapping_add(b),
16214 PrimitiveOp::Sub => a.wrapping_sub(b),
16215 PrimitiveOp::Mul => a.wrapping_mul(b),
16216 PrimitiveOp::And => a.and(b),
16217 PrimitiveOp::Or => a.or(b),
16218 PrimitiveOp::Xor => a.xor(b),
16219 PrimitiveOp::Neg => Limbs::<128>::zero().wrapping_sub(a),
16220 PrimitiveOp::Bnot => a.not(),
16221 PrimitiveOp::Succ => a.wrapping_add(limbs_one_128()),
16222 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_128()),
16223 PrimitiveOp::Le => {
16224 if limbs_le_128(a, b) {
16225 limbs_one_128()
16226 } else {
16227 Limbs::<128>::zero()
16228 }
16229 }
16230 PrimitiveOp::Lt => {
16231 if limbs_lt_128(a, b) {
16232 limbs_one_128()
16233 } else {
16234 Limbs::<128>::zero()
16235 }
16236 }
16237 PrimitiveOp::Ge => {
16238 if limbs_le_128(b, a) {
16239 limbs_one_128()
16240 } else {
16241 Limbs::<128>::zero()
16242 }
16243 }
16244 PrimitiveOp::Gt => {
16245 if limbs_lt_128(b, a) {
16246 limbs_one_128()
16247 } else {
16248 Limbs::<128>::zero()
16249 }
16250 }
16251 PrimitiveOp::Concat => Limbs::<128>::zero(),
16252 PrimitiveOp::Div => {
16253 if limbs_is_zero_128(b) {
16254 Limbs::<128>::zero()
16255 } else {
16256 limbs_div_128(a, b)
16257 }
16258 }
16259 PrimitiveOp::Mod => {
16260 if limbs_is_zero_128(b) {
16261 Limbs::<128>::zero()
16262 } else {
16263 limbs_mod_128(a, b)
16264 }
16265 }
16266 PrimitiveOp::Pow => limbs_pow_128(a, b),
16267 }
16268}
16269
16270#[inline]
16271#[must_use]
16272pub const fn const_ring_eval_w12288(op: PrimitiveOp, a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
16273 match op {
16274 PrimitiveOp::Add => a.wrapping_add(b),
16275 PrimitiveOp::Sub => a.wrapping_sub(b),
16276 PrimitiveOp::Mul => a.wrapping_mul(b),
16277 PrimitiveOp::And => a.and(b),
16278 PrimitiveOp::Or => a.or(b),
16279 PrimitiveOp::Xor => a.xor(b),
16280 PrimitiveOp::Neg => Limbs::<192>::zero().wrapping_sub(a),
16281 PrimitiveOp::Bnot => a.not(),
16282 PrimitiveOp::Succ => a.wrapping_add(limbs_one_192()),
16283 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_192()),
16284 PrimitiveOp::Le => {
16285 if limbs_le_192(a, b) {
16286 limbs_one_192()
16287 } else {
16288 Limbs::<192>::zero()
16289 }
16290 }
16291 PrimitiveOp::Lt => {
16292 if limbs_lt_192(a, b) {
16293 limbs_one_192()
16294 } else {
16295 Limbs::<192>::zero()
16296 }
16297 }
16298 PrimitiveOp::Ge => {
16299 if limbs_le_192(b, a) {
16300 limbs_one_192()
16301 } else {
16302 Limbs::<192>::zero()
16303 }
16304 }
16305 PrimitiveOp::Gt => {
16306 if limbs_lt_192(b, a) {
16307 limbs_one_192()
16308 } else {
16309 Limbs::<192>::zero()
16310 }
16311 }
16312 PrimitiveOp::Concat => Limbs::<192>::zero(),
16313 PrimitiveOp::Div => {
16314 if limbs_is_zero_192(b) {
16315 Limbs::<192>::zero()
16316 } else {
16317 limbs_div_192(a, b)
16318 }
16319 }
16320 PrimitiveOp::Mod => {
16321 if limbs_is_zero_192(b) {
16322 Limbs::<192>::zero()
16323 } else {
16324 limbs_mod_192(a, b)
16325 }
16326 }
16327 PrimitiveOp::Pow => limbs_pow_192(a, b),
16328 }
16329}
16330
16331#[inline]
16332#[must_use]
16333pub const fn const_ring_eval_w16384(op: PrimitiveOp, a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
16334 match op {
16335 PrimitiveOp::Add => a.wrapping_add(b),
16336 PrimitiveOp::Sub => a.wrapping_sub(b),
16337 PrimitiveOp::Mul => a.wrapping_mul(b),
16338 PrimitiveOp::And => a.and(b),
16339 PrimitiveOp::Or => a.or(b),
16340 PrimitiveOp::Xor => a.xor(b),
16341 PrimitiveOp::Neg => Limbs::<256>::zero().wrapping_sub(a),
16342 PrimitiveOp::Bnot => a.not(),
16343 PrimitiveOp::Succ => a.wrapping_add(limbs_one_256()),
16344 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_256()),
16345 PrimitiveOp::Le => {
16346 if limbs_le_256(a, b) {
16347 limbs_one_256()
16348 } else {
16349 Limbs::<256>::zero()
16350 }
16351 }
16352 PrimitiveOp::Lt => {
16353 if limbs_lt_256(a, b) {
16354 limbs_one_256()
16355 } else {
16356 Limbs::<256>::zero()
16357 }
16358 }
16359 PrimitiveOp::Ge => {
16360 if limbs_le_256(b, a) {
16361 limbs_one_256()
16362 } else {
16363 Limbs::<256>::zero()
16364 }
16365 }
16366 PrimitiveOp::Gt => {
16367 if limbs_lt_256(b, a) {
16368 limbs_one_256()
16369 } else {
16370 Limbs::<256>::zero()
16371 }
16372 }
16373 PrimitiveOp::Concat => Limbs::<256>::zero(),
16374 PrimitiveOp::Div => {
16375 if limbs_is_zero_256(b) {
16376 Limbs::<256>::zero()
16377 } else {
16378 limbs_div_256(a, b)
16379 }
16380 }
16381 PrimitiveOp::Mod => {
16382 if limbs_is_zero_256(b) {
16383 Limbs::<256>::zero()
16384 } else {
16385 limbs_mod_256(a, b)
16386 }
16387 }
16388 PrimitiveOp::Pow => limbs_pow_256(a, b),
16389 }
16390}
16391
16392#[inline]
16393#[must_use]
16394pub const fn const_ring_eval_w32768(op: PrimitiveOp, a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
16395 match op {
16396 PrimitiveOp::Add => a.wrapping_add(b),
16397 PrimitiveOp::Sub => a.wrapping_sub(b),
16398 PrimitiveOp::Mul => a.wrapping_mul(b),
16399 PrimitiveOp::And => a.and(b),
16400 PrimitiveOp::Or => a.or(b),
16401 PrimitiveOp::Xor => a.xor(b),
16402 PrimitiveOp::Neg => Limbs::<512>::zero().wrapping_sub(a),
16403 PrimitiveOp::Bnot => a.not(),
16404 PrimitiveOp::Succ => a.wrapping_add(limbs_one_512()),
16405 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_512()),
16406 PrimitiveOp::Le => {
16407 if limbs_le_512(a, b) {
16408 limbs_one_512()
16409 } else {
16410 Limbs::<512>::zero()
16411 }
16412 }
16413 PrimitiveOp::Lt => {
16414 if limbs_lt_512(a, b) {
16415 limbs_one_512()
16416 } else {
16417 Limbs::<512>::zero()
16418 }
16419 }
16420 PrimitiveOp::Ge => {
16421 if limbs_le_512(b, a) {
16422 limbs_one_512()
16423 } else {
16424 Limbs::<512>::zero()
16425 }
16426 }
16427 PrimitiveOp::Gt => {
16428 if limbs_lt_512(b, a) {
16429 limbs_one_512()
16430 } else {
16431 Limbs::<512>::zero()
16432 }
16433 }
16434 PrimitiveOp::Concat => Limbs::<512>::zero(),
16435 PrimitiveOp::Div => {
16436 if limbs_is_zero_512(b) {
16437 Limbs::<512>::zero()
16438 } else {
16439 limbs_div_512(a, b)
16440 }
16441 }
16442 PrimitiveOp::Mod => {
16443 if limbs_is_zero_512(b) {
16444 Limbs::<512>::zero()
16445 } else {
16446 limbs_mod_512(a, b)
16447 }
16448 }
16449 PrimitiveOp::Pow => limbs_pow_512(a, b),
16450 }
16451}
16452
16453#[inline]
16455#[must_use]
16456const fn limbs_one_3() -> Limbs<3> {
16457 Limbs::<3>::from_words([1u64, 0u64, 0u64])
16458}
16459
16460#[inline]
16461#[must_use]
16462const fn limbs_one_4() -> Limbs<4> {
16463 Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64])
16464}
16465
16466#[inline]
16467#[must_use]
16468const fn limbs_one_6() -> Limbs<6> {
16469 Limbs::<6>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16470}
16471
16472#[inline]
16473#[must_use]
16474const fn limbs_one_7() -> Limbs<7> {
16475 Limbs::<7>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16476}
16477
16478#[inline]
16479#[must_use]
16480const fn limbs_one_8() -> Limbs<8> {
16481 Limbs::<8>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16482}
16483
16484#[inline]
16485#[must_use]
16486const fn limbs_one_9() -> Limbs<9> {
16487 Limbs::<9>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16488}
16489
16490#[inline]
16491#[must_use]
16492const fn limbs_one_16() -> Limbs<16> {
16493 Limbs::<16>::from_words([
16494 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16495 0u64,
16496 ])
16497}
16498
16499#[inline]
16500#[must_use]
16501const fn limbs_one_32() -> Limbs<32> {
16502 Limbs::<32>::from_words([
16503 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16504 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16505 0u64, 0u64,
16506 ])
16507}
16508
16509#[inline]
16510#[must_use]
16511const fn limbs_one_64() -> Limbs<64> {
16512 Limbs::<64>::from_words([
16513 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16514 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16515 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16516 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16517 0u64, 0u64, 0u64, 0u64,
16518 ])
16519}
16520
16521#[inline]
16522#[must_use]
16523const fn limbs_one_128() -> Limbs<128> {
16524 Limbs::<128>::from_words([
16525 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16526 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16527 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16528 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16529 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16530 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16531 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16532 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16533 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16534 ])
16535}
16536
16537#[inline]
16538#[must_use]
16539const fn limbs_one_192() -> Limbs<192> {
16540 Limbs::<192>::from_words([
16541 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16542 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16543 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16544 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16545 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16546 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16547 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16548 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16549 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16550 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16551 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16552 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16553 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16554 ])
16555}
16556
16557#[inline]
16558#[must_use]
16559const fn limbs_one_256() -> Limbs<256> {
16560 Limbs::<256>::from_words([
16561 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16562 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16563 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16564 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16565 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16566 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16567 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16568 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16569 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16570 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16571 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16572 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16573 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16574 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16575 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16576 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16577 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16578 0u64,
16579 ])
16580}
16581
16582#[inline]
16583#[must_use]
16584const fn limbs_one_512() -> Limbs<512> {
16585 Limbs::<512>::from_words([
16586 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16587 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16588 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16589 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16590 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16591 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16592 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16593 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16594 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16595 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16596 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16597 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16598 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16599 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16600 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16601 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16602 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16603 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16604 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16605 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16606 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16607 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16608 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16609 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16610 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16611 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16612 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16613 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16614 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16615 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16616 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16617 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16618 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16619 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16620 0u64, 0u64,
16621 ])
16622}
16623
16624#[inline]
16627#[must_use]
16628const fn limbs_lt_3(a: Limbs<3>, b: Limbs<3>) -> bool {
16629 let aw = a.words();
16630 let bw = b.words();
16631 let mut i = 3;
16632 while i > 0 {
16633 i -= 1;
16634 if aw[i] < bw[i] {
16635 return true;
16636 }
16637 if aw[i] > bw[i] {
16638 return false;
16639 }
16640 }
16641 false
16642}
16643
16644#[inline]
16645#[must_use]
16646const fn limbs_le_3(a: Limbs<3>, b: Limbs<3>) -> bool {
16647 let aw = a.words();
16648 let bw = b.words();
16649 let mut i = 3;
16650 while i > 0 {
16651 i -= 1;
16652 if aw[i] < bw[i] {
16653 return true;
16654 }
16655 if aw[i] > bw[i] {
16656 return false;
16657 }
16658 }
16659 true
16660}
16661
16662#[inline]
16663#[must_use]
16664const fn limbs_lt_4(a: Limbs<4>, b: Limbs<4>) -> bool {
16665 let aw = a.words();
16666 let bw = b.words();
16667 let mut i = 4;
16668 while i > 0 {
16669 i -= 1;
16670 if aw[i] < bw[i] {
16671 return true;
16672 }
16673 if aw[i] > bw[i] {
16674 return false;
16675 }
16676 }
16677 false
16678}
16679
16680#[inline]
16681#[must_use]
16682const fn limbs_le_4(a: Limbs<4>, b: Limbs<4>) -> bool {
16683 let aw = a.words();
16684 let bw = b.words();
16685 let mut i = 4;
16686 while i > 0 {
16687 i -= 1;
16688 if aw[i] < bw[i] {
16689 return true;
16690 }
16691 if aw[i] > bw[i] {
16692 return false;
16693 }
16694 }
16695 true
16696}
16697
16698#[inline]
16699#[must_use]
16700const fn limbs_lt_6(a: Limbs<6>, b: Limbs<6>) -> bool {
16701 let aw = a.words();
16702 let bw = b.words();
16703 let mut i = 6;
16704 while i > 0 {
16705 i -= 1;
16706 if aw[i] < bw[i] {
16707 return true;
16708 }
16709 if aw[i] > bw[i] {
16710 return false;
16711 }
16712 }
16713 false
16714}
16715
16716#[inline]
16717#[must_use]
16718const fn limbs_le_6(a: Limbs<6>, b: Limbs<6>) -> bool {
16719 let aw = a.words();
16720 let bw = b.words();
16721 let mut i = 6;
16722 while i > 0 {
16723 i -= 1;
16724 if aw[i] < bw[i] {
16725 return true;
16726 }
16727 if aw[i] > bw[i] {
16728 return false;
16729 }
16730 }
16731 true
16732}
16733
16734#[inline]
16735#[must_use]
16736const fn limbs_lt_7(a: Limbs<7>, b: Limbs<7>) -> bool {
16737 let aw = a.words();
16738 let bw = b.words();
16739 let mut i = 7;
16740 while i > 0 {
16741 i -= 1;
16742 if aw[i] < bw[i] {
16743 return true;
16744 }
16745 if aw[i] > bw[i] {
16746 return false;
16747 }
16748 }
16749 false
16750}
16751
16752#[inline]
16753#[must_use]
16754const fn limbs_le_7(a: Limbs<7>, b: Limbs<7>) -> bool {
16755 let aw = a.words();
16756 let bw = b.words();
16757 let mut i = 7;
16758 while i > 0 {
16759 i -= 1;
16760 if aw[i] < bw[i] {
16761 return true;
16762 }
16763 if aw[i] > bw[i] {
16764 return false;
16765 }
16766 }
16767 true
16768}
16769
16770#[inline]
16771#[must_use]
16772const fn limbs_lt_8(a: Limbs<8>, b: Limbs<8>) -> bool {
16773 let aw = a.words();
16774 let bw = b.words();
16775 let mut i = 8;
16776 while i > 0 {
16777 i -= 1;
16778 if aw[i] < bw[i] {
16779 return true;
16780 }
16781 if aw[i] > bw[i] {
16782 return false;
16783 }
16784 }
16785 false
16786}
16787
16788#[inline]
16789#[must_use]
16790const fn limbs_le_8(a: Limbs<8>, b: Limbs<8>) -> bool {
16791 let aw = a.words();
16792 let bw = b.words();
16793 let mut i = 8;
16794 while i > 0 {
16795 i -= 1;
16796 if aw[i] < bw[i] {
16797 return true;
16798 }
16799 if aw[i] > bw[i] {
16800 return false;
16801 }
16802 }
16803 true
16804}
16805
16806#[inline]
16807#[must_use]
16808const fn limbs_lt_9(a: Limbs<9>, b: Limbs<9>) -> bool {
16809 let aw = a.words();
16810 let bw = b.words();
16811 let mut i = 9;
16812 while i > 0 {
16813 i -= 1;
16814 if aw[i] < bw[i] {
16815 return true;
16816 }
16817 if aw[i] > bw[i] {
16818 return false;
16819 }
16820 }
16821 false
16822}
16823
16824#[inline]
16825#[must_use]
16826const fn limbs_le_9(a: Limbs<9>, b: Limbs<9>) -> bool {
16827 let aw = a.words();
16828 let bw = b.words();
16829 let mut i = 9;
16830 while i > 0 {
16831 i -= 1;
16832 if aw[i] < bw[i] {
16833 return true;
16834 }
16835 if aw[i] > bw[i] {
16836 return false;
16837 }
16838 }
16839 true
16840}
16841
16842#[inline]
16843#[must_use]
16844const fn limbs_lt_16(a: Limbs<16>, b: Limbs<16>) -> bool {
16845 let aw = a.words();
16846 let bw = b.words();
16847 let mut i = 16;
16848 while i > 0 {
16849 i -= 1;
16850 if aw[i] < bw[i] {
16851 return true;
16852 }
16853 if aw[i] > bw[i] {
16854 return false;
16855 }
16856 }
16857 false
16858}
16859
16860#[inline]
16861#[must_use]
16862const fn limbs_le_16(a: Limbs<16>, b: Limbs<16>) -> bool {
16863 let aw = a.words();
16864 let bw = b.words();
16865 let mut i = 16;
16866 while i > 0 {
16867 i -= 1;
16868 if aw[i] < bw[i] {
16869 return true;
16870 }
16871 if aw[i] > bw[i] {
16872 return false;
16873 }
16874 }
16875 true
16876}
16877
16878#[inline]
16879#[must_use]
16880const fn limbs_lt_32(a: Limbs<32>, b: Limbs<32>) -> bool {
16881 let aw = a.words();
16882 let bw = b.words();
16883 let mut i = 32;
16884 while i > 0 {
16885 i -= 1;
16886 if aw[i] < bw[i] {
16887 return true;
16888 }
16889 if aw[i] > bw[i] {
16890 return false;
16891 }
16892 }
16893 false
16894}
16895
16896#[inline]
16897#[must_use]
16898const fn limbs_le_32(a: Limbs<32>, b: Limbs<32>) -> bool {
16899 let aw = a.words();
16900 let bw = b.words();
16901 let mut i = 32;
16902 while i > 0 {
16903 i -= 1;
16904 if aw[i] < bw[i] {
16905 return true;
16906 }
16907 if aw[i] > bw[i] {
16908 return false;
16909 }
16910 }
16911 true
16912}
16913
16914#[inline]
16915#[must_use]
16916const fn limbs_lt_64(a: Limbs<64>, b: Limbs<64>) -> bool {
16917 let aw = a.words();
16918 let bw = b.words();
16919 let mut i = 64;
16920 while i > 0 {
16921 i -= 1;
16922 if aw[i] < bw[i] {
16923 return true;
16924 }
16925 if aw[i] > bw[i] {
16926 return false;
16927 }
16928 }
16929 false
16930}
16931
16932#[inline]
16933#[must_use]
16934const fn limbs_le_64(a: Limbs<64>, b: Limbs<64>) -> bool {
16935 let aw = a.words();
16936 let bw = b.words();
16937 let mut i = 64;
16938 while i > 0 {
16939 i -= 1;
16940 if aw[i] < bw[i] {
16941 return true;
16942 }
16943 if aw[i] > bw[i] {
16944 return false;
16945 }
16946 }
16947 true
16948}
16949
16950#[inline]
16951#[must_use]
16952const fn limbs_lt_128(a: Limbs<128>, b: Limbs<128>) -> bool {
16953 let aw = a.words();
16954 let bw = b.words();
16955 let mut i = 128;
16956 while i > 0 {
16957 i -= 1;
16958 if aw[i] < bw[i] {
16959 return true;
16960 }
16961 if aw[i] > bw[i] {
16962 return false;
16963 }
16964 }
16965 false
16966}
16967
16968#[inline]
16969#[must_use]
16970const fn limbs_le_128(a: Limbs<128>, b: Limbs<128>) -> bool {
16971 let aw = a.words();
16972 let bw = b.words();
16973 let mut i = 128;
16974 while i > 0 {
16975 i -= 1;
16976 if aw[i] < bw[i] {
16977 return true;
16978 }
16979 if aw[i] > bw[i] {
16980 return false;
16981 }
16982 }
16983 true
16984}
16985
16986#[inline]
16987#[must_use]
16988const fn limbs_lt_192(a: Limbs<192>, b: Limbs<192>) -> bool {
16989 let aw = a.words();
16990 let bw = b.words();
16991 let mut i = 192;
16992 while i > 0 {
16993 i -= 1;
16994 if aw[i] < bw[i] {
16995 return true;
16996 }
16997 if aw[i] > bw[i] {
16998 return false;
16999 }
17000 }
17001 false
17002}
17003
17004#[inline]
17005#[must_use]
17006const fn limbs_le_192(a: Limbs<192>, b: Limbs<192>) -> bool {
17007 let aw = a.words();
17008 let bw = b.words();
17009 let mut i = 192;
17010 while i > 0 {
17011 i -= 1;
17012 if aw[i] < bw[i] {
17013 return true;
17014 }
17015 if aw[i] > bw[i] {
17016 return false;
17017 }
17018 }
17019 true
17020}
17021
17022#[inline]
17023#[must_use]
17024const fn limbs_lt_256(a: Limbs<256>, b: Limbs<256>) -> bool {
17025 let aw = a.words();
17026 let bw = b.words();
17027 let mut i = 256;
17028 while i > 0 {
17029 i -= 1;
17030 if aw[i] < bw[i] {
17031 return true;
17032 }
17033 if aw[i] > bw[i] {
17034 return false;
17035 }
17036 }
17037 false
17038}
17039
17040#[inline]
17041#[must_use]
17042const fn limbs_le_256(a: Limbs<256>, b: Limbs<256>) -> bool {
17043 let aw = a.words();
17044 let bw = b.words();
17045 let mut i = 256;
17046 while i > 0 {
17047 i -= 1;
17048 if aw[i] < bw[i] {
17049 return true;
17050 }
17051 if aw[i] > bw[i] {
17052 return false;
17053 }
17054 }
17055 true
17056}
17057
17058#[inline]
17059#[must_use]
17060const fn limbs_lt_512(a: Limbs<512>, b: Limbs<512>) -> bool {
17061 let aw = a.words();
17062 let bw = b.words();
17063 let mut i = 512;
17064 while i > 0 {
17065 i -= 1;
17066 if aw[i] < bw[i] {
17067 return true;
17068 }
17069 if aw[i] > bw[i] {
17070 return false;
17071 }
17072 }
17073 false
17074}
17075
17076#[inline]
17077#[must_use]
17078const fn limbs_le_512(a: Limbs<512>, b: Limbs<512>) -> bool {
17079 let aw = a.words();
17080 let bw = b.words();
17081 let mut i = 512;
17082 while i > 0 {
17083 i -= 1;
17084 if aw[i] < bw[i] {
17085 return true;
17086 }
17087 if aw[i] > bw[i] {
17088 return false;
17089 }
17090 }
17091 true
17092}
17093
17094#[inline]
17097#[must_use]
17098const fn limbs_is_zero_3(a: Limbs<3>) -> bool {
17099 let aw = a.words();
17100 let mut i = 0usize;
17101 while i < 3 {
17102 if aw[i] != 0 {
17103 return false;
17104 }
17105 i += 1;
17106 }
17107 true
17108}
17109
17110#[inline]
17111#[must_use]
17112const fn limbs_shl1_3(a: Limbs<3>) -> Limbs<3> {
17113 let aw = a.words();
17114 let mut out = [0u64; 3];
17115 let mut carry: u64 = 0;
17116 let mut i = 0usize;
17117 while i < 3 {
17118 let v = aw[i];
17119 out[i] = (v << 1) | carry;
17120 carry = v >> 63;
17121 i += 1;
17122 }
17123 Limbs::<3>::from_words(out)
17124}
17125
17126#[inline]
17127#[must_use]
17128const fn limbs_set_bit0_3(a: Limbs<3>) -> Limbs<3> {
17129 let aw = a.words();
17130 let mut out = [0u64; 3];
17131 let mut i = 0usize;
17132 while i < 3 {
17133 out[i] = aw[i];
17134 i += 1;
17135 }
17136 out[0] |= 1u64;
17137 Limbs::<3>::from_words(out)
17138}
17139
17140#[inline]
17141#[must_use]
17142const fn limbs_bit_msb_3(a: Limbs<3>, msb_index: usize) -> u64 {
17143 let aw = a.words();
17144 let total_bits = 3 * 64;
17145 let lsb_index = total_bits - 1 - msb_index;
17146 let word = lsb_index / 64;
17147 let bit = lsb_index % 64;
17148 (aw[word] >> bit) & 1u64
17149}
17150
17151#[inline]
17152#[must_use]
17153const fn limbs_divmod_3(a: Limbs<3>, b: Limbs<3>) -> (Limbs<3>, Limbs<3>) {
17154 let mut q = Limbs::<3>::zero();
17155 let mut r = Limbs::<3>::zero();
17156 let total_bits = 3 * 64;
17157 let mut i = 0usize;
17158 while i < total_bits {
17159 r = limbs_shl1_3(r);
17160 if limbs_bit_msb_3(a, i) == 1 {
17161 r = limbs_set_bit0_3(r);
17162 }
17163 if limbs_le_3(b, r) {
17164 r = r.wrapping_sub(b);
17165 q = limbs_shl1_3(q);
17166 q = limbs_set_bit0_3(q);
17167 } else {
17168 q = limbs_shl1_3(q);
17169 }
17170 i += 1;
17171 }
17172 (q, r)
17173}
17174
17175#[inline]
17176#[must_use]
17177const fn limbs_div_3(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
17178 let (q, _) = limbs_divmod_3(a, b);
17179 q
17180}
17181
17182#[inline]
17183#[must_use]
17184const fn limbs_mod_3(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
17185 let (_, r) = limbs_divmod_3(a, b);
17186 r
17187}
17188
17189#[inline]
17190#[must_use]
17191const fn limbs_pow_3(base: Limbs<3>, exp: Limbs<3>) -> Limbs<3> {
17192 let mut result = limbs_one_3();
17193 let mut b = base;
17194 let ew = exp.words();
17195 let mut word = 0usize;
17196 while word < 3 {
17197 let mut bit = 0u32;
17198 while bit < 64 {
17199 if ((ew[word] >> bit) & 1u64) == 1u64 {
17200 result = result.wrapping_mul(b);
17201 }
17202 b = b.wrapping_mul(b);
17203 bit += 1;
17204 }
17205 word += 1;
17206 }
17207 result
17208}
17209
17210#[inline]
17211#[must_use]
17212const fn limbs_is_zero_4(a: Limbs<4>) -> bool {
17213 let aw = a.words();
17214 let mut i = 0usize;
17215 while i < 4 {
17216 if aw[i] != 0 {
17217 return false;
17218 }
17219 i += 1;
17220 }
17221 true
17222}
17223
17224#[inline]
17225#[must_use]
17226const fn limbs_shl1_4(a: Limbs<4>) -> Limbs<4> {
17227 let aw = a.words();
17228 let mut out = [0u64; 4];
17229 let mut carry: u64 = 0;
17230 let mut i = 0usize;
17231 while i < 4 {
17232 let v = aw[i];
17233 out[i] = (v << 1) | carry;
17234 carry = v >> 63;
17235 i += 1;
17236 }
17237 Limbs::<4>::from_words(out)
17238}
17239
17240#[inline]
17241#[must_use]
17242const fn limbs_set_bit0_4(a: Limbs<4>) -> Limbs<4> {
17243 let aw = a.words();
17244 let mut out = [0u64; 4];
17245 let mut i = 0usize;
17246 while i < 4 {
17247 out[i] = aw[i];
17248 i += 1;
17249 }
17250 out[0] |= 1u64;
17251 Limbs::<4>::from_words(out)
17252}
17253
17254#[inline]
17255#[must_use]
17256const fn limbs_bit_msb_4(a: Limbs<4>, msb_index: usize) -> u64 {
17257 let aw = a.words();
17258 let total_bits = 4 * 64;
17259 let lsb_index = total_bits - 1 - msb_index;
17260 let word = lsb_index / 64;
17261 let bit = lsb_index % 64;
17262 (aw[word] >> bit) & 1u64
17263}
17264
17265#[inline]
17266#[must_use]
17267const fn limbs_divmod_4(a: Limbs<4>, b: Limbs<4>) -> (Limbs<4>, Limbs<4>) {
17268 let mut q = Limbs::<4>::zero();
17269 let mut r = Limbs::<4>::zero();
17270 let total_bits = 4 * 64;
17271 let mut i = 0usize;
17272 while i < total_bits {
17273 r = limbs_shl1_4(r);
17274 if limbs_bit_msb_4(a, i) == 1 {
17275 r = limbs_set_bit0_4(r);
17276 }
17277 if limbs_le_4(b, r) {
17278 r = r.wrapping_sub(b);
17279 q = limbs_shl1_4(q);
17280 q = limbs_set_bit0_4(q);
17281 } else {
17282 q = limbs_shl1_4(q);
17283 }
17284 i += 1;
17285 }
17286 (q, r)
17287}
17288
17289#[inline]
17290#[must_use]
17291const fn limbs_div_4(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
17292 let (q, _) = limbs_divmod_4(a, b);
17293 q
17294}
17295
17296#[inline]
17297#[must_use]
17298const fn limbs_mod_4(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
17299 let (_, r) = limbs_divmod_4(a, b);
17300 r
17301}
17302
17303#[inline]
17304#[must_use]
17305const fn limbs_pow_4(base: Limbs<4>, exp: Limbs<4>) -> Limbs<4> {
17306 let mut result = limbs_one_4();
17307 let mut b = base;
17308 let ew = exp.words();
17309 let mut word = 0usize;
17310 while word < 4 {
17311 let mut bit = 0u32;
17312 while bit < 64 {
17313 if ((ew[word] >> bit) & 1u64) == 1u64 {
17314 result = result.wrapping_mul(b);
17315 }
17316 b = b.wrapping_mul(b);
17317 bit += 1;
17318 }
17319 word += 1;
17320 }
17321 result
17322}
17323
17324#[inline]
17325#[must_use]
17326const fn limbs_is_zero_6(a: Limbs<6>) -> bool {
17327 let aw = a.words();
17328 let mut i = 0usize;
17329 while i < 6 {
17330 if aw[i] != 0 {
17331 return false;
17332 }
17333 i += 1;
17334 }
17335 true
17336}
17337
17338#[inline]
17339#[must_use]
17340const fn limbs_shl1_6(a: Limbs<6>) -> Limbs<6> {
17341 let aw = a.words();
17342 let mut out = [0u64; 6];
17343 let mut carry: u64 = 0;
17344 let mut i = 0usize;
17345 while i < 6 {
17346 let v = aw[i];
17347 out[i] = (v << 1) | carry;
17348 carry = v >> 63;
17349 i += 1;
17350 }
17351 Limbs::<6>::from_words(out)
17352}
17353
17354#[inline]
17355#[must_use]
17356const fn limbs_set_bit0_6(a: Limbs<6>) -> Limbs<6> {
17357 let aw = a.words();
17358 let mut out = [0u64; 6];
17359 let mut i = 0usize;
17360 while i < 6 {
17361 out[i] = aw[i];
17362 i += 1;
17363 }
17364 out[0] |= 1u64;
17365 Limbs::<6>::from_words(out)
17366}
17367
17368#[inline]
17369#[must_use]
17370const fn limbs_bit_msb_6(a: Limbs<6>, msb_index: usize) -> u64 {
17371 let aw = a.words();
17372 let total_bits = 6 * 64;
17373 let lsb_index = total_bits - 1 - msb_index;
17374 let word = lsb_index / 64;
17375 let bit = lsb_index % 64;
17376 (aw[word] >> bit) & 1u64
17377}
17378
17379#[inline]
17380#[must_use]
17381const fn limbs_divmod_6(a: Limbs<6>, b: Limbs<6>) -> (Limbs<6>, Limbs<6>) {
17382 let mut q = Limbs::<6>::zero();
17383 let mut r = Limbs::<6>::zero();
17384 let total_bits = 6 * 64;
17385 let mut i = 0usize;
17386 while i < total_bits {
17387 r = limbs_shl1_6(r);
17388 if limbs_bit_msb_6(a, i) == 1 {
17389 r = limbs_set_bit0_6(r);
17390 }
17391 if limbs_le_6(b, r) {
17392 r = r.wrapping_sub(b);
17393 q = limbs_shl1_6(q);
17394 q = limbs_set_bit0_6(q);
17395 } else {
17396 q = limbs_shl1_6(q);
17397 }
17398 i += 1;
17399 }
17400 (q, r)
17401}
17402
17403#[inline]
17404#[must_use]
17405const fn limbs_div_6(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
17406 let (q, _) = limbs_divmod_6(a, b);
17407 q
17408}
17409
17410#[inline]
17411#[must_use]
17412const fn limbs_mod_6(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
17413 let (_, r) = limbs_divmod_6(a, b);
17414 r
17415}
17416
17417#[inline]
17418#[must_use]
17419const fn limbs_pow_6(base: Limbs<6>, exp: Limbs<6>) -> Limbs<6> {
17420 let mut result = limbs_one_6();
17421 let mut b = base;
17422 let ew = exp.words();
17423 let mut word = 0usize;
17424 while word < 6 {
17425 let mut bit = 0u32;
17426 while bit < 64 {
17427 if ((ew[word] >> bit) & 1u64) == 1u64 {
17428 result = result.wrapping_mul(b);
17429 }
17430 b = b.wrapping_mul(b);
17431 bit += 1;
17432 }
17433 word += 1;
17434 }
17435 result
17436}
17437
17438#[inline]
17439#[must_use]
17440const fn limbs_is_zero_7(a: Limbs<7>) -> bool {
17441 let aw = a.words();
17442 let mut i = 0usize;
17443 while i < 7 {
17444 if aw[i] != 0 {
17445 return false;
17446 }
17447 i += 1;
17448 }
17449 true
17450}
17451
17452#[inline]
17453#[must_use]
17454const fn limbs_shl1_7(a: Limbs<7>) -> Limbs<7> {
17455 let aw = a.words();
17456 let mut out = [0u64; 7];
17457 let mut carry: u64 = 0;
17458 let mut i = 0usize;
17459 while i < 7 {
17460 let v = aw[i];
17461 out[i] = (v << 1) | carry;
17462 carry = v >> 63;
17463 i += 1;
17464 }
17465 Limbs::<7>::from_words(out)
17466}
17467
17468#[inline]
17469#[must_use]
17470const fn limbs_set_bit0_7(a: Limbs<7>) -> Limbs<7> {
17471 let aw = a.words();
17472 let mut out = [0u64; 7];
17473 let mut i = 0usize;
17474 while i < 7 {
17475 out[i] = aw[i];
17476 i += 1;
17477 }
17478 out[0] |= 1u64;
17479 Limbs::<7>::from_words(out)
17480}
17481
17482#[inline]
17483#[must_use]
17484const fn limbs_bit_msb_7(a: Limbs<7>, msb_index: usize) -> u64 {
17485 let aw = a.words();
17486 let total_bits = 7 * 64;
17487 let lsb_index = total_bits - 1 - msb_index;
17488 let word = lsb_index / 64;
17489 let bit = lsb_index % 64;
17490 (aw[word] >> bit) & 1u64
17491}
17492
17493#[inline]
17494#[must_use]
17495const fn limbs_divmod_7(a: Limbs<7>, b: Limbs<7>) -> (Limbs<7>, Limbs<7>) {
17496 let mut q = Limbs::<7>::zero();
17497 let mut r = Limbs::<7>::zero();
17498 let total_bits = 7 * 64;
17499 let mut i = 0usize;
17500 while i < total_bits {
17501 r = limbs_shl1_7(r);
17502 if limbs_bit_msb_7(a, i) == 1 {
17503 r = limbs_set_bit0_7(r);
17504 }
17505 if limbs_le_7(b, r) {
17506 r = r.wrapping_sub(b);
17507 q = limbs_shl1_7(q);
17508 q = limbs_set_bit0_7(q);
17509 } else {
17510 q = limbs_shl1_7(q);
17511 }
17512 i += 1;
17513 }
17514 (q, r)
17515}
17516
17517#[inline]
17518#[must_use]
17519const fn limbs_div_7(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
17520 let (q, _) = limbs_divmod_7(a, b);
17521 q
17522}
17523
17524#[inline]
17525#[must_use]
17526const fn limbs_mod_7(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
17527 let (_, r) = limbs_divmod_7(a, b);
17528 r
17529}
17530
17531#[inline]
17532#[must_use]
17533const fn limbs_pow_7(base: Limbs<7>, exp: Limbs<7>) -> Limbs<7> {
17534 let mut result = limbs_one_7();
17535 let mut b = base;
17536 let ew = exp.words();
17537 let mut word = 0usize;
17538 while word < 7 {
17539 let mut bit = 0u32;
17540 while bit < 64 {
17541 if ((ew[word] >> bit) & 1u64) == 1u64 {
17542 result = result.wrapping_mul(b);
17543 }
17544 b = b.wrapping_mul(b);
17545 bit += 1;
17546 }
17547 word += 1;
17548 }
17549 result
17550}
17551
17552#[inline]
17553#[must_use]
17554const fn limbs_is_zero_8(a: Limbs<8>) -> bool {
17555 let aw = a.words();
17556 let mut i = 0usize;
17557 while i < 8 {
17558 if aw[i] != 0 {
17559 return false;
17560 }
17561 i += 1;
17562 }
17563 true
17564}
17565
17566#[inline]
17567#[must_use]
17568const fn limbs_shl1_8(a: Limbs<8>) -> Limbs<8> {
17569 let aw = a.words();
17570 let mut out = [0u64; 8];
17571 let mut carry: u64 = 0;
17572 let mut i = 0usize;
17573 while i < 8 {
17574 let v = aw[i];
17575 out[i] = (v << 1) | carry;
17576 carry = v >> 63;
17577 i += 1;
17578 }
17579 Limbs::<8>::from_words(out)
17580}
17581
17582#[inline]
17583#[must_use]
17584const fn limbs_set_bit0_8(a: Limbs<8>) -> Limbs<8> {
17585 let aw = a.words();
17586 let mut out = [0u64; 8];
17587 let mut i = 0usize;
17588 while i < 8 {
17589 out[i] = aw[i];
17590 i += 1;
17591 }
17592 out[0] |= 1u64;
17593 Limbs::<8>::from_words(out)
17594}
17595
17596#[inline]
17597#[must_use]
17598const fn limbs_bit_msb_8(a: Limbs<8>, msb_index: usize) -> u64 {
17599 let aw = a.words();
17600 let total_bits = 8 * 64;
17601 let lsb_index = total_bits - 1 - msb_index;
17602 let word = lsb_index / 64;
17603 let bit = lsb_index % 64;
17604 (aw[word] >> bit) & 1u64
17605}
17606
17607#[inline]
17608#[must_use]
17609const fn limbs_divmod_8(a: Limbs<8>, b: Limbs<8>) -> (Limbs<8>, Limbs<8>) {
17610 let mut q = Limbs::<8>::zero();
17611 let mut r = Limbs::<8>::zero();
17612 let total_bits = 8 * 64;
17613 let mut i = 0usize;
17614 while i < total_bits {
17615 r = limbs_shl1_8(r);
17616 if limbs_bit_msb_8(a, i) == 1 {
17617 r = limbs_set_bit0_8(r);
17618 }
17619 if limbs_le_8(b, r) {
17620 r = r.wrapping_sub(b);
17621 q = limbs_shl1_8(q);
17622 q = limbs_set_bit0_8(q);
17623 } else {
17624 q = limbs_shl1_8(q);
17625 }
17626 i += 1;
17627 }
17628 (q, r)
17629}
17630
17631#[inline]
17632#[must_use]
17633const fn limbs_div_8(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
17634 let (q, _) = limbs_divmod_8(a, b);
17635 q
17636}
17637
17638#[inline]
17639#[must_use]
17640const fn limbs_mod_8(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
17641 let (_, r) = limbs_divmod_8(a, b);
17642 r
17643}
17644
17645#[inline]
17646#[must_use]
17647const fn limbs_pow_8(base: Limbs<8>, exp: Limbs<8>) -> Limbs<8> {
17648 let mut result = limbs_one_8();
17649 let mut b = base;
17650 let ew = exp.words();
17651 let mut word = 0usize;
17652 while word < 8 {
17653 let mut bit = 0u32;
17654 while bit < 64 {
17655 if ((ew[word] >> bit) & 1u64) == 1u64 {
17656 result = result.wrapping_mul(b);
17657 }
17658 b = b.wrapping_mul(b);
17659 bit += 1;
17660 }
17661 word += 1;
17662 }
17663 result
17664}
17665
17666#[inline]
17667#[must_use]
17668const fn limbs_is_zero_9(a: Limbs<9>) -> bool {
17669 let aw = a.words();
17670 let mut i = 0usize;
17671 while i < 9 {
17672 if aw[i] != 0 {
17673 return false;
17674 }
17675 i += 1;
17676 }
17677 true
17678}
17679
17680#[inline]
17681#[must_use]
17682const fn limbs_shl1_9(a: Limbs<9>) -> Limbs<9> {
17683 let aw = a.words();
17684 let mut out = [0u64; 9];
17685 let mut carry: u64 = 0;
17686 let mut i = 0usize;
17687 while i < 9 {
17688 let v = aw[i];
17689 out[i] = (v << 1) | carry;
17690 carry = v >> 63;
17691 i += 1;
17692 }
17693 Limbs::<9>::from_words(out)
17694}
17695
17696#[inline]
17697#[must_use]
17698const fn limbs_set_bit0_9(a: Limbs<9>) -> Limbs<9> {
17699 let aw = a.words();
17700 let mut out = [0u64; 9];
17701 let mut i = 0usize;
17702 while i < 9 {
17703 out[i] = aw[i];
17704 i += 1;
17705 }
17706 out[0] |= 1u64;
17707 Limbs::<9>::from_words(out)
17708}
17709
17710#[inline]
17711#[must_use]
17712const fn limbs_bit_msb_9(a: Limbs<9>, msb_index: usize) -> u64 {
17713 let aw = a.words();
17714 let total_bits = 9 * 64;
17715 let lsb_index = total_bits - 1 - msb_index;
17716 let word = lsb_index / 64;
17717 let bit = lsb_index % 64;
17718 (aw[word] >> bit) & 1u64
17719}
17720
17721#[inline]
17722#[must_use]
17723const fn limbs_divmod_9(a: Limbs<9>, b: Limbs<9>) -> (Limbs<9>, Limbs<9>) {
17724 let mut q = Limbs::<9>::zero();
17725 let mut r = Limbs::<9>::zero();
17726 let total_bits = 9 * 64;
17727 let mut i = 0usize;
17728 while i < total_bits {
17729 r = limbs_shl1_9(r);
17730 if limbs_bit_msb_9(a, i) == 1 {
17731 r = limbs_set_bit0_9(r);
17732 }
17733 if limbs_le_9(b, r) {
17734 r = r.wrapping_sub(b);
17735 q = limbs_shl1_9(q);
17736 q = limbs_set_bit0_9(q);
17737 } else {
17738 q = limbs_shl1_9(q);
17739 }
17740 i += 1;
17741 }
17742 (q, r)
17743}
17744
17745#[inline]
17746#[must_use]
17747const fn limbs_div_9(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
17748 let (q, _) = limbs_divmod_9(a, b);
17749 q
17750}
17751
17752#[inline]
17753#[must_use]
17754const fn limbs_mod_9(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
17755 let (_, r) = limbs_divmod_9(a, b);
17756 r
17757}
17758
17759#[inline]
17760#[must_use]
17761const fn limbs_pow_9(base: Limbs<9>, exp: Limbs<9>) -> Limbs<9> {
17762 let mut result = limbs_one_9();
17763 let mut b = base;
17764 let ew = exp.words();
17765 let mut word = 0usize;
17766 while word < 9 {
17767 let mut bit = 0u32;
17768 while bit < 64 {
17769 if ((ew[word] >> bit) & 1u64) == 1u64 {
17770 result = result.wrapping_mul(b);
17771 }
17772 b = b.wrapping_mul(b);
17773 bit += 1;
17774 }
17775 word += 1;
17776 }
17777 result
17778}
17779
17780#[inline]
17781#[must_use]
17782const fn limbs_is_zero_16(a: Limbs<16>) -> bool {
17783 let aw = a.words();
17784 let mut i = 0usize;
17785 while i < 16 {
17786 if aw[i] != 0 {
17787 return false;
17788 }
17789 i += 1;
17790 }
17791 true
17792}
17793
17794#[inline]
17795#[must_use]
17796const fn limbs_shl1_16(a: Limbs<16>) -> Limbs<16> {
17797 let aw = a.words();
17798 let mut out = [0u64; 16];
17799 let mut carry: u64 = 0;
17800 let mut i = 0usize;
17801 while i < 16 {
17802 let v = aw[i];
17803 out[i] = (v << 1) | carry;
17804 carry = v >> 63;
17805 i += 1;
17806 }
17807 Limbs::<16>::from_words(out)
17808}
17809
17810#[inline]
17811#[must_use]
17812const fn limbs_set_bit0_16(a: Limbs<16>) -> Limbs<16> {
17813 let aw = a.words();
17814 let mut out = [0u64; 16];
17815 let mut i = 0usize;
17816 while i < 16 {
17817 out[i] = aw[i];
17818 i += 1;
17819 }
17820 out[0] |= 1u64;
17821 Limbs::<16>::from_words(out)
17822}
17823
17824#[inline]
17825#[must_use]
17826const fn limbs_bit_msb_16(a: Limbs<16>, msb_index: usize) -> u64 {
17827 let aw = a.words();
17828 let total_bits = 16 * 64;
17829 let lsb_index = total_bits - 1 - msb_index;
17830 let word = lsb_index / 64;
17831 let bit = lsb_index % 64;
17832 (aw[word] >> bit) & 1u64
17833}
17834
17835#[inline]
17836#[must_use]
17837const fn limbs_divmod_16(a: Limbs<16>, b: Limbs<16>) -> (Limbs<16>, Limbs<16>) {
17838 let mut q = Limbs::<16>::zero();
17839 let mut r = Limbs::<16>::zero();
17840 let total_bits = 16 * 64;
17841 let mut i = 0usize;
17842 while i < total_bits {
17843 r = limbs_shl1_16(r);
17844 if limbs_bit_msb_16(a, i) == 1 {
17845 r = limbs_set_bit0_16(r);
17846 }
17847 if limbs_le_16(b, r) {
17848 r = r.wrapping_sub(b);
17849 q = limbs_shl1_16(q);
17850 q = limbs_set_bit0_16(q);
17851 } else {
17852 q = limbs_shl1_16(q);
17853 }
17854 i += 1;
17855 }
17856 (q, r)
17857}
17858
17859#[inline]
17860#[must_use]
17861const fn limbs_div_16(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
17862 let (q, _) = limbs_divmod_16(a, b);
17863 q
17864}
17865
17866#[inline]
17867#[must_use]
17868const fn limbs_mod_16(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
17869 let (_, r) = limbs_divmod_16(a, b);
17870 r
17871}
17872
17873#[inline]
17874#[must_use]
17875const fn limbs_pow_16(base: Limbs<16>, exp: Limbs<16>) -> Limbs<16> {
17876 let mut result = limbs_one_16();
17877 let mut b = base;
17878 let ew = exp.words();
17879 let mut word = 0usize;
17880 while word < 16 {
17881 let mut bit = 0u32;
17882 while bit < 64 {
17883 if ((ew[word] >> bit) & 1u64) == 1u64 {
17884 result = result.wrapping_mul(b);
17885 }
17886 b = b.wrapping_mul(b);
17887 bit += 1;
17888 }
17889 word += 1;
17890 }
17891 result
17892}
17893
17894#[inline]
17895#[must_use]
17896const fn limbs_is_zero_32(a: Limbs<32>) -> bool {
17897 let aw = a.words();
17898 let mut i = 0usize;
17899 while i < 32 {
17900 if aw[i] != 0 {
17901 return false;
17902 }
17903 i += 1;
17904 }
17905 true
17906}
17907
17908#[inline]
17909#[must_use]
17910const fn limbs_shl1_32(a: Limbs<32>) -> Limbs<32> {
17911 let aw = a.words();
17912 let mut out = [0u64; 32];
17913 let mut carry: u64 = 0;
17914 let mut i = 0usize;
17915 while i < 32 {
17916 let v = aw[i];
17917 out[i] = (v << 1) | carry;
17918 carry = v >> 63;
17919 i += 1;
17920 }
17921 Limbs::<32>::from_words(out)
17922}
17923
17924#[inline]
17925#[must_use]
17926const fn limbs_set_bit0_32(a: Limbs<32>) -> Limbs<32> {
17927 let aw = a.words();
17928 let mut out = [0u64; 32];
17929 let mut i = 0usize;
17930 while i < 32 {
17931 out[i] = aw[i];
17932 i += 1;
17933 }
17934 out[0] |= 1u64;
17935 Limbs::<32>::from_words(out)
17936}
17937
17938#[inline]
17939#[must_use]
17940const fn limbs_bit_msb_32(a: Limbs<32>, msb_index: usize) -> u64 {
17941 let aw = a.words();
17942 let total_bits = 32 * 64;
17943 let lsb_index = total_bits - 1 - msb_index;
17944 let word = lsb_index / 64;
17945 let bit = lsb_index % 64;
17946 (aw[word] >> bit) & 1u64
17947}
17948
17949#[inline]
17950#[must_use]
17951const fn limbs_divmod_32(a: Limbs<32>, b: Limbs<32>) -> (Limbs<32>, Limbs<32>) {
17952 let mut q = Limbs::<32>::zero();
17953 let mut r = Limbs::<32>::zero();
17954 let total_bits = 32 * 64;
17955 let mut i = 0usize;
17956 while i < total_bits {
17957 r = limbs_shl1_32(r);
17958 if limbs_bit_msb_32(a, i) == 1 {
17959 r = limbs_set_bit0_32(r);
17960 }
17961 if limbs_le_32(b, r) {
17962 r = r.wrapping_sub(b);
17963 q = limbs_shl1_32(q);
17964 q = limbs_set_bit0_32(q);
17965 } else {
17966 q = limbs_shl1_32(q);
17967 }
17968 i += 1;
17969 }
17970 (q, r)
17971}
17972
17973#[inline]
17974#[must_use]
17975const fn limbs_div_32(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
17976 let (q, _) = limbs_divmod_32(a, b);
17977 q
17978}
17979
17980#[inline]
17981#[must_use]
17982const fn limbs_mod_32(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
17983 let (_, r) = limbs_divmod_32(a, b);
17984 r
17985}
17986
17987#[inline]
17988#[must_use]
17989const fn limbs_pow_32(base: Limbs<32>, exp: Limbs<32>) -> Limbs<32> {
17990 let mut result = limbs_one_32();
17991 let mut b = base;
17992 let ew = exp.words();
17993 let mut word = 0usize;
17994 while word < 32 {
17995 let mut bit = 0u32;
17996 while bit < 64 {
17997 if ((ew[word] >> bit) & 1u64) == 1u64 {
17998 result = result.wrapping_mul(b);
17999 }
18000 b = b.wrapping_mul(b);
18001 bit += 1;
18002 }
18003 word += 1;
18004 }
18005 result
18006}
18007
18008#[inline]
18009#[must_use]
18010const fn limbs_is_zero_64(a: Limbs<64>) -> bool {
18011 let aw = a.words();
18012 let mut i = 0usize;
18013 while i < 64 {
18014 if aw[i] != 0 {
18015 return false;
18016 }
18017 i += 1;
18018 }
18019 true
18020}
18021
18022#[inline]
18023#[must_use]
18024const fn limbs_shl1_64(a: Limbs<64>) -> Limbs<64> {
18025 let aw = a.words();
18026 let mut out = [0u64; 64];
18027 let mut carry: u64 = 0;
18028 let mut i = 0usize;
18029 while i < 64 {
18030 let v = aw[i];
18031 out[i] = (v << 1) | carry;
18032 carry = v >> 63;
18033 i += 1;
18034 }
18035 Limbs::<64>::from_words(out)
18036}
18037
18038#[inline]
18039#[must_use]
18040const fn limbs_set_bit0_64(a: Limbs<64>) -> Limbs<64> {
18041 let aw = a.words();
18042 let mut out = [0u64; 64];
18043 let mut i = 0usize;
18044 while i < 64 {
18045 out[i] = aw[i];
18046 i += 1;
18047 }
18048 out[0] |= 1u64;
18049 Limbs::<64>::from_words(out)
18050}
18051
18052#[inline]
18053#[must_use]
18054const fn limbs_bit_msb_64(a: Limbs<64>, msb_index: usize) -> u64 {
18055 let aw = a.words();
18056 let total_bits = 64 * 64;
18057 let lsb_index = total_bits - 1 - msb_index;
18058 let word = lsb_index / 64;
18059 let bit = lsb_index % 64;
18060 (aw[word] >> bit) & 1u64
18061}
18062
18063#[inline]
18064#[must_use]
18065const fn limbs_divmod_64(a: Limbs<64>, b: Limbs<64>) -> (Limbs<64>, Limbs<64>) {
18066 let mut q = Limbs::<64>::zero();
18067 let mut r = Limbs::<64>::zero();
18068 let total_bits = 64 * 64;
18069 let mut i = 0usize;
18070 while i < total_bits {
18071 r = limbs_shl1_64(r);
18072 if limbs_bit_msb_64(a, i) == 1 {
18073 r = limbs_set_bit0_64(r);
18074 }
18075 if limbs_le_64(b, r) {
18076 r = r.wrapping_sub(b);
18077 q = limbs_shl1_64(q);
18078 q = limbs_set_bit0_64(q);
18079 } else {
18080 q = limbs_shl1_64(q);
18081 }
18082 i += 1;
18083 }
18084 (q, r)
18085}
18086
18087#[inline]
18088#[must_use]
18089const fn limbs_div_64(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
18090 let (q, _) = limbs_divmod_64(a, b);
18091 q
18092}
18093
18094#[inline]
18095#[must_use]
18096const fn limbs_mod_64(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
18097 let (_, r) = limbs_divmod_64(a, b);
18098 r
18099}
18100
18101#[inline]
18102#[must_use]
18103const fn limbs_pow_64(base: Limbs<64>, exp: Limbs<64>) -> Limbs<64> {
18104 let mut result = limbs_one_64();
18105 let mut b = base;
18106 let ew = exp.words();
18107 let mut word = 0usize;
18108 while word < 64 {
18109 let mut bit = 0u32;
18110 while bit < 64 {
18111 if ((ew[word] >> bit) & 1u64) == 1u64 {
18112 result = result.wrapping_mul(b);
18113 }
18114 b = b.wrapping_mul(b);
18115 bit += 1;
18116 }
18117 word += 1;
18118 }
18119 result
18120}
18121
18122#[inline]
18123#[must_use]
18124const fn limbs_is_zero_128(a: Limbs<128>) -> bool {
18125 let aw = a.words();
18126 let mut i = 0usize;
18127 while i < 128 {
18128 if aw[i] != 0 {
18129 return false;
18130 }
18131 i += 1;
18132 }
18133 true
18134}
18135
18136#[inline]
18137#[must_use]
18138const fn limbs_shl1_128(a: Limbs<128>) -> Limbs<128> {
18139 let aw = a.words();
18140 let mut out = [0u64; 128];
18141 let mut carry: u64 = 0;
18142 let mut i = 0usize;
18143 while i < 128 {
18144 let v = aw[i];
18145 out[i] = (v << 1) | carry;
18146 carry = v >> 63;
18147 i += 1;
18148 }
18149 Limbs::<128>::from_words(out)
18150}
18151
18152#[inline]
18153#[must_use]
18154const fn limbs_set_bit0_128(a: Limbs<128>) -> Limbs<128> {
18155 let aw = a.words();
18156 let mut out = [0u64; 128];
18157 let mut i = 0usize;
18158 while i < 128 {
18159 out[i] = aw[i];
18160 i += 1;
18161 }
18162 out[0] |= 1u64;
18163 Limbs::<128>::from_words(out)
18164}
18165
18166#[inline]
18167#[must_use]
18168const fn limbs_bit_msb_128(a: Limbs<128>, msb_index: usize) -> u64 {
18169 let aw = a.words();
18170 let total_bits = 128 * 64;
18171 let lsb_index = total_bits - 1 - msb_index;
18172 let word = lsb_index / 64;
18173 let bit = lsb_index % 64;
18174 (aw[word] >> bit) & 1u64
18175}
18176
18177#[inline]
18178#[must_use]
18179const fn limbs_divmod_128(a: Limbs<128>, b: Limbs<128>) -> (Limbs<128>, Limbs<128>) {
18180 let mut q = Limbs::<128>::zero();
18181 let mut r = Limbs::<128>::zero();
18182 let total_bits = 128 * 64;
18183 let mut i = 0usize;
18184 while i < total_bits {
18185 r = limbs_shl1_128(r);
18186 if limbs_bit_msb_128(a, i) == 1 {
18187 r = limbs_set_bit0_128(r);
18188 }
18189 if limbs_le_128(b, r) {
18190 r = r.wrapping_sub(b);
18191 q = limbs_shl1_128(q);
18192 q = limbs_set_bit0_128(q);
18193 } else {
18194 q = limbs_shl1_128(q);
18195 }
18196 i += 1;
18197 }
18198 (q, r)
18199}
18200
18201#[inline]
18202#[must_use]
18203const fn limbs_div_128(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
18204 let (q, _) = limbs_divmod_128(a, b);
18205 q
18206}
18207
18208#[inline]
18209#[must_use]
18210const fn limbs_mod_128(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
18211 let (_, r) = limbs_divmod_128(a, b);
18212 r
18213}
18214
18215#[inline]
18216#[must_use]
18217const fn limbs_pow_128(base: Limbs<128>, exp: Limbs<128>) -> Limbs<128> {
18218 let mut result = limbs_one_128();
18219 let mut b = base;
18220 let ew = exp.words();
18221 let mut word = 0usize;
18222 while word < 128 {
18223 let mut bit = 0u32;
18224 while bit < 64 {
18225 if ((ew[word] >> bit) & 1u64) == 1u64 {
18226 result = result.wrapping_mul(b);
18227 }
18228 b = b.wrapping_mul(b);
18229 bit += 1;
18230 }
18231 word += 1;
18232 }
18233 result
18234}
18235
18236#[inline]
18237#[must_use]
18238const fn limbs_is_zero_192(a: Limbs<192>) -> bool {
18239 let aw = a.words();
18240 let mut i = 0usize;
18241 while i < 192 {
18242 if aw[i] != 0 {
18243 return false;
18244 }
18245 i += 1;
18246 }
18247 true
18248}
18249
18250#[inline]
18251#[must_use]
18252const fn limbs_shl1_192(a: Limbs<192>) -> Limbs<192> {
18253 let aw = a.words();
18254 let mut out = [0u64; 192];
18255 let mut carry: u64 = 0;
18256 let mut i = 0usize;
18257 while i < 192 {
18258 let v = aw[i];
18259 out[i] = (v << 1) | carry;
18260 carry = v >> 63;
18261 i += 1;
18262 }
18263 Limbs::<192>::from_words(out)
18264}
18265
18266#[inline]
18267#[must_use]
18268const fn limbs_set_bit0_192(a: Limbs<192>) -> Limbs<192> {
18269 let aw = a.words();
18270 let mut out = [0u64; 192];
18271 let mut i = 0usize;
18272 while i < 192 {
18273 out[i] = aw[i];
18274 i += 1;
18275 }
18276 out[0] |= 1u64;
18277 Limbs::<192>::from_words(out)
18278}
18279
18280#[inline]
18281#[must_use]
18282const fn limbs_bit_msb_192(a: Limbs<192>, msb_index: usize) -> u64 {
18283 let aw = a.words();
18284 let total_bits = 192 * 64;
18285 let lsb_index = total_bits - 1 - msb_index;
18286 let word = lsb_index / 64;
18287 let bit = lsb_index % 64;
18288 (aw[word] >> bit) & 1u64
18289}
18290
18291#[inline]
18292#[must_use]
18293const fn limbs_divmod_192(a: Limbs<192>, b: Limbs<192>) -> (Limbs<192>, Limbs<192>) {
18294 let mut q = Limbs::<192>::zero();
18295 let mut r = Limbs::<192>::zero();
18296 let total_bits = 192 * 64;
18297 let mut i = 0usize;
18298 while i < total_bits {
18299 r = limbs_shl1_192(r);
18300 if limbs_bit_msb_192(a, i) == 1 {
18301 r = limbs_set_bit0_192(r);
18302 }
18303 if limbs_le_192(b, r) {
18304 r = r.wrapping_sub(b);
18305 q = limbs_shl1_192(q);
18306 q = limbs_set_bit0_192(q);
18307 } else {
18308 q = limbs_shl1_192(q);
18309 }
18310 i += 1;
18311 }
18312 (q, r)
18313}
18314
18315#[inline]
18316#[must_use]
18317const fn limbs_div_192(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
18318 let (q, _) = limbs_divmod_192(a, b);
18319 q
18320}
18321
18322#[inline]
18323#[must_use]
18324const fn limbs_mod_192(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
18325 let (_, r) = limbs_divmod_192(a, b);
18326 r
18327}
18328
18329#[inline]
18330#[must_use]
18331const fn limbs_pow_192(base: Limbs<192>, exp: Limbs<192>) -> Limbs<192> {
18332 let mut result = limbs_one_192();
18333 let mut b = base;
18334 let ew = exp.words();
18335 let mut word = 0usize;
18336 while word < 192 {
18337 let mut bit = 0u32;
18338 while bit < 64 {
18339 if ((ew[word] >> bit) & 1u64) == 1u64 {
18340 result = result.wrapping_mul(b);
18341 }
18342 b = b.wrapping_mul(b);
18343 bit += 1;
18344 }
18345 word += 1;
18346 }
18347 result
18348}
18349
18350#[inline]
18351#[must_use]
18352const fn limbs_is_zero_256(a: Limbs<256>) -> bool {
18353 let aw = a.words();
18354 let mut i = 0usize;
18355 while i < 256 {
18356 if aw[i] != 0 {
18357 return false;
18358 }
18359 i += 1;
18360 }
18361 true
18362}
18363
18364#[inline]
18365#[must_use]
18366const fn limbs_shl1_256(a: Limbs<256>) -> Limbs<256> {
18367 let aw = a.words();
18368 let mut out = [0u64; 256];
18369 let mut carry: u64 = 0;
18370 let mut i = 0usize;
18371 while i < 256 {
18372 let v = aw[i];
18373 out[i] = (v << 1) | carry;
18374 carry = v >> 63;
18375 i += 1;
18376 }
18377 Limbs::<256>::from_words(out)
18378}
18379
18380#[inline]
18381#[must_use]
18382const fn limbs_set_bit0_256(a: Limbs<256>) -> Limbs<256> {
18383 let aw = a.words();
18384 let mut out = [0u64; 256];
18385 let mut i = 0usize;
18386 while i < 256 {
18387 out[i] = aw[i];
18388 i += 1;
18389 }
18390 out[0] |= 1u64;
18391 Limbs::<256>::from_words(out)
18392}
18393
18394#[inline]
18395#[must_use]
18396const fn limbs_bit_msb_256(a: Limbs<256>, msb_index: usize) -> u64 {
18397 let aw = a.words();
18398 let total_bits = 256 * 64;
18399 let lsb_index = total_bits - 1 - msb_index;
18400 let word = lsb_index / 64;
18401 let bit = lsb_index % 64;
18402 (aw[word] >> bit) & 1u64
18403}
18404
18405#[inline]
18406#[must_use]
18407const fn limbs_divmod_256(a: Limbs<256>, b: Limbs<256>) -> (Limbs<256>, Limbs<256>) {
18408 let mut q = Limbs::<256>::zero();
18409 let mut r = Limbs::<256>::zero();
18410 let total_bits = 256 * 64;
18411 let mut i = 0usize;
18412 while i < total_bits {
18413 r = limbs_shl1_256(r);
18414 if limbs_bit_msb_256(a, i) == 1 {
18415 r = limbs_set_bit0_256(r);
18416 }
18417 if limbs_le_256(b, r) {
18418 r = r.wrapping_sub(b);
18419 q = limbs_shl1_256(q);
18420 q = limbs_set_bit0_256(q);
18421 } else {
18422 q = limbs_shl1_256(q);
18423 }
18424 i += 1;
18425 }
18426 (q, r)
18427}
18428
18429#[inline]
18430#[must_use]
18431const fn limbs_div_256(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
18432 let (q, _) = limbs_divmod_256(a, b);
18433 q
18434}
18435
18436#[inline]
18437#[must_use]
18438const fn limbs_mod_256(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
18439 let (_, r) = limbs_divmod_256(a, b);
18440 r
18441}
18442
18443#[inline]
18444#[must_use]
18445const fn limbs_pow_256(base: Limbs<256>, exp: Limbs<256>) -> Limbs<256> {
18446 let mut result = limbs_one_256();
18447 let mut b = base;
18448 let ew = exp.words();
18449 let mut word = 0usize;
18450 while word < 256 {
18451 let mut bit = 0u32;
18452 while bit < 64 {
18453 if ((ew[word] >> bit) & 1u64) == 1u64 {
18454 result = result.wrapping_mul(b);
18455 }
18456 b = b.wrapping_mul(b);
18457 bit += 1;
18458 }
18459 word += 1;
18460 }
18461 result
18462}
18463
18464#[inline]
18465#[must_use]
18466const fn limbs_is_zero_512(a: Limbs<512>) -> bool {
18467 let aw = a.words();
18468 let mut i = 0usize;
18469 while i < 512 {
18470 if aw[i] != 0 {
18471 return false;
18472 }
18473 i += 1;
18474 }
18475 true
18476}
18477
18478#[inline]
18479#[must_use]
18480const fn limbs_shl1_512(a: Limbs<512>) -> Limbs<512> {
18481 let aw = a.words();
18482 let mut out = [0u64; 512];
18483 let mut carry: u64 = 0;
18484 let mut i = 0usize;
18485 while i < 512 {
18486 let v = aw[i];
18487 out[i] = (v << 1) | carry;
18488 carry = v >> 63;
18489 i += 1;
18490 }
18491 Limbs::<512>::from_words(out)
18492}
18493
18494#[inline]
18495#[must_use]
18496const fn limbs_set_bit0_512(a: Limbs<512>) -> Limbs<512> {
18497 let aw = a.words();
18498 let mut out = [0u64; 512];
18499 let mut i = 0usize;
18500 while i < 512 {
18501 out[i] = aw[i];
18502 i += 1;
18503 }
18504 out[0] |= 1u64;
18505 Limbs::<512>::from_words(out)
18506}
18507
18508#[inline]
18509#[must_use]
18510const fn limbs_bit_msb_512(a: Limbs<512>, msb_index: usize) -> u64 {
18511 let aw = a.words();
18512 let total_bits = 512 * 64;
18513 let lsb_index = total_bits - 1 - msb_index;
18514 let word = lsb_index / 64;
18515 let bit = lsb_index % 64;
18516 (aw[word] >> bit) & 1u64
18517}
18518
18519#[inline]
18520#[must_use]
18521const fn limbs_divmod_512(a: Limbs<512>, b: Limbs<512>) -> (Limbs<512>, Limbs<512>) {
18522 let mut q = Limbs::<512>::zero();
18523 let mut r = Limbs::<512>::zero();
18524 let total_bits = 512 * 64;
18525 let mut i = 0usize;
18526 while i < total_bits {
18527 r = limbs_shl1_512(r);
18528 if limbs_bit_msb_512(a, i) == 1 {
18529 r = limbs_set_bit0_512(r);
18530 }
18531 if limbs_le_512(b, r) {
18532 r = r.wrapping_sub(b);
18533 q = limbs_shl1_512(q);
18534 q = limbs_set_bit0_512(q);
18535 } else {
18536 q = limbs_shl1_512(q);
18537 }
18538 i += 1;
18539 }
18540 (q, r)
18541}
18542
18543#[inline]
18544#[must_use]
18545const fn limbs_div_512(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
18546 let (q, _) = limbs_divmod_512(a, b);
18547 q
18548}
18549
18550#[inline]
18551#[must_use]
18552const fn limbs_mod_512(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
18553 let (_, r) = limbs_divmod_512(a, b);
18554 r
18555}
18556
18557#[inline]
18558#[must_use]
18559const fn limbs_pow_512(base: Limbs<512>, exp: Limbs<512>) -> Limbs<512> {
18560 let mut result = limbs_one_512();
18561 let mut b = base;
18562 let ew = exp.words();
18563 let mut word = 0usize;
18564 while word < 512 {
18565 let mut bit = 0u32;
18566 while bit < 64 {
18567 if ((ew[word] >> bit) & 1u64) == 1u64 {
18568 result = result.wrapping_mul(b);
18569 }
18570 b = b.wrapping_mul(b);
18571 bit += 1;
18572 }
18573 word += 1;
18574 }
18575 result
18576}
18577
18578pub trait FragmentMarker: fragment_sealed::Sealed {}
18582
18583mod fragment_sealed {
18584 pub trait Sealed {}
18586 impl Sealed for super::Is2SatShape {}
18587 impl Sealed for super::IsHornShape {}
18588 impl Sealed for super::IsResidualFragment {}
18589}
18590
18591#[derive(Debug, Default, Clone, Copy)]
18593pub struct Is2SatShape;
18594impl FragmentMarker for Is2SatShape {}
18595
18596#[derive(Debug, Default, Clone, Copy)]
18598pub struct IsHornShape;
18599impl FragmentMarker for IsHornShape {}
18600
18601#[derive(Debug, Default, Clone, Copy)]
18603pub struct IsResidualFragment;
18604impl FragmentMarker for IsResidualFragment {}
18605
18606#[derive(Debug, Clone, Copy)]
18609pub struct DispatchRule {
18610 pub predicate_iri: &'static str,
18612 pub target_resolver_iri: &'static str,
18614 pub priority: u32,
18616}
18617
18618pub type DispatchTable = &'static [DispatchRule];
18620
18621pub const INHABITANCE_DISPATCH_TABLE: DispatchTable = &[
18623 DispatchRule {
18624 predicate_iri: "https://uor.foundation/predicate/Is2SatShape",
18625 target_resolver_iri: "https://uor.foundation/resolver/TwoSatDecider",
18626 priority: 0,
18627 },
18628 DispatchRule {
18629 predicate_iri: "https://uor.foundation/predicate/IsHornShape",
18630 target_resolver_iri: "https://uor.foundation/resolver/HornSatDecider",
18631 priority: 1,
18632 },
18633 DispatchRule {
18634 predicate_iri: "https://uor.foundation/predicate/IsResidualFragment",
18635 target_resolver_iri: "https://uor.foundation/resolver/ResidualVerdictResolver",
18636 priority: 2,
18637 },
18638];
18639
18640impl<T: OntologyTarget> core::ops::Deref for Validated<T> {
18645 type Target = T;
18646 #[inline]
18647 fn deref(&self) -> &T {
18648 &self.inner
18649 }
18650}
18651
18652mod bound_constraint_sealed {
18653 pub trait ObservableSealed {}
18655 pub trait BoundShapeSealed {}
18657}
18658
18659pub trait Observable: bound_constraint_sealed::ObservableSealed {
18664 const IRI: &'static str;
18666}
18667
18668pub trait BoundShape: bound_constraint_sealed::BoundShapeSealed {
18672 const IRI: &'static str;
18674}
18675
18676#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18678pub struct ValueModObservable;
18679impl bound_constraint_sealed::ObservableSealed for ValueModObservable {}
18680impl Observable for ValueModObservable {
18681 const IRI: &'static str = "https://uor.foundation/observable/ValueModObservable";
18682}
18683
18684#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18686pub struct HammingMetric;
18687impl bound_constraint_sealed::ObservableSealed for HammingMetric {}
18688impl Observable for HammingMetric {
18689 const IRI: &'static str = "https://uor.foundation/observable/HammingMetric";
18690}
18691
18692#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18694pub struct DerivationDepthObservable;
18695impl bound_constraint_sealed::ObservableSealed for DerivationDepthObservable {}
18696impl Observable for DerivationDepthObservable {
18697 const IRI: &'static str = "https://uor.foundation/derivation/DerivationDepthObservable";
18698}
18699
18700#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18702pub struct CarryDepthObservable;
18703impl bound_constraint_sealed::ObservableSealed for CarryDepthObservable {}
18704impl Observable for CarryDepthObservable {
18705 const IRI: &'static str = "https://uor.foundation/carry/CarryDepthObservable";
18706}
18707
18708#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18710pub struct FreeRankObservable;
18711impl bound_constraint_sealed::ObservableSealed for FreeRankObservable {}
18712impl Observable for FreeRankObservable {
18713 const IRI: &'static str = "https://uor.foundation/partition/FreeRankObservable";
18714}
18715
18716#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18718pub struct EqualBound;
18719impl bound_constraint_sealed::BoundShapeSealed for EqualBound {}
18720impl BoundShape for EqualBound {
18721 const IRI: &'static str = "https://uor.foundation/type/EqualBound";
18722}
18723
18724#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18726pub struct LessEqBound;
18727impl bound_constraint_sealed::BoundShapeSealed for LessEqBound {}
18728impl BoundShape for LessEqBound {
18729 const IRI: &'static str = "https://uor.foundation/type/LessEqBound";
18730}
18731
18732#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18734pub struct GreaterEqBound;
18735impl bound_constraint_sealed::BoundShapeSealed for GreaterEqBound {}
18736impl BoundShape for GreaterEqBound {
18737 const IRI: &'static str = "https://uor.foundation/type/GreaterEqBound";
18738}
18739
18740#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18742pub struct RangeContainBound;
18743impl bound_constraint_sealed::BoundShapeSealed for RangeContainBound {}
18744impl BoundShape for RangeContainBound {
18745 const IRI: &'static str = "https://uor.foundation/type/RangeContainBound";
18746}
18747
18748#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18750pub struct ResidueClassBound;
18751impl bound_constraint_sealed::BoundShapeSealed for ResidueClassBound {}
18752impl BoundShape for ResidueClassBound {
18753 const IRI: &'static str = "https://uor.foundation/type/ResidueClassBound";
18754}
18755
18756#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18758pub struct AffineEqualBound;
18759impl bound_constraint_sealed::BoundShapeSealed for AffineEqualBound {}
18760impl BoundShape for AffineEqualBound {
18761 const IRI: &'static str = "https://uor.foundation/type/AffineEqualBound";
18762}
18763
18764#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18768pub enum BoundArgValue {
18769 U64(u64),
18771 I64(i64),
18773 Bytes32([u8; 32]),
18775}
18776
18777#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18783pub struct BoundArguments {
18784 entries: [Option<BoundArgEntry>; 8],
18785}
18786
18787#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18789pub struct BoundArgEntry {
18790 pub name: &'static str,
18792 pub value: BoundArgValue,
18794}
18795
18796impl BoundArguments {
18797 #[inline]
18799 #[must_use]
18800 pub const fn empty() -> Self {
18801 Self { entries: [None; 8] }
18802 }
18803
18804 #[inline]
18806 #[must_use]
18807 pub const fn single(name: &'static str, value: BoundArgValue) -> Self {
18808 let mut entries = [None; 8];
18809 entries[0] = Some(BoundArgEntry { name, value });
18810 Self { entries }
18811 }
18812
18813 #[inline]
18815 #[must_use]
18816 pub const fn pair(
18817 first: (&'static str, BoundArgValue),
18818 second: (&'static str, BoundArgValue),
18819 ) -> Self {
18820 let mut entries = [None; 8];
18821 entries[0] = Some(BoundArgEntry {
18822 name: first.0,
18823 value: first.1,
18824 });
18825 entries[1] = Some(BoundArgEntry {
18826 name: second.0,
18827 value: second.1,
18828 });
18829 Self { entries }
18830 }
18831
18832 #[inline]
18834 #[must_use]
18835 pub const fn entries(&self) -> &[Option<BoundArgEntry>; 8] {
18836 &self.entries
18837 }
18838}
18839
18840#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18845pub struct BoundConstraint<O: Observable, B: BoundShape> {
18846 observable: O,
18847 bound: B,
18848 args: BoundArguments,
18849 _sealed: (),
18850}
18851
18852impl<O: Observable, B: BoundShape> BoundConstraint<O, B> {
18853 #[inline]
18856 #[must_use]
18857 pub(crate) const fn from_parts(observable: O, bound: B, args: BoundArguments) -> Self {
18858 Self {
18859 observable,
18860 bound,
18861 args,
18862 _sealed: (),
18863 }
18864 }
18865
18866 #[inline]
18868 #[must_use]
18869 pub const fn observable(&self) -> &O {
18870 &self.observable
18871 }
18872
18873 #[inline]
18875 #[must_use]
18876 pub const fn bound(&self) -> &B {
18877 &self.bound
18878 }
18879
18880 #[inline]
18882 #[must_use]
18883 pub const fn args(&self) -> &BoundArguments {
18884 &self.args
18885 }
18886}
18887
18888#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18892pub struct Conjunction<const N: usize> {
18893 len: usize,
18894 _sealed: (),
18895}
18896
18897impl<const N: usize> Conjunction<N> {
18898 #[inline]
18900 #[must_use]
18901 pub const fn new(len: usize) -> Self {
18902 Self { len, _sealed: () }
18903 }
18904
18905 #[inline]
18907 #[must_use]
18908 pub const fn len(&self) -> usize {
18909 self.len
18910 }
18911
18912 #[inline]
18914 #[must_use]
18915 pub const fn is_empty(&self) -> bool {
18916 self.len == 0
18917 }
18918}
18919
18920pub type ResidueConstraint = BoundConstraint<ValueModObservable, ResidueClassBound>;
18923
18924impl ResidueConstraint {
18925 #[inline]
18927 #[must_use]
18928 pub const fn new(modulus: u64, residue: u64) -> Self {
18929 let args = BoundArguments::pair(
18930 ("modulus", BoundArgValue::U64(modulus)),
18931 ("residue", BoundArgValue::U64(residue)),
18932 );
18933 BoundConstraint::from_parts(ValueModObservable, ResidueClassBound, args)
18934 }
18935}
18936
18937pub type HammingConstraint = BoundConstraint<HammingMetric, LessEqBound>;
18940
18941impl HammingConstraint {
18942 #[inline]
18944 #[must_use]
18945 pub const fn new(bound: u64) -> Self {
18946 let args = BoundArguments::single("bound", BoundArgValue::U64(bound));
18947 BoundConstraint::from_parts(HammingMetric, LessEqBound, args)
18948 }
18949}
18950
18951pub type DepthConstraint = BoundConstraint<DerivationDepthObservable, LessEqBound>;
18954
18955impl DepthConstraint {
18956 #[inline]
18958 #[must_use]
18959 pub const fn new(min_depth: u64, max_depth: u64) -> Self {
18960 let args = BoundArguments::pair(
18961 ("min_depth", BoundArgValue::U64(min_depth)),
18962 ("max_depth", BoundArgValue::U64(max_depth)),
18963 );
18964 BoundConstraint::from_parts(DerivationDepthObservable, LessEqBound, args)
18965 }
18966}
18967
18968pub type CarryConstraint = BoundConstraint<CarryDepthObservable, LessEqBound>;
18971
18972impl CarryConstraint {
18973 #[inline]
18975 #[must_use]
18976 pub const fn new(bound: u64) -> Self {
18977 let args = BoundArguments::single("bound", BoundArgValue::U64(bound));
18978 BoundConstraint::from_parts(CarryDepthObservable, LessEqBound, args)
18979 }
18980}
18981
18982pub type SiteConstraint = BoundConstraint<FreeRankObservable, LessEqBound>;
18985
18986impl SiteConstraint {
18987 #[inline]
18989 #[must_use]
18990 pub const fn new(site_index: u64) -> Self {
18991 let args = BoundArguments::single("site_index", BoundArgValue::U64(site_index));
18992 BoundConstraint::from_parts(FreeRankObservable, LessEqBound, args)
18993 }
18994}
18995
18996pub type AffineConstraint = BoundConstraint<ValueModObservable, AffineEqualBound>;
18999
19000impl AffineConstraint {
19001 #[inline]
19003 #[must_use]
19004 pub const fn new(offset: u64) -> Self {
19005 let args = BoundArguments::single("offset", BoundArgValue::U64(offset));
19006 BoundConstraint::from_parts(ValueModObservable, AffineEqualBound, args)
19007 }
19008}
19009
19010pub type CompositeConstraint<const N: usize> = Conjunction<N>;
19013
19014#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19016pub struct Query {
19017 address: ContentAddress,
19018 _sealed: (),
19019}
19020
19021impl Query {
19022 #[inline]
19024 #[must_use]
19025 pub const fn address(&self) -> ContentAddress {
19026 self.address
19027 }
19028
19029 #[inline]
19031 #[must_use]
19032 #[allow(dead_code)]
19033 pub(crate) const fn new(address: ContentAddress) -> Self {
19034 Self {
19035 address,
19036 _sealed: (),
19037 }
19038 }
19039}
19040
19041#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19043pub struct Coordinate<L> {
19044 stratum: u64,
19045 spectrum: u64,
19046 address: u64,
19047 _level: PhantomData<L>,
19048 _sealed: (),
19049}
19050
19051impl<L> Coordinate<L> {
19052 #[inline]
19054 #[must_use]
19055 pub const fn stratum(&self) -> u64 {
19056 self.stratum
19057 }
19058
19059 #[inline]
19061 #[must_use]
19062 pub const fn spectrum(&self) -> u64 {
19063 self.spectrum
19064 }
19065
19066 #[inline]
19068 #[must_use]
19069 pub const fn address(&self) -> u64 {
19070 self.address
19071 }
19072
19073 #[inline]
19075 #[must_use]
19076 #[allow(dead_code)]
19077 pub(crate) const fn new(stratum: u64, spectrum: u64, address: u64) -> Self {
19078 Self {
19079 stratum,
19080 spectrum,
19081 address,
19082 _level: PhantomData,
19083 _sealed: (),
19084 }
19085 }
19086}
19087
19088#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19090pub struct BindingQuery {
19091 address: ContentAddress,
19092 _sealed: (),
19093}
19094
19095impl BindingQuery {
19096 #[inline]
19098 #[must_use]
19099 pub const fn address(&self) -> ContentAddress {
19100 self.address
19101 }
19102
19103 #[inline]
19105 #[must_use]
19106 #[allow(dead_code)]
19107 pub(crate) const fn new(address: ContentAddress) -> Self {
19108 Self {
19109 address,
19110 _sealed: (),
19111 }
19112 }
19113}
19114
19115#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19118pub struct Partition {
19119 component: PartitionComponent,
19120 _sealed: (),
19121}
19122
19123impl Partition {
19124 #[inline]
19126 #[must_use]
19127 pub const fn component(&self) -> PartitionComponent {
19128 self.component
19129 }
19130
19131 #[inline]
19133 #[must_use]
19134 #[allow(dead_code)]
19135 pub(crate) const fn new(component: PartitionComponent) -> Self {
19136 Self {
19137 component,
19138 _sealed: (),
19139 }
19140 }
19141}
19142
19143#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19148pub struct TraceEvent {
19149 step_index: u32,
19151 op: PrimitiveOp,
19153 target: ContentAddress,
19155 _sealed: (),
19157}
19158
19159impl TraceEvent {
19160 #[inline]
19162 #[must_use]
19163 pub const fn step_index(&self) -> u32 {
19164 self.step_index
19165 }
19166
19167 #[inline]
19169 #[must_use]
19170 pub const fn op(&self) -> PrimitiveOp {
19171 self.op
19172 }
19173
19174 #[inline]
19176 #[must_use]
19177 pub const fn target(&self) -> ContentAddress {
19178 self.target
19179 }
19180
19181 #[inline]
19183 #[must_use]
19184 #[allow(dead_code)]
19185 pub(crate) const fn new(step_index: u32, op: PrimitiveOp, target: ContentAddress) -> Self {
19186 Self {
19187 step_index,
19188 op,
19189 target,
19190 _sealed: (),
19191 }
19192 }
19193}
19194
19195#[derive(Debug, Clone, Copy)]
19204pub struct Trace<const TR_MAX: usize = 256> {
19205 events: [Option<TraceEvent>; TR_MAX],
19206 len: u16,
19207 witt_level_bits: u16,
19211 content_fingerprint: ContentFingerprint,
19218 _sealed: (),
19219}
19220
19221impl<const TR_MAX: usize> Trace<TR_MAX> {
19222 #[inline]
19224 #[must_use]
19225 pub const fn empty() -> Self {
19226 Self {
19227 events: [None; TR_MAX],
19228 len: 0,
19229 witt_level_bits: 0,
19230 content_fingerprint: ContentFingerprint::zero(),
19231 _sealed: (),
19232 }
19233 }
19234
19235 #[inline]
19241 #[must_use]
19242 #[allow(dead_code)]
19243 pub(crate) const fn from_replay_events_const(
19244 events: [Option<TraceEvent>; TR_MAX],
19245 len: u16,
19246 witt_level_bits: u16,
19247 content_fingerprint: ContentFingerprint,
19248 ) -> Self {
19249 Self {
19250 events,
19251 len,
19252 witt_level_bits,
19253 content_fingerprint,
19254 _sealed: (),
19255 }
19256 }
19257
19258 #[inline]
19260 #[must_use]
19261 pub const fn len(&self) -> u16 {
19262 self.len
19263 }
19264
19265 #[inline]
19267 #[must_use]
19268 pub const fn is_empty(&self) -> bool {
19269 self.len == 0
19270 }
19271
19272 #[inline]
19274 #[must_use]
19275 pub fn event(&self, index: usize) -> Option<&TraceEvent> {
19276 self.events.get(index).and_then(|e| e.as_ref())
19277 }
19278
19279 #[inline]
19282 #[must_use]
19283 pub const fn witt_level_bits(&self) -> u16 {
19284 self.witt_level_bits
19285 }
19286
19287 #[inline]
19292 #[must_use]
19293 pub const fn content_fingerprint(&self) -> ContentFingerprint {
19294 self.content_fingerprint
19295 }
19296
19297 pub fn try_from_events(
19309 events: &[TraceEvent],
19310 witt_level_bits: u16,
19311 content_fingerprint: ContentFingerprint,
19312 ) -> Result<Self, ReplayError> {
19313 if events.is_empty() {
19314 return Err(ReplayError::EmptyTrace);
19315 }
19316 if events.len() > TR_MAX {
19317 return Err(ReplayError::CapacityExceeded {
19318 declared: TR_MAX as u16,
19319 provided: events.len() as u32,
19320 });
19321 }
19322 let mut i = 0usize;
19323 while i < events.len() {
19324 let e = &events[i];
19325 if e.step_index() as usize != i {
19326 return Err(ReplayError::OutOfOrderEvent { index: i });
19327 }
19328 if e.target().is_zero() {
19329 return Err(ReplayError::ZeroTarget { index: i });
19330 }
19331 i += 1;
19332 }
19333 let mut arr = [None; TR_MAX];
19334 let mut j = 0usize;
19335 while j < events.len() {
19336 arr[j] = Some(events[j]);
19337 j += 1;
19338 }
19339 Ok(Self {
19340 events: arr,
19341 len: events.len() as u16,
19342 witt_level_bits,
19343 content_fingerprint,
19344 _sealed: (),
19345 })
19346 }
19347}
19348
19349impl<const TR_MAX: usize> Default for Trace<TR_MAX> {
19350 #[inline]
19351 fn default() -> Self {
19352 Self::empty()
19353 }
19354}
19355
19356impl Derivation {
19361 #[inline]
19400 #[must_use]
19401 pub fn replay<const TR_MAX: usize>(&self) -> Trace<TR_MAX> {
19402 let steps = self.step_count() as usize;
19403 let len = if steps > TR_MAX { TR_MAX } else { steps };
19404 let mut events = [None; TR_MAX];
19405 let fp = self.content_fingerprint.as_bytes();
19411 let seed =
19412 u64::from_be_bytes([fp[0], fp[1], fp[2], fp[3], fp[4], fp[5], fp[6], fp[7]]) as u128;
19413 let nonzero_seed = seed | 1u128;
19414 let mut i = 0usize;
19415 while i < len {
19416 let target_raw = nonzero_seed ^ ((i as u128) + 1u128);
19417 events[i] = Some(TraceEvent::new(
19418 i as u32,
19419 crate::PrimitiveOp::Add,
19420 ContentAddress::from_u128(target_raw),
19421 ));
19422 i += 1;
19423 }
19424 Trace::from_replay_events_const(
19430 events,
19431 len as u16,
19432 self.witt_level_bits,
19433 self.content_fingerprint,
19434 )
19435 }
19436}
19437
19438#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19440#[non_exhaustive]
19441pub enum ReplayError {
19442 EmptyTrace,
19444 OutOfOrderEvent {
19446 index: usize,
19448 },
19449 ZeroTarget {
19451 index: usize,
19453 },
19454 NonContiguousSteps {
19460 declared: u16,
19462 last_step: u32,
19466 },
19467 CapacityExceeded {
19474 declared: u16,
19476 provided: u32,
19478 },
19479}
19480
19481impl core::fmt::Display for ReplayError {
19482 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
19483 match self {
19484 Self::EmptyTrace => f.write_str("trace was empty; nothing to replay"),
19485 Self::OutOfOrderEvent { index } => write!(
19486 f,
19487 "event at index {index} has out-of-order step index",
19488 ),
19489 Self::ZeroTarget { index } => write!(
19490 f,
19491 "event at index {index} has a zero ContentAddress target",
19492 ),
19493 Self::NonContiguousSteps { declared, last_step } => write!(
19494 f,
19495 "trace declares {declared} events but step indices skip values \
19496 (last step {last_step})",
19497 ),
19498 Self::CapacityExceeded { declared, provided } => write!(
19499 f,
19500 "trace capacity exceeded: tried to pack {provided} events into a buffer of {declared}",
19501 ),
19502 }
19503 }
19504}
19505
19506impl core::error::Error for ReplayError {}
19507
19508pub mod replay {
19515 use super::{Certified, GroundingCertificate, ReplayError, Trace};
19516
19517 pub fn certify_from_trace<const TR_MAX: usize>(
19545 trace: &Trace<TR_MAX>,
19546 ) -> Result<Certified<GroundingCertificate>, ReplayError> {
19547 let len = trace.len() as usize;
19548 if len == 0 {
19549 return Err(ReplayError::EmptyTrace);
19550 }
19551 let mut last_step: i64 = -1;
19554 let mut max_step_index: u32 = 0;
19555 let mut i = 0usize;
19556 while i < len {
19557 let event = match trace.event(i) {
19558 Some(e) => e,
19559 None => return Err(ReplayError::OutOfOrderEvent { index: i }),
19560 };
19561 let step_index = event.step_index();
19562 if (step_index as i64) <= last_step {
19563 return Err(ReplayError::OutOfOrderEvent { index: i });
19564 }
19565 if event.target().is_zero() {
19566 return Err(ReplayError::ZeroTarget { index: i });
19567 }
19568 if step_index > max_step_index {
19569 max_step_index = step_index;
19570 }
19571 last_step = step_index as i64;
19572 i += 1;
19573 }
19574 if (max_step_index as u16).saturating_add(1) != trace.len() {
19575 return Err(ReplayError::NonContiguousSteps {
19576 declared: trace.len(),
19577 last_step: max_step_index,
19578 });
19579 }
19580 Ok(Certified::new(
19588 GroundingCertificate::with_level_and_fingerprint_const(
19589 trace.witt_level_bits(),
19590 trace.content_fingerprint(),
19591 ),
19592 ))
19593 }
19594}
19595
19596#[derive(Debug, Clone, Copy, Default)]
19601pub struct InteractionDeclarationBuilder {
19602 peer_protocol: Option<u128>,
19603 convergence_predicate: Option<u128>,
19604 commutator_state_class: Option<u128>,
19605}
19606
19607impl InteractionDeclarationBuilder {
19608 #[inline]
19610 #[must_use]
19611 pub const fn new() -> Self {
19612 Self {
19613 peer_protocol: None,
19614 convergence_predicate: None,
19615 commutator_state_class: None,
19616 }
19617 }
19618
19619 #[inline]
19621 #[must_use]
19622 pub const fn peer_protocol(mut self, address: u128) -> Self {
19623 self.peer_protocol = Some(address);
19624 self
19625 }
19626
19627 #[inline]
19629 #[must_use]
19630 pub const fn convergence_predicate(mut self, address: u128) -> Self {
19631 self.convergence_predicate = Some(address);
19632 self
19633 }
19634
19635 #[inline]
19637 #[must_use]
19638 pub const fn commutator_state_class(mut self, address: u128) -> Self {
19639 self.commutator_state_class = Some(address);
19640 self
19641 }
19642
19643 pub fn validate(&self) -> Result<Validated<InteractionShape>, ShapeViolation> {
19647 self.validate_common().map(|_| {
19648 Validated::new(InteractionShape {
19649 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19650 })
19651 })
19652 }
19653
19654 pub const fn validate_const(
19658 &self,
19659 ) -> Result<Validated<InteractionShape, CompileTime>, ShapeViolation> {
19660 if self.peer_protocol.is_none() {
19661 return Err(ShapeViolation {
19662 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19663 constraint_iri: "https://uor.foundation/conformance/InteractionShape",
19664 property_iri: "https://uor.foundation/interaction/peerProtocol",
19665 expected_range: "http://www.w3.org/2002/07/owl#Thing",
19666 min_count: 1,
19667 max_count: 1,
19668 kind: ViolationKind::Missing,
19669 });
19670 }
19671 if self.convergence_predicate.is_none() {
19672 return Err(ShapeViolation {
19673 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19674 constraint_iri: "https://uor.foundation/conformance/InteractionShape",
19675 property_iri: "https://uor.foundation/interaction/convergencePredicate",
19676 expected_range: "http://www.w3.org/2002/07/owl#Thing",
19677 min_count: 1,
19678 max_count: 1,
19679 kind: ViolationKind::Missing,
19680 });
19681 }
19682 if self.commutator_state_class.is_none() {
19683 return Err(ShapeViolation {
19684 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19685 constraint_iri: "https://uor.foundation/conformance/InteractionShape",
19686 property_iri: "https://uor.foundation/interaction/commutatorStateClass",
19687 expected_range: "http://www.w3.org/2002/07/owl#Thing",
19688 min_count: 1,
19689 max_count: 1,
19690 kind: ViolationKind::Missing,
19691 });
19692 }
19693 Ok(Validated::new(InteractionShape {
19694 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19695 }))
19696 }
19697
19698 fn validate_common(&self) -> Result<(), ShapeViolation> {
19699 self.validate_const().map(|_| ())
19700 }
19701}
19702
19703#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19705pub struct InteractionShape {
19706 pub shape_iri: &'static str,
19708}
19709
19710#[cfg(feature = "observability")]
19716pub fn subscribe_trace_events<F>(handler: F) -> ObservabilitySubscription<F>
19717where
19718 F: FnMut(&TraceEvent),
19719{
19720 ObservabilitySubscription {
19721 handler,
19722 _sealed: (),
19723 }
19724}
19725
19726#[cfg(feature = "observability")]
19727#[cfg(feature = "observability")]
19729pub struct ObservabilitySubscription<F: FnMut(&TraceEvent)> {
19730 handler: F,
19731 _sealed: (),
19732}
19733
19734#[cfg(feature = "observability")]
19735impl<F: FnMut(&TraceEvent)> ObservabilitySubscription<F> {
19736 pub fn emit(&mut self, event: &TraceEvent) {
19738 (self.handler)(event);
19739 }
19740}
19741
19742#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19748#[non_exhaustive]
19749pub enum ConstraintKind {
19750 Residue,
19752 Carry,
19754 Depth,
19756 Hamming,
19758 Site,
19760 Affine,
19762}
19763
19764#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19766pub struct CarryProfile {
19767 chain_length: u32,
19768 max_depth: u32,
19769 _sealed: (),
19770}
19771
19772impl CarryProfile {
19773 #[inline]
19775 #[must_use]
19776 pub const fn chain_length(&self) -> u32 {
19777 self.chain_length
19778 }
19779
19780 #[inline]
19782 #[must_use]
19783 pub const fn max_depth(&self) -> u32 {
19784 self.max_depth
19785 }
19786
19787 #[inline]
19789 #[must_use]
19790 #[allow(dead_code)]
19791 pub(crate) const fn new(chain_length: u32, max_depth: u32) -> Self {
19792 Self {
19793 chain_length,
19794 max_depth,
19795 _sealed: (),
19796 }
19797 }
19798}
19799
19800#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19803pub struct CarryEvent {
19804 left_bits: u16,
19805 right_bits: u16,
19806 _sealed: (),
19807}
19808
19809impl CarryEvent {
19810 #[inline]
19812 #[must_use]
19813 pub const fn left_bits(&self) -> u16 {
19814 self.left_bits
19815 }
19816
19817 #[inline]
19819 #[must_use]
19820 pub const fn right_bits(&self) -> u16 {
19821 self.right_bits
19822 }
19823
19824 #[inline]
19826 #[must_use]
19827 #[allow(dead_code)]
19828 pub(crate) const fn new(left_bits: u16, right_bits: u16) -> Self {
19829 Self {
19830 left_bits,
19831 right_bits,
19832 _sealed: (),
19833 }
19834 }
19835}
19836
19837#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19839pub struct ConvergenceLevel<L> {
19840 valuation: u32,
19841 _level: PhantomData<L>,
19842 _sealed: (),
19843}
19844
19845impl<L> ConvergenceLevel<L> {
19846 #[inline]
19848 #[must_use]
19849 pub const fn valuation(&self) -> u32 {
19850 self.valuation
19851 }
19852
19853 #[inline]
19855 #[must_use]
19856 #[allow(dead_code)]
19857 pub(crate) const fn new(valuation: u32) -> Self {
19858 Self {
19859 valuation,
19860 _level: PhantomData,
19861 _sealed: (),
19862 }
19863 }
19864}
19865
19866#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19869#[non_exhaustive]
19870pub enum DivisionAlgebraWitness {
19871 Real,
19873 Complex,
19875 Quaternion,
19877 Octonion,
19879}
19880
19881#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19883pub struct MonoidalProduct<L, R> {
19884 _left: PhantomData<L>,
19885 _right: PhantomData<R>,
19886 _sealed: (),
19887}
19888
19889impl<L, R> MonoidalProduct<L, R> {
19890 #[inline]
19892 #[must_use]
19893 #[allow(dead_code)]
19894 pub(crate) const fn new() -> Self {
19895 Self {
19896 _left: PhantomData,
19897 _right: PhantomData,
19898 _sealed: (),
19899 }
19900 }
19901}
19902
19903#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19905pub struct MonoidalUnit<L> {
19906 _level: PhantomData<L>,
19907 _sealed: (),
19908}
19909
19910impl<L> MonoidalUnit<L> {
19911 #[inline]
19913 #[must_use]
19914 #[allow(dead_code)]
19915 pub(crate) const fn new() -> Self {
19916 Self {
19917 _level: PhantomData,
19918 _sealed: (),
19919 }
19920 }
19921}
19922
19923#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19927pub struct OperadComposition {
19928 outer_type_iri: &'static str,
19929 inner_type_iri: &'static str,
19930 composed_site_count: u32,
19931 _sealed: (),
19932}
19933
19934impl OperadComposition {
19935 #[inline]
19937 #[must_use]
19938 pub const fn outer_type_iri(&self) -> &'static str {
19939 self.outer_type_iri
19940 }
19941
19942 #[inline]
19944 #[must_use]
19945 pub const fn inner_type_iri(&self) -> &'static str {
19946 self.inner_type_iri
19947 }
19948
19949 #[inline]
19951 #[must_use]
19952 pub const fn composed_site_count(&self) -> u32 {
19953 self.composed_site_count
19954 }
19955
19956 #[inline]
19958 #[must_use]
19959 #[allow(dead_code)]
19960 pub(crate) const fn new(
19961 outer_type_iri: &'static str,
19962 inner_type_iri: &'static str,
19963 composed_site_count: u32,
19964 ) -> Self {
19965 Self {
19966 outer_type_iri,
19967 inner_type_iri,
19968 composed_site_count,
19969 _sealed: (),
19970 }
19971 }
19972}
19973
19974pub const RECURSION_TRACE_MAX_DEPTH: usize = 16;
19980
19981#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19984pub struct RecursionTrace {
19985 depth: u32,
19986 measure: [u32; RECURSION_TRACE_MAX_DEPTH],
19987 _sealed: (),
19988}
19989
19990impl RecursionTrace {
19991 #[inline]
19993 #[must_use]
19994 pub const fn depth(&self) -> u32 {
19995 self.depth
19996 }
19997
19998 #[inline]
20000 #[must_use]
20001 pub const fn measure(&self) -> &[u32; RECURSION_TRACE_MAX_DEPTH] {
20002 &self.measure
20003 }
20004
20005 #[inline]
20007 #[must_use]
20008 #[allow(dead_code)]
20009 pub(crate) const fn new(depth: u32, measure: [u32; RECURSION_TRACE_MAX_DEPTH]) -> Self {
20010 Self {
20011 depth,
20012 measure,
20013 _sealed: (),
20014 }
20015 }
20016}
20017
20018#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20020pub struct AddressRegion {
20021 base: u128,
20022 extent: u64,
20023 _sealed: (),
20024}
20025
20026impl AddressRegion {
20027 #[inline]
20029 #[must_use]
20030 pub const fn base(&self) -> u128 {
20031 self.base
20032 }
20033
20034 #[inline]
20036 #[must_use]
20037 pub const fn extent(&self) -> u64 {
20038 self.extent
20039 }
20040
20041 #[inline]
20043 #[must_use]
20044 #[allow(dead_code)]
20045 pub(crate) const fn new(base: u128, extent: u64) -> Self {
20046 Self {
20047 base,
20048 extent,
20049 _sealed: (),
20050 }
20051 }
20052}
20053
20054#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20056pub struct LinearBudget {
20057 sites_remaining: u64,
20058 _sealed: (),
20059}
20060
20061impl LinearBudget {
20062 #[inline]
20064 #[must_use]
20065 pub const fn sites_remaining(&self) -> u64 {
20066 self.sites_remaining
20067 }
20068
20069 #[inline]
20071 #[must_use]
20072 #[allow(dead_code)]
20073 pub(crate) const fn new(sites_remaining: u64) -> Self {
20074 Self {
20075 sites_remaining,
20076 _sealed: (),
20077 }
20078 }
20079}
20080
20081#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20083pub struct LeaseAllocation {
20084 site_count: u32,
20085 scope_hash: u128,
20086 _sealed: (),
20087}
20088
20089impl LeaseAllocation {
20090 #[inline]
20092 #[must_use]
20093 pub const fn site_count(&self) -> u32 {
20094 self.site_count
20095 }
20096
20097 #[inline]
20099 #[must_use]
20100 pub const fn scope_hash(&self) -> u128 {
20101 self.scope_hash
20102 }
20103
20104 #[inline]
20106 #[must_use]
20107 #[allow(dead_code)]
20108 pub(crate) const fn new(site_count: u32, scope_hash: u128) -> Self {
20109 Self {
20110 site_count,
20111 scope_hash,
20112 _sealed: (),
20113 }
20114 }
20115}
20116
20117#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
20119pub struct TotalMarker;
20120
20121#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
20123pub struct InvertibleMarker;
20124
20125#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
20127pub struct PreservesStructureMarker;
20128
20129mod marker_tuple_sealed {
20130 pub trait Sealed {}
20132}
20133
20134pub trait MarkerTuple: marker_tuple_sealed::Sealed {}
20139
20140impl marker_tuple_sealed::Sealed for () {}
20141impl MarkerTuple for () {}
20142impl marker_tuple_sealed::Sealed for (TotalMarker,) {}
20143impl MarkerTuple for (TotalMarker,) {}
20144impl marker_tuple_sealed::Sealed for (TotalMarker, InvertibleMarker) {}
20145impl MarkerTuple for (TotalMarker, InvertibleMarker) {}
20146impl marker_tuple_sealed::Sealed for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {}
20147impl MarkerTuple for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {}
20148impl marker_tuple_sealed::Sealed for (InvertibleMarker,) {}
20149impl MarkerTuple for (InvertibleMarker,) {}
20150impl marker_tuple_sealed::Sealed for (InvertibleMarker, PreservesStructureMarker) {}
20151impl MarkerTuple for (InvertibleMarker, PreservesStructureMarker) {}
20152
20153pub trait MarkerIntersection<Other: MarkerTuple>: MarkerTuple {
20160 type Output: MarkerTuple;
20162}
20163
20164impl MarkerIntersection<()> for () {
20165 type Output = ();
20166}
20167impl MarkerIntersection<(TotalMarker,)> for () {
20168 type Output = ();
20169}
20170impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for () {
20171 type Output = ();
20172}
20173impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)> for () {
20174 type Output = ();
20175}
20176impl MarkerIntersection<(InvertibleMarker,)> for () {
20177 type Output = ();
20178}
20179impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for () {
20180 type Output = ();
20181}
20182impl MarkerIntersection<()> for (TotalMarker,) {
20183 type Output = ();
20184}
20185impl MarkerIntersection<(TotalMarker,)> for (TotalMarker,) {
20186 type Output = (TotalMarker,);
20187}
20188impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (TotalMarker,) {
20189 type Output = (TotalMarker,);
20190}
20191impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20192 for (TotalMarker,)
20193{
20194 type Output = (TotalMarker,);
20195}
20196impl MarkerIntersection<(InvertibleMarker,)> for (TotalMarker,) {
20197 type Output = ();
20198}
20199impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for (TotalMarker,) {
20200 type Output = ();
20201}
20202impl MarkerIntersection<()> for (TotalMarker, InvertibleMarker) {
20203 type Output = ();
20204}
20205impl MarkerIntersection<(TotalMarker,)> for (TotalMarker, InvertibleMarker) {
20206 type Output = (TotalMarker,);
20207}
20208impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (TotalMarker, InvertibleMarker) {
20209 type Output = (TotalMarker, InvertibleMarker);
20210}
20211impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20212 for (TotalMarker, InvertibleMarker)
20213{
20214 type Output = (TotalMarker, InvertibleMarker);
20215}
20216impl MarkerIntersection<(InvertibleMarker,)> for (TotalMarker, InvertibleMarker) {
20217 type Output = (InvertibleMarker,);
20218}
20219impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
20220 for (TotalMarker, InvertibleMarker)
20221{
20222 type Output = (InvertibleMarker,);
20223}
20224impl MarkerIntersection<()> for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {
20225 type Output = ();
20226}
20227impl MarkerIntersection<(TotalMarker,)>
20228 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20229{
20230 type Output = (TotalMarker,);
20231}
20232impl MarkerIntersection<(TotalMarker, InvertibleMarker)>
20233 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20234{
20235 type Output = (TotalMarker, InvertibleMarker);
20236}
20237impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20238 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20239{
20240 type Output = (TotalMarker, InvertibleMarker, PreservesStructureMarker);
20241}
20242impl MarkerIntersection<(InvertibleMarker,)>
20243 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20244{
20245 type Output = (InvertibleMarker,);
20246}
20247impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
20248 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20249{
20250 type Output = (InvertibleMarker, PreservesStructureMarker);
20251}
20252impl MarkerIntersection<()> for (InvertibleMarker,) {
20253 type Output = ();
20254}
20255impl MarkerIntersection<(TotalMarker,)> for (InvertibleMarker,) {
20256 type Output = ();
20257}
20258impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (InvertibleMarker,) {
20259 type Output = (InvertibleMarker,);
20260}
20261impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20262 for (InvertibleMarker,)
20263{
20264 type Output = (InvertibleMarker,);
20265}
20266impl MarkerIntersection<(InvertibleMarker,)> for (InvertibleMarker,) {
20267 type Output = (InvertibleMarker,);
20268}
20269impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for (InvertibleMarker,) {
20270 type Output = (InvertibleMarker,);
20271}
20272impl MarkerIntersection<()> for (InvertibleMarker, PreservesStructureMarker) {
20273 type Output = ();
20274}
20275impl MarkerIntersection<(TotalMarker,)> for (InvertibleMarker, PreservesStructureMarker) {
20276 type Output = ();
20277}
20278impl MarkerIntersection<(TotalMarker, InvertibleMarker)>
20279 for (InvertibleMarker, PreservesStructureMarker)
20280{
20281 type Output = (InvertibleMarker,);
20282}
20283impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20284 for (InvertibleMarker, PreservesStructureMarker)
20285{
20286 type Output = (InvertibleMarker, PreservesStructureMarker);
20287}
20288impl MarkerIntersection<(InvertibleMarker,)> for (InvertibleMarker, PreservesStructureMarker) {
20289 type Output = (InvertibleMarker,);
20290}
20291impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
20292 for (InvertibleMarker, PreservesStructureMarker)
20293{
20294 type Output = (InvertibleMarker, PreservesStructureMarker);
20295}
20296
20297pub trait MarkersImpliedBy<Map: GroundingMapKind>: MarkerTuple {}
20303
20304#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20307pub struct MarkerBits(u8);
20308
20309impl MarkerBits {
20310 pub const TOTAL: Self = Self(1);
20312 pub const INVERTIBLE: Self = Self(2);
20314 pub const PRESERVES_STRUCTURE: Self = Self(4);
20316 pub const NONE: Self = Self(0);
20318
20319 #[inline]
20321 #[must_use]
20322 pub const fn from_u8(bits: u8) -> Self {
20323 Self(bits)
20324 }
20325
20326 #[inline]
20328 #[must_use]
20329 pub const fn as_u8(&self) -> u8 {
20330 self.0
20331 }
20332
20333 #[inline]
20335 #[must_use]
20336 pub const fn union(self, other: Self) -> Self {
20337 Self(self.0 | other.0)
20338 }
20339
20340 #[inline]
20342 #[must_use]
20343 pub const fn intersection(self, other: Self) -> Self {
20344 Self(self.0 & other.0)
20345 }
20346
20347 #[inline]
20349 #[must_use]
20350 pub const fn contains(&self, other: Self) -> bool {
20351 (self.0 & other.0) == other.0
20352 }
20353}
20354
20355#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20361#[non_exhaustive]
20362pub enum GroundingPrimitiveOp {
20363 ReadBytes,
20365 InterpretLeInteger,
20367 InterpretBeInteger,
20369 Digest,
20375 DecodeUtf8,
20381 DecodeJson,
20387 SelectField,
20389 SelectIndex,
20391 ConstValue,
20397 Then,
20399 MapErr,
20401 AndThen,
20403}
20404
20405pub const MAX_OP_CHAIN_DEPTH: usize = 8;
20412
20413#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20423pub struct GroundingPrimitive<Out, Markers: MarkerTuple = ()> {
20424 op: GroundingPrimitiveOp,
20425 markers: MarkerBits,
20426 chain: [GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH],
20427 chain_len: u8,
20428 _out: PhantomData<Out>,
20429 _markers: PhantomData<Markers>,
20430 _sealed: (),
20431}
20432
20433impl<Out, Markers: MarkerTuple> GroundingPrimitive<Out, Markers> {
20434 #[inline]
20436 #[must_use]
20437 pub const fn op(&self) -> GroundingPrimitiveOp {
20438 self.op
20439 }
20440
20441 #[inline]
20443 #[must_use]
20444 pub const fn markers(&self) -> MarkerBits {
20445 self.markers
20446 }
20447
20448 #[inline]
20451 #[must_use]
20452 pub fn chain(&self) -> &[GroundingPrimitiveOp] {
20453 &self.chain[..self.chain_len as usize]
20454 }
20455
20456 #[inline]
20460 #[must_use]
20461 #[allow(dead_code)]
20462 pub(crate) const fn from_parts(op: GroundingPrimitiveOp, markers: MarkerBits) -> Self {
20463 Self {
20464 op,
20465 markers,
20466 chain: [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH],
20467 chain_len: 0,
20468 _out: PhantomData,
20469 _markers: PhantomData,
20470 _sealed: (),
20471 }
20472 }
20473
20474 #[inline]
20477 #[must_use]
20478 #[allow(dead_code)]
20479 pub(crate) const fn from_parts_with_chain(
20480 op: GroundingPrimitiveOp,
20481 markers: MarkerBits,
20482 chain: [GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH],
20483 chain_len: u8,
20484 ) -> Self {
20485 Self {
20486 op,
20487 markers,
20488 chain,
20489 chain_len,
20490 _out: PhantomData,
20491 _markers: PhantomData,
20492 _sealed: (),
20493 }
20494 }
20495}
20496
20497pub mod combinators {
20503 use super::{
20504 GroundingPrimitive, GroundingPrimitiveOp, InvertibleMarker, MarkerBits, MarkerIntersection,
20505 MarkerTuple, PreservesStructureMarker, TotalMarker, MAX_OP_CHAIN_DEPTH,
20506 };
20507
20508 fn compose_chain<A, B, MA: MarkerTuple, MB: MarkerTuple>(
20512 first: &GroundingPrimitive<A, MA>,
20513 second: &GroundingPrimitive<B, MB>,
20514 ) -> ([GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH], u8) {
20515 let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
20516 let mut len: usize = 0;
20517 for &op in first.chain() {
20518 if len >= MAX_OP_CHAIN_DEPTH {
20519 return (chain, len as u8);
20520 }
20521 chain[len] = op;
20522 len += 1;
20523 }
20524 if len < MAX_OP_CHAIN_DEPTH {
20525 chain[len] = first.op();
20526 len += 1;
20527 }
20528 for &op in second.chain() {
20529 if len >= MAX_OP_CHAIN_DEPTH {
20530 return (chain, len as u8);
20531 }
20532 chain[len] = op;
20533 len += 1;
20534 }
20535 if len < MAX_OP_CHAIN_DEPTH {
20536 chain[len] = second.op();
20537 len += 1;
20538 }
20539 (chain, len as u8)
20540 }
20541
20542 fn map_err_chain<A, M: MarkerTuple>(
20544 first: &GroundingPrimitive<A, M>,
20545 ) -> ([GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH], u8) {
20546 let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
20547 let mut len: usize = 0;
20548 for &op in first.chain() {
20549 if len >= MAX_OP_CHAIN_DEPTH {
20550 return (chain, len as u8);
20551 }
20552 chain[len] = op;
20553 len += 1;
20554 }
20555 if len < MAX_OP_CHAIN_DEPTH {
20556 chain[len] = first.op();
20557 len += 1;
20558 }
20559 (chain, len as u8)
20560 }
20561
20562 #[inline]
20564 #[must_use]
20565 pub const fn read_bytes<Out>() -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker)> {
20566 GroundingPrimitive::from_parts(
20567 GroundingPrimitiveOp::ReadBytes,
20568 MarkerBits::TOTAL.union(MarkerBits::INVERTIBLE),
20569 )
20570 }
20571
20572 #[inline]
20574 #[must_use]
20575 pub const fn interpret_le_integer<Out>(
20576 ) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
20577 GroundingPrimitive::from_parts(
20578 GroundingPrimitiveOp::InterpretLeInteger,
20579 MarkerBits::TOTAL
20580 .union(MarkerBits::INVERTIBLE)
20581 .union(MarkerBits::PRESERVES_STRUCTURE),
20582 )
20583 }
20584
20585 #[inline]
20587 #[must_use]
20588 pub const fn interpret_be_integer<Out>(
20589 ) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
20590 GroundingPrimitive::from_parts(
20591 GroundingPrimitiveOp::InterpretBeInteger,
20592 MarkerBits::TOTAL
20593 .union(MarkerBits::INVERTIBLE)
20594 .union(MarkerBits::PRESERVES_STRUCTURE),
20595 )
20596 }
20597
20598 #[inline]
20600 #[must_use]
20601 pub const fn digest<Out>() -> GroundingPrimitive<Out, (TotalMarker,)> {
20602 GroundingPrimitive::from_parts(GroundingPrimitiveOp::Digest, MarkerBits::TOTAL)
20603 }
20604
20605 #[inline]
20607 #[must_use]
20608 pub const fn decode_utf8<Out>(
20609 ) -> GroundingPrimitive<Out, (InvertibleMarker, PreservesStructureMarker)> {
20610 GroundingPrimitive::from_parts(
20611 GroundingPrimitiveOp::DecodeUtf8,
20612 MarkerBits::INVERTIBLE.union(MarkerBits::PRESERVES_STRUCTURE),
20613 )
20614 }
20615
20616 #[inline]
20618 #[must_use]
20619 pub const fn decode_json<Out>(
20620 ) -> GroundingPrimitive<Out, (InvertibleMarker, PreservesStructureMarker)> {
20621 GroundingPrimitive::from_parts(
20622 GroundingPrimitiveOp::DecodeJson,
20623 MarkerBits::INVERTIBLE.union(MarkerBits::PRESERVES_STRUCTURE),
20624 )
20625 }
20626
20627 #[inline]
20629 #[must_use]
20630 pub const fn select_field<Out>() -> GroundingPrimitive<Out, (InvertibleMarker,)> {
20631 GroundingPrimitive::from_parts(GroundingPrimitiveOp::SelectField, MarkerBits::INVERTIBLE)
20632 }
20633
20634 #[inline]
20636 #[must_use]
20637 pub const fn select_index<Out>() -> GroundingPrimitive<Out, (InvertibleMarker,)> {
20638 GroundingPrimitive::from_parts(GroundingPrimitiveOp::SelectIndex, MarkerBits::INVERTIBLE)
20639 }
20640
20641 #[inline]
20643 #[must_use]
20644 pub const fn const_value<Out>(
20645 ) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
20646 GroundingPrimitive::from_parts(
20647 GroundingPrimitiveOp::ConstValue,
20648 MarkerBits::TOTAL
20649 .union(MarkerBits::INVERTIBLE)
20650 .union(MarkerBits::PRESERVES_STRUCTURE),
20651 )
20652 }
20653
20654 #[inline]
20659 #[must_use]
20660 pub fn then<A, B, MA, MB>(
20661 first: GroundingPrimitive<A, MA>,
20662 second: GroundingPrimitive<B, MB>,
20663 ) -> GroundingPrimitive<B, <MA as MarkerIntersection<MB>>::Output>
20664 where
20665 MA: MarkerTuple + MarkerIntersection<MB>,
20666 MB: MarkerTuple,
20667 {
20668 let (chain, chain_len) = compose_chain(&first, &second);
20669 GroundingPrimitive::from_parts_with_chain(
20670 GroundingPrimitiveOp::Then,
20671 first.markers().intersection(second.markers()),
20672 chain,
20673 chain_len,
20674 )
20675 }
20676
20677 #[inline]
20681 #[must_use]
20682 pub fn map_err<A, M: MarkerTuple>(first: GroundingPrimitive<A, M>) -> GroundingPrimitive<A, M> {
20683 let (chain, chain_len) = map_err_chain(&first);
20684 GroundingPrimitive::from_parts_with_chain(
20685 GroundingPrimitiveOp::MapErr,
20686 first.markers(),
20687 chain,
20688 chain_len,
20689 )
20690 }
20691
20692 #[inline]
20695 #[must_use]
20696 pub fn and_then<A, B, MA, MB>(
20697 first: GroundingPrimitive<A, MA>,
20698 second: GroundingPrimitive<B, MB>,
20699 ) -> GroundingPrimitive<B, <MA as MarkerIntersection<MB>>::Output>
20700 where
20701 MA: MarkerTuple + MarkerIntersection<MB>,
20702 MB: MarkerTuple,
20703 {
20704 let (chain, chain_len) = compose_chain(&first, &second);
20705 GroundingPrimitive::from_parts_with_chain(
20706 GroundingPrimitiveOp::AndThen,
20707 first.markers().intersection(second.markers()),
20708 chain,
20709 chain_len,
20710 )
20711 }
20712}
20713
20714#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20720pub struct GroundingProgram<Out, Map: GroundingMapKind> {
20721 primitive: GroundingPrimitive<Out>,
20722 _map: PhantomData<Map>,
20723 _sealed: (),
20724}
20725
20726impl<Out, Map: GroundingMapKind> GroundingProgram<Out, Map> {
20727 #[inline]
20749 #[must_use]
20750 pub fn from_primitive<Markers>(primitive: GroundingPrimitive<Out, Markers>) -> Self
20751 where
20752 Markers: MarkerTuple + MarkersImpliedBy<Map>,
20753 {
20754 let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
20757 let src = primitive.chain();
20758 let mut i = 0;
20759 while i < src.len() && i < MAX_OP_CHAIN_DEPTH {
20760 chain[i] = src[i];
20761 i += 1;
20762 }
20763 let erased = GroundingPrimitive::<Out, ()>::from_parts_with_chain(
20764 primitive.op(),
20765 primitive.markers(),
20766 chain,
20767 i as u8,
20768 );
20769 Self {
20770 primitive: erased,
20771 _map: PhantomData,
20772 _sealed: (),
20773 }
20774 }
20775
20776 #[inline]
20778 #[must_use]
20779 pub const fn primitive(&self) -> &GroundingPrimitive<Out> {
20780 &self.primitive
20781 }
20782}
20783
20784impl<Map: GroundingMapKind> GroundingProgram<GroundedCoord, Map> {
20797 #[inline]
20801 #[must_use]
20802 pub fn run(&self, external: &[u8]) -> Option<GroundedCoord> {
20803 match self.primitive.op() {
20804 GroundingPrimitiveOp::Then | GroundingPrimitiveOp::AndThen => {
20805 let chain = self.primitive.chain();
20806 if chain.is_empty() {
20807 return None;
20808 }
20809 let mut last: Option<GroundedCoord> = None;
20810 for &op in chain {
20811 match interpret_leaf_op(op, external) {
20812 Some(c) => last = Some(c),
20813 None => return None,
20814 }
20815 }
20816 last
20817 }
20818 GroundingPrimitiveOp::MapErr => self
20819 .primitive
20820 .chain()
20821 .first()
20822 .and_then(|&op| interpret_leaf_op(op, external)),
20823 leaf => interpret_leaf_op(leaf, external),
20824 }
20825 }
20826}
20827
20828impl<const N: usize, Map: GroundingMapKind> GroundingProgram<GroundedTuple<N>, Map> {
20835 #[inline]
20837 #[must_use]
20838 pub fn run(&self, external: &[u8]) -> Option<GroundedTuple<N>> {
20839 if N == 0 || external.is_empty() || external.len() % N != 0 {
20840 return None;
20841 }
20842 let window = external.len() / N;
20843 let mut coords: [GroundedCoord; N] = [const { GroundedCoord::w8(0) }; N];
20844 let mut i = 0usize;
20845 while i < N {
20846 let start = i * window;
20847 let end = start + window;
20848 let sub = &external[start..end];
20849 let outcome = match self.primitive.op() {
20854 GroundingPrimitiveOp::Then | GroundingPrimitiveOp::AndThen => {
20855 let chain = self.primitive.chain();
20856 if chain.is_empty() {
20857 return None;
20858 }
20859 let mut last: Option<GroundedCoord> = None;
20860 for &op in chain {
20861 match interpret_leaf_op(op, sub) {
20862 Some(c) => last = Some(c),
20863 None => return None,
20864 }
20865 }
20866 last
20867 }
20868 GroundingPrimitiveOp::MapErr => self
20869 .primitive
20870 .chain()
20871 .first()
20872 .and_then(|&op| interpret_leaf_op(op, sub)),
20873 leaf => interpret_leaf_op(leaf, sub),
20874 };
20875 match outcome {
20876 Some(c) => {
20877 coords[i] = c;
20878 }
20879 None => {
20880 return None;
20881 }
20882 }
20883 i += 1;
20884 }
20885 Some(GroundedTuple::new(coords))
20886 }
20887}
20888
20889#[inline]
20893fn interpret_leaf_op(op: GroundingPrimitiveOp, external: &[u8]) -> Option<GroundedCoord> {
20894 match op {
20895 GroundingPrimitiveOp::ReadBytes | GroundingPrimitiveOp::InterpretLeInteger => {
20896 external.first().map(|&b| GroundedCoord::w8(b))
20897 }
20898 GroundingPrimitiveOp::InterpretBeInteger => external.last().map(|&b| GroundedCoord::w8(b)),
20899 GroundingPrimitiveOp::Digest => {
20900 external.first().map(|&b| GroundedCoord::w8(b))
20907 }
20908 GroundingPrimitiveOp::DecodeUtf8 => {
20909 match external.first() {
20915 Some(&b) if b < 0x80 => Some(GroundedCoord::w8(b)),
20916 _ => None,
20917 }
20918 }
20919 GroundingPrimitiveOp::DecodeJson => {
20920 match external.first() {
20922 Some(&b) if b == b'-' || b.is_ascii_digit() => Some(GroundedCoord::w8(b)),
20923 _ => None,
20924 }
20925 }
20926 GroundingPrimitiveOp::ConstValue => Some(GroundedCoord::w8(0)),
20927 GroundingPrimitiveOp::SelectField | GroundingPrimitiveOp::SelectIndex => {
20928 external.first().map(|&b| GroundedCoord::w8(b))
20931 }
20932 GroundingPrimitiveOp::Then
20933 | GroundingPrimitiveOp::AndThen
20934 | GroundingPrimitiveOp::MapErr => {
20935 None
20938 }
20939 }
20940}
20941
20942impl MarkersImpliedBy<DigestGroundingMap> for (TotalMarker,) {}
20946impl MarkersImpliedBy<BinaryGroundingMap> for (TotalMarker, InvertibleMarker) {}
20947impl MarkersImpliedBy<DigestGroundingMap> for (TotalMarker, InvertibleMarker) {}
20948impl MarkersImpliedBy<BinaryGroundingMap>
20949 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20950{
20951}
20952impl MarkersImpliedBy<DigestGroundingMap>
20953 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20954{
20955}
20956impl MarkersImpliedBy<IntegerGroundingMap>
20957 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20958{
20959}
20960impl MarkersImpliedBy<JsonGroundingMap>
20961 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20962{
20963}
20964impl MarkersImpliedBy<Utf8GroundingMap>
20965 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20966{
20967}
20968impl MarkersImpliedBy<JsonGroundingMap> for (InvertibleMarker, PreservesStructureMarker) {}
20969impl MarkersImpliedBy<Utf8GroundingMap> for (InvertibleMarker, PreservesStructureMarker) {}
20970
20971#[doc(hidden)]
20976pub mod __test_helpers {
20977 use super::{ContentAddress, ContentFingerprint, MulContext, Trace, TraceEvent, Validated};
20978
20979 #[must_use]
20985 pub fn trace_from_events<const TR_MAX: usize>(events: &[TraceEvent]) -> Trace<TR_MAX> {
20986 trace_with_fingerprint(events, 0, ContentFingerprint::zero())
20987 }
20988
20989 #[must_use]
20993 pub fn trace_with_fingerprint<const TR_MAX: usize>(
20994 events: &[TraceEvent],
20995 witt_level_bits: u16,
20996 content_fingerprint: ContentFingerprint,
20997 ) -> Trace<TR_MAX> {
20998 let mut arr = [None; TR_MAX];
20999 let n = events.len().min(TR_MAX);
21000 let mut i = 0;
21001 while i < n {
21002 arr[i] = Some(events[i]);
21003 i += 1;
21004 }
21005 Trace::from_replay_events_const(arr, n as u16, witt_level_bits, content_fingerprint)
21009 }
21010
21011 #[must_use]
21013 pub fn trace_event(step_index: u32, target: u128) -> TraceEvent {
21014 TraceEvent::new(
21015 step_index,
21016 crate::PrimitiveOp::Add,
21017 ContentAddress::from_u128(target),
21018 )
21019 }
21020
21021 #[must_use]
21023 pub fn mul_context(stack_budget_bytes: u64, const_eval: bool, limb_count: usize) -> MulContext {
21024 MulContext::new(stack_budget_bytes, const_eval, limb_count)
21025 }
21026
21027 #[must_use]
21031 pub fn validated_runtime<T>(inner: T) -> Validated<T> {
21032 Validated::new(inner)
21033 }
21034}
21035
21036type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
21045
21046#[inline]
21047const fn pc_entropy_tolerance(expected: DefaultDecimal) -> DefaultDecimal {
21048 let magnitude = if expected < 0.0 { -expected } else { expected };
21049 let scale = if magnitude > 1.0 { magnitude } else { 1.0 };
21050 1024.0 * <DefaultDecimal>::EPSILON * scale
21051}
21052
21053#[inline]
21058fn pc_entropy_input_is_valid(value: DefaultDecimal) -> bool {
21059 value.is_finite() && value >= 0.0
21060}
21061
21062#[inline]
21067fn pc_entropy_additivity_holds(actual: DefaultDecimal, expected: DefaultDecimal) -> bool {
21068 if !pc_entropy_input_is_valid(actual) || !pc_entropy_input_is_valid(expected) {
21069 return false;
21070 }
21071 let diff = actual - expected;
21072 let diff_abs = if diff < 0.0 { -diff } else { diff };
21073 diff_abs <= pc_entropy_tolerance(expected)
21074}
21075
21076#[derive(Debug, Clone, Copy, PartialEq)]
21081pub struct PartitionProductEvidence {
21082 pub left_site_budget: u16,
21084 pub right_site_budget: u16,
21086 pub left_total_site_count: u16,
21088 pub right_total_site_count: u16,
21090 pub left_euler: i32,
21092 pub right_euler: i32,
21094 pub left_entropy_nats_bits: u64,
21096 pub right_entropy_nats_bits: u64,
21098 pub source_witness_fingerprint: ContentFingerprint,
21100}
21101
21102#[derive(Debug, Clone, Copy, PartialEq)]
21105pub struct PartitionCoproductEvidence {
21106 pub left_site_budget: u16,
21107 pub right_site_budget: u16,
21108 pub left_total_site_count: u16,
21109 pub right_total_site_count: u16,
21110 pub left_euler: i32,
21111 pub right_euler: i32,
21112 pub left_entropy_nats_bits: u64,
21113 pub right_entropy_nats_bits: u64,
21114 pub left_betti: [u32; MAX_BETTI_DIMENSION],
21115 pub right_betti: [u32; MAX_BETTI_DIMENSION],
21116 pub source_witness_fingerprint: ContentFingerprint,
21117}
21118
21119#[derive(Debug, Clone, Copy, PartialEq)]
21125pub struct CartesianProductEvidence {
21126 pub left_site_budget: u16,
21127 pub right_site_budget: u16,
21128 pub left_total_site_count: u16,
21129 pub right_total_site_count: u16,
21130 pub left_euler: i32,
21131 pub right_euler: i32,
21132 pub left_betti: [u32; MAX_BETTI_DIMENSION],
21133 pub right_betti: [u32; MAX_BETTI_DIMENSION],
21134 pub left_entropy_nats_bits: u64,
21135 pub right_entropy_nats_bits: u64,
21136 pub combined_entropy_nats_bits: u64,
21137 pub source_witness_fingerprint: ContentFingerprint,
21138}
21139
21140#[derive(Debug, Clone, Copy, PartialEq)]
21146pub struct PartitionProductMintInputs {
21147 pub witt_bits: u16,
21148 pub left_fingerprint: ContentFingerprint,
21149 pub right_fingerprint: ContentFingerprint,
21150 pub left_site_budget: u16,
21151 pub right_site_budget: u16,
21152 pub left_total_site_count: u16,
21153 pub right_total_site_count: u16,
21154 pub left_euler: i32,
21155 pub right_euler: i32,
21156 pub left_entropy_nats_bits: u64,
21157 pub right_entropy_nats_bits: u64,
21158 pub combined_site_budget: u16,
21159 pub combined_site_count: u16,
21160 pub combined_euler: i32,
21161 pub combined_entropy_nats_bits: u64,
21162 pub combined_fingerprint: ContentFingerprint,
21163}
21164
21165#[derive(Debug, Clone, Copy)]
21177pub struct PartitionCoproductMintInputs {
21178 pub witt_bits: u16,
21179 pub left_fingerprint: ContentFingerprint,
21180 pub right_fingerprint: ContentFingerprint,
21181 pub left_site_budget: u16,
21182 pub right_site_budget: u16,
21183 pub left_total_site_count: u16,
21184 pub right_total_site_count: u16,
21185 pub left_euler: i32,
21186 pub right_euler: i32,
21187 pub left_entropy_nats_bits: u64,
21188 pub right_entropy_nats_bits: u64,
21189 pub left_betti: [u32; MAX_BETTI_DIMENSION],
21190 pub right_betti: [u32; MAX_BETTI_DIMENSION],
21191 pub combined_site_budget: u16,
21192 pub combined_site_count: u16,
21193 pub combined_euler: i32,
21194 pub combined_entropy_nats_bits: u64,
21195 pub combined_betti: [u32; MAX_BETTI_DIMENSION],
21196 pub combined_fingerprint: ContentFingerprint,
21197 pub combined_constraints: &'static [crate::pipeline::ConstraintRef],
21198 pub left_constraint_count: usize,
21199 pub tag_site: u16,
21200}
21201
21202#[derive(Debug, Clone, Copy, PartialEq)]
21205pub struct CartesianProductMintInputs {
21206 pub witt_bits: u16,
21207 pub left_fingerprint: ContentFingerprint,
21208 pub right_fingerprint: ContentFingerprint,
21209 pub left_site_budget: u16,
21210 pub right_site_budget: u16,
21211 pub left_total_site_count: u16,
21212 pub right_total_site_count: u16,
21213 pub left_euler: i32,
21214 pub right_euler: i32,
21215 pub left_betti: [u32; MAX_BETTI_DIMENSION],
21216 pub right_betti: [u32; MAX_BETTI_DIMENSION],
21217 pub left_entropy_nats_bits: u64,
21218 pub right_entropy_nats_bits: u64,
21219 pub combined_site_budget: u16,
21220 pub combined_site_count: u16,
21221 pub combined_euler: i32,
21222 pub combined_betti: [u32; MAX_BETTI_DIMENSION],
21223 pub combined_entropy_nats_bits: u64,
21224 pub combined_fingerprint: ContentFingerprint,
21225}
21226
21227#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21234pub struct PartitionProductWitness {
21235 witt_bits: u16,
21236 content_fingerprint: ContentFingerprint,
21237 left_fingerprint: ContentFingerprint,
21238 right_fingerprint: ContentFingerprint,
21239 combined_site_budget: u16,
21240 combined_site_count: u16,
21241}
21242
21243impl PartitionProductWitness {
21244 #[inline]
21246 #[must_use]
21247 pub const fn witt_bits(&self) -> u16 {
21248 self.witt_bits
21249 }
21250 #[inline]
21252 #[must_use]
21253 pub const fn content_fingerprint(&self) -> ContentFingerprint {
21254 self.content_fingerprint
21255 }
21256 #[inline]
21258 #[must_use]
21259 pub const fn left_fingerprint(&self) -> ContentFingerprint {
21260 self.left_fingerprint
21261 }
21262 #[inline]
21264 #[must_use]
21265 pub const fn right_fingerprint(&self) -> ContentFingerprint {
21266 self.right_fingerprint
21267 }
21268 #[inline]
21270 #[must_use]
21271 pub const fn combined_site_budget(&self) -> u16 {
21272 self.combined_site_budget
21273 }
21274 #[inline]
21276 #[must_use]
21277 pub const fn combined_site_count(&self) -> u16 {
21278 self.combined_site_count
21279 }
21280 #[inline]
21282 #[must_use]
21283 #[allow(clippy::too_many_arguments)]
21284 pub(crate) const fn with_level_fingerprints_and_sites(
21285 witt_bits: u16,
21286 content_fingerprint: ContentFingerprint,
21287 left_fingerprint: ContentFingerprint,
21288 right_fingerprint: ContentFingerprint,
21289 combined_site_budget: u16,
21290 combined_site_count: u16,
21291 ) -> Self {
21292 Self {
21293 witt_bits,
21294 content_fingerprint,
21295 left_fingerprint,
21296 right_fingerprint,
21297 combined_site_budget,
21298 combined_site_count,
21299 }
21300 }
21301}
21302
21303#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21309pub struct PartitionCoproductWitness {
21310 witt_bits: u16,
21311 content_fingerprint: ContentFingerprint,
21312 left_fingerprint: ContentFingerprint,
21313 right_fingerprint: ContentFingerprint,
21314 combined_site_budget: u16,
21315 combined_site_count: u16,
21316 tag_site_index: u16,
21317}
21318
21319impl PartitionCoproductWitness {
21320 #[inline]
21321 #[must_use]
21322 pub const fn witt_bits(&self) -> u16 {
21323 self.witt_bits
21324 }
21325 #[inline]
21326 #[must_use]
21327 pub const fn content_fingerprint(&self) -> ContentFingerprint {
21328 self.content_fingerprint
21329 }
21330 #[inline]
21331 #[must_use]
21332 pub const fn left_fingerprint(&self) -> ContentFingerprint {
21333 self.left_fingerprint
21334 }
21335 #[inline]
21336 #[must_use]
21337 pub const fn right_fingerprint(&self) -> ContentFingerprint {
21338 self.right_fingerprint
21339 }
21340 #[inline]
21342 #[must_use]
21343 pub const fn combined_site_budget(&self) -> u16 {
21344 self.combined_site_budget
21345 }
21346 #[inline]
21348 #[must_use]
21349 pub const fn combined_site_count(&self) -> u16 {
21350 self.combined_site_count
21351 }
21352 #[inline]
21355 #[must_use]
21356 pub const fn tag_site_index(&self) -> u16 {
21357 self.tag_site_index
21358 }
21359 #[inline]
21360 #[must_use]
21361 #[allow(clippy::too_many_arguments)]
21362 pub(crate) const fn with_level_fingerprints_sites_and_tag(
21363 witt_bits: u16,
21364 content_fingerprint: ContentFingerprint,
21365 left_fingerprint: ContentFingerprint,
21366 right_fingerprint: ContentFingerprint,
21367 combined_site_budget: u16,
21368 combined_site_count: u16,
21369 tag_site_index: u16,
21370 ) -> Self {
21371 Self {
21372 witt_bits,
21373 content_fingerprint,
21374 left_fingerprint,
21375 right_fingerprint,
21376 combined_site_budget,
21377 combined_site_count,
21378 tag_site_index,
21379 }
21380 }
21381}
21382
21383#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21392pub struct CartesianProductWitness {
21393 witt_bits: u16,
21394 content_fingerprint: ContentFingerprint,
21395 left_fingerprint: ContentFingerprint,
21396 right_fingerprint: ContentFingerprint,
21397 combined_site_budget: u16,
21398 combined_site_count: u16,
21399 combined_euler: i32,
21400 combined_betti: [u32; MAX_BETTI_DIMENSION],
21401}
21402
21403impl CartesianProductWitness {
21404 #[inline]
21405 #[must_use]
21406 pub const fn witt_bits(&self) -> u16 {
21407 self.witt_bits
21408 }
21409 #[inline]
21410 #[must_use]
21411 pub const fn content_fingerprint(&self) -> ContentFingerprint {
21412 self.content_fingerprint
21413 }
21414 #[inline]
21415 #[must_use]
21416 pub const fn left_fingerprint(&self) -> ContentFingerprint {
21417 self.left_fingerprint
21418 }
21419 #[inline]
21420 #[must_use]
21421 pub const fn right_fingerprint(&self) -> ContentFingerprint {
21422 self.right_fingerprint
21423 }
21424 #[inline]
21425 #[must_use]
21426 pub const fn combined_site_budget(&self) -> u16 {
21427 self.combined_site_budget
21428 }
21429 #[inline]
21430 #[must_use]
21431 pub const fn combined_site_count(&self) -> u16 {
21432 self.combined_site_count
21433 }
21434 #[inline]
21435 #[must_use]
21436 pub const fn combined_euler(&self) -> i32 {
21437 self.combined_euler
21438 }
21439 #[inline]
21440 #[must_use]
21441 pub const fn combined_betti(&self) -> [u32; MAX_BETTI_DIMENSION] {
21442 self.combined_betti
21443 }
21444 #[inline]
21445 #[must_use]
21446 #[allow(clippy::too_many_arguments)]
21447 pub(crate) const fn with_level_fingerprints_and_invariants(
21448 witt_bits: u16,
21449 content_fingerprint: ContentFingerprint,
21450 left_fingerprint: ContentFingerprint,
21451 right_fingerprint: ContentFingerprint,
21452 combined_site_budget: u16,
21453 combined_site_count: u16,
21454 combined_euler: i32,
21455 combined_betti: [u32; MAX_BETTI_DIMENSION],
21456 ) -> Self {
21457 Self {
21458 witt_bits,
21459 content_fingerprint,
21460 left_fingerprint,
21461 right_fingerprint,
21462 combined_site_budget,
21463 combined_site_count,
21464 combined_euler,
21465 combined_betti,
21466 }
21467 }
21468}
21469
21470impl Certificate for PartitionProductWitness {
21471 const IRI: &'static str = "https://uor.foundation/partition/PartitionProduct";
21472 type Evidence = PartitionProductEvidence;
21473}
21474
21475impl Certificate for PartitionCoproductWitness {
21476 const IRI: &'static str = "https://uor.foundation/partition/PartitionCoproduct";
21477 type Evidence = PartitionCoproductEvidence;
21478}
21479
21480impl Certificate for CartesianProductWitness {
21481 const IRI: &'static str = "https://uor.foundation/partition/CartesianPartitionProduct";
21482 type Evidence = CartesianProductEvidence;
21483}
21484
21485impl core::fmt::Display for PartitionProductWitness {
21486 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21487 f.write_str("PartitionProductWitness")
21488 }
21489}
21490impl core::error::Error for PartitionProductWitness {}
21491
21492impl core::fmt::Display for PartitionCoproductWitness {
21493 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21494 f.write_str("PartitionCoproductWitness")
21495 }
21496}
21497impl core::error::Error for PartitionCoproductWitness {}
21498
21499impl core::fmt::Display for CartesianProductWitness {
21500 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21501 f.write_str("CartesianProductWitness")
21502 }
21503}
21504impl core::error::Error for CartesianProductWitness {}
21505
21506pub trait VerifiedMint: Certificate {
21516 type Inputs;
21518 type Error;
21522 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error>
21530 where
21531 Self: Sized;
21532}
21533
21534#[allow(clippy::too_many_arguments)]
21539fn pc_classify_constraint(
21540 c: &crate::pipeline::ConstraintRef,
21541 in_left_region: bool,
21542 tag_site: u16,
21543 max_depth: u32,
21544 left_pins: &mut u32,
21545 right_pins: &mut u32,
21546 left_bias_ok: &mut bool,
21547 right_bias_ok: &mut bool,
21548) -> Result<(), GenericImpossibilityWitness> {
21549 match c {
21550 crate::pipeline::ConstraintRef::Site { position } => {
21551 if (*position as u16) >= tag_site {
21552 return Err(GenericImpossibilityWitness::for_identity(
21553 "https://uor.foundation/op/ST_6",
21554 ));
21555 }
21556 }
21557 crate::pipeline::ConstraintRef::Carry { site } => {
21558 if (*site as u16) >= tag_site {
21559 return Err(GenericImpossibilityWitness::for_identity(
21560 "https://uor.foundation/op/ST_6",
21561 ));
21562 }
21563 }
21564 crate::pipeline::ConstraintRef::Affine { coefficients, coefficient_count, bias } => {
21565 let count = *coefficient_count as usize;
21566 let mut nonzero_count: u32 = 0;
21567 let mut nonzero_index: usize = 0;
21568 let mut max_nonzero_index: usize = 0;
21569 let mut i: usize = 0;
21570 while i < count && i < crate::pipeline::AFFINE_MAX_COEFFS {
21571 if coefficients[i] != 0 {
21572 nonzero_count = nonzero_count.saturating_add(1);
21573 nonzero_index = i;
21574 if i > max_nonzero_index { max_nonzero_index = i; }
21575 }
21576 i += 1;
21577 }
21578 let touches_tag_site = nonzero_count > 0
21579 && (max_nonzero_index as u16) >= tag_site;
21580 let is_canonical_tag_pinner = nonzero_count == 1
21581 && (nonzero_index as u16) == tag_site
21582 && coefficients[nonzero_index] == 1;
21583 if is_canonical_tag_pinner {
21584 if *bias != 0 && *bias != -1 {
21585 return Err(GenericImpossibilityWitness::for_identity(
21586 "https://uor.foundation/foundation/CoproductTagEncoding",
21587 ));
21588 }
21589 if in_left_region {
21590 *left_pins = left_pins.saturating_add(1);
21591 if *bias != 0 { *left_bias_ok = false; }
21592 } else {
21593 *right_pins = right_pins.saturating_add(1);
21594 if *bias != -1 { *right_bias_ok = false; }
21595 }
21596 } else if touches_tag_site {
21597 let nonzero_only_at_tag_site = nonzero_count == 1
21598 && (nonzero_index as u16) == tag_site;
21599 if nonzero_only_at_tag_site {
21600 return Err(GenericImpossibilityWitness::for_identity(
21601 "https://uor.foundation/foundation/CoproductTagEncoding",
21602 ));
21603 } else {
21604 return Err(GenericImpossibilityWitness::for_identity(
21605 "https://uor.foundation/op/ST_6",
21606 ));
21607 }
21608 }
21609 }
21610 crate::pipeline::ConstraintRef::Conjunction { conjuncts, conjunct_count } => {
21611 if max_depth == 0 {
21612 return Err(GenericImpossibilityWitness::for_identity(
21613 "https://uor.foundation/op/ST_6",
21614 ));
21615 }
21616 let count = *conjunct_count as usize;
21617 let mut idx: usize = 0;
21618 while idx < count && idx < crate::pipeline::CONJUNCTION_MAX_TERMS {
21619 let lifted = conjuncts[idx].into_constraint();
21620 pc_classify_constraint(
21621 &lifted,
21622 in_left_region,
21623 tag_site,
21624 max_depth - 1,
21625 left_pins,
21626 right_pins,
21627 left_bias_ok,
21628 right_bias_ok,
21629 )?;
21630 idx += 1;
21631 }
21632 }
21633 crate::pipeline::ConstraintRef::Residue { .. }
21634 | crate::pipeline::ConstraintRef::Hamming { .. }
21635 | crate::pipeline::ConstraintRef::Depth { .. }
21636 | crate::pipeline::ConstraintRef::SatClauses { .. }
21637 | crate::pipeline::ConstraintRef::Bound { .. }
21638 | crate::pipeline::ConstraintRef::Recurse { .. } => {
21641 }
21643 }
21644 Ok(())
21645}
21646
21647pub(crate) fn validate_coproduct_structure(
21658 combined_constraints: &[crate::pipeline::ConstraintRef],
21659 left_constraint_count: usize,
21660 tag_site: u16,
21661) -> Result<(), GenericImpossibilityWitness> {
21662 let mut left_pins: u32 = 0;
21663 let mut right_pins: u32 = 0;
21664 let mut left_bias_ok: bool = true;
21665 let mut right_bias_ok: bool = true;
21666 let mut idx: usize = 0;
21667 while idx < combined_constraints.len() {
21668 let in_left_region = idx < left_constraint_count;
21669 pc_classify_constraint(
21670 &combined_constraints[idx],
21671 in_left_region,
21672 tag_site,
21673 NERVE_CONSTRAINTS_CAP as u32,
21674 &mut left_pins,
21675 &mut right_pins,
21676 &mut left_bias_ok,
21677 &mut right_bias_ok,
21678 )?;
21679 idx += 1;
21680 }
21681 if left_pins != 1 || right_pins != 1 {
21682 return Err(GenericImpossibilityWitness::for_identity(
21683 "https://uor.foundation/op/ST_6",
21684 ));
21685 }
21686 if !left_bias_ok || !right_bias_ok {
21687 return Err(GenericImpossibilityWitness::for_identity(
21688 "https://uor.foundation/op/ST_7",
21689 ));
21690 }
21691 Ok(())
21692}
21693
21694#[allow(clippy::too_many_arguments)]
21699pub(crate) fn pc_primitive_partition_product(
21700 witt_bits: u16,
21701 left_fingerprint: ContentFingerprint,
21702 right_fingerprint: ContentFingerprint,
21703 left_site_budget: u16,
21704 right_site_budget: u16,
21705 left_total_site_count: u16,
21706 right_total_site_count: u16,
21707 left_euler: i32,
21708 right_euler: i32,
21709 left_entropy_nats_bits: u64,
21710 right_entropy_nats_bits: u64,
21711 combined_site_budget: u16,
21712 combined_site_count: u16,
21713 combined_euler: i32,
21714 combined_entropy_nats_bits: u64,
21715 combined_fingerprint: ContentFingerprint,
21716) -> Result<PartitionProductWitness, GenericImpossibilityWitness> {
21717 let left_entropy_nats =
21718 <f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
21719 let right_entropy_nats =
21720 <f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
21721 let combined_entropy_nats =
21722 <f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
21723 if combined_site_budget != left_site_budget.saturating_add(right_site_budget) {
21724 return Err(GenericImpossibilityWitness::for_identity(
21725 "https://uor.foundation/op/PT_1",
21726 ));
21727 }
21728 if combined_site_count != left_total_site_count.saturating_add(right_total_site_count) {
21729 return Err(GenericImpossibilityWitness::for_identity(
21730 "https://uor.foundation/foundation/ProductLayoutWidth",
21731 ));
21732 }
21733 if combined_euler != left_euler.saturating_add(right_euler) {
21734 return Err(GenericImpossibilityWitness::for_identity(
21735 "https://uor.foundation/op/PT_3",
21736 ));
21737 }
21738 if !pc_entropy_input_is_valid(left_entropy_nats)
21739 || !pc_entropy_input_is_valid(right_entropy_nats)
21740 || !pc_entropy_input_is_valid(combined_entropy_nats)
21741 {
21742 return Err(GenericImpossibilityWitness::for_identity(
21743 "https://uor.foundation/op/PT_4",
21744 ));
21745 }
21746 let expected_entropy = left_entropy_nats + right_entropy_nats;
21747 if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
21748 return Err(GenericImpossibilityWitness::for_identity(
21749 "https://uor.foundation/op/PT_4",
21750 ));
21751 }
21752 Ok(PartitionProductWitness::with_level_fingerprints_and_sites(
21753 witt_bits,
21754 combined_fingerprint,
21755 left_fingerprint,
21756 right_fingerprint,
21757 combined_site_budget,
21758 combined_site_count,
21759 ))
21760}
21761
21762#[allow(clippy::too_many_arguments)]
21767pub(crate) fn pc_primitive_partition_coproduct(
21768 witt_bits: u16,
21769 left_fingerprint: ContentFingerprint,
21770 right_fingerprint: ContentFingerprint,
21771 left_site_budget: u16,
21772 right_site_budget: u16,
21773 left_total_site_count: u16,
21774 right_total_site_count: u16,
21775 left_euler: i32,
21776 right_euler: i32,
21777 left_entropy_nats_bits: u64,
21778 right_entropy_nats_bits: u64,
21779 left_betti: [u32; MAX_BETTI_DIMENSION],
21780 right_betti: [u32; MAX_BETTI_DIMENSION],
21781 combined_site_budget: u16,
21782 combined_site_count: u16,
21783 combined_euler: i32,
21784 combined_entropy_nats_bits: u64,
21785 combined_betti: [u32; MAX_BETTI_DIMENSION],
21786 combined_fingerprint: ContentFingerprint,
21787 combined_constraints: &[crate::pipeline::ConstraintRef],
21788 left_constraint_count: usize,
21789 tag_site: u16,
21790) -> Result<PartitionCoproductWitness, GenericImpossibilityWitness> {
21791 let left_entropy_nats =
21792 <f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
21793 let right_entropy_nats =
21794 <f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
21795 let combined_entropy_nats =
21796 <f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
21797 let expected_budget = if left_site_budget > right_site_budget {
21798 left_site_budget
21799 } else {
21800 right_site_budget
21801 };
21802 if combined_site_budget != expected_budget {
21803 return Err(GenericImpossibilityWitness::for_identity(
21804 "https://uor.foundation/op/ST_1",
21805 ));
21806 }
21807 let max_total = if left_total_site_count > right_total_site_count {
21808 left_total_site_count
21809 } else {
21810 right_total_site_count
21811 };
21812 let expected_total = max_total.saturating_add(1);
21813 if combined_site_count != expected_total {
21814 return Err(GenericImpossibilityWitness::for_identity(
21815 "https://uor.foundation/foundation/CoproductLayoutWidth",
21816 ));
21817 }
21818 if !pc_entropy_input_is_valid(left_entropy_nats)
21819 || !pc_entropy_input_is_valid(right_entropy_nats)
21820 || !pc_entropy_input_is_valid(combined_entropy_nats)
21821 {
21822 return Err(GenericImpossibilityWitness::for_identity(
21823 "https://uor.foundation/op/ST_2",
21824 ));
21825 }
21826 let max_operand_entropy = if left_entropy_nats > right_entropy_nats {
21827 left_entropy_nats
21828 } else {
21829 right_entropy_nats
21830 };
21831 let expected_entropy = core::f64::consts::LN_2 + max_operand_entropy;
21832 if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
21833 return Err(GenericImpossibilityWitness::for_identity(
21834 "https://uor.foundation/op/ST_2",
21835 ));
21836 }
21837 if tag_site != max_total {
21838 return Err(GenericImpossibilityWitness::for_identity(
21839 "https://uor.foundation/foundation/CoproductLayoutWidth",
21840 ));
21841 }
21842 validate_coproduct_structure(combined_constraints, left_constraint_count, tag_site)?;
21843 if combined_euler != left_euler.saturating_add(right_euler) {
21844 return Err(GenericImpossibilityWitness::for_identity(
21845 "https://uor.foundation/op/ST_9",
21846 ));
21847 }
21848 let mut k: usize = 0;
21849 while k < MAX_BETTI_DIMENSION {
21850 if combined_betti[k] != left_betti[k].saturating_add(right_betti[k]) {
21851 return Err(GenericImpossibilityWitness::for_identity(
21852 "https://uor.foundation/op/ST_10",
21853 ));
21854 }
21855 k += 1;
21856 }
21857 Ok(
21858 PartitionCoproductWitness::with_level_fingerprints_sites_and_tag(
21859 witt_bits,
21860 combined_fingerprint,
21861 left_fingerprint,
21862 right_fingerprint,
21863 combined_site_budget,
21864 combined_site_count,
21865 max_total,
21866 ),
21867 )
21868}
21869
21870#[allow(clippy::too_many_arguments)]
21875pub(crate) fn pc_primitive_cartesian_product(
21876 witt_bits: u16,
21877 left_fingerprint: ContentFingerprint,
21878 right_fingerprint: ContentFingerprint,
21879 left_site_budget: u16,
21880 right_site_budget: u16,
21881 left_total_site_count: u16,
21882 right_total_site_count: u16,
21883 left_euler: i32,
21884 right_euler: i32,
21885 left_betti: [u32; MAX_BETTI_DIMENSION],
21886 right_betti: [u32; MAX_BETTI_DIMENSION],
21887 left_entropy_nats_bits: u64,
21888 right_entropy_nats_bits: u64,
21889 combined_site_budget: u16,
21890 combined_site_count: u16,
21891 combined_euler: i32,
21892 combined_betti: [u32; MAX_BETTI_DIMENSION],
21893 combined_entropy_nats_bits: u64,
21894 combined_fingerprint: ContentFingerprint,
21895) -> Result<CartesianProductWitness, GenericImpossibilityWitness> {
21896 let left_entropy_nats =
21897 <f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
21898 let right_entropy_nats =
21899 <f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
21900 let combined_entropy_nats =
21901 <f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
21902 if combined_site_budget != left_site_budget.saturating_add(right_site_budget) {
21903 return Err(GenericImpossibilityWitness::for_identity(
21904 "https://uor.foundation/op/CPT_1",
21905 ));
21906 }
21907 if combined_site_count != left_total_site_count.saturating_add(right_total_site_count) {
21908 return Err(GenericImpossibilityWitness::for_identity(
21909 "https://uor.foundation/foundation/CartesianLayoutWidth",
21910 ));
21911 }
21912 if combined_euler != left_euler.saturating_mul(right_euler) {
21913 return Err(GenericImpossibilityWitness::for_identity(
21914 "https://uor.foundation/op/CPT_3",
21915 ));
21916 }
21917 let kunneth = crate::pipeline::kunneth_compose(&left_betti, &right_betti);
21918 let mut k: usize = 0;
21919 while k < MAX_BETTI_DIMENSION {
21920 if combined_betti[k] != kunneth[k] {
21921 return Err(GenericImpossibilityWitness::for_identity(
21922 "https://uor.foundation/op/CPT_4",
21923 ));
21924 }
21925 k += 1;
21926 }
21927 if !pc_entropy_input_is_valid(left_entropy_nats)
21928 || !pc_entropy_input_is_valid(right_entropy_nats)
21929 || !pc_entropy_input_is_valid(combined_entropy_nats)
21930 {
21931 return Err(GenericImpossibilityWitness::for_identity(
21932 "https://uor.foundation/op/CPT_5",
21933 ));
21934 }
21935 let expected_entropy = left_entropy_nats + right_entropy_nats;
21936 if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
21937 return Err(GenericImpossibilityWitness::for_identity(
21938 "https://uor.foundation/op/CPT_5",
21939 ));
21940 }
21941 Ok(
21942 CartesianProductWitness::with_level_fingerprints_and_invariants(
21943 witt_bits,
21944 combined_fingerprint,
21945 left_fingerprint,
21946 right_fingerprint,
21947 combined_site_budget,
21948 combined_site_count,
21949 combined_euler,
21950 combined_betti,
21951 ),
21952 )
21953}
21954
21955impl VerifiedMint for PartitionProductWitness {
21956 type Inputs = PartitionProductMintInputs;
21957 type Error = GenericImpossibilityWitness;
21958 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
21959 pc_primitive_partition_product(
21960 inputs.witt_bits,
21961 inputs.left_fingerprint,
21962 inputs.right_fingerprint,
21963 inputs.left_site_budget,
21964 inputs.right_site_budget,
21965 inputs.left_total_site_count,
21966 inputs.right_total_site_count,
21967 inputs.left_euler,
21968 inputs.right_euler,
21969 inputs.left_entropy_nats_bits,
21970 inputs.right_entropy_nats_bits,
21971 inputs.combined_site_budget,
21972 inputs.combined_site_count,
21973 inputs.combined_euler,
21974 inputs.combined_entropy_nats_bits,
21975 inputs.combined_fingerprint,
21976 )
21977 }
21978}
21979
21980impl VerifiedMint for PartitionCoproductWitness {
21981 type Inputs = PartitionCoproductMintInputs;
21982 type Error = GenericImpossibilityWitness;
21983 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
21984 pc_primitive_partition_coproduct(
21985 inputs.witt_bits,
21986 inputs.left_fingerprint,
21987 inputs.right_fingerprint,
21988 inputs.left_site_budget,
21989 inputs.right_site_budget,
21990 inputs.left_total_site_count,
21991 inputs.right_total_site_count,
21992 inputs.left_euler,
21993 inputs.right_euler,
21994 inputs.left_entropy_nats_bits,
21995 inputs.right_entropy_nats_bits,
21996 inputs.left_betti,
21997 inputs.right_betti,
21998 inputs.combined_site_budget,
21999 inputs.combined_site_count,
22000 inputs.combined_euler,
22001 inputs.combined_entropy_nats_bits,
22002 inputs.combined_betti,
22003 inputs.combined_fingerprint,
22004 inputs.combined_constraints,
22005 inputs.left_constraint_count,
22006 inputs.tag_site,
22007 )
22008 }
22009}
22010
22011impl VerifiedMint for CartesianProductWitness {
22012 type Inputs = CartesianProductMintInputs;
22013 type Error = GenericImpossibilityWitness;
22014 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
22015 pc_primitive_cartesian_product(
22016 inputs.witt_bits,
22017 inputs.left_fingerprint,
22018 inputs.right_fingerprint,
22019 inputs.left_site_budget,
22020 inputs.right_site_budget,
22021 inputs.left_total_site_count,
22022 inputs.right_total_site_count,
22023 inputs.left_euler,
22024 inputs.right_euler,
22025 inputs.left_betti,
22026 inputs.right_betti,
22027 inputs.left_entropy_nats_bits,
22028 inputs.right_entropy_nats_bits,
22029 inputs.combined_site_budget,
22030 inputs.combined_site_count,
22031 inputs.combined_euler,
22032 inputs.combined_betti,
22033 inputs.combined_entropy_nats_bits,
22034 inputs.combined_fingerprint,
22035 )
22036 }
22037}
22038
22039#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22046pub struct PartitionRecord<H: crate::HostTypes> {
22047 pub site_budget: u16,
22049 pub euler: i32,
22051 pub betti: [u32; MAX_BETTI_DIMENSION],
22053 pub entropy_nats_bits: u64,
22055 _phantom: core::marker::PhantomData<H>,
22056}
22057
22058impl<H: crate::HostTypes> PartitionRecord<H> {
22059 #[inline]
22062 #[must_use]
22063 pub const fn new(
22064 site_budget: u16,
22065 euler: i32,
22066 betti: [u32; MAX_BETTI_DIMENSION],
22067 entropy_nats_bits: u64,
22068 ) -> Self {
22069 Self {
22070 site_budget,
22071 euler,
22072 betti,
22073 entropy_nats_bits,
22074 _phantom: core::marker::PhantomData,
22075 }
22076 }
22077}
22078
22079pub trait PartitionResolver<H: crate::HostTypes> {
22084 fn resolve(&self, fp: ContentFingerprint) -> Option<PartitionRecord<H>>;
22088}
22089
22090#[derive(Debug)]
22096pub struct PartitionHandle<H: crate::HostTypes> {
22097 fingerprint: ContentFingerprint,
22098 _phantom: core::marker::PhantomData<H>,
22099}
22100impl<H: crate::HostTypes> Copy for PartitionHandle<H> {}
22101impl<H: crate::HostTypes> Clone for PartitionHandle<H> {
22102 #[inline]
22103 fn clone(&self) -> Self {
22104 *self
22105 }
22106}
22107impl<H: crate::HostTypes> PartialEq for PartitionHandle<H> {
22108 #[inline]
22109 fn eq(&self, other: &Self) -> bool {
22110 self.fingerprint == other.fingerprint
22111 }
22112}
22113impl<H: crate::HostTypes> Eq for PartitionHandle<H> {}
22114impl<H: crate::HostTypes> core::hash::Hash for PartitionHandle<H> {
22115 #[inline]
22116 fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
22117 self.fingerprint.hash(state);
22118 }
22119}
22120
22121impl<H: crate::HostTypes> PartitionHandle<H> {
22122 #[inline]
22124 #[must_use]
22125 pub const fn from_fingerprint(fingerprint: ContentFingerprint) -> Self {
22126 Self {
22127 fingerprint,
22128 _phantom: core::marker::PhantomData,
22129 }
22130 }
22131 #[inline]
22133 #[must_use]
22134 pub const fn fingerprint(&self) -> ContentFingerprint {
22135 self.fingerprint
22136 }
22137 #[inline]
22140 pub fn resolve_with<R: PartitionResolver<H>>(
22141 &self,
22142 resolver: &R,
22143 ) -> Option<PartitionRecord<H>> {
22144 resolver.resolve(self.fingerprint)
22145 }
22146}
22147
22148#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22152pub struct NullElement<H: HostTypes> {
22153 _phantom: core::marker::PhantomData<H>,
22154}
22155impl<H: HostTypes> Default for NullElement<H> {
22156 fn default() -> Self {
22157 Self {
22158 _phantom: core::marker::PhantomData,
22159 }
22160 }
22161}
22162impl<H: HostTypes> crate::kernel::address::Element<H> for NullElement<H> {
22163 fn length(&self) -> u64 {
22164 0
22165 }
22166 fn addresses(&self) -> &H::HostString {
22167 H::EMPTY_HOST_STRING
22168 }
22169 fn digest(&self) -> &H::HostString {
22170 H::EMPTY_HOST_STRING
22171 }
22172 fn digest_algorithm(&self) -> &H::HostString {
22173 H::EMPTY_HOST_STRING
22174 }
22175 fn canonical_bytes(&self) -> &H::WitnessBytes {
22176 H::EMPTY_WITNESS_BYTES
22177 }
22178 fn witt_length(&self) -> u64 {
22179 0
22180 }
22181}
22182
22183#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22185pub struct NullDatum<H: HostTypes> {
22186 element: NullElement<H>,
22187 _phantom: core::marker::PhantomData<H>,
22188}
22189impl<H: HostTypes> Default for NullDatum<H> {
22190 fn default() -> Self {
22191 Self {
22192 element: NullElement::default(),
22193 _phantom: core::marker::PhantomData,
22194 }
22195 }
22196}
22197impl<H: HostTypes> crate::kernel::schema::Datum<H> for NullDatum<H> {
22198 fn value(&self) -> u64 {
22199 0
22200 }
22201 fn witt_length(&self) -> u64 {
22202 0
22203 }
22204 fn stratum(&self) -> u64 {
22205 0
22206 }
22207 fn spectrum(&self) -> u64 {
22208 0
22209 }
22210 type Element = NullElement<H>;
22211 fn element(&self) -> &Self::Element {
22212 &self.element
22213 }
22214}
22215
22216#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22218pub struct NullTermExpression<H: HostTypes> {
22219 _phantom: core::marker::PhantomData<H>,
22220}
22221impl<H: HostTypes> Default for NullTermExpression<H> {
22222 fn default() -> Self {
22223 Self {
22224 _phantom: core::marker::PhantomData,
22225 }
22226 }
22227}
22228impl<H: HostTypes> crate::kernel::schema::TermExpression<H> for NullTermExpression<H> {}
22229
22230#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22233pub struct NullSiteIndex<H: HostTypes> {
22234 _phantom: core::marker::PhantomData<H>,
22235}
22236impl<H: HostTypes> Default for NullSiteIndex<H> {
22237 fn default() -> Self {
22238 Self {
22239 _phantom: core::marker::PhantomData,
22240 }
22241 }
22242}
22243impl<H: HostTypes> crate::bridge::partition::SiteIndex<H> for NullSiteIndex<H> {
22244 fn site_position(&self) -> u64 {
22245 0
22246 }
22247 fn site_state(&self) -> u64 {
22248 0
22249 }
22250 type SiteIndexTarget = NullSiteIndex<H>;
22251 fn ancilla_site(&self) -> &Self::SiteIndexTarget {
22252 self
22253 }
22254}
22255
22256#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22260pub struct NullTagSite<H: HostTypes> {
22261 ancilla: NullSiteIndex<H>,
22262}
22263impl<H: HostTypes> Default for NullTagSite<H> {
22264 fn default() -> Self {
22265 Self {
22266 ancilla: NullSiteIndex::default(),
22267 }
22268 }
22269}
22270impl<H: HostTypes> crate::bridge::partition::SiteIndex<H> for NullTagSite<H> {
22271 fn site_position(&self) -> u64 {
22272 0
22273 }
22274 fn site_state(&self) -> u64 {
22275 0
22276 }
22277 type SiteIndexTarget = NullSiteIndex<H>;
22278 fn ancilla_site(&self) -> &Self::SiteIndexTarget {
22279 &self.ancilla
22280 }
22281}
22282impl<H: HostTypes> crate::bridge::partition::TagSite<H> for NullTagSite<H> {
22283 fn tag_value(&self) -> bool {
22284 false
22285 }
22286}
22287
22288#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22291pub struct NullSiteBinding<H: HostTypes> {
22292 constraint: NullConstraint<H>,
22293 site_index: NullSiteIndex<H>,
22294}
22295impl<H: HostTypes> Default for NullSiteBinding<H> {
22296 fn default() -> Self {
22297 Self {
22298 constraint: NullConstraint::default(),
22299 site_index: NullSiteIndex::default(),
22300 }
22301 }
22302}
22303impl<H: HostTypes> crate::bridge::partition::SiteBinding<H> for NullSiteBinding<H> {
22304 type Constraint = NullConstraint<H>;
22305 fn pinned_by(&self) -> &Self::Constraint {
22306 &self.constraint
22307 }
22308 type SiteIndex = NullSiteIndex<H>;
22309 fn pins_coordinate(&self) -> &Self::SiteIndex {
22310 &self.site_index
22311 }
22312}
22313
22314#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22317pub struct NullConstraint<H: HostTypes> {
22318 _phantom: core::marker::PhantomData<H>,
22319}
22320impl<H: HostTypes> Default for NullConstraint<H> {
22321 fn default() -> Self {
22322 Self {
22323 _phantom: core::marker::PhantomData,
22324 }
22325 }
22326}
22327impl<H: HostTypes> crate::user::type_::Constraint<H> for NullConstraint<H> {
22328 fn metric_axis(&self) -> MetricAxis {
22329 MetricAxis::Vertical
22330 }
22331 type SiteIndex = NullSiteIndex<H>;
22332 fn pins_sites(&self) -> &[Self::SiteIndex] {
22333 &[]
22334 }
22335 fn crossing_cost(&self) -> u64 {
22336 0
22337 }
22338}
22339
22340#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22343pub struct NullFreeRank<H: HostTypes> {
22344 _phantom: core::marker::PhantomData<H>,
22345}
22346impl<H: HostTypes> Default for NullFreeRank<H> {
22347 fn default() -> Self {
22348 Self {
22349 _phantom: core::marker::PhantomData,
22350 }
22351 }
22352}
22353impl<H: HostTypes> crate::bridge::partition::FreeRank<H> for NullFreeRank<H> {
22354 fn total_sites(&self) -> u64 {
22355 0
22356 }
22357 fn pinned_count(&self) -> u64 {
22358 0
22359 }
22360 fn free_rank(&self) -> u64 {
22361 0
22362 }
22363 fn is_closed(&self) -> bool {
22364 true
22365 }
22366 type SiteIndex = NullSiteIndex<H>;
22367 fn has_site(&self) -> &[Self::SiteIndex] {
22368 &[]
22369 }
22370 type SiteBinding = NullSiteBinding<H>;
22371 fn has_binding(&self) -> &[Self::SiteBinding] {
22372 &[]
22373 }
22374 fn reversible_strategy(&self) -> bool {
22375 false
22376 }
22377}
22378
22379#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22382pub struct NullIrreducibleSet<H: HostTypes> {
22383 _phantom: core::marker::PhantomData<H>,
22384}
22385impl<H: HostTypes> Default for NullIrreducibleSet<H> {
22386 fn default() -> Self {
22387 Self {
22388 _phantom: core::marker::PhantomData,
22389 }
22390 }
22391}
22392impl<H: HostTypes> crate::bridge::partition::Component<H> for NullIrreducibleSet<H> {
22393 type Datum = NullDatum<H>;
22394 fn member(&self) -> &[Self::Datum] {
22395 &[]
22396 }
22397 fn cardinality(&self) -> u64 {
22398 0
22399 }
22400}
22401impl<H: HostTypes> crate::bridge::partition::IrreducibleSet<H> for NullIrreducibleSet<H> {}
22402
22403#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22406pub struct NullReducibleSet<H: HostTypes> {
22407 _phantom: core::marker::PhantomData<H>,
22408}
22409impl<H: HostTypes> Default for NullReducibleSet<H> {
22410 fn default() -> Self {
22411 Self {
22412 _phantom: core::marker::PhantomData,
22413 }
22414 }
22415}
22416impl<H: HostTypes> crate::bridge::partition::Component<H> for NullReducibleSet<H> {
22417 type Datum = NullDatum<H>;
22418 fn member(&self) -> &[Self::Datum] {
22419 &[]
22420 }
22421 fn cardinality(&self) -> u64 {
22422 0
22423 }
22424}
22425impl<H: HostTypes> crate::bridge::partition::ReducibleSet<H> for NullReducibleSet<H> {}
22426
22427#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22430pub struct NullUnitGroup<H: HostTypes> {
22431 _phantom: core::marker::PhantomData<H>,
22432}
22433impl<H: HostTypes> Default for NullUnitGroup<H> {
22434 fn default() -> Self {
22435 Self {
22436 _phantom: core::marker::PhantomData,
22437 }
22438 }
22439}
22440impl<H: HostTypes> crate::bridge::partition::Component<H> for NullUnitGroup<H> {
22441 type Datum = NullDatum<H>;
22442 fn member(&self) -> &[Self::Datum] {
22443 &[]
22444 }
22445 fn cardinality(&self) -> u64 {
22446 0
22447 }
22448}
22449impl<H: HostTypes> crate::bridge::partition::UnitGroup<H> for NullUnitGroup<H> {}
22450
22451#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22455pub struct NullComplement<H: HostTypes> {
22456 term: NullTermExpression<H>,
22457}
22458impl<H: HostTypes> Default for NullComplement<H> {
22459 fn default() -> Self {
22460 Self {
22461 term: NullTermExpression::default(),
22462 }
22463 }
22464}
22465impl<H: HostTypes> crate::bridge::partition::Component<H> for NullComplement<H> {
22466 type Datum = NullDatum<H>;
22467 fn member(&self) -> &[Self::Datum] {
22468 &[]
22469 }
22470 fn cardinality(&self) -> u64 {
22471 0
22472 }
22473}
22474impl<H: HostTypes> crate::bridge::partition::Complement<H> for NullComplement<H> {
22475 type TermExpression = NullTermExpression<H>;
22476 fn exterior_criteria(&self) -> &Self::TermExpression {
22477 &self.term
22478 }
22479}
22480
22481#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22484pub struct NullTypeDefinition<H: HostTypes> {
22485 element: NullElement<H>,
22486}
22487impl<H: HostTypes> Default for NullTypeDefinition<H> {
22488 fn default() -> Self {
22489 Self {
22490 element: NullElement::default(),
22491 }
22492 }
22493}
22494impl<H: HostTypes> crate::user::type_::TypeDefinition<H> for NullTypeDefinition<H> {
22495 type Element = NullElement<H>;
22496 fn content_address(&self) -> &Self::Element {
22497 &self.element
22498 }
22499}
22500
22501#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22510pub struct NullPartition<H: HostTypes> {
22511 irreducibles: NullIrreducibleSet<H>,
22512 reducibles: NullReducibleSet<H>,
22513 units: NullUnitGroup<H>,
22514 exterior: NullComplement<H>,
22515 free_rank: NullFreeRank<H>,
22516 tag_site: NullTagSite<H>,
22517 source_type: NullTypeDefinition<H>,
22518 fingerprint: ContentFingerprint,
22519}
22520
22521impl<H: HostTypes> NullPartition<H> {
22522 #[inline]
22525 #[must_use]
22526 pub fn from_fingerprint(fingerprint: ContentFingerprint) -> Self {
22527 Self {
22528 irreducibles: NullIrreducibleSet::default(),
22529 reducibles: NullReducibleSet::default(),
22530 units: NullUnitGroup::default(),
22531 exterior: NullComplement::default(),
22532 free_rank: NullFreeRank::default(),
22533 tag_site: NullTagSite::default(),
22534 source_type: NullTypeDefinition::default(),
22535 fingerprint,
22536 }
22537 }
22538 #[inline]
22540 #[must_use]
22541 pub const fn fingerprint(&self) -> ContentFingerprint {
22542 self.fingerprint
22543 }
22544 pub const ABSENT: NullPartition<H> = NullPartition {
22547 irreducibles: NullIrreducibleSet {
22548 _phantom: core::marker::PhantomData,
22549 },
22550 reducibles: NullReducibleSet {
22551 _phantom: core::marker::PhantomData,
22552 },
22553 units: NullUnitGroup {
22554 _phantom: core::marker::PhantomData,
22555 },
22556 exterior: NullComplement {
22557 term: NullTermExpression {
22558 _phantom: core::marker::PhantomData,
22559 },
22560 },
22561 free_rank: NullFreeRank {
22562 _phantom: core::marker::PhantomData,
22563 },
22564 tag_site: NullTagSite {
22565 ancilla: NullSiteIndex {
22566 _phantom: core::marker::PhantomData,
22567 },
22568 },
22569 source_type: NullTypeDefinition {
22570 element: NullElement {
22571 _phantom: core::marker::PhantomData,
22572 },
22573 },
22574 fingerprint: ContentFingerprint::zero(),
22575 };
22576}
22577
22578impl<H: HostTypes> crate::bridge::partition::Partition<H> for NullPartition<H> {
22579 type IrreducibleSet = NullIrreducibleSet<H>;
22580 fn irreducibles(&self) -> &Self::IrreducibleSet {
22581 &self.irreducibles
22582 }
22583 type ReducibleSet = NullReducibleSet<H>;
22584 fn reducibles(&self) -> &Self::ReducibleSet {
22585 &self.reducibles
22586 }
22587 type UnitGroup = NullUnitGroup<H>;
22588 fn units(&self) -> &Self::UnitGroup {
22589 &self.units
22590 }
22591 type Complement = NullComplement<H>;
22592 fn exterior(&self) -> &Self::Complement {
22593 &self.exterior
22594 }
22595 fn density(&self) -> H::Decimal {
22596 H::EMPTY_DECIMAL
22597 }
22598 type TypeDefinition = NullTypeDefinition<H>;
22599 fn source_type(&self) -> &Self::TypeDefinition {
22600 &self.source_type
22601 }
22602 fn witt_length(&self) -> u64 {
22603 0
22604 }
22605 type FreeRank = NullFreeRank<H>;
22606 fn site_budget(&self) -> &Self::FreeRank {
22607 &self.free_rank
22608 }
22609 fn is_exhaustive(&self) -> bool {
22610 true
22611 }
22612 type TagSite = NullTagSite<H>;
22613 fn tag_site_of(&self) -> &Self::TagSite {
22614 &self.tag_site
22615 }
22616 fn product_category_level(&self) -> &H::HostString {
22617 H::EMPTY_HOST_STRING
22618 }
22619}
22620
22621impl<H: HostTypes> crate::bridge::partition::PartitionProduct<H> for PartitionProductWitness {
22622 type Partition = NullPartition<H>;
22623 fn left_factor(&self) -> Self::Partition {
22624 NullPartition::from_fingerprint(self.left_fingerprint)
22625 }
22626 fn right_factor(&self) -> Self::Partition {
22627 NullPartition::from_fingerprint(self.right_fingerprint)
22628 }
22629}
22630
22631impl<H: HostTypes> crate::bridge::partition::PartitionCoproduct<H> for PartitionCoproductWitness {
22632 type Partition = NullPartition<H>;
22633 fn left_summand(&self) -> Self::Partition {
22634 NullPartition::from_fingerprint(self.left_fingerprint)
22635 }
22636 fn right_summand(&self) -> Self::Partition {
22637 NullPartition::from_fingerprint(self.right_fingerprint)
22638 }
22639}
22640
22641impl<H: HostTypes> crate::bridge::partition::CartesianPartitionProduct<H>
22642 for CartesianProductWitness
22643{
22644 type Partition = NullPartition<H>;
22645 fn left_cartesian_factor(&self) -> Self::Partition {
22646 NullPartition::from_fingerprint(self.left_fingerprint)
22647 }
22648 fn right_cartesian_factor(&self) -> Self::Partition {
22649 NullPartition::from_fingerprint(self.right_fingerprint)
22650 }
22651}
22652
22653pub mod prelude {
22660 pub use super::calibrations;
22661 pub use super::Add;
22662 pub use super::And;
22663 pub use super::BNot;
22664 pub use super::BinaryGroundingMap;
22665 pub use super::BindingEntry;
22666 pub use super::BindingsTable;
22667 pub use super::BornRuleVerification;
22668 pub use super::Calibration;
22669 pub use super::CalibrationError;
22670 pub use super::CanonicalTimingPolicy;
22671 pub use super::Certificate;
22672 pub use super::Certified;
22673 pub use super::ChainAuditTrail;
22674 pub use super::CompileTime;
22675 pub use super::CompileUnit;
22676 pub use super::CompileUnitBuilder;
22677 pub use super::CompletenessAuditTrail;
22678 pub use super::CompletenessCertificate;
22679 pub use super::ConstrainedTypeInput;
22680 pub use super::ContentAddress;
22681 pub use super::ContentFingerprint;
22682 pub use super::Datum;
22683 pub use super::DigestGroundingMap;
22684 pub use super::Embed;
22685 pub use super::FragmentMarker;
22686 pub use super::GenericImpossibilityWitness;
22687 pub use super::GeodesicCertificate;
22688 pub use super::GeodesicEvidenceBundle;
22689 pub use super::Grounded;
22690 pub use super::GroundedCoord;
22691 pub use super::GroundedShape;
22692 pub use super::GroundedTuple;
22693 pub use super::GroundedValue;
22694 pub use super::Grounding;
22695 pub use super::GroundingCertificate;
22696 pub use super::GroundingExt;
22697 pub use super::GroundingMapKind;
22698 pub use super::GroundingProgram;
22699 pub use super::Hasher;
22700 pub use super::ImpossibilityWitnessKind;
22701 pub use super::InhabitanceCertificate;
22702 pub use super::InhabitanceImpossibilityWitness;
22703 pub use super::IntegerGroundingMap;
22704 pub use super::Invertible;
22705 pub use super::InvolutionCertificate;
22706 pub use super::IsometryCertificate;
22707 pub use super::JsonGroundingMap;
22708 pub use super::LandauerBudget;
22709 pub use super::LiftChainCertificate;
22710 pub use super::MeasurementCertificate;
22711 pub use super::Mul;
22712 pub use super::Nanos;
22713 pub use super::Neg;
22714 pub use super::OntologyTarget;
22715 pub use super::Or;
22716 pub use super::PipelineFailure;
22717 pub use super::PreservesMetric;
22718 pub use super::PreservesStructure;
22719 pub use super::RingOp;
22720 pub use super::Runtime;
22721 pub use super::ShapeViolation;
22722 pub use super::Sub;
22723 pub use super::Succ;
22724 pub use super::Term;
22725 pub use super::TermArena;
22726 pub use super::TimingPolicy;
22727 pub use super::Total;
22728 pub use super::TransformCertificate;
22729 pub use super::Triad;
22730 pub use super::UnaryRingOp;
22731 pub use super::UorTime;
22732 pub use super::Utf8GroundingMap;
22733 pub use super::ValidLevelEmbedding;
22734 pub use super::Validated;
22735 pub use super::ValidationPhase;
22736 pub use super::Xor;
22737 pub use super::W16;
22738 pub use super::W8;
22739 pub use crate::pipeline::empty_bindings_table;
22740 pub use crate::pipeline::{
22741 validate_constrained_type, validate_constrained_type_const, ConstrainedTypeShape,
22742 ConstraintRef, FragmentKind,
22743 };
22744 pub use crate::{DecimalTranscendental, DefaultHostTypes, HostTypes, WittLevel};
22745}