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<'a, 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: crate::pipeline::TermValue<'a, INLINE_BYTES>,
8944 _phantom: PhantomData<T>,
8946 _tag: PhantomData<Tag>,
8949}
8950
8951impl<'a, T: GroundedShape, const INLINE_BYTES: usize, Tag> Grounded<'a, T, INLINE_BYTES, Tag> {
8952 #[inline]
8956 #[must_use]
8957 pub fn get_binding(&self, address: ContentAddress) -> Option<&'static [u8]> {
8958 self.bindings
8959 .entries
8960 .binary_search_by_key(&address.as_u128(), |e| e.address.as_u128())
8961 .ok()
8962 .map(|i| self.bindings.entries[i].bytes)
8963 }
8964
8965 #[inline]
8967 pub fn iter_bindings(&self) -> impl Iterator<Item = &BindingEntry> + '_ {
8968 self.bindings.entries.iter()
8969 }
8970
8971 #[inline]
8973 #[must_use]
8974 pub const fn witt_level_bits(&self) -> u16 {
8975 self.witt_level_bits
8976 }
8977
8978 #[inline]
8980 #[must_use]
8981 pub const fn unit_address(&self) -> ContentAddress {
8982 self.unit_address
8983 }
8984
8985 #[inline]
8987 #[must_use]
8988 pub const fn certificate(&self) -> &Validated<GroundingCertificate> {
8989 &self.validated
8990 }
8991
8992 #[inline]
8995 #[must_use]
8996 pub const fn d_delta(&self) -> DDeltaMetric {
8997 DDeltaMetric::new(self.d_delta)
8998 }
8999
9000 #[inline]
9002 #[must_use]
9003 pub fn sigma(&self) -> SigmaValue<crate::DefaultHostTypes> {
9004 let value = <f64 as crate::DecimalTranscendental>::from_u32(self.sigma_ppm)
9007 / <f64 as crate::DecimalTranscendental>::from_u32(1_000_000);
9008 SigmaValue::<crate::DefaultHostTypes>::new_unchecked(value)
9009 }
9010
9011 #[inline]
9013 #[must_use]
9014 pub fn jacobian(&self) -> JacobianMetric<T> {
9015 JacobianMetric::from_entries(self.jacobian_entries, self.jacobian_len)
9016 }
9017
9018 #[inline]
9020 #[must_use]
9021 pub const fn betti(&self) -> BettiMetric {
9022 BettiMetric::new(self.betti_numbers)
9023 }
9024
9025 #[inline]
9028 #[must_use]
9029 pub const fn euler(&self) -> EulerMetric {
9030 EulerMetric::new(self.euler_characteristic)
9031 }
9032
9033 #[inline]
9035 #[must_use]
9036 pub const fn residual(&self) -> ResidualMetric {
9037 ResidualMetric::new(self.residual_count)
9038 }
9039
9040 #[inline]
9046 #[must_use]
9047 pub const fn content_fingerprint(&self) -> ContentFingerprint {
9048 self.content_fingerprint
9049 }
9050
9051 #[inline]
9062 #[must_use]
9063 pub const fn derivation(&self) -> Derivation {
9064 Derivation::new(
9065 (self.jacobian_len as u32) + 1,
9066 self.witt_level_bits,
9067 self.content_fingerprint,
9068 )
9069 }
9070
9071 #[inline]
9080 #[must_use]
9081 pub fn tag<NewTag>(self) -> Grounded<'a, T, INLINE_BYTES, NewTag> {
9082 Grounded {
9083 validated: self.validated,
9084 bindings: self.bindings,
9085 witt_level_bits: self.witt_level_bits,
9086 unit_address: self.unit_address,
9087 uor_time: self.uor_time,
9088 sigma_ppm: self.sigma_ppm,
9089 d_delta: self.d_delta,
9090 euler_characteristic: self.euler_characteristic,
9091 residual_count: self.residual_count,
9092 jacobian_entries: self.jacobian_entries,
9093 jacobian_len: self.jacobian_len,
9094 betti_numbers: self.betti_numbers,
9095 content_fingerprint: self.content_fingerprint,
9096 output: self.output,
9097 _phantom: PhantomData,
9098 _tag: PhantomData,
9099 }
9100 }
9101
9102 #[inline]
9110 #[must_use]
9111 pub fn output_bytes(&self) -> &[u8] {
9112 self.output.bytes()
9116 }
9117
9118 #[inline]
9124 #[must_use]
9125 pub fn output_value(&self) -> crate::pipeline::TermValue<'a, INLINE_BYTES> {
9126 self.output
9127 }
9128
9129 #[inline]
9136 #[must_use]
9137 pub const fn uor_time(&self) -> UorTime {
9138 self.uor_time
9139 }
9140
9141 #[inline]
9148 #[must_use]
9149 pub const fn triad(&self) -> Triad<T> {
9150 let addr = self.unit_address.as_u128();
9151 let addr_lo = addr as u64;
9152 let addr_hi = (addr >> 64) as u64;
9153 let stratum = if addr_lo == 0 {
9154 0u64
9155 } else {
9156 addr_lo.trailing_zeros() as u64
9157 };
9158 Triad::new(stratum, addr_lo, addr_hi)
9159 }
9160
9161 #[inline]
9169 #[allow(dead_code)]
9170 pub(crate) const fn new_internal(
9171 validated: Validated<GroundingCertificate>,
9172 bindings: BindingsTable,
9173 witt_level_bits: u16,
9174 unit_address: ContentAddress,
9175 content_fingerprint: ContentFingerprint,
9176 ) -> Self {
9177 let bound_count = bindings.entries.len() as u32;
9178 let declared_sites = if witt_level_bits == 0 {
9179 1u32
9180 } else {
9181 witt_level_bits as u32
9182 };
9183 let sigma_ppm = if bound_count >= declared_sites {
9185 1_000_000u32
9186 } else {
9187 let num = (bound_count as u64) * 1_000_000u64;
9189 (num / (declared_sites as u64)) as u32
9190 };
9191 let residual_count = declared_sites.saturating_sub(bound_count);
9193 let d_delta = (witt_level_bits as i64) - (bound_count as i64);
9195 let mut betti = [0u32; MAX_BETTI_DIMENSION];
9197 betti[0] = 1;
9198 let mut k = 1usize;
9199 while k < MAX_BETTI_DIMENSION {
9200 betti[k] = ((witt_level_bits as u32) >> (k - 1)) & 1;
9201 k += 1;
9202 }
9203 let mut euler: i64 = 0;
9205 let mut k = 0usize;
9206 while k < MAX_BETTI_DIMENSION {
9207 if k & 1 == 0 {
9208 euler += betti[k] as i64;
9209 } else {
9210 euler -= betti[k] as i64;
9211 }
9212 k += 1;
9213 }
9214 let mut jac = [0i64; JACOBIAN_MAX_SITES];
9216 let modulus = (witt_level_bits as i64) + 1;
9217 let ua_lo = unit_address.as_u128() as i64;
9218 let mut i = 0usize;
9219 let jac_len = if (witt_level_bits as usize) < JACOBIAN_MAX_SITES {
9220 witt_level_bits as usize
9221 } else {
9222 JACOBIAN_MAX_SITES
9223 };
9224 while i < jac_len {
9225 let raw = ua_lo ^ (i as i64);
9226 let m = if modulus == 0 { 1 } else { modulus };
9228 jac[i] = ((raw % m) + m) % m;
9229 i += 1;
9230 }
9231 let steps = (witt_level_bits as u64) + (bound_count as u64) + (jac_len as u64);
9237 let landauer = LandauerBudget::new((steps as f64) * core::f64::consts::LN_2);
9238 let uor_time = UorTime::new(landauer, steps);
9239 Self {
9240 validated,
9241 bindings,
9242 witt_level_bits,
9243 unit_address,
9244 uor_time,
9245 sigma_ppm,
9246 d_delta,
9247 euler_characteristic: euler,
9248 residual_count,
9249 jacobian_entries: jac,
9250 jacobian_len: jac_len as u16,
9251 betti_numbers: betti,
9252 content_fingerprint,
9253 output: crate::pipeline::TermValue::empty(),
9254 _phantom: PhantomData,
9255 _tag: PhantomData,
9256 }
9257 }
9258
9259 #[inline]
9267 #[must_use]
9268 pub(crate) fn with_output(
9269 mut self,
9270 output: crate::pipeline::TermValue<'a, INLINE_BYTES>,
9271 ) -> Self {
9272 self.output = output;
9273 self
9274 }
9275
9276 #[inline]
9287 #[must_use]
9288 pub fn with_bindings(self, bindings: BindingsTable) -> Self {
9289 Self { bindings, ..self }
9290 }
9291
9292 #[inline]
9300 #[must_use]
9301 pub fn as_inhabitance_certificate(
9302 &self,
9303 ) -> crate::pipeline::InhabitanceCertificateView<'_, T, INLINE_BYTES, Tag> {
9304 crate::pipeline::InhabitanceCertificateView(self)
9305 }
9306}
9307
9308#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9313pub struct Triad<L> {
9314 stratum: u64,
9316 spectrum: u64,
9318 address: u64,
9320 _level: PhantomData<L>,
9322}
9323
9324impl<L> Triad<L> {
9325 #[inline]
9327 #[must_use]
9328 pub const fn stratum(&self) -> u64 {
9329 self.stratum
9330 }
9331
9332 #[inline]
9334 #[must_use]
9335 pub const fn spectrum(&self) -> u64 {
9336 self.spectrum
9337 }
9338
9339 #[inline]
9341 #[must_use]
9342 pub const fn address(&self) -> u64 {
9343 self.address
9344 }
9345
9346 #[inline]
9348 #[must_use]
9349 #[allow(dead_code)]
9350 pub(crate) const fn new(stratum: u64, spectrum: u64, address: u64) -> Self {
9351 Self {
9352 stratum,
9353 spectrum,
9354 address,
9355 _level: PhantomData,
9356 }
9357 }
9358}
9359
9360#[derive(Debug, Clone, PartialEq)]
9380#[non_exhaustive]
9381pub enum PipelineFailure {
9382 DispatchMiss {
9384 query_iri: &'static str,
9386 table_iri: &'static str,
9388 },
9389 GroundingFailure {
9391 reason_iri: &'static str,
9393 },
9394 ConvergenceStall {
9396 stage_iri: &'static str,
9398 angle_milliradians: i64,
9400 },
9401 ContradictionDetected {
9403 at_step: usize,
9405 trace_iri: &'static str,
9407 },
9408 CoherenceViolation {
9410 site_position: usize,
9412 constraint_iri: &'static str,
9414 },
9415 ShapeMismatch {
9417 expected: &'static str,
9419 got: &'static str,
9421 },
9422 LiftObstructionFailure {
9424 site_position: usize,
9426 obstruction_class_iri: &'static str,
9428 },
9429 ShapeViolation {
9431 report: ShapeViolation,
9433 },
9434}
9435
9436impl core::fmt::Display for PipelineFailure {
9437 fn fmt(&self, ff: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
9438 match self {
9439 Self::DispatchMiss {
9440 query_iri,
9441 table_iri,
9442 } => write!(
9443 ff,
9444 "DispatchMiss(query_iri={:?}, table_iri={:?})",
9445 query_iri, table_iri
9446 ),
9447 Self::GroundingFailure { reason_iri } => {
9448 write!(ff, "GroundingFailure(reason_iri={:?})", reason_iri)
9449 }
9450 Self::ConvergenceStall {
9451 stage_iri,
9452 angle_milliradians,
9453 } => write!(
9454 ff,
9455 "ConvergenceStall(stage_iri={:?}, angle_milliradians={:?})",
9456 stage_iri, angle_milliradians
9457 ),
9458 Self::ContradictionDetected { at_step, trace_iri } => write!(
9459 ff,
9460 "ContradictionDetected(at_step={:?}, trace_iri={:?})",
9461 at_step, trace_iri
9462 ),
9463 Self::CoherenceViolation {
9464 site_position,
9465 constraint_iri,
9466 } => write!(
9467 ff,
9468 "CoherenceViolation(site_position={:?}, constraint_iri={:?})",
9469 site_position, constraint_iri
9470 ),
9471 Self::ShapeMismatch { expected, got } => {
9472 write!(ff, "ShapeMismatch(expected={:?}, got={:?})", expected, got)
9473 }
9474 Self::LiftObstructionFailure {
9475 site_position,
9476 obstruction_class_iri,
9477 } => write!(
9478 ff,
9479 "LiftObstructionFailure(site_position={:?}, obstruction_class_iri={:?})",
9480 site_position, obstruction_class_iri
9481 ),
9482 Self::ShapeViolation { report } => write!(ff, "ShapeViolation({:?})", report),
9483 }
9484 }
9485}
9486
9487impl core::error::Error for PipelineFailure {}
9488
9489pub trait ImpossibilityWitnessKind: impossibility_witness_kind_sealed::Sealed {}
9493
9494mod impossibility_witness_kind_sealed {
9495 pub trait Sealed {}
9497 impl Sealed for super::GenericImpossibilityWitness {}
9498 impl Sealed for super::InhabitanceImpossibilityWitness {}
9499}
9500
9501impl ImpossibilityWitnessKind for GenericImpossibilityWitness {}
9502impl ImpossibilityWitnessKind for InhabitanceImpossibilityWitness {}
9503
9504pub mod resolver {
9508 use super::{
9509 BornRuleVerification,
9510 Certified,
9511 CompileUnit,
9512 CompletenessCertificate,
9513 GenericImpossibilityWitness,
9514 GeodesicCertificate,
9515 GroundingCertificate,
9516 InhabitanceCertificate,
9517 InhabitanceImpossibilityWitness,
9518 InvolutionCertificate,
9519 IsometryCertificate,
9520 LiftChainCertificate,
9521 MeasurementCertificate,
9522 TransformCertificate,
9524 Validated,
9525 WittLevel,
9526 };
9527
9528 pub mod tower_completeness {
9538 use super::*;
9539 pub fn certify<T, P, H>(
9545 input: &Validated<T, P>,
9546 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9547 where
9548 T: crate::pipeline::ConstrainedTypeShape,
9549 P: crate::enforcement::ValidationPhase,
9550 H: crate::enforcement::Hasher,
9551 {
9552 certify_at::<T, P, H>(input, WittLevel::W32)
9553 }
9554
9555 pub fn certify_at<T, P, H>(
9561 input: &Validated<T, P>,
9562 level: WittLevel,
9563 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9564 where
9565 T: crate::pipeline::ConstrainedTypeShape,
9566 P: crate::enforcement::ValidationPhase,
9567 H: crate::enforcement::Hasher,
9568 {
9569 crate::pipeline::run_tower_completeness::<T, H>(input.inner(), level)
9570 .map(|v| Certified::new(*v.inner()))
9571 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
9572 }
9573 }
9574
9575 pub mod incremental_completeness {
9577 use super::*;
9578 pub fn certify<T, P, H>(
9584 input: &Validated<T, P>,
9585 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9586 where
9587 T: crate::pipeline::ConstrainedTypeShape,
9588 P: crate::enforcement::ValidationPhase,
9589 H: crate::enforcement::Hasher,
9590 {
9591 certify_at::<T, P, H>(input, WittLevel::W32)
9592 }
9593
9594 pub fn certify_at<T, P, H>(
9600 input: &Validated<T, P>,
9601 level: WittLevel,
9602 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9603 where
9604 T: crate::pipeline::ConstrainedTypeShape,
9605 P: crate::enforcement::ValidationPhase,
9606 H: crate::enforcement::Hasher,
9607 {
9608 crate::pipeline::run_incremental_completeness::<T, H>(input.inner(), level)
9609 .map(|v| Certified::new(*v.inner()))
9610 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
9611 }
9612 }
9613
9614 pub mod grounding_aware {
9616 use super::*;
9617 pub fn certify<P, H, const INLINE_BYTES: usize>(
9623 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
9624 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9625 where
9626 P: crate::enforcement::ValidationPhase,
9627 H: crate::enforcement::Hasher,
9628 {
9629 certify_at::<P, H, INLINE_BYTES>(input, WittLevel::W32)
9630 }
9631
9632 pub fn certify_at<P, H, const INLINE_BYTES: usize>(
9638 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
9639 level: WittLevel,
9640 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9641 where
9642 P: crate::enforcement::ValidationPhase,
9643 H: crate::enforcement::Hasher,
9644 {
9645 crate::pipeline::run_grounding_aware::<INLINE_BYTES, H>(input.inner(), level)
9646 .map(|v| Certified::new(*v.inner()))
9647 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
9648 }
9649 }
9650
9651 pub mod inhabitance {
9653 use super::*;
9654 pub fn certify<T, P, H>(
9660 input: &Validated<T, P>,
9661 ) -> Result<Certified<InhabitanceCertificate>, Certified<InhabitanceImpossibilityWitness>>
9662 where
9663 T: crate::pipeline::ConstrainedTypeShape,
9664 P: crate::enforcement::ValidationPhase,
9665 H: crate::enforcement::Hasher,
9666 {
9667 certify_at::<T, P, H>(input, WittLevel::W32)
9668 }
9669
9670 pub fn certify_at<T, P, H>(
9676 input: &Validated<T, P>,
9677 level: WittLevel,
9678 ) -> Result<Certified<InhabitanceCertificate>, Certified<InhabitanceImpossibilityWitness>>
9679 where
9680 T: crate::pipeline::ConstrainedTypeShape,
9681 P: crate::enforcement::ValidationPhase,
9682 H: crate::enforcement::Hasher,
9683 {
9684 crate::pipeline::run_inhabitance::<T, H>(input.inner(), level)
9685 .map(|v: Validated<InhabitanceCertificate>| Certified::new(*v.inner()))
9686 .map_err(|_| Certified::new(InhabitanceImpossibilityWitness::default()))
9687 }
9688 }
9689
9690 pub mod multiplication {
9701 use super::super::{MulContext, MultiplicationCertificate};
9702 use super::*;
9703
9704 pub fn certify<H: crate::enforcement::Hasher>(
9716 context: &MulContext,
9717 ) -> Result<Certified<MultiplicationCertificate>, GenericImpossibilityWitness> {
9718 if context.stack_budget_bytes == 0 {
9719 return Err(GenericImpossibilityWitness::default());
9720 }
9721 let limb_count = context.limb_count.max(1);
9723 let karatsuba_stack_need = limb_count * 8 * 6;
9724 let choose_karatsuba = !context.const_eval
9725 && (context.stack_budget_bytes as usize) >= karatsuba_stack_need;
9726 let mut hasher = H::initial();
9728 hasher = hasher.fold_bytes(&context.stack_budget_bytes.to_be_bytes());
9729 hasher = hasher.fold_byte(if context.const_eval { 1 } else { 0 });
9730 hasher = hasher.fold_bytes(&(limb_count as u64).to_be_bytes());
9731 hasher = hasher.fold_byte(crate::enforcement::certificate_kind_discriminant(
9732 crate::enforcement::CertificateKind::Multiplication,
9733 ));
9734 let buffer = hasher.finalize();
9735 let fp =
9736 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
9737 let cert = if choose_karatsuba {
9738 MultiplicationCertificate::with_evidence(
9739 2,
9740 3,
9741 karatsuba_landauer_cost(limb_count),
9742 fp,
9743 )
9744 } else {
9745 MultiplicationCertificate::with_evidence(
9746 1,
9747 1,
9748 schoolbook_landauer_cost(limb_count),
9749 fp,
9750 )
9751 };
9752 Ok(Certified::new(cert))
9753 }
9754
9755 type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
9757
9758 fn schoolbook_landauer_cost(limb_count: usize) -> u64 {
9762 let n = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(limb_count as u32);
9763 let sixty_four = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(64);
9764 let ln_2 =
9765 <DefaultDecimal as crate::DecimalTranscendental>::from_bits(crate::LN_2_BITS);
9766 (n * n * sixty_four * ln_2).to_bits()
9767 }
9768
9769 fn karatsuba_landauer_cost(limb_count: usize) -> u64 {
9772 let n = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(limb_count as u32);
9773 let two = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(2);
9774 let three = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(3);
9775 let sixty_four = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(64);
9776 let ln_2 =
9777 <DefaultDecimal as crate::DecimalTranscendental>::from_bits(crate::LN_2_BITS);
9778 let n_half = n / two;
9779 (three * n_half * n_half * sixty_four * ln_2).to_bits()
9780 }
9781 }
9782
9783 pub(crate) trait ResolverKernel {
9790 const KIND: crate::enforcement::CertificateKind;
9791 type Cert: crate::enforcement::Certificate;
9794 }
9795
9796 pub mod two_sat_decider {
9814 use super::*;
9815
9816 #[doc(hidden)]
9817 pub struct Kernel;
9818 impl super::ResolverKernel for Kernel {
9819 type Cert = crate::enforcement::GroundingCertificate;
9820 const KIND: crate::enforcement::CertificateKind =
9821 crate::enforcement::CertificateKind::TwoSat;
9822 }
9823
9824 pub fn certify<
9830 T: crate::pipeline::ConstrainedTypeShape,
9831 P: crate::enforcement::ValidationPhase,
9832 H: crate::enforcement::Hasher,
9833 >(
9834 input: &Validated<T, P>,
9835 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9836 {
9837 certify_at::<T, P, H>(input, WittLevel::W32)
9838 }
9839
9840 pub fn certify_at<
9846 T: crate::pipeline::ConstrainedTypeShape,
9847 P: crate::enforcement::ValidationPhase,
9848 H: crate::enforcement::Hasher,
9849 >(
9850 input: &Validated<T, P>,
9851 level: WittLevel,
9852 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9853 {
9854 let _ = input.inner();
9855 let witt_bits = level.witt_length() as u16;
9856 let (tr_bits, tr_constraints, tr_sat) =
9857 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
9858 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
9859 if tr_sat == 0 {
9860 return Err(Certified::new(GenericImpossibilityWitness::default()));
9861 }
9862 let mut hasher = H::initial();
9863 hasher = crate::enforcement::fold_terminal_reduction(
9864 hasher,
9865 tr_bits,
9866 tr_constraints,
9867 tr_sat,
9868 );
9869 hasher = crate::enforcement::fold_unit_digest(
9870 hasher,
9871 witt_bits,
9872 witt_bits as u64,
9873 T::IRI,
9874 T::SITE_COUNT,
9875 T::CONSTRAINTS,
9876 <Kernel as super::ResolverKernel>::KIND,
9877 );
9878 let buffer = hasher.finalize();
9879 let fp =
9880 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
9881 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
9882 Ok(Certified::new(cert))
9883 }
9884 }
9885
9886 pub mod horn_sat_decider {
9904 use super::*;
9905
9906 #[doc(hidden)]
9907 pub struct Kernel;
9908 impl super::ResolverKernel for Kernel {
9909 type Cert = crate::enforcement::GroundingCertificate;
9910 const KIND: crate::enforcement::CertificateKind =
9911 crate::enforcement::CertificateKind::HornSat;
9912 }
9913
9914 pub fn certify<
9920 T: crate::pipeline::ConstrainedTypeShape,
9921 P: crate::enforcement::ValidationPhase,
9922 H: crate::enforcement::Hasher,
9923 >(
9924 input: &Validated<T, P>,
9925 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9926 {
9927 certify_at::<T, P, H>(input, WittLevel::W32)
9928 }
9929
9930 pub fn certify_at<
9936 T: crate::pipeline::ConstrainedTypeShape,
9937 P: crate::enforcement::ValidationPhase,
9938 H: crate::enforcement::Hasher,
9939 >(
9940 input: &Validated<T, P>,
9941 level: WittLevel,
9942 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9943 {
9944 let _ = input.inner();
9945 let witt_bits = level.witt_length() as u16;
9946 let (tr_bits, tr_constraints, tr_sat) =
9947 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
9948 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
9949 if tr_sat == 0 {
9950 return Err(Certified::new(GenericImpossibilityWitness::default()));
9951 }
9952 let mut hasher = H::initial();
9953 hasher = crate::enforcement::fold_terminal_reduction(
9954 hasher,
9955 tr_bits,
9956 tr_constraints,
9957 tr_sat,
9958 );
9959 hasher = crate::enforcement::fold_unit_digest(
9960 hasher,
9961 witt_bits,
9962 witt_bits as u64,
9963 T::IRI,
9964 T::SITE_COUNT,
9965 T::CONSTRAINTS,
9966 <Kernel as super::ResolverKernel>::KIND,
9967 );
9968 let buffer = hasher.finalize();
9969 let fp =
9970 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
9971 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
9972 Ok(Certified::new(cert))
9973 }
9974 }
9975
9976 pub mod residual_verdict {
9994 use super::*;
9995
9996 #[doc(hidden)]
9997 pub struct Kernel;
9998 impl super::ResolverKernel for Kernel {
9999 type Cert = crate::enforcement::GroundingCertificate;
10000 const KIND: crate::enforcement::CertificateKind =
10001 crate::enforcement::CertificateKind::ResidualVerdict;
10002 }
10003
10004 pub fn certify<
10010 T: crate::pipeline::ConstrainedTypeShape,
10011 P: crate::enforcement::ValidationPhase,
10012 H: crate::enforcement::Hasher,
10013 >(
10014 input: &Validated<T, P>,
10015 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10016 {
10017 certify_at::<T, P, H>(input, WittLevel::W32)
10018 }
10019
10020 pub fn certify_at<
10026 T: crate::pipeline::ConstrainedTypeShape,
10027 P: crate::enforcement::ValidationPhase,
10028 H: crate::enforcement::Hasher,
10029 >(
10030 input: &Validated<T, P>,
10031 level: WittLevel,
10032 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10033 {
10034 let _ = input.inner();
10035 let witt_bits = level.witt_length() as u16;
10036 let (tr_bits, tr_constraints, tr_sat) =
10037 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10038 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10039 if tr_sat == 0 {
10040 return Err(Certified::new(GenericImpossibilityWitness::default()));
10041 }
10042 let mut hasher = H::initial();
10043 hasher = crate::enforcement::fold_terminal_reduction(
10044 hasher,
10045 tr_bits,
10046 tr_constraints,
10047 tr_sat,
10048 );
10049 hasher = crate::enforcement::fold_unit_digest(
10050 hasher,
10051 witt_bits,
10052 witt_bits as u64,
10053 T::IRI,
10054 T::SITE_COUNT,
10055 T::CONSTRAINTS,
10056 <Kernel as super::ResolverKernel>::KIND,
10057 );
10058 let buffer = hasher.finalize();
10059 let fp =
10060 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10061 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10062 Ok(Certified::new(cert))
10063 }
10064 }
10065
10066 pub mod canonical_form {
10084 use super::*;
10085
10086 #[doc(hidden)]
10087 pub struct Kernel;
10088 impl super::ResolverKernel for Kernel {
10089 type Cert = crate::enforcement::TransformCertificate;
10090 const KIND: crate::enforcement::CertificateKind =
10091 crate::enforcement::CertificateKind::CanonicalForm;
10092 }
10093
10094 pub fn certify<
10100 T: crate::pipeline::ConstrainedTypeShape,
10101 P: crate::enforcement::ValidationPhase,
10102 H: crate::enforcement::Hasher,
10103 >(
10104 input: &Validated<T, P>,
10105 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10106 {
10107 certify_at::<T, P, H>(input, WittLevel::W32)
10108 }
10109
10110 pub fn certify_at<
10116 T: crate::pipeline::ConstrainedTypeShape,
10117 P: crate::enforcement::ValidationPhase,
10118 H: crate::enforcement::Hasher,
10119 >(
10120 input: &Validated<T, P>,
10121 level: WittLevel,
10122 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10123 {
10124 let _ = input.inner();
10125 let witt_bits = level.witt_length() as u16;
10126 let (tr_bits, tr_constraints, tr_sat) =
10127 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10128 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10129 if tr_sat == 0 {
10130 return Err(Certified::new(GenericImpossibilityWitness::default()));
10131 }
10132 let mut hasher = H::initial();
10133 hasher = crate::enforcement::fold_terminal_reduction(
10134 hasher,
10135 tr_bits,
10136 tr_constraints,
10137 tr_sat,
10138 );
10139 let (tr2_bits, tr2_constraints, tr2_sat) =
10140 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10141 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10142 if tr2_bits != tr_bits || tr2_constraints != tr_constraints || tr2_sat != tr_sat {
10144 return Err(Certified::new(GenericImpossibilityWitness::default()));
10145 }
10146 hasher = crate::enforcement::fold_terminal_reduction(
10147 hasher,
10148 tr2_bits,
10149 tr2_constraints,
10150 tr2_sat,
10151 );
10152 hasher = crate::enforcement::fold_unit_digest(
10153 hasher,
10154 witt_bits,
10155 witt_bits as u64,
10156 T::IRI,
10157 T::SITE_COUNT,
10158 T::CONSTRAINTS,
10159 <Kernel as super::ResolverKernel>::KIND,
10160 );
10161 let buffer = hasher.finalize();
10162 let fp =
10163 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10164 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10165 Ok(Certified::new(cert))
10166 }
10167 }
10168
10169 pub mod type_synthesis {
10187 use super::*;
10188
10189 #[doc(hidden)]
10190 pub struct Kernel;
10191 impl super::ResolverKernel for Kernel {
10192 type Cert = crate::enforcement::TransformCertificate;
10193 const KIND: crate::enforcement::CertificateKind =
10194 crate::enforcement::CertificateKind::TypeSynthesis;
10195 }
10196
10197 pub fn certify<
10203 T: crate::pipeline::ConstrainedTypeShape,
10204 P: crate::enforcement::ValidationPhase,
10205 H: crate::enforcement::Hasher,
10206 >(
10207 input: &Validated<T, P>,
10208 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10209 {
10210 certify_at::<T, P, H>(input, WittLevel::W32)
10211 }
10212
10213 pub fn certify_at<
10219 T: crate::pipeline::ConstrainedTypeShape,
10220 P: crate::enforcement::ValidationPhase,
10221 H: crate::enforcement::Hasher,
10222 >(
10223 input: &Validated<T, P>,
10224 level: WittLevel,
10225 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10226 {
10227 let _ = input.inner();
10228 let witt_bits = level.witt_length() as u16;
10229 let (tr_bits, tr_constraints, tr_sat) =
10230 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10231 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10232 if tr_sat == 0 {
10233 return Err(Certified::new(GenericImpossibilityWitness::default()));
10234 }
10235 let mut hasher = H::initial();
10236 hasher = crate::enforcement::fold_terminal_reduction(
10237 hasher,
10238 tr_bits,
10239 tr_constraints,
10240 tr_sat,
10241 );
10242 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10243 .map_err(crate::enforcement::Certified::new)?;
10244 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
10245 let (residual, entropy) = crate::enforcement::primitive_descent_metrics::<T>(&betti);
10246 hasher = crate::enforcement::fold_descent_metrics(hasher, residual, entropy);
10247 hasher = crate::enforcement::fold_unit_digest(
10248 hasher,
10249 witt_bits,
10250 witt_bits as u64,
10251 T::IRI,
10252 T::SITE_COUNT,
10253 T::CONSTRAINTS,
10254 <Kernel as super::ResolverKernel>::KIND,
10255 );
10256 let buffer = hasher.finalize();
10257 let fp =
10258 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10259 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10260 Ok(Certified::new(cert))
10261 }
10262 }
10263
10264 pub mod homotopy {
10282 use super::*;
10283
10284 #[doc(hidden)]
10285 pub struct Kernel;
10286 impl super::ResolverKernel for Kernel {
10287 type Cert = crate::enforcement::TransformCertificate;
10288 const KIND: crate::enforcement::CertificateKind =
10289 crate::enforcement::CertificateKind::Homotopy;
10290 }
10291
10292 pub fn certify<
10298 T: crate::pipeline::ConstrainedTypeShape,
10299 P: crate::enforcement::ValidationPhase,
10300 H: crate::enforcement::Hasher,
10301 >(
10302 input: &Validated<T, P>,
10303 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10304 {
10305 certify_at::<T, P, H>(input, WittLevel::W32)
10306 }
10307
10308 pub fn certify_at<
10314 T: crate::pipeline::ConstrainedTypeShape,
10315 P: crate::enforcement::ValidationPhase,
10316 H: crate::enforcement::Hasher,
10317 >(
10318 input: &Validated<T, P>,
10319 level: WittLevel,
10320 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10321 {
10322 let _ = input.inner();
10323 let witt_bits = level.witt_length() as u16;
10324 let (tr_bits, tr_constraints, tr_sat) =
10325 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10326 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10327 if tr_sat == 0 {
10328 return Err(Certified::new(GenericImpossibilityWitness::default()));
10329 }
10330 let mut hasher = H::initial();
10331 hasher = crate::enforcement::fold_terminal_reduction(
10332 hasher,
10333 tr_bits,
10334 tr_constraints,
10335 tr_sat,
10336 );
10337 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10338 .map_err(crate::enforcement::Certified::new)?;
10339 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
10340 hasher = crate::enforcement::fold_unit_digest(
10341 hasher,
10342 witt_bits,
10343 witt_bits as u64,
10344 T::IRI,
10345 T::SITE_COUNT,
10346 T::CONSTRAINTS,
10347 <Kernel as super::ResolverKernel>::KIND,
10348 );
10349 let buffer = hasher.finalize();
10350 let fp =
10351 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10352 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10353 Ok(Certified::new(cert))
10354 }
10355 }
10356
10357 pub mod monodromy {
10375 use super::*;
10376
10377 #[doc(hidden)]
10378 pub struct Kernel;
10379 impl super::ResolverKernel for Kernel {
10380 type Cert = crate::enforcement::IsometryCertificate;
10381 const KIND: crate::enforcement::CertificateKind =
10382 crate::enforcement::CertificateKind::Monodromy;
10383 }
10384
10385 pub fn certify<
10391 T: crate::pipeline::ConstrainedTypeShape,
10392 P: crate::enforcement::ValidationPhase,
10393 H: crate::enforcement::Hasher,
10394 >(
10395 input: &Validated<T, P>,
10396 ) -> Result<Certified<IsometryCertificate>, Certified<GenericImpossibilityWitness>>
10397 {
10398 certify_at::<T, P, H>(input, WittLevel::W32)
10399 }
10400
10401 pub fn certify_at<
10407 T: crate::pipeline::ConstrainedTypeShape,
10408 P: crate::enforcement::ValidationPhase,
10409 H: crate::enforcement::Hasher,
10410 >(
10411 input: &Validated<T, P>,
10412 level: WittLevel,
10413 ) -> Result<Certified<IsometryCertificate>, Certified<GenericImpossibilityWitness>>
10414 {
10415 let _ = input.inner();
10416 let witt_bits = level.witt_length() as u16;
10417 let (tr_bits, tr_constraints, tr_sat) =
10418 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10419 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10420 if tr_sat == 0 {
10421 return Err(Certified::new(GenericImpossibilityWitness::default()));
10422 }
10423 let mut hasher = H::initial();
10424 hasher = crate::enforcement::fold_terminal_reduction(
10425 hasher,
10426 tr_bits,
10427 tr_constraints,
10428 tr_sat,
10429 );
10430 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10431 .map_err(crate::enforcement::Certified::new)?;
10432 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
10433 let (orbit_size, representative) =
10434 crate::enforcement::primitive_dihedral_signature::<T>();
10435 hasher =
10436 crate::enforcement::fold_dihedral_signature(hasher, orbit_size, representative);
10437 hasher = crate::enforcement::fold_unit_digest(
10438 hasher,
10439 witt_bits,
10440 witt_bits as u64,
10441 T::IRI,
10442 T::SITE_COUNT,
10443 T::CONSTRAINTS,
10444 <Kernel as super::ResolverKernel>::KIND,
10445 );
10446 let buffer = hasher.finalize();
10447 let fp =
10448 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10449 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10450 Ok(Certified::new(cert))
10451 }
10452 }
10453
10454 pub mod moduli {
10472 use super::*;
10473
10474 #[doc(hidden)]
10475 pub struct Kernel;
10476 impl super::ResolverKernel for Kernel {
10477 type Cert = crate::enforcement::TransformCertificate;
10478 const KIND: crate::enforcement::CertificateKind =
10479 crate::enforcement::CertificateKind::Moduli;
10480 }
10481
10482 pub fn certify<
10488 T: crate::pipeline::ConstrainedTypeShape,
10489 P: crate::enforcement::ValidationPhase,
10490 H: crate::enforcement::Hasher,
10491 >(
10492 input: &Validated<T, P>,
10493 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10494 {
10495 certify_at::<T, P, H>(input, WittLevel::W32)
10496 }
10497
10498 pub fn certify_at<
10504 T: crate::pipeline::ConstrainedTypeShape,
10505 P: crate::enforcement::ValidationPhase,
10506 H: crate::enforcement::Hasher,
10507 >(
10508 input: &Validated<T, P>,
10509 level: WittLevel,
10510 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10511 {
10512 let _ = input.inner();
10513 let witt_bits = level.witt_length() as u16;
10514 let (tr_bits, tr_constraints, tr_sat) =
10515 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10516 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10517 if tr_sat == 0 {
10518 return Err(Certified::new(GenericImpossibilityWitness::default()));
10519 }
10520 let mut hasher = H::initial();
10521 hasher = crate::enforcement::fold_terminal_reduction(
10522 hasher,
10523 tr_bits,
10524 tr_constraints,
10525 tr_sat,
10526 );
10527 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10528 .map_err(crate::enforcement::Certified::new)?;
10529 let automorphisms: u32 = betti[0];
10530 let deformations: u32 = if crate::enforcement::MAX_BETTI_DIMENSION > 1 {
10531 betti[1]
10532 } else {
10533 0
10534 };
10535 let obstructions: u32 = if crate::enforcement::MAX_BETTI_DIMENSION > 2 {
10536 betti[2]
10537 } else {
10538 0
10539 };
10540 hasher = hasher.fold_bytes(&automorphisms.to_be_bytes());
10541 hasher = hasher.fold_bytes(&deformations.to_be_bytes());
10542 hasher = hasher.fold_bytes(&obstructions.to_be_bytes());
10543 hasher = crate::enforcement::fold_unit_digest(
10544 hasher,
10545 witt_bits,
10546 witt_bits as u64,
10547 T::IRI,
10548 T::SITE_COUNT,
10549 T::CONSTRAINTS,
10550 <Kernel as super::ResolverKernel>::KIND,
10551 );
10552 let buffer = hasher.finalize();
10553 let fp =
10554 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10555 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10556 Ok(Certified::new(cert))
10557 }
10558 }
10559
10560 pub mod jacobian_guided {
10578 use super::*;
10579
10580 #[doc(hidden)]
10581 pub struct Kernel;
10582 impl super::ResolverKernel for Kernel {
10583 type Cert = crate::enforcement::GroundingCertificate;
10584 const KIND: crate::enforcement::CertificateKind =
10585 crate::enforcement::CertificateKind::JacobianGuided;
10586 }
10587
10588 pub fn certify<
10594 T: crate::pipeline::ConstrainedTypeShape,
10595 P: crate::enforcement::ValidationPhase,
10596 H: crate::enforcement::Hasher,
10597 >(
10598 input: &Validated<T, P>,
10599 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10600 {
10601 certify_at::<T, P, H>(input, WittLevel::W32)
10602 }
10603
10604 pub fn certify_at<
10610 T: crate::pipeline::ConstrainedTypeShape,
10611 P: crate::enforcement::ValidationPhase,
10612 H: crate::enforcement::Hasher,
10613 >(
10614 input: &Validated<T, P>,
10615 level: WittLevel,
10616 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10617 {
10618 let _ = input.inner();
10619 let witt_bits = level.witt_length() as u16;
10620 let (tr_bits, tr_constraints, tr_sat) =
10621 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10622 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10623 if tr_sat == 0 {
10624 return Err(Certified::new(GenericImpossibilityWitness::default()));
10625 }
10626 let mut hasher = H::initial();
10627 hasher = crate::enforcement::fold_terminal_reduction(
10628 hasher,
10629 tr_bits,
10630 tr_constraints,
10631 tr_sat,
10632 );
10633 let jac = crate::enforcement::primitive_curvature_jacobian::<T>();
10634 hasher = crate::enforcement::fold_jacobian_profile(hasher, &jac);
10635 let selected_site = crate::enforcement::primitive_dc10_select(&jac);
10636 hasher = hasher.fold_bytes(&(selected_site as u32).to_be_bytes());
10637 hasher = crate::enforcement::fold_unit_digest(
10638 hasher,
10639 witt_bits,
10640 witt_bits as u64,
10641 T::IRI,
10642 T::SITE_COUNT,
10643 T::CONSTRAINTS,
10644 <Kernel as super::ResolverKernel>::KIND,
10645 );
10646 let buffer = hasher.finalize();
10647 let fp =
10648 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10649 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10650 Ok(Certified::new(cert))
10651 }
10652 }
10653
10654 pub mod evaluation {
10672 use super::*;
10673
10674 #[doc(hidden)]
10675 pub struct Kernel;
10676 impl super::ResolverKernel for Kernel {
10677 type Cert = crate::enforcement::GroundingCertificate;
10678 const KIND: crate::enforcement::CertificateKind =
10679 crate::enforcement::CertificateKind::Evaluation;
10680 }
10681
10682 pub fn certify<
10688 T: crate::pipeline::ConstrainedTypeShape,
10689 P: crate::enforcement::ValidationPhase,
10690 H: crate::enforcement::Hasher,
10691 >(
10692 input: &Validated<T, P>,
10693 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10694 {
10695 certify_at::<T, P, H>(input, WittLevel::W32)
10696 }
10697
10698 pub fn certify_at<
10704 T: crate::pipeline::ConstrainedTypeShape,
10705 P: crate::enforcement::ValidationPhase,
10706 H: crate::enforcement::Hasher,
10707 >(
10708 input: &Validated<T, P>,
10709 level: WittLevel,
10710 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10711 {
10712 let _ = input.inner();
10713 let witt_bits = level.witt_length() as u16;
10714 let (tr_bits, tr_constraints, tr_sat) =
10715 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10716 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10717 if tr_sat == 0 {
10718 return Err(Certified::new(GenericImpossibilityWitness::default()));
10719 }
10720 let mut hasher = H::initial();
10721 hasher = crate::enforcement::fold_terminal_reduction(
10722 hasher,
10723 tr_bits,
10724 tr_constraints,
10725 tr_sat,
10726 );
10727 hasher = crate::enforcement::fold_unit_digest(
10728 hasher,
10729 witt_bits,
10730 witt_bits as u64,
10731 T::IRI,
10732 T::SITE_COUNT,
10733 T::CONSTRAINTS,
10734 <Kernel as super::ResolverKernel>::KIND,
10735 );
10736 let buffer = hasher.finalize();
10737 let fp =
10738 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10739 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10740 Ok(Certified::new(cert))
10741 }
10742 }
10743
10744 pub mod session {
10762 use super::*;
10763
10764 #[doc(hidden)]
10765 pub struct Kernel;
10766 impl super::ResolverKernel for Kernel {
10767 type Cert = crate::enforcement::GroundingCertificate;
10768 const KIND: crate::enforcement::CertificateKind =
10769 crate::enforcement::CertificateKind::Session;
10770 }
10771
10772 pub fn certify<
10778 P: crate::enforcement::ValidationPhase,
10779 H: crate::enforcement::Hasher,
10780 const INLINE_BYTES: usize,
10781 >(
10782 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10783 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10784 {
10785 certify_at::<P, H, INLINE_BYTES>(input, WittLevel::W32)
10786 }
10787
10788 pub fn certify_at<
10794 P: crate::enforcement::ValidationPhase,
10795 H: crate::enforcement::Hasher,
10796 const INLINE_BYTES: usize,
10797 >(
10798 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10799 level: WittLevel,
10800 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10801 {
10802 let unit = input.inner();
10803 let witt_bits = level.witt_length() as u16;
10804 let budget = unit.thermodynamic_budget();
10805 let result_type_iri = unit.result_type_iri();
10806 let mut hasher = H::initial();
10807 let (binding_count, fold_addr) =
10808 crate::enforcement::primitive_session_binding_signature(unit.bindings());
10809 hasher = crate::enforcement::fold_session_signature(hasher, binding_count, fold_addr);
10810 hasher = crate::enforcement::fold_unit_digest(
10811 hasher,
10812 witt_bits,
10813 budget,
10814 result_type_iri,
10815 0usize,
10816 &[],
10817 <Kernel as super::ResolverKernel>::KIND,
10818 );
10819 let buffer = hasher.finalize();
10820 let fp =
10821 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10822 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10823 Ok(Certified::new(cert))
10824 }
10825 }
10826
10827 pub mod superposition {
10845 use super::*;
10846
10847 #[doc(hidden)]
10848 pub struct Kernel;
10849 impl super::ResolverKernel for Kernel {
10850 type Cert = crate::enforcement::BornRuleVerification;
10851 const KIND: crate::enforcement::CertificateKind =
10852 crate::enforcement::CertificateKind::Superposition;
10853 }
10854
10855 pub fn certify<
10861 P: crate::enforcement::ValidationPhase,
10862 H: crate::enforcement::Hasher,
10863 const INLINE_BYTES: usize,
10864 >(
10865 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10866 ) -> Result<Certified<BornRuleVerification>, Certified<GenericImpossibilityWitness>>
10867 {
10868 certify_at::<P, H, INLINE_BYTES>(input, WittLevel::W32)
10869 }
10870
10871 pub fn certify_at<
10877 P: crate::enforcement::ValidationPhase,
10878 H: crate::enforcement::Hasher,
10879 const INLINE_BYTES: usize,
10880 >(
10881 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10882 level: WittLevel,
10883 ) -> Result<Certified<BornRuleVerification>, Certified<GenericImpossibilityWitness>>
10884 {
10885 let unit = input.inner();
10886 let witt_bits = level.witt_length() as u16;
10887 let budget = unit.thermodynamic_budget();
10888 let result_type_iri = unit.result_type_iri();
10889 let mut hasher = H::initial();
10890 let (binding_count, fold_addr) =
10891 crate::enforcement::primitive_session_binding_signature(unit.bindings());
10892 hasher = crate::enforcement::fold_session_signature(hasher, binding_count, fold_addr);
10893 let (outcome_index, probability) =
10894 crate::enforcement::primitive_measurement_projection(budget);
10895 hasher = crate::enforcement::fold_born_outcome(hasher, outcome_index, probability);
10896 hasher = crate::enforcement::fold_unit_digest(
10897 hasher,
10898 witt_bits,
10899 budget,
10900 result_type_iri,
10901 0usize,
10902 &[],
10903 <Kernel as super::ResolverKernel>::KIND,
10904 );
10905 let buffer = hasher.finalize();
10906 let fp =
10907 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10908 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10909 Ok(Certified::new(cert))
10910 }
10911 }
10912
10913 pub mod measurement {
10931 use super::*;
10932
10933 #[doc(hidden)]
10934 pub struct Kernel;
10935 impl super::ResolverKernel for Kernel {
10936 type Cert = crate::enforcement::MeasurementCertificate;
10937 const KIND: crate::enforcement::CertificateKind =
10938 crate::enforcement::CertificateKind::Measurement;
10939 }
10940
10941 pub fn certify<
10947 P: crate::enforcement::ValidationPhase,
10948 H: crate::enforcement::Hasher,
10949 const INLINE_BYTES: usize,
10950 >(
10951 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10952 ) -> Result<Certified<MeasurementCertificate>, Certified<GenericImpossibilityWitness>>
10953 {
10954 certify_at::<P, H, INLINE_BYTES>(input, WittLevel::W32)
10955 }
10956
10957 pub fn certify_at<
10963 P: crate::enforcement::ValidationPhase,
10964 H: crate::enforcement::Hasher,
10965 const INLINE_BYTES: usize,
10966 >(
10967 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
10968 level: WittLevel,
10969 ) -> Result<Certified<MeasurementCertificate>, Certified<GenericImpossibilityWitness>>
10970 {
10971 let unit = input.inner();
10972 let witt_bits = level.witt_length() as u16;
10973 let budget = unit.thermodynamic_budget();
10974 let result_type_iri = unit.result_type_iri();
10975 let mut hasher = H::initial();
10976 let (outcome_index, probability) =
10977 crate::enforcement::primitive_measurement_projection(budget);
10978 hasher = crate::enforcement::fold_born_outcome(hasher, outcome_index, probability);
10979 hasher = crate::enforcement::fold_unit_digest(
10980 hasher,
10981 witt_bits,
10982 budget,
10983 result_type_iri,
10984 0usize,
10985 &[],
10986 <Kernel as super::ResolverKernel>::KIND,
10987 );
10988 let buffer = hasher.finalize();
10989 let fp =
10990 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10991 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10992 Ok(Certified::new(cert))
10993 }
10994 }
10995
10996 pub mod witt_level_resolver {
11014 use super::*;
11015
11016 #[doc(hidden)]
11017 pub struct Kernel;
11018 impl super::ResolverKernel for Kernel {
11019 type Cert = crate::enforcement::GroundingCertificate;
11020 const KIND: crate::enforcement::CertificateKind =
11021 crate::enforcement::CertificateKind::WittLevel;
11022 }
11023
11024 pub fn certify<
11030 P: crate::enforcement::ValidationPhase,
11031 H: crate::enforcement::Hasher,
11032 const INLINE_BYTES: usize,
11033 >(
11034 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
11035 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
11036 {
11037 certify_at::<P, H, INLINE_BYTES>(input, WittLevel::W32)
11038 }
11039
11040 pub fn certify_at<
11046 P: crate::enforcement::ValidationPhase,
11047 H: crate::enforcement::Hasher,
11048 const INLINE_BYTES: usize,
11049 >(
11050 input: &Validated<CompileUnit<'_, INLINE_BYTES>, P>,
11051 level: WittLevel,
11052 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
11053 {
11054 let unit = input.inner();
11055 let witt_bits = level.witt_length() as u16;
11056 let budget = unit.thermodynamic_budget();
11057 let result_type_iri = unit.result_type_iri();
11058 let mut hasher = H::initial();
11059 hasher = hasher.fold_bytes(&witt_bits.to_be_bytes());
11060 let declared_level_bits = unit.witt_level().witt_length() as u16;
11061 hasher = hasher.fold_bytes(&declared_level_bits.to_be_bytes());
11062 hasher = crate::enforcement::fold_unit_digest(
11063 hasher,
11064 witt_bits,
11065 budget,
11066 result_type_iri,
11067 0usize,
11068 &[],
11069 <Kernel as super::ResolverKernel>::KIND,
11070 );
11071 let buffer = hasher.finalize();
11072 let fp =
11073 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11074 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11075 Ok(Certified::new(cert))
11076 }
11077 }
11078
11079 pub mod dihedral_factorization {
11097 use super::*;
11098
11099 #[doc(hidden)]
11100 pub struct Kernel;
11101 impl super::ResolverKernel for Kernel {
11102 type Cert = crate::enforcement::InvolutionCertificate;
11103 const KIND: crate::enforcement::CertificateKind =
11104 crate::enforcement::CertificateKind::DihedralFactorization;
11105 }
11106
11107 pub fn certify<
11113 T: crate::pipeline::ConstrainedTypeShape,
11114 P: crate::enforcement::ValidationPhase,
11115 H: crate::enforcement::Hasher,
11116 >(
11117 input: &Validated<T, P>,
11118 ) -> Result<Certified<InvolutionCertificate>, Certified<GenericImpossibilityWitness>>
11119 {
11120 certify_at::<T, P, H>(input, WittLevel::W32)
11121 }
11122
11123 pub fn certify_at<
11129 T: crate::pipeline::ConstrainedTypeShape,
11130 P: crate::enforcement::ValidationPhase,
11131 H: crate::enforcement::Hasher,
11132 >(
11133 input: &Validated<T, P>,
11134 level: WittLevel,
11135 ) -> Result<Certified<InvolutionCertificate>, Certified<GenericImpossibilityWitness>>
11136 {
11137 let _ = input.inner();
11138 let witt_bits = level.witt_length() as u16;
11139 let (tr_bits, tr_constraints, tr_sat) =
11140 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
11141 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
11142 if tr_sat == 0 {
11143 return Err(Certified::new(GenericImpossibilityWitness::default()));
11144 }
11145 let mut hasher = H::initial();
11146 hasher = crate::enforcement::fold_terminal_reduction(
11147 hasher,
11148 tr_bits,
11149 tr_constraints,
11150 tr_sat,
11151 );
11152 let (orbit_size, representative) =
11153 crate::enforcement::primitive_dihedral_signature::<T>();
11154 hasher =
11155 crate::enforcement::fold_dihedral_signature(hasher, orbit_size, representative);
11156 hasher = crate::enforcement::fold_unit_digest(
11157 hasher,
11158 witt_bits,
11159 witt_bits as u64,
11160 T::IRI,
11161 T::SITE_COUNT,
11162 T::CONSTRAINTS,
11163 <Kernel as super::ResolverKernel>::KIND,
11164 );
11165 let buffer = hasher.finalize();
11166 let fp =
11167 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11168 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11169 Ok(Certified::new(cert))
11170 }
11171 }
11172
11173 pub mod completeness {
11191 use super::*;
11192
11193 #[doc(hidden)]
11194 pub struct Kernel;
11195 impl super::ResolverKernel for Kernel {
11196 type Cert = crate::enforcement::CompletenessCertificate;
11197 const KIND: crate::enforcement::CertificateKind =
11198 crate::enforcement::CertificateKind::Completeness;
11199 }
11200
11201 pub fn certify<
11207 T: crate::pipeline::ConstrainedTypeShape,
11208 P: crate::enforcement::ValidationPhase,
11209 H: crate::enforcement::Hasher,
11210 >(
11211 input: &Validated<T, P>,
11212 ) -> Result<Certified<CompletenessCertificate>, Certified<GenericImpossibilityWitness>>
11213 {
11214 certify_at::<T, P, H>(input, WittLevel::W32)
11215 }
11216
11217 pub fn certify_at<
11223 T: crate::pipeline::ConstrainedTypeShape,
11224 P: crate::enforcement::ValidationPhase,
11225 H: crate::enforcement::Hasher,
11226 >(
11227 input: &Validated<T, P>,
11228 level: WittLevel,
11229 ) -> Result<Certified<CompletenessCertificate>, Certified<GenericImpossibilityWitness>>
11230 {
11231 let _ = input.inner();
11232 let witt_bits = level.witt_length() as u16;
11233 let (tr_bits, tr_constraints, tr_sat) =
11234 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
11235 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
11236 if tr_sat == 0 {
11237 return Err(Certified::new(GenericImpossibilityWitness::default()));
11238 }
11239 let mut hasher = H::initial();
11240 hasher = crate::enforcement::fold_terminal_reduction(
11241 hasher,
11242 tr_bits,
11243 tr_constraints,
11244 tr_sat,
11245 );
11246 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
11247 .map_err(crate::enforcement::Certified::new)?;
11248 let chi = crate::enforcement::primitive_euler_characteristic(&betti);
11249 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
11250 hasher = hasher.fold_bytes(&chi.to_be_bytes());
11251 hasher = crate::enforcement::fold_unit_digest(
11252 hasher,
11253 witt_bits,
11254 witt_bits as u64,
11255 T::IRI,
11256 T::SITE_COUNT,
11257 T::CONSTRAINTS,
11258 <Kernel as super::ResolverKernel>::KIND,
11259 );
11260 let buffer = hasher.finalize();
11261 let fp =
11262 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11263 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11264 Ok(Certified::new(cert))
11265 }
11266 }
11267
11268 pub mod geodesic_validator {
11286 use super::*;
11287
11288 #[doc(hidden)]
11289 pub struct Kernel;
11290 impl super::ResolverKernel for Kernel {
11291 type Cert = crate::enforcement::GeodesicCertificate;
11292 const KIND: crate::enforcement::CertificateKind =
11293 crate::enforcement::CertificateKind::GeodesicValidator;
11294 }
11295
11296 pub fn certify<
11302 T: crate::pipeline::ConstrainedTypeShape,
11303 P: crate::enforcement::ValidationPhase,
11304 H: crate::enforcement::Hasher,
11305 >(
11306 input: &Validated<T, P>,
11307 ) -> Result<Certified<GeodesicCertificate>, Certified<GenericImpossibilityWitness>>
11308 {
11309 certify_at::<T, P, H>(input, WittLevel::W32)
11310 }
11311
11312 pub fn certify_at<
11318 T: crate::pipeline::ConstrainedTypeShape,
11319 P: crate::enforcement::ValidationPhase,
11320 H: crate::enforcement::Hasher,
11321 >(
11322 input: &Validated<T, P>,
11323 level: WittLevel,
11324 ) -> Result<Certified<GeodesicCertificate>, Certified<GenericImpossibilityWitness>>
11325 {
11326 let _ = input.inner();
11327 let witt_bits = level.witt_length() as u16;
11328 let (tr_bits, tr_constraints, tr_sat) =
11329 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
11330 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
11331 if tr_sat == 0 {
11332 return Err(Certified::new(GenericImpossibilityWitness::default()));
11333 }
11334 let mut hasher = H::initial();
11335 hasher = crate::enforcement::fold_terminal_reduction(
11336 hasher,
11337 tr_bits,
11338 tr_constraints,
11339 tr_sat,
11340 );
11341 let jac = crate::enforcement::primitive_curvature_jacobian::<T>();
11342 hasher = crate::enforcement::fold_jacobian_profile(hasher, &jac);
11343 let selected_site = crate::enforcement::primitive_dc10_select(&jac);
11344 hasher = hasher.fold_bytes(&(selected_site as u32).to_be_bytes());
11345 hasher = crate::enforcement::fold_unit_digest(
11346 hasher,
11347 witt_bits,
11348 witt_bits as u64,
11349 T::IRI,
11350 T::SITE_COUNT,
11351 T::CONSTRAINTS,
11352 <Kernel as super::ResolverKernel>::KIND,
11353 );
11354 let buffer = hasher.finalize();
11355 let fp =
11356 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11357 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11358 Ok(Certified::new(cert))
11359 }
11360 }
11361}
11362
11363pub trait RingOp<L> {
11367 type Operand;
11369 fn apply(a: Self::Operand, b: Self::Operand) -> Self::Operand;
11371}
11372
11373pub trait UnaryRingOp<L> {
11377 type Operand;
11379 fn apply(a: Self::Operand) -> Self::Operand;
11381}
11382
11383#[derive(Debug, Default, Clone, Copy)]
11385pub struct Mul<L>(PhantomData<L>);
11386
11387#[derive(Debug, Default, Clone, Copy)]
11389pub struct Add<L>(PhantomData<L>);
11390
11391#[derive(Debug, Default, Clone, Copy)]
11393pub struct Sub<L>(PhantomData<L>);
11394
11395#[derive(Debug, Default, Clone, Copy)]
11397pub struct Xor<L>(PhantomData<L>);
11398
11399#[derive(Debug, Default, Clone, Copy)]
11401pub struct And<L>(PhantomData<L>);
11402
11403#[derive(Debug, Default, Clone, Copy)]
11405pub struct Or<L>(PhantomData<L>);
11406
11407#[derive(Debug, Default, Clone, Copy)]
11409pub struct Neg<L>(PhantomData<L>);
11410
11411#[derive(Debug, Default, Clone, Copy)]
11413pub struct BNot<L>(PhantomData<L>);
11414
11415#[derive(Debug, Default, Clone, Copy)]
11417pub struct Succ<L>(PhantomData<L>);
11418
11419#[derive(Debug, Default, Clone, Copy)]
11421pub struct W8;
11422
11423#[derive(Debug, Default, Clone, Copy)]
11425pub struct W16;
11426
11427#[derive(Debug, Default, Clone, Copy)]
11429pub struct W24;
11430
11431#[derive(Debug, Default, Clone, Copy)]
11433pub struct W32;
11434
11435#[derive(Debug, Default, Clone, Copy)]
11437pub struct W40;
11438
11439#[derive(Debug, Default, Clone, Copy)]
11441pub struct W48;
11442
11443#[derive(Debug, Default, Clone, Copy)]
11445pub struct W56;
11446
11447#[derive(Debug, Default, Clone, Copy)]
11449pub struct W64;
11450
11451#[derive(Debug, Default, Clone, Copy)]
11453pub struct W72;
11454
11455#[derive(Debug, Default, Clone, Copy)]
11457pub struct W80;
11458
11459#[derive(Debug, Default, Clone, Copy)]
11461pub struct W88;
11462
11463#[derive(Debug, Default, Clone, Copy)]
11465pub struct W96;
11466
11467#[derive(Debug, Default, Clone, Copy)]
11469pub struct W104;
11470
11471#[derive(Debug, Default, Clone, Copy)]
11473pub struct W112;
11474
11475#[derive(Debug, Default, Clone, Copy)]
11477pub struct W120;
11478
11479#[derive(Debug, Default, Clone, Copy)]
11481pub struct W128;
11482
11483impl RingOp<W8> for Mul<W8> {
11484 type Operand = u8;
11485 #[inline]
11486 fn apply(a: u8, b: u8) -> u8 {
11487 const_ring_eval_w8(PrimitiveOp::Mul, a, b)
11488 }
11489}
11490
11491impl RingOp<W8> for Add<W8> {
11492 type Operand = u8;
11493 #[inline]
11494 fn apply(a: u8, b: u8) -> u8 {
11495 const_ring_eval_w8(PrimitiveOp::Add, a, b)
11496 }
11497}
11498
11499impl RingOp<W8> for Sub<W8> {
11500 type Operand = u8;
11501 #[inline]
11502 fn apply(a: u8, b: u8) -> u8 {
11503 const_ring_eval_w8(PrimitiveOp::Sub, a, b)
11504 }
11505}
11506
11507impl RingOp<W8> for Xor<W8> {
11508 type Operand = u8;
11509 #[inline]
11510 fn apply(a: u8, b: u8) -> u8 {
11511 const_ring_eval_w8(PrimitiveOp::Xor, a, b)
11512 }
11513}
11514
11515impl RingOp<W8> for And<W8> {
11516 type Operand = u8;
11517 #[inline]
11518 fn apply(a: u8, b: u8) -> u8 {
11519 const_ring_eval_w8(PrimitiveOp::And, a, b)
11520 }
11521}
11522
11523impl RingOp<W8> for Or<W8> {
11524 type Operand = u8;
11525 #[inline]
11526 fn apply(a: u8, b: u8) -> u8 {
11527 const_ring_eval_w8(PrimitiveOp::Or, a, b)
11528 }
11529}
11530
11531impl RingOp<W16> for Mul<W16> {
11532 type Operand = u16;
11533 #[inline]
11534 fn apply(a: u16, b: u16) -> u16 {
11535 const_ring_eval_w16(PrimitiveOp::Mul, a, b)
11536 }
11537}
11538
11539impl RingOp<W16> for Add<W16> {
11540 type Operand = u16;
11541 #[inline]
11542 fn apply(a: u16, b: u16) -> u16 {
11543 const_ring_eval_w16(PrimitiveOp::Add, a, b)
11544 }
11545}
11546
11547impl RingOp<W16> for Sub<W16> {
11548 type Operand = u16;
11549 #[inline]
11550 fn apply(a: u16, b: u16) -> u16 {
11551 const_ring_eval_w16(PrimitiveOp::Sub, a, b)
11552 }
11553}
11554
11555impl RingOp<W16> for Xor<W16> {
11556 type Operand = u16;
11557 #[inline]
11558 fn apply(a: u16, b: u16) -> u16 {
11559 const_ring_eval_w16(PrimitiveOp::Xor, a, b)
11560 }
11561}
11562
11563impl RingOp<W16> for And<W16> {
11564 type Operand = u16;
11565 #[inline]
11566 fn apply(a: u16, b: u16) -> u16 {
11567 const_ring_eval_w16(PrimitiveOp::And, a, b)
11568 }
11569}
11570
11571impl RingOp<W16> for Or<W16> {
11572 type Operand = u16;
11573 #[inline]
11574 fn apply(a: u16, b: u16) -> u16 {
11575 const_ring_eval_w16(PrimitiveOp::Or, a, b)
11576 }
11577}
11578
11579impl RingOp<W24> for Mul<W24> {
11580 type Operand = u32;
11581 #[inline]
11582 fn apply(a: u32, b: u32) -> u32 {
11583 const_ring_eval_w24(PrimitiveOp::Mul, a, b)
11584 }
11585}
11586
11587impl RingOp<W24> for Add<W24> {
11588 type Operand = u32;
11589 #[inline]
11590 fn apply(a: u32, b: u32) -> u32 {
11591 const_ring_eval_w24(PrimitiveOp::Add, a, b)
11592 }
11593}
11594
11595impl RingOp<W24> for Sub<W24> {
11596 type Operand = u32;
11597 #[inline]
11598 fn apply(a: u32, b: u32) -> u32 {
11599 const_ring_eval_w24(PrimitiveOp::Sub, a, b)
11600 }
11601}
11602
11603impl RingOp<W24> for Xor<W24> {
11604 type Operand = u32;
11605 #[inline]
11606 fn apply(a: u32, b: u32) -> u32 {
11607 const_ring_eval_w24(PrimitiveOp::Xor, a, b)
11608 }
11609}
11610
11611impl RingOp<W24> for And<W24> {
11612 type Operand = u32;
11613 #[inline]
11614 fn apply(a: u32, b: u32) -> u32 {
11615 const_ring_eval_w24(PrimitiveOp::And, a, b)
11616 }
11617}
11618
11619impl RingOp<W24> for Or<W24> {
11620 type Operand = u32;
11621 #[inline]
11622 fn apply(a: u32, b: u32) -> u32 {
11623 const_ring_eval_w24(PrimitiveOp::Or, a, b)
11624 }
11625}
11626
11627impl RingOp<W32> for Mul<W32> {
11628 type Operand = u32;
11629 #[inline]
11630 fn apply(a: u32, b: u32) -> u32 {
11631 const_ring_eval_w32(PrimitiveOp::Mul, a, b)
11632 }
11633}
11634
11635impl RingOp<W32> for Add<W32> {
11636 type Operand = u32;
11637 #[inline]
11638 fn apply(a: u32, b: u32) -> u32 {
11639 const_ring_eval_w32(PrimitiveOp::Add, a, b)
11640 }
11641}
11642
11643impl RingOp<W32> for Sub<W32> {
11644 type Operand = u32;
11645 #[inline]
11646 fn apply(a: u32, b: u32) -> u32 {
11647 const_ring_eval_w32(PrimitiveOp::Sub, a, b)
11648 }
11649}
11650
11651impl RingOp<W32> for Xor<W32> {
11652 type Operand = u32;
11653 #[inline]
11654 fn apply(a: u32, b: u32) -> u32 {
11655 const_ring_eval_w32(PrimitiveOp::Xor, a, b)
11656 }
11657}
11658
11659impl RingOp<W32> for And<W32> {
11660 type Operand = u32;
11661 #[inline]
11662 fn apply(a: u32, b: u32) -> u32 {
11663 const_ring_eval_w32(PrimitiveOp::And, a, b)
11664 }
11665}
11666
11667impl RingOp<W32> for Or<W32> {
11668 type Operand = u32;
11669 #[inline]
11670 fn apply(a: u32, b: u32) -> u32 {
11671 const_ring_eval_w32(PrimitiveOp::Or, a, b)
11672 }
11673}
11674
11675impl RingOp<W40> for Mul<W40> {
11676 type Operand = u64;
11677 #[inline]
11678 fn apply(a: u64, b: u64) -> u64 {
11679 const_ring_eval_w40(PrimitiveOp::Mul, a, b)
11680 }
11681}
11682
11683impl RingOp<W40> for Add<W40> {
11684 type Operand = u64;
11685 #[inline]
11686 fn apply(a: u64, b: u64) -> u64 {
11687 const_ring_eval_w40(PrimitiveOp::Add, a, b)
11688 }
11689}
11690
11691impl RingOp<W40> for Sub<W40> {
11692 type Operand = u64;
11693 #[inline]
11694 fn apply(a: u64, b: u64) -> u64 {
11695 const_ring_eval_w40(PrimitiveOp::Sub, a, b)
11696 }
11697}
11698
11699impl RingOp<W40> for Xor<W40> {
11700 type Operand = u64;
11701 #[inline]
11702 fn apply(a: u64, b: u64) -> u64 {
11703 const_ring_eval_w40(PrimitiveOp::Xor, a, b)
11704 }
11705}
11706
11707impl RingOp<W40> for And<W40> {
11708 type Operand = u64;
11709 #[inline]
11710 fn apply(a: u64, b: u64) -> u64 {
11711 const_ring_eval_w40(PrimitiveOp::And, a, b)
11712 }
11713}
11714
11715impl RingOp<W40> for Or<W40> {
11716 type Operand = u64;
11717 #[inline]
11718 fn apply(a: u64, b: u64) -> u64 {
11719 const_ring_eval_w40(PrimitiveOp::Or, a, b)
11720 }
11721}
11722
11723impl RingOp<W48> for Mul<W48> {
11724 type Operand = u64;
11725 #[inline]
11726 fn apply(a: u64, b: u64) -> u64 {
11727 const_ring_eval_w48(PrimitiveOp::Mul, a, b)
11728 }
11729}
11730
11731impl RingOp<W48> for Add<W48> {
11732 type Operand = u64;
11733 #[inline]
11734 fn apply(a: u64, b: u64) -> u64 {
11735 const_ring_eval_w48(PrimitiveOp::Add, a, b)
11736 }
11737}
11738
11739impl RingOp<W48> for Sub<W48> {
11740 type Operand = u64;
11741 #[inline]
11742 fn apply(a: u64, b: u64) -> u64 {
11743 const_ring_eval_w48(PrimitiveOp::Sub, a, b)
11744 }
11745}
11746
11747impl RingOp<W48> for Xor<W48> {
11748 type Operand = u64;
11749 #[inline]
11750 fn apply(a: u64, b: u64) -> u64 {
11751 const_ring_eval_w48(PrimitiveOp::Xor, a, b)
11752 }
11753}
11754
11755impl RingOp<W48> for And<W48> {
11756 type Operand = u64;
11757 #[inline]
11758 fn apply(a: u64, b: u64) -> u64 {
11759 const_ring_eval_w48(PrimitiveOp::And, a, b)
11760 }
11761}
11762
11763impl RingOp<W48> for Or<W48> {
11764 type Operand = u64;
11765 #[inline]
11766 fn apply(a: u64, b: u64) -> u64 {
11767 const_ring_eval_w48(PrimitiveOp::Or, a, b)
11768 }
11769}
11770
11771impl RingOp<W56> for Mul<W56> {
11772 type Operand = u64;
11773 #[inline]
11774 fn apply(a: u64, b: u64) -> u64 {
11775 const_ring_eval_w56(PrimitiveOp::Mul, a, b)
11776 }
11777}
11778
11779impl RingOp<W56> for Add<W56> {
11780 type Operand = u64;
11781 #[inline]
11782 fn apply(a: u64, b: u64) -> u64 {
11783 const_ring_eval_w56(PrimitiveOp::Add, a, b)
11784 }
11785}
11786
11787impl RingOp<W56> for Sub<W56> {
11788 type Operand = u64;
11789 #[inline]
11790 fn apply(a: u64, b: u64) -> u64 {
11791 const_ring_eval_w56(PrimitiveOp::Sub, a, b)
11792 }
11793}
11794
11795impl RingOp<W56> for Xor<W56> {
11796 type Operand = u64;
11797 #[inline]
11798 fn apply(a: u64, b: u64) -> u64 {
11799 const_ring_eval_w56(PrimitiveOp::Xor, a, b)
11800 }
11801}
11802
11803impl RingOp<W56> for And<W56> {
11804 type Operand = u64;
11805 #[inline]
11806 fn apply(a: u64, b: u64) -> u64 {
11807 const_ring_eval_w56(PrimitiveOp::And, a, b)
11808 }
11809}
11810
11811impl RingOp<W56> for Or<W56> {
11812 type Operand = u64;
11813 #[inline]
11814 fn apply(a: u64, b: u64) -> u64 {
11815 const_ring_eval_w56(PrimitiveOp::Or, a, b)
11816 }
11817}
11818
11819impl RingOp<W64> for Mul<W64> {
11820 type Operand = u64;
11821 #[inline]
11822 fn apply(a: u64, b: u64) -> u64 {
11823 const_ring_eval_w64(PrimitiveOp::Mul, a, b)
11824 }
11825}
11826
11827impl RingOp<W64> for Add<W64> {
11828 type Operand = u64;
11829 #[inline]
11830 fn apply(a: u64, b: u64) -> u64 {
11831 const_ring_eval_w64(PrimitiveOp::Add, a, b)
11832 }
11833}
11834
11835impl RingOp<W64> for Sub<W64> {
11836 type Operand = u64;
11837 #[inline]
11838 fn apply(a: u64, b: u64) -> u64 {
11839 const_ring_eval_w64(PrimitiveOp::Sub, a, b)
11840 }
11841}
11842
11843impl RingOp<W64> for Xor<W64> {
11844 type Operand = u64;
11845 #[inline]
11846 fn apply(a: u64, b: u64) -> u64 {
11847 const_ring_eval_w64(PrimitiveOp::Xor, a, b)
11848 }
11849}
11850
11851impl RingOp<W64> for And<W64> {
11852 type Operand = u64;
11853 #[inline]
11854 fn apply(a: u64, b: u64) -> u64 {
11855 const_ring_eval_w64(PrimitiveOp::And, a, b)
11856 }
11857}
11858
11859impl RingOp<W64> for Or<W64> {
11860 type Operand = u64;
11861 #[inline]
11862 fn apply(a: u64, b: u64) -> u64 {
11863 const_ring_eval_w64(PrimitiveOp::Or, a, b)
11864 }
11865}
11866
11867impl RingOp<W72> for Mul<W72> {
11868 type Operand = u128;
11869 #[inline]
11870 fn apply(a: u128, b: u128) -> u128 {
11871 const_ring_eval_w72(PrimitiveOp::Mul, a, b)
11872 }
11873}
11874
11875impl RingOp<W72> for Add<W72> {
11876 type Operand = u128;
11877 #[inline]
11878 fn apply(a: u128, b: u128) -> u128 {
11879 const_ring_eval_w72(PrimitiveOp::Add, a, b)
11880 }
11881}
11882
11883impl RingOp<W72> for Sub<W72> {
11884 type Operand = u128;
11885 #[inline]
11886 fn apply(a: u128, b: u128) -> u128 {
11887 const_ring_eval_w72(PrimitiveOp::Sub, a, b)
11888 }
11889}
11890
11891impl RingOp<W72> for Xor<W72> {
11892 type Operand = u128;
11893 #[inline]
11894 fn apply(a: u128, b: u128) -> u128 {
11895 const_ring_eval_w72(PrimitiveOp::Xor, a, b)
11896 }
11897}
11898
11899impl RingOp<W72> for And<W72> {
11900 type Operand = u128;
11901 #[inline]
11902 fn apply(a: u128, b: u128) -> u128 {
11903 const_ring_eval_w72(PrimitiveOp::And, a, b)
11904 }
11905}
11906
11907impl RingOp<W72> for Or<W72> {
11908 type Operand = u128;
11909 #[inline]
11910 fn apply(a: u128, b: u128) -> u128 {
11911 const_ring_eval_w72(PrimitiveOp::Or, a, b)
11912 }
11913}
11914
11915impl RingOp<W80> for Mul<W80> {
11916 type Operand = u128;
11917 #[inline]
11918 fn apply(a: u128, b: u128) -> u128 {
11919 const_ring_eval_w80(PrimitiveOp::Mul, a, b)
11920 }
11921}
11922
11923impl RingOp<W80> for Add<W80> {
11924 type Operand = u128;
11925 #[inline]
11926 fn apply(a: u128, b: u128) -> u128 {
11927 const_ring_eval_w80(PrimitiveOp::Add, a, b)
11928 }
11929}
11930
11931impl RingOp<W80> for Sub<W80> {
11932 type Operand = u128;
11933 #[inline]
11934 fn apply(a: u128, b: u128) -> u128 {
11935 const_ring_eval_w80(PrimitiveOp::Sub, a, b)
11936 }
11937}
11938
11939impl RingOp<W80> for Xor<W80> {
11940 type Operand = u128;
11941 #[inline]
11942 fn apply(a: u128, b: u128) -> u128 {
11943 const_ring_eval_w80(PrimitiveOp::Xor, a, b)
11944 }
11945}
11946
11947impl RingOp<W80> for And<W80> {
11948 type Operand = u128;
11949 #[inline]
11950 fn apply(a: u128, b: u128) -> u128 {
11951 const_ring_eval_w80(PrimitiveOp::And, a, b)
11952 }
11953}
11954
11955impl RingOp<W80> for Or<W80> {
11956 type Operand = u128;
11957 #[inline]
11958 fn apply(a: u128, b: u128) -> u128 {
11959 const_ring_eval_w80(PrimitiveOp::Or, a, b)
11960 }
11961}
11962
11963impl RingOp<W88> for Mul<W88> {
11964 type Operand = u128;
11965 #[inline]
11966 fn apply(a: u128, b: u128) -> u128 {
11967 const_ring_eval_w88(PrimitiveOp::Mul, a, b)
11968 }
11969}
11970
11971impl RingOp<W88> for Add<W88> {
11972 type Operand = u128;
11973 #[inline]
11974 fn apply(a: u128, b: u128) -> u128 {
11975 const_ring_eval_w88(PrimitiveOp::Add, a, b)
11976 }
11977}
11978
11979impl RingOp<W88> for Sub<W88> {
11980 type Operand = u128;
11981 #[inline]
11982 fn apply(a: u128, b: u128) -> u128 {
11983 const_ring_eval_w88(PrimitiveOp::Sub, a, b)
11984 }
11985}
11986
11987impl RingOp<W88> for Xor<W88> {
11988 type Operand = u128;
11989 #[inline]
11990 fn apply(a: u128, b: u128) -> u128 {
11991 const_ring_eval_w88(PrimitiveOp::Xor, a, b)
11992 }
11993}
11994
11995impl RingOp<W88> for And<W88> {
11996 type Operand = u128;
11997 #[inline]
11998 fn apply(a: u128, b: u128) -> u128 {
11999 const_ring_eval_w88(PrimitiveOp::And, a, b)
12000 }
12001}
12002
12003impl RingOp<W88> for Or<W88> {
12004 type Operand = u128;
12005 #[inline]
12006 fn apply(a: u128, b: u128) -> u128 {
12007 const_ring_eval_w88(PrimitiveOp::Or, a, b)
12008 }
12009}
12010
12011impl RingOp<W96> for Mul<W96> {
12012 type Operand = u128;
12013 #[inline]
12014 fn apply(a: u128, b: u128) -> u128 {
12015 const_ring_eval_w96(PrimitiveOp::Mul, a, b)
12016 }
12017}
12018
12019impl RingOp<W96> for Add<W96> {
12020 type Operand = u128;
12021 #[inline]
12022 fn apply(a: u128, b: u128) -> u128 {
12023 const_ring_eval_w96(PrimitiveOp::Add, a, b)
12024 }
12025}
12026
12027impl RingOp<W96> for Sub<W96> {
12028 type Operand = u128;
12029 #[inline]
12030 fn apply(a: u128, b: u128) -> u128 {
12031 const_ring_eval_w96(PrimitiveOp::Sub, a, b)
12032 }
12033}
12034
12035impl RingOp<W96> for Xor<W96> {
12036 type Operand = u128;
12037 #[inline]
12038 fn apply(a: u128, b: u128) -> u128 {
12039 const_ring_eval_w96(PrimitiveOp::Xor, a, b)
12040 }
12041}
12042
12043impl RingOp<W96> for And<W96> {
12044 type Operand = u128;
12045 #[inline]
12046 fn apply(a: u128, b: u128) -> u128 {
12047 const_ring_eval_w96(PrimitiveOp::And, a, b)
12048 }
12049}
12050
12051impl RingOp<W96> for Or<W96> {
12052 type Operand = u128;
12053 #[inline]
12054 fn apply(a: u128, b: u128) -> u128 {
12055 const_ring_eval_w96(PrimitiveOp::Or, a, b)
12056 }
12057}
12058
12059impl RingOp<W104> for Mul<W104> {
12060 type Operand = u128;
12061 #[inline]
12062 fn apply(a: u128, b: u128) -> u128 {
12063 const_ring_eval_w104(PrimitiveOp::Mul, a, b)
12064 }
12065}
12066
12067impl RingOp<W104> for Add<W104> {
12068 type Operand = u128;
12069 #[inline]
12070 fn apply(a: u128, b: u128) -> u128 {
12071 const_ring_eval_w104(PrimitiveOp::Add, a, b)
12072 }
12073}
12074
12075impl RingOp<W104> for Sub<W104> {
12076 type Operand = u128;
12077 #[inline]
12078 fn apply(a: u128, b: u128) -> u128 {
12079 const_ring_eval_w104(PrimitiveOp::Sub, a, b)
12080 }
12081}
12082
12083impl RingOp<W104> for Xor<W104> {
12084 type Operand = u128;
12085 #[inline]
12086 fn apply(a: u128, b: u128) -> u128 {
12087 const_ring_eval_w104(PrimitiveOp::Xor, a, b)
12088 }
12089}
12090
12091impl RingOp<W104> for And<W104> {
12092 type Operand = u128;
12093 #[inline]
12094 fn apply(a: u128, b: u128) -> u128 {
12095 const_ring_eval_w104(PrimitiveOp::And, a, b)
12096 }
12097}
12098
12099impl RingOp<W104> for Or<W104> {
12100 type Operand = u128;
12101 #[inline]
12102 fn apply(a: u128, b: u128) -> u128 {
12103 const_ring_eval_w104(PrimitiveOp::Or, a, b)
12104 }
12105}
12106
12107impl RingOp<W112> for Mul<W112> {
12108 type Operand = u128;
12109 #[inline]
12110 fn apply(a: u128, b: u128) -> u128 {
12111 const_ring_eval_w112(PrimitiveOp::Mul, a, b)
12112 }
12113}
12114
12115impl RingOp<W112> for Add<W112> {
12116 type Operand = u128;
12117 #[inline]
12118 fn apply(a: u128, b: u128) -> u128 {
12119 const_ring_eval_w112(PrimitiveOp::Add, a, b)
12120 }
12121}
12122
12123impl RingOp<W112> for Sub<W112> {
12124 type Operand = u128;
12125 #[inline]
12126 fn apply(a: u128, b: u128) -> u128 {
12127 const_ring_eval_w112(PrimitiveOp::Sub, a, b)
12128 }
12129}
12130
12131impl RingOp<W112> for Xor<W112> {
12132 type Operand = u128;
12133 #[inline]
12134 fn apply(a: u128, b: u128) -> u128 {
12135 const_ring_eval_w112(PrimitiveOp::Xor, a, b)
12136 }
12137}
12138
12139impl RingOp<W112> for And<W112> {
12140 type Operand = u128;
12141 #[inline]
12142 fn apply(a: u128, b: u128) -> u128 {
12143 const_ring_eval_w112(PrimitiveOp::And, a, b)
12144 }
12145}
12146
12147impl RingOp<W112> for Or<W112> {
12148 type Operand = u128;
12149 #[inline]
12150 fn apply(a: u128, b: u128) -> u128 {
12151 const_ring_eval_w112(PrimitiveOp::Or, a, b)
12152 }
12153}
12154
12155impl RingOp<W120> for Mul<W120> {
12156 type Operand = u128;
12157 #[inline]
12158 fn apply(a: u128, b: u128) -> u128 {
12159 const_ring_eval_w120(PrimitiveOp::Mul, a, b)
12160 }
12161}
12162
12163impl RingOp<W120> for Add<W120> {
12164 type Operand = u128;
12165 #[inline]
12166 fn apply(a: u128, b: u128) -> u128 {
12167 const_ring_eval_w120(PrimitiveOp::Add, a, b)
12168 }
12169}
12170
12171impl RingOp<W120> for Sub<W120> {
12172 type Operand = u128;
12173 #[inline]
12174 fn apply(a: u128, b: u128) -> u128 {
12175 const_ring_eval_w120(PrimitiveOp::Sub, a, b)
12176 }
12177}
12178
12179impl RingOp<W120> for Xor<W120> {
12180 type Operand = u128;
12181 #[inline]
12182 fn apply(a: u128, b: u128) -> u128 {
12183 const_ring_eval_w120(PrimitiveOp::Xor, a, b)
12184 }
12185}
12186
12187impl RingOp<W120> for And<W120> {
12188 type Operand = u128;
12189 #[inline]
12190 fn apply(a: u128, b: u128) -> u128 {
12191 const_ring_eval_w120(PrimitiveOp::And, a, b)
12192 }
12193}
12194
12195impl RingOp<W120> for Or<W120> {
12196 type Operand = u128;
12197 #[inline]
12198 fn apply(a: u128, b: u128) -> u128 {
12199 const_ring_eval_w120(PrimitiveOp::Or, a, b)
12200 }
12201}
12202
12203impl RingOp<W128> for Mul<W128> {
12204 type Operand = u128;
12205 #[inline]
12206 fn apply(a: u128, b: u128) -> u128 {
12207 const_ring_eval_w128(PrimitiveOp::Mul, a, b)
12208 }
12209}
12210
12211impl RingOp<W128> for Add<W128> {
12212 type Operand = u128;
12213 #[inline]
12214 fn apply(a: u128, b: u128) -> u128 {
12215 const_ring_eval_w128(PrimitiveOp::Add, a, b)
12216 }
12217}
12218
12219impl RingOp<W128> for Sub<W128> {
12220 type Operand = u128;
12221 #[inline]
12222 fn apply(a: u128, b: u128) -> u128 {
12223 const_ring_eval_w128(PrimitiveOp::Sub, a, b)
12224 }
12225}
12226
12227impl RingOp<W128> for Xor<W128> {
12228 type Operand = u128;
12229 #[inline]
12230 fn apply(a: u128, b: u128) -> u128 {
12231 const_ring_eval_w128(PrimitiveOp::Xor, a, b)
12232 }
12233}
12234
12235impl RingOp<W128> for And<W128> {
12236 type Operand = u128;
12237 #[inline]
12238 fn apply(a: u128, b: u128) -> u128 {
12239 const_ring_eval_w128(PrimitiveOp::And, a, b)
12240 }
12241}
12242
12243impl RingOp<W128> for Or<W128> {
12244 type Operand = u128;
12245 #[inline]
12246 fn apply(a: u128, b: u128) -> u128 {
12247 const_ring_eval_w128(PrimitiveOp::Or, a, b)
12248 }
12249}
12250
12251impl UnaryRingOp<W8> for Neg<W8> {
12252 type Operand = u8;
12253 #[inline]
12254 fn apply(a: u8) -> u8 {
12255 const_ring_eval_w8(PrimitiveOp::Sub, 0, a)
12256 }
12257}
12258
12259impl UnaryRingOp<W8> for BNot<W8> {
12260 type Operand = u8;
12261 #[inline]
12262 fn apply(a: u8) -> u8 {
12263 const_ring_eval_w8(PrimitiveOp::Xor, a, u8::MAX)
12264 }
12265}
12266
12267impl UnaryRingOp<W8> for Succ<W8> {
12268 type Operand = u8;
12269 #[inline]
12270 fn apply(a: u8) -> u8 {
12271 <Neg<W8> as UnaryRingOp<W8>>::apply(<BNot<W8> as UnaryRingOp<W8>>::apply(a))
12272 }
12273}
12274
12275impl UnaryRingOp<W16> for Neg<W16> {
12276 type Operand = u16;
12277 #[inline]
12278 fn apply(a: u16) -> u16 {
12279 const_ring_eval_w16(PrimitiveOp::Sub, 0, a)
12280 }
12281}
12282
12283impl UnaryRingOp<W16> for BNot<W16> {
12284 type Operand = u16;
12285 #[inline]
12286 fn apply(a: u16) -> u16 {
12287 const_ring_eval_w16(PrimitiveOp::Xor, a, u16::MAX)
12288 }
12289}
12290
12291impl UnaryRingOp<W16> for Succ<W16> {
12292 type Operand = u16;
12293 #[inline]
12294 fn apply(a: u16) -> u16 {
12295 <Neg<W16> as UnaryRingOp<W16>>::apply(<BNot<W16> as UnaryRingOp<W16>>::apply(a))
12296 }
12297}
12298
12299impl UnaryRingOp<W24> for Neg<W24> {
12300 type Operand = u32;
12301 #[inline]
12302 fn apply(a: u32) -> u32 {
12303 const_ring_eval_w24(PrimitiveOp::Sub, 0, a)
12304 }
12305}
12306
12307impl UnaryRingOp<W24> for BNot<W24> {
12308 type Operand = u32;
12309 #[inline]
12310 fn apply(a: u32) -> u32 {
12311 const_ring_eval_w24(PrimitiveOp::Xor, a, 0x00FF_FFFFu32)
12312 }
12313}
12314
12315impl UnaryRingOp<W24> for Succ<W24> {
12316 type Operand = u32;
12317 #[inline]
12318 fn apply(a: u32) -> u32 {
12319 <Neg<W24> as UnaryRingOp<W24>>::apply(<BNot<W24> as UnaryRingOp<W24>>::apply(a))
12320 }
12321}
12322
12323impl UnaryRingOp<W32> for Neg<W32> {
12324 type Operand = u32;
12325 #[inline]
12326 fn apply(a: u32) -> u32 {
12327 const_ring_eval_w32(PrimitiveOp::Sub, 0, a)
12328 }
12329}
12330
12331impl UnaryRingOp<W32> for BNot<W32> {
12332 type Operand = u32;
12333 #[inline]
12334 fn apply(a: u32) -> u32 {
12335 const_ring_eval_w32(PrimitiveOp::Xor, a, u32::MAX)
12336 }
12337}
12338
12339impl UnaryRingOp<W32> for Succ<W32> {
12340 type Operand = u32;
12341 #[inline]
12342 fn apply(a: u32) -> u32 {
12343 <Neg<W32> as UnaryRingOp<W32>>::apply(<BNot<W32> as UnaryRingOp<W32>>::apply(a))
12344 }
12345}
12346
12347impl UnaryRingOp<W40> for Neg<W40> {
12348 type Operand = u64;
12349 #[inline]
12350 fn apply(a: u64) -> u64 {
12351 const_ring_eval_w40(PrimitiveOp::Sub, 0, a)
12352 }
12353}
12354
12355impl UnaryRingOp<W40> for BNot<W40> {
12356 type Operand = u64;
12357 #[inline]
12358 fn apply(a: u64) -> u64 {
12359 const_ring_eval_w40(PrimitiveOp::Xor, a, 0x0000_00FF_FFFF_FFFFu64)
12360 }
12361}
12362
12363impl UnaryRingOp<W40> for Succ<W40> {
12364 type Operand = u64;
12365 #[inline]
12366 fn apply(a: u64) -> u64 {
12367 <Neg<W40> as UnaryRingOp<W40>>::apply(<BNot<W40> as UnaryRingOp<W40>>::apply(a))
12368 }
12369}
12370
12371impl UnaryRingOp<W48> for Neg<W48> {
12372 type Operand = u64;
12373 #[inline]
12374 fn apply(a: u64) -> u64 {
12375 const_ring_eval_w48(PrimitiveOp::Sub, 0, a)
12376 }
12377}
12378
12379impl UnaryRingOp<W48> for BNot<W48> {
12380 type Operand = u64;
12381 #[inline]
12382 fn apply(a: u64) -> u64 {
12383 const_ring_eval_w48(PrimitiveOp::Xor, a, 0x0000_FFFF_FFFF_FFFFu64)
12384 }
12385}
12386
12387impl UnaryRingOp<W48> for Succ<W48> {
12388 type Operand = u64;
12389 #[inline]
12390 fn apply(a: u64) -> u64 {
12391 <Neg<W48> as UnaryRingOp<W48>>::apply(<BNot<W48> as UnaryRingOp<W48>>::apply(a))
12392 }
12393}
12394
12395impl UnaryRingOp<W56> for Neg<W56> {
12396 type Operand = u64;
12397 #[inline]
12398 fn apply(a: u64) -> u64 {
12399 const_ring_eval_w56(PrimitiveOp::Sub, 0, a)
12400 }
12401}
12402
12403impl UnaryRingOp<W56> for BNot<W56> {
12404 type Operand = u64;
12405 #[inline]
12406 fn apply(a: u64) -> u64 {
12407 const_ring_eval_w56(PrimitiveOp::Xor, a, 0x00FF_FFFF_FFFF_FFFFu64)
12408 }
12409}
12410
12411impl UnaryRingOp<W56> for Succ<W56> {
12412 type Operand = u64;
12413 #[inline]
12414 fn apply(a: u64) -> u64 {
12415 <Neg<W56> as UnaryRingOp<W56>>::apply(<BNot<W56> as UnaryRingOp<W56>>::apply(a))
12416 }
12417}
12418
12419impl UnaryRingOp<W64> for Neg<W64> {
12420 type Operand = u64;
12421 #[inline]
12422 fn apply(a: u64) -> u64 {
12423 const_ring_eval_w64(PrimitiveOp::Sub, 0, a)
12424 }
12425}
12426
12427impl UnaryRingOp<W64> for BNot<W64> {
12428 type Operand = u64;
12429 #[inline]
12430 fn apply(a: u64) -> u64 {
12431 const_ring_eval_w64(PrimitiveOp::Xor, a, u64::MAX)
12432 }
12433}
12434
12435impl UnaryRingOp<W64> for Succ<W64> {
12436 type Operand = u64;
12437 #[inline]
12438 fn apply(a: u64) -> u64 {
12439 <Neg<W64> as UnaryRingOp<W64>>::apply(<BNot<W64> as UnaryRingOp<W64>>::apply(a))
12440 }
12441}
12442
12443impl UnaryRingOp<W72> for Neg<W72> {
12444 type Operand = u128;
12445 #[inline]
12446 fn apply(a: u128) -> u128 {
12447 const_ring_eval_w72(PrimitiveOp::Sub, 0, a)
12448 }
12449}
12450
12451impl UnaryRingOp<W72> for BNot<W72> {
12452 type Operand = u128;
12453 #[inline]
12454 fn apply(a: u128) -> u128 {
12455 const_ring_eval_w72(PrimitiveOp::Xor, a, u128::MAX >> (128 - 72))
12456 }
12457}
12458
12459impl UnaryRingOp<W72> for Succ<W72> {
12460 type Operand = u128;
12461 #[inline]
12462 fn apply(a: u128) -> u128 {
12463 <Neg<W72> as UnaryRingOp<W72>>::apply(<BNot<W72> as UnaryRingOp<W72>>::apply(a))
12464 }
12465}
12466
12467impl UnaryRingOp<W80> for Neg<W80> {
12468 type Operand = u128;
12469 #[inline]
12470 fn apply(a: u128) -> u128 {
12471 const_ring_eval_w80(PrimitiveOp::Sub, 0, a)
12472 }
12473}
12474
12475impl UnaryRingOp<W80> for BNot<W80> {
12476 type Operand = u128;
12477 #[inline]
12478 fn apply(a: u128) -> u128 {
12479 const_ring_eval_w80(PrimitiveOp::Xor, a, u128::MAX >> (128 - 80))
12480 }
12481}
12482
12483impl UnaryRingOp<W80> for Succ<W80> {
12484 type Operand = u128;
12485 #[inline]
12486 fn apply(a: u128) -> u128 {
12487 <Neg<W80> as UnaryRingOp<W80>>::apply(<BNot<W80> as UnaryRingOp<W80>>::apply(a))
12488 }
12489}
12490
12491impl UnaryRingOp<W88> for Neg<W88> {
12492 type Operand = u128;
12493 #[inline]
12494 fn apply(a: u128) -> u128 {
12495 const_ring_eval_w88(PrimitiveOp::Sub, 0, a)
12496 }
12497}
12498
12499impl UnaryRingOp<W88> for BNot<W88> {
12500 type Operand = u128;
12501 #[inline]
12502 fn apply(a: u128) -> u128 {
12503 const_ring_eval_w88(PrimitiveOp::Xor, a, u128::MAX >> (128 - 88))
12504 }
12505}
12506
12507impl UnaryRingOp<W88> for Succ<W88> {
12508 type Operand = u128;
12509 #[inline]
12510 fn apply(a: u128) -> u128 {
12511 <Neg<W88> as UnaryRingOp<W88>>::apply(<BNot<W88> as UnaryRingOp<W88>>::apply(a))
12512 }
12513}
12514
12515impl UnaryRingOp<W96> for Neg<W96> {
12516 type Operand = u128;
12517 #[inline]
12518 fn apply(a: u128) -> u128 {
12519 const_ring_eval_w96(PrimitiveOp::Sub, 0, a)
12520 }
12521}
12522
12523impl UnaryRingOp<W96> for BNot<W96> {
12524 type Operand = u128;
12525 #[inline]
12526 fn apply(a: u128) -> u128 {
12527 const_ring_eval_w96(PrimitiveOp::Xor, a, u128::MAX >> (128 - 96))
12528 }
12529}
12530
12531impl UnaryRingOp<W96> for Succ<W96> {
12532 type Operand = u128;
12533 #[inline]
12534 fn apply(a: u128) -> u128 {
12535 <Neg<W96> as UnaryRingOp<W96>>::apply(<BNot<W96> as UnaryRingOp<W96>>::apply(a))
12536 }
12537}
12538
12539impl UnaryRingOp<W104> for Neg<W104> {
12540 type Operand = u128;
12541 #[inline]
12542 fn apply(a: u128) -> u128 {
12543 const_ring_eval_w104(PrimitiveOp::Sub, 0, a)
12544 }
12545}
12546
12547impl UnaryRingOp<W104> for BNot<W104> {
12548 type Operand = u128;
12549 #[inline]
12550 fn apply(a: u128) -> u128 {
12551 const_ring_eval_w104(PrimitiveOp::Xor, a, u128::MAX >> (128 - 104))
12552 }
12553}
12554
12555impl UnaryRingOp<W104> for Succ<W104> {
12556 type Operand = u128;
12557 #[inline]
12558 fn apply(a: u128) -> u128 {
12559 <Neg<W104> as UnaryRingOp<W104>>::apply(<BNot<W104> as UnaryRingOp<W104>>::apply(a))
12560 }
12561}
12562
12563impl UnaryRingOp<W112> for Neg<W112> {
12564 type Operand = u128;
12565 #[inline]
12566 fn apply(a: u128) -> u128 {
12567 const_ring_eval_w112(PrimitiveOp::Sub, 0, a)
12568 }
12569}
12570
12571impl UnaryRingOp<W112> for BNot<W112> {
12572 type Operand = u128;
12573 #[inline]
12574 fn apply(a: u128) -> u128 {
12575 const_ring_eval_w112(PrimitiveOp::Xor, a, u128::MAX >> (128 - 112))
12576 }
12577}
12578
12579impl UnaryRingOp<W112> for Succ<W112> {
12580 type Operand = u128;
12581 #[inline]
12582 fn apply(a: u128) -> u128 {
12583 <Neg<W112> as UnaryRingOp<W112>>::apply(<BNot<W112> as UnaryRingOp<W112>>::apply(a))
12584 }
12585}
12586
12587impl UnaryRingOp<W120> for Neg<W120> {
12588 type Operand = u128;
12589 #[inline]
12590 fn apply(a: u128) -> u128 {
12591 const_ring_eval_w120(PrimitiveOp::Sub, 0, a)
12592 }
12593}
12594
12595impl UnaryRingOp<W120> for BNot<W120> {
12596 type Operand = u128;
12597 #[inline]
12598 fn apply(a: u128) -> u128 {
12599 const_ring_eval_w120(PrimitiveOp::Xor, a, u128::MAX >> (128 - 120))
12600 }
12601}
12602
12603impl UnaryRingOp<W120> for Succ<W120> {
12604 type Operand = u128;
12605 #[inline]
12606 fn apply(a: u128) -> u128 {
12607 <Neg<W120> as UnaryRingOp<W120>>::apply(<BNot<W120> as UnaryRingOp<W120>>::apply(a))
12608 }
12609}
12610
12611impl UnaryRingOp<W128> for Neg<W128> {
12612 type Operand = u128;
12613 #[inline]
12614 fn apply(a: u128) -> u128 {
12615 const_ring_eval_w128(PrimitiveOp::Sub, 0, a)
12616 }
12617}
12618
12619impl UnaryRingOp<W128> for BNot<W128> {
12620 type Operand = u128;
12621 #[inline]
12622 fn apply(a: u128) -> u128 {
12623 const_ring_eval_w128(PrimitiveOp::Xor, a, u128::MAX)
12624 }
12625}
12626
12627impl UnaryRingOp<W128> for Succ<W128> {
12628 type Operand = u128;
12629 #[inline]
12630 fn apply(a: u128) -> u128 {
12631 <Neg<W128> as UnaryRingOp<W128>>::apply(<BNot<W128> as UnaryRingOp<W128>>::apply(a))
12632 }
12633}
12634
12635pub trait ValidLevelEmbedding: valid_level_embedding_sealed::Sealed {}
12638
12639mod valid_level_embedding_sealed {
12640 pub trait Sealed {}
12642 impl Sealed for (super::W8, super::W8) {}
12643 impl Sealed for (super::W8, super::W16) {}
12644 impl Sealed for (super::W8, super::W24) {}
12645 impl Sealed for (super::W8, super::W32) {}
12646 impl Sealed for (super::W8, super::W40) {}
12647 impl Sealed for (super::W8, super::W48) {}
12648 impl Sealed for (super::W8, super::W56) {}
12649 impl Sealed for (super::W8, super::W64) {}
12650 impl Sealed for (super::W8, super::W72) {}
12651 impl Sealed for (super::W8, super::W80) {}
12652 impl Sealed for (super::W8, super::W88) {}
12653 impl Sealed for (super::W8, super::W96) {}
12654 impl Sealed for (super::W8, super::W104) {}
12655 impl Sealed for (super::W8, super::W112) {}
12656 impl Sealed for (super::W8, super::W120) {}
12657 impl Sealed for (super::W8, super::W128) {}
12658 impl Sealed for (super::W16, super::W16) {}
12659 impl Sealed for (super::W16, super::W24) {}
12660 impl Sealed for (super::W16, super::W32) {}
12661 impl Sealed for (super::W16, super::W40) {}
12662 impl Sealed for (super::W16, super::W48) {}
12663 impl Sealed for (super::W16, super::W56) {}
12664 impl Sealed for (super::W16, super::W64) {}
12665 impl Sealed for (super::W16, super::W72) {}
12666 impl Sealed for (super::W16, super::W80) {}
12667 impl Sealed for (super::W16, super::W88) {}
12668 impl Sealed for (super::W16, super::W96) {}
12669 impl Sealed for (super::W16, super::W104) {}
12670 impl Sealed for (super::W16, super::W112) {}
12671 impl Sealed for (super::W16, super::W120) {}
12672 impl Sealed for (super::W16, super::W128) {}
12673 impl Sealed for (super::W24, super::W24) {}
12674 impl Sealed for (super::W24, super::W32) {}
12675 impl Sealed for (super::W24, super::W40) {}
12676 impl Sealed for (super::W24, super::W48) {}
12677 impl Sealed for (super::W24, super::W56) {}
12678 impl Sealed for (super::W24, super::W64) {}
12679 impl Sealed for (super::W24, super::W72) {}
12680 impl Sealed for (super::W24, super::W80) {}
12681 impl Sealed for (super::W24, super::W88) {}
12682 impl Sealed for (super::W24, super::W96) {}
12683 impl Sealed for (super::W24, super::W104) {}
12684 impl Sealed for (super::W24, super::W112) {}
12685 impl Sealed for (super::W24, super::W120) {}
12686 impl Sealed for (super::W24, super::W128) {}
12687 impl Sealed for (super::W32, super::W32) {}
12688 impl Sealed for (super::W32, super::W40) {}
12689 impl Sealed for (super::W32, super::W48) {}
12690 impl Sealed for (super::W32, super::W56) {}
12691 impl Sealed for (super::W32, super::W64) {}
12692 impl Sealed for (super::W32, super::W72) {}
12693 impl Sealed for (super::W32, super::W80) {}
12694 impl Sealed for (super::W32, super::W88) {}
12695 impl Sealed for (super::W32, super::W96) {}
12696 impl Sealed for (super::W32, super::W104) {}
12697 impl Sealed for (super::W32, super::W112) {}
12698 impl Sealed for (super::W32, super::W120) {}
12699 impl Sealed for (super::W32, super::W128) {}
12700 impl Sealed for (super::W40, super::W40) {}
12701 impl Sealed for (super::W40, super::W48) {}
12702 impl Sealed for (super::W40, super::W56) {}
12703 impl Sealed for (super::W40, super::W64) {}
12704 impl Sealed for (super::W40, super::W72) {}
12705 impl Sealed for (super::W40, super::W80) {}
12706 impl Sealed for (super::W40, super::W88) {}
12707 impl Sealed for (super::W40, super::W96) {}
12708 impl Sealed for (super::W40, super::W104) {}
12709 impl Sealed for (super::W40, super::W112) {}
12710 impl Sealed for (super::W40, super::W120) {}
12711 impl Sealed for (super::W40, super::W128) {}
12712 impl Sealed for (super::W48, super::W48) {}
12713 impl Sealed for (super::W48, super::W56) {}
12714 impl Sealed for (super::W48, super::W64) {}
12715 impl Sealed for (super::W48, super::W72) {}
12716 impl Sealed for (super::W48, super::W80) {}
12717 impl Sealed for (super::W48, super::W88) {}
12718 impl Sealed for (super::W48, super::W96) {}
12719 impl Sealed for (super::W48, super::W104) {}
12720 impl Sealed for (super::W48, super::W112) {}
12721 impl Sealed for (super::W48, super::W120) {}
12722 impl Sealed for (super::W48, super::W128) {}
12723 impl Sealed for (super::W56, super::W56) {}
12724 impl Sealed for (super::W56, super::W64) {}
12725 impl Sealed for (super::W56, super::W72) {}
12726 impl Sealed for (super::W56, super::W80) {}
12727 impl Sealed for (super::W56, super::W88) {}
12728 impl Sealed for (super::W56, super::W96) {}
12729 impl Sealed for (super::W56, super::W104) {}
12730 impl Sealed for (super::W56, super::W112) {}
12731 impl Sealed for (super::W56, super::W120) {}
12732 impl Sealed for (super::W56, super::W128) {}
12733 impl Sealed for (super::W64, super::W64) {}
12734 impl Sealed for (super::W64, super::W72) {}
12735 impl Sealed for (super::W64, super::W80) {}
12736 impl Sealed for (super::W64, super::W88) {}
12737 impl Sealed for (super::W64, super::W96) {}
12738 impl Sealed for (super::W64, super::W104) {}
12739 impl Sealed for (super::W64, super::W112) {}
12740 impl Sealed for (super::W64, super::W120) {}
12741 impl Sealed for (super::W64, super::W128) {}
12742 impl Sealed for (super::W72, super::W72) {}
12743 impl Sealed for (super::W72, super::W80) {}
12744 impl Sealed for (super::W72, super::W88) {}
12745 impl Sealed for (super::W72, super::W96) {}
12746 impl Sealed for (super::W72, super::W104) {}
12747 impl Sealed for (super::W72, super::W112) {}
12748 impl Sealed for (super::W72, super::W120) {}
12749 impl Sealed for (super::W72, super::W128) {}
12750 impl Sealed for (super::W80, super::W80) {}
12751 impl Sealed for (super::W80, super::W88) {}
12752 impl Sealed for (super::W80, super::W96) {}
12753 impl Sealed for (super::W80, super::W104) {}
12754 impl Sealed for (super::W80, super::W112) {}
12755 impl Sealed for (super::W80, super::W120) {}
12756 impl Sealed for (super::W80, super::W128) {}
12757 impl Sealed for (super::W88, super::W88) {}
12758 impl Sealed for (super::W88, super::W96) {}
12759 impl Sealed for (super::W88, super::W104) {}
12760 impl Sealed for (super::W88, super::W112) {}
12761 impl Sealed for (super::W88, super::W120) {}
12762 impl Sealed for (super::W88, super::W128) {}
12763 impl Sealed for (super::W96, super::W96) {}
12764 impl Sealed for (super::W96, super::W104) {}
12765 impl Sealed for (super::W96, super::W112) {}
12766 impl Sealed for (super::W96, super::W120) {}
12767 impl Sealed for (super::W96, super::W128) {}
12768 impl Sealed for (super::W104, super::W104) {}
12769 impl Sealed for (super::W104, super::W112) {}
12770 impl Sealed for (super::W104, super::W120) {}
12771 impl Sealed for (super::W104, super::W128) {}
12772 impl Sealed for (super::W112, super::W112) {}
12773 impl Sealed for (super::W112, super::W120) {}
12774 impl Sealed for (super::W112, super::W128) {}
12775 impl Sealed for (super::W120, super::W120) {}
12776 impl Sealed for (super::W120, super::W128) {}
12777 impl Sealed for (super::W128, super::W128) {}
12778}
12779
12780impl ValidLevelEmbedding for (W8, W8) {}
12781impl ValidLevelEmbedding for (W8, W16) {}
12782impl ValidLevelEmbedding for (W8, W24) {}
12783impl ValidLevelEmbedding for (W8, W32) {}
12784impl ValidLevelEmbedding for (W8, W40) {}
12785impl ValidLevelEmbedding for (W8, W48) {}
12786impl ValidLevelEmbedding for (W8, W56) {}
12787impl ValidLevelEmbedding for (W8, W64) {}
12788impl ValidLevelEmbedding for (W8, W72) {}
12789impl ValidLevelEmbedding for (W8, W80) {}
12790impl ValidLevelEmbedding for (W8, W88) {}
12791impl ValidLevelEmbedding for (W8, W96) {}
12792impl ValidLevelEmbedding for (W8, W104) {}
12793impl ValidLevelEmbedding for (W8, W112) {}
12794impl ValidLevelEmbedding for (W8, W120) {}
12795impl ValidLevelEmbedding for (W8, W128) {}
12796impl ValidLevelEmbedding for (W16, W16) {}
12797impl ValidLevelEmbedding for (W16, W24) {}
12798impl ValidLevelEmbedding for (W16, W32) {}
12799impl ValidLevelEmbedding for (W16, W40) {}
12800impl ValidLevelEmbedding for (W16, W48) {}
12801impl ValidLevelEmbedding for (W16, W56) {}
12802impl ValidLevelEmbedding for (W16, W64) {}
12803impl ValidLevelEmbedding for (W16, W72) {}
12804impl ValidLevelEmbedding for (W16, W80) {}
12805impl ValidLevelEmbedding for (W16, W88) {}
12806impl ValidLevelEmbedding for (W16, W96) {}
12807impl ValidLevelEmbedding for (W16, W104) {}
12808impl ValidLevelEmbedding for (W16, W112) {}
12809impl ValidLevelEmbedding for (W16, W120) {}
12810impl ValidLevelEmbedding for (W16, W128) {}
12811impl ValidLevelEmbedding for (W24, W24) {}
12812impl ValidLevelEmbedding for (W24, W32) {}
12813impl ValidLevelEmbedding for (W24, W40) {}
12814impl ValidLevelEmbedding for (W24, W48) {}
12815impl ValidLevelEmbedding for (W24, W56) {}
12816impl ValidLevelEmbedding for (W24, W64) {}
12817impl ValidLevelEmbedding for (W24, W72) {}
12818impl ValidLevelEmbedding for (W24, W80) {}
12819impl ValidLevelEmbedding for (W24, W88) {}
12820impl ValidLevelEmbedding for (W24, W96) {}
12821impl ValidLevelEmbedding for (W24, W104) {}
12822impl ValidLevelEmbedding for (W24, W112) {}
12823impl ValidLevelEmbedding for (W24, W120) {}
12824impl ValidLevelEmbedding for (W24, W128) {}
12825impl ValidLevelEmbedding for (W32, W32) {}
12826impl ValidLevelEmbedding for (W32, W40) {}
12827impl ValidLevelEmbedding for (W32, W48) {}
12828impl ValidLevelEmbedding for (W32, W56) {}
12829impl ValidLevelEmbedding for (W32, W64) {}
12830impl ValidLevelEmbedding for (W32, W72) {}
12831impl ValidLevelEmbedding for (W32, W80) {}
12832impl ValidLevelEmbedding for (W32, W88) {}
12833impl ValidLevelEmbedding for (W32, W96) {}
12834impl ValidLevelEmbedding for (W32, W104) {}
12835impl ValidLevelEmbedding for (W32, W112) {}
12836impl ValidLevelEmbedding for (W32, W120) {}
12837impl ValidLevelEmbedding for (W32, W128) {}
12838impl ValidLevelEmbedding for (W40, W40) {}
12839impl ValidLevelEmbedding for (W40, W48) {}
12840impl ValidLevelEmbedding for (W40, W56) {}
12841impl ValidLevelEmbedding for (W40, W64) {}
12842impl ValidLevelEmbedding for (W40, W72) {}
12843impl ValidLevelEmbedding for (W40, W80) {}
12844impl ValidLevelEmbedding for (W40, W88) {}
12845impl ValidLevelEmbedding for (W40, W96) {}
12846impl ValidLevelEmbedding for (W40, W104) {}
12847impl ValidLevelEmbedding for (W40, W112) {}
12848impl ValidLevelEmbedding for (W40, W120) {}
12849impl ValidLevelEmbedding for (W40, W128) {}
12850impl ValidLevelEmbedding for (W48, W48) {}
12851impl ValidLevelEmbedding for (W48, W56) {}
12852impl ValidLevelEmbedding for (W48, W64) {}
12853impl ValidLevelEmbedding for (W48, W72) {}
12854impl ValidLevelEmbedding for (W48, W80) {}
12855impl ValidLevelEmbedding for (W48, W88) {}
12856impl ValidLevelEmbedding for (W48, W96) {}
12857impl ValidLevelEmbedding for (W48, W104) {}
12858impl ValidLevelEmbedding for (W48, W112) {}
12859impl ValidLevelEmbedding for (W48, W120) {}
12860impl ValidLevelEmbedding for (W48, W128) {}
12861impl ValidLevelEmbedding for (W56, W56) {}
12862impl ValidLevelEmbedding for (W56, W64) {}
12863impl ValidLevelEmbedding for (W56, W72) {}
12864impl ValidLevelEmbedding for (W56, W80) {}
12865impl ValidLevelEmbedding for (W56, W88) {}
12866impl ValidLevelEmbedding for (W56, W96) {}
12867impl ValidLevelEmbedding for (W56, W104) {}
12868impl ValidLevelEmbedding for (W56, W112) {}
12869impl ValidLevelEmbedding for (W56, W120) {}
12870impl ValidLevelEmbedding for (W56, W128) {}
12871impl ValidLevelEmbedding for (W64, W64) {}
12872impl ValidLevelEmbedding for (W64, W72) {}
12873impl ValidLevelEmbedding for (W64, W80) {}
12874impl ValidLevelEmbedding for (W64, W88) {}
12875impl ValidLevelEmbedding for (W64, W96) {}
12876impl ValidLevelEmbedding for (W64, W104) {}
12877impl ValidLevelEmbedding for (W64, W112) {}
12878impl ValidLevelEmbedding for (W64, W120) {}
12879impl ValidLevelEmbedding for (W64, W128) {}
12880impl ValidLevelEmbedding for (W72, W72) {}
12881impl ValidLevelEmbedding for (W72, W80) {}
12882impl ValidLevelEmbedding for (W72, W88) {}
12883impl ValidLevelEmbedding for (W72, W96) {}
12884impl ValidLevelEmbedding for (W72, W104) {}
12885impl ValidLevelEmbedding for (W72, W112) {}
12886impl ValidLevelEmbedding for (W72, W120) {}
12887impl ValidLevelEmbedding for (W72, W128) {}
12888impl ValidLevelEmbedding for (W80, W80) {}
12889impl ValidLevelEmbedding for (W80, W88) {}
12890impl ValidLevelEmbedding for (W80, W96) {}
12891impl ValidLevelEmbedding for (W80, W104) {}
12892impl ValidLevelEmbedding for (W80, W112) {}
12893impl ValidLevelEmbedding for (W80, W120) {}
12894impl ValidLevelEmbedding for (W80, W128) {}
12895impl ValidLevelEmbedding for (W88, W88) {}
12896impl ValidLevelEmbedding for (W88, W96) {}
12897impl ValidLevelEmbedding for (W88, W104) {}
12898impl ValidLevelEmbedding for (W88, W112) {}
12899impl ValidLevelEmbedding for (W88, W120) {}
12900impl ValidLevelEmbedding for (W88, W128) {}
12901impl ValidLevelEmbedding for (W96, W96) {}
12902impl ValidLevelEmbedding for (W96, W104) {}
12903impl ValidLevelEmbedding for (W96, W112) {}
12904impl ValidLevelEmbedding for (W96, W120) {}
12905impl ValidLevelEmbedding for (W96, W128) {}
12906impl ValidLevelEmbedding for (W104, W104) {}
12907impl ValidLevelEmbedding for (W104, W112) {}
12908impl ValidLevelEmbedding for (W104, W120) {}
12909impl ValidLevelEmbedding for (W104, W128) {}
12910impl ValidLevelEmbedding for (W112, W112) {}
12911impl ValidLevelEmbedding for (W112, W120) {}
12912impl ValidLevelEmbedding for (W112, W128) {}
12913impl ValidLevelEmbedding for (W120, W120) {}
12914impl ValidLevelEmbedding for (W120, W128) {}
12915impl ValidLevelEmbedding for (W128, W128) {}
12916
12917#[derive(Debug, Default, Clone, Copy)]
12923pub struct Embed<From, To>(PhantomData<(From, To)>);
12924
12925impl Embed<W8, W8> {
12926 #[inline]
12928 #[must_use]
12929 pub const fn apply(value: u8) -> u8 {
12930 value
12931 }
12932}
12933
12934impl Embed<W8, W16> {
12935 #[inline]
12937 #[must_use]
12938 pub const fn apply(value: u8) -> u16 {
12939 value as u16
12940 }
12941}
12942
12943impl Embed<W8, W24> {
12944 #[inline]
12946 #[must_use]
12947 pub const fn apply(value: u8) -> u32 {
12948 value as u32
12949 }
12950}
12951
12952impl Embed<W8, W32> {
12953 #[inline]
12955 #[must_use]
12956 pub const fn apply(value: u8) -> u32 {
12957 value as u32
12958 }
12959}
12960
12961impl Embed<W8, W40> {
12962 #[inline]
12964 #[must_use]
12965 pub const fn apply(value: u8) -> u64 {
12966 value as u64
12967 }
12968}
12969
12970impl Embed<W8, W48> {
12971 #[inline]
12973 #[must_use]
12974 pub const fn apply(value: u8) -> u64 {
12975 value as u64
12976 }
12977}
12978
12979impl Embed<W8, W56> {
12980 #[inline]
12982 #[must_use]
12983 pub const fn apply(value: u8) -> u64 {
12984 value as u64
12985 }
12986}
12987
12988impl Embed<W8, W64> {
12989 #[inline]
12991 #[must_use]
12992 pub const fn apply(value: u8) -> u64 {
12993 value as u64
12994 }
12995}
12996
12997impl Embed<W8, W72> {
12998 #[inline]
13000 #[must_use]
13001 pub const fn apply(value: u8) -> u128 {
13002 value as u128
13003 }
13004}
13005
13006impl Embed<W8, W80> {
13007 #[inline]
13009 #[must_use]
13010 pub const fn apply(value: u8) -> u128 {
13011 value as u128
13012 }
13013}
13014
13015impl Embed<W8, W88> {
13016 #[inline]
13018 #[must_use]
13019 pub const fn apply(value: u8) -> u128 {
13020 value as u128
13021 }
13022}
13023
13024impl Embed<W8, W96> {
13025 #[inline]
13027 #[must_use]
13028 pub const fn apply(value: u8) -> u128 {
13029 value as u128
13030 }
13031}
13032
13033impl Embed<W8, W104> {
13034 #[inline]
13036 #[must_use]
13037 pub const fn apply(value: u8) -> u128 {
13038 value as u128
13039 }
13040}
13041
13042impl Embed<W8, W112> {
13043 #[inline]
13045 #[must_use]
13046 pub const fn apply(value: u8) -> u128 {
13047 value as u128
13048 }
13049}
13050
13051impl Embed<W8, W120> {
13052 #[inline]
13054 #[must_use]
13055 pub const fn apply(value: u8) -> u128 {
13056 value as u128
13057 }
13058}
13059
13060impl Embed<W8, W128> {
13061 #[inline]
13063 #[must_use]
13064 pub const fn apply(value: u8) -> u128 {
13065 value as u128
13066 }
13067}
13068
13069impl Embed<W16, W16> {
13070 #[inline]
13072 #[must_use]
13073 pub const fn apply(value: u16) -> u16 {
13074 value
13075 }
13076}
13077
13078impl Embed<W16, W24> {
13079 #[inline]
13081 #[must_use]
13082 pub const fn apply(value: u16) -> u32 {
13083 value as u32
13084 }
13085}
13086
13087impl Embed<W16, W32> {
13088 #[inline]
13090 #[must_use]
13091 pub const fn apply(value: u16) -> u32 {
13092 value as u32
13093 }
13094}
13095
13096impl Embed<W16, W40> {
13097 #[inline]
13099 #[must_use]
13100 pub const fn apply(value: u16) -> u64 {
13101 value as u64
13102 }
13103}
13104
13105impl Embed<W16, W48> {
13106 #[inline]
13108 #[must_use]
13109 pub const fn apply(value: u16) -> u64 {
13110 value as u64
13111 }
13112}
13113
13114impl Embed<W16, W56> {
13115 #[inline]
13117 #[must_use]
13118 pub const fn apply(value: u16) -> u64 {
13119 value as u64
13120 }
13121}
13122
13123impl Embed<W16, W64> {
13124 #[inline]
13126 #[must_use]
13127 pub const fn apply(value: u16) -> u64 {
13128 value as u64
13129 }
13130}
13131
13132impl Embed<W16, W72> {
13133 #[inline]
13135 #[must_use]
13136 pub const fn apply(value: u16) -> u128 {
13137 value as u128
13138 }
13139}
13140
13141impl Embed<W16, W80> {
13142 #[inline]
13144 #[must_use]
13145 pub const fn apply(value: u16) -> u128 {
13146 value as u128
13147 }
13148}
13149
13150impl Embed<W16, W88> {
13151 #[inline]
13153 #[must_use]
13154 pub const fn apply(value: u16) -> u128 {
13155 value as u128
13156 }
13157}
13158
13159impl Embed<W16, W96> {
13160 #[inline]
13162 #[must_use]
13163 pub const fn apply(value: u16) -> u128 {
13164 value as u128
13165 }
13166}
13167
13168impl Embed<W16, W104> {
13169 #[inline]
13171 #[must_use]
13172 pub const fn apply(value: u16) -> u128 {
13173 value as u128
13174 }
13175}
13176
13177impl Embed<W16, W112> {
13178 #[inline]
13180 #[must_use]
13181 pub const fn apply(value: u16) -> u128 {
13182 value as u128
13183 }
13184}
13185
13186impl Embed<W16, W120> {
13187 #[inline]
13189 #[must_use]
13190 pub const fn apply(value: u16) -> u128 {
13191 value as u128
13192 }
13193}
13194
13195impl Embed<W16, W128> {
13196 #[inline]
13198 #[must_use]
13199 pub const fn apply(value: u16) -> u128 {
13200 value as u128
13201 }
13202}
13203
13204impl Embed<W24, W24> {
13205 #[inline]
13207 #[must_use]
13208 pub const fn apply(value: u32) -> u32 {
13209 value
13210 }
13211}
13212
13213impl Embed<W24, W32> {
13214 #[inline]
13216 #[must_use]
13217 pub const fn apply(value: u32) -> u32 {
13218 value
13219 }
13220}
13221
13222impl Embed<W24, W40> {
13223 #[inline]
13225 #[must_use]
13226 pub const fn apply(value: u32) -> u64 {
13227 value as u64
13228 }
13229}
13230
13231impl Embed<W24, W48> {
13232 #[inline]
13234 #[must_use]
13235 pub const fn apply(value: u32) -> u64 {
13236 value as u64
13237 }
13238}
13239
13240impl Embed<W24, W56> {
13241 #[inline]
13243 #[must_use]
13244 pub const fn apply(value: u32) -> u64 {
13245 value as u64
13246 }
13247}
13248
13249impl Embed<W24, W64> {
13250 #[inline]
13252 #[must_use]
13253 pub const fn apply(value: u32) -> u64 {
13254 value as u64
13255 }
13256}
13257
13258impl Embed<W24, W72> {
13259 #[inline]
13261 #[must_use]
13262 pub const fn apply(value: u32) -> u128 {
13263 value as u128
13264 }
13265}
13266
13267impl Embed<W24, W80> {
13268 #[inline]
13270 #[must_use]
13271 pub const fn apply(value: u32) -> u128 {
13272 value as u128
13273 }
13274}
13275
13276impl Embed<W24, W88> {
13277 #[inline]
13279 #[must_use]
13280 pub const fn apply(value: u32) -> u128 {
13281 value as u128
13282 }
13283}
13284
13285impl Embed<W24, W96> {
13286 #[inline]
13288 #[must_use]
13289 pub const fn apply(value: u32) -> u128 {
13290 value as u128
13291 }
13292}
13293
13294impl Embed<W24, W104> {
13295 #[inline]
13297 #[must_use]
13298 pub const fn apply(value: u32) -> u128 {
13299 value as u128
13300 }
13301}
13302
13303impl Embed<W24, W112> {
13304 #[inline]
13306 #[must_use]
13307 pub const fn apply(value: u32) -> u128 {
13308 value as u128
13309 }
13310}
13311
13312impl Embed<W24, W120> {
13313 #[inline]
13315 #[must_use]
13316 pub const fn apply(value: u32) -> u128 {
13317 value as u128
13318 }
13319}
13320
13321impl Embed<W24, W128> {
13322 #[inline]
13324 #[must_use]
13325 pub const fn apply(value: u32) -> u128 {
13326 value as u128
13327 }
13328}
13329
13330impl Embed<W32, W32> {
13331 #[inline]
13333 #[must_use]
13334 pub const fn apply(value: u32) -> u32 {
13335 value
13336 }
13337}
13338
13339impl Embed<W32, W40> {
13340 #[inline]
13342 #[must_use]
13343 pub const fn apply(value: u32) -> u64 {
13344 value as u64
13345 }
13346}
13347
13348impl Embed<W32, W48> {
13349 #[inline]
13351 #[must_use]
13352 pub const fn apply(value: u32) -> u64 {
13353 value as u64
13354 }
13355}
13356
13357impl Embed<W32, W56> {
13358 #[inline]
13360 #[must_use]
13361 pub const fn apply(value: u32) -> u64 {
13362 value as u64
13363 }
13364}
13365
13366impl Embed<W32, W64> {
13367 #[inline]
13369 #[must_use]
13370 pub const fn apply(value: u32) -> u64 {
13371 value as u64
13372 }
13373}
13374
13375impl Embed<W32, W72> {
13376 #[inline]
13378 #[must_use]
13379 pub const fn apply(value: u32) -> u128 {
13380 value as u128
13381 }
13382}
13383
13384impl Embed<W32, W80> {
13385 #[inline]
13387 #[must_use]
13388 pub const fn apply(value: u32) -> u128 {
13389 value as u128
13390 }
13391}
13392
13393impl Embed<W32, W88> {
13394 #[inline]
13396 #[must_use]
13397 pub const fn apply(value: u32) -> u128 {
13398 value as u128
13399 }
13400}
13401
13402impl Embed<W32, W96> {
13403 #[inline]
13405 #[must_use]
13406 pub const fn apply(value: u32) -> u128 {
13407 value as u128
13408 }
13409}
13410
13411impl Embed<W32, W104> {
13412 #[inline]
13414 #[must_use]
13415 pub const fn apply(value: u32) -> u128 {
13416 value as u128
13417 }
13418}
13419
13420impl Embed<W32, W112> {
13421 #[inline]
13423 #[must_use]
13424 pub const fn apply(value: u32) -> u128 {
13425 value as u128
13426 }
13427}
13428
13429impl Embed<W32, W120> {
13430 #[inline]
13432 #[must_use]
13433 pub const fn apply(value: u32) -> u128 {
13434 value as u128
13435 }
13436}
13437
13438impl Embed<W32, W128> {
13439 #[inline]
13441 #[must_use]
13442 pub const fn apply(value: u32) -> u128 {
13443 value as u128
13444 }
13445}
13446
13447impl Embed<W40, W40> {
13448 #[inline]
13450 #[must_use]
13451 pub const fn apply(value: u64) -> u64 {
13452 value
13453 }
13454}
13455
13456impl Embed<W40, W48> {
13457 #[inline]
13459 #[must_use]
13460 pub const fn apply(value: u64) -> u64 {
13461 value
13462 }
13463}
13464
13465impl Embed<W40, W56> {
13466 #[inline]
13468 #[must_use]
13469 pub const fn apply(value: u64) -> u64 {
13470 value
13471 }
13472}
13473
13474impl Embed<W40, W64> {
13475 #[inline]
13477 #[must_use]
13478 pub const fn apply(value: u64) -> u64 {
13479 value
13480 }
13481}
13482
13483impl Embed<W40, W72> {
13484 #[inline]
13486 #[must_use]
13487 pub const fn apply(value: u64) -> u128 {
13488 value as u128
13489 }
13490}
13491
13492impl Embed<W40, W80> {
13493 #[inline]
13495 #[must_use]
13496 pub const fn apply(value: u64) -> u128 {
13497 value as u128
13498 }
13499}
13500
13501impl Embed<W40, W88> {
13502 #[inline]
13504 #[must_use]
13505 pub const fn apply(value: u64) -> u128 {
13506 value as u128
13507 }
13508}
13509
13510impl Embed<W40, W96> {
13511 #[inline]
13513 #[must_use]
13514 pub const fn apply(value: u64) -> u128 {
13515 value as u128
13516 }
13517}
13518
13519impl Embed<W40, W104> {
13520 #[inline]
13522 #[must_use]
13523 pub const fn apply(value: u64) -> u128 {
13524 value as u128
13525 }
13526}
13527
13528impl Embed<W40, W112> {
13529 #[inline]
13531 #[must_use]
13532 pub const fn apply(value: u64) -> u128 {
13533 value as u128
13534 }
13535}
13536
13537impl Embed<W40, W120> {
13538 #[inline]
13540 #[must_use]
13541 pub const fn apply(value: u64) -> u128 {
13542 value as u128
13543 }
13544}
13545
13546impl Embed<W40, W128> {
13547 #[inline]
13549 #[must_use]
13550 pub const fn apply(value: u64) -> u128 {
13551 value as u128
13552 }
13553}
13554
13555impl Embed<W48, W48> {
13556 #[inline]
13558 #[must_use]
13559 pub const fn apply(value: u64) -> u64 {
13560 value
13561 }
13562}
13563
13564impl Embed<W48, W56> {
13565 #[inline]
13567 #[must_use]
13568 pub const fn apply(value: u64) -> u64 {
13569 value
13570 }
13571}
13572
13573impl Embed<W48, W64> {
13574 #[inline]
13576 #[must_use]
13577 pub const fn apply(value: u64) -> u64 {
13578 value
13579 }
13580}
13581
13582impl Embed<W48, W72> {
13583 #[inline]
13585 #[must_use]
13586 pub const fn apply(value: u64) -> u128 {
13587 value as u128
13588 }
13589}
13590
13591impl Embed<W48, W80> {
13592 #[inline]
13594 #[must_use]
13595 pub const fn apply(value: u64) -> u128 {
13596 value as u128
13597 }
13598}
13599
13600impl Embed<W48, W88> {
13601 #[inline]
13603 #[must_use]
13604 pub const fn apply(value: u64) -> u128 {
13605 value as u128
13606 }
13607}
13608
13609impl Embed<W48, W96> {
13610 #[inline]
13612 #[must_use]
13613 pub const fn apply(value: u64) -> u128 {
13614 value as u128
13615 }
13616}
13617
13618impl Embed<W48, W104> {
13619 #[inline]
13621 #[must_use]
13622 pub const fn apply(value: u64) -> u128 {
13623 value as u128
13624 }
13625}
13626
13627impl Embed<W48, W112> {
13628 #[inline]
13630 #[must_use]
13631 pub const fn apply(value: u64) -> u128 {
13632 value as u128
13633 }
13634}
13635
13636impl Embed<W48, W120> {
13637 #[inline]
13639 #[must_use]
13640 pub const fn apply(value: u64) -> u128 {
13641 value as u128
13642 }
13643}
13644
13645impl Embed<W48, W128> {
13646 #[inline]
13648 #[must_use]
13649 pub const fn apply(value: u64) -> u128 {
13650 value as u128
13651 }
13652}
13653
13654impl Embed<W56, W56> {
13655 #[inline]
13657 #[must_use]
13658 pub const fn apply(value: u64) -> u64 {
13659 value
13660 }
13661}
13662
13663impl Embed<W56, W64> {
13664 #[inline]
13666 #[must_use]
13667 pub const fn apply(value: u64) -> u64 {
13668 value
13669 }
13670}
13671
13672impl Embed<W56, W72> {
13673 #[inline]
13675 #[must_use]
13676 pub const fn apply(value: u64) -> u128 {
13677 value as u128
13678 }
13679}
13680
13681impl Embed<W56, W80> {
13682 #[inline]
13684 #[must_use]
13685 pub const fn apply(value: u64) -> u128 {
13686 value as u128
13687 }
13688}
13689
13690impl Embed<W56, W88> {
13691 #[inline]
13693 #[must_use]
13694 pub const fn apply(value: u64) -> u128 {
13695 value as u128
13696 }
13697}
13698
13699impl Embed<W56, W96> {
13700 #[inline]
13702 #[must_use]
13703 pub const fn apply(value: u64) -> u128 {
13704 value as u128
13705 }
13706}
13707
13708impl Embed<W56, W104> {
13709 #[inline]
13711 #[must_use]
13712 pub const fn apply(value: u64) -> u128 {
13713 value as u128
13714 }
13715}
13716
13717impl Embed<W56, W112> {
13718 #[inline]
13720 #[must_use]
13721 pub const fn apply(value: u64) -> u128 {
13722 value as u128
13723 }
13724}
13725
13726impl Embed<W56, W120> {
13727 #[inline]
13729 #[must_use]
13730 pub const fn apply(value: u64) -> u128 {
13731 value as u128
13732 }
13733}
13734
13735impl Embed<W56, W128> {
13736 #[inline]
13738 #[must_use]
13739 pub const fn apply(value: u64) -> u128 {
13740 value as u128
13741 }
13742}
13743
13744impl Embed<W64, W64> {
13745 #[inline]
13747 #[must_use]
13748 pub const fn apply(value: u64) -> u64 {
13749 value
13750 }
13751}
13752
13753impl Embed<W64, W72> {
13754 #[inline]
13756 #[must_use]
13757 pub const fn apply(value: u64) -> u128 {
13758 value as u128
13759 }
13760}
13761
13762impl Embed<W64, W80> {
13763 #[inline]
13765 #[must_use]
13766 pub const fn apply(value: u64) -> u128 {
13767 value as u128
13768 }
13769}
13770
13771impl Embed<W64, W88> {
13772 #[inline]
13774 #[must_use]
13775 pub const fn apply(value: u64) -> u128 {
13776 value as u128
13777 }
13778}
13779
13780impl Embed<W64, W96> {
13781 #[inline]
13783 #[must_use]
13784 pub const fn apply(value: u64) -> u128 {
13785 value as u128
13786 }
13787}
13788
13789impl Embed<W64, W104> {
13790 #[inline]
13792 #[must_use]
13793 pub const fn apply(value: u64) -> u128 {
13794 value as u128
13795 }
13796}
13797
13798impl Embed<W64, W112> {
13799 #[inline]
13801 #[must_use]
13802 pub const fn apply(value: u64) -> u128 {
13803 value as u128
13804 }
13805}
13806
13807impl Embed<W64, W120> {
13808 #[inline]
13810 #[must_use]
13811 pub const fn apply(value: u64) -> u128 {
13812 value as u128
13813 }
13814}
13815
13816impl Embed<W64, W128> {
13817 #[inline]
13819 #[must_use]
13820 pub const fn apply(value: u64) -> u128 {
13821 value as u128
13822 }
13823}
13824
13825impl Embed<W72, W72> {
13826 #[inline]
13828 #[must_use]
13829 pub const fn apply(value: u128) -> u128 {
13830 value
13831 }
13832}
13833
13834impl Embed<W72, W80> {
13835 #[inline]
13837 #[must_use]
13838 pub const fn apply(value: u128) -> u128 {
13839 value
13840 }
13841}
13842
13843impl Embed<W72, W88> {
13844 #[inline]
13846 #[must_use]
13847 pub const fn apply(value: u128) -> u128 {
13848 value
13849 }
13850}
13851
13852impl Embed<W72, W96> {
13853 #[inline]
13855 #[must_use]
13856 pub const fn apply(value: u128) -> u128 {
13857 value
13858 }
13859}
13860
13861impl Embed<W72, W104> {
13862 #[inline]
13864 #[must_use]
13865 pub const fn apply(value: u128) -> u128 {
13866 value
13867 }
13868}
13869
13870impl Embed<W72, W112> {
13871 #[inline]
13873 #[must_use]
13874 pub const fn apply(value: u128) -> u128 {
13875 value
13876 }
13877}
13878
13879impl Embed<W72, W120> {
13880 #[inline]
13882 #[must_use]
13883 pub const fn apply(value: u128) -> u128 {
13884 value
13885 }
13886}
13887
13888impl Embed<W72, W128> {
13889 #[inline]
13891 #[must_use]
13892 pub const fn apply(value: u128) -> u128 {
13893 value
13894 }
13895}
13896
13897impl Embed<W80, W80> {
13898 #[inline]
13900 #[must_use]
13901 pub const fn apply(value: u128) -> u128 {
13902 value
13903 }
13904}
13905
13906impl Embed<W80, W88> {
13907 #[inline]
13909 #[must_use]
13910 pub const fn apply(value: u128) -> u128 {
13911 value
13912 }
13913}
13914
13915impl Embed<W80, W96> {
13916 #[inline]
13918 #[must_use]
13919 pub const fn apply(value: u128) -> u128 {
13920 value
13921 }
13922}
13923
13924impl Embed<W80, W104> {
13925 #[inline]
13927 #[must_use]
13928 pub const fn apply(value: u128) -> u128 {
13929 value
13930 }
13931}
13932
13933impl Embed<W80, W112> {
13934 #[inline]
13936 #[must_use]
13937 pub const fn apply(value: u128) -> u128 {
13938 value
13939 }
13940}
13941
13942impl Embed<W80, W120> {
13943 #[inline]
13945 #[must_use]
13946 pub const fn apply(value: u128) -> u128 {
13947 value
13948 }
13949}
13950
13951impl Embed<W80, W128> {
13952 #[inline]
13954 #[must_use]
13955 pub const fn apply(value: u128) -> u128 {
13956 value
13957 }
13958}
13959
13960impl Embed<W88, W88> {
13961 #[inline]
13963 #[must_use]
13964 pub const fn apply(value: u128) -> u128 {
13965 value
13966 }
13967}
13968
13969impl Embed<W88, W96> {
13970 #[inline]
13972 #[must_use]
13973 pub const fn apply(value: u128) -> u128 {
13974 value
13975 }
13976}
13977
13978impl Embed<W88, W104> {
13979 #[inline]
13981 #[must_use]
13982 pub const fn apply(value: u128) -> u128 {
13983 value
13984 }
13985}
13986
13987impl Embed<W88, W112> {
13988 #[inline]
13990 #[must_use]
13991 pub const fn apply(value: u128) -> u128 {
13992 value
13993 }
13994}
13995
13996impl Embed<W88, W120> {
13997 #[inline]
13999 #[must_use]
14000 pub const fn apply(value: u128) -> u128 {
14001 value
14002 }
14003}
14004
14005impl Embed<W88, W128> {
14006 #[inline]
14008 #[must_use]
14009 pub const fn apply(value: u128) -> u128 {
14010 value
14011 }
14012}
14013
14014impl Embed<W96, W96> {
14015 #[inline]
14017 #[must_use]
14018 pub const fn apply(value: u128) -> u128 {
14019 value
14020 }
14021}
14022
14023impl Embed<W96, W104> {
14024 #[inline]
14026 #[must_use]
14027 pub const fn apply(value: u128) -> u128 {
14028 value
14029 }
14030}
14031
14032impl Embed<W96, W112> {
14033 #[inline]
14035 #[must_use]
14036 pub const fn apply(value: u128) -> u128 {
14037 value
14038 }
14039}
14040
14041impl Embed<W96, W120> {
14042 #[inline]
14044 #[must_use]
14045 pub const fn apply(value: u128) -> u128 {
14046 value
14047 }
14048}
14049
14050impl Embed<W96, W128> {
14051 #[inline]
14053 #[must_use]
14054 pub const fn apply(value: u128) -> u128 {
14055 value
14056 }
14057}
14058
14059impl Embed<W104, W104> {
14060 #[inline]
14062 #[must_use]
14063 pub const fn apply(value: u128) -> u128 {
14064 value
14065 }
14066}
14067
14068impl Embed<W104, W112> {
14069 #[inline]
14071 #[must_use]
14072 pub const fn apply(value: u128) -> u128 {
14073 value
14074 }
14075}
14076
14077impl Embed<W104, W120> {
14078 #[inline]
14080 #[must_use]
14081 pub const fn apply(value: u128) -> u128 {
14082 value
14083 }
14084}
14085
14086impl Embed<W104, W128> {
14087 #[inline]
14089 #[must_use]
14090 pub const fn apply(value: u128) -> u128 {
14091 value
14092 }
14093}
14094
14095impl Embed<W112, W112> {
14096 #[inline]
14098 #[must_use]
14099 pub const fn apply(value: u128) -> u128 {
14100 value
14101 }
14102}
14103
14104impl Embed<W112, W120> {
14105 #[inline]
14107 #[must_use]
14108 pub const fn apply(value: u128) -> u128 {
14109 value
14110 }
14111}
14112
14113impl Embed<W112, W128> {
14114 #[inline]
14116 #[must_use]
14117 pub const fn apply(value: u128) -> u128 {
14118 value
14119 }
14120}
14121
14122impl Embed<W120, W120> {
14123 #[inline]
14125 #[must_use]
14126 pub const fn apply(value: u128) -> u128 {
14127 value
14128 }
14129}
14130
14131impl Embed<W120, W128> {
14132 #[inline]
14134 #[must_use]
14135 pub const fn apply(value: u128) -> u128 {
14136 value
14137 }
14138}
14139
14140impl Embed<W128, W128> {
14141 #[inline]
14143 #[must_use]
14144 pub const fn apply(value: u128) -> u128 {
14145 value
14146 }
14147}
14148
14149#[derive(Debug, Default, Clone, Copy)]
14153pub struct W160;
14154
14155#[derive(Debug, Default, Clone, Copy)]
14157pub struct W192;
14158
14159#[derive(Debug, Default, Clone, Copy)]
14161pub struct W224;
14162
14163#[derive(Debug, Default, Clone, Copy)]
14165pub struct W256;
14166
14167#[derive(Debug, Default, Clone, Copy)]
14169pub struct W384;
14170
14171#[derive(Debug, Default, Clone, Copy)]
14173pub struct W448;
14174
14175#[derive(Debug, Default, Clone, Copy)]
14177pub struct W512;
14178
14179#[derive(Debug, Default, Clone, Copy)]
14181pub struct W520;
14182
14183#[derive(Debug, Default, Clone, Copy)]
14185pub struct W528;
14186
14187#[derive(Debug, Default, Clone, Copy)]
14189pub struct W1024;
14190
14191#[derive(Debug, Default, Clone, Copy)]
14193pub struct W2048;
14194
14195#[derive(Debug, Default, Clone, Copy)]
14197pub struct W4096;
14198
14199#[derive(Debug, Default, Clone, Copy)]
14201pub struct W8192;
14202
14203#[derive(Debug, Default, Clone, Copy)]
14205pub struct W12288;
14206
14207#[derive(Debug, Default, Clone, Copy)]
14209pub struct W16384;
14210
14211#[derive(Debug, Default, Clone, Copy)]
14213pub struct W32768;
14214
14215impl RingOp<W160> for Mul<W160> {
14216 type Operand = Limbs<3>;
14217 #[inline]
14218 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14219 a.wrapping_mul(b).mask_high_bits(160)
14220 }
14221}
14222
14223impl RingOp<W160> for Add<W160> {
14224 type Operand = Limbs<3>;
14225 #[inline]
14226 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14227 a.wrapping_add(b).mask_high_bits(160)
14228 }
14229}
14230
14231impl RingOp<W160> for Sub<W160> {
14232 type Operand = Limbs<3>;
14233 #[inline]
14234 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14235 a.wrapping_sub(b).mask_high_bits(160)
14236 }
14237}
14238
14239impl RingOp<W160> for Xor<W160> {
14240 type Operand = Limbs<3>;
14241 #[inline]
14242 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14243 a.xor(b).mask_high_bits(160)
14244 }
14245}
14246
14247impl RingOp<W160> for And<W160> {
14248 type Operand = Limbs<3>;
14249 #[inline]
14250 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14251 a.and(b).mask_high_bits(160)
14252 }
14253}
14254
14255impl RingOp<W160> for Or<W160> {
14256 type Operand = Limbs<3>;
14257 #[inline]
14258 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14259 a.or(b).mask_high_bits(160)
14260 }
14261}
14262
14263impl UnaryRingOp<W160> for Neg<W160> {
14264 type Operand = Limbs<3>;
14265 #[inline]
14266 fn apply(a: Limbs<3>) -> Limbs<3> {
14267 (Limbs::<3>::zero().wrapping_sub(a)).mask_high_bits(160)
14268 }
14269}
14270
14271impl UnaryRingOp<W160> for BNot<W160> {
14272 type Operand = Limbs<3>;
14273 #[inline]
14274 fn apply(a: Limbs<3>) -> Limbs<3> {
14275 (a.not()).mask_high_bits(160)
14276 }
14277}
14278
14279impl UnaryRingOp<W160> for Succ<W160> {
14280 type Operand = Limbs<3>;
14281 #[inline]
14282 fn apply(a: Limbs<3>) -> Limbs<3> {
14283 (a.wrapping_add(Limbs::<3>::from_words([1u64, 0u64, 0u64]))).mask_high_bits(160)
14284 }
14285}
14286
14287impl RingOp<W192> for Mul<W192> {
14288 type Operand = Limbs<3>;
14289 #[inline]
14290 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14291 a.wrapping_mul(b)
14292 }
14293}
14294
14295impl RingOp<W192> for Add<W192> {
14296 type Operand = Limbs<3>;
14297 #[inline]
14298 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14299 a.wrapping_add(b)
14300 }
14301}
14302
14303impl RingOp<W192> for Sub<W192> {
14304 type Operand = Limbs<3>;
14305 #[inline]
14306 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14307 a.wrapping_sub(b)
14308 }
14309}
14310
14311impl RingOp<W192> for Xor<W192> {
14312 type Operand = Limbs<3>;
14313 #[inline]
14314 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14315 a.xor(b)
14316 }
14317}
14318
14319impl RingOp<W192> for And<W192> {
14320 type Operand = Limbs<3>;
14321 #[inline]
14322 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14323 a.and(b)
14324 }
14325}
14326
14327impl RingOp<W192> for Or<W192> {
14328 type Operand = Limbs<3>;
14329 #[inline]
14330 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14331 a.or(b)
14332 }
14333}
14334
14335impl UnaryRingOp<W192> for Neg<W192> {
14336 type Operand = Limbs<3>;
14337 #[inline]
14338 fn apply(a: Limbs<3>) -> Limbs<3> {
14339 Limbs::<3>::zero().wrapping_sub(a)
14340 }
14341}
14342
14343impl UnaryRingOp<W192> for BNot<W192> {
14344 type Operand = Limbs<3>;
14345 #[inline]
14346 fn apply(a: Limbs<3>) -> Limbs<3> {
14347 a.not()
14348 }
14349}
14350
14351impl UnaryRingOp<W192> for Succ<W192> {
14352 type Operand = Limbs<3>;
14353 #[inline]
14354 fn apply(a: Limbs<3>) -> Limbs<3> {
14355 a.wrapping_add(Limbs::<3>::from_words([1u64, 0u64, 0u64]))
14356 }
14357}
14358
14359impl RingOp<W224> for Mul<W224> {
14360 type Operand = Limbs<4>;
14361 #[inline]
14362 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14363 a.wrapping_mul(b).mask_high_bits(224)
14364 }
14365}
14366
14367impl RingOp<W224> for Add<W224> {
14368 type Operand = Limbs<4>;
14369 #[inline]
14370 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14371 a.wrapping_add(b).mask_high_bits(224)
14372 }
14373}
14374
14375impl RingOp<W224> for Sub<W224> {
14376 type Operand = Limbs<4>;
14377 #[inline]
14378 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14379 a.wrapping_sub(b).mask_high_bits(224)
14380 }
14381}
14382
14383impl RingOp<W224> for Xor<W224> {
14384 type Operand = Limbs<4>;
14385 #[inline]
14386 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14387 a.xor(b).mask_high_bits(224)
14388 }
14389}
14390
14391impl RingOp<W224> for And<W224> {
14392 type Operand = Limbs<4>;
14393 #[inline]
14394 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14395 a.and(b).mask_high_bits(224)
14396 }
14397}
14398
14399impl RingOp<W224> for Or<W224> {
14400 type Operand = Limbs<4>;
14401 #[inline]
14402 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14403 a.or(b).mask_high_bits(224)
14404 }
14405}
14406
14407impl UnaryRingOp<W224> for Neg<W224> {
14408 type Operand = Limbs<4>;
14409 #[inline]
14410 fn apply(a: Limbs<4>) -> Limbs<4> {
14411 (Limbs::<4>::zero().wrapping_sub(a)).mask_high_bits(224)
14412 }
14413}
14414
14415impl UnaryRingOp<W224> for BNot<W224> {
14416 type Operand = Limbs<4>;
14417 #[inline]
14418 fn apply(a: Limbs<4>) -> Limbs<4> {
14419 (a.not()).mask_high_bits(224)
14420 }
14421}
14422
14423impl UnaryRingOp<W224> for Succ<W224> {
14424 type Operand = Limbs<4>;
14425 #[inline]
14426 fn apply(a: Limbs<4>) -> Limbs<4> {
14427 (a.wrapping_add(Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64]))).mask_high_bits(224)
14428 }
14429}
14430
14431impl RingOp<W256> for Mul<W256> {
14432 type Operand = Limbs<4>;
14433 #[inline]
14434 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14435 a.wrapping_mul(b)
14436 }
14437}
14438
14439impl RingOp<W256> for Add<W256> {
14440 type Operand = Limbs<4>;
14441 #[inline]
14442 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14443 a.wrapping_add(b)
14444 }
14445}
14446
14447impl RingOp<W256> for Sub<W256> {
14448 type Operand = Limbs<4>;
14449 #[inline]
14450 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14451 a.wrapping_sub(b)
14452 }
14453}
14454
14455impl RingOp<W256> for Xor<W256> {
14456 type Operand = Limbs<4>;
14457 #[inline]
14458 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14459 a.xor(b)
14460 }
14461}
14462
14463impl RingOp<W256> for And<W256> {
14464 type Operand = Limbs<4>;
14465 #[inline]
14466 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14467 a.and(b)
14468 }
14469}
14470
14471impl RingOp<W256> for Or<W256> {
14472 type Operand = Limbs<4>;
14473 #[inline]
14474 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14475 a.or(b)
14476 }
14477}
14478
14479impl UnaryRingOp<W256> for Neg<W256> {
14480 type Operand = Limbs<4>;
14481 #[inline]
14482 fn apply(a: Limbs<4>) -> Limbs<4> {
14483 Limbs::<4>::zero().wrapping_sub(a)
14484 }
14485}
14486
14487impl UnaryRingOp<W256> for BNot<W256> {
14488 type Operand = Limbs<4>;
14489 #[inline]
14490 fn apply(a: Limbs<4>) -> Limbs<4> {
14491 a.not()
14492 }
14493}
14494
14495impl UnaryRingOp<W256> for Succ<W256> {
14496 type Operand = Limbs<4>;
14497 #[inline]
14498 fn apply(a: Limbs<4>) -> Limbs<4> {
14499 a.wrapping_add(Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64]))
14500 }
14501}
14502
14503impl RingOp<W384> for Mul<W384> {
14504 type Operand = Limbs<6>;
14505 #[inline]
14506 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14507 a.wrapping_mul(b)
14508 }
14509}
14510
14511impl RingOp<W384> for Add<W384> {
14512 type Operand = Limbs<6>;
14513 #[inline]
14514 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14515 a.wrapping_add(b)
14516 }
14517}
14518
14519impl RingOp<W384> for Sub<W384> {
14520 type Operand = Limbs<6>;
14521 #[inline]
14522 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14523 a.wrapping_sub(b)
14524 }
14525}
14526
14527impl RingOp<W384> for Xor<W384> {
14528 type Operand = Limbs<6>;
14529 #[inline]
14530 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14531 a.xor(b)
14532 }
14533}
14534
14535impl RingOp<W384> for And<W384> {
14536 type Operand = Limbs<6>;
14537 #[inline]
14538 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14539 a.and(b)
14540 }
14541}
14542
14543impl RingOp<W384> for Or<W384> {
14544 type Operand = Limbs<6>;
14545 #[inline]
14546 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14547 a.or(b)
14548 }
14549}
14550
14551impl UnaryRingOp<W384> for Neg<W384> {
14552 type Operand = Limbs<6>;
14553 #[inline]
14554 fn apply(a: Limbs<6>) -> Limbs<6> {
14555 Limbs::<6>::zero().wrapping_sub(a)
14556 }
14557}
14558
14559impl UnaryRingOp<W384> for BNot<W384> {
14560 type Operand = Limbs<6>;
14561 #[inline]
14562 fn apply(a: Limbs<6>) -> Limbs<6> {
14563 a.not()
14564 }
14565}
14566
14567impl UnaryRingOp<W384> for Succ<W384> {
14568 type Operand = Limbs<6>;
14569 #[inline]
14570 fn apply(a: Limbs<6>) -> Limbs<6> {
14571 a.wrapping_add(Limbs::<6>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64]))
14572 }
14573}
14574
14575impl RingOp<W448> for Mul<W448> {
14576 type Operand = Limbs<7>;
14577 #[inline]
14578 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14579 a.wrapping_mul(b)
14580 }
14581}
14582
14583impl RingOp<W448> for Add<W448> {
14584 type Operand = Limbs<7>;
14585 #[inline]
14586 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14587 a.wrapping_add(b)
14588 }
14589}
14590
14591impl RingOp<W448> for Sub<W448> {
14592 type Operand = Limbs<7>;
14593 #[inline]
14594 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14595 a.wrapping_sub(b)
14596 }
14597}
14598
14599impl RingOp<W448> for Xor<W448> {
14600 type Operand = Limbs<7>;
14601 #[inline]
14602 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14603 a.xor(b)
14604 }
14605}
14606
14607impl RingOp<W448> for And<W448> {
14608 type Operand = Limbs<7>;
14609 #[inline]
14610 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14611 a.and(b)
14612 }
14613}
14614
14615impl RingOp<W448> for Or<W448> {
14616 type Operand = Limbs<7>;
14617 #[inline]
14618 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14619 a.or(b)
14620 }
14621}
14622
14623impl UnaryRingOp<W448> for Neg<W448> {
14624 type Operand = Limbs<7>;
14625 #[inline]
14626 fn apply(a: Limbs<7>) -> Limbs<7> {
14627 Limbs::<7>::zero().wrapping_sub(a)
14628 }
14629}
14630
14631impl UnaryRingOp<W448> for BNot<W448> {
14632 type Operand = Limbs<7>;
14633 #[inline]
14634 fn apply(a: Limbs<7>) -> Limbs<7> {
14635 a.not()
14636 }
14637}
14638
14639impl UnaryRingOp<W448> for Succ<W448> {
14640 type Operand = Limbs<7>;
14641 #[inline]
14642 fn apply(a: Limbs<7>) -> Limbs<7> {
14643 a.wrapping_add(Limbs::<7>::from_words([
14644 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14645 ]))
14646 }
14647}
14648
14649impl RingOp<W512> for Mul<W512> {
14650 type Operand = Limbs<8>;
14651 #[inline]
14652 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14653 a.wrapping_mul(b)
14654 }
14655}
14656
14657impl RingOp<W512> for Add<W512> {
14658 type Operand = Limbs<8>;
14659 #[inline]
14660 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14661 a.wrapping_add(b)
14662 }
14663}
14664
14665impl RingOp<W512> for Sub<W512> {
14666 type Operand = Limbs<8>;
14667 #[inline]
14668 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14669 a.wrapping_sub(b)
14670 }
14671}
14672
14673impl RingOp<W512> for Xor<W512> {
14674 type Operand = Limbs<8>;
14675 #[inline]
14676 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14677 a.xor(b)
14678 }
14679}
14680
14681impl RingOp<W512> for And<W512> {
14682 type Operand = Limbs<8>;
14683 #[inline]
14684 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14685 a.and(b)
14686 }
14687}
14688
14689impl RingOp<W512> for Or<W512> {
14690 type Operand = Limbs<8>;
14691 #[inline]
14692 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14693 a.or(b)
14694 }
14695}
14696
14697impl UnaryRingOp<W512> for Neg<W512> {
14698 type Operand = Limbs<8>;
14699 #[inline]
14700 fn apply(a: Limbs<8>) -> Limbs<8> {
14701 Limbs::<8>::zero().wrapping_sub(a)
14702 }
14703}
14704
14705impl UnaryRingOp<W512> for BNot<W512> {
14706 type Operand = Limbs<8>;
14707 #[inline]
14708 fn apply(a: Limbs<8>) -> Limbs<8> {
14709 a.not()
14710 }
14711}
14712
14713impl UnaryRingOp<W512> for Succ<W512> {
14714 type Operand = Limbs<8>;
14715 #[inline]
14716 fn apply(a: Limbs<8>) -> Limbs<8> {
14717 a.wrapping_add(Limbs::<8>::from_words([
14718 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14719 ]))
14720 }
14721}
14722
14723impl RingOp<W520> for Mul<W520> {
14724 type Operand = Limbs<9>;
14725 #[inline]
14726 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14727 a.wrapping_mul(b).mask_high_bits(520)
14728 }
14729}
14730
14731impl RingOp<W520> for Add<W520> {
14732 type Operand = Limbs<9>;
14733 #[inline]
14734 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14735 a.wrapping_add(b).mask_high_bits(520)
14736 }
14737}
14738
14739impl RingOp<W520> for Sub<W520> {
14740 type Operand = Limbs<9>;
14741 #[inline]
14742 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14743 a.wrapping_sub(b).mask_high_bits(520)
14744 }
14745}
14746
14747impl RingOp<W520> for Xor<W520> {
14748 type Operand = Limbs<9>;
14749 #[inline]
14750 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14751 a.xor(b).mask_high_bits(520)
14752 }
14753}
14754
14755impl RingOp<W520> for And<W520> {
14756 type Operand = Limbs<9>;
14757 #[inline]
14758 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14759 a.and(b).mask_high_bits(520)
14760 }
14761}
14762
14763impl RingOp<W520> for Or<W520> {
14764 type Operand = Limbs<9>;
14765 #[inline]
14766 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14767 a.or(b).mask_high_bits(520)
14768 }
14769}
14770
14771impl UnaryRingOp<W520> for Neg<W520> {
14772 type Operand = Limbs<9>;
14773 #[inline]
14774 fn apply(a: Limbs<9>) -> Limbs<9> {
14775 (Limbs::<9>::zero().wrapping_sub(a)).mask_high_bits(520)
14776 }
14777}
14778
14779impl UnaryRingOp<W520> for BNot<W520> {
14780 type Operand = Limbs<9>;
14781 #[inline]
14782 fn apply(a: Limbs<9>) -> Limbs<9> {
14783 (a.not()).mask_high_bits(520)
14784 }
14785}
14786
14787impl UnaryRingOp<W520> for Succ<W520> {
14788 type Operand = Limbs<9>;
14789 #[inline]
14790 fn apply(a: Limbs<9>) -> Limbs<9> {
14791 (a.wrapping_add(Limbs::<9>::from_words([
14792 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14793 ])))
14794 .mask_high_bits(520)
14795 }
14796}
14797
14798impl RingOp<W528> for Mul<W528> {
14799 type Operand = Limbs<9>;
14800 #[inline]
14801 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14802 a.wrapping_mul(b).mask_high_bits(528)
14803 }
14804}
14805
14806impl RingOp<W528> for Add<W528> {
14807 type Operand = Limbs<9>;
14808 #[inline]
14809 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14810 a.wrapping_add(b).mask_high_bits(528)
14811 }
14812}
14813
14814impl RingOp<W528> for Sub<W528> {
14815 type Operand = Limbs<9>;
14816 #[inline]
14817 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14818 a.wrapping_sub(b).mask_high_bits(528)
14819 }
14820}
14821
14822impl RingOp<W528> for Xor<W528> {
14823 type Operand = Limbs<9>;
14824 #[inline]
14825 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14826 a.xor(b).mask_high_bits(528)
14827 }
14828}
14829
14830impl RingOp<W528> for And<W528> {
14831 type Operand = Limbs<9>;
14832 #[inline]
14833 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14834 a.and(b).mask_high_bits(528)
14835 }
14836}
14837
14838impl RingOp<W528> for Or<W528> {
14839 type Operand = Limbs<9>;
14840 #[inline]
14841 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14842 a.or(b).mask_high_bits(528)
14843 }
14844}
14845
14846impl UnaryRingOp<W528> for Neg<W528> {
14847 type Operand = Limbs<9>;
14848 #[inline]
14849 fn apply(a: Limbs<9>) -> Limbs<9> {
14850 (Limbs::<9>::zero().wrapping_sub(a)).mask_high_bits(528)
14851 }
14852}
14853
14854impl UnaryRingOp<W528> for BNot<W528> {
14855 type Operand = Limbs<9>;
14856 #[inline]
14857 fn apply(a: Limbs<9>) -> Limbs<9> {
14858 (a.not()).mask_high_bits(528)
14859 }
14860}
14861
14862impl UnaryRingOp<W528> for Succ<W528> {
14863 type Operand = Limbs<9>;
14864 #[inline]
14865 fn apply(a: Limbs<9>) -> Limbs<9> {
14866 (a.wrapping_add(Limbs::<9>::from_words([
14867 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14868 ])))
14869 .mask_high_bits(528)
14870 }
14871}
14872
14873impl RingOp<W1024> for Mul<W1024> {
14874 type Operand = Limbs<16>;
14875 #[inline]
14876 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14877 a.wrapping_mul(b)
14878 }
14879}
14880
14881impl RingOp<W1024> for Add<W1024> {
14882 type Operand = Limbs<16>;
14883 #[inline]
14884 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14885 a.wrapping_add(b)
14886 }
14887}
14888
14889impl RingOp<W1024> for Sub<W1024> {
14890 type Operand = Limbs<16>;
14891 #[inline]
14892 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14893 a.wrapping_sub(b)
14894 }
14895}
14896
14897impl RingOp<W1024> for Xor<W1024> {
14898 type Operand = Limbs<16>;
14899 #[inline]
14900 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14901 a.xor(b)
14902 }
14903}
14904
14905impl RingOp<W1024> for And<W1024> {
14906 type Operand = Limbs<16>;
14907 #[inline]
14908 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14909 a.and(b)
14910 }
14911}
14912
14913impl RingOp<W1024> for Or<W1024> {
14914 type Operand = Limbs<16>;
14915 #[inline]
14916 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14917 a.or(b)
14918 }
14919}
14920
14921impl UnaryRingOp<W1024> for Neg<W1024> {
14922 type Operand = Limbs<16>;
14923 #[inline]
14924 fn apply(a: Limbs<16>) -> Limbs<16> {
14925 Limbs::<16>::zero().wrapping_sub(a)
14926 }
14927}
14928
14929impl UnaryRingOp<W1024> for BNot<W1024> {
14930 type Operand = Limbs<16>;
14931 #[inline]
14932 fn apply(a: Limbs<16>) -> Limbs<16> {
14933 a.not()
14934 }
14935}
14936
14937impl UnaryRingOp<W1024> for Succ<W1024> {
14938 type Operand = Limbs<16>;
14939 #[inline]
14940 fn apply(a: Limbs<16>) -> Limbs<16> {
14941 a.wrapping_add(Limbs::<16>::from_words([
14942 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14943 0u64, 0u64,
14944 ]))
14945 }
14946}
14947
14948impl RingOp<W2048> for Mul<W2048> {
14949 type Operand = Limbs<32>;
14950 #[inline]
14951 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14952 a.wrapping_mul(b)
14953 }
14954}
14955
14956impl RingOp<W2048> for Add<W2048> {
14957 type Operand = Limbs<32>;
14958 #[inline]
14959 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14960 a.wrapping_add(b)
14961 }
14962}
14963
14964impl RingOp<W2048> for Sub<W2048> {
14965 type Operand = Limbs<32>;
14966 #[inline]
14967 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14968 a.wrapping_sub(b)
14969 }
14970}
14971
14972impl RingOp<W2048> for Xor<W2048> {
14973 type Operand = Limbs<32>;
14974 #[inline]
14975 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14976 a.xor(b)
14977 }
14978}
14979
14980impl RingOp<W2048> for And<W2048> {
14981 type Operand = Limbs<32>;
14982 #[inline]
14983 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14984 a.and(b)
14985 }
14986}
14987
14988impl RingOp<W2048> for Or<W2048> {
14989 type Operand = Limbs<32>;
14990 #[inline]
14991 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14992 a.or(b)
14993 }
14994}
14995
14996impl UnaryRingOp<W2048> for Neg<W2048> {
14997 type Operand = Limbs<32>;
14998 #[inline]
14999 fn apply(a: Limbs<32>) -> Limbs<32> {
15000 Limbs::<32>::zero().wrapping_sub(a)
15001 }
15002}
15003
15004impl UnaryRingOp<W2048> for BNot<W2048> {
15005 type Operand = Limbs<32>;
15006 #[inline]
15007 fn apply(a: Limbs<32>) -> Limbs<32> {
15008 a.not()
15009 }
15010}
15011
15012impl UnaryRingOp<W2048> for Succ<W2048> {
15013 type Operand = Limbs<32>;
15014 #[inline]
15015 fn apply(a: Limbs<32>) -> Limbs<32> {
15016 a.wrapping_add(Limbs::<32>::from_words([
15017 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15018 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15019 0u64, 0u64, 0u64, 0u64,
15020 ]))
15021 }
15022}
15023
15024impl RingOp<W4096> for Mul<W4096> {
15025 type Operand = Limbs<64>;
15026 #[inline]
15027 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15028 a.wrapping_mul(b)
15029 }
15030}
15031
15032impl RingOp<W4096> for Add<W4096> {
15033 type Operand = Limbs<64>;
15034 #[inline]
15035 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15036 a.wrapping_add(b)
15037 }
15038}
15039
15040impl RingOp<W4096> for Sub<W4096> {
15041 type Operand = Limbs<64>;
15042 #[inline]
15043 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15044 a.wrapping_sub(b)
15045 }
15046}
15047
15048impl RingOp<W4096> for Xor<W4096> {
15049 type Operand = Limbs<64>;
15050 #[inline]
15051 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15052 a.xor(b)
15053 }
15054}
15055
15056impl RingOp<W4096> for And<W4096> {
15057 type Operand = Limbs<64>;
15058 #[inline]
15059 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15060 a.and(b)
15061 }
15062}
15063
15064impl RingOp<W4096> for Or<W4096> {
15065 type Operand = Limbs<64>;
15066 #[inline]
15067 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
15068 a.or(b)
15069 }
15070}
15071
15072impl UnaryRingOp<W4096> for Neg<W4096> {
15073 type Operand = Limbs<64>;
15074 #[inline]
15075 fn apply(a: Limbs<64>) -> Limbs<64> {
15076 Limbs::<64>::zero().wrapping_sub(a)
15077 }
15078}
15079
15080impl UnaryRingOp<W4096> for BNot<W4096> {
15081 type Operand = Limbs<64>;
15082 #[inline]
15083 fn apply(a: Limbs<64>) -> Limbs<64> {
15084 a.not()
15085 }
15086}
15087
15088impl UnaryRingOp<W4096> for Succ<W4096> {
15089 type Operand = Limbs<64>;
15090 #[inline]
15091 fn apply(a: Limbs<64>) -> Limbs<64> {
15092 a.wrapping_add(Limbs::<64>::from_words([
15093 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15094 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15095 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15096 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15097 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15098 ]))
15099 }
15100}
15101
15102impl RingOp<W8192> for Mul<W8192> {
15103 type Operand = Limbs<128>;
15104 #[inline]
15105 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15106 a.wrapping_mul(b)
15107 }
15108}
15109
15110impl RingOp<W8192> for Add<W8192> {
15111 type Operand = Limbs<128>;
15112 #[inline]
15113 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15114 a.wrapping_add(b)
15115 }
15116}
15117
15118impl RingOp<W8192> for Sub<W8192> {
15119 type Operand = Limbs<128>;
15120 #[inline]
15121 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15122 a.wrapping_sub(b)
15123 }
15124}
15125
15126impl RingOp<W8192> for Xor<W8192> {
15127 type Operand = Limbs<128>;
15128 #[inline]
15129 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15130 a.xor(b)
15131 }
15132}
15133
15134impl RingOp<W8192> for And<W8192> {
15135 type Operand = Limbs<128>;
15136 #[inline]
15137 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15138 a.and(b)
15139 }
15140}
15141
15142impl RingOp<W8192> for Or<W8192> {
15143 type Operand = Limbs<128>;
15144 #[inline]
15145 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15146 a.or(b)
15147 }
15148}
15149
15150impl UnaryRingOp<W8192> for Neg<W8192> {
15151 type Operand = Limbs<128>;
15152 #[inline]
15153 fn apply(a: Limbs<128>) -> Limbs<128> {
15154 Limbs::<128>::zero().wrapping_sub(a)
15155 }
15156}
15157
15158impl UnaryRingOp<W8192> for BNot<W8192> {
15159 type Operand = Limbs<128>;
15160 #[inline]
15161 fn apply(a: Limbs<128>) -> Limbs<128> {
15162 a.not()
15163 }
15164}
15165
15166impl UnaryRingOp<W8192> for Succ<W8192> {
15167 type Operand = Limbs<128>;
15168 #[inline]
15169 fn apply(a: Limbs<128>) -> Limbs<128> {
15170 a.wrapping_add(Limbs::<128>::from_words([
15171 1u64, 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, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15174 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15175 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15176 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15177 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15178 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15179 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15180 0u64, 0u64,
15181 ]))
15182 }
15183}
15184
15185impl RingOp<W12288> for Mul<W12288> {
15186 type Operand = Limbs<192>;
15187 #[inline]
15188 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15189 a.wrapping_mul(b)
15190 }
15191}
15192
15193impl RingOp<W12288> for Add<W12288> {
15194 type Operand = Limbs<192>;
15195 #[inline]
15196 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15197 a.wrapping_add(b)
15198 }
15199}
15200
15201impl RingOp<W12288> for Sub<W12288> {
15202 type Operand = Limbs<192>;
15203 #[inline]
15204 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15205 a.wrapping_sub(b)
15206 }
15207}
15208
15209impl RingOp<W12288> for Xor<W12288> {
15210 type Operand = Limbs<192>;
15211 #[inline]
15212 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15213 a.xor(b)
15214 }
15215}
15216
15217impl RingOp<W12288> for And<W12288> {
15218 type Operand = Limbs<192>;
15219 #[inline]
15220 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15221 a.and(b)
15222 }
15223}
15224
15225impl RingOp<W12288> for Or<W12288> {
15226 type Operand = Limbs<192>;
15227 #[inline]
15228 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15229 a.or(b)
15230 }
15231}
15232
15233impl UnaryRingOp<W12288> for Neg<W12288> {
15234 type Operand = Limbs<192>;
15235 #[inline]
15236 fn apply(a: Limbs<192>) -> Limbs<192> {
15237 Limbs::<192>::zero().wrapping_sub(a)
15238 }
15239}
15240
15241impl UnaryRingOp<W12288> for BNot<W12288> {
15242 type Operand = Limbs<192>;
15243 #[inline]
15244 fn apply(a: Limbs<192>) -> Limbs<192> {
15245 a.not()
15246 }
15247}
15248
15249impl UnaryRingOp<W12288> for Succ<W12288> {
15250 type Operand = Limbs<192>;
15251 #[inline]
15252 fn apply(a: Limbs<192>) -> Limbs<192> {
15253 a.wrapping_add(Limbs::<192>::from_words([
15254 1u64, 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, 0u64, 0u64, 0u64, 0u64,
15261 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15262 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15263 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15264 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15265 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15266 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15267 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15268 ]))
15269 }
15270}
15271
15272impl RingOp<W16384> for Mul<W16384> {
15273 type Operand = Limbs<256>;
15274 #[inline]
15275 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15276 a.wrapping_mul(b)
15277 }
15278}
15279
15280impl RingOp<W16384> for Add<W16384> {
15281 type Operand = Limbs<256>;
15282 #[inline]
15283 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15284 a.wrapping_add(b)
15285 }
15286}
15287
15288impl RingOp<W16384> for Sub<W16384> {
15289 type Operand = Limbs<256>;
15290 #[inline]
15291 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15292 a.wrapping_sub(b)
15293 }
15294}
15295
15296impl RingOp<W16384> for Xor<W16384> {
15297 type Operand = Limbs<256>;
15298 #[inline]
15299 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15300 a.xor(b)
15301 }
15302}
15303
15304impl RingOp<W16384> for And<W16384> {
15305 type Operand = Limbs<256>;
15306 #[inline]
15307 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15308 a.and(b)
15309 }
15310}
15311
15312impl RingOp<W16384> for Or<W16384> {
15313 type Operand = Limbs<256>;
15314 #[inline]
15315 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15316 a.or(b)
15317 }
15318}
15319
15320impl UnaryRingOp<W16384> for Neg<W16384> {
15321 type Operand = Limbs<256>;
15322 #[inline]
15323 fn apply(a: Limbs<256>) -> Limbs<256> {
15324 Limbs::<256>::zero().wrapping_sub(a)
15325 }
15326}
15327
15328impl UnaryRingOp<W16384> for BNot<W16384> {
15329 type Operand = Limbs<256>;
15330 #[inline]
15331 fn apply(a: Limbs<256>) -> Limbs<256> {
15332 a.not()
15333 }
15334}
15335
15336impl UnaryRingOp<W16384> for Succ<W16384> {
15337 type Operand = Limbs<256>;
15338 #[inline]
15339 fn apply(a: Limbs<256>) -> Limbs<256> {
15340 a.wrapping_add(Limbs::<256>::from_words([
15341 1u64, 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, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15353 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15354 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15355 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15356 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15357 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15358 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15359 0u64, 0u64, 0u64, 0u64,
15360 ]))
15361 }
15362}
15363
15364impl RingOp<W32768> for Mul<W32768> {
15365 type Operand = Limbs<512>;
15366 #[inline]
15367 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15368 a.wrapping_mul(b)
15369 }
15370}
15371
15372impl RingOp<W32768> for Add<W32768> {
15373 type Operand = Limbs<512>;
15374 #[inline]
15375 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15376 a.wrapping_add(b)
15377 }
15378}
15379
15380impl RingOp<W32768> for Sub<W32768> {
15381 type Operand = Limbs<512>;
15382 #[inline]
15383 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15384 a.wrapping_sub(b)
15385 }
15386}
15387
15388impl RingOp<W32768> for Xor<W32768> {
15389 type Operand = Limbs<512>;
15390 #[inline]
15391 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15392 a.xor(b)
15393 }
15394}
15395
15396impl RingOp<W32768> for And<W32768> {
15397 type Operand = Limbs<512>;
15398 #[inline]
15399 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15400 a.and(b)
15401 }
15402}
15403
15404impl RingOp<W32768> for Or<W32768> {
15405 type Operand = Limbs<512>;
15406 #[inline]
15407 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15408 a.or(b)
15409 }
15410}
15411
15412impl UnaryRingOp<W32768> for Neg<W32768> {
15413 type Operand = Limbs<512>;
15414 #[inline]
15415 fn apply(a: Limbs<512>) -> Limbs<512> {
15416 Limbs::<512>::zero().wrapping_sub(a)
15417 }
15418}
15419
15420impl UnaryRingOp<W32768> for BNot<W32768> {
15421 type Operand = Limbs<512>;
15422 #[inline]
15423 fn apply(a: Limbs<512>) -> Limbs<512> {
15424 a.not()
15425 }
15426}
15427
15428impl UnaryRingOp<W32768> for Succ<W32768> {
15429 type Operand = Limbs<512>;
15430 #[inline]
15431 fn apply(a: Limbs<512>) -> Limbs<512> {
15432 a.wrapping_add(Limbs::<512>::from_words([
15433 1u64, 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, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15463 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15464 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15465 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15466 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15467 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15468 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15469 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15470 ]))
15471 }
15472}
15473
15474#[inline]
15481#[must_use]
15482pub const fn const_ring_eval_w160(op: PrimitiveOp, a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
15483 let raw = match op {
15484 PrimitiveOp::Add => a.wrapping_add(b),
15485 PrimitiveOp::Sub => a.wrapping_sub(b),
15486 PrimitiveOp::Mul => a.wrapping_mul(b),
15487 PrimitiveOp::And => a.and(b),
15488 PrimitiveOp::Or => a.or(b),
15489 PrimitiveOp::Xor => a.xor(b),
15490 PrimitiveOp::Neg => Limbs::<3>::zero().wrapping_sub(a),
15491 PrimitiveOp::Bnot => a.not(),
15492 PrimitiveOp::Succ => a.wrapping_add(limbs_one_3()),
15493 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_3()),
15494 PrimitiveOp::Le => {
15495 if limbs_le_3(a, b) {
15496 limbs_one_3()
15497 } else {
15498 Limbs::<3>::zero()
15499 }
15500 }
15501 PrimitiveOp::Lt => {
15502 if limbs_lt_3(a, b) {
15503 limbs_one_3()
15504 } else {
15505 Limbs::<3>::zero()
15506 }
15507 }
15508 PrimitiveOp::Ge => {
15509 if limbs_le_3(b, a) {
15510 limbs_one_3()
15511 } else {
15512 Limbs::<3>::zero()
15513 }
15514 }
15515 PrimitiveOp::Gt => {
15516 if limbs_lt_3(b, a) {
15517 limbs_one_3()
15518 } else {
15519 Limbs::<3>::zero()
15520 }
15521 }
15522 PrimitiveOp::Concat => Limbs::<3>::zero(),
15523 PrimitiveOp::Div => {
15524 if limbs_is_zero_3(b) {
15525 Limbs::<3>::zero()
15526 } else {
15527 limbs_div_3(a, b)
15528 }
15529 }
15530 PrimitiveOp::Mod => {
15531 if limbs_is_zero_3(b) {
15532 Limbs::<3>::zero()
15533 } else {
15534 limbs_mod_3(a, b)
15535 }
15536 }
15537 PrimitiveOp::Pow => limbs_pow_3(a, b),
15538 };
15539 raw.mask_high_bits(160)
15540}
15541
15542#[inline]
15543#[must_use]
15544pub const fn const_ring_eval_w192(op: PrimitiveOp, a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
15545 match op {
15546 PrimitiveOp::Add => a.wrapping_add(b),
15547 PrimitiveOp::Sub => a.wrapping_sub(b),
15548 PrimitiveOp::Mul => a.wrapping_mul(b),
15549 PrimitiveOp::And => a.and(b),
15550 PrimitiveOp::Or => a.or(b),
15551 PrimitiveOp::Xor => a.xor(b),
15552 PrimitiveOp::Neg => Limbs::<3>::zero().wrapping_sub(a),
15553 PrimitiveOp::Bnot => a.not(),
15554 PrimitiveOp::Succ => a.wrapping_add(limbs_one_3()),
15555 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_3()),
15556 PrimitiveOp::Le => {
15557 if limbs_le_3(a, b) {
15558 limbs_one_3()
15559 } else {
15560 Limbs::<3>::zero()
15561 }
15562 }
15563 PrimitiveOp::Lt => {
15564 if limbs_lt_3(a, b) {
15565 limbs_one_3()
15566 } else {
15567 Limbs::<3>::zero()
15568 }
15569 }
15570 PrimitiveOp::Ge => {
15571 if limbs_le_3(b, a) {
15572 limbs_one_3()
15573 } else {
15574 Limbs::<3>::zero()
15575 }
15576 }
15577 PrimitiveOp::Gt => {
15578 if limbs_lt_3(b, a) {
15579 limbs_one_3()
15580 } else {
15581 Limbs::<3>::zero()
15582 }
15583 }
15584 PrimitiveOp::Concat => Limbs::<3>::zero(),
15585 PrimitiveOp::Div => {
15586 if limbs_is_zero_3(b) {
15587 Limbs::<3>::zero()
15588 } else {
15589 limbs_div_3(a, b)
15590 }
15591 }
15592 PrimitiveOp::Mod => {
15593 if limbs_is_zero_3(b) {
15594 Limbs::<3>::zero()
15595 } else {
15596 limbs_mod_3(a, b)
15597 }
15598 }
15599 PrimitiveOp::Pow => limbs_pow_3(a, b),
15600 }
15601}
15602
15603#[inline]
15604#[must_use]
15605pub const fn const_ring_eval_w224(op: PrimitiveOp, a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
15606 let raw = match op {
15607 PrimitiveOp::Add => a.wrapping_add(b),
15608 PrimitiveOp::Sub => a.wrapping_sub(b),
15609 PrimitiveOp::Mul => a.wrapping_mul(b),
15610 PrimitiveOp::And => a.and(b),
15611 PrimitiveOp::Or => a.or(b),
15612 PrimitiveOp::Xor => a.xor(b),
15613 PrimitiveOp::Neg => Limbs::<4>::zero().wrapping_sub(a),
15614 PrimitiveOp::Bnot => a.not(),
15615 PrimitiveOp::Succ => a.wrapping_add(limbs_one_4()),
15616 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_4()),
15617 PrimitiveOp::Le => {
15618 if limbs_le_4(a, b) {
15619 limbs_one_4()
15620 } else {
15621 Limbs::<4>::zero()
15622 }
15623 }
15624 PrimitiveOp::Lt => {
15625 if limbs_lt_4(a, b) {
15626 limbs_one_4()
15627 } else {
15628 Limbs::<4>::zero()
15629 }
15630 }
15631 PrimitiveOp::Ge => {
15632 if limbs_le_4(b, a) {
15633 limbs_one_4()
15634 } else {
15635 Limbs::<4>::zero()
15636 }
15637 }
15638 PrimitiveOp::Gt => {
15639 if limbs_lt_4(b, a) {
15640 limbs_one_4()
15641 } else {
15642 Limbs::<4>::zero()
15643 }
15644 }
15645 PrimitiveOp::Concat => Limbs::<4>::zero(),
15646 PrimitiveOp::Div => {
15647 if limbs_is_zero_4(b) {
15648 Limbs::<4>::zero()
15649 } else {
15650 limbs_div_4(a, b)
15651 }
15652 }
15653 PrimitiveOp::Mod => {
15654 if limbs_is_zero_4(b) {
15655 Limbs::<4>::zero()
15656 } else {
15657 limbs_mod_4(a, b)
15658 }
15659 }
15660 PrimitiveOp::Pow => limbs_pow_4(a, b),
15661 };
15662 raw.mask_high_bits(224)
15663}
15664
15665#[inline]
15666#[must_use]
15667pub const fn const_ring_eval_w256(op: PrimitiveOp, a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
15668 match op {
15669 PrimitiveOp::Add => a.wrapping_add(b),
15670 PrimitiveOp::Sub => a.wrapping_sub(b),
15671 PrimitiveOp::Mul => a.wrapping_mul(b),
15672 PrimitiveOp::And => a.and(b),
15673 PrimitiveOp::Or => a.or(b),
15674 PrimitiveOp::Xor => a.xor(b),
15675 PrimitiveOp::Neg => Limbs::<4>::zero().wrapping_sub(a),
15676 PrimitiveOp::Bnot => a.not(),
15677 PrimitiveOp::Succ => a.wrapping_add(limbs_one_4()),
15678 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_4()),
15679 PrimitiveOp::Le => {
15680 if limbs_le_4(a, b) {
15681 limbs_one_4()
15682 } else {
15683 Limbs::<4>::zero()
15684 }
15685 }
15686 PrimitiveOp::Lt => {
15687 if limbs_lt_4(a, b) {
15688 limbs_one_4()
15689 } else {
15690 Limbs::<4>::zero()
15691 }
15692 }
15693 PrimitiveOp::Ge => {
15694 if limbs_le_4(b, a) {
15695 limbs_one_4()
15696 } else {
15697 Limbs::<4>::zero()
15698 }
15699 }
15700 PrimitiveOp::Gt => {
15701 if limbs_lt_4(b, a) {
15702 limbs_one_4()
15703 } else {
15704 Limbs::<4>::zero()
15705 }
15706 }
15707 PrimitiveOp::Concat => Limbs::<4>::zero(),
15708 PrimitiveOp::Div => {
15709 if limbs_is_zero_4(b) {
15710 Limbs::<4>::zero()
15711 } else {
15712 limbs_div_4(a, b)
15713 }
15714 }
15715 PrimitiveOp::Mod => {
15716 if limbs_is_zero_4(b) {
15717 Limbs::<4>::zero()
15718 } else {
15719 limbs_mod_4(a, b)
15720 }
15721 }
15722 PrimitiveOp::Pow => limbs_pow_4(a, b),
15723 }
15724}
15725
15726#[inline]
15727#[must_use]
15728pub const fn const_ring_eval_w384(op: PrimitiveOp, a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
15729 match op {
15730 PrimitiveOp::Add => a.wrapping_add(b),
15731 PrimitiveOp::Sub => a.wrapping_sub(b),
15732 PrimitiveOp::Mul => a.wrapping_mul(b),
15733 PrimitiveOp::And => a.and(b),
15734 PrimitiveOp::Or => a.or(b),
15735 PrimitiveOp::Xor => a.xor(b),
15736 PrimitiveOp::Neg => Limbs::<6>::zero().wrapping_sub(a),
15737 PrimitiveOp::Bnot => a.not(),
15738 PrimitiveOp::Succ => a.wrapping_add(limbs_one_6()),
15739 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_6()),
15740 PrimitiveOp::Le => {
15741 if limbs_le_6(a, b) {
15742 limbs_one_6()
15743 } else {
15744 Limbs::<6>::zero()
15745 }
15746 }
15747 PrimitiveOp::Lt => {
15748 if limbs_lt_6(a, b) {
15749 limbs_one_6()
15750 } else {
15751 Limbs::<6>::zero()
15752 }
15753 }
15754 PrimitiveOp::Ge => {
15755 if limbs_le_6(b, a) {
15756 limbs_one_6()
15757 } else {
15758 Limbs::<6>::zero()
15759 }
15760 }
15761 PrimitiveOp::Gt => {
15762 if limbs_lt_6(b, a) {
15763 limbs_one_6()
15764 } else {
15765 Limbs::<6>::zero()
15766 }
15767 }
15768 PrimitiveOp::Concat => Limbs::<6>::zero(),
15769 PrimitiveOp::Div => {
15770 if limbs_is_zero_6(b) {
15771 Limbs::<6>::zero()
15772 } else {
15773 limbs_div_6(a, b)
15774 }
15775 }
15776 PrimitiveOp::Mod => {
15777 if limbs_is_zero_6(b) {
15778 Limbs::<6>::zero()
15779 } else {
15780 limbs_mod_6(a, b)
15781 }
15782 }
15783 PrimitiveOp::Pow => limbs_pow_6(a, b),
15784 }
15785}
15786
15787#[inline]
15788#[must_use]
15789pub const fn const_ring_eval_w448(op: PrimitiveOp, a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
15790 match op {
15791 PrimitiveOp::Add => a.wrapping_add(b),
15792 PrimitiveOp::Sub => a.wrapping_sub(b),
15793 PrimitiveOp::Mul => a.wrapping_mul(b),
15794 PrimitiveOp::And => a.and(b),
15795 PrimitiveOp::Or => a.or(b),
15796 PrimitiveOp::Xor => a.xor(b),
15797 PrimitiveOp::Neg => Limbs::<7>::zero().wrapping_sub(a),
15798 PrimitiveOp::Bnot => a.not(),
15799 PrimitiveOp::Succ => a.wrapping_add(limbs_one_7()),
15800 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_7()),
15801 PrimitiveOp::Le => {
15802 if limbs_le_7(a, b) {
15803 limbs_one_7()
15804 } else {
15805 Limbs::<7>::zero()
15806 }
15807 }
15808 PrimitiveOp::Lt => {
15809 if limbs_lt_7(a, b) {
15810 limbs_one_7()
15811 } else {
15812 Limbs::<7>::zero()
15813 }
15814 }
15815 PrimitiveOp::Ge => {
15816 if limbs_le_7(b, a) {
15817 limbs_one_7()
15818 } else {
15819 Limbs::<7>::zero()
15820 }
15821 }
15822 PrimitiveOp::Gt => {
15823 if limbs_lt_7(b, a) {
15824 limbs_one_7()
15825 } else {
15826 Limbs::<7>::zero()
15827 }
15828 }
15829 PrimitiveOp::Concat => Limbs::<7>::zero(),
15830 PrimitiveOp::Div => {
15831 if limbs_is_zero_7(b) {
15832 Limbs::<7>::zero()
15833 } else {
15834 limbs_div_7(a, b)
15835 }
15836 }
15837 PrimitiveOp::Mod => {
15838 if limbs_is_zero_7(b) {
15839 Limbs::<7>::zero()
15840 } else {
15841 limbs_mod_7(a, b)
15842 }
15843 }
15844 PrimitiveOp::Pow => limbs_pow_7(a, b),
15845 }
15846}
15847
15848#[inline]
15849#[must_use]
15850pub const fn const_ring_eval_w512(op: PrimitiveOp, a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
15851 match op {
15852 PrimitiveOp::Add => a.wrapping_add(b),
15853 PrimitiveOp::Sub => a.wrapping_sub(b),
15854 PrimitiveOp::Mul => a.wrapping_mul(b),
15855 PrimitiveOp::And => a.and(b),
15856 PrimitiveOp::Or => a.or(b),
15857 PrimitiveOp::Xor => a.xor(b),
15858 PrimitiveOp::Neg => Limbs::<8>::zero().wrapping_sub(a),
15859 PrimitiveOp::Bnot => a.not(),
15860 PrimitiveOp::Succ => a.wrapping_add(limbs_one_8()),
15861 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_8()),
15862 PrimitiveOp::Le => {
15863 if limbs_le_8(a, b) {
15864 limbs_one_8()
15865 } else {
15866 Limbs::<8>::zero()
15867 }
15868 }
15869 PrimitiveOp::Lt => {
15870 if limbs_lt_8(a, b) {
15871 limbs_one_8()
15872 } else {
15873 Limbs::<8>::zero()
15874 }
15875 }
15876 PrimitiveOp::Ge => {
15877 if limbs_le_8(b, a) {
15878 limbs_one_8()
15879 } else {
15880 Limbs::<8>::zero()
15881 }
15882 }
15883 PrimitiveOp::Gt => {
15884 if limbs_lt_8(b, a) {
15885 limbs_one_8()
15886 } else {
15887 Limbs::<8>::zero()
15888 }
15889 }
15890 PrimitiveOp::Concat => Limbs::<8>::zero(),
15891 PrimitiveOp::Div => {
15892 if limbs_is_zero_8(b) {
15893 Limbs::<8>::zero()
15894 } else {
15895 limbs_div_8(a, b)
15896 }
15897 }
15898 PrimitiveOp::Mod => {
15899 if limbs_is_zero_8(b) {
15900 Limbs::<8>::zero()
15901 } else {
15902 limbs_mod_8(a, b)
15903 }
15904 }
15905 PrimitiveOp::Pow => limbs_pow_8(a, b),
15906 }
15907}
15908
15909#[inline]
15910#[must_use]
15911pub const fn const_ring_eval_w520(op: PrimitiveOp, a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
15912 let raw = match op {
15913 PrimitiveOp::Add => a.wrapping_add(b),
15914 PrimitiveOp::Sub => a.wrapping_sub(b),
15915 PrimitiveOp::Mul => a.wrapping_mul(b),
15916 PrimitiveOp::And => a.and(b),
15917 PrimitiveOp::Or => a.or(b),
15918 PrimitiveOp::Xor => a.xor(b),
15919 PrimitiveOp::Neg => Limbs::<9>::zero().wrapping_sub(a),
15920 PrimitiveOp::Bnot => a.not(),
15921 PrimitiveOp::Succ => a.wrapping_add(limbs_one_9()),
15922 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_9()),
15923 PrimitiveOp::Le => {
15924 if limbs_le_9(a, b) {
15925 limbs_one_9()
15926 } else {
15927 Limbs::<9>::zero()
15928 }
15929 }
15930 PrimitiveOp::Lt => {
15931 if limbs_lt_9(a, b) {
15932 limbs_one_9()
15933 } else {
15934 Limbs::<9>::zero()
15935 }
15936 }
15937 PrimitiveOp::Ge => {
15938 if limbs_le_9(b, a) {
15939 limbs_one_9()
15940 } else {
15941 Limbs::<9>::zero()
15942 }
15943 }
15944 PrimitiveOp::Gt => {
15945 if limbs_lt_9(b, a) {
15946 limbs_one_9()
15947 } else {
15948 Limbs::<9>::zero()
15949 }
15950 }
15951 PrimitiveOp::Concat => Limbs::<9>::zero(),
15952 PrimitiveOp::Div => {
15953 if limbs_is_zero_9(b) {
15954 Limbs::<9>::zero()
15955 } else {
15956 limbs_div_9(a, b)
15957 }
15958 }
15959 PrimitiveOp::Mod => {
15960 if limbs_is_zero_9(b) {
15961 Limbs::<9>::zero()
15962 } else {
15963 limbs_mod_9(a, b)
15964 }
15965 }
15966 PrimitiveOp::Pow => limbs_pow_9(a, b),
15967 };
15968 raw.mask_high_bits(520)
15969}
15970
15971#[inline]
15972#[must_use]
15973pub const fn const_ring_eval_w528(op: PrimitiveOp, a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
15974 let raw = match op {
15975 PrimitiveOp::Add => a.wrapping_add(b),
15976 PrimitiveOp::Sub => a.wrapping_sub(b),
15977 PrimitiveOp::Mul => a.wrapping_mul(b),
15978 PrimitiveOp::And => a.and(b),
15979 PrimitiveOp::Or => a.or(b),
15980 PrimitiveOp::Xor => a.xor(b),
15981 PrimitiveOp::Neg => Limbs::<9>::zero().wrapping_sub(a),
15982 PrimitiveOp::Bnot => a.not(),
15983 PrimitiveOp::Succ => a.wrapping_add(limbs_one_9()),
15984 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_9()),
15985 PrimitiveOp::Le => {
15986 if limbs_le_9(a, b) {
15987 limbs_one_9()
15988 } else {
15989 Limbs::<9>::zero()
15990 }
15991 }
15992 PrimitiveOp::Lt => {
15993 if limbs_lt_9(a, b) {
15994 limbs_one_9()
15995 } else {
15996 Limbs::<9>::zero()
15997 }
15998 }
15999 PrimitiveOp::Ge => {
16000 if limbs_le_9(b, a) {
16001 limbs_one_9()
16002 } else {
16003 Limbs::<9>::zero()
16004 }
16005 }
16006 PrimitiveOp::Gt => {
16007 if limbs_lt_9(b, a) {
16008 limbs_one_9()
16009 } else {
16010 Limbs::<9>::zero()
16011 }
16012 }
16013 PrimitiveOp::Concat => Limbs::<9>::zero(),
16014 PrimitiveOp::Div => {
16015 if limbs_is_zero_9(b) {
16016 Limbs::<9>::zero()
16017 } else {
16018 limbs_div_9(a, b)
16019 }
16020 }
16021 PrimitiveOp::Mod => {
16022 if limbs_is_zero_9(b) {
16023 Limbs::<9>::zero()
16024 } else {
16025 limbs_mod_9(a, b)
16026 }
16027 }
16028 PrimitiveOp::Pow => limbs_pow_9(a, b),
16029 };
16030 raw.mask_high_bits(528)
16031}
16032
16033#[inline]
16034#[must_use]
16035pub const fn const_ring_eval_w1024(op: PrimitiveOp, a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
16036 match op {
16037 PrimitiveOp::Add => a.wrapping_add(b),
16038 PrimitiveOp::Sub => a.wrapping_sub(b),
16039 PrimitiveOp::Mul => a.wrapping_mul(b),
16040 PrimitiveOp::And => a.and(b),
16041 PrimitiveOp::Or => a.or(b),
16042 PrimitiveOp::Xor => a.xor(b),
16043 PrimitiveOp::Neg => Limbs::<16>::zero().wrapping_sub(a),
16044 PrimitiveOp::Bnot => a.not(),
16045 PrimitiveOp::Succ => a.wrapping_add(limbs_one_16()),
16046 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_16()),
16047 PrimitiveOp::Le => {
16048 if limbs_le_16(a, b) {
16049 limbs_one_16()
16050 } else {
16051 Limbs::<16>::zero()
16052 }
16053 }
16054 PrimitiveOp::Lt => {
16055 if limbs_lt_16(a, b) {
16056 limbs_one_16()
16057 } else {
16058 Limbs::<16>::zero()
16059 }
16060 }
16061 PrimitiveOp::Ge => {
16062 if limbs_le_16(b, a) {
16063 limbs_one_16()
16064 } else {
16065 Limbs::<16>::zero()
16066 }
16067 }
16068 PrimitiveOp::Gt => {
16069 if limbs_lt_16(b, a) {
16070 limbs_one_16()
16071 } else {
16072 Limbs::<16>::zero()
16073 }
16074 }
16075 PrimitiveOp::Concat => Limbs::<16>::zero(),
16076 PrimitiveOp::Div => {
16077 if limbs_is_zero_16(b) {
16078 Limbs::<16>::zero()
16079 } else {
16080 limbs_div_16(a, b)
16081 }
16082 }
16083 PrimitiveOp::Mod => {
16084 if limbs_is_zero_16(b) {
16085 Limbs::<16>::zero()
16086 } else {
16087 limbs_mod_16(a, b)
16088 }
16089 }
16090 PrimitiveOp::Pow => limbs_pow_16(a, b),
16091 }
16092}
16093
16094#[inline]
16095#[must_use]
16096pub const fn const_ring_eval_w2048(op: PrimitiveOp, a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
16097 match op {
16098 PrimitiveOp::Add => a.wrapping_add(b),
16099 PrimitiveOp::Sub => a.wrapping_sub(b),
16100 PrimitiveOp::Mul => a.wrapping_mul(b),
16101 PrimitiveOp::And => a.and(b),
16102 PrimitiveOp::Or => a.or(b),
16103 PrimitiveOp::Xor => a.xor(b),
16104 PrimitiveOp::Neg => Limbs::<32>::zero().wrapping_sub(a),
16105 PrimitiveOp::Bnot => a.not(),
16106 PrimitiveOp::Succ => a.wrapping_add(limbs_one_32()),
16107 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_32()),
16108 PrimitiveOp::Le => {
16109 if limbs_le_32(a, b) {
16110 limbs_one_32()
16111 } else {
16112 Limbs::<32>::zero()
16113 }
16114 }
16115 PrimitiveOp::Lt => {
16116 if limbs_lt_32(a, b) {
16117 limbs_one_32()
16118 } else {
16119 Limbs::<32>::zero()
16120 }
16121 }
16122 PrimitiveOp::Ge => {
16123 if limbs_le_32(b, a) {
16124 limbs_one_32()
16125 } else {
16126 Limbs::<32>::zero()
16127 }
16128 }
16129 PrimitiveOp::Gt => {
16130 if limbs_lt_32(b, a) {
16131 limbs_one_32()
16132 } else {
16133 Limbs::<32>::zero()
16134 }
16135 }
16136 PrimitiveOp::Concat => Limbs::<32>::zero(),
16137 PrimitiveOp::Div => {
16138 if limbs_is_zero_32(b) {
16139 Limbs::<32>::zero()
16140 } else {
16141 limbs_div_32(a, b)
16142 }
16143 }
16144 PrimitiveOp::Mod => {
16145 if limbs_is_zero_32(b) {
16146 Limbs::<32>::zero()
16147 } else {
16148 limbs_mod_32(a, b)
16149 }
16150 }
16151 PrimitiveOp::Pow => limbs_pow_32(a, b),
16152 }
16153}
16154
16155#[inline]
16156#[must_use]
16157pub const fn const_ring_eval_w4096(op: PrimitiveOp, a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
16158 match op {
16159 PrimitiveOp::Add => a.wrapping_add(b),
16160 PrimitiveOp::Sub => a.wrapping_sub(b),
16161 PrimitiveOp::Mul => a.wrapping_mul(b),
16162 PrimitiveOp::And => a.and(b),
16163 PrimitiveOp::Or => a.or(b),
16164 PrimitiveOp::Xor => a.xor(b),
16165 PrimitiveOp::Neg => Limbs::<64>::zero().wrapping_sub(a),
16166 PrimitiveOp::Bnot => a.not(),
16167 PrimitiveOp::Succ => a.wrapping_add(limbs_one_64()),
16168 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_64()),
16169 PrimitiveOp::Le => {
16170 if limbs_le_64(a, b) {
16171 limbs_one_64()
16172 } else {
16173 Limbs::<64>::zero()
16174 }
16175 }
16176 PrimitiveOp::Lt => {
16177 if limbs_lt_64(a, b) {
16178 limbs_one_64()
16179 } else {
16180 Limbs::<64>::zero()
16181 }
16182 }
16183 PrimitiveOp::Ge => {
16184 if limbs_le_64(b, a) {
16185 limbs_one_64()
16186 } else {
16187 Limbs::<64>::zero()
16188 }
16189 }
16190 PrimitiveOp::Gt => {
16191 if limbs_lt_64(b, a) {
16192 limbs_one_64()
16193 } else {
16194 Limbs::<64>::zero()
16195 }
16196 }
16197 PrimitiveOp::Concat => Limbs::<64>::zero(),
16198 PrimitiveOp::Div => {
16199 if limbs_is_zero_64(b) {
16200 Limbs::<64>::zero()
16201 } else {
16202 limbs_div_64(a, b)
16203 }
16204 }
16205 PrimitiveOp::Mod => {
16206 if limbs_is_zero_64(b) {
16207 Limbs::<64>::zero()
16208 } else {
16209 limbs_mod_64(a, b)
16210 }
16211 }
16212 PrimitiveOp::Pow => limbs_pow_64(a, b),
16213 }
16214}
16215
16216#[inline]
16217#[must_use]
16218pub const fn const_ring_eval_w8192(op: PrimitiveOp, a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
16219 match op {
16220 PrimitiveOp::Add => a.wrapping_add(b),
16221 PrimitiveOp::Sub => a.wrapping_sub(b),
16222 PrimitiveOp::Mul => a.wrapping_mul(b),
16223 PrimitiveOp::And => a.and(b),
16224 PrimitiveOp::Or => a.or(b),
16225 PrimitiveOp::Xor => a.xor(b),
16226 PrimitiveOp::Neg => Limbs::<128>::zero().wrapping_sub(a),
16227 PrimitiveOp::Bnot => a.not(),
16228 PrimitiveOp::Succ => a.wrapping_add(limbs_one_128()),
16229 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_128()),
16230 PrimitiveOp::Le => {
16231 if limbs_le_128(a, b) {
16232 limbs_one_128()
16233 } else {
16234 Limbs::<128>::zero()
16235 }
16236 }
16237 PrimitiveOp::Lt => {
16238 if limbs_lt_128(a, b) {
16239 limbs_one_128()
16240 } else {
16241 Limbs::<128>::zero()
16242 }
16243 }
16244 PrimitiveOp::Ge => {
16245 if limbs_le_128(b, a) {
16246 limbs_one_128()
16247 } else {
16248 Limbs::<128>::zero()
16249 }
16250 }
16251 PrimitiveOp::Gt => {
16252 if limbs_lt_128(b, a) {
16253 limbs_one_128()
16254 } else {
16255 Limbs::<128>::zero()
16256 }
16257 }
16258 PrimitiveOp::Concat => Limbs::<128>::zero(),
16259 PrimitiveOp::Div => {
16260 if limbs_is_zero_128(b) {
16261 Limbs::<128>::zero()
16262 } else {
16263 limbs_div_128(a, b)
16264 }
16265 }
16266 PrimitiveOp::Mod => {
16267 if limbs_is_zero_128(b) {
16268 Limbs::<128>::zero()
16269 } else {
16270 limbs_mod_128(a, b)
16271 }
16272 }
16273 PrimitiveOp::Pow => limbs_pow_128(a, b),
16274 }
16275}
16276
16277#[inline]
16278#[must_use]
16279pub const fn const_ring_eval_w12288(op: PrimitiveOp, a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
16280 match op {
16281 PrimitiveOp::Add => a.wrapping_add(b),
16282 PrimitiveOp::Sub => a.wrapping_sub(b),
16283 PrimitiveOp::Mul => a.wrapping_mul(b),
16284 PrimitiveOp::And => a.and(b),
16285 PrimitiveOp::Or => a.or(b),
16286 PrimitiveOp::Xor => a.xor(b),
16287 PrimitiveOp::Neg => Limbs::<192>::zero().wrapping_sub(a),
16288 PrimitiveOp::Bnot => a.not(),
16289 PrimitiveOp::Succ => a.wrapping_add(limbs_one_192()),
16290 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_192()),
16291 PrimitiveOp::Le => {
16292 if limbs_le_192(a, b) {
16293 limbs_one_192()
16294 } else {
16295 Limbs::<192>::zero()
16296 }
16297 }
16298 PrimitiveOp::Lt => {
16299 if limbs_lt_192(a, b) {
16300 limbs_one_192()
16301 } else {
16302 Limbs::<192>::zero()
16303 }
16304 }
16305 PrimitiveOp::Ge => {
16306 if limbs_le_192(b, a) {
16307 limbs_one_192()
16308 } else {
16309 Limbs::<192>::zero()
16310 }
16311 }
16312 PrimitiveOp::Gt => {
16313 if limbs_lt_192(b, a) {
16314 limbs_one_192()
16315 } else {
16316 Limbs::<192>::zero()
16317 }
16318 }
16319 PrimitiveOp::Concat => Limbs::<192>::zero(),
16320 PrimitiveOp::Div => {
16321 if limbs_is_zero_192(b) {
16322 Limbs::<192>::zero()
16323 } else {
16324 limbs_div_192(a, b)
16325 }
16326 }
16327 PrimitiveOp::Mod => {
16328 if limbs_is_zero_192(b) {
16329 Limbs::<192>::zero()
16330 } else {
16331 limbs_mod_192(a, b)
16332 }
16333 }
16334 PrimitiveOp::Pow => limbs_pow_192(a, b),
16335 }
16336}
16337
16338#[inline]
16339#[must_use]
16340pub const fn const_ring_eval_w16384(op: PrimitiveOp, a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
16341 match op {
16342 PrimitiveOp::Add => a.wrapping_add(b),
16343 PrimitiveOp::Sub => a.wrapping_sub(b),
16344 PrimitiveOp::Mul => a.wrapping_mul(b),
16345 PrimitiveOp::And => a.and(b),
16346 PrimitiveOp::Or => a.or(b),
16347 PrimitiveOp::Xor => a.xor(b),
16348 PrimitiveOp::Neg => Limbs::<256>::zero().wrapping_sub(a),
16349 PrimitiveOp::Bnot => a.not(),
16350 PrimitiveOp::Succ => a.wrapping_add(limbs_one_256()),
16351 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_256()),
16352 PrimitiveOp::Le => {
16353 if limbs_le_256(a, b) {
16354 limbs_one_256()
16355 } else {
16356 Limbs::<256>::zero()
16357 }
16358 }
16359 PrimitiveOp::Lt => {
16360 if limbs_lt_256(a, b) {
16361 limbs_one_256()
16362 } else {
16363 Limbs::<256>::zero()
16364 }
16365 }
16366 PrimitiveOp::Ge => {
16367 if limbs_le_256(b, a) {
16368 limbs_one_256()
16369 } else {
16370 Limbs::<256>::zero()
16371 }
16372 }
16373 PrimitiveOp::Gt => {
16374 if limbs_lt_256(b, a) {
16375 limbs_one_256()
16376 } else {
16377 Limbs::<256>::zero()
16378 }
16379 }
16380 PrimitiveOp::Concat => Limbs::<256>::zero(),
16381 PrimitiveOp::Div => {
16382 if limbs_is_zero_256(b) {
16383 Limbs::<256>::zero()
16384 } else {
16385 limbs_div_256(a, b)
16386 }
16387 }
16388 PrimitiveOp::Mod => {
16389 if limbs_is_zero_256(b) {
16390 Limbs::<256>::zero()
16391 } else {
16392 limbs_mod_256(a, b)
16393 }
16394 }
16395 PrimitiveOp::Pow => limbs_pow_256(a, b),
16396 }
16397}
16398
16399#[inline]
16400#[must_use]
16401pub const fn const_ring_eval_w32768(op: PrimitiveOp, a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
16402 match op {
16403 PrimitiveOp::Add => a.wrapping_add(b),
16404 PrimitiveOp::Sub => a.wrapping_sub(b),
16405 PrimitiveOp::Mul => a.wrapping_mul(b),
16406 PrimitiveOp::And => a.and(b),
16407 PrimitiveOp::Or => a.or(b),
16408 PrimitiveOp::Xor => a.xor(b),
16409 PrimitiveOp::Neg => Limbs::<512>::zero().wrapping_sub(a),
16410 PrimitiveOp::Bnot => a.not(),
16411 PrimitiveOp::Succ => a.wrapping_add(limbs_one_512()),
16412 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_512()),
16413 PrimitiveOp::Le => {
16414 if limbs_le_512(a, b) {
16415 limbs_one_512()
16416 } else {
16417 Limbs::<512>::zero()
16418 }
16419 }
16420 PrimitiveOp::Lt => {
16421 if limbs_lt_512(a, b) {
16422 limbs_one_512()
16423 } else {
16424 Limbs::<512>::zero()
16425 }
16426 }
16427 PrimitiveOp::Ge => {
16428 if limbs_le_512(b, a) {
16429 limbs_one_512()
16430 } else {
16431 Limbs::<512>::zero()
16432 }
16433 }
16434 PrimitiveOp::Gt => {
16435 if limbs_lt_512(b, a) {
16436 limbs_one_512()
16437 } else {
16438 Limbs::<512>::zero()
16439 }
16440 }
16441 PrimitiveOp::Concat => Limbs::<512>::zero(),
16442 PrimitiveOp::Div => {
16443 if limbs_is_zero_512(b) {
16444 Limbs::<512>::zero()
16445 } else {
16446 limbs_div_512(a, b)
16447 }
16448 }
16449 PrimitiveOp::Mod => {
16450 if limbs_is_zero_512(b) {
16451 Limbs::<512>::zero()
16452 } else {
16453 limbs_mod_512(a, b)
16454 }
16455 }
16456 PrimitiveOp::Pow => limbs_pow_512(a, b),
16457 }
16458}
16459
16460#[inline]
16462#[must_use]
16463const fn limbs_one_3() -> Limbs<3> {
16464 Limbs::<3>::from_words([1u64, 0u64, 0u64])
16465}
16466
16467#[inline]
16468#[must_use]
16469const fn limbs_one_4() -> Limbs<4> {
16470 Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64])
16471}
16472
16473#[inline]
16474#[must_use]
16475const fn limbs_one_6() -> Limbs<6> {
16476 Limbs::<6>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16477}
16478
16479#[inline]
16480#[must_use]
16481const fn limbs_one_7() -> Limbs<7> {
16482 Limbs::<7>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16483}
16484
16485#[inline]
16486#[must_use]
16487const fn limbs_one_8() -> Limbs<8> {
16488 Limbs::<8>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16489}
16490
16491#[inline]
16492#[must_use]
16493const fn limbs_one_9() -> Limbs<9> {
16494 Limbs::<9>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16495}
16496
16497#[inline]
16498#[must_use]
16499const fn limbs_one_16() -> Limbs<16> {
16500 Limbs::<16>::from_words([
16501 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16502 0u64,
16503 ])
16504}
16505
16506#[inline]
16507#[must_use]
16508const fn limbs_one_32() -> Limbs<32> {
16509 Limbs::<32>::from_words([
16510 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16511 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16512 0u64, 0u64,
16513 ])
16514}
16515
16516#[inline]
16517#[must_use]
16518const fn limbs_one_64() -> Limbs<64> {
16519 Limbs::<64>::from_words([
16520 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16521 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16522 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16523 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16524 0u64, 0u64, 0u64, 0u64,
16525 ])
16526}
16527
16528#[inline]
16529#[must_use]
16530const fn limbs_one_128() -> Limbs<128> {
16531 Limbs::<128>::from_words([
16532 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16533 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16534 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16535 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16536 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16537 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16538 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16539 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16540 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16541 ])
16542}
16543
16544#[inline]
16545#[must_use]
16546const fn limbs_one_192() -> Limbs<192> {
16547 Limbs::<192>::from_words([
16548 1u64, 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, 0u64, 0u64, 0u64,
16554 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16555 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16556 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16557 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16558 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16559 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16560 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16561 ])
16562}
16563
16564#[inline]
16565#[must_use]
16566const fn limbs_one_256() -> Limbs<256> {
16567 Limbs::<256>::from_words([
16568 1u64, 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, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16579 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16580 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16581 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16582 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16583 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16584 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16585 0u64,
16586 ])
16587}
16588
16589#[inline]
16590#[must_use]
16591const fn limbs_one_512() -> Limbs<512> {
16592 Limbs::<512>::from_words([
16593 1u64, 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, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16621 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16622 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16623 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16624 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16625 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16626 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16627 0u64, 0u64,
16628 ])
16629}
16630
16631#[inline]
16634#[must_use]
16635const fn limbs_lt_3(a: Limbs<3>, b: Limbs<3>) -> bool {
16636 let aw = a.words();
16637 let bw = b.words();
16638 let mut i = 3;
16639 while i > 0 {
16640 i -= 1;
16641 if aw[i] < bw[i] {
16642 return true;
16643 }
16644 if aw[i] > bw[i] {
16645 return false;
16646 }
16647 }
16648 false
16649}
16650
16651#[inline]
16652#[must_use]
16653const fn limbs_le_3(a: Limbs<3>, b: Limbs<3>) -> bool {
16654 let aw = a.words();
16655 let bw = b.words();
16656 let mut i = 3;
16657 while i > 0 {
16658 i -= 1;
16659 if aw[i] < bw[i] {
16660 return true;
16661 }
16662 if aw[i] > bw[i] {
16663 return false;
16664 }
16665 }
16666 true
16667}
16668
16669#[inline]
16670#[must_use]
16671const fn limbs_lt_4(a: Limbs<4>, b: Limbs<4>) -> bool {
16672 let aw = a.words();
16673 let bw = b.words();
16674 let mut i = 4;
16675 while i > 0 {
16676 i -= 1;
16677 if aw[i] < bw[i] {
16678 return true;
16679 }
16680 if aw[i] > bw[i] {
16681 return false;
16682 }
16683 }
16684 false
16685}
16686
16687#[inline]
16688#[must_use]
16689const fn limbs_le_4(a: Limbs<4>, b: Limbs<4>) -> bool {
16690 let aw = a.words();
16691 let bw = b.words();
16692 let mut i = 4;
16693 while i > 0 {
16694 i -= 1;
16695 if aw[i] < bw[i] {
16696 return true;
16697 }
16698 if aw[i] > bw[i] {
16699 return false;
16700 }
16701 }
16702 true
16703}
16704
16705#[inline]
16706#[must_use]
16707const fn limbs_lt_6(a: Limbs<6>, b: Limbs<6>) -> bool {
16708 let aw = a.words();
16709 let bw = b.words();
16710 let mut i = 6;
16711 while i > 0 {
16712 i -= 1;
16713 if aw[i] < bw[i] {
16714 return true;
16715 }
16716 if aw[i] > bw[i] {
16717 return false;
16718 }
16719 }
16720 false
16721}
16722
16723#[inline]
16724#[must_use]
16725const fn limbs_le_6(a: Limbs<6>, b: Limbs<6>) -> bool {
16726 let aw = a.words();
16727 let bw = b.words();
16728 let mut i = 6;
16729 while i > 0 {
16730 i -= 1;
16731 if aw[i] < bw[i] {
16732 return true;
16733 }
16734 if aw[i] > bw[i] {
16735 return false;
16736 }
16737 }
16738 true
16739}
16740
16741#[inline]
16742#[must_use]
16743const fn limbs_lt_7(a: Limbs<7>, b: Limbs<7>) -> bool {
16744 let aw = a.words();
16745 let bw = b.words();
16746 let mut i = 7;
16747 while i > 0 {
16748 i -= 1;
16749 if aw[i] < bw[i] {
16750 return true;
16751 }
16752 if aw[i] > bw[i] {
16753 return false;
16754 }
16755 }
16756 false
16757}
16758
16759#[inline]
16760#[must_use]
16761const fn limbs_le_7(a: Limbs<7>, b: Limbs<7>) -> bool {
16762 let aw = a.words();
16763 let bw = b.words();
16764 let mut i = 7;
16765 while i > 0 {
16766 i -= 1;
16767 if aw[i] < bw[i] {
16768 return true;
16769 }
16770 if aw[i] > bw[i] {
16771 return false;
16772 }
16773 }
16774 true
16775}
16776
16777#[inline]
16778#[must_use]
16779const fn limbs_lt_8(a: Limbs<8>, b: Limbs<8>) -> bool {
16780 let aw = a.words();
16781 let bw = b.words();
16782 let mut i = 8;
16783 while i > 0 {
16784 i -= 1;
16785 if aw[i] < bw[i] {
16786 return true;
16787 }
16788 if aw[i] > bw[i] {
16789 return false;
16790 }
16791 }
16792 false
16793}
16794
16795#[inline]
16796#[must_use]
16797const fn limbs_le_8(a: Limbs<8>, b: Limbs<8>) -> bool {
16798 let aw = a.words();
16799 let bw = b.words();
16800 let mut i = 8;
16801 while i > 0 {
16802 i -= 1;
16803 if aw[i] < bw[i] {
16804 return true;
16805 }
16806 if aw[i] > bw[i] {
16807 return false;
16808 }
16809 }
16810 true
16811}
16812
16813#[inline]
16814#[must_use]
16815const fn limbs_lt_9(a: Limbs<9>, b: Limbs<9>) -> bool {
16816 let aw = a.words();
16817 let bw = b.words();
16818 let mut i = 9;
16819 while i > 0 {
16820 i -= 1;
16821 if aw[i] < bw[i] {
16822 return true;
16823 }
16824 if aw[i] > bw[i] {
16825 return false;
16826 }
16827 }
16828 false
16829}
16830
16831#[inline]
16832#[must_use]
16833const fn limbs_le_9(a: Limbs<9>, b: Limbs<9>) -> bool {
16834 let aw = a.words();
16835 let bw = b.words();
16836 let mut i = 9;
16837 while i > 0 {
16838 i -= 1;
16839 if aw[i] < bw[i] {
16840 return true;
16841 }
16842 if aw[i] > bw[i] {
16843 return false;
16844 }
16845 }
16846 true
16847}
16848
16849#[inline]
16850#[must_use]
16851const fn limbs_lt_16(a: Limbs<16>, b: Limbs<16>) -> bool {
16852 let aw = a.words();
16853 let bw = b.words();
16854 let mut i = 16;
16855 while i > 0 {
16856 i -= 1;
16857 if aw[i] < bw[i] {
16858 return true;
16859 }
16860 if aw[i] > bw[i] {
16861 return false;
16862 }
16863 }
16864 false
16865}
16866
16867#[inline]
16868#[must_use]
16869const fn limbs_le_16(a: Limbs<16>, b: Limbs<16>) -> bool {
16870 let aw = a.words();
16871 let bw = b.words();
16872 let mut i = 16;
16873 while i > 0 {
16874 i -= 1;
16875 if aw[i] < bw[i] {
16876 return true;
16877 }
16878 if aw[i] > bw[i] {
16879 return false;
16880 }
16881 }
16882 true
16883}
16884
16885#[inline]
16886#[must_use]
16887const fn limbs_lt_32(a: Limbs<32>, b: Limbs<32>) -> bool {
16888 let aw = a.words();
16889 let bw = b.words();
16890 let mut i = 32;
16891 while i > 0 {
16892 i -= 1;
16893 if aw[i] < bw[i] {
16894 return true;
16895 }
16896 if aw[i] > bw[i] {
16897 return false;
16898 }
16899 }
16900 false
16901}
16902
16903#[inline]
16904#[must_use]
16905const fn limbs_le_32(a: Limbs<32>, b: Limbs<32>) -> bool {
16906 let aw = a.words();
16907 let bw = b.words();
16908 let mut i = 32;
16909 while i > 0 {
16910 i -= 1;
16911 if aw[i] < bw[i] {
16912 return true;
16913 }
16914 if aw[i] > bw[i] {
16915 return false;
16916 }
16917 }
16918 true
16919}
16920
16921#[inline]
16922#[must_use]
16923const fn limbs_lt_64(a: Limbs<64>, b: Limbs<64>) -> bool {
16924 let aw = a.words();
16925 let bw = b.words();
16926 let mut i = 64;
16927 while i > 0 {
16928 i -= 1;
16929 if aw[i] < bw[i] {
16930 return true;
16931 }
16932 if aw[i] > bw[i] {
16933 return false;
16934 }
16935 }
16936 false
16937}
16938
16939#[inline]
16940#[must_use]
16941const fn limbs_le_64(a: Limbs<64>, b: Limbs<64>) -> bool {
16942 let aw = a.words();
16943 let bw = b.words();
16944 let mut i = 64;
16945 while i > 0 {
16946 i -= 1;
16947 if aw[i] < bw[i] {
16948 return true;
16949 }
16950 if aw[i] > bw[i] {
16951 return false;
16952 }
16953 }
16954 true
16955}
16956
16957#[inline]
16958#[must_use]
16959const fn limbs_lt_128(a: Limbs<128>, b: Limbs<128>) -> bool {
16960 let aw = a.words();
16961 let bw = b.words();
16962 let mut i = 128;
16963 while i > 0 {
16964 i -= 1;
16965 if aw[i] < bw[i] {
16966 return true;
16967 }
16968 if aw[i] > bw[i] {
16969 return false;
16970 }
16971 }
16972 false
16973}
16974
16975#[inline]
16976#[must_use]
16977const fn limbs_le_128(a: Limbs<128>, b: Limbs<128>) -> bool {
16978 let aw = a.words();
16979 let bw = b.words();
16980 let mut i = 128;
16981 while i > 0 {
16982 i -= 1;
16983 if aw[i] < bw[i] {
16984 return true;
16985 }
16986 if aw[i] > bw[i] {
16987 return false;
16988 }
16989 }
16990 true
16991}
16992
16993#[inline]
16994#[must_use]
16995const fn limbs_lt_192(a: Limbs<192>, b: Limbs<192>) -> bool {
16996 let aw = a.words();
16997 let bw = b.words();
16998 let mut i = 192;
16999 while i > 0 {
17000 i -= 1;
17001 if aw[i] < bw[i] {
17002 return true;
17003 }
17004 if aw[i] > bw[i] {
17005 return false;
17006 }
17007 }
17008 false
17009}
17010
17011#[inline]
17012#[must_use]
17013const fn limbs_le_192(a: Limbs<192>, b: Limbs<192>) -> bool {
17014 let aw = a.words();
17015 let bw = b.words();
17016 let mut i = 192;
17017 while i > 0 {
17018 i -= 1;
17019 if aw[i] < bw[i] {
17020 return true;
17021 }
17022 if aw[i] > bw[i] {
17023 return false;
17024 }
17025 }
17026 true
17027}
17028
17029#[inline]
17030#[must_use]
17031const fn limbs_lt_256(a: Limbs<256>, b: Limbs<256>) -> bool {
17032 let aw = a.words();
17033 let bw = b.words();
17034 let mut i = 256;
17035 while i > 0 {
17036 i -= 1;
17037 if aw[i] < bw[i] {
17038 return true;
17039 }
17040 if aw[i] > bw[i] {
17041 return false;
17042 }
17043 }
17044 false
17045}
17046
17047#[inline]
17048#[must_use]
17049const fn limbs_le_256(a: Limbs<256>, b: Limbs<256>) -> bool {
17050 let aw = a.words();
17051 let bw = b.words();
17052 let mut i = 256;
17053 while i > 0 {
17054 i -= 1;
17055 if aw[i] < bw[i] {
17056 return true;
17057 }
17058 if aw[i] > bw[i] {
17059 return false;
17060 }
17061 }
17062 true
17063}
17064
17065#[inline]
17066#[must_use]
17067const fn limbs_lt_512(a: Limbs<512>, b: Limbs<512>) -> bool {
17068 let aw = a.words();
17069 let bw = b.words();
17070 let mut i = 512;
17071 while i > 0 {
17072 i -= 1;
17073 if aw[i] < bw[i] {
17074 return true;
17075 }
17076 if aw[i] > bw[i] {
17077 return false;
17078 }
17079 }
17080 false
17081}
17082
17083#[inline]
17084#[must_use]
17085const fn limbs_le_512(a: Limbs<512>, b: Limbs<512>) -> bool {
17086 let aw = a.words();
17087 let bw = b.words();
17088 let mut i = 512;
17089 while i > 0 {
17090 i -= 1;
17091 if aw[i] < bw[i] {
17092 return true;
17093 }
17094 if aw[i] > bw[i] {
17095 return false;
17096 }
17097 }
17098 true
17099}
17100
17101#[inline]
17104#[must_use]
17105const fn limbs_is_zero_3(a: Limbs<3>) -> bool {
17106 let aw = a.words();
17107 let mut i = 0usize;
17108 while i < 3 {
17109 if aw[i] != 0 {
17110 return false;
17111 }
17112 i += 1;
17113 }
17114 true
17115}
17116
17117#[inline]
17118#[must_use]
17119const fn limbs_shl1_3(a: Limbs<3>) -> Limbs<3> {
17120 let aw = a.words();
17121 let mut out = [0u64; 3];
17122 let mut carry: u64 = 0;
17123 let mut i = 0usize;
17124 while i < 3 {
17125 let v = aw[i];
17126 out[i] = (v << 1) | carry;
17127 carry = v >> 63;
17128 i += 1;
17129 }
17130 Limbs::<3>::from_words(out)
17131}
17132
17133#[inline]
17134#[must_use]
17135const fn limbs_set_bit0_3(a: Limbs<3>) -> Limbs<3> {
17136 let aw = a.words();
17137 let mut out = [0u64; 3];
17138 let mut i = 0usize;
17139 while i < 3 {
17140 out[i] = aw[i];
17141 i += 1;
17142 }
17143 out[0] |= 1u64;
17144 Limbs::<3>::from_words(out)
17145}
17146
17147#[inline]
17148#[must_use]
17149const fn limbs_bit_msb_3(a: Limbs<3>, msb_index: usize) -> u64 {
17150 let aw = a.words();
17151 let total_bits = 3 * 64;
17152 let lsb_index = total_bits - 1 - msb_index;
17153 let word = lsb_index / 64;
17154 let bit = lsb_index % 64;
17155 (aw[word] >> bit) & 1u64
17156}
17157
17158#[inline]
17159#[must_use]
17160const fn limbs_divmod_3(a: Limbs<3>, b: Limbs<3>) -> (Limbs<3>, Limbs<3>) {
17161 let mut q = Limbs::<3>::zero();
17162 let mut r = Limbs::<3>::zero();
17163 let total_bits = 3 * 64;
17164 let mut i = 0usize;
17165 while i < total_bits {
17166 r = limbs_shl1_3(r);
17167 if limbs_bit_msb_3(a, i) == 1 {
17168 r = limbs_set_bit0_3(r);
17169 }
17170 if limbs_le_3(b, r) {
17171 r = r.wrapping_sub(b);
17172 q = limbs_shl1_3(q);
17173 q = limbs_set_bit0_3(q);
17174 } else {
17175 q = limbs_shl1_3(q);
17176 }
17177 i += 1;
17178 }
17179 (q, r)
17180}
17181
17182#[inline]
17183#[must_use]
17184const fn limbs_div_3(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
17185 let (q, _) = limbs_divmod_3(a, b);
17186 q
17187}
17188
17189#[inline]
17190#[must_use]
17191const fn limbs_mod_3(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
17192 let (_, r) = limbs_divmod_3(a, b);
17193 r
17194}
17195
17196#[inline]
17197#[must_use]
17198const fn limbs_pow_3(base: Limbs<3>, exp: Limbs<3>) -> Limbs<3> {
17199 let mut result = limbs_one_3();
17200 let mut b = base;
17201 let ew = exp.words();
17202 let mut word = 0usize;
17203 while word < 3 {
17204 let mut bit = 0u32;
17205 while bit < 64 {
17206 if ((ew[word] >> bit) & 1u64) == 1u64 {
17207 result = result.wrapping_mul(b);
17208 }
17209 b = b.wrapping_mul(b);
17210 bit += 1;
17211 }
17212 word += 1;
17213 }
17214 result
17215}
17216
17217#[inline]
17218#[must_use]
17219const fn limbs_is_zero_4(a: Limbs<4>) -> bool {
17220 let aw = a.words();
17221 let mut i = 0usize;
17222 while i < 4 {
17223 if aw[i] != 0 {
17224 return false;
17225 }
17226 i += 1;
17227 }
17228 true
17229}
17230
17231#[inline]
17232#[must_use]
17233const fn limbs_shl1_4(a: Limbs<4>) -> Limbs<4> {
17234 let aw = a.words();
17235 let mut out = [0u64; 4];
17236 let mut carry: u64 = 0;
17237 let mut i = 0usize;
17238 while i < 4 {
17239 let v = aw[i];
17240 out[i] = (v << 1) | carry;
17241 carry = v >> 63;
17242 i += 1;
17243 }
17244 Limbs::<4>::from_words(out)
17245}
17246
17247#[inline]
17248#[must_use]
17249const fn limbs_set_bit0_4(a: Limbs<4>) -> Limbs<4> {
17250 let aw = a.words();
17251 let mut out = [0u64; 4];
17252 let mut i = 0usize;
17253 while i < 4 {
17254 out[i] = aw[i];
17255 i += 1;
17256 }
17257 out[0] |= 1u64;
17258 Limbs::<4>::from_words(out)
17259}
17260
17261#[inline]
17262#[must_use]
17263const fn limbs_bit_msb_4(a: Limbs<4>, msb_index: usize) -> u64 {
17264 let aw = a.words();
17265 let total_bits = 4 * 64;
17266 let lsb_index = total_bits - 1 - msb_index;
17267 let word = lsb_index / 64;
17268 let bit = lsb_index % 64;
17269 (aw[word] >> bit) & 1u64
17270}
17271
17272#[inline]
17273#[must_use]
17274const fn limbs_divmod_4(a: Limbs<4>, b: Limbs<4>) -> (Limbs<4>, Limbs<4>) {
17275 let mut q = Limbs::<4>::zero();
17276 let mut r = Limbs::<4>::zero();
17277 let total_bits = 4 * 64;
17278 let mut i = 0usize;
17279 while i < total_bits {
17280 r = limbs_shl1_4(r);
17281 if limbs_bit_msb_4(a, i) == 1 {
17282 r = limbs_set_bit0_4(r);
17283 }
17284 if limbs_le_4(b, r) {
17285 r = r.wrapping_sub(b);
17286 q = limbs_shl1_4(q);
17287 q = limbs_set_bit0_4(q);
17288 } else {
17289 q = limbs_shl1_4(q);
17290 }
17291 i += 1;
17292 }
17293 (q, r)
17294}
17295
17296#[inline]
17297#[must_use]
17298const fn limbs_div_4(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
17299 let (q, _) = limbs_divmod_4(a, b);
17300 q
17301}
17302
17303#[inline]
17304#[must_use]
17305const fn limbs_mod_4(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
17306 let (_, r) = limbs_divmod_4(a, b);
17307 r
17308}
17309
17310#[inline]
17311#[must_use]
17312const fn limbs_pow_4(base: Limbs<4>, exp: Limbs<4>) -> Limbs<4> {
17313 let mut result = limbs_one_4();
17314 let mut b = base;
17315 let ew = exp.words();
17316 let mut word = 0usize;
17317 while word < 4 {
17318 let mut bit = 0u32;
17319 while bit < 64 {
17320 if ((ew[word] >> bit) & 1u64) == 1u64 {
17321 result = result.wrapping_mul(b);
17322 }
17323 b = b.wrapping_mul(b);
17324 bit += 1;
17325 }
17326 word += 1;
17327 }
17328 result
17329}
17330
17331#[inline]
17332#[must_use]
17333const fn limbs_is_zero_6(a: Limbs<6>) -> bool {
17334 let aw = a.words();
17335 let mut i = 0usize;
17336 while i < 6 {
17337 if aw[i] != 0 {
17338 return false;
17339 }
17340 i += 1;
17341 }
17342 true
17343}
17344
17345#[inline]
17346#[must_use]
17347const fn limbs_shl1_6(a: Limbs<6>) -> Limbs<6> {
17348 let aw = a.words();
17349 let mut out = [0u64; 6];
17350 let mut carry: u64 = 0;
17351 let mut i = 0usize;
17352 while i < 6 {
17353 let v = aw[i];
17354 out[i] = (v << 1) | carry;
17355 carry = v >> 63;
17356 i += 1;
17357 }
17358 Limbs::<6>::from_words(out)
17359}
17360
17361#[inline]
17362#[must_use]
17363const fn limbs_set_bit0_6(a: Limbs<6>) -> Limbs<6> {
17364 let aw = a.words();
17365 let mut out = [0u64; 6];
17366 let mut i = 0usize;
17367 while i < 6 {
17368 out[i] = aw[i];
17369 i += 1;
17370 }
17371 out[0] |= 1u64;
17372 Limbs::<6>::from_words(out)
17373}
17374
17375#[inline]
17376#[must_use]
17377const fn limbs_bit_msb_6(a: Limbs<6>, msb_index: usize) -> u64 {
17378 let aw = a.words();
17379 let total_bits = 6 * 64;
17380 let lsb_index = total_bits - 1 - msb_index;
17381 let word = lsb_index / 64;
17382 let bit = lsb_index % 64;
17383 (aw[word] >> bit) & 1u64
17384}
17385
17386#[inline]
17387#[must_use]
17388const fn limbs_divmod_6(a: Limbs<6>, b: Limbs<6>) -> (Limbs<6>, Limbs<6>) {
17389 let mut q = Limbs::<6>::zero();
17390 let mut r = Limbs::<6>::zero();
17391 let total_bits = 6 * 64;
17392 let mut i = 0usize;
17393 while i < total_bits {
17394 r = limbs_shl1_6(r);
17395 if limbs_bit_msb_6(a, i) == 1 {
17396 r = limbs_set_bit0_6(r);
17397 }
17398 if limbs_le_6(b, r) {
17399 r = r.wrapping_sub(b);
17400 q = limbs_shl1_6(q);
17401 q = limbs_set_bit0_6(q);
17402 } else {
17403 q = limbs_shl1_6(q);
17404 }
17405 i += 1;
17406 }
17407 (q, r)
17408}
17409
17410#[inline]
17411#[must_use]
17412const fn limbs_div_6(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
17413 let (q, _) = limbs_divmod_6(a, b);
17414 q
17415}
17416
17417#[inline]
17418#[must_use]
17419const fn limbs_mod_6(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
17420 let (_, r) = limbs_divmod_6(a, b);
17421 r
17422}
17423
17424#[inline]
17425#[must_use]
17426const fn limbs_pow_6(base: Limbs<6>, exp: Limbs<6>) -> Limbs<6> {
17427 let mut result = limbs_one_6();
17428 let mut b = base;
17429 let ew = exp.words();
17430 let mut word = 0usize;
17431 while word < 6 {
17432 let mut bit = 0u32;
17433 while bit < 64 {
17434 if ((ew[word] >> bit) & 1u64) == 1u64 {
17435 result = result.wrapping_mul(b);
17436 }
17437 b = b.wrapping_mul(b);
17438 bit += 1;
17439 }
17440 word += 1;
17441 }
17442 result
17443}
17444
17445#[inline]
17446#[must_use]
17447const fn limbs_is_zero_7(a: Limbs<7>) -> bool {
17448 let aw = a.words();
17449 let mut i = 0usize;
17450 while i < 7 {
17451 if aw[i] != 0 {
17452 return false;
17453 }
17454 i += 1;
17455 }
17456 true
17457}
17458
17459#[inline]
17460#[must_use]
17461const fn limbs_shl1_7(a: Limbs<7>) -> Limbs<7> {
17462 let aw = a.words();
17463 let mut out = [0u64; 7];
17464 let mut carry: u64 = 0;
17465 let mut i = 0usize;
17466 while i < 7 {
17467 let v = aw[i];
17468 out[i] = (v << 1) | carry;
17469 carry = v >> 63;
17470 i += 1;
17471 }
17472 Limbs::<7>::from_words(out)
17473}
17474
17475#[inline]
17476#[must_use]
17477const fn limbs_set_bit0_7(a: Limbs<7>) -> Limbs<7> {
17478 let aw = a.words();
17479 let mut out = [0u64; 7];
17480 let mut i = 0usize;
17481 while i < 7 {
17482 out[i] = aw[i];
17483 i += 1;
17484 }
17485 out[0] |= 1u64;
17486 Limbs::<7>::from_words(out)
17487}
17488
17489#[inline]
17490#[must_use]
17491const fn limbs_bit_msb_7(a: Limbs<7>, msb_index: usize) -> u64 {
17492 let aw = a.words();
17493 let total_bits = 7 * 64;
17494 let lsb_index = total_bits - 1 - msb_index;
17495 let word = lsb_index / 64;
17496 let bit = lsb_index % 64;
17497 (aw[word] >> bit) & 1u64
17498}
17499
17500#[inline]
17501#[must_use]
17502const fn limbs_divmod_7(a: Limbs<7>, b: Limbs<7>) -> (Limbs<7>, Limbs<7>) {
17503 let mut q = Limbs::<7>::zero();
17504 let mut r = Limbs::<7>::zero();
17505 let total_bits = 7 * 64;
17506 let mut i = 0usize;
17507 while i < total_bits {
17508 r = limbs_shl1_7(r);
17509 if limbs_bit_msb_7(a, i) == 1 {
17510 r = limbs_set_bit0_7(r);
17511 }
17512 if limbs_le_7(b, r) {
17513 r = r.wrapping_sub(b);
17514 q = limbs_shl1_7(q);
17515 q = limbs_set_bit0_7(q);
17516 } else {
17517 q = limbs_shl1_7(q);
17518 }
17519 i += 1;
17520 }
17521 (q, r)
17522}
17523
17524#[inline]
17525#[must_use]
17526const fn limbs_div_7(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
17527 let (q, _) = limbs_divmod_7(a, b);
17528 q
17529}
17530
17531#[inline]
17532#[must_use]
17533const fn limbs_mod_7(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
17534 let (_, r) = limbs_divmod_7(a, b);
17535 r
17536}
17537
17538#[inline]
17539#[must_use]
17540const fn limbs_pow_7(base: Limbs<7>, exp: Limbs<7>) -> Limbs<7> {
17541 let mut result = limbs_one_7();
17542 let mut b = base;
17543 let ew = exp.words();
17544 let mut word = 0usize;
17545 while word < 7 {
17546 let mut bit = 0u32;
17547 while bit < 64 {
17548 if ((ew[word] >> bit) & 1u64) == 1u64 {
17549 result = result.wrapping_mul(b);
17550 }
17551 b = b.wrapping_mul(b);
17552 bit += 1;
17553 }
17554 word += 1;
17555 }
17556 result
17557}
17558
17559#[inline]
17560#[must_use]
17561const fn limbs_is_zero_8(a: Limbs<8>) -> bool {
17562 let aw = a.words();
17563 let mut i = 0usize;
17564 while i < 8 {
17565 if aw[i] != 0 {
17566 return false;
17567 }
17568 i += 1;
17569 }
17570 true
17571}
17572
17573#[inline]
17574#[must_use]
17575const fn limbs_shl1_8(a: Limbs<8>) -> Limbs<8> {
17576 let aw = a.words();
17577 let mut out = [0u64; 8];
17578 let mut carry: u64 = 0;
17579 let mut i = 0usize;
17580 while i < 8 {
17581 let v = aw[i];
17582 out[i] = (v << 1) | carry;
17583 carry = v >> 63;
17584 i += 1;
17585 }
17586 Limbs::<8>::from_words(out)
17587}
17588
17589#[inline]
17590#[must_use]
17591const fn limbs_set_bit0_8(a: Limbs<8>) -> Limbs<8> {
17592 let aw = a.words();
17593 let mut out = [0u64; 8];
17594 let mut i = 0usize;
17595 while i < 8 {
17596 out[i] = aw[i];
17597 i += 1;
17598 }
17599 out[0] |= 1u64;
17600 Limbs::<8>::from_words(out)
17601}
17602
17603#[inline]
17604#[must_use]
17605const fn limbs_bit_msb_8(a: Limbs<8>, msb_index: usize) -> u64 {
17606 let aw = a.words();
17607 let total_bits = 8 * 64;
17608 let lsb_index = total_bits - 1 - msb_index;
17609 let word = lsb_index / 64;
17610 let bit = lsb_index % 64;
17611 (aw[word] >> bit) & 1u64
17612}
17613
17614#[inline]
17615#[must_use]
17616const fn limbs_divmod_8(a: Limbs<8>, b: Limbs<8>) -> (Limbs<8>, Limbs<8>) {
17617 let mut q = Limbs::<8>::zero();
17618 let mut r = Limbs::<8>::zero();
17619 let total_bits = 8 * 64;
17620 let mut i = 0usize;
17621 while i < total_bits {
17622 r = limbs_shl1_8(r);
17623 if limbs_bit_msb_8(a, i) == 1 {
17624 r = limbs_set_bit0_8(r);
17625 }
17626 if limbs_le_8(b, r) {
17627 r = r.wrapping_sub(b);
17628 q = limbs_shl1_8(q);
17629 q = limbs_set_bit0_8(q);
17630 } else {
17631 q = limbs_shl1_8(q);
17632 }
17633 i += 1;
17634 }
17635 (q, r)
17636}
17637
17638#[inline]
17639#[must_use]
17640const fn limbs_div_8(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
17641 let (q, _) = limbs_divmod_8(a, b);
17642 q
17643}
17644
17645#[inline]
17646#[must_use]
17647const fn limbs_mod_8(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
17648 let (_, r) = limbs_divmod_8(a, b);
17649 r
17650}
17651
17652#[inline]
17653#[must_use]
17654const fn limbs_pow_8(base: Limbs<8>, exp: Limbs<8>) -> Limbs<8> {
17655 let mut result = limbs_one_8();
17656 let mut b = base;
17657 let ew = exp.words();
17658 let mut word = 0usize;
17659 while word < 8 {
17660 let mut bit = 0u32;
17661 while bit < 64 {
17662 if ((ew[word] >> bit) & 1u64) == 1u64 {
17663 result = result.wrapping_mul(b);
17664 }
17665 b = b.wrapping_mul(b);
17666 bit += 1;
17667 }
17668 word += 1;
17669 }
17670 result
17671}
17672
17673#[inline]
17674#[must_use]
17675const fn limbs_is_zero_9(a: Limbs<9>) -> bool {
17676 let aw = a.words();
17677 let mut i = 0usize;
17678 while i < 9 {
17679 if aw[i] != 0 {
17680 return false;
17681 }
17682 i += 1;
17683 }
17684 true
17685}
17686
17687#[inline]
17688#[must_use]
17689const fn limbs_shl1_9(a: Limbs<9>) -> Limbs<9> {
17690 let aw = a.words();
17691 let mut out = [0u64; 9];
17692 let mut carry: u64 = 0;
17693 let mut i = 0usize;
17694 while i < 9 {
17695 let v = aw[i];
17696 out[i] = (v << 1) | carry;
17697 carry = v >> 63;
17698 i += 1;
17699 }
17700 Limbs::<9>::from_words(out)
17701}
17702
17703#[inline]
17704#[must_use]
17705const fn limbs_set_bit0_9(a: Limbs<9>) -> Limbs<9> {
17706 let aw = a.words();
17707 let mut out = [0u64; 9];
17708 let mut i = 0usize;
17709 while i < 9 {
17710 out[i] = aw[i];
17711 i += 1;
17712 }
17713 out[0] |= 1u64;
17714 Limbs::<9>::from_words(out)
17715}
17716
17717#[inline]
17718#[must_use]
17719const fn limbs_bit_msb_9(a: Limbs<9>, msb_index: usize) -> u64 {
17720 let aw = a.words();
17721 let total_bits = 9 * 64;
17722 let lsb_index = total_bits - 1 - msb_index;
17723 let word = lsb_index / 64;
17724 let bit = lsb_index % 64;
17725 (aw[word] >> bit) & 1u64
17726}
17727
17728#[inline]
17729#[must_use]
17730const fn limbs_divmod_9(a: Limbs<9>, b: Limbs<9>) -> (Limbs<9>, Limbs<9>) {
17731 let mut q = Limbs::<9>::zero();
17732 let mut r = Limbs::<9>::zero();
17733 let total_bits = 9 * 64;
17734 let mut i = 0usize;
17735 while i < total_bits {
17736 r = limbs_shl1_9(r);
17737 if limbs_bit_msb_9(a, i) == 1 {
17738 r = limbs_set_bit0_9(r);
17739 }
17740 if limbs_le_9(b, r) {
17741 r = r.wrapping_sub(b);
17742 q = limbs_shl1_9(q);
17743 q = limbs_set_bit0_9(q);
17744 } else {
17745 q = limbs_shl1_9(q);
17746 }
17747 i += 1;
17748 }
17749 (q, r)
17750}
17751
17752#[inline]
17753#[must_use]
17754const fn limbs_div_9(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
17755 let (q, _) = limbs_divmod_9(a, b);
17756 q
17757}
17758
17759#[inline]
17760#[must_use]
17761const fn limbs_mod_9(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
17762 let (_, r) = limbs_divmod_9(a, b);
17763 r
17764}
17765
17766#[inline]
17767#[must_use]
17768const fn limbs_pow_9(base: Limbs<9>, exp: Limbs<9>) -> Limbs<9> {
17769 let mut result = limbs_one_9();
17770 let mut b = base;
17771 let ew = exp.words();
17772 let mut word = 0usize;
17773 while word < 9 {
17774 let mut bit = 0u32;
17775 while bit < 64 {
17776 if ((ew[word] >> bit) & 1u64) == 1u64 {
17777 result = result.wrapping_mul(b);
17778 }
17779 b = b.wrapping_mul(b);
17780 bit += 1;
17781 }
17782 word += 1;
17783 }
17784 result
17785}
17786
17787#[inline]
17788#[must_use]
17789const fn limbs_is_zero_16(a: Limbs<16>) -> bool {
17790 let aw = a.words();
17791 let mut i = 0usize;
17792 while i < 16 {
17793 if aw[i] != 0 {
17794 return false;
17795 }
17796 i += 1;
17797 }
17798 true
17799}
17800
17801#[inline]
17802#[must_use]
17803const fn limbs_shl1_16(a: Limbs<16>) -> Limbs<16> {
17804 let aw = a.words();
17805 let mut out = [0u64; 16];
17806 let mut carry: u64 = 0;
17807 let mut i = 0usize;
17808 while i < 16 {
17809 let v = aw[i];
17810 out[i] = (v << 1) | carry;
17811 carry = v >> 63;
17812 i += 1;
17813 }
17814 Limbs::<16>::from_words(out)
17815}
17816
17817#[inline]
17818#[must_use]
17819const fn limbs_set_bit0_16(a: Limbs<16>) -> Limbs<16> {
17820 let aw = a.words();
17821 let mut out = [0u64; 16];
17822 let mut i = 0usize;
17823 while i < 16 {
17824 out[i] = aw[i];
17825 i += 1;
17826 }
17827 out[0] |= 1u64;
17828 Limbs::<16>::from_words(out)
17829}
17830
17831#[inline]
17832#[must_use]
17833const fn limbs_bit_msb_16(a: Limbs<16>, msb_index: usize) -> u64 {
17834 let aw = a.words();
17835 let total_bits = 16 * 64;
17836 let lsb_index = total_bits - 1 - msb_index;
17837 let word = lsb_index / 64;
17838 let bit = lsb_index % 64;
17839 (aw[word] >> bit) & 1u64
17840}
17841
17842#[inline]
17843#[must_use]
17844const fn limbs_divmod_16(a: Limbs<16>, b: Limbs<16>) -> (Limbs<16>, Limbs<16>) {
17845 let mut q = Limbs::<16>::zero();
17846 let mut r = Limbs::<16>::zero();
17847 let total_bits = 16 * 64;
17848 let mut i = 0usize;
17849 while i < total_bits {
17850 r = limbs_shl1_16(r);
17851 if limbs_bit_msb_16(a, i) == 1 {
17852 r = limbs_set_bit0_16(r);
17853 }
17854 if limbs_le_16(b, r) {
17855 r = r.wrapping_sub(b);
17856 q = limbs_shl1_16(q);
17857 q = limbs_set_bit0_16(q);
17858 } else {
17859 q = limbs_shl1_16(q);
17860 }
17861 i += 1;
17862 }
17863 (q, r)
17864}
17865
17866#[inline]
17867#[must_use]
17868const fn limbs_div_16(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
17869 let (q, _) = limbs_divmod_16(a, b);
17870 q
17871}
17872
17873#[inline]
17874#[must_use]
17875const fn limbs_mod_16(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
17876 let (_, r) = limbs_divmod_16(a, b);
17877 r
17878}
17879
17880#[inline]
17881#[must_use]
17882const fn limbs_pow_16(base: Limbs<16>, exp: Limbs<16>) -> Limbs<16> {
17883 let mut result = limbs_one_16();
17884 let mut b = base;
17885 let ew = exp.words();
17886 let mut word = 0usize;
17887 while word < 16 {
17888 let mut bit = 0u32;
17889 while bit < 64 {
17890 if ((ew[word] >> bit) & 1u64) == 1u64 {
17891 result = result.wrapping_mul(b);
17892 }
17893 b = b.wrapping_mul(b);
17894 bit += 1;
17895 }
17896 word += 1;
17897 }
17898 result
17899}
17900
17901#[inline]
17902#[must_use]
17903const fn limbs_is_zero_32(a: Limbs<32>) -> bool {
17904 let aw = a.words();
17905 let mut i = 0usize;
17906 while i < 32 {
17907 if aw[i] != 0 {
17908 return false;
17909 }
17910 i += 1;
17911 }
17912 true
17913}
17914
17915#[inline]
17916#[must_use]
17917const fn limbs_shl1_32(a: Limbs<32>) -> Limbs<32> {
17918 let aw = a.words();
17919 let mut out = [0u64; 32];
17920 let mut carry: u64 = 0;
17921 let mut i = 0usize;
17922 while i < 32 {
17923 let v = aw[i];
17924 out[i] = (v << 1) | carry;
17925 carry = v >> 63;
17926 i += 1;
17927 }
17928 Limbs::<32>::from_words(out)
17929}
17930
17931#[inline]
17932#[must_use]
17933const fn limbs_set_bit0_32(a: Limbs<32>) -> Limbs<32> {
17934 let aw = a.words();
17935 let mut out = [0u64; 32];
17936 let mut i = 0usize;
17937 while i < 32 {
17938 out[i] = aw[i];
17939 i += 1;
17940 }
17941 out[0] |= 1u64;
17942 Limbs::<32>::from_words(out)
17943}
17944
17945#[inline]
17946#[must_use]
17947const fn limbs_bit_msb_32(a: Limbs<32>, msb_index: usize) -> u64 {
17948 let aw = a.words();
17949 let total_bits = 32 * 64;
17950 let lsb_index = total_bits - 1 - msb_index;
17951 let word = lsb_index / 64;
17952 let bit = lsb_index % 64;
17953 (aw[word] >> bit) & 1u64
17954}
17955
17956#[inline]
17957#[must_use]
17958const fn limbs_divmod_32(a: Limbs<32>, b: Limbs<32>) -> (Limbs<32>, Limbs<32>) {
17959 let mut q = Limbs::<32>::zero();
17960 let mut r = Limbs::<32>::zero();
17961 let total_bits = 32 * 64;
17962 let mut i = 0usize;
17963 while i < total_bits {
17964 r = limbs_shl1_32(r);
17965 if limbs_bit_msb_32(a, i) == 1 {
17966 r = limbs_set_bit0_32(r);
17967 }
17968 if limbs_le_32(b, r) {
17969 r = r.wrapping_sub(b);
17970 q = limbs_shl1_32(q);
17971 q = limbs_set_bit0_32(q);
17972 } else {
17973 q = limbs_shl1_32(q);
17974 }
17975 i += 1;
17976 }
17977 (q, r)
17978}
17979
17980#[inline]
17981#[must_use]
17982const fn limbs_div_32(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
17983 let (q, _) = limbs_divmod_32(a, b);
17984 q
17985}
17986
17987#[inline]
17988#[must_use]
17989const fn limbs_mod_32(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
17990 let (_, r) = limbs_divmod_32(a, b);
17991 r
17992}
17993
17994#[inline]
17995#[must_use]
17996const fn limbs_pow_32(base: Limbs<32>, exp: Limbs<32>) -> Limbs<32> {
17997 let mut result = limbs_one_32();
17998 let mut b = base;
17999 let ew = exp.words();
18000 let mut word = 0usize;
18001 while word < 32 {
18002 let mut bit = 0u32;
18003 while bit < 64 {
18004 if ((ew[word] >> bit) & 1u64) == 1u64 {
18005 result = result.wrapping_mul(b);
18006 }
18007 b = b.wrapping_mul(b);
18008 bit += 1;
18009 }
18010 word += 1;
18011 }
18012 result
18013}
18014
18015#[inline]
18016#[must_use]
18017const fn limbs_is_zero_64(a: Limbs<64>) -> bool {
18018 let aw = a.words();
18019 let mut i = 0usize;
18020 while i < 64 {
18021 if aw[i] != 0 {
18022 return false;
18023 }
18024 i += 1;
18025 }
18026 true
18027}
18028
18029#[inline]
18030#[must_use]
18031const fn limbs_shl1_64(a: Limbs<64>) -> Limbs<64> {
18032 let aw = a.words();
18033 let mut out = [0u64; 64];
18034 let mut carry: u64 = 0;
18035 let mut i = 0usize;
18036 while i < 64 {
18037 let v = aw[i];
18038 out[i] = (v << 1) | carry;
18039 carry = v >> 63;
18040 i += 1;
18041 }
18042 Limbs::<64>::from_words(out)
18043}
18044
18045#[inline]
18046#[must_use]
18047const fn limbs_set_bit0_64(a: Limbs<64>) -> Limbs<64> {
18048 let aw = a.words();
18049 let mut out = [0u64; 64];
18050 let mut i = 0usize;
18051 while i < 64 {
18052 out[i] = aw[i];
18053 i += 1;
18054 }
18055 out[0] |= 1u64;
18056 Limbs::<64>::from_words(out)
18057}
18058
18059#[inline]
18060#[must_use]
18061const fn limbs_bit_msb_64(a: Limbs<64>, msb_index: usize) -> u64 {
18062 let aw = a.words();
18063 let total_bits = 64 * 64;
18064 let lsb_index = total_bits - 1 - msb_index;
18065 let word = lsb_index / 64;
18066 let bit = lsb_index % 64;
18067 (aw[word] >> bit) & 1u64
18068}
18069
18070#[inline]
18071#[must_use]
18072const fn limbs_divmod_64(a: Limbs<64>, b: Limbs<64>) -> (Limbs<64>, Limbs<64>) {
18073 let mut q = Limbs::<64>::zero();
18074 let mut r = Limbs::<64>::zero();
18075 let total_bits = 64 * 64;
18076 let mut i = 0usize;
18077 while i < total_bits {
18078 r = limbs_shl1_64(r);
18079 if limbs_bit_msb_64(a, i) == 1 {
18080 r = limbs_set_bit0_64(r);
18081 }
18082 if limbs_le_64(b, r) {
18083 r = r.wrapping_sub(b);
18084 q = limbs_shl1_64(q);
18085 q = limbs_set_bit0_64(q);
18086 } else {
18087 q = limbs_shl1_64(q);
18088 }
18089 i += 1;
18090 }
18091 (q, r)
18092}
18093
18094#[inline]
18095#[must_use]
18096const fn limbs_div_64(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
18097 let (q, _) = limbs_divmod_64(a, b);
18098 q
18099}
18100
18101#[inline]
18102#[must_use]
18103const fn limbs_mod_64(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
18104 let (_, r) = limbs_divmod_64(a, b);
18105 r
18106}
18107
18108#[inline]
18109#[must_use]
18110const fn limbs_pow_64(base: Limbs<64>, exp: Limbs<64>) -> Limbs<64> {
18111 let mut result = limbs_one_64();
18112 let mut b = base;
18113 let ew = exp.words();
18114 let mut word = 0usize;
18115 while word < 64 {
18116 let mut bit = 0u32;
18117 while bit < 64 {
18118 if ((ew[word] >> bit) & 1u64) == 1u64 {
18119 result = result.wrapping_mul(b);
18120 }
18121 b = b.wrapping_mul(b);
18122 bit += 1;
18123 }
18124 word += 1;
18125 }
18126 result
18127}
18128
18129#[inline]
18130#[must_use]
18131const fn limbs_is_zero_128(a: Limbs<128>) -> bool {
18132 let aw = a.words();
18133 let mut i = 0usize;
18134 while i < 128 {
18135 if aw[i] != 0 {
18136 return false;
18137 }
18138 i += 1;
18139 }
18140 true
18141}
18142
18143#[inline]
18144#[must_use]
18145const fn limbs_shl1_128(a: Limbs<128>) -> Limbs<128> {
18146 let aw = a.words();
18147 let mut out = [0u64; 128];
18148 let mut carry: u64 = 0;
18149 let mut i = 0usize;
18150 while i < 128 {
18151 let v = aw[i];
18152 out[i] = (v << 1) | carry;
18153 carry = v >> 63;
18154 i += 1;
18155 }
18156 Limbs::<128>::from_words(out)
18157}
18158
18159#[inline]
18160#[must_use]
18161const fn limbs_set_bit0_128(a: Limbs<128>) -> Limbs<128> {
18162 let aw = a.words();
18163 let mut out = [0u64; 128];
18164 let mut i = 0usize;
18165 while i < 128 {
18166 out[i] = aw[i];
18167 i += 1;
18168 }
18169 out[0] |= 1u64;
18170 Limbs::<128>::from_words(out)
18171}
18172
18173#[inline]
18174#[must_use]
18175const fn limbs_bit_msb_128(a: Limbs<128>, msb_index: usize) -> u64 {
18176 let aw = a.words();
18177 let total_bits = 128 * 64;
18178 let lsb_index = total_bits - 1 - msb_index;
18179 let word = lsb_index / 64;
18180 let bit = lsb_index % 64;
18181 (aw[word] >> bit) & 1u64
18182}
18183
18184#[inline]
18185#[must_use]
18186const fn limbs_divmod_128(a: Limbs<128>, b: Limbs<128>) -> (Limbs<128>, Limbs<128>) {
18187 let mut q = Limbs::<128>::zero();
18188 let mut r = Limbs::<128>::zero();
18189 let total_bits = 128 * 64;
18190 let mut i = 0usize;
18191 while i < total_bits {
18192 r = limbs_shl1_128(r);
18193 if limbs_bit_msb_128(a, i) == 1 {
18194 r = limbs_set_bit0_128(r);
18195 }
18196 if limbs_le_128(b, r) {
18197 r = r.wrapping_sub(b);
18198 q = limbs_shl1_128(q);
18199 q = limbs_set_bit0_128(q);
18200 } else {
18201 q = limbs_shl1_128(q);
18202 }
18203 i += 1;
18204 }
18205 (q, r)
18206}
18207
18208#[inline]
18209#[must_use]
18210const fn limbs_div_128(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
18211 let (q, _) = limbs_divmod_128(a, b);
18212 q
18213}
18214
18215#[inline]
18216#[must_use]
18217const fn limbs_mod_128(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
18218 let (_, r) = limbs_divmod_128(a, b);
18219 r
18220}
18221
18222#[inline]
18223#[must_use]
18224const fn limbs_pow_128(base: Limbs<128>, exp: Limbs<128>) -> Limbs<128> {
18225 let mut result = limbs_one_128();
18226 let mut b = base;
18227 let ew = exp.words();
18228 let mut word = 0usize;
18229 while word < 128 {
18230 let mut bit = 0u32;
18231 while bit < 64 {
18232 if ((ew[word] >> bit) & 1u64) == 1u64 {
18233 result = result.wrapping_mul(b);
18234 }
18235 b = b.wrapping_mul(b);
18236 bit += 1;
18237 }
18238 word += 1;
18239 }
18240 result
18241}
18242
18243#[inline]
18244#[must_use]
18245const fn limbs_is_zero_192(a: Limbs<192>) -> bool {
18246 let aw = a.words();
18247 let mut i = 0usize;
18248 while i < 192 {
18249 if aw[i] != 0 {
18250 return false;
18251 }
18252 i += 1;
18253 }
18254 true
18255}
18256
18257#[inline]
18258#[must_use]
18259const fn limbs_shl1_192(a: Limbs<192>) -> Limbs<192> {
18260 let aw = a.words();
18261 let mut out = [0u64; 192];
18262 let mut carry: u64 = 0;
18263 let mut i = 0usize;
18264 while i < 192 {
18265 let v = aw[i];
18266 out[i] = (v << 1) | carry;
18267 carry = v >> 63;
18268 i += 1;
18269 }
18270 Limbs::<192>::from_words(out)
18271}
18272
18273#[inline]
18274#[must_use]
18275const fn limbs_set_bit0_192(a: Limbs<192>) -> Limbs<192> {
18276 let aw = a.words();
18277 let mut out = [0u64; 192];
18278 let mut i = 0usize;
18279 while i < 192 {
18280 out[i] = aw[i];
18281 i += 1;
18282 }
18283 out[0] |= 1u64;
18284 Limbs::<192>::from_words(out)
18285}
18286
18287#[inline]
18288#[must_use]
18289const fn limbs_bit_msb_192(a: Limbs<192>, msb_index: usize) -> u64 {
18290 let aw = a.words();
18291 let total_bits = 192 * 64;
18292 let lsb_index = total_bits - 1 - msb_index;
18293 let word = lsb_index / 64;
18294 let bit = lsb_index % 64;
18295 (aw[word] >> bit) & 1u64
18296}
18297
18298#[inline]
18299#[must_use]
18300const fn limbs_divmod_192(a: Limbs<192>, b: Limbs<192>) -> (Limbs<192>, Limbs<192>) {
18301 let mut q = Limbs::<192>::zero();
18302 let mut r = Limbs::<192>::zero();
18303 let total_bits = 192 * 64;
18304 let mut i = 0usize;
18305 while i < total_bits {
18306 r = limbs_shl1_192(r);
18307 if limbs_bit_msb_192(a, i) == 1 {
18308 r = limbs_set_bit0_192(r);
18309 }
18310 if limbs_le_192(b, r) {
18311 r = r.wrapping_sub(b);
18312 q = limbs_shl1_192(q);
18313 q = limbs_set_bit0_192(q);
18314 } else {
18315 q = limbs_shl1_192(q);
18316 }
18317 i += 1;
18318 }
18319 (q, r)
18320}
18321
18322#[inline]
18323#[must_use]
18324const fn limbs_div_192(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
18325 let (q, _) = limbs_divmod_192(a, b);
18326 q
18327}
18328
18329#[inline]
18330#[must_use]
18331const fn limbs_mod_192(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
18332 let (_, r) = limbs_divmod_192(a, b);
18333 r
18334}
18335
18336#[inline]
18337#[must_use]
18338const fn limbs_pow_192(base: Limbs<192>, exp: Limbs<192>) -> Limbs<192> {
18339 let mut result = limbs_one_192();
18340 let mut b = base;
18341 let ew = exp.words();
18342 let mut word = 0usize;
18343 while word < 192 {
18344 let mut bit = 0u32;
18345 while bit < 64 {
18346 if ((ew[word] >> bit) & 1u64) == 1u64 {
18347 result = result.wrapping_mul(b);
18348 }
18349 b = b.wrapping_mul(b);
18350 bit += 1;
18351 }
18352 word += 1;
18353 }
18354 result
18355}
18356
18357#[inline]
18358#[must_use]
18359const fn limbs_is_zero_256(a: Limbs<256>) -> bool {
18360 let aw = a.words();
18361 let mut i = 0usize;
18362 while i < 256 {
18363 if aw[i] != 0 {
18364 return false;
18365 }
18366 i += 1;
18367 }
18368 true
18369}
18370
18371#[inline]
18372#[must_use]
18373const fn limbs_shl1_256(a: Limbs<256>) -> Limbs<256> {
18374 let aw = a.words();
18375 let mut out = [0u64; 256];
18376 let mut carry: u64 = 0;
18377 let mut i = 0usize;
18378 while i < 256 {
18379 let v = aw[i];
18380 out[i] = (v << 1) | carry;
18381 carry = v >> 63;
18382 i += 1;
18383 }
18384 Limbs::<256>::from_words(out)
18385}
18386
18387#[inline]
18388#[must_use]
18389const fn limbs_set_bit0_256(a: Limbs<256>) -> Limbs<256> {
18390 let aw = a.words();
18391 let mut out = [0u64; 256];
18392 let mut i = 0usize;
18393 while i < 256 {
18394 out[i] = aw[i];
18395 i += 1;
18396 }
18397 out[0] |= 1u64;
18398 Limbs::<256>::from_words(out)
18399}
18400
18401#[inline]
18402#[must_use]
18403const fn limbs_bit_msb_256(a: Limbs<256>, msb_index: usize) -> u64 {
18404 let aw = a.words();
18405 let total_bits = 256 * 64;
18406 let lsb_index = total_bits - 1 - msb_index;
18407 let word = lsb_index / 64;
18408 let bit = lsb_index % 64;
18409 (aw[word] >> bit) & 1u64
18410}
18411
18412#[inline]
18413#[must_use]
18414const fn limbs_divmod_256(a: Limbs<256>, b: Limbs<256>) -> (Limbs<256>, Limbs<256>) {
18415 let mut q = Limbs::<256>::zero();
18416 let mut r = Limbs::<256>::zero();
18417 let total_bits = 256 * 64;
18418 let mut i = 0usize;
18419 while i < total_bits {
18420 r = limbs_shl1_256(r);
18421 if limbs_bit_msb_256(a, i) == 1 {
18422 r = limbs_set_bit0_256(r);
18423 }
18424 if limbs_le_256(b, r) {
18425 r = r.wrapping_sub(b);
18426 q = limbs_shl1_256(q);
18427 q = limbs_set_bit0_256(q);
18428 } else {
18429 q = limbs_shl1_256(q);
18430 }
18431 i += 1;
18432 }
18433 (q, r)
18434}
18435
18436#[inline]
18437#[must_use]
18438const fn limbs_div_256(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
18439 let (q, _) = limbs_divmod_256(a, b);
18440 q
18441}
18442
18443#[inline]
18444#[must_use]
18445const fn limbs_mod_256(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
18446 let (_, r) = limbs_divmod_256(a, b);
18447 r
18448}
18449
18450#[inline]
18451#[must_use]
18452const fn limbs_pow_256(base: Limbs<256>, exp: Limbs<256>) -> Limbs<256> {
18453 let mut result = limbs_one_256();
18454 let mut b = base;
18455 let ew = exp.words();
18456 let mut word = 0usize;
18457 while word < 256 {
18458 let mut bit = 0u32;
18459 while bit < 64 {
18460 if ((ew[word] >> bit) & 1u64) == 1u64 {
18461 result = result.wrapping_mul(b);
18462 }
18463 b = b.wrapping_mul(b);
18464 bit += 1;
18465 }
18466 word += 1;
18467 }
18468 result
18469}
18470
18471#[inline]
18472#[must_use]
18473const fn limbs_is_zero_512(a: Limbs<512>) -> bool {
18474 let aw = a.words();
18475 let mut i = 0usize;
18476 while i < 512 {
18477 if aw[i] != 0 {
18478 return false;
18479 }
18480 i += 1;
18481 }
18482 true
18483}
18484
18485#[inline]
18486#[must_use]
18487const fn limbs_shl1_512(a: Limbs<512>) -> Limbs<512> {
18488 let aw = a.words();
18489 let mut out = [0u64; 512];
18490 let mut carry: u64 = 0;
18491 let mut i = 0usize;
18492 while i < 512 {
18493 let v = aw[i];
18494 out[i] = (v << 1) | carry;
18495 carry = v >> 63;
18496 i += 1;
18497 }
18498 Limbs::<512>::from_words(out)
18499}
18500
18501#[inline]
18502#[must_use]
18503const fn limbs_set_bit0_512(a: Limbs<512>) -> Limbs<512> {
18504 let aw = a.words();
18505 let mut out = [0u64; 512];
18506 let mut i = 0usize;
18507 while i < 512 {
18508 out[i] = aw[i];
18509 i += 1;
18510 }
18511 out[0] |= 1u64;
18512 Limbs::<512>::from_words(out)
18513}
18514
18515#[inline]
18516#[must_use]
18517const fn limbs_bit_msb_512(a: Limbs<512>, msb_index: usize) -> u64 {
18518 let aw = a.words();
18519 let total_bits = 512 * 64;
18520 let lsb_index = total_bits - 1 - msb_index;
18521 let word = lsb_index / 64;
18522 let bit = lsb_index % 64;
18523 (aw[word] >> bit) & 1u64
18524}
18525
18526#[inline]
18527#[must_use]
18528const fn limbs_divmod_512(a: Limbs<512>, b: Limbs<512>) -> (Limbs<512>, Limbs<512>) {
18529 let mut q = Limbs::<512>::zero();
18530 let mut r = Limbs::<512>::zero();
18531 let total_bits = 512 * 64;
18532 let mut i = 0usize;
18533 while i < total_bits {
18534 r = limbs_shl1_512(r);
18535 if limbs_bit_msb_512(a, i) == 1 {
18536 r = limbs_set_bit0_512(r);
18537 }
18538 if limbs_le_512(b, r) {
18539 r = r.wrapping_sub(b);
18540 q = limbs_shl1_512(q);
18541 q = limbs_set_bit0_512(q);
18542 } else {
18543 q = limbs_shl1_512(q);
18544 }
18545 i += 1;
18546 }
18547 (q, r)
18548}
18549
18550#[inline]
18551#[must_use]
18552const fn limbs_div_512(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
18553 let (q, _) = limbs_divmod_512(a, b);
18554 q
18555}
18556
18557#[inline]
18558#[must_use]
18559const fn limbs_mod_512(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
18560 let (_, r) = limbs_divmod_512(a, b);
18561 r
18562}
18563
18564#[inline]
18565#[must_use]
18566const fn limbs_pow_512(base: Limbs<512>, exp: Limbs<512>) -> Limbs<512> {
18567 let mut result = limbs_one_512();
18568 let mut b = base;
18569 let ew = exp.words();
18570 let mut word = 0usize;
18571 while word < 512 {
18572 let mut bit = 0u32;
18573 while bit < 64 {
18574 if ((ew[word] >> bit) & 1u64) == 1u64 {
18575 result = result.wrapping_mul(b);
18576 }
18577 b = b.wrapping_mul(b);
18578 bit += 1;
18579 }
18580 word += 1;
18581 }
18582 result
18583}
18584
18585pub trait FragmentMarker: fragment_sealed::Sealed {}
18589
18590mod fragment_sealed {
18591 pub trait Sealed {}
18593 impl Sealed for super::Is2SatShape {}
18594 impl Sealed for super::IsHornShape {}
18595 impl Sealed for super::IsResidualFragment {}
18596}
18597
18598#[derive(Debug, Default, Clone, Copy)]
18600pub struct Is2SatShape;
18601impl FragmentMarker for Is2SatShape {}
18602
18603#[derive(Debug, Default, Clone, Copy)]
18605pub struct IsHornShape;
18606impl FragmentMarker for IsHornShape {}
18607
18608#[derive(Debug, Default, Clone, Copy)]
18610pub struct IsResidualFragment;
18611impl FragmentMarker for IsResidualFragment {}
18612
18613#[derive(Debug, Clone, Copy)]
18616pub struct DispatchRule {
18617 pub predicate_iri: &'static str,
18619 pub target_resolver_iri: &'static str,
18621 pub priority: u32,
18623}
18624
18625pub type DispatchTable = &'static [DispatchRule];
18627
18628pub const INHABITANCE_DISPATCH_TABLE: DispatchTable = &[
18630 DispatchRule {
18631 predicate_iri: "https://uor.foundation/predicate/Is2SatShape",
18632 target_resolver_iri: "https://uor.foundation/resolver/TwoSatDecider",
18633 priority: 0,
18634 },
18635 DispatchRule {
18636 predicate_iri: "https://uor.foundation/predicate/IsHornShape",
18637 target_resolver_iri: "https://uor.foundation/resolver/HornSatDecider",
18638 priority: 1,
18639 },
18640 DispatchRule {
18641 predicate_iri: "https://uor.foundation/predicate/IsResidualFragment",
18642 target_resolver_iri: "https://uor.foundation/resolver/ResidualVerdictResolver",
18643 priority: 2,
18644 },
18645];
18646
18647impl<T: OntologyTarget> core::ops::Deref for Validated<T> {
18652 type Target = T;
18653 #[inline]
18654 fn deref(&self) -> &T {
18655 &self.inner
18656 }
18657}
18658
18659mod bound_constraint_sealed {
18660 pub trait ObservableSealed {}
18662 pub trait BoundShapeSealed {}
18664}
18665
18666pub trait Observable: bound_constraint_sealed::ObservableSealed {
18671 const IRI: &'static str;
18673}
18674
18675pub trait BoundShape: bound_constraint_sealed::BoundShapeSealed {
18679 const IRI: &'static str;
18681}
18682
18683#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18685pub struct ValueModObservable;
18686impl bound_constraint_sealed::ObservableSealed for ValueModObservable {}
18687impl Observable for ValueModObservable {
18688 const IRI: &'static str = "https://uor.foundation/observable/ValueModObservable";
18689}
18690
18691#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18693pub struct HammingMetric;
18694impl bound_constraint_sealed::ObservableSealed for HammingMetric {}
18695impl Observable for HammingMetric {
18696 const IRI: &'static str = "https://uor.foundation/observable/HammingMetric";
18697}
18698
18699#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18701pub struct DerivationDepthObservable;
18702impl bound_constraint_sealed::ObservableSealed for DerivationDepthObservable {}
18703impl Observable for DerivationDepthObservable {
18704 const IRI: &'static str = "https://uor.foundation/derivation/DerivationDepthObservable";
18705}
18706
18707#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18709pub struct CarryDepthObservable;
18710impl bound_constraint_sealed::ObservableSealed for CarryDepthObservable {}
18711impl Observable for CarryDepthObservable {
18712 const IRI: &'static str = "https://uor.foundation/carry/CarryDepthObservable";
18713}
18714
18715#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18717pub struct FreeRankObservable;
18718impl bound_constraint_sealed::ObservableSealed for FreeRankObservable {}
18719impl Observable for FreeRankObservable {
18720 const IRI: &'static str = "https://uor.foundation/partition/FreeRankObservable";
18721}
18722
18723#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18725pub struct EqualBound;
18726impl bound_constraint_sealed::BoundShapeSealed for EqualBound {}
18727impl BoundShape for EqualBound {
18728 const IRI: &'static str = "https://uor.foundation/type/EqualBound";
18729}
18730
18731#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18733pub struct LessEqBound;
18734impl bound_constraint_sealed::BoundShapeSealed for LessEqBound {}
18735impl BoundShape for LessEqBound {
18736 const IRI: &'static str = "https://uor.foundation/type/LessEqBound";
18737}
18738
18739#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18741pub struct GreaterEqBound;
18742impl bound_constraint_sealed::BoundShapeSealed for GreaterEqBound {}
18743impl BoundShape for GreaterEqBound {
18744 const IRI: &'static str = "https://uor.foundation/type/GreaterEqBound";
18745}
18746
18747#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18749pub struct RangeContainBound;
18750impl bound_constraint_sealed::BoundShapeSealed for RangeContainBound {}
18751impl BoundShape for RangeContainBound {
18752 const IRI: &'static str = "https://uor.foundation/type/RangeContainBound";
18753}
18754
18755#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18757pub struct ResidueClassBound;
18758impl bound_constraint_sealed::BoundShapeSealed for ResidueClassBound {}
18759impl BoundShape for ResidueClassBound {
18760 const IRI: &'static str = "https://uor.foundation/type/ResidueClassBound";
18761}
18762
18763#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18765pub struct AffineEqualBound;
18766impl bound_constraint_sealed::BoundShapeSealed for AffineEqualBound {}
18767impl BoundShape for AffineEqualBound {
18768 const IRI: &'static str = "https://uor.foundation/type/AffineEqualBound";
18769}
18770
18771#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18775pub enum BoundArgValue {
18776 U64(u64),
18778 I64(i64),
18780 Bytes32([u8; 32]),
18782}
18783
18784#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18790pub struct BoundArguments {
18791 entries: [Option<BoundArgEntry>; 8],
18792}
18793
18794#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18796pub struct BoundArgEntry {
18797 pub name: &'static str,
18799 pub value: BoundArgValue,
18801}
18802
18803impl BoundArguments {
18804 #[inline]
18806 #[must_use]
18807 pub const fn empty() -> Self {
18808 Self { entries: [None; 8] }
18809 }
18810
18811 #[inline]
18813 #[must_use]
18814 pub const fn single(name: &'static str, value: BoundArgValue) -> Self {
18815 let mut entries = [None; 8];
18816 entries[0] = Some(BoundArgEntry { name, value });
18817 Self { entries }
18818 }
18819
18820 #[inline]
18822 #[must_use]
18823 pub const fn pair(
18824 first: (&'static str, BoundArgValue),
18825 second: (&'static str, BoundArgValue),
18826 ) -> Self {
18827 let mut entries = [None; 8];
18828 entries[0] = Some(BoundArgEntry {
18829 name: first.0,
18830 value: first.1,
18831 });
18832 entries[1] = Some(BoundArgEntry {
18833 name: second.0,
18834 value: second.1,
18835 });
18836 Self { entries }
18837 }
18838
18839 #[inline]
18841 #[must_use]
18842 pub const fn entries(&self) -> &[Option<BoundArgEntry>; 8] {
18843 &self.entries
18844 }
18845}
18846
18847#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18852pub struct BoundConstraint<O: Observable, B: BoundShape> {
18853 observable: O,
18854 bound: B,
18855 args: BoundArguments,
18856 _sealed: (),
18857}
18858
18859impl<O: Observable, B: BoundShape> BoundConstraint<O, B> {
18860 #[inline]
18863 #[must_use]
18864 pub(crate) const fn from_parts(observable: O, bound: B, args: BoundArguments) -> Self {
18865 Self {
18866 observable,
18867 bound,
18868 args,
18869 _sealed: (),
18870 }
18871 }
18872
18873 #[inline]
18875 #[must_use]
18876 pub const fn observable(&self) -> &O {
18877 &self.observable
18878 }
18879
18880 #[inline]
18882 #[must_use]
18883 pub const fn bound(&self) -> &B {
18884 &self.bound
18885 }
18886
18887 #[inline]
18889 #[must_use]
18890 pub const fn args(&self) -> &BoundArguments {
18891 &self.args
18892 }
18893}
18894
18895#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18899pub struct Conjunction<const N: usize> {
18900 len: usize,
18901 _sealed: (),
18902}
18903
18904impl<const N: usize> Conjunction<N> {
18905 #[inline]
18907 #[must_use]
18908 pub const fn new(len: usize) -> Self {
18909 Self { len, _sealed: () }
18910 }
18911
18912 #[inline]
18914 #[must_use]
18915 pub const fn len(&self) -> usize {
18916 self.len
18917 }
18918
18919 #[inline]
18921 #[must_use]
18922 pub const fn is_empty(&self) -> bool {
18923 self.len == 0
18924 }
18925}
18926
18927pub type ResidueConstraint = BoundConstraint<ValueModObservable, ResidueClassBound>;
18930
18931impl ResidueConstraint {
18932 #[inline]
18934 #[must_use]
18935 pub const fn new(modulus: u64, residue: u64) -> Self {
18936 let args = BoundArguments::pair(
18937 ("modulus", BoundArgValue::U64(modulus)),
18938 ("residue", BoundArgValue::U64(residue)),
18939 );
18940 BoundConstraint::from_parts(ValueModObservable, ResidueClassBound, args)
18941 }
18942}
18943
18944pub type HammingConstraint = BoundConstraint<HammingMetric, LessEqBound>;
18947
18948impl HammingConstraint {
18949 #[inline]
18951 #[must_use]
18952 pub const fn new(bound: u64) -> Self {
18953 let args = BoundArguments::single("bound", BoundArgValue::U64(bound));
18954 BoundConstraint::from_parts(HammingMetric, LessEqBound, args)
18955 }
18956}
18957
18958pub type DepthConstraint = BoundConstraint<DerivationDepthObservable, LessEqBound>;
18961
18962impl DepthConstraint {
18963 #[inline]
18965 #[must_use]
18966 pub const fn new(min_depth: u64, max_depth: u64) -> Self {
18967 let args = BoundArguments::pair(
18968 ("min_depth", BoundArgValue::U64(min_depth)),
18969 ("max_depth", BoundArgValue::U64(max_depth)),
18970 );
18971 BoundConstraint::from_parts(DerivationDepthObservable, LessEqBound, args)
18972 }
18973}
18974
18975pub type CarryConstraint = BoundConstraint<CarryDepthObservable, LessEqBound>;
18978
18979impl CarryConstraint {
18980 #[inline]
18982 #[must_use]
18983 pub const fn new(bound: u64) -> Self {
18984 let args = BoundArguments::single("bound", BoundArgValue::U64(bound));
18985 BoundConstraint::from_parts(CarryDepthObservable, LessEqBound, args)
18986 }
18987}
18988
18989pub type SiteConstraint = BoundConstraint<FreeRankObservable, LessEqBound>;
18992
18993impl SiteConstraint {
18994 #[inline]
18996 #[must_use]
18997 pub const fn new(site_index: u64) -> Self {
18998 let args = BoundArguments::single("site_index", BoundArgValue::U64(site_index));
18999 BoundConstraint::from_parts(FreeRankObservable, LessEqBound, args)
19000 }
19001}
19002
19003pub type AffineConstraint = BoundConstraint<ValueModObservable, AffineEqualBound>;
19006
19007impl AffineConstraint {
19008 #[inline]
19010 #[must_use]
19011 pub const fn new(offset: u64) -> Self {
19012 let args = BoundArguments::single("offset", BoundArgValue::U64(offset));
19013 BoundConstraint::from_parts(ValueModObservable, AffineEqualBound, args)
19014 }
19015}
19016
19017pub type CompositeConstraint<const N: usize> = Conjunction<N>;
19020
19021#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19023pub struct Query {
19024 address: ContentAddress,
19025 _sealed: (),
19026}
19027
19028impl Query {
19029 #[inline]
19031 #[must_use]
19032 pub const fn address(&self) -> ContentAddress {
19033 self.address
19034 }
19035
19036 #[inline]
19038 #[must_use]
19039 #[allow(dead_code)]
19040 pub(crate) const fn new(address: ContentAddress) -> Self {
19041 Self {
19042 address,
19043 _sealed: (),
19044 }
19045 }
19046}
19047
19048#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19050pub struct Coordinate<L> {
19051 stratum: u64,
19052 spectrum: u64,
19053 address: u64,
19054 _level: PhantomData<L>,
19055 _sealed: (),
19056}
19057
19058impl<L> Coordinate<L> {
19059 #[inline]
19061 #[must_use]
19062 pub const fn stratum(&self) -> u64 {
19063 self.stratum
19064 }
19065
19066 #[inline]
19068 #[must_use]
19069 pub const fn spectrum(&self) -> u64 {
19070 self.spectrum
19071 }
19072
19073 #[inline]
19075 #[must_use]
19076 pub const fn address(&self) -> u64 {
19077 self.address
19078 }
19079
19080 #[inline]
19082 #[must_use]
19083 #[allow(dead_code)]
19084 pub(crate) const fn new(stratum: u64, spectrum: u64, address: u64) -> Self {
19085 Self {
19086 stratum,
19087 spectrum,
19088 address,
19089 _level: PhantomData,
19090 _sealed: (),
19091 }
19092 }
19093}
19094
19095#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19097pub struct BindingQuery {
19098 address: ContentAddress,
19099 _sealed: (),
19100}
19101
19102impl BindingQuery {
19103 #[inline]
19105 #[must_use]
19106 pub const fn address(&self) -> ContentAddress {
19107 self.address
19108 }
19109
19110 #[inline]
19112 #[must_use]
19113 #[allow(dead_code)]
19114 pub(crate) const fn new(address: ContentAddress) -> Self {
19115 Self {
19116 address,
19117 _sealed: (),
19118 }
19119 }
19120}
19121
19122#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19125pub struct Partition {
19126 component: PartitionComponent,
19127 _sealed: (),
19128}
19129
19130impl Partition {
19131 #[inline]
19133 #[must_use]
19134 pub const fn component(&self) -> PartitionComponent {
19135 self.component
19136 }
19137
19138 #[inline]
19140 #[must_use]
19141 #[allow(dead_code)]
19142 pub(crate) const fn new(component: PartitionComponent) -> Self {
19143 Self {
19144 component,
19145 _sealed: (),
19146 }
19147 }
19148}
19149
19150#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19155pub struct TraceEvent {
19156 step_index: u32,
19158 op: PrimitiveOp,
19160 target: ContentAddress,
19162 _sealed: (),
19164}
19165
19166impl TraceEvent {
19167 #[inline]
19169 #[must_use]
19170 pub const fn step_index(&self) -> u32 {
19171 self.step_index
19172 }
19173
19174 #[inline]
19176 #[must_use]
19177 pub const fn op(&self) -> PrimitiveOp {
19178 self.op
19179 }
19180
19181 #[inline]
19183 #[must_use]
19184 pub const fn target(&self) -> ContentAddress {
19185 self.target
19186 }
19187
19188 #[inline]
19190 #[must_use]
19191 #[allow(dead_code)]
19192 pub(crate) const fn new(step_index: u32, op: PrimitiveOp, target: ContentAddress) -> Self {
19193 Self {
19194 step_index,
19195 op,
19196 target,
19197 _sealed: (),
19198 }
19199 }
19200}
19201
19202#[derive(Debug, Clone, Copy)]
19211pub struct Trace<const TR_MAX: usize = 256> {
19212 events: [Option<TraceEvent>; TR_MAX],
19213 len: u16,
19214 witt_level_bits: u16,
19218 content_fingerprint: ContentFingerprint,
19225 _sealed: (),
19226}
19227
19228impl<const TR_MAX: usize> Trace<TR_MAX> {
19229 #[inline]
19231 #[must_use]
19232 pub const fn empty() -> Self {
19233 Self {
19234 events: [None; TR_MAX],
19235 len: 0,
19236 witt_level_bits: 0,
19237 content_fingerprint: ContentFingerprint::zero(),
19238 _sealed: (),
19239 }
19240 }
19241
19242 #[inline]
19248 #[must_use]
19249 #[allow(dead_code)]
19250 pub(crate) const fn from_replay_events_const(
19251 events: [Option<TraceEvent>; TR_MAX],
19252 len: u16,
19253 witt_level_bits: u16,
19254 content_fingerprint: ContentFingerprint,
19255 ) -> Self {
19256 Self {
19257 events,
19258 len,
19259 witt_level_bits,
19260 content_fingerprint,
19261 _sealed: (),
19262 }
19263 }
19264
19265 #[inline]
19267 #[must_use]
19268 pub const fn len(&self) -> u16 {
19269 self.len
19270 }
19271
19272 #[inline]
19274 #[must_use]
19275 pub const fn is_empty(&self) -> bool {
19276 self.len == 0
19277 }
19278
19279 #[inline]
19281 #[must_use]
19282 pub fn event(&self, index: usize) -> Option<&TraceEvent> {
19283 self.events.get(index).and_then(|e| e.as_ref())
19284 }
19285
19286 #[inline]
19289 #[must_use]
19290 pub const fn witt_level_bits(&self) -> u16 {
19291 self.witt_level_bits
19292 }
19293
19294 #[inline]
19299 #[must_use]
19300 pub const fn content_fingerprint(&self) -> ContentFingerprint {
19301 self.content_fingerprint
19302 }
19303
19304 pub fn try_from_events(
19316 events: &[TraceEvent],
19317 witt_level_bits: u16,
19318 content_fingerprint: ContentFingerprint,
19319 ) -> Result<Self, ReplayError> {
19320 if events.is_empty() {
19321 return Err(ReplayError::EmptyTrace);
19322 }
19323 if events.len() > TR_MAX {
19324 return Err(ReplayError::CapacityExceeded {
19325 declared: TR_MAX as u16,
19326 provided: events.len() as u32,
19327 });
19328 }
19329 let mut i = 0usize;
19330 while i < events.len() {
19331 let e = &events[i];
19332 if e.step_index() as usize != i {
19333 return Err(ReplayError::OutOfOrderEvent { index: i });
19334 }
19335 if e.target().is_zero() {
19336 return Err(ReplayError::ZeroTarget { index: i });
19337 }
19338 i += 1;
19339 }
19340 let mut arr = [None; TR_MAX];
19341 let mut j = 0usize;
19342 while j < events.len() {
19343 arr[j] = Some(events[j]);
19344 j += 1;
19345 }
19346 Ok(Self {
19347 events: arr,
19348 len: events.len() as u16,
19349 witt_level_bits,
19350 content_fingerprint,
19351 _sealed: (),
19352 })
19353 }
19354}
19355
19356impl<const TR_MAX: usize> Default for Trace<TR_MAX> {
19357 #[inline]
19358 fn default() -> Self {
19359 Self::empty()
19360 }
19361}
19362
19363impl Derivation {
19368 #[inline]
19407 #[must_use]
19408 pub fn replay<const TR_MAX: usize>(&self) -> Trace<TR_MAX> {
19409 let steps = self.step_count() as usize;
19410 let len = if steps > TR_MAX { TR_MAX } else { steps };
19411 let mut events = [None; TR_MAX];
19412 let fp = self.content_fingerprint.as_bytes();
19418 let seed =
19419 u64::from_be_bytes([fp[0], fp[1], fp[2], fp[3], fp[4], fp[5], fp[6], fp[7]]) as u128;
19420 let nonzero_seed = seed | 1u128;
19421 let mut i = 0usize;
19422 while i < len {
19423 let target_raw = nonzero_seed ^ ((i as u128) + 1u128);
19424 events[i] = Some(TraceEvent::new(
19425 i as u32,
19426 crate::PrimitiveOp::Add,
19427 ContentAddress::from_u128(target_raw),
19428 ));
19429 i += 1;
19430 }
19431 Trace::from_replay_events_const(
19437 events,
19438 len as u16,
19439 self.witt_level_bits,
19440 self.content_fingerprint,
19441 )
19442 }
19443}
19444
19445#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19447#[non_exhaustive]
19448pub enum ReplayError {
19449 EmptyTrace,
19451 OutOfOrderEvent {
19453 index: usize,
19455 },
19456 ZeroTarget {
19458 index: usize,
19460 },
19461 NonContiguousSteps {
19467 declared: u16,
19469 last_step: u32,
19473 },
19474 CapacityExceeded {
19481 declared: u16,
19483 provided: u32,
19485 },
19486}
19487
19488impl core::fmt::Display for ReplayError {
19489 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
19490 match self {
19491 Self::EmptyTrace => f.write_str("trace was empty; nothing to replay"),
19492 Self::OutOfOrderEvent { index } => write!(
19493 f,
19494 "event at index {index} has out-of-order step index",
19495 ),
19496 Self::ZeroTarget { index } => write!(
19497 f,
19498 "event at index {index} has a zero ContentAddress target",
19499 ),
19500 Self::NonContiguousSteps { declared, last_step } => write!(
19501 f,
19502 "trace declares {declared} events but step indices skip values \
19503 (last step {last_step})",
19504 ),
19505 Self::CapacityExceeded { declared, provided } => write!(
19506 f,
19507 "trace capacity exceeded: tried to pack {provided} events into a buffer of {declared}",
19508 ),
19509 }
19510 }
19511}
19512
19513impl core::error::Error for ReplayError {}
19514
19515pub mod replay {
19522 use super::{Certified, GroundingCertificate, ReplayError, Trace};
19523
19524 pub fn certify_from_trace<const TR_MAX: usize>(
19552 trace: &Trace<TR_MAX>,
19553 ) -> Result<Certified<GroundingCertificate>, ReplayError> {
19554 let len = trace.len() as usize;
19555 if len == 0 {
19556 return Err(ReplayError::EmptyTrace);
19557 }
19558 let mut last_step: i64 = -1;
19561 let mut max_step_index: u32 = 0;
19562 let mut i = 0usize;
19563 while i < len {
19564 let event = match trace.event(i) {
19565 Some(e) => e,
19566 None => return Err(ReplayError::OutOfOrderEvent { index: i }),
19567 };
19568 let step_index = event.step_index();
19569 if (step_index as i64) <= last_step {
19570 return Err(ReplayError::OutOfOrderEvent { index: i });
19571 }
19572 if event.target().is_zero() {
19573 return Err(ReplayError::ZeroTarget { index: i });
19574 }
19575 if step_index > max_step_index {
19576 max_step_index = step_index;
19577 }
19578 last_step = step_index as i64;
19579 i += 1;
19580 }
19581 if (max_step_index as u16).saturating_add(1) != trace.len() {
19582 return Err(ReplayError::NonContiguousSteps {
19583 declared: trace.len(),
19584 last_step: max_step_index,
19585 });
19586 }
19587 Ok(Certified::new(
19595 GroundingCertificate::with_level_and_fingerprint_const(
19596 trace.witt_level_bits(),
19597 trace.content_fingerprint(),
19598 ),
19599 ))
19600 }
19601}
19602
19603#[derive(Debug, Clone, Copy, Default)]
19608pub struct InteractionDeclarationBuilder {
19609 peer_protocol: Option<u128>,
19610 convergence_predicate: Option<u128>,
19611 commutator_state_class: Option<u128>,
19612}
19613
19614impl InteractionDeclarationBuilder {
19615 #[inline]
19617 #[must_use]
19618 pub const fn new() -> Self {
19619 Self {
19620 peer_protocol: None,
19621 convergence_predicate: None,
19622 commutator_state_class: None,
19623 }
19624 }
19625
19626 #[inline]
19628 #[must_use]
19629 pub const fn peer_protocol(mut self, address: u128) -> Self {
19630 self.peer_protocol = Some(address);
19631 self
19632 }
19633
19634 #[inline]
19636 #[must_use]
19637 pub const fn convergence_predicate(mut self, address: u128) -> Self {
19638 self.convergence_predicate = Some(address);
19639 self
19640 }
19641
19642 #[inline]
19644 #[must_use]
19645 pub const fn commutator_state_class(mut self, address: u128) -> Self {
19646 self.commutator_state_class = Some(address);
19647 self
19648 }
19649
19650 pub fn validate(&self) -> Result<Validated<InteractionShape>, ShapeViolation> {
19654 self.validate_common().map(|_| {
19655 Validated::new(InteractionShape {
19656 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19657 })
19658 })
19659 }
19660
19661 pub const fn validate_const(
19665 &self,
19666 ) -> Result<Validated<InteractionShape, CompileTime>, ShapeViolation> {
19667 if self.peer_protocol.is_none() {
19668 return Err(ShapeViolation {
19669 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19670 constraint_iri: "https://uor.foundation/conformance/InteractionShape",
19671 property_iri: "https://uor.foundation/interaction/peerProtocol",
19672 expected_range: "http://www.w3.org/2002/07/owl#Thing",
19673 min_count: 1,
19674 max_count: 1,
19675 kind: ViolationKind::Missing,
19676 });
19677 }
19678 if self.convergence_predicate.is_none() {
19679 return Err(ShapeViolation {
19680 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19681 constraint_iri: "https://uor.foundation/conformance/InteractionShape",
19682 property_iri: "https://uor.foundation/interaction/convergencePredicate",
19683 expected_range: "http://www.w3.org/2002/07/owl#Thing",
19684 min_count: 1,
19685 max_count: 1,
19686 kind: ViolationKind::Missing,
19687 });
19688 }
19689 if self.commutator_state_class.is_none() {
19690 return Err(ShapeViolation {
19691 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19692 constraint_iri: "https://uor.foundation/conformance/InteractionShape",
19693 property_iri: "https://uor.foundation/interaction/commutatorStateClass",
19694 expected_range: "http://www.w3.org/2002/07/owl#Thing",
19695 min_count: 1,
19696 max_count: 1,
19697 kind: ViolationKind::Missing,
19698 });
19699 }
19700 Ok(Validated::new(InteractionShape {
19701 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19702 }))
19703 }
19704
19705 fn validate_common(&self) -> Result<(), ShapeViolation> {
19706 self.validate_const().map(|_| ())
19707 }
19708}
19709
19710#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19712pub struct InteractionShape {
19713 pub shape_iri: &'static str,
19715}
19716
19717#[cfg(feature = "observability")]
19723pub fn subscribe_trace_events<F>(handler: F) -> ObservabilitySubscription<F>
19724where
19725 F: FnMut(&TraceEvent),
19726{
19727 ObservabilitySubscription {
19728 handler,
19729 _sealed: (),
19730 }
19731}
19732
19733#[cfg(feature = "observability")]
19734#[cfg(feature = "observability")]
19736pub struct ObservabilitySubscription<F: FnMut(&TraceEvent)> {
19737 handler: F,
19738 _sealed: (),
19739}
19740
19741#[cfg(feature = "observability")]
19742impl<F: FnMut(&TraceEvent)> ObservabilitySubscription<F> {
19743 pub fn emit(&mut self, event: &TraceEvent) {
19745 (self.handler)(event);
19746 }
19747}
19748
19749#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19755#[non_exhaustive]
19756pub enum ConstraintKind {
19757 Residue,
19759 Carry,
19761 Depth,
19763 Hamming,
19765 Site,
19767 Affine,
19769}
19770
19771#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19773pub struct CarryProfile {
19774 chain_length: u32,
19775 max_depth: u32,
19776 _sealed: (),
19777}
19778
19779impl CarryProfile {
19780 #[inline]
19782 #[must_use]
19783 pub const fn chain_length(&self) -> u32 {
19784 self.chain_length
19785 }
19786
19787 #[inline]
19789 #[must_use]
19790 pub const fn max_depth(&self) -> u32 {
19791 self.max_depth
19792 }
19793
19794 #[inline]
19796 #[must_use]
19797 #[allow(dead_code)]
19798 pub(crate) const fn new(chain_length: u32, max_depth: u32) -> Self {
19799 Self {
19800 chain_length,
19801 max_depth,
19802 _sealed: (),
19803 }
19804 }
19805}
19806
19807#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19810pub struct CarryEvent {
19811 left_bits: u16,
19812 right_bits: u16,
19813 _sealed: (),
19814}
19815
19816impl CarryEvent {
19817 #[inline]
19819 #[must_use]
19820 pub const fn left_bits(&self) -> u16 {
19821 self.left_bits
19822 }
19823
19824 #[inline]
19826 #[must_use]
19827 pub const fn right_bits(&self) -> u16 {
19828 self.right_bits
19829 }
19830
19831 #[inline]
19833 #[must_use]
19834 #[allow(dead_code)]
19835 pub(crate) const fn new(left_bits: u16, right_bits: u16) -> Self {
19836 Self {
19837 left_bits,
19838 right_bits,
19839 _sealed: (),
19840 }
19841 }
19842}
19843
19844#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19846pub struct ConvergenceLevel<L> {
19847 valuation: u32,
19848 _level: PhantomData<L>,
19849 _sealed: (),
19850}
19851
19852impl<L> ConvergenceLevel<L> {
19853 #[inline]
19855 #[must_use]
19856 pub const fn valuation(&self) -> u32 {
19857 self.valuation
19858 }
19859
19860 #[inline]
19862 #[must_use]
19863 #[allow(dead_code)]
19864 pub(crate) const fn new(valuation: u32) -> Self {
19865 Self {
19866 valuation,
19867 _level: PhantomData,
19868 _sealed: (),
19869 }
19870 }
19871}
19872
19873#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19876#[non_exhaustive]
19877pub enum DivisionAlgebraWitness {
19878 Real,
19880 Complex,
19882 Quaternion,
19884 Octonion,
19886}
19887
19888#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19890pub struct MonoidalProduct<L, R> {
19891 _left: PhantomData<L>,
19892 _right: PhantomData<R>,
19893 _sealed: (),
19894}
19895
19896impl<L, R> MonoidalProduct<L, R> {
19897 #[inline]
19899 #[must_use]
19900 #[allow(dead_code)]
19901 pub(crate) const fn new() -> Self {
19902 Self {
19903 _left: PhantomData,
19904 _right: PhantomData,
19905 _sealed: (),
19906 }
19907 }
19908}
19909
19910#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19912pub struct MonoidalUnit<L> {
19913 _level: PhantomData<L>,
19914 _sealed: (),
19915}
19916
19917impl<L> MonoidalUnit<L> {
19918 #[inline]
19920 #[must_use]
19921 #[allow(dead_code)]
19922 pub(crate) const fn new() -> Self {
19923 Self {
19924 _level: PhantomData,
19925 _sealed: (),
19926 }
19927 }
19928}
19929
19930#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19934pub struct OperadComposition {
19935 outer_type_iri: &'static str,
19936 inner_type_iri: &'static str,
19937 composed_site_count: u32,
19938 _sealed: (),
19939}
19940
19941impl OperadComposition {
19942 #[inline]
19944 #[must_use]
19945 pub const fn outer_type_iri(&self) -> &'static str {
19946 self.outer_type_iri
19947 }
19948
19949 #[inline]
19951 #[must_use]
19952 pub const fn inner_type_iri(&self) -> &'static str {
19953 self.inner_type_iri
19954 }
19955
19956 #[inline]
19958 #[must_use]
19959 pub const fn composed_site_count(&self) -> u32 {
19960 self.composed_site_count
19961 }
19962
19963 #[inline]
19965 #[must_use]
19966 #[allow(dead_code)]
19967 pub(crate) const fn new(
19968 outer_type_iri: &'static str,
19969 inner_type_iri: &'static str,
19970 composed_site_count: u32,
19971 ) -> Self {
19972 Self {
19973 outer_type_iri,
19974 inner_type_iri,
19975 composed_site_count,
19976 _sealed: (),
19977 }
19978 }
19979}
19980
19981pub const RECURSION_TRACE_MAX_DEPTH: usize = 16;
19987
19988#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19991pub struct RecursionTrace {
19992 depth: u32,
19993 measure: [u32; RECURSION_TRACE_MAX_DEPTH],
19994 _sealed: (),
19995}
19996
19997impl RecursionTrace {
19998 #[inline]
20000 #[must_use]
20001 pub const fn depth(&self) -> u32 {
20002 self.depth
20003 }
20004
20005 #[inline]
20007 #[must_use]
20008 pub const fn measure(&self) -> &[u32; RECURSION_TRACE_MAX_DEPTH] {
20009 &self.measure
20010 }
20011
20012 #[inline]
20014 #[must_use]
20015 #[allow(dead_code)]
20016 pub(crate) const fn new(depth: u32, measure: [u32; RECURSION_TRACE_MAX_DEPTH]) -> Self {
20017 Self {
20018 depth,
20019 measure,
20020 _sealed: (),
20021 }
20022 }
20023}
20024
20025#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20027pub struct AddressRegion {
20028 base: u128,
20029 extent: u64,
20030 _sealed: (),
20031}
20032
20033impl AddressRegion {
20034 #[inline]
20036 #[must_use]
20037 pub const fn base(&self) -> u128 {
20038 self.base
20039 }
20040
20041 #[inline]
20043 #[must_use]
20044 pub const fn extent(&self) -> u64 {
20045 self.extent
20046 }
20047
20048 #[inline]
20050 #[must_use]
20051 #[allow(dead_code)]
20052 pub(crate) const fn new(base: u128, extent: u64) -> Self {
20053 Self {
20054 base,
20055 extent,
20056 _sealed: (),
20057 }
20058 }
20059}
20060
20061#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20063pub struct LinearBudget {
20064 sites_remaining: u64,
20065 _sealed: (),
20066}
20067
20068impl LinearBudget {
20069 #[inline]
20071 #[must_use]
20072 pub const fn sites_remaining(&self) -> u64 {
20073 self.sites_remaining
20074 }
20075
20076 #[inline]
20078 #[must_use]
20079 #[allow(dead_code)]
20080 pub(crate) const fn new(sites_remaining: u64) -> Self {
20081 Self {
20082 sites_remaining,
20083 _sealed: (),
20084 }
20085 }
20086}
20087
20088#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20090pub struct LeaseAllocation {
20091 site_count: u32,
20092 scope_hash: u128,
20093 _sealed: (),
20094}
20095
20096impl LeaseAllocation {
20097 #[inline]
20099 #[must_use]
20100 pub const fn site_count(&self) -> u32 {
20101 self.site_count
20102 }
20103
20104 #[inline]
20106 #[must_use]
20107 pub const fn scope_hash(&self) -> u128 {
20108 self.scope_hash
20109 }
20110
20111 #[inline]
20113 #[must_use]
20114 #[allow(dead_code)]
20115 pub(crate) const fn new(site_count: u32, scope_hash: u128) -> Self {
20116 Self {
20117 site_count,
20118 scope_hash,
20119 _sealed: (),
20120 }
20121 }
20122}
20123
20124#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
20126pub struct TotalMarker;
20127
20128#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
20130pub struct InvertibleMarker;
20131
20132#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
20134pub struct PreservesStructureMarker;
20135
20136mod marker_tuple_sealed {
20137 pub trait Sealed {}
20139}
20140
20141pub trait MarkerTuple: marker_tuple_sealed::Sealed {}
20146
20147impl marker_tuple_sealed::Sealed for () {}
20148impl MarkerTuple for () {}
20149impl marker_tuple_sealed::Sealed for (TotalMarker,) {}
20150impl MarkerTuple for (TotalMarker,) {}
20151impl marker_tuple_sealed::Sealed for (TotalMarker, InvertibleMarker) {}
20152impl MarkerTuple for (TotalMarker, InvertibleMarker) {}
20153impl marker_tuple_sealed::Sealed for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {}
20154impl MarkerTuple for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {}
20155impl marker_tuple_sealed::Sealed for (InvertibleMarker,) {}
20156impl MarkerTuple for (InvertibleMarker,) {}
20157impl marker_tuple_sealed::Sealed for (InvertibleMarker, PreservesStructureMarker) {}
20158impl MarkerTuple for (InvertibleMarker, PreservesStructureMarker) {}
20159
20160pub trait MarkerIntersection<Other: MarkerTuple>: MarkerTuple {
20167 type Output: MarkerTuple;
20169}
20170
20171impl MarkerIntersection<()> for () {
20172 type Output = ();
20173}
20174impl MarkerIntersection<(TotalMarker,)> for () {
20175 type Output = ();
20176}
20177impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for () {
20178 type Output = ();
20179}
20180impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)> for () {
20181 type Output = ();
20182}
20183impl MarkerIntersection<(InvertibleMarker,)> for () {
20184 type Output = ();
20185}
20186impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for () {
20187 type Output = ();
20188}
20189impl MarkerIntersection<()> for (TotalMarker,) {
20190 type Output = ();
20191}
20192impl MarkerIntersection<(TotalMarker,)> for (TotalMarker,) {
20193 type Output = (TotalMarker,);
20194}
20195impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (TotalMarker,) {
20196 type Output = (TotalMarker,);
20197}
20198impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20199 for (TotalMarker,)
20200{
20201 type Output = (TotalMarker,);
20202}
20203impl MarkerIntersection<(InvertibleMarker,)> for (TotalMarker,) {
20204 type Output = ();
20205}
20206impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for (TotalMarker,) {
20207 type Output = ();
20208}
20209impl MarkerIntersection<()> for (TotalMarker, InvertibleMarker) {
20210 type Output = ();
20211}
20212impl MarkerIntersection<(TotalMarker,)> for (TotalMarker, InvertibleMarker) {
20213 type Output = (TotalMarker,);
20214}
20215impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (TotalMarker, InvertibleMarker) {
20216 type Output = (TotalMarker, InvertibleMarker);
20217}
20218impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20219 for (TotalMarker, InvertibleMarker)
20220{
20221 type Output = (TotalMarker, InvertibleMarker);
20222}
20223impl MarkerIntersection<(InvertibleMarker,)> for (TotalMarker, InvertibleMarker) {
20224 type Output = (InvertibleMarker,);
20225}
20226impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
20227 for (TotalMarker, InvertibleMarker)
20228{
20229 type Output = (InvertibleMarker,);
20230}
20231impl MarkerIntersection<()> for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {
20232 type Output = ();
20233}
20234impl MarkerIntersection<(TotalMarker,)>
20235 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20236{
20237 type Output = (TotalMarker,);
20238}
20239impl MarkerIntersection<(TotalMarker, InvertibleMarker)>
20240 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20241{
20242 type Output = (TotalMarker, InvertibleMarker);
20243}
20244impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20245 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20246{
20247 type Output = (TotalMarker, InvertibleMarker, PreservesStructureMarker);
20248}
20249impl MarkerIntersection<(InvertibleMarker,)>
20250 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20251{
20252 type Output = (InvertibleMarker,);
20253}
20254impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
20255 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20256{
20257 type Output = (InvertibleMarker, PreservesStructureMarker);
20258}
20259impl MarkerIntersection<()> for (InvertibleMarker,) {
20260 type Output = ();
20261}
20262impl MarkerIntersection<(TotalMarker,)> for (InvertibleMarker,) {
20263 type Output = ();
20264}
20265impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (InvertibleMarker,) {
20266 type Output = (InvertibleMarker,);
20267}
20268impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20269 for (InvertibleMarker,)
20270{
20271 type Output = (InvertibleMarker,);
20272}
20273impl MarkerIntersection<(InvertibleMarker,)> for (InvertibleMarker,) {
20274 type Output = (InvertibleMarker,);
20275}
20276impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for (InvertibleMarker,) {
20277 type Output = (InvertibleMarker,);
20278}
20279impl MarkerIntersection<()> for (InvertibleMarker, PreservesStructureMarker) {
20280 type Output = ();
20281}
20282impl MarkerIntersection<(TotalMarker,)> for (InvertibleMarker, PreservesStructureMarker) {
20283 type Output = ();
20284}
20285impl MarkerIntersection<(TotalMarker, InvertibleMarker)>
20286 for (InvertibleMarker, PreservesStructureMarker)
20287{
20288 type Output = (InvertibleMarker,);
20289}
20290impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20291 for (InvertibleMarker, PreservesStructureMarker)
20292{
20293 type Output = (InvertibleMarker, PreservesStructureMarker);
20294}
20295impl MarkerIntersection<(InvertibleMarker,)> for (InvertibleMarker, PreservesStructureMarker) {
20296 type Output = (InvertibleMarker,);
20297}
20298impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
20299 for (InvertibleMarker, PreservesStructureMarker)
20300{
20301 type Output = (InvertibleMarker, PreservesStructureMarker);
20302}
20303
20304pub trait MarkersImpliedBy<Map: GroundingMapKind>: MarkerTuple {}
20310
20311#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20314pub struct MarkerBits(u8);
20315
20316impl MarkerBits {
20317 pub const TOTAL: Self = Self(1);
20319 pub const INVERTIBLE: Self = Self(2);
20321 pub const PRESERVES_STRUCTURE: Self = Self(4);
20323 pub const NONE: Self = Self(0);
20325
20326 #[inline]
20328 #[must_use]
20329 pub const fn from_u8(bits: u8) -> Self {
20330 Self(bits)
20331 }
20332
20333 #[inline]
20335 #[must_use]
20336 pub const fn as_u8(&self) -> u8 {
20337 self.0
20338 }
20339
20340 #[inline]
20342 #[must_use]
20343 pub const fn union(self, other: Self) -> Self {
20344 Self(self.0 | other.0)
20345 }
20346
20347 #[inline]
20349 #[must_use]
20350 pub const fn intersection(self, other: Self) -> Self {
20351 Self(self.0 & other.0)
20352 }
20353
20354 #[inline]
20356 #[must_use]
20357 pub const fn contains(&self, other: Self) -> bool {
20358 (self.0 & other.0) == other.0
20359 }
20360}
20361
20362#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20368#[non_exhaustive]
20369pub enum GroundingPrimitiveOp {
20370 ReadBytes,
20372 InterpretLeInteger,
20374 InterpretBeInteger,
20376 Digest,
20382 DecodeUtf8,
20388 DecodeJson,
20394 SelectField,
20396 SelectIndex,
20398 ConstValue,
20404 Then,
20406 MapErr,
20408 AndThen,
20410}
20411
20412pub const MAX_OP_CHAIN_DEPTH: usize = 8;
20419
20420#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20430pub struct GroundingPrimitive<Out, Markers: MarkerTuple = ()> {
20431 op: GroundingPrimitiveOp,
20432 markers: MarkerBits,
20433 chain: [GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH],
20434 chain_len: u8,
20435 _out: PhantomData<Out>,
20436 _markers: PhantomData<Markers>,
20437 _sealed: (),
20438}
20439
20440impl<Out, Markers: MarkerTuple> GroundingPrimitive<Out, Markers> {
20441 #[inline]
20443 #[must_use]
20444 pub const fn op(&self) -> GroundingPrimitiveOp {
20445 self.op
20446 }
20447
20448 #[inline]
20450 #[must_use]
20451 pub const fn markers(&self) -> MarkerBits {
20452 self.markers
20453 }
20454
20455 #[inline]
20458 #[must_use]
20459 pub fn chain(&self) -> &[GroundingPrimitiveOp] {
20460 &self.chain[..self.chain_len as usize]
20461 }
20462
20463 #[inline]
20467 #[must_use]
20468 #[allow(dead_code)]
20469 pub(crate) const fn from_parts(op: GroundingPrimitiveOp, markers: MarkerBits) -> Self {
20470 Self {
20471 op,
20472 markers,
20473 chain: [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH],
20474 chain_len: 0,
20475 _out: PhantomData,
20476 _markers: PhantomData,
20477 _sealed: (),
20478 }
20479 }
20480
20481 #[inline]
20484 #[must_use]
20485 #[allow(dead_code)]
20486 pub(crate) const fn from_parts_with_chain(
20487 op: GroundingPrimitiveOp,
20488 markers: MarkerBits,
20489 chain: [GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH],
20490 chain_len: u8,
20491 ) -> Self {
20492 Self {
20493 op,
20494 markers,
20495 chain,
20496 chain_len,
20497 _out: PhantomData,
20498 _markers: PhantomData,
20499 _sealed: (),
20500 }
20501 }
20502}
20503
20504pub mod combinators {
20510 use super::{
20511 GroundingPrimitive, GroundingPrimitiveOp, InvertibleMarker, MarkerBits, MarkerIntersection,
20512 MarkerTuple, PreservesStructureMarker, TotalMarker, MAX_OP_CHAIN_DEPTH,
20513 };
20514
20515 fn compose_chain<A, B, MA: MarkerTuple, MB: MarkerTuple>(
20519 first: &GroundingPrimitive<A, MA>,
20520 second: &GroundingPrimitive<B, MB>,
20521 ) -> ([GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH], u8) {
20522 let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
20523 let mut len: usize = 0;
20524 for &op in first.chain() {
20525 if len >= MAX_OP_CHAIN_DEPTH {
20526 return (chain, len as u8);
20527 }
20528 chain[len] = op;
20529 len += 1;
20530 }
20531 if len < MAX_OP_CHAIN_DEPTH {
20532 chain[len] = first.op();
20533 len += 1;
20534 }
20535 for &op in second.chain() {
20536 if len >= MAX_OP_CHAIN_DEPTH {
20537 return (chain, len as u8);
20538 }
20539 chain[len] = op;
20540 len += 1;
20541 }
20542 if len < MAX_OP_CHAIN_DEPTH {
20543 chain[len] = second.op();
20544 len += 1;
20545 }
20546 (chain, len as u8)
20547 }
20548
20549 fn map_err_chain<A, M: MarkerTuple>(
20551 first: &GroundingPrimitive<A, M>,
20552 ) -> ([GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH], u8) {
20553 let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
20554 let mut len: usize = 0;
20555 for &op in first.chain() {
20556 if len >= MAX_OP_CHAIN_DEPTH {
20557 return (chain, len as u8);
20558 }
20559 chain[len] = op;
20560 len += 1;
20561 }
20562 if len < MAX_OP_CHAIN_DEPTH {
20563 chain[len] = first.op();
20564 len += 1;
20565 }
20566 (chain, len as u8)
20567 }
20568
20569 #[inline]
20571 #[must_use]
20572 pub const fn read_bytes<Out>() -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker)> {
20573 GroundingPrimitive::from_parts(
20574 GroundingPrimitiveOp::ReadBytes,
20575 MarkerBits::TOTAL.union(MarkerBits::INVERTIBLE),
20576 )
20577 }
20578
20579 #[inline]
20581 #[must_use]
20582 pub const fn interpret_le_integer<Out>(
20583 ) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
20584 GroundingPrimitive::from_parts(
20585 GroundingPrimitiveOp::InterpretLeInteger,
20586 MarkerBits::TOTAL
20587 .union(MarkerBits::INVERTIBLE)
20588 .union(MarkerBits::PRESERVES_STRUCTURE),
20589 )
20590 }
20591
20592 #[inline]
20594 #[must_use]
20595 pub const fn interpret_be_integer<Out>(
20596 ) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
20597 GroundingPrimitive::from_parts(
20598 GroundingPrimitiveOp::InterpretBeInteger,
20599 MarkerBits::TOTAL
20600 .union(MarkerBits::INVERTIBLE)
20601 .union(MarkerBits::PRESERVES_STRUCTURE),
20602 )
20603 }
20604
20605 #[inline]
20607 #[must_use]
20608 pub const fn digest<Out>() -> GroundingPrimitive<Out, (TotalMarker,)> {
20609 GroundingPrimitive::from_parts(GroundingPrimitiveOp::Digest, MarkerBits::TOTAL)
20610 }
20611
20612 #[inline]
20614 #[must_use]
20615 pub const fn decode_utf8<Out>(
20616 ) -> GroundingPrimitive<Out, (InvertibleMarker, PreservesStructureMarker)> {
20617 GroundingPrimitive::from_parts(
20618 GroundingPrimitiveOp::DecodeUtf8,
20619 MarkerBits::INVERTIBLE.union(MarkerBits::PRESERVES_STRUCTURE),
20620 )
20621 }
20622
20623 #[inline]
20625 #[must_use]
20626 pub const fn decode_json<Out>(
20627 ) -> GroundingPrimitive<Out, (InvertibleMarker, PreservesStructureMarker)> {
20628 GroundingPrimitive::from_parts(
20629 GroundingPrimitiveOp::DecodeJson,
20630 MarkerBits::INVERTIBLE.union(MarkerBits::PRESERVES_STRUCTURE),
20631 )
20632 }
20633
20634 #[inline]
20636 #[must_use]
20637 pub const fn select_field<Out>() -> GroundingPrimitive<Out, (InvertibleMarker,)> {
20638 GroundingPrimitive::from_parts(GroundingPrimitiveOp::SelectField, MarkerBits::INVERTIBLE)
20639 }
20640
20641 #[inline]
20643 #[must_use]
20644 pub const fn select_index<Out>() -> GroundingPrimitive<Out, (InvertibleMarker,)> {
20645 GroundingPrimitive::from_parts(GroundingPrimitiveOp::SelectIndex, MarkerBits::INVERTIBLE)
20646 }
20647
20648 #[inline]
20650 #[must_use]
20651 pub const fn const_value<Out>(
20652 ) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
20653 GroundingPrimitive::from_parts(
20654 GroundingPrimitiveOp::ConstValue,
20655 MarkerBits::TOTAL
20656 .union(MarkerBits::INVERTIBLE)
20657 .union(MarkerBits::PRESERVES_STRUCTURE),
20658 )
20659 }
20660
20661 #[inline]
20666 #[must_use]
20667 pub fn then<A, B, MA, MB>(
20668 first: GroundingPrimitive<A, MA>,
20669 second: GroundingPrimitive<B, MB>,
20670 ) -> GroundingPrimitive<B, <MA as MarkerIntersection<MB>>::Output>
20671 where
20672 MA: MarkerTuple + MarkerIntersection<MB>,
20673 MB: MarkerTuple,
20674 {
20675 let (chain, chain_len) = compose_chain(&first, &second);
20676 GroundingPrimitive::from_parts_with_chain(
20677 GroundingPrimitiveOp::Then,
20678 first.markers().intersection(second.markers()),
20679 chain,
20680 chain_len,
20681 )
20682 }
20683
20684 #[inline]
20688 #[must_use]
20689 pub fn map_err<A, M: MarkerTuple>(first: GroundingPrimitive<A, M>) -> GroundingPrimitive<A, M> {
20690 let (chain, chain_len) = map_err_chain(&first);
20691 GroundingPrimitive::from_parts_with_chain(
20692 GroundingPrimitiveOp::MapErr,
20693 first.markers(),
20694 chain,
20695 chain_len,
20696 )
20697 }
20698
20699 #[inline]
20702 #[must_use]
20703 pub fn and_then<A, B, MA, MB>(
20704 first: GroundingPrimitive<A, MA>,
20705 second: GroundingPrimitive<B, MB>,
20706 ) -> GroundingPrimitive<B, <MA as MarkerIntersection<MB>>::Output>
20707 where
20708 MA: MarkerTuple + MarkerIntersection<MB>,
20709 MB: MarkerTuple,
20710 {
20711 let (chain, chain_len) = compose_chain(&first, &second);
20712 GroundingPrimitive::from_parts_with_chain(
20713 GroundingPrimitiveOp::AndThen,
20714 first.markers().intersection(second.markers()),
20715 chain,
20716 chain_len,
20717 )
20718 }
20719}
20720
20721#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20727pub struct GroundingProgram<Out, Map: GroundingMapKind> {
20728 primitive: GroundingPrimitive<Out>,
20729 _map: PhantomData<Map>,
20730 _sealed: (),
20731}
20732
20733impl<Out, Map: GroundingMapKind> GroundingProgram<Out, Map> {
20734 #[inline]
20756 #[must_use]
20757 pub fn from_primitive<Markers>(primitive: GroundingPrimitive<Out, Markers>) -> Self
20758 where
20759 Markers: MarkerTuple + MarkersImpliedBy<Map>,
20760 {
20761 let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
20764 let src = primitive.chain();
20765 let mut i = 0;
20766 while i < src.len() && i < MAX_OP_CHAIN_DEPTH {
20767 chain[i] = src[i];
20768 i += 1;
20769 }
20770 let erased = GroundingPrimitive::<Out, ()>::from_parts_with_chain(
20771 primitive.op(),
20772 primitive.markers(),
20773 chain,
20774 i as u8,
20775 );
20776 Self {
20777 primitive: erased,
20778 _map: PhantomData,
20779 _sealed: (),
20780 }
20781 }
20782
20783 #[inline]
20785 #[must_use]
20786 pub const fn primitive(&self) -> &GroundingPrimitive<Out> {
20787 &self.primitive
20788 }
20789}
20790
20791impl<Map: GroundingMapKind> GroundingProgram<GroundedCoord, Map> {
20804 #[inline]
20808 #[must_use]
20809 pub fn run(&self, external: &[u8]) -> Option<GroundedCoord> {
20810 match self.primitive.op() {
20811 GroundingPrimitiveOp::Then | GroundingPrimitiveOp::AndThen => {
20812 let chain = self.primitive.chain();
20813 if chain.is_empty() {
20814 return None;
20815 }
20816 let mut last: Option<GroundedCoord> = None;
20817 for &op in chain {
20818 match interpret_leaf_op(op, external) {
20819 Some(c) => last = Some(c),
20820 None => return None,
20821 }
20822 }
20823 last
20824 }
20825 GroundingPrimitiveOp::MapErr => self
20826 .primitive
20827 .chain()
20828 .first()
20829 .and_then(|&op| interpret_leaf_op(op, external)),
20830 leaf => interpret_leaf_op(leaf, external),
20831 }
20832 }
20833}
20834
20835impl<const N: usize, Map: GroundingMapKind> GroundingProgram<GroundedTuple<N>, Map> {
20842 #[inline]
20844 #[must_use]
20845 pub fn run(&self, external: &[u8]) -> Option<GroundedTuple<N>> {
20846 if N == 0 || external.is_empty() || external.len() % N != 0 {
20847 return None;
20848 }
20849 let window = external.len() / N;
20850 let mut coords: [GroundedCoord; N] = [const { GroundedCoord::w8(0) }; N];
20851 let mut i = 0usize;
20852 while i < N {
20853 let start = i * window;
20854 let end = start + window;
20855 let sub = &external[start..end];
20856 let outcome = match self.primitive.op() {
20861 GroundingPrimitiveOp::Then | GroundingPrimitiveOp::AndThen => {
20862 let chain = self.primitive.chain();
20863 if chain.is_empty() {
20864 return None;
20865 }
20866 let mut last: Option<GroundedCoord> = None;
20867 for &op in chain {
20868 match interpret_leaf_op(op, sub) {
20869 Some(c) => last = Some(c),
20870 None => return None,
20871 }
20872 }
20873 last
20874 }
20875 GroundingPrimitiveOp::MapErr => self
20876 .primitive
20877 .chain()
20878 .first()
20879 .and_then(|&op| interpret_leaf_op(op, sub)),
20880 leaf => interpret_leaf_op(leaf, sub),
20881 };
20882 match outcome {
20883 Some(c) => {
20884 coords[i] = c;
20885 }
20886 None => {
20887 return None;
20888 }
20889 }
20890 i += 1;
20891 }
20892 Some(GroundedTuple::new(coords))
20893 }
20894}
20895
20896#[inline]
20900fn interpret_leaf_op(op: GroundingPrimitiveOp, external: &[u8]) -> Option<GroundedCoord> {
20901 match op {
20902 GroundingPrimitiveOp::ReadBytes | GroundingPrimitiveOp::InterpretLeInteger => {
20903 external.first().map(|&b| GroundedCoord::w8(b))
20904 }
20905 GroundingPrimitiveOp::InterpretBeInteger => external.last().map(|&b| GroundedCoord::w8(b)),
20906 GroundingPrimitiveOp::Digest => {
20907 external.first().map(|&b| GroundedCoord::w8(b))
20914 }
20915 GroundingPrimitiveOp::DecodeUtf8 => {
20916 match external.first() {
20922 Some(&b) if b < 0x80 => Some(GroundedCoord::w8(b)),
20923 _ => None,
20924 }
20925 }
20926 GroundingPrimitiveOp::DecodeJson => {
20927 match external.first() {
20929 Some(&b) if b == b'-' || b.is_ascii_digit() => Some(GroundedCoord::w8(b)),
20930 _ => None,
20931 }
20932 }
20933 GroundingPrimitiveOp::ConstValue => Some(GroundedCoord::w8(0)),
20934 GroundingPrimitiveOp::SelectField | GroundingPrimitiveOp::SelectIndex => {
20935 external.first().map(|&b| GroundedCoord::w8(b))
20938 }
20939 GroundingPrimitiveOp::Then
20940 | GroundingPrimitiveOp::AndThen
20941 | GroundingPrimitiveOp::MapErr => {
20942 None
20945 }
20946 }
20947}
20948
20949impl MarkersImpliedBy<DigestGroundingMap> for (TotalMarker,) {}
20953impl MarkersImpliedBy<BinaryGroundingMap> for (TotalMarker, InvertibleMarker) {}
20954impl MarkersImpliedBy<DigestGroundingMap> for (TotalMarker, InvertibleMarker) {}
20955impl MarkersImpliedBy<BinaryGroundingMap>
20956 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20957{
20958}
20959impl MarkersImpliedBy<DigestGroundingMap>
20960 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20961{
20962}
20963impl MarkersImpliedBy<IntegerGroundingMap>
20964 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20965{
20966}
20967impl MarkersImpliedBy<JsonGroundingMap>
20968 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20969{
20970}
20971impl MarkersImpliedBy<Utf8GroundingMap>
20972 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20973{
20974}
20975impl MarkersImpliedBy<JsonGroundingMap> for (InvertibleMarker, PreservesStructureMarker) {}
20976impl MarkersImpliedBy<Utf8GroundingMap> for (InvertibleMarker, PreservesStructureMarker) {}
20977
20978#[doc(hidden)]
20983pub mod __test_helpers {
20984 use super::{ContentAddress, ContentFingerprint, MulContext, Trace, TraceEvent, Validated};
20985
20986 #[must_use]
20992 pub fn trace_from_events<const TR_MAX: usize>(events: &[TraceEvent]) -> Trace<TR_MAX> {
20993 trace_with_fingerprint(events, 0, ContentFingerprint::zero())
20994 }
20995
20996 #[must_use]
21000 pub fn trace_with_fingerprint<const TR_MAX: usize>(
21001 events: &[TraceEvent],
21002 witt_level_bits: u16,
21003 content_fingerprint: ContentFingerprint,
21004 ) -> Trace<TR_MAX> {
21005 let mut arr = [None; TR_MAX];
21006 let n = events.len().min(TR_MAX);
21007 let mut i = 0;
21008 while i < n {
21009 arr[i] = Some(events[i]);
21010 i += 1;
21011 }
21012 Trace::from_replay_events_const(arr, n as u16, witt_level_bits, content_fingerprint)
21016 }
21017
21018 #[must_use]
21020 pub fn trace_event(step_index: u32, target: u128) -> TraceEvent {
21021 TraceEvent::new(
21022 step_index,
21023 crate::PrimitiveOp::Add,
21024 ContentAddress::from_u128(target),
21025 )
21026 }
21027
21028 #[must_use]
21030 pub fn mul_context(stack_budget_bytes: u64, const_eval: bool, limb_count: usize) -> MulContext {
21031 MulContext::new(stack_budget_bytes, const_eval, limb_count)
21032 }
21033
21034 #[must_use]
21038 pub fn validated_runtime<T>(inner: T) -> Validated<T> {
21039 Validated::new(inner)
21040 }
21041}
21042
21043type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
21052
21053#[inline]
21054const fn pc_entropy_tolerance(expected: DefaultDecimal) -> DefaultDecimal {
21055 let magnitude = if expected < 0.0 { -expected } else { expected };
21056 let scale = if magnitude > 1.0 { magnitude } else { 1.0 };
21057 1024.0 * <DefaultDecimal>::EPSILON * scale
21058}
21059
21060#[inline]
21065fn pc_entropy_input_is_valid(value: DefaultDecimal) -> bool {
21066 value.is_finite() && value >= 0.0
21067}
21068
21069#[inline]
21074fn pc_entropy_additivity_holds(actual: DefaultDecimal, expected: DefaultDecimal) -> bool {
21075 if !pc_entropy_input_is_valid(actual) || !pc_entropy_input_is_valid(expected) {
21076 return false;
21077 }
21078 let diff = actual - expected;
21079 let diff_abs = if diff < 0.0 { -diff } else { diff };
21080 diff_abs <= pc_entropy_tolerance(expected)
21081}
21082
21083#[derive(Debug, Clone, Copy, PartialEq)]
21088pub struct PartitionProductEvidence {
21089 pub left_site_budget: u16,
21091 pub right_site_budget: u16,
21093 pub left_total_site_count: u16,
21095 pub right_total_site_count: u16,
21097 pub left_euler: i32,
21099 pub right_euler: i32,
21101 pub left_entropy_nats_bits: u64,
21103 pub right_entropy_nats_bits: u64,
21105 pub source_witness_fingerprint: ContentFingerprint,
21107}
21108
21109#[derive(Debug, Clone, Copy, PartialEq)]
21112pub struct PartitionCoproductEvidence {
21113 pub left_site_budget: u16,
21114 pub right_site_budget: u16,
21115 pub left_total_site_count: u16,
21116 pub right_total_site_count: u16,
21117 pub left_euler: i32,
21118 pub right_euler: i32,
21119 pub left_entropy_nats_bits: u64,
21120 pub right_entropy_nats_bits: u64,
21121 pub left_betti: [u32; MAX_BETTI_DIMENSION],
21122 pub right_betti: [u32; MAX_BETTI_DIMENSION],
21123 pub source_witness_fingerprint: ContentFingerprint,
21124}
21125
21126#[derive(Debug, Clone, Copy, PartialEq)]
21132pub struct CartesianProductEvidence {
21133 pub left_site_budget: u16,
21134 pub right_site_budget: u16,
21135 pub left_total_site_count: u16,
21136 pub right_total_site_count: u16,
21137 pub left_euler: i32,
21138 pub right_euler: i32,
21139 pub left_betti: [u32; MAX_BETTI_DIMENSION],
21140 pub right_betti: [u32; MAX_BETTI_DIMENSION],
21141 pub left_entropy_nats_bits: u64,
21142 pub right_entropy_nats_bits: u64,
21143 pub combined_entropy_nats_bits: u64,
21144 pub source_witness_fingerprint: ContentFingerprint,
21145}
21146
21147#[derive(Debug, Clone, Copy, PartialEq)]
21153pub struct PartitionProductMintInputs {
21154 pub witt_bits: u16,
21155 pub left_fingerprint: ContentFingerprint,
21156 pub right_fingerprint: ContentFingerprint,
21157 pub left_site_budget: u16,
21158 pub right_site_budget: u16,
21159 pub left_total_site_count: u16,
21160 pub right_total_site_count: u16,
21161 pub left_euler: i32,
21162 pub right_euler: i32,
21163 pub left_entropy_nats_bits: u64,
21164 pub right_entropy_nats_bits: u64,
21165 pub combined_site_budget: u16,
21166 pub combined_site_count: u16,
21167 pub combined_euler: i32,
21168 pub combined_entropy_nats_bits: u64,
21169 pub combined_fingerprint: ContentFingerprint,
21170}
21171
21172#[derive(Debug, Clone, Copy)]
21184pub struct PartitionCoproductMintInputs {
21185 pub witt_bits: u16,
21186 pub left_fingerprint: ContentFingerprint,
21187 pub right_fingerprint: ContentFingerprint,
21188 pub left_site_budget: u16,
21189 pub right_site_budget: u16,
21190 pub left_total_site_count: u16,
21191 pub right_total_site_count: u16,
21192 pub left_euler: i32,
21193 pub right_euler: i32,
21194 pub left_entropy_nats_bits: u64,
21195 pub right_entropy_nats_bits: u64,
21196 pub left_betti: [u32; MAX_BETTI_DIMENSION],
21197 pub right_betti: [u32; MAX_BETTI_DIMENSION],
21198 pub combined_site_budget: u16,
21199 pub combined_site_count: u16,
21200 pub combined_euler: i32,
21201 pub combined_entropy_nats_bits: u64,
21202 pub combined_betti: [u32; MAX_BETTI_DIMENSION],
21203 pub combined_fingerprint: ContentFingerprint,
21204 pub combined_constraints: &'static [crate::pipeline::ConstraintRef],
21205 pub left_constraint_count: usize,
21206 pub tag_site: u16,
21207}
21208
21209#[derive(Debug, Clone, Copy, PartialEq)]
21212pub struct CartesianProductMintInputs {
21213 pub witt_bits: u16,
21214 pub left_fingerprint: ContentFingerprint,
21215 pub right_fingerprint: ContentFingerprint,
21216 pub left_site_budget: u16,
21217 pub right_site_budget: u16,
21218 pub left_total_site_count: u16,
21219 pub right_total_site_count: u16,
21220 pub left_euler: i32,
21221 pub right_euler: i32,
21222 pub left_betti: [u32; MAX_BETTI_DIMENSION],
21223 pub right_betti: [u32; MAX_BETTI_DIMENSION],
21224 pub left_entropy_nats_bits: u64,
21225 pub right_entropy_nats_bits: u64,
21226 pub combined_site_budget: u16,
21227 pub combined_site_count: u16,
21228 pub combined_euler: i32,
21229 pub combined_betti: [u32; MAX_BETTI_DIMENSION],
21230 pub combined_entropy_nats_bits: u64,
21231 pub combined_fingerprint: ContentFingerprint,
21232}
21233
21234#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21241pub struct PartitionProductWitness {
21242 witt_bits: u16,
21243 content_fingerprint: ContentFingerprint,
21244 left_fingerprint: ContentFingerprint,
21245 right_fingerprint: ContentFingerprint,
21246 combined_site_budget: u16,
21247 combined_site_count: u16,
21248}
21249
21250impl PartitionProductWitness {
21251 #[inline]
21253 #[must_use]
21254 pub const fn witt_bits(&self) -> u16 {
21255 self.witt_bits
21256 }
21257 #[inline]
21259 #[must_use]
21260 pub const fn content_fingerprint(&self) -> ContentFingerprint {
21261 self.content_fingerprint
21262 }
21263 #[inline]
21265 #[must_use]
21266 pub const fn left_fingerprint(&self) -> ContentFingerprint {
21267 self.left_fingerprint
21268 }
21269 #[inline]
21271 #[must_use]
21272 pub const fn right_fingerprint(&self) -> ContentFingerprint {
21273 self.right_fingerprint
21274 }
21275 #[inline]
21277 #[must_use]
21278 pub const fn combined_site_budget(&self) -> u16 {
21279 self.combined_site_budget
21280 }
21281 #[inline]
21283 #[must_use]
21284 pub const fn combined_site_count(&self) -> u16 {
21285 self.combined_site_count
21286 }
21287 #[inline]
21289 #[must_use]
21290 #[allow(clippy::too_many_arguments)]
21291 pub(crate) const fn with_level_fingerprints_and_sites(
21292 witt_bits: u16,
21293 content_fingerprint: ContentFingerprint,
21294 left_fingerprint: ContentFingerprint,
21295 right_fingerprint: ContentFingerprint,
21296 combined_site_budget: u16,
21297 combined_site_count: u16,
21298 ) -> Self {
21299 Self {
21300 witt_bits,
21301 content_fingerprint,
21302 left_fingerprint,
21303 right_fingerprint,
21304 combined_site_budget,
21305 combined_site_count,
21306 }
21307 }
21308}
21309
21310#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21316pub struct PartitionCoproductWitness {
21317 witt_bits: u16,
21318 content_fingerprint: ContentFingerprint,
21319 left_fingerprint: ContentFingerprint,
21320 right_fingerprint: ContentFingerprint,
21321 combined_site_budget: u16,
21322 combined_site_count: u16,
21323 tag_site_index: u16,
21324}
21325
21326impl PartitionCoproductWitness {
21327 #[inline]
21328 #[must_use]
21329 pub const fn witt_bits(&self) -> u16 {
21330 self.witt_bits
21331 }
21332 #[inline]
21333 #[must_use]
21334 pub const fn content_fingerprint(&self) -> ContentFingerprint {
21335 self.content_fingerprint
21336 }
21337 #[inline]
21338 #[must_use]
21339 pub const fn left_fingerprint(&self) -> ContentFingerprint {
21340 self.left_fingerprint
21341 }
21342 #[inline]
21343 #[must_use]
21344 pub const fn right_fingerprint(&self) -> ContentFingerprint {
21345 self.right_fingerprint
21346 }
21347 #[inline]
21349 #[must_use]
21350 pub const fn combined_site_budget(&self) -> u16 {
21351 self.combined_site_budget
21352 }
21353 #[inline]
21355 #[must_use]
21356 pub const fn combined_site_count(&self) -> u16 {
21357 self.combined_site_count
21358 }
21359 #[inline]
21362 #[must_use]
21363 pub const fn tag_site_index(&self) -> u16 {
21364 self.tag_site_index
21365 }
21366 #[inline]
21367 #[must_use]
21368 #[allow(clippy::too_many_arguments)]
21369 pub(crate) const fn with_level_fingerprints_sites_and_tag(
21370 witt_bits: u16,
21371 content_fingerprint: ContentFingerprint,
21372 left_fingerprint: ContentFingerprint,
21373 right_fingerprint: ContentFingerprint,
21374 combined_site_budget: u16,
21375 combined_site_count: u16,
21376 tag_site_index: u16,
21377 ) -> Self {
21378 Self {
21379 witt_bits,
21380 content_fingerprint,
21381 left_fingerprint,
21382 right_fingerprint,
21383 combined_site_budget,
21384 combined_site_count,
21385 tag_site_index,
21386 }
21387 }
21388}
21389
21390#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21399pub struct CartesianProductWitness {
21400 witt_bits: u16,
21401 content_fingerprint: ContentFingerprint,
21402 left_fingerprint: ContentFingerprint,
21403 right_fingerprint: ContentFingerprint,
21404 combined_site_budget: u16,
21405 combined_site_count: u16,
21406 combined_euler: i32,
21407 combined_betti: [u32; MAX_BETTI_DIMENSION],
21408}
21409
21410impl CartesianProductWitness {
21411 #[inline]
21412 #[must_use]
21413 pub const fn witt_bits(&self) -> u16 {
21414 self.witt_bits
21415 }
21416 #[inline]
21417 #[must_use]
21418 pub const fn content_fingerprint(&self) -> ContentFingerprint {
21419 self.content_fingerprint
21420 }
21421 #[inline]
21422 #[must_use]
21423 pub const fn left_fingerprint(&self) -> ContentFingerprint {
21424 self.left_fingerprint
21425 }
21426 #[inline]
21427 #[must_use]
21428 pub const fn right_fingerprint(&self) -> ContentFingerprint {
21429 self.right_fingerprint
21430 }
21431 #[inline]
21432 #[must_use]
21433 pub const fn combined_site_budget(&self) -> u16 {
21434 self.combined_site_budget
21435 }
21436 #[inline]
21437 #[must_use]
21438 pub const fn combined_site_count(&self) -> u16 {
21439 self.combined_site_count
21440 }
21441 #[inline]
21442 #[must_use]
21443 pub const fn combined_euler(&self) -> i32 {
21444 self.combined_euler
21445 }
21446 #[inline]
21447 #[must_use]
21448 pub const fn combined_betti(&self) -> [u32; MAX_BETTI_DIMENSION] {
21449 self.combined_betti
21450 }
21451 #[inline]
21452 #[must_use]
21453 #[allow(clippy::too_many_arguments)]
21454 pub(crate) const fn with_level_fingerprints_and_invariants(
21455 witt_bits: u16,
21456 content_fingerprint: ContentFingerprint,
21457 left_fingerprint: ContentFingerprint,
21458 right_fingerprint: ContentFingerprint,
21459 combined_site_budget: u16,
21460 combined_site_count: u16,
21461 combined_euler: i32,
21462 combined_betti: [u32; MAX_BETTI_DIMENSION],
21463 ) -> Self {
21464 Self {
21465 witt_bits,
21466 content_fingerprint,
21467 left_fingerprint,
21468 right_fingerprint,
21469 combined_site_budget,
21470 combined_site_count,
21471 combined_euler,
21472 combined_betti,
21473 }
21474 }
21475}
21476
21477impl Certificate for PartitionProductWitness {
21478 const IRI: &'static str = "https://uor.foundation/partition/PartitionProduct";
21479 type Evidence = PartitionProductEvidence;
21480}
21481
21482impl Certificate for PartitionCoproductWitness {
21483 const IRI: &'static str = "https://uor.foundation/partition/PartitionCoproduct";
21484 type Evidence = PartitionCoproductEvidence;
21485}
21486
21487impl Certificate for CartesianProductWitness {
21488 const IRI: &'static str = "https://uor.foundation/partition/CartesianPartitionProduct";
21489 type Evidence = CartesianProductEvidence;
21490}
21491
21492impl core::fmt::Display for PartitionProductWitness {
21493 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21494 f.write_str("PartitionProductWitness")
21495 }
21496}
21497impl core::error::Error for PartitionProductWitness {}
21498
21499impl core::fmt::Display for PartitionCoproductWitness {
21500 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21501 f.write_str("PartitionCoproductWitness")
21502 }
21503}
21504impl core::error::Error for PartitionCoproductWitness {}
21505
21506impl core::fmt::Display for CartesianProductWitness {
21507 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21508 f.write_str("CartesianProductWitness")
21509 }
21510}
21511impl core::error::Error for CartesianProductWitness {}
21512
21513pub trait VerifiedMint: Certificate {
21523 type Inputs;
21525 type Error;
21529 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error>
21537 where
21538 Self: Sized;
21539}
21540
21541#[allow(clippy::too_many_arguments)]
21546fn pc_classify_constraint(
21547 c: &crate::pipeline::ConstraintRef,
21548 in_left_region: bool,
21549 tag_site: u16,
21550 max_depth: u32,
21551 left_pins: &mut u32,
21552 right_pins: &mut u32,
21553 left_bias_ok: &mut bool,
21554 right_bias_ok: &mut bool,
21555) -> Result<(), GenericImpossibilityWitness> {
21556 match c {
21557 crate::pipeline::ConstraintRef::Site { position } => {
21558 if (*position as u16) >= tag_site {
21559 return Err(GenericImpossibilityWitness::for_identity(
21560 "https://uor.foundation/op/ST_6",
21561 ));
21562 }
21563 }
21564 crate::pipeline::ConstraintRef::Carry { site } => {
21565 if (*site as u16) >= tag_site {
21566 return Err(GenericImpossibilityWitness::for_identity(
21567 "https://uor.foundation/op/ST_6",
21568 ));
21569 }
21570 }
21571 crate::pipeline::ConstraintRef::Affine { coefficients, coefficient_count, bias } => {
21572 let count = *coefficient_count as usize;
21573 let mut nonzero_count: u32 = 0;
21574 let mut nonzero_index: usize = 0;
21575 let mut max_nonzero_index: usize = 0;
21576 let mut i: usize = 0;
21577 while i < count && i < crate::pipeline::AFFINE_MAX_COEFFS {
21578 if coefficients[i] != 0 {
21579 nonzero_count = nonzero_count.saturating_add(1);
21580 nonzero_index = i;
21581 if i > max_nonzero_index { max_nonzero_index = i; }
21582 }
21583 i += 1;
21584 }
21585 let touches_tag_site = nonzero_count > 0
21586 && (max_nonzero_index as u16) >= tag_site;
21587 let is_canonical_tag_pinner = nonzero_count == 1
21588 && (nonzero_index as u16) == tag_site
21589 && coefficients[nonzero_index] == 1;
21590 if is_canonical_tag_pinner {
21591 if *bias != 0 && *bias != -1 {
21592 return Err(GenericImpossibilityWitness::for_identity(
21593 "https://uor.foundation/foundation/CoproductTagEncoding",
21594 ));
21595 }
21596 if in_left_region {
21597 *left_pins = left_pins.saturating_add(1);
21598 if *bias != 0 { *left_bias_ok = false; }
21599 } else {
21600 *right_pins = right_pins.saturating_add(1);
21601 if *bias != -1 { *right_bias_ok = false; }
21602 }
21603 } else if touches_tag_site {
21604 let nonzero_only_at_tag_site = nonzero_count == 1
21605 && (nonzero_index as u16) == tag_site;
21606 if nonzero_only_at_tag_site {
21607 return Err(GenericImpossibilityWitness::for_identity(
21608 "https://uor.foundation/foundation/CoproductTagEncoding",
21609 ));
21610 } else {
21611 return Err(GenericImpossibilityWitness::for_identity(
21612 "https://uor.foundation/op/ST_6",
21613 ));
21614 }
21615 }
21616 }
21617 crate::pipeline::ConstraintRef::Conjunction { conjuncts, conjunct_count } => {
21618 if max_depth == 0 {
21619 return Err(GenericImpossibilityWitness::for_identity(
21620 "https://uor.foundation/op/ST_6",
21621 ));
21622 }
21623 let count = *conjunct_count as usize;
21624 let mut idx: usize = 0;
21625 while idx < count && idx < crate::pipeline::CONJUNCTION_MAX_TERMS {
21626 let lifted = conjuncts[idx].into_constraint();
21627 pc_classify_constraint(
21628 &lifted,
21629 in_left_region,
21630 tag_site,
21631 max_depth - 1,
21632 left_pins,
21633 right_pins,
21634 left_bias_ok,
21635 right_bias_ok,
21636 )?;
21637 idx += 1;
21638 }
21639 }
21640 crate::pipeline::ConstraintRef::Residue { .. }
21641 | crate::pipeline::ConstraintRef::Hamming { .. }
21642 | crate::pipeline::ConstraintRef::Depth { .. }
21643 | crate::pipeline::ConstraintRef::SatClauses { .. }
21644 | crate::pipeline::ConstraintRef::Bound { .. }
21645 | crate::pipeline::ConstraintRef::Recurse { .. } => {
21648 }
21650 }
21651 Ok(())
21652}
21653
21654pub(crate) fn validate_coproduct_structure(
21665 combined_constraints: &[crate::pipeline::ConstraintRef],
21666 left_constraint_count: usize,
21667 tag_site: u16,
21668) -> Result<(), GenericImpossibilityWitness> {
21669 let mut left_pins: u32 = 0;
21670 let mut right_pins: u32 = 0;
21671 let mut left_bias_ok: bool = true;
21672 let mut right_bias_ok: bool = true;
21673 let mut idx: usize = 0;
21674 while idx < combined_constraints.len() {
21675 let in_left_region = idx < left_constraint_count;
21676 pc_classify_constraint(
21677 &combined_constraints[idx],
21678 in_left_region,
21679 tag_site,
21680 NERVE_CONSTRAINTS_CAP as u32,
21681 &mut left_pins,
21682 &mut right_pins,
21683 &mut left_bias_ok,
21684 &mut right_bias_ok,
21685 )?;
21686 idx += 1;
21687 }
21688 if left_pins != 1 || right_pins != 1 {
21689 return Err(GenericImpossibilityWitness::for_identity(
21690 "https://uor.foundation/op/ST_6",
21691 ));
21692 }
21693 if !left_bias_ok || !right_bias_ok {
21694 return Err(GenericImpossibilityWitness::for_identity(
21695 "https://uor.foundation/op/ST_7",
21696 ));
21697 }
21698 Ok(())
21699}
21700
21701#[allow(clippy::too_many_arguments)]
21706pub(crate) fn pc_primitive_partition_product(
21707 witt_bits: u16,
21708 left_fingerprint: ContentFingerprint,
21709 right_fingerprint: ContentFingerprint,
21710 left_site_budget: u16,
21711 right_site_budget: u16,
21712 left_total_site_count: u16,
21713 right_total_site_count: u16,
21714 left_euler: i32,
21715 right_euler: i32,
21716 left_entropy_nats_bits: u64,
21717 right_entropy_nats_bits: u64,
21718 combined_site_budget: u16,
21719 combined_site_count: u16,
21720 combined_euler: i32,
21721 combined_entropy_nats_bits: u64,
21722 combined_fingerprint: ContentFingerprint,
21723) -> Result<PartitionProductWitness, GenericImpossibilityWitness> {
21724 let left_entropy_nats =
21725 <f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
21726 let right_entropy_nats =
21727 <f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
21728 let combined_entropy_nats =
21729 <f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
21730 if combined_site_budget != left_site_budget.saturating_add(right_site_budget) {
21731 return Err(GenericImpossibilityWitness::for_identity(
21732 "https://uor.foundation/op/PT_1",
21733 ));
21734 }
21735 if combined_site_count != left_total_site_count.saturating_add(right_total_site_count) {
21736 return Err(GenericImpossibilityWitness::for_identity(
21737 "https://uor.foundation/foundation/ProductLayoutWidth",
21738 ));
21739 }
21740 if combined_euler != left_euler.saturating_add(right_euler) {
21741 return Err(GenericImpossibilityWitness::for_identity(
21742 "https://uor.foundation/op/PT_3",
21743 ));
21744 }
21745 if !pc_entropy_input_is_valid(left_entropy_nats)
21746 || !pc_entropy_input_is_valid(right_entropy_nats)
21747 || !pc_entropy_input_is_valid(combined_entropy_nats)
21748 {
21749 return Err(GenericImpossibilityWitness::for_identity(
21750 "https://uor.foundation/op/PT_4",
21751 ));
21752 }
21753 let expected_entropy = left_entropy_nats + right_entropy_nats;
21754 if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
21755 return Err(GenericImpossibilityWitness::for_identity(
21756 "https://uor.foundation/op/PT_4",
21757 ));
21758 }
21759 Ok(PartitionProductWitness::with_level_fingerprints_and_sites(
21760 witt_bits,
21761 combined_fingerprint,
21762 left_fingerprint,
21763 right_fingerprint,
21764 combined_site_budget,
21765 combined_site_count,
21766 ))
21767}
21768
21769#[allow(clippy::too_many_arguments)]
21774pub(crate) fn pc_primitive_partition_coproduct(
21775 witt_bits: u16,
21776 left_fingerprint: ContentFingerprint,
21777 right_fingerprint: ContentFingerprint,
21778 left_site_budget: u16,
21779 right_site_budget: u16,
21780 left_total_site_count: u16,
21781 right_total_site_count: u16,
21782 left_euler: i32,
21783 right_euler: i32,
21784 left_entropy_nats_bits: u64,
21785 right_entropy_nats_bits: u64,
21786 left_betti: [u32; MAX_BETTI_DIMENSION],
21787 right_betti: [u32; MAX_BETTI_DIMENSION],
21788 combined_site_budget: u16,
21789 combined_site_count: u16,
21790 combined_euler: i32,
21791 combined_entropy_nats_bits: u64,
21792 combined_betti: [u32; MAX_BETTI_DIMENSION],
21793 combined_fingerprint: ContentFingerprint,
21794 combined_constraints: &[crate::pipeline::ConstraintRef],
21795 left_constraint_count: usize,
21796 tag_site: u16,
21797) -> Result<PartitionCoproductWitness, GenericImpossibilityWitness> {
21798 let left_entropy_nats =
21799 <f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
21800 let right_entropy_nats =
21801 <f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
21802 let combined_entropy_nats =
21803 <f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
21804 let expected_budget = if left_site_budget > right_site_budget {
21805 left_site_budget
21806 } else {
21807 right_site_budget
21808 };
21809 if combined_site_budget != expected_budget {
21810 return Err(GenericImpossibilityWitness::for_identity(
21811 "https://uor.foundation/op/ST_1",
21812 ));
21813 }
21814 let max_total = if left_total_site_count > right_total_site_count {
21815 left_total_site_count
21816 } else {
21817 right_total_site_count
21818 };
21819 let expected_total = max_total.saturating_add(1);
21820 if combined_site_count != expected_total {
21821 return Err(GenericImpossibilityWitness::for_identity(
21822 "https://uor.foundation/foundation/CoproductLayoutWidth",
21823 ));
21824 }
21825 if !pc_entropy_input_is_valid(left_entropy_nats)
21826 || !pc_entropy_input_is_valid(right_entropy_nats)
21827 || !pc_entropy_input_is_valid(combined_entropy_nats)
21828 {
21829 return Err(GenericImpossibilityWitness::for_identity(
21830 "https://uor.foundation/op/ST_2",
21831 ));
21832 }
21833 let max_operand_entropy = if left_entropy_nats > right_entropy_nats {
21834 left_entropy_nats
21835 } else {
21836 right_entropy_nats
21837 };
21838 let expected_entropy = core::f64::consts::LN_2 + max_operand_entropy;
21839 if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
21840 return Err(GenericImpossibilityWitness::for_identity(
21841 "https://uor.foundation/op/ST_2",
21842 ));
21843 }
21844 if tag_site != max_total {
21845 return Err(GenericImpossibilityWitness::for_identity(
21846 "https://uor.foundation/foundation/CoproductLayoutWidth",
21847 ));
21848 }
21849 validate_coproduct_structure(combined_constraints, left_constraint_count, tag_site)?;
21850 if combined_euler != left_euler.saturating_add(right_euler) {
21851 return Err(GenericImpossibilityWitness::for_identity(
21852 "https://uor.foundation/op/ST_9",
21853 ));
21854 }
21855 let mut k: usize = 0;
21856 while k < MAX_BETTI_DIMENSION {
21857 if combined_betti[k] != left_betti[k].saturating_add(right_betti[k]) {
21858 return Err(GenericImpossibilityWitness::for_identity(
21859 "https://uor.foundation/op/ST_10",
21860 ));
21861 }
21862 k += 1;
21863 }
21864 Ok(
21865 PartitionCoproductWitness::with_level_fingerprints_sites_and_tag(
21866 witt_bits,
21867 combined_fingerprint,
21868 left_fingerprint,
21869 right_fingerprint,
21870 combined_site_budget,
21871 combined_site_count,
21872 max_total,
21873 ),
21874 )
21875}
21876
21877#[allow(clippy::too_many_arguments)]
21882pub(crate) fn pc_primitive_cartesian_product(
21883 witt_bits: u16,
21884 left_fingerprint: ContentFingerprint,
21885 right_fingerprint: ContentFingerprint,
21886 left_site_budget: u16,
21887 right_site_budget: u16,
21888 left_total_site_count: u16,
21889 right_total_site_count: u16,
21890 left_euler: i32,
21891 right_euler: i32,
21892 left_betti: [u32; MAX_BETTI_DIMENSION],
21893 right_betti: [u32; MAX_BETTI_DIMENSION],
21894 left_entropy_nats_bits: u64,
21895 right_entropy_nats_bits: u64,
21896 combined_site_budget: u16,
21897 combined_site_count: u16,
21898 combined_euler: i32,
21899 combined_betti: [u32; MAX_BETTI_DIMENSION],
21900 combined_entropy_nats_bits: u64,
21901 combined_fingerprint: ContentFingerprint,
21902) -> Result<CartesianProductWitness, GenericImpossibilityWitness> {
21903 let left_entropy_nats =
21904 <f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
21905 let right_entropy_nats =
21906 <f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
21907 let combined_entropy_nats =
21908 <f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
21909 if combined_site_budget != left_site_budget.saturating_add(right_site_budget) {
21910 return Err(GenericImpossibilityWitness::for_identity(
21911 "https://uor.foundation/op/CPT_1",
21912 ));
21913 }
21914 if combined_site_count != left_total_site_count.saturating_add(right_total_site_count) {
21915 return Err(GenericImpossibilityWitness::for_identity(
21916 "https://uor.foundation/foundation/CartesianLayoutWidth",
21917 ));
21918 }
21919 if combined_euler != left_euler.saturating_mul(right_euler) {
21920 return Err(GenericImpossibilityWitness::for_identity(
21921 "https://uor.foundation/op/CPT_3",
21922 ));
21923 }
21924 let kunneth = crate::pipeline::kunneth_compose(&left_betti, &right_betti);
21925 let mut k: usize = 0;
21926 while k < MAX_BETTI_DIMENSION {
21927 if combined_betti[k] != kunneth[k] {
21928 return Err(GenericImpossibilityWitness::for_identity(
21929 "https://uor.foundation/op/CPT_4",
21930 ));
21931 }
21932 k += 1;
21933 }
21934 if !pc_entropy_input_is_valid(left_entropy_nats)
21935 || !pc_entropy_input_is_valid(right_entropy_nats)
21936 || !pc_entropy_input_is_valid(combined_entropy_nats)
21937 {
21938 return Err(GenericImpossibilityWitness::for_identity(
21939 "https://uor.foundation/op/CPT_5",
21940 ));
21941 }
21942 let expected_entropy = left_entropy_nats + right_entropy_nats;
21943 if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
21944 return Err(GenericImpossibilityWitness::for_identity(
21945 "https://uor.foundation/op/CPT_5",
21946 ));
21947 }
21948 Ok(
21949 CartesianProductWitness::with_level_fingerprints_and_invariants(
21950 witt_bits,
21951 combined_fingerprint,
21952 left_fingerprint,
21953 right_fingerprint,
21954 combined_site_budget,
21955 combined_site_count,
21956 combined_euler,
21957 combined_betti,
21958 ),
21959 )
21960}
21961
21962impl VerifiedMint for PartitionProductWitness {
21963 type Inputs = PartitionProductMintInputs;
21964 type Error = GenericImpossibilityWitness;
21965 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
21966 pc_primitive_partition_product(
21967 inputs.witt_bits,
21968 inputs.left_fingerprint,
21969 inputs.right_fingerprint,
21970 inputs.left_site_budget,
21971 inputs.right_site_budget,
21972 inputs.left_total_site_count,
21973 inputs.right_total_site_count,
21974 inputs.left_euler,
21975 inputs.right_euler,
21976 inputs.left_entropy_nats_bits,
21977 inputs.right_entropy_nats_bits,
21978 inputs.combined_site_budget,
21979 inputs.combined_site_count,
21980 inputs.combined_euler,
21981 inputs.combined_entropy_nats_bits,
21982 inputs.combined_fingerprint,
21983 )
21984 }
21985}
21986
21987impl VerifiedMint for PartitionCoproductWitness {
21988 type Inputs = PartitionCoproductMintInputs;
21989 type Error = GenericImpossibilityWitness;
21990 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
21991 pc_primitive_partition_coproduct(
21992 inputs.witt_bits,
21993 inputs.left_fingerprint,
21994 inputs.right_fingerprint,
21995 inputs.left_site_budget,
21996 inputs.right_site_budget,
21997 inputs.left_total_site_count,
21998 inputs.right_total_site_count,
21999 inputs.left_euler,
22000 inputs.right_euler,
22001 inputs.left_entropy_nats_bits,
22002 inputs.right_entropy_nats_bits,
22003 inputs.left_betti,
22004 inputs.right_betti,
22005 inputs.combined_site_budget,
22006 inputs.combined_site_count,
22007 inputs.combined_euler,
22008 inputs.combined_entropy_nats_bits,
22009 inputs.combined_betti,
22010 inputs.combined_fingerprint,
22011 inputs.combined_constraints,
22012 inputs.left_constraint_count,
22013 inputs.tag_site,
22014 )
22015 }
22016}
22017
22018impl VerifiedMint for CartesianProductWitness {
22019 type Inputs = CartesianProductMintInputs;
22020 type Error = GenericImpossibilityWitness;
22021 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
22022 pc_primitive_cartesian_product(
22023 inputs.witt_bits,
22024 inputs.left_fingerprint,
22025 inputs.right_fingerprint,
22026 inputs.left_site_budget,
22027 inputs.right_site_budget,
22028 inputs.left_total_site_count,
22029 inputs.right_total_site_count,
22030 inputs.left_euler,
22031 inputs.right_euler,
22032 inputs.left_betti,
22033 inputs.right_betti,
22034 inputs.left_entropy_nats_bits,
22035 inputs.right_entropy_nats_bits,
22036 inputs.combined_site_budget,
22037 inputs.combined_site_count,
22038 inputs.combined_euler,
22039 inputs.combined_betti,
22040 inputs.combined_entropy_nats_bits,
22041 inputs.combined_fingerprint,
22042 )
22043 }
22044}
22045
22046#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22053pub struct PartitionRecord<H: crate::HostTypes> {
22054 pub site_budget: u16,
22056 pub euler: i32,
22058 pub betti: [u32; MAX_BETTI_DIMENSION],
22060 pub entropy_nats_bits: u64,
22062 _phantom: core::marker::PhantomData<H>,
22063}
22064
22065impl<H: crate::HostTypes> PartitionRecord<H> {
22066 #[inline]
22069 #[must_use]
22070 pub const fn new(
22071 site_budget: u16,
22072 euler: i32,
22073 betti: [u32; MAX_BETTI_DIMENSION],
22074 entropy_nats_bits: u64,
22075 ) -> Self {
22076 Self {
22077 site_budget,
22078 euler,
22079 betti,
22080 entropy_nats_bits,
22081 _phantom: core::marker::PhantomData,
22082 }
22083 }
22084}
22085
22086pub trait PartitionResolver<H: crate::HostTypes> {
22091 fn resolve(&self, fp: ContentFingerprint) -> Option<PartitionRecord<H>>;
22095}
22096
22097#[derive(Debug)]
22103pub struct PartitionHandle<H: crate::HostTypes> {
22104 fingerprint: ContentFingerprint,
22105 _phantom: core::marker::PhantomData<H>,
22106}
22107impl<H: crate::HostTypes> Copy for PartitionHandle<H> {}
22108impl<H: crate::HostTypes> Clone for PartitionHandle<H> {
22109 #[inline]
22110 fn clone(&self) -> Self {
22111 *self
22112 }
22113}
22114impl<H: crate::HostTypes> PartialEq for PartitionHandle<H> {
22115 #[inline]
22116 fn eq(&self, other: &Self) -> bool {
22117 self.fingerprint == other.fingerprint
22118 }
22119}
22120impl<H: crate::HostTypes> Eq for PartitionHandle<H> {}
22121impl<H: crate::HostTypes> core::hash::Hash for PartitionHandle<H> {
22122 #[inline]
22123 fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
22124 self.fingerprint.hash(state);
22125 }
22126}
22127
22128impl<H: crate::HostTypes> PartitionHandle<H> {
22129 #[inline]
22131 #[must_use]
22132 pub const fn from_fingerprint(fingerprint: ContentFingerprint) -> Self {
22133 Self {
22134 fingerprint,
22135 _phantom: core::marker::PhantomData,
22136 }
22137 }
22138 #[inline]
22140 #[must_use]
22141 pub const fn fingerprint(&self) -> ContentFingerprint {
22142 self.fingerprint
22143 }
22144 #[inline]
22147 pub fn resolve_with<R: PartitionResolver<H>>(
22148 &self,
22149 resolver: &R,
22150 ) -> Option<PartitionRecord<H>> {
22151 resolver.resolve(self.fingerprint)
22152 }
22153}
22154
22155#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22159pub struct NullElement<H: HostTypes> {
22160 _phantom: core::marker::PhantomData<H>,
22161}
22162impl<H: HostTypes> Default for NullElement<H> {
22163 fn default() -> Self {
22164 Self {
22165 _phantom: core::marker::PhantomData,
22166 }
22167 }
22168}
22169impl<H: HostTypes> crate::kernel::address::Element<H> for NullElement<H> {
22170 fn length(&self) -> u64 {
22171 0
22172 }
22173 fn addresses(&self) -> &H::HostString {
22174 H::EMPTY_HOST_STRING
22175 }
22176 fn digest(&self) -> &H::HostString {
22177 H::EMPTY_HOST_STRING
22178 }
22179 fn digest_algorithm(&self) -> &H::HostString {
22180 H::EMPTY_HOST_STRING
22181 }
22182 fn canonical_bytes(&self) -> &H::WitnessBytes {
22183 H::EMPTY_WITNESS_BYTES
22184 }
22185 fn witt_length(&self) -> u64 {
22186 0
22187 }
22188}
22189
22190#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22192pub struct NullDatum<H: HostTypes> {
22193 element: NullElement<H>,
22194 _phantom: core::marker::PhantomData<H>,
22195}
22196impl<H: HostTypes> Default for NullDatum<H> {
22197 fn default() -> Self {
22198 Self {
22199 element: NullElement::default(),
22200 _phantom: core::marker::PhantomData,
22201 }
22202 }
22203}
22204impl<H: HostTypes> crate::kernel::schema::Datum<H> for NullDatum<H> {
22205 fn value(&self) -> u64 {
22206 0
22207 }
22208 fn witt_length(&self) -> u64 {
22209 0
22210 }
22211 fn stratum(&self) -> u64 {
22212 0
22213 }
22214 fn spectrum(&self) -> u64 {
22215 0
22216 }
22217 type Element = NullElement<H>;
22218 fn element(&self) -> &Self::Element {
22219 &self.element
22220 }
22221}
22222
22223#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22225pub struct NullTermExpression<H: HostTypes> {
22226 _phantom: core::marker::PhantomData<H>,
22227}
22228impl<H: HostTypes> Default for NullTermExpression<H> {
22229 fn default() -> Self {
22230 Self {
22231 _phantom: core::marker::PhantomData,
22232 }
22233 }
22234}
22235impl<H: HostTypes> crate::kernel::schema::TermExpression<H> for NullTermExpression<H> {}
22236
22237#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22240pub struct NullSiteIndex<H: HostTypes> {
22241 _phantom: core::marker::PhantomData<H>,
22242}
22243impl<H: HostTypes> Default for NullSiteIndex<H> {
22244 fn default() -> Self {
22245 Self {
22246 _phantom: core::marker::PhantomData,
22247 }
22248 }
22249}
22250impl<H: HostTypes> crate::bridge::partition::SiteIndex<H> for NullSiteIndex<H> {
22251 fn site_position(&self) -> u64 {
22252 0
22253 }
22254 fn site_state(&self) -> u64 {
22255 0
22256 }
22257 type SiteIndexTarget = NullSiteIndex<H>;
22258 fn ancilla_site(&self) -> &Self::SiteIndexTarget {
22259 self
22260 }
22261}
22262
22263#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22267pub struct NullTagSite<H: HostTypes> {
22268 ancilla: NullSiteIndex<H>,
22269}
22270impl<H: HostTypes> Default for NullTagSite<H> {
22271 fn default() -> Self {
22272 Self {
22273 ancilla: NullSiteIndex::default(),
22274 }
22275 }
22276}
22277impl<H: HostTypes> crate::bridge::partition::SiteIndex<H> for NullTagSite<H> {
22278 fn site_position(&self) -> u64 {
22279 0
22280 }
22281 fn site_state(&self) -> u64 {
22282 0
22283 }
22284 type SiteIndexTarget = NullSiteIndex<H>;
22285 fn ancilla_site(&self) -> &Self::SiteIndexTarget {
22286 &self.ancilla
22287 }
22288}
22289impl<H: HostTypes> crate::bridge::partition::TagSite<H> for NullTagSite<H> {
22290 fn tag_value(&self) -> bool {
22291 false
22292 }
22293}
22294
22295#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22298pub struct NullSiteBinding<H: HostTypes> {
22299 constraint: NullConstraint<H>,
22300 site_index: NullSiteIndex<H>,
22301}
22302impl<H: HostTypes> Default for NullSiteBinding<H> {
22303 fn default() -> Self {
22304 Self {
22305 constraint: NullConstraint::default(),
22306 site_index: NullSiteIndex::default(),
22307 }
22308 }
22309}
22310impl<H: HostTypes> crate::bridge::partition::SiteBinding<H> for NullSiteBinding<H> {
22311 type Constraint = NullConstraint<H>;
22312 fn pinned_by(&self) -> &Self::Constraint {
22313 &self.constraint
22314 }
22315 type SiteIndex = NullSiteIndex<H>;
22316 fn pins_coordinate(&self) -> &Self::SiteIndex {
22317 &self.site_index
22318 }
22319}
22320
22321#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22324pub struct NullConstraint<H: HostTypes> {
22325 _phantom: core::marker::PhantomData<H>,
22326}
22327impl<H: HostTypes> Default for NullConstraint<H> {
22328 fn default() -> Self {
22329 Self {
22330 _phantom: core::marker::PhantomData,
22331 }
22332 }
22333}
22334impl<H: HostTypes> crate::user::type_::Constraint<H> for NullConstraint<H> {
22335 fn metric_axis(&self) -> MetricAxis {
22336 MetricAxis::Vertical
22337 }
22338 type SiteIndex = NullSiteIndex<H>;
22339 fn pins_sites(&self) -> &[Self::SiteIndex] {
22340 &[]
22341 }
22342 fn crossing_cost(&self) -> u64 {
22343 0
22344 }
22345}
22346
22347#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22350pub struct NullFreeRank<H: HostTypes> {
22351 _phantom: core::marker::PhantomData<H>,
22352}
22353impl<H: HostTypes> Default for NullFreeRank<H> {
22354 fn default() -> Self {
22355 Self {
22356 _phantom: core::marker::PhantomData,
22357 }
22358 }
22359}
22360impl<H: HostTypes> crate::bridge::partition::FreeRank<H> for NullFreeRank<H> {
22361 fn total_sites(&self) -> u64 {
22362 0
22363 }
22364 fn pinned_count(&self) -> u64 {
22365 0
22366 }
22367 fn free_rank(&self) -> u64 {
22368 0
22369 }
22370 fn is_closed(&self) -> bool {
22371 true
22372 }
22373 type SiteIndex = NullSiteIndex<H>;
22374 fn has_site(&self) -> &[Self::SiteIndex] {
22375 &[]
22376 }
22377 type SiteBinding = NullSiteBinding<H>;
22378 fn has_binding(&self) -> &[Self::SiteBinding] {
22379 &[]
22380 }
22381 fn reversible_strategy(&self) -> bool {
22382 false
22383 }
22384}
22385
22386#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22389pub struct NullIrreducibleSet<H: HostTypes> {
22390 _phantom: core::marker::PhantomData<H>,
22391}
22392impl<H: HostTypes> Default for NullIrreducibleSet<H> {
22393 fn default() -> Self {
22394 Self {
22395 _phantom: core::marker::PhantomData,
22396 }
22397 }
22398}
22399impl<H: HostTypes> crate::bridge::partition::Component<H> for NullIrreducibleSet<H> {
22400 type Datum = NullDatum<H>;
22401 fn member(&self) -> &[Self::Datum] {
22402 &[]
22403 }
22404 fn cardinality(&self) -> u64 {
22405 0
22406 }
22407}
22408impl<H: HostTypes> crate::bridge::partition::IrreducibleSet<H> for NullIrreducibleSet<H> {}
22409
22410#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22413pub struct NullReducibleSet<H: HostTypes> {
22414 _phantom: core::marker::PhantomData<H>,
22415}
22416impl<H: HostTypes> Default for NullReducibleSet<H> {
22417 fn default() -> Self {
22418 Self {
22419 _phantom: core::marker::PhantomData,
22420 }
22421 }
22422}
22423impl<H: HostTypes> crate::bridge::partition::Component<H> for NullReducibleSet<H> {
22424 type Datum = NullDatum<H>;
22425 fn member(&self) -> &[Self::Datum] {
22426 &[]
22427 }
22428 fn cardinality(&self) -> u64 {
22429 0
22430 }
22431}
22432impl<H: HostTypes> crate::bridge::partition::ReducibleSet<H> for NullReducibleSet<H> {}
22433
22434#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22437pub struct NullUnitGroup<H: HostTypes> {
22438 _phantom: core::marker::PhantomData<H>,
22439}
22440impl<H: HostTypes> Default for NullUnitGroup<H> {
22441 fn default() -> Self {
22442 Self {
22443 _phantom: core::marker::PhantomData,
22444 }
22445 }
22446}
22447impl<H: HostTypes> crate::bridge::partition::Component<H> for NullUnitGroup<H> {
22448 type Datum = NullDatum<H>;
22449 fn member(&self) -> &[Self::Datum] {
22450 &[]
22451 }
22452 fn cardinality(&self) -> u64 {
22453 0
22454 }
22455}
22456impl<H: HostTypes> crate::bridge::partition::UnitGroup<H> for NullUnitGroup<H> {}
22457
22458#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22462pub struct NullComplement<H: HostTypes> {
22463 term: NullTermExpression<H>,
22464}
22465impl<H: HostTypes> Default for NullComplement<H> {
22466 fn default() -> Self {
22467 Self {
22468 term: NullTermExpression::default(),
22469 }
22470 }
22471}
22472impl<H: HostTypes> crate::bridge::partition::Component<H> for NullComplement<H> {
22473 type Datum = NullDatum<H>;
22474 fn member(&self) -> &[Self::Datum] {
22475 &[]
22476 }
22477 fn cardinality(&self) -> u64 {
22478 0
22479 }
22480}
22481impl<H: HostTypes> crate::bridge::partition::Complement<H> for NullComplement<H> {
22482 type TermExpression = NullTermExpression<H>;
22483 fn exterior_criteria(&self) -> &Self::TermExpression {
22484 &self.term
22485 }
22486}
22487
22488#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22491pub struct NullTypeDefinition<H: HostTypes> {
22492 element: NullElement<H>,
22493}
22494impl<H: HostTypes> Default for NullTypeDefinition<H> {
22495 fn default() -> Self {
22496 Self {
22497 element: NullElement::default(),
22498 }
22499 }
22500}
22501impl<H: HostTypes> crate::user::type_::TypeDefinition<H> for NullTypeDefinition<H> {
22502 type Element = NullElement<H>;
22503 fn content_address(&self) -> &Self::Element {
22504 &self.element
22505 }
22506}
22507
22508#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22517pub struct NullPartition<H: HostTypes> {
22518 irreducibles: NullIrreducibleSet<H>,
22519 reducibles: NullReducibleSet<H>,
22520 units: NullUnitGroup<H>,
22521 exterior: NullComplement<H>,
22522 free_rank: NullFreeRank<H>,
22523 tag_site: NullTagSite<H>,
22524 source_type: NullTypeDefinition<H>,
22525 fingerprint: ContentFingerprint,
22526}
22527
22528impl<H: HostTypes> NullPartition<H> {
22529 #[inline]
22532 #[must_use]
22533 pub fn from_fingerprint(fingerprint: ContentFingerprint) -> Self {
22534 Self {
22535 irreducibles: NullIrreducibleSet::default(),
22536 reducibles: NullReducibleSet::default(),
22537 units: NullUnitGroup::default(),
22538 exterior: NullComplement::default(),
22539 free_rank: NullFreeRank::default(),
22540 tag_site: NullTagSite::default(),
22541 source_type: NullTypeDefinition::default(),
22542 fingerprint,
22543 }
22544 }
22545 #[inline]
22547 #[must_use]
22548 pub const fn fingerprint(&self) -> ContentFingerprint {
22549 self.fingerprint
22550 }
22551 pub const ABSENT: NullPartition<H> = NullPartition {
22554 irreducibles: NullIrreducibleSet {
22555 _phantom: core::marker::PhantomData,
22556 },
22557 reducibles: NullReducibleSet {
22558 _phantom: core::marker::PhantomData,
22559 },
22560 units: NullUnitGroup {
22561 _phantom: core::marker::PhantomData,
22562 },
22563 exterior: NullComplement {
22564 term: NullTermExpression {
22565 _phantom: core::marker::PhantomData,
22566 },
22567 },
22568 free_rank: NullFreeRank {
22569 _phantom: core::marker::PhantomData,
22570 },
22571 tag_site: NullTagSite {
22572 ancilla: NullSiteIndex {
22573 _phantom: core::marker::PhantomData,
22574 },
22575 },
22576 source_type: NullTypeDefinition {
22577 element: NullElement {
22578 _phantom: core::marker::PhantomData,
22579 },
22580 },
22581 fingerprint: ContentFingerprint::zero(),
22582 };
22583}
22584
22585impl<H: HostTypes> crate::bridge::partition::Partition<H> for NullPartition<H> {
22586 type IrreducibleSet = NullIrreducibleSet<H>;
22587 fn irreducibles(&self) -> &Self::IrreducibleSet {
22588 &self.irreducibles
22589 }
22590 type ReducibleSet = NullReducibleSet<H>;
22591 fn reducibles(&self) -> &Self::ReducibleSet {
22592 &self.reducibles
22593 }
22594 type UnitGroup = NullUnitGroup<H>;
22595 fn units(&self) -> &Self::UnitGroup {
22596 &self.units
22597 }
22598 type Complement = NullComplement<H>;
22599 fn exterior(&self) -> &Self::Complement {
22600 &self.exterior
22601 }
22602 fn density(&self) -> H::Decimal {
22603 H::EMPTY_DECIMAL
22604 }
22605 type TypeDefinition = NullTypeDefinition<H>;
22606 fn source_type(&self) -> &Self::TypeDefinition {
22607 &self.source_type
22608 }
22609 fn witt_length(&self) -> u64 {
22610 0
22611 }
22612 type FreeRank = NullFreeRank<H>;
22613 fn site_budget(&self) -> &Self::FreeRank {
22614 &self.free_rank
22615 }
22616 fn is_exhaustive(&self) -> bool {
22617 true
22618 }
22619 type TagSite = NullTagSite<H>;
22620 fn tag_site_of(&self) -> &Self::TagSite {
22621 &self.tag_site
22622 }
22623 fn product_category_level(&self) -> &H::HostString {
22624 H::EMPTY_HOST_STRING
22625 }
22626}
22627
22628impl<H: HostTypes> crate::bridge::partition::PartitionProduct<H> for PartitionProductWitness {
22629 type Partition = NullPartition<H>;
22630 fn left_factor(&self) -> Self::Partition {
22631 NullPartition::from_fingerprint(self.left_fingerprint)
22632 }
22633 fn right_factor(&self) -> Self::Partition {
22634 NullPartition::from_fingerprint(self.right_fingerprint)
22635 }
22636}
22637
22638impl<H: HostTypes> crate::bridge::partition::PartitionCoproduct<H> for PartitionCoproductWitness {
22639 type Partition = NullPartition<H>;
22640 fn left_summand(&self) -> Self::Partition {
22641 NullPartition::from_fingerprint(self.left_fingerprint)
22642 }
22643 fn right_summand(&self) -> Self::Partition {
22644 NullPartition::from_fingerprint(self.right_fingerprint)
22645 }
22646}
22647
22648impl<H: HostTypes> crate::bridge::partition::CartesianPartitionProduct<H>
22649 for CartesianProductWitness
22650{
22651 type Partition = NullPartition<H>;
22652 fn left_cartesian_factor(&self) -> Self::Partition {
22653 NullPartition::from_fingerprint(self.left_fingerprint)
22654 }
22655 fn right_cartesian_factor(&self) -> Self::Partition {
22656 NullPartition::from_fingerprint(self.right_fingerprint)
22657 }
22658}
22659
22660pub mod prelude {
22667 pub use super::calibrations;
22668 pub use super::Add;
22669 pub use super::And;
22670 pub use super::BNot;
22671 pub use super::BinaryGroundingMap;
22672 pub use super::BindingEntry;
22673 pub use super::BindingsTable;
22674 pub use super::BornRuleVerification;
22675 pub use super::Calibration;
22676 pub use super::CalibrationError;
22677 pub use super::CanonicalTimingPolicy;
22678 pub use super::Certificate;
22679 pub use super::Certified;
22680 pub use super::ChainAuditTrail;
22681 pub use super::CompileTime;
22682 pub use super::CompileUnit;
22683 pub use super::CompileUnitBuilder;
22684 pub use super::CompletenessAuditTrail;
22685 pub use super::CompletenessCertificate;
22686 pub use super::ConstrainedTypeInput;
22687 pub use super::ContentAddress;
22688 pub use super::ContentFingerprint;
22689 pub use super::Datum;
22690 pub use super::DigestGroundingMap;
22691 pub use super::Embed;
22692 pub use super::FragmentMarker;
22693 pub use super::GenericImpossibilityWitness;
22694 pub use super::GeodesicCertificate;
22695 pub use super::GeodesicEvidenceBundle;
22696 pub use super::Grounded;
22697 pub use super::GroundedCoord;
22698 pub use super::GroundedShape;
22699 pub use super::GroundedTuple;
22700 pub use super::GroundedValue;
22701 pub use super::Grounding;
22702 pub use super::GroundingCertificate;
22703 pub use super::GroundingExt;
22704 pub use super::GroundingMapKind;
22705 pub use super::GroundingProgram;
22706 pub use super::Hasher;
22707 pub use super::ImpossibilityWitnessKind;
22708 pub use super::InhabitanceCertificate;
22709 pub use super::InhabitanceImpossibilityWitness;
22710 pub use super::IntegerGroundingMap;
22711 pub use super::Invertible;
22712 pub use super::InvolutionCertificate;
22713 pub use super::IsometryCertificate;
22714 pub use super::JsonGroundingMap;
22715 pub use super::LandauerBudget;
22716 pub use super::LiftChainCertificate;
22717 pub use super::MeasurementCertificate;
22718 pub use super::Mul;
22719 pub use super::Nanos;
22720 pub use super::Neg;
22721 pub use super::OntologyTarget;
22722 pub use super::Or;
22723 pub use super::PipelineFailure;
22724 pub use super::PreservesMetric;
22725 pub use super::PreservesStructure;
22726 pub use super::RingOp;
22727 pub use super::Runtime;
22728 pub use super::ShapeViolation;
22729 pub use super::Sub;
22730 pub use super::Succ;
22731 pub use super::Term;
22732 pub use super::TermArena;
22733 pub use super::TimingPolicy;
22734 pub use super::Total;
22735 pub use super::TransformCertificate;
22736 pub use super::Triad;
22737 pub use super::UnaryRingOp;
22738 pub use super::UorTime;
22739 pub use super::Utf8GroundingMap;
22740 pub use super::ValidLevelEmbedding;
22741 pub use super::Validated;
22742 pub use super::ValidationPhase;
22743 pub use super::Xor;
22744 pub use super::W16;
22745 pub use super::W8;
22746 pub use crate::pipeline::empty_bindings_table;
22747 pub use crate::pipeline::{
22748 validate_constrained_type, validate_constrained_type_const, ConstrainedTypeShape,
22749 ConstraintRef, FragmentKind,
22750 };
22751 pub use crate::{DecimalTranscendental, DefaultHostTypes, HostTypes, WittLevel};
22752}