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 {
818 type Source: GroundedShape;
821
822 type ProjectionMap: ProjectionMapKind;
825
826 type Output;
830
831 fn project(&self, grounded: &Grounded<Self::Source>) -> Self::Output;
835}
836
837pub trait EmitThrough<H: crate::HostTypes>: crate::bridge::boundary::EmitEffect<H> {
842 type Sinking: Sinking;
844
845 fn emit(
849 &self,
850 grounded: &Grounded<<Self::Sinking as Sinking>::Source>,
851 ) -> <Self::Sinking as Sinking>::Output;
852}
853
854pub trait ValidationPhase: validation_phase_sealed::Sealed {}
858
859mod validation_phase_sealed {
860 pub trait Sealed {}
862 impl Sealed for super::CompileTime {}
863 impl Sealed for super::Runtime {}
864}
865
866#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
870pub struct CompileTime;
871impl ValidationPhase for CompileTime {}
872
873#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
877pub struct Runtime;
878impl ValidationPhase for Runtime {}
879
880#[derive(Debug, Clone, PartialEq, Eq)]
913pub struct Validated<T, Phase: ValidationPhase = Runtime> {
914 inner: T,
916 _phase: PhantomData<Phase>,
918 _sealed: (),
920}
921
922impl<T, Phase: ValidationPhase> Validated<T, Phase> {
923 #[inline]
925 #[must_use]
926 pub const fn inner(&self) -> &T {
927 &self.inner
928 }
929
930 #[inline]
932 #[allow(dead_code)]
933 pub(crate) const fn new(inner: T) -> Self {
934 Self {
935 inner,
936 _phase: PhantomData,
937 _sealed: (),
938 }
939 }
940}
941
942impl<T> From<Validated<T, CompileTime>> for Validated<T, Runtime> {
944 #[inline]
945 fn from(value: Validated<T, CompileTime>) -> Self {
946 Self {
947 inner: value.inner,
948 _phase: PhantomData,
949 _sealed: (),
950 }
951 }
952}
953
954#[derive(Debug, Clone, PartialEq, Eq)]
961pub struct Derivation {
962 step_count: u32,
964 witt_level_bits: u16,
967 content_fingerprint: ContentFingerprint,
972}
973
974impl Derivation {
975 #[inline]
977 #[must_use]
978 pub const fn step_count(&self) -> u32 {
979 self.step_count
980 }
981
982 #[inline]
984 #[must_use]
985 pub const fn witt_level_bits(&self) -> u16 {
986 self.witt_level_bits
987 }
988
989 #[inline]
992 #[must_use]
993 pub const fn content_fingerprint(&self) -> ContentFingerprint {
994 self.content_fingerprint
995 }
996
997 #[inline]
999 #[must_use]
1000 #[allow(dead_code)]
1001 pub(crate) const fn new(
1002 step_count: u32,
1003 witt_level_bits: u16,
1004 content_fingerprint: ContentFingerprint,
1005 ) -> Self {
1006 Self {
1007 step_count,
1008 witt_level_bits,
1009 content_fingerprint,
1010 }
1011 }
1012}
1013
1014#[derive(Debug, Clone, PartialEq, Eq)]
1017pub struct FreeRank {
1018 total: u32,
1020 pinned: u32,
1022}
1023
1024impl FreeRank {
1025 #[inline]
1027 #[must_use]
1028 pub const fn total(&self) -> u32 {
1029 self.total
1030 }
1031
1032 #[inline]
1034 #[must_use]
1035 pub const fn pinned(&self) -> u32 {
1036 self.pinned
1037 }
1038
1039 #[inline]
1041 #[must_use]
1042 pub const fn remaining(&self) -> u32 {
1043 self.total - self.pinned
1044 }
1045
1046 #[inline]
1048 #[allow(dead_code)]
1049 pub(crate) const fn new(total: u32, pinned: u32) -> Self {
1050 Self { total, pinned }
1051 }
1052}
1053
1054#[derive(Debug)]
1062pub struct LandauerBudget<H: HostTypes = crate::DefaultHostTypes> {
1063 nats: H::Decimal,
1065 _phantom: core::marker::PhantomData<H>,
1067 _sealed: (),
1069}
1070
1071impl<H: HostTypes> LandauerBudget<H> {
1072 #[inline]
1074 #[must_use]
1075 pub const fn nats(&self) -> H::Decimal {
1076 self.nats
1077 }
1078
1079 #[inline]
1082 #[must_use]
1083 #[allow(dead_code)]
1084 pub(crate) const fn new(nats: H::Decimal) -> Self {
1085 Self {
1086 nats,
1087 _phantom: core::marker::PhantomData,
1088 _sealed: (),
1089 }
1090 }
1091
1092 #[inline]
1094 #[must_use]
1095 #[allow(dead_code)]
1096 pub(crate) const fn zero() -> Self {
1097 Self {
1098 nats: H::EMPTY_DECIMAL,
1099 _phantom: core::marker::PhantomData,
1100 _sealed: (),
1101 }
1102 }
1103}
1104
1105impl<H: HostTypes> Copy for LandauerBudget<H> {}
1106impl<H: HostTypes> Clone for LandauerBudget<H> {
1107 #[inline]
1108 fn clone(&self) -> Self {
1109 *self
1110 }
1111}
1112impl<H: HostTypes> PartialEq for LandauerBudget<H> {
1113 #[inline]
1114 fn eq(&self, other: &Self) -> bool {
1115 self.nats == other.nats
1116 }
1117}
1118impl<H: HostTypes> Eq for LandauerBudget<H> {}
1119impl<H: HostTypes> PartialOrd for LandauerBudget<H> {
1120 #[inline]
1121 fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
1122 Some(self.cmp(other))
1123 }
1124}
1125impl<H: HostTypes> Ord for LandauerBudget<H> {
1126 #[inline]
1127 fn cmp(&self, other: &Self) -> core::cmp::Ordering {
1128 self.nats
1130 .partial_cmp(&other.nats)
1131 .unwrap_or(core::cmp::Ordering::Equal)
1132 }
1133}
1134impl<H: HostTypes> core::hash::Hash for LandauerBudget<H> {
1135 #[inline]
1136 fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
1137 self.nats.to_bits().hash(state);
1140 }
1141}
1142
1143#[derive(Debug)]
1158pub struct UorTime<H: HostTypes = crate::DefaultHostTypes> {
1159 landauer_nats: LandauerBudget<H>,
1161 rewrite_steps: u64,
1163 _sealed: (),
1165}
1166
1167impl<H: HostTypes> UorTime<H> {
1168 #[inline]
1171 #[must_use]
1172 pub const fn landauer_nats(&self) -> LandauerBudget<H> {
1173 self.landauer_nats
1174 }
1175
1176 #[inline]
1179 #[must_use]
1180 pub const fn rewrite_steps(&self) -> u64 {
1181 self.rewrite_steps
1182 }
1183
1184 #[inline]
1186 #[must_use]
1187 #[allow(dead_code)]
1188 pub(crate) const fn new(landauer_nats: LandauerBudget<H>, rewrite_steps: u64) -> Self {
1189 Self {
1190 landauer_nats,
1191 rewrite_steps,
1192 _sealed: (),
1193 }
1194 }
1195
1196 #[inline]
1198 #[must_use]
1199 #[allow(dead_code)]
1200 pub(crate) const fn zero() -> Self {
1201 Self {
1202 landauer_nats: LandauerBudget::<H>::zero(),
1203 rewrite_steps: 0,
1204 _sealed: (),
1205 }
1206 }
1207
1208 #[inline]
1216 #[must_use]
1217 pub fn min_wall_clock(&self, cal: &Calibration<H>) -> Nanos {
1218 let landauer_seconds = self.landauer_nats.nats() * cal.k_b_t() / cal.thermal_power();
1220 let pi_times_h_bar =
1225 <H::Decimal as DecimalTranscendental>::from_bits(crate::PI_TIMES_H_BAR_BITS);
1226 let two = <H::Decimal as DecimalTranscendental>::from_u32(2);
1227 let ml_seconds_per_step = pi_times_h_bar / (two * cal.characteristic_energy());
1228 let steps = <H::Decimal as DecimalTranscendental>::from_u64(self.rewrite_steps);
1229 let ml_seconds = ml_seconds_per_step * steps;
1230 let max_seconds = if landauer_seconds > ml_seconds {
1231 landauer_seconds
1232 } else {
1233 ml_seconds
1234 };
1235 let nanos_per_second =
1237 <H::Decimal as DecimalTranscendental>::from_bits(crate::NANOS_PER_SECOND_BITS);
1238 let nanos = max_seconds * nanos_per_second;
1239 Nanos {
1240 ns: <H::Decimal as DecimalTranscendental>::as_u64_saturating(nanos),
1241 _sealed: (),
1242 }
1243 }
1244}
1245
1246impl<H: HostTypes> Copy for UorTime<H> {}
1247impl<H: HostTypes> Clone for UorTime<H> {
1248 #[inline]
1249 fn clone(&self) -> Self {
1250 *self
1251 }
1252}
1253impl<H: HostTypes> PartialEq for UorTime<H> {
1254 #[inline]
1255 fn eq(&self, other: &Self) -> bool {
1256 self.landauer_nats == other.landauer_nats && self.rewrite_steps == other.rewrite_steps
1257 }
1258}
1259impl<H: HostTypes> Eq for UorTime<H> {}
1260impl<H: HostTypes> core::hash::Hash for UorTime<H> {
1261 #[inline]
1262 fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
1263 self.landauer_nats.hash(state);
1264 self.rewrite_steps.hash(state);
1265 }
1266}
1267impl<H: HostTypes> PartialOrd for UorTime<H> {
1268 #[inline]
1269 fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
1270 let l = self.landauer_nats.cmp(&other.landauer_nats);
1271 let r = self.rewrite_steps.cmp(&other.rewrite_steps);
1272 match (l, r) {
1273 (core::cmp::Ordering::Equal, core::cmp::Ordering::Equal) => {
1274 Some(core::cmp::Ordering::Equal)
1275 }
1276 (core::cmp::Ordering::Less, core::cmp::Ordering::Less)
1277 | (core::cmp::Ordering::Less, core::cmp::Ordering::Equal)
1278 | (core::cmp::Ordering::Equal, core::cmp::Ordering::Less) => {
1279 Some(core::cmp::Ordering::Less)
1280 }
1281 (core::cmp::Ordering::Greater, core::cmp::Ordering::Greater)
1282 | (core::cmp::Ordering::Greater, core::cmp::Ordering::Equal)
1283 | (core::cmp::Ordering::Equal, core::cmp::Ordering::Greater) => {
1284 Some(core::cmp::Ordering::Greater)
1285 }
1286 _ => None,
1287 }
1288 }
1289}
1290
1291#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1299pub struct Nanos {
1300 ns: u64,
1302 _sealed: (),
1304}
1305
1306impl Nanos {
1307 #[inline]
1310 #[must_use]
1311 pub const fn as_u64(self) -> u64 {
1312 self.ns
1313 }
1314}
1315
1316#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1319pub enum CalibrationError {
1320 ThermalEnergy,
1323 ThermalPower,
1325 CharacteristicEnergy,
1328}
1329
1330impl core::fmt::Display for CalibrationError {
1331 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1332 match self {
1333 Self::ThermalEnergy => {
1334 f.write_str("calibration k_b_t out of range (must be in [1e-30, 1e-15] joules)")
1335 }
1336 Self::ThermalPower => {
1337 f.write_str("calibration thermal_power out of range (must be > 0 and <= 1e9 W)")
1338 }
1339 Self::CharacteristicEnergy => f.write_str(
1340 "calibration characteristic_energy out of range (must be > 0 and <= 1e3 J)",
1341 ),
1342 }
1343 }
1344}
1345
1346impl core::error::Error for CalibrationError {}
1347
1348#[derive(Debug)]
1358pub struct Calibration<H: HostTypes = crate::DefaultHostTypes> {
1359 k_b_t: H::Decimal,
1361 thermal_power: H::Decimal,
1363 characteristic_energy: H::Decimal,
1365 _phantom: core::marker::PhantomData<H>,
1367}
1368
1369impl<H: HostTypes> Copy for Calibration<H> {}
1370impl<H: HostTypes> Clone for Calibration<H> {
1371 #[inline]
1372 fn clone(&self) -> Self {
1373 *self
1374 }
1375}
1376impl<H: HostTypes> PartialEq for Calibration<H> {
1377 #[inline]
1378 fn eq(&self, other: &Self) -> bool {
1379 self.k_b_t == other.k_b_t
1380 && self.thermal_power == other.thermal_power
1381 && self.characteristic_energy == other.characteristic_energy
1382 }
1383}
1384
1385impl<H: HostTypes> Calibration<H> {
1386 #[inline]
1411 pub fn new(
1412 k_b_t: H::Decimal,
1413 thermal_power: H::Decimal,
1414 characteristic_energy: H::Decimal,
1415 ) -> Result<Self, CalibrationError> {
1416 let zero = <H::Decimal as Default>::default();
1420 let kbt_lo =
1421 <H::Decimal as DecimalTranscendental>::from_bits(crate::CALIBRATION_KBT_LO_BITS);
1422 let kbt_hi =
1423 <H::Decimal as DecimalTranscendental>::from_bits(crate::CALIBRATION_KBT_HI_BITS);
1424 let tp_hi = <H::Decimal as DecimalTranscendental>::from_bits(
1425 crate::CALIBRATION_THERMAL_POWER_HI_BITS,
1426 );
1427 let ce_hi = <H::Decimal as DecimalTranscendental>::from_bits(
1428 crate::CALIBRATION_CHAR_ENERGY_HI_BITS,
1429 );
1430 #[allow(clippy::eq_op)]
1432 let k_b_t_nan = k_b_t != k_b_t;
1433 if k_b_t_nan || k_b_t <= zero || k_b_t < kbt_lo || k_b_t > kbt_hi {
1434 return Err(CalibrationError::ThermalEnergy);
1435 }
1436 #[allow(clippy::eq_op)]
1437 let tp_nan = thermal_power != thermal_power;
1438 if tp_nan || thermal_power <= zero || thermal_power > tp_hi {
1439 return Err(CalibrationError::ThermalPower);
1440 }
1441 #[allow(clippy::eq_op)]
1442 let ce_nan = characteristic_energy != characteristic_energy;
1443 if ce_nan || characteristic_energy <= zero || characteristic_energy > ce_hi {
1444 return Err(CalibrationError::CharacteristicEnergy);
1445 }
1446 Ok(Self {
1447 k_b_t,
1448 thermal_power,
1449 characteristic_energy,
1450 _phantom: core::marker::PhantomData,
1451 })
1452 }
1453
1454 #[inline]
1456 #[must_use]
1457 pub const fn k_b_t(&self) -> H::Decimal {
1458 self.k_b_t
1459 }
1460
1461 #[inline]
1463 #[must_use]
1464 pub const fn thermal_power(&self) -> H::Decimal {
1465 self.thermal_power
1466 }
1467
1468 #[inline]
1470 #[must_use]
1471 pub const fn characteristic_energy(&self) -> H::Decimal {
1472 self.characteristic_energy
1473 }
1474
1475 pub const ZERO_SENTINEL: Calibration<H> = Self {
1485 k_b_t: H::EMPTY_DECIMAL,
1486 thermal_power: H::EMPTY_DECIMAL,
1487 characteristic_energy: H::EMPTY_DECIMAL,
1488 _phantom: core::marker::PhantomData,
1489 };
1490}
1491
1492impl Calibration<crate::DefaultHostTypes> {
1493 #[inline]
1495 #[must_use]
1496 pub(crate) const fn from_f64_unchecked(
1497 k_b_t: <crate::DefaultHostTypes as crate::HostTypes>::Decimal,
1498 thermal_power: <crate::DefaultHostTypes as crate::HostTypes>::Decimal,
1499 characteristic_energy: <crate::DefaultHostTypes as crate::HostTypes>::Decimal,
1500 ) -> Self {
1501 Self {
1502 k_b_t,
1503 thermal_power,
1504 characteristic_energy,
1505 _phantom: core::marker::PhantomData,
1506 }
1507 }
1508}
1509
1510pub mod calibrations {
1514 use super::Calibration;
1515 use crate::DefaultHostTypes;
1516
1517 pub const X86_SERVER: Calibration<DefaultHostTypes> =
1521 Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 85.0, 1.0e-15);
1522
1523 pub const ARM_MOBILE: Calibration<DefaultHostTypes> =
1526 Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 5.0, 1.0e-16);
1527
1528 pub const CORTEX_M_EMBEDDED: Calibration<DefaultHostTypes> =
1531 Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 0.1, 1.0e-17);
1532
1533 pub const CONSERVATIVE_WORST_CASE: Calibration<DefaultHostTypes> =
1541 Calibration::<DefaultHostTypes>::from_f64_unchecked(4.14e-21, 1.0e9, 1.0);
1542}
1543
1544pub trait TimingPolicy {
1555 const PREFLIGHT_BUDGET_NS: u64;
1558 const RUNTIME_BUDGET_NS: u64;
1560 const CALIBRATION: &'static Calibration<crate::DefaultHostTypes>;
1563}
1564
1565#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
1570pub struct CanonicalTimingPolicy;
1571
1572impl TimingPolicy for CanonicalTimingPolicy {
1573 const PREFLIGHT_BUDGET_NS: u64 = 10_000_000;
1574 const RUNTIME_BUDGET_NS: u64 = 10_000_000;
1575 const CALIBRATION: &'static Calibration<crate::DefaultHostTypes> =
1576 &calibrations::CONSERVATIVE_WORST_CASE;
1577}
1578
1579pub mod transcendentals {
1590 use crate::DecimalTranscendental;
1591
1592 #[inline]
1595 #[must_use]
1596 pub fn ln<D: DecimalTranscendental>(x: D) -> D {
1597 x.ln()
1598 }
1599
1600 #[inline]
1602 #[must_use]
1603 pub fn exp<D: DecimalTranscendental>(x: D) -> D {
1604 x.exp()
1605 }
1606
1607 #[inline]
1609 #[must_use]
1610 pub fn sqrt<D: DecimalTranscendental>(x: D) -> D {
1611 x.sqrt()
1612 }
1613
1614 #[inline]
1617 #[must_use]
1618 pub fn entropy_term_nats<D: DecimalTranscendental>(p: D) -> D {
1619 let zero = <D as Default>::default();
1620 if p <= zero {
1621 zero
1622 } else {
1623 zero - p * p.ln()
1624 }
1625 }
1626}
1627
1628#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1630pub struct TermList {
1631 pub start: u32,
1633 pub len: u32,
1635}
1636
1637#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1665pub struct TermArena<const CAP: usize> {
1666 nodes: [Option<Term>; CAP],
1668 len: u32,
1670}
1671
1672impl<const CAP: usize> TermArena<CAP> {
1673 #[inline]
1675 #[must_use]
1676 pub const fn new() -> Self {
1677 Self {
1680 nodes: [None; CAP],
1681 len: 0,
1682 }
1683 }
1684
1685 #[must_use]
1689 pub fn push(&mut self, term: Term) -> Option<u32> {
1690 let idx = self.len;
1691 if (idx as usize) >= CAP {
1692 return None;
1693 }
1694 self.nodes[idx as usize] = Some(term);
1695 self.len = idx + 1;
1696 Some(idx)
1697 }
1698
1699 #[inline]
1701 #[must_use]
1702 pub fn get(&self, index: u32) -> Option<&Term> {
1703 self.nodes
1704 .get(index as usize)
1705 .and_then(|slot| slot.as_ref())
1706 }
1707
1708 #[inline]
1710 #[must_use]
1711 pub const fn len(&self) -> u32 {
1712 self.len
1713 }
1714
1715 #[inline]
1717 #[must_use]
1718 pub const fn is_empty(&self) -> bool {
1719 self.len == 0
1720 }
1721
1722 #[inline]
1727 #[must_use]
1728 pub fn as_slice(&self) -> &[Option<Term>] {
1729 &self.nodes[..self.len as usize]
1730 }
1731
1732 #[inline]
1744 #[must_use]
1745 pub const fn from_slice(slice: &'static [Term]) -> Self {
1746 let mut nodes: [Option<Term>; CAP] = [None; CAP];
1747 let mut i = 0usize;
1748 while i < slice.len() && i < CAP {
1749 nodes[i] = Some(slice[i]);
1750 i += 1;
1751 }
1752 #[allow(clippy::cast_possible_truncation)]
1756 let len = if slice.len() > CAP {
1757 CAP as u32
1758 } else {
1759 slice.len() as u32
1760 };
1761 Self { nodes, len }
1762 }
1763}
1764
1765impl<const CAP: usize> Default for TermArena<CAP> {
1766 fn default() -> Self {
1767 Self::new()
1768 }
1769}
1770
1771#[allow(clippy::large_enum_variant)]
1797#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1798pub enum Term {
1799 Literal {
1804 value: crate::pipeline::TermValue,
1808 level: WittLevel,
1810 },
1811 Variable {
1813 name_index: u32,
1815 },
1816 Application {
1818 operator: PrimitiveOp,
1820 args: TermList,
1822 },
1823 Lift {
1825 operand_index: u32,
1827 target: WittLevel,
1829 },
1830 Project {
1832 operand_index: u32,
1834 target: WittLevel,
1836 },
1837 Match {
1839 scrutinee_index: u32,
1841 arms: TermList,
1843 },
1844 Recurse {
1846 measure_index: u32,
1848 base_index: u32,
1850 step_index: u32,
1852 },
1853 Unfold {
1855 seed_index: u32,
1857 step_index: u32,
1859 },
1860 Try {
1862 body_index: u32,
1864 handler_index: u32,
1866 },
1867 AxisInvocation {
1875 axis_index: u32,
1877 kernel_id: u32,
1879 input_index: u32,
1881 },
1882 ProjectField {
1891 source_index: u32,
1893 byte_offset: u32,
1896 byte_length: u32,
1898 },
1899 FirstAdmit {
1911 domain_size_index: u32,
1914 predicate_index: u32,
1918 },
1919 Nerve {
1923 value_index: u32,
1926 },
1927 ChainComplex { simplicial_index: u32 },
1931 HomologyGroups { chain_index: u32 },
1936 Betti { homology_index: u32 },
1940 CochainComplex { chain_index: u32 },
1945 CohomologyGroups { cochain_index: u32 },
1950 PostnikovTower { simplicial_index: u32 },
1957 HomotopyGroups { postnikov_index: u32 },
1962 KInvariants { homotopy_index: u32 },
1967}
1968
1969#[must_use]
1977pub const fn shift_term(term: Term, offset: u32) -> Term {
1978 match term {
1979 Term::Literal { value, level } => Term::Literal { value, level },
1980 Term::Variable { name_index } => Term::Variable { name_index },
1982 Term::Application { operator, args } => Term::Application {
1983 operator,
1984 args: TermList {
1985 start: args.start + offset,
1986 len: args.len,
1987 },
1988 },
1989 Term::Lift {
1990 operand_index,
1991 target,
1992 } => Term::Lift {
1993 operand_index: operand_index + offset,
1994 target,
1995 },
1996 Term::Project {
1997 operand_index,
1998 target,
1999 } => Term::Project {
2000 operand_index: operand_index + offset,
2001 target,
2002 },
2003 Term::Match {
2004 scrutinee_index,
2005 arms,
2006 } => Term::Match {
2007 scrutinee_index: scrutinee_index + offset,
2008 arms: TermList {
2009 start: arms.start + offset,
2010 len: arms.len,
2011 },
2012 },
2013 Term::Recurse {
2014 measure_index,
2015 base_index,
2016 step_index,
2017 } => Term::Recurse {
2018 measure_index: measure_index + offset,
2019 base_index: base_index + offset,
2020 step_index: step_index + offset,
2021 },
2022 Term::Unfold {
2023 seed_index,
2024 step_index,
2025 } => Term::Unfold {
2026 seed_index: seed_index + offset,
2027 step_index: step_index + offset,
2028 },
2029 Term::Try {
2030 body_index,
2031 handler_index,
2032 } => Term::Try {
2033 body_index: body_index + offset,
2034 handler_index: if handler_index == u32::MAX {
2035 u32::MAX
2036 } else {
2037 handler_index + offset
2038 },
2039 },
2040 Term::AxisInvocation {
2041 axis_index,
2042 kernel_id,
2043 input_index,
2044 } => Term::AxisInvocation {
2045 axis_index,
2046 kernel_id,
2047 input_index: input_index + offset,
2048 },
2049 Term::ProjectField {
2050 source_index,
2051 byte_offset,
2052 byte_length,
2053 } => Term::ProjectField {
2054 source_index: source_index + offset,
2055 byte_offset,
2056 byte_length,
2057 },
2058 Term::FirstAdmit {
2059 domain_size_index,
2060 predicate_index,
2061 } => Term::FirstAdmit {
2062 domain_size_index: domain_size_index + offset,
2063 predicate_index: predicate_index + offset,
2064 },
2065 Term::Nerve { value_index } => Term::Nerve {
2066 value_index: value_index + offset,
2067 },
2068 Term::ChainComplex { simplicial_index } => Term::ChainComplex {
2069 simplicial_index: simplicial_index + offset,
2070 },
2071 Term::HomologyGroups { chain_index } => Term::HomologyGroups {
2072 chain_index: chain_index + offset,
2073 },
2074 Term::Betti { homology_index } => Term::Betti {
2075 homology_index: homology_index + offset,
2076 },
2077 Term::CochainComplex { chain_index } => Term::CochainComplex {
2078 chain_index: chain_index + offset,
2079 },
2080 Term::CohomologyGroups { cochain_index } => Term::CohomologyGroups {
2081 cochain_index: cochain_index + offset,
2082 },
2083 Term::PostnikovTower { simplicial_index } => Term::PostnikovTower {
2084 simplicial_index: simplicial_index + offset,
2085 },
2086 Term::HomotopyGroups { postnikov_index } => Term::HomotopyGroups {
2087 postnikov_index: postnikov_index + offset,
2088 },
2089 Term::KInvariants { homotopy_index } => Term::KInvariants {
2090 homotopy_index: homotopy_index + offset,
2091 },
2092 }
2093}
2094
2095#[must_use]
2111pub const fn inline_verb_fragment<const CAP: usize>(
2112 mut buf: [Term; CAP],
2113 mut len: usize,
2114 fragment: &[Term],
2115 arg_root_idx: u32,
2116) -> ([Term; CAP], usize) {
2117 let offset = len as u32;
2118 let arg_root_term = buf[arg_root_idx as usize];
2121 let mut i = 0;
2122 while i < fragment.len() {
2123 let term = fragment[i];
2124 let new_term = match term {
2125 Term::Variable { name_index: 0 } => arg_root_term,
2126 other => shift_term(other, offset),
2127 };
2128 buf[len] = new_term;
2129 len += 1;
2130 i += 1;
2131 }
2132 (buf, len)
2133}
2134
2135#[derive(Debug, Clone, PartialEq, Eq)]
2137pub struct TypeDeclaration {
2138 pub name_index: u32,
2140 pub constraints: TermList,
2142}
2143
2144#[derive(Debug, Clone, PartialEq, Eq)]
2146pub struct Binding {
2147 pub name_index: u32,
2149 pub type_index: u32,
2151 pub value_index: u32,
2153 pub surface: &'static str,
2155 pub content_address: u64,
2157}
2158
2159impl Binding {
2160 #[inline]
2165 #[must_use]
2166 pub const fn to_binding_entry(&self) -> BindingEntry {
2167 BindingEntry {
2168 address: ContentAddress::from_u64_fingerprint(self.content_address),
2169 bytes: self.surface.as_bytes(),
2170 }
2171 }
2172}
2173
2174#[derive(Debug, Clone, PartialEq, Eq)]
2176pub struct Assertion {
2177 pub lhs_index: u32,
2179 pub rhs_index: u32,
2181 pub surface: &'static str,
2183}
2184
2185#[derive(Debug, Clone, PartialEq, Eq)]
2187pub struct SourceDeclaration {
2188 pub name_index: u32,
2190 pub type_index: u32,
2192 pub grounding_name_index: u32,
2194}
2195
2196#[derive(Debug, Clone, PartialEq, Eq)]
2198pub struct SinkDeclaration {
2199 pub name_index: u32,
2201 pub type_index: u32,
2203 pub projection_name_index: u32,
2205}
2206
2207#[derive(Debug, Clone, PartialEq, Eq)]
2232pub struct ShapeViolation {
2233 pub shape_iri: &'static str,
2235 pub constraint_iri: &'static str,
2237 pub property_iri: &'static str,
2239 pub expected_range: &'static str,
2241 pub min_count: u32,
2243 pub max_count: u32,
2245 pub kind: ViolationKind,
2247}
2248
2249impl core::fmt::Display for ShapeViolation {
2250 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2251 write!(
2252 f,
2253 "shape violation: {} (constraint {}, property {}, kind {:?})",
2254 self.shape_iri, self.constraint_iri, self.property_iri, self.kind,
2255 )
2256 }
2257}
2258
2259impl core::error::Error for ShapeViolation {}
2260
2261impl ShapeViolation {
2262 #[inline]
2266 #[must_use]
2267 pub const fn const_message(&self) -> &'static str {
2268 self.shape_iri
2269 }
2270}
2271
2272#[derive(Debug, Clone)]
2310pub struct CompileUnitBuilder<'a> {
2311 root_term: Option<&'a [Term]>,
2313 bindings: Option<&'a [Binding]>,
2317 witt_level_ceiling: Option<WittLevel>,
2319 thermodynamic_budget: Option<u64>,
2321 target_domains: Option<&'a [VerificationDomain]>,
2323 result_type_iri: Option<&'static str>,
2329}
2330
2331#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2341pub struct CompileUnit<'a> {
2342 level: WittLevel,
2344 budget: u64,
2346 result_type_iri: &'static str,
2349 root_term: &'a [Term],
2354 bindings: &'a [Binding],
2358 target_domains: &'a [VerificationDomain],
2360}
2361
2362impl<'a> CompileUnit<'a> {
2363 #[inline]
2365 #[must_use]
2366 pub const fn witt_level(&self) -> WittLevel {
2367 self.level
2368 }
2369
2370 #[inline]
2372 #[must_use]
2373 pub const fn thermodynamic_budget(&self) -> u64 {
2374 self.budget
2375 }
2376
2377 #[inline]
2381 #[must_use]
2382 pub const fn result_type_iri(&self) -> &'static str {
2383 self.result_type_iri
2384 }
2385
2386 #[inline]
2389 #[must_use]
2390 pub const fn root_term(&self) -> &'a [Term] {
2391 self.root_term
2392 }
2393
2394 #[inline]
2398 #[must_use]
2399 pub const fn bindings(&self) -> &'a [Binding] {
2400 self.bindings
2401 }
2402
2403 #[inline]
2405 #[must_use]
2406 pub const fn target_domains(&self) -> &'a [VerificationDomain] {
2407 self.target_domains
2408 }
2409
2410 #[inline]
2416 #[must_use]
2417 pub(crate) const fn from_parts_const(
2418 level: WittLevel,
2419 budget: u64,
2420 result_type_iri: &'static str,
2421 root_term: &'a [Term],
2422 bindings: &'a [Binding],
2423 target_domains: &'a [VerificationDomain],
2424 ) -> Self {
2425 Self {
2426 level,
2427 budget,
2428 result_type_iri,
2429 root_term,
2430 bindings,
2431 target_domains,
2432 }
2433 }
2434}
2435
2436impl<'a> CompileUnitBuilder<'a> {
2437 #[must_use]
2439 pub const fn new() -> Self {
2440 Self {
2441 root_term: None,
2442 bindings: None,
2443 witt_level_ceiling: None,
2444 thermodynamic_budget: None,
2445 target_domains: None,
2446 result_type_iri: None,
2447 }
2448 }
2449
2450 #[must_use]
2452 pub const fn root_term(mut self, terms: &'a [Term]) -> Self {
2453 self.root_term = Some(terms);
2454 self
2455 }
2456
2457 #[must_use]
2462 pub const fn bindings(mut self, bindings: &'a [Binding]) -> Self {
2463 self.bindings = Some(bindings);
2464 self
2465 }
2466
2467 #[must_use]
2469 pub const fn witt_level_ceiling(mut self, level: WittLevel) -> Self {
2470 self.witt_level_ceiling = Some(level);
2471 self
2472 }
2473
2474 #[must_use]
2476 pub const fn thermodynamic_budget(mut self, budget: u64) -> Self {
2477 self.thermodynamic_budget = Some(budget);
2478 self
2479 }
2480
2481 #[must_use]
2483 pub const fn target_domains(mut self, domains: &'a [VerificationDomain]) -> Self {
2484 self.target_domains = Some(domains);
2485 self
2486 }
2487
2488 #[must_use]
2495 pub const fn result_type<T: crate::pipeline::ConstrainedTypeShape>(mut self) -> Self {
2496 self.result_type_iri = Some(T::IRI);
2497 self
2498 }
2499
2500 #[inline]
2503 #[must_use]
2504 pub const fn witt_level_option(&self) -> Option<WittLevel> {
2505 self.witt_level_ceiling
2506 }
2507
2508 #[inline]
2511 #[must_use]
2512 pub const fn budget_option(&self) -> Option<u64> {
2513 self.thermodynamic_budget
2514 }
2515
2516 #[inline]
2518 #[must_use]
2519 pub const fn has_root_term_const(&self) -> bool {
2520 self.root_term.is_some()
2521 }
2522
2523 #[inline]
2526 #[must_use]
2527 pub const fn has_target_domains_const(&self) -> bool {
2528 match self.target_domains {
2529 Some(d) => !d.is_empty(),
2530 None => false,
2531 }
2532 }
2533
2534 #[inline]
2537 #[must_use]
2538 pub const fn result_type_iri_const(&self) -> Option<&'static str> {
2539 self.result_type_iri
2540 }
2541
2542 #[inline]
2546 #[must_use]
2547 pub const fn root_term_slice_const(&self) -> &'a [Term] {
2548 match self.root_term {
2549 Some(terms) => terms,
2550 None => &[],
2551 }
2552 }
2553
2554 #[inline]
2558 #[must_use]
2559 pub const fn bindings_slice_const(&self) -> &'a [Binding] {
2560 match self.bindings {
2561 Some(bindings) => bindings,
2562 None => &[],
2563 }
2564 }
2565
2566 #[inline]
2569 #[must_use]
2570 pub const fn target_domains_slice_const(&self) -> &'a [VerificationDomain] {
2571 match self.target_domains {
2572 Some(d) => d,
2573 None => &[],
2574 }
2575 }
2576
2577 pub fn validate(self) -> Result<Validated<CompileUnit<'a>>, ShapeViolation> {
2583 let root_term = match self.root_term {
2584 Some(terms) => terms,
2585 None => {
2586 return Err(ShapeViolation {
2587 shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
2588 constraint_iri:
2589 "https://uor.foundation/conformance/compileUnit_rootTerm_constraint",
2590 property_iri: "https://uor.foundation/reduction/rootTerm",
2591 expected_range: "https://uor.foundation/schema/Term",
2592 min_count: 1,
2593 max_count: 1,
2594 kind: ViolationKind::Missing,
2595 })
2596 }
2597 };
2598 let level =
2599 match self.witt_level_ceiling {
2600 Some(l) => l,
2601 None => return Err(ShapeViolation {
2602 shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
2603 constraint_iri:
2604 "https://uor.foundation/conformance/compileUnit_unitWittLevel_constraint",
2605 property_iri: "https://uor.foundation/reduction/unitWittLevel",
2606 expected_range: "https://uor.foundation/schema/WittLevel",
2607 min_count: 1,
2608 max_count: 1,
2609 kind: ViolationKind::Missing,
2610 }),
2611 };
2612 let budget = match self.thermodynamic_budget {
2613 Some(b) => b,
2614 None => return Err(ShapeViolation {
2615 shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
2616 constraint_iri:
2617 "https://uor.foundation/conformance/compileUnit_thermodynamicBudget_constraint",
2618 property_iri: "https://uor.foundation/reduction/thermodynamicBudget",
2619 expected_range: "http://www.w3.org/2001/XMLSchema#decimal",
2620 min_count: 1,
2621 max_count: 1,
2622 kind: ViolationKind::Missing,
2623 }),
2624 };
2625 let target_domains =
2626 match self.target_domains {
2627 Some(d) if !d.is_empty() => d,
2628 _ => return Err(ShapeViolation {
2629 shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
2630 constraint_iri:
2631 "https://uor.foundation/conformance/compileUnit_targetDomains_constraint",
2632 property_iri: "https://uor.foundation/reduction/targetDomains",
2633 expected_range: "https://uor.foundation/op/VerificationDomain",
2634 min_count: 1,
2635 max_count: 0,
2636 kind: ViolationKind::Missing,
2637 }),
2638 };
2639 let result_type_iri = match self.result_type_iri {
2640 Some(iri) => iri,
2641 None => {
2642 return Err(ShapeViolation {
2643 shape_iri: "https://uor.foundation/conformance/CompileUnitShape",
2644 constraint_iri:
2645 "https://uor.foundation/conformance/compileUnit_resultType_constraint",
2646 property_iri: "https://uor.foundation/reduction/resultType",
2647 expected_range: "https://uor.foundation/type/ConstrainedType",
2648 min_count: 1,
2649 max_count: 1,
2650 kind: ViolationKind::Missing,
2651 })
2652 }
2653 };
2654 let bindings: &'a [Binding] = match self.bindings {
2656 Some(b) => b,
2657 None => &[],
2658 };
2659 Ok(Validated::new(CompileUnit {
2660 level,
2661 budget,
2662 result_type_iri,
2663 root_term,
2664 bindings,
2665 target_domains,
2666 }))
2667 }
2668}
2669
2670impl<'a> Default for CompileUnitBuilder<'a> {
2671 fn default() -> Self {
2672 Self::new()
2673 }
2674}
2675
2676#[derive(Debug, Clone)]
2678pub struct EffectDeclarationBuilder<'a> {
2679 name: Option<&'a str>,
2681 target_sites: Option<&'a [u32]>,
2683 budget_delta: Option<i64>,
2685 commutes: Option<bool>,
2687}
2688
2689#[derive(Debug, Clone, PartialEq, Eq)]
2691pub struct EffectDeclaration {
2692 pub shape_iri: &'static str,
2694}
2695
2696impl EffectDeclaration {
2697 #[inline]
2700 #[must_use]
2701 #[allow(dead_code)]
2702 pub(crate) const fn empty_const() -> Self {
2703 Self {
2704 shape_iri: "https://uor.foundation/conformance/EffectShape",
2705 }
2706 }
2707}
2708
2709impl<'a> EffectDeclarationBuilder<'a> {
2710 #[must_use]
2712 pub const fn new() -> Self {
2713 Self {
2714 name: None,
2715 target_sites: None,
2716 budget_delta: None,
2717 commutes: None,
2718 }
2719 }
2720
2721 #[must_use]
2723 pub const fn name(mut self, value: &'a str) -> Self {
2724 self.name = Some(value);
2725 self
2726 }
2727
2728 #[must_use]
2730 pub const fn target_sites(mut self, value: &'a [u32]) -> Self {
2731 self.target_sites = Some(value);
2732 self
2733 }
2734
2735 #[must_use]
2737 pub const fn budget_delta(mut self, value: i64) -> Self {
2738 self.budget_delta = Some(value);
2739 self
2740 }
2741
2742 #[must_use]
2744 pub const fn commutes(mut self, value: bool) -> Self {
2745 self.commutes = Some(value);
2746 self
2747 }
2748
2749 pub fn validate(self) -> Result<Validated<EffectDeclaration>, ShapeViolation> {
2753 if self.name.is_none() {
2754 return Err(ShapeViolation {
2755 shape_iri: "https://uor.foundation/conformance/EffectShape",
2756 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2757 property_iri: "https://uor.foundation/conformance/name",
2758 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2759 min_count: 1,
2760 max_count: 1,
2761 kind: ViolationKind::Missing,
2762 });
2763 }
2764 if self.target_sites.is_none() {
2765 return Err(ShapeViolation {
2766 shape_iri: "https://uor.foundation/conformance/EffectShape",
2767 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2768 property_iri: "https://uor.foundation/conformance/target_sites",
2769 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2770 min_count: 1,
2771 max_count: 1,
2772 kind: ViolationKind::Missing,
2773 });
2774 }
2775 if self.budget_delta.is_none() {
2776 return Err(ShapeViolation {
2777 shape_iri: "https://uor.foundation/conformance/EffectShape",
2778 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2779 property_iri: "https://uor.foundation/conformance/budget_delta",
2780 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2781 min_count: 1,
2782 max_count: 1,
2783 kind: ViolationKind::Missing,
2784 });
2785 }
2786 if self.commutes.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/commutes",
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 Ok(Validated::new(EffectDeclaration {
2798 shape_iri: "https://uor.foundation/conformance/EffectShape",
2799 }))
2800 }
2801
2802 pub const fn validate_const(
2808 &self,
2809 ) -> Result<Validated<EffectDeclaration, CompileTime>, ShapeViolation> {
2810 if self.name.is_none() {
2811 return Err(ShapeViolation {
2812 shape_iri: "https://uor.foundation/conformance/EffectShape",
2813 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2814 property_iri: "https://uor.foundation/conformance/name",
2815 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2816 min_count: 1,
2817 max_count: 1,
2818 kind: ViolationKind::Missing,
2819 });
2820 }
2821 if self.target_sites.is_none() {
2822 return Err(ShapeViolation {
2823 shape_iri: "https://uor.foundation/conformance/EffectShape",
2824 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2825 property_iri: "https://uor.foundation/conformance/target_sites",
2826 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2827 min_count: 1,
2828 max_count: 1,
2829 kind: ViolationKind::Missing,
2830 });
2831 }
2832 if self.budget_delta.is_none() {
2833 return Err(ShapeViolation {
2834 shape_iri: "https://uor.foundation/conformance/EffectShape",
2835 constraint_iri: "https://uor.foundation/conformance/EffectShape",
2836 property_iri: "https://uor.foundation/conformance/budget_delta",
2837 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2838 min_count: 1,
2839 max_count: 1,
2840 kind: ViolationKind::Missing,
2841 });
2842 }
2843 if self.commutes.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/commutes",
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 Ok(Validated::new(EffectDeclaration {
2855 shape_iri: "https://uor.foundation/conformance/EffectShape",
2856 }))
2857 }
2858}
2859
2860impl<'a> Default for EffectDeclarationBuilder<'a> {
2861 fn default() -> Self {
2862 Self::new()
2863 }
2864}
2865
2866#[derive(Debug, Clone)]
2868pub struct GroundingDeclarationBuilder<'a> {
2869 source_type: Option<&'a str>,
2871 ring_mapping: Option<&'a str>,
2873 invertibility: Option<bool>,
2875}
2876
2877#[derive(Debug, Clone, PartialEq, Eq)]
2879pub struct GroundingDeclaration {
2880 pub shape_iri: &'static str,
2882}
2883
2884impl GroundingDeclaration {
2885 #[inline]
2888 #[must_use]
2889 #[allow(dead_code)]
2890 pub(crate) const fn empty_const() -> Self {
2891 Self {
2892 shape_iri: "https://uor.foundation/conformance/GroundingShape",
2893 }
2894 }
2895}
2896
2897impl<'a> GroundingDeclarationBuilder<'a> {
2898 #[must_use]
2900 pub const fn new() -> Self {
2901 Self {
2902 source_type: None,
2903 ring_mapping: None,
2904 invertibility: None,
2905 }
2906 }
2907
2908 #[must_use]
2910 pub const fn source_type(mut self, value: &'a str) -> Self {
2911 self.source_type = Some(value);
2912 self
2913 }
2914
2915 #[must_use]
2917 pub const fn ring_mapping(mut self, value: &'a str) -> Self {
2918 self.ring_mapping = Some(value);
2919 self
2920 }
2921
2922 #[must_use]
2924 pub const fn invertibility(mut self, value: bool) -> Self {
2925 self.invertibility = Some(value);
2926 self
2927 }
2928
2929 pub fn validate(self) -> Result<Validated<GroundingDeclaration>, ShapeViolation> {
2933 if self.source_type.is_none() {
2934 return Err(ShapeViolation {
2935 shape_iri: "https://uor.foundation/conformance/GroundingShape",
2936 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
2937 property_iri: "https://uor.foundation/conformance/source_type",
2938 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2939 min_count: 1,
2940 max_count: 1,
2941 kind: ViolationKind::Missing,
2942 });
2943 }
2944 if self.ring_mapping.is_none() {
2945 return Err(ShapeViolation {
2946 shape_iri: "https://uor.foundation/conformance/GroundingShape",
2947 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
2948 property_iri: "https://uor.foundation/conformance/ring_mapping",
2949 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2950 min_count: 1,
2951 max_count: 1,
2952 kind: ViolationKind::Missing,
2953 });
2954 }
2955 if self.invertibility.is_none() {
2956 return Err(ShapeViolation {
2957 shape_iri: "https://uor.foundation/conformance/GroundingShape",
2958 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
2959 property_iri: "https://uor.foundation/conformance/invertibility",
2960 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2961 min_count: 1,
2962 max_count: 1,
2963 kind: ViolationKind::Missing,
2964 });
2965 }
2966 Ok(Validated::new(GroundingDeclaration {
2967 shape_iri: "https://uor.foundation/conformance/GroundingShape",
2968 }))
2969 }
2970
2971 pub const fn validate_const(
2977 &self,
2978 ) -> Result<Validated<GroundingDeclaration, CompileTime>, ShapeViolation> {
2979 if self.source_type.is_none() {
2980 return Err(ShapeViolation {
2981 shape_iri: "https://uor.foundation/conformance/GroundingShape",
2982 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
2983 property_iri: "https://uor.foundation/conformance/source_type",
2984 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2985 min_count: 1,
2986 max_count: 1,
2987 kind: ViolationKind::Missing,
2988 });
2989 }
2990 if self.ring_mapping.is_none() {
2991 return Err(ShapeViolation {
2992 shape_iri: "https://uor.foundation/conformance/GroundingShape",
2993 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
2994 property_iri: "https://uor.foundation/conformance/ring_mapping",
2995 expected_range: "http://www.w3.org/2002/07/owl#Thing",
2996 min_count: 1,
2997 max_count: 1,
2998 kind: ViolationKind::Missing,
2999 });
3000 }
3001 if self.invertibility.is_none() {
3002 return Err(ShapeViolation {
3003 shape_iri: "https://uor.foundation/conformance/GroundingShape",
3004 constraint_iri: "https://uor.foundation/conformance/GroundingShape",
3005 property_iri: "https://uor.foundation/conformance/invertibility",
3006 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3007 min_count: 1,
3008 max_count: 1,
3009 kind: ViolationKind::Missing,
3010 });
3011 }
3012 Ok(Validated::new(GroundingDeclaration {
3013 shape_iri: "https://uor.foundation/conformance/GroundingShape",
3014 }))
3015 }
3016}
3017
3018impl<'a> Default for GroundingDeclarationBuilder<'a> {
3019 fn default() -> Self {
3020 Self::new()
3021 }
3022}
3023
3024#[derive(Debug, Clone)]
3026pub struct DispatchDeclarationBuilder<'a> {
3027 predicate: Option<&'a [Term]>,
3029 target_resolver: Option<&'a str>,
3031 priority: Option<u32>,
3033}
3034
3035#[derive(Debug, Clone, PartialEq, Eq)]
3037pub struct DispatchDeclaration {
3038 pub shape_iri: &'static str,
3040}
3041
3042impl DispatchDeclaration {
3043 #[inline]
3046 #[must_use]
3047 #[allow(dead_code)]
3048 pub(crate) const fn empty_const() -> Self {
3049 Self {
3050 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3051 }
3052 }
3053}
3054
3055impl<'a> DispatchDeclarationBuilder<'a> {
3056 #[must_use]
3058 pub const fn new() -> Self {
3059 Self {
3060 predicate: None,
3061 target_resolver: None,
3062 priority: None,
3063 }
3064 }
3065
3066 #[must_use]
3068 pub const fn predicate(mut self, value: &'a [Term]) -> Self {
3069 self.predicate = Some(value);
3070 self
3071 }
3072
3073 #[must_use]
3075 pub const fn target_resolver(mut self, value: &'a str) -> Self {
3076 self.target_resolver = Some(value);
3077 self
3078 }
3079
3080 #[must_use]
3082 pub const fn priority(mut self, value: u32) -> Self {
3083 self.priority = Some(value);
3084 self
3085 }
3086
3087 pub fn validate(self) -> Result<Validated<DispatchDeclaration>, ShapeViolation> {
3091 if self.predicate.is_none() {
3092 return Err(ShapeViolation {
3093 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3094 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3095 property_iri: "https://uor.foundation/conformance/predicate",
3096 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3097 min_count: 1,
3098 max_count: 1,
3099 kind: ViolationKind::Missing,
3100 });
3101 }
3102 if self.target_resolver.is_none() {
3103 return Err(ShapeViolation {
3104 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3105 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3106 property_iri: "https://uor.foundation/conformance/target_resolver",
3107 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3108 min_count: 1,
3109 max_count: 1,
3110 kind: ViolationKind::Missing,
3111 });
3112 }
3113 if self.priority.is_none() {
3114 return Err(ShapeViolation {
3115 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3116 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3117 property_iri: "https://uor.foundation/conformance/priority",
3118 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3119 min_count: 1,
3120 max_count: 1,
3121 kind: ViolationKind::Missing,
3122 });
3123 }
3124 Ok(Validated::new(DispatchDeclaration {
3125 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3126 }))
3127 }
3128
3129 pub const fn validate_const(
3135 &self,
3136 ) -> Result<Validated<DispatchDeclaration, CompileTime>, ShapeViolation> {
3137 if self.predicate.is_none() {
3138 return Err(ShapeViolation {
3139 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3140 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3141 property_iri: "https://uor.foundation/conformance/predicate",
3142 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3143 min_count: 1,
3144 max_count: 1,
3145 kind: ViolationKind::Missing,
3146 });
3147 }
3148 if self.target_resolver.is_none() {
3149 return Err(ShapeViolation {
3150 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3151 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3152 property_iri: "https://uor.foundation/conformance/target_resolver",
3153 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3154 min_count: 1,
3155 max_count: 1,
3156 kind: ViolationKind::Missing,
3157 });
3158 }
3159 if self.priority.is_none() {
3160 return Err(ShapeViolation {
3161 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3162 constraint_iri: "https://uor.foundation/conformance/DispatchShape",
3163 property_iri: "https://uor.foundation/conformance/priority",
3164 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3165 min_count: 1,
3166 max_count: 1,
3167 kind: ViolationKind::Missing,
3168 });
3169 }
3170 Ok(Validated::new(DispatchDeclaration {
3171 shape_iri: "https://uor.foundation/conformance/DispatchShape",
3172 }))
3173 }
3174}
3175
3176impl<'a> Default for DispatchDeclarationBuilder<'a> {
3177 fn default() -> Self {
3178 Self::new()
3179 }
3180}
3181
3182#[derive(Debug, Clone)]
3184pub struct LeaseDeclarationBuilder<'a> {
3185 linear_site: Option<u32>,
3187 scope: Option<&'a str>,
3189}
3190
3191#[derive(Debug, Clone, PartialEq, Eq)]
3193pub struct LeaseDeclaration {
3194 pub shape_iri: &'static str,
3196}
3197
3198impl LeaseDeclaration {
3199 #[inline]
3202 #[must_use]
3203 #[allow(dead_code)]
3204 pub(crate) const fn empty_const() -> Self {
3205 Self {
3206 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3207 }
3208 }
3209}
3210
3211impl<'a> LeaseDeclarationBuilder<'a> {
3212 #[must_use]
3214 pub const fn new() -> Self {
3215 Self {
3216 linear_site: None,
3217 scope: None,
3218 }
3219 }
3220
3221 #[must_use]
3223 pub const fn linear_site(mut self, value: u32) -> Self {
3224 self.linear_site = Some(value);
3225 self
3226 }
3227
3228 #[must_use]
3230 pub const fn scope(mut self, value: &'a str) -> Self {
3231 self.scope = Some(value);
3232 self
3233 }
3234
3235 pub fn validate(self) -> Result<Validated<LeaseDeclaration>, ShapeViolation> {
3239 if self.linear_site.is_none() {
3240 return Err(ShapeViolation {
3241 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3242 constraint_iri: "https://uor.foundation/conformance/LeaseShape",
3243 property_iri: "https://uor.foundation/conformance/linear_site",
3244 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3245 min_count: 1,
3246 max_count: 1,
3247 kind: ViolationKind::Missing,
3248 });
3249 }
3250 if self.scope.is_none() {
3251 return Err(ShapeViolation {
3252 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3253 constraint_iri: "https://uor.foundation/conformance/LeaseShape",
3254 property_iri: "https://uor.foundation/conformance/scope",
3255 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3256 min_count: 1,
3257 max_count: 1,
3258 kind: ViolationKind::Missing,
3259 });
3260 }
3261 Ok(Validated::new(LeaseDeclaration {
3262 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3263 }))
3264 }
3265
3266 pub const fn validate_const(
3272 &self,
3273 ) -> Result<Validated<LeaseDeclaration, CompileTime>, ShapeViolation> {
3274 if self.linear_site.is_none() {
3275 return Err(ShapeViolation {
3276 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3277 constraint_iri: "https://uor.foundation/conformance/LeaseShape",
3278 property_iri: "https://uor.foundation/conformance/linear_site",
3279 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3280 min_count: 1,
3281 max_count: 1,
3282 kind: ViolationKind::Missing,
3283 });
3284 }
3285 if self.scope.is_none() {
3286 return Err(ShapeViolation {
3287 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3288 constraint_iri: "https://uor.foundation/conformance/LeaseShape",
3289 property_iri: "https://uor.foundation/conformance/scope",
3290 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3291 min_count: 1,
3292 max_count: 1,
3293 kind: ViolationKind::Missing,
3294 });
3295 }
3296 Ok(Validated::new(LeaseDeclaration {
3297 shape_iri: "https://uor.foundation/conformance/LeaseShape",
3298 }))
3299 }
3300}
3301
3302impl<'a> Default for LeaseDeclarationBuilder<'a> {
3303 fn default() -> Self {
3304 Self::new()
3305 }
3306}
3307
3308#[derive(Debug, Clone)]
3310pub struct StreamDeclarationBuilder<'a> {
3311 seed: Option<&'a [Term]>,
3313 step: Option<&'a [Term]>,
3315 productivity_witness: Option<&'a str>,
3317}
3318
3319#[derive(Debug, Clone, PartialEq, Eq)]
3321pub struct StreamDeclaration {
3322 pub shape_iri: &'static str,
3324}
3325
3326impl StreamDeclaration {
3327 #[inline]
3330 #[must_use]
3331 #[allow(dead_code)]
3332 pub(crate) const fn empty_const() -> Self {
3333 Self {
3334 shape_iri: "https://uor.foundation/conformance/StreamShape",
3335 }
3336 }
3337}
3338
3339impl<'a> StreamDeclarationBuilder<'a> {
3340 #[must_use]
3342 pub const fn new() -> Self {
3343 Self {
3344 seed: None,
3345 step: None,
3346 productivity_witness: None,
3347 }
3348 }
3349
3350 #[must_use]
3352 pub const fn seed(mut self, value: &'a [Term]) -> Self {
3353 self.seed = Some(value);
3354 self
3355 }
3356
3357 #[must_use]
3359 pub const fn step(mut self, value: &'a [Term]) -> Self {
3360 self.step = Some(value);
3361 self
3362 }
3363
3364 #[must_use]
3366 pub const fn productivity_witness(mut self, value: &'a str) -> Self {
3367 self.productivity_witness = Some(value);
3368 self
3369 }
3370
3371 pub fn validate(self) -> Result<Validated<StreamDeclaration>, ShapeViolation> {
3375 if self.seed.is_none() {
3376 return Err(ShapeViolation {
3377 shape_iri: "https://uor.foundation/conformance/StreamShape",
3378 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3379 property_iri: "https://uor.foundation/conformance/seed",
3380 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3381 min_count: 1,
3382 max_count: 1,
3383 kind: ViolationKind::Missing,
3384 });
3385 }
3386 if self.step.is_none() {
3387 return Err(ShapeViolation {
3388 shape_iri: "https://uor.foundation/conformance/StreamShape",
3389 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3390 property_iri: "https://uor.foundation/conformance/step",
3391 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3392 min_count: 1,
3393 max_count: 1,
3394 kind: ViolationKind::Missing,
3395 });
3396 }
3397 if self.productivity_witness.is_none() {
3398 return Err(ShapeViolation {
3399 shape_iri: "https://uor.foundation/conformance/StreamShape",
3400 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3401 property_iri: "https://uor.foundation/conformance/productivity_witness",
3402 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3403 min_count: 1,
3404 max_count: 1,
3405 kind: ViolationKind::Missing,
3406 });
3407 }
3408 Ok(Validated::new(StreamDeclaration {
3409 shape_iri: "https://uor.foundation/conformance/StreamShape",
3410 }))
3411 }
3412
3413 pub const fn validate_const(
3419 &self,
3420 ) -> Result<Validated<StreamDeclaration, CompileTime>, ShapeViolation> {
3421 if self.seed.is_none() {
3422 return Err(ShapeViolation {
3423 shape_iri: "https://uor.foundation/conformance/StreamShape",
3424 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3425 property_iri: "https://uor.foundation/conformance/seed",
3426 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3427 min_count: 1,
3428 max_count: 1,
3429 kind: ViolationKind::Missing,
3430 });
3431 }
3432 if self.step.is_none() {
3433 return Err(ShapeViolation {
3434 shape_iri: "https://uor.foundation/conformance/StreamShape",
3435 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3436 property_iri: "https://uor.foundation/conformance/step",
3437 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3438 min_count: 1,
3439 max_count: 1,
3440 kind: ViolationKind::Missing,
3441 });
3442 }
3443 if self.productivity_witness.is_none() {
3444 return Err(ShapeViolation {
3445 shape_iri: "https://uor.foundation/conformance/StreamShape",
3446 constraint_iri: "https://uor.foundation/conformance/StreamShape",
3447 property_iri: "https://uor.foundation/conformance/productivity_witness",
3448 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3449 min_count: 1,
3450 max_count: 1,
3451 kind: ViolationKind::Missing,
3452 });
3453 }
3454 Ok(Validated::new(StreamDeclaration {
3455 shape_iri: "https://uor.foundation/conformance/StreamShape",
3456 }))
3457 }
3458}
3459
3460impl<'a> Default for StreamDeclarationBuilder<'a> {
3461 fn default() -> Self {
3462 Self::new()
3463 }
3464}
3465
3466#[derive(Debug, Clone)]
3468pub struct PredicateDeclarationBuilder<'a> {
3469 input_type: Option<&'a str>,
3471 evaluator: Option<&'a [Term]>,
3473 termination_witness: Option<&'a str>,
3475}
3476
3477#[derive(Debug, Clone, PartialEq, Eq)]
3479pub struct PredicateDeclaration {
3480 pub shape_iri: &'static str,
3482}
3483
3484impl PredicateDeclaration {
3485 #[inline]
3488 #[must_use]
3489 #[allow(dead_code)]
3490 pub(crate) const fn empty_const() -> Self {
3491 Self {
3492 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3493 }
3494 }
3495}
3496
3497impl<'a> PredicateDeclarationBuilder<'a> {
3498 #[must_use]
3500 pub const fn new() -> Self {
3501 Self {
3502 input_type: None,
3503 evaluator: None,
3504 termination_witness: None,
3505 }
3506 }
3507
3508 #[must_use]
3510 pub const fn input_type(mut self, value: &'a str) -> Self {
3511 self.input_type = Some(value);
3512 self
3513 }
3514
3515 #[must_use]
3517 pub const fn evaluator(mut self, value: &'a [Term]) -> Self {
3518 self.evaluator = Some(value);
3519 self
3520 }
3521
3522 #[must_use]
3524 pub const fn termination_witness(mut self, value: &'a str) -> Self {
3525 self.termination_witness = Some(value);
3526 self
3527 }
3528
3529 pub fn validate(self) -> Result<Validated<PredicateDeclaration>, ShapeViolation> {
3533 if self.input_type.is_none() {
3534 return Err(ShapeViolation {
3535 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3536 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3537 property_iri: "https://uor.foundation/conformance/input_type",
3538 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3539 min_count: 1,
3540 max_count: 1,
3541 kind: ViolationKind::Missing,
3542 });
3543 }
3544 if self.evaluator.is_none() {
3545 return Err(ShapeViolation {
3546 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3547 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3548 property_iri: "https://uor.foundation/conformance/evaluator",
3549 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3550 min_count: 1,
3551 max_count: 1,
3552 kind: ViolationKind::Missing,
3553 });
3554 }
3555 if self.termination_witness.is_none() {
3556 return Err(ShapeViolation {
3557 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3558 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3559 property_iri: "https://uor.foundation/conformance/termination_witness",
3560 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3561 min_count: 1,
3562 max_count: 1,
3563 kind: ViolationKind::Missing,
3564 });
3565 }
3566 Ok(Validated::new(PredicateDeclaration {
3567 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3568 }))
3569 }
3570
3571 pub const fn validate_const(
3577 &self,
3578 ) -> Result<Validated<PredicateDeclaration, CompileTime>, ShapeViolation> {
3579 if self.input_type.is_none() {
3580 return Err(ShapeViolation {
3581 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3582 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3583 property_iri: "https://uor.foundation/conformance/input_type",
3584 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3585 min_count: 1,
3586 max_count: 1,
3587 kind: ViolationKind::Missing,
3588 });
3589 }
3590 if self.evaluator.is_none() {
3591 return Err(ShapeViolation {
3592 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3593 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3594 property_iri: "https://uor.foundation/conformance/evaluator",
3595 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3596 min_count: 1,
3597 max_count: 1,
3598 kind: ViolationKind::Missing,
3599 });
3600 }
3601 if self.termination_witness.is_none() {
3602 return Err(ShapeViolation {
3603 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3604 constraint_iri: "https://uor.foundation/conformance/PredicateShape",
3605 property_iri: "https://uor.foundation/conformance/termination_witness",
3606 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3607 min_count: 1,
3608 max_count: 1,
3609 kind: ViolationKind::Missing,
3610 });
3611 }
3612 Ok(Validated::new(PredicateDeclaration {
3613 shape_iri: "https://uor.foundation/conformance/PredicateShape",
3614 }))
3615 }
3616}
3617
3618impl<'a> Default for PredicateDeclarationBuilder<'a> {
3619 fn default() -> Self {
3620 Self::new()
3621 }
3622}
3623
3624#[derive(Debug, Clone)]
3626pub struct ParallelDeclarationBuilder<'a> {
3627 site_partition: Option<&'a [u32]>,
3629 disjointness_witness: Option<&'a str>,
3631}
3632
3633#[derive(Debug, Clone, PartialEq, Eq)]
3635pub struct ParallelDeclaration {
3636 pub shape_iri: &'static str,
3638}
3639
3640impl ParallelDeclaration {
3641 #[inline]
3644 #[must_use]
3645 #[allow(dead_code)]
3646 pub(crate) const fn empty_const() -> Self {
3647 Self {
3648 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3649 }
3650 }
3651}
3652
3653impl<'a> ParallelDeclarationBuilder<'a> {
3654 #[must_use]
3656 pub const fn new() -> Self {
3657 Self {
3658 site_partition: None,
3659 disjointness_witness: None,
3660 }
3661 }
3662
3663 #[must_use]
3665 pub const fn site_partition(mut self, value: &'a [u32]) -> Self {
3666 self.site_partition = Some(value);
3667 self
3668 }
3669
3670 #[must_use]
3672 pub const fn disjointness_witness(mut self, value: &'a str) -> Self {
3673 self.disjointness_witness = Some(value);
3674 self
3675 }
3676
3677 pub fn validate(self) -> Result<Validated<ParallelDeclaration>, ShapeViolation> {
3681 if self.site_partition.is_none() {
3682 return Err(ShapeViolation {
3683 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3684 constraint_iri: "https://uor.foundation/conformance/ParallelShape",
3685 property_iri: "https://uor.foundation/conformance/site_partition",
3686 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3687 min_count: 1,
3688 max_count: 1,
3689 kind: ViolationKind::Missing,
3690 });
3691 }
3692 if self.disjointness_witness.is_none() {
3693 return Err(ShapeViolation {
3694 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3695 constraint_iri: "https://uor.foundation/conformance/ParallelShape",
3696 property_iri: "https://uor.foundation/conformance/disjointness_witness",
3697 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3698 min_count: 1,
3699 max_count: 1,
3700 kind: ViolationKind::Missing,
3701 });
3702 }
3703 Ok(Validated::new(ParallelDeclaration {
3704 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3705 }))
3706 }
3707
3708 pub const fn validate_const(
3714 &self,
3715 ) -> Result<Validated<ParallelDeclaration, CompileTime>, ShapeViolation> {
3716 if self.site_partition.is_none() {
3717 return Err(ShapeViolation {
3718 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3719 constraint_iri: "https://uor.foundation/conformance/ParallelShape",
3720 property_iri: "https://uor.foundation/conformance/site_partition",
3721 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3722 min_count: 1,
3723 max_count: 1,
3724 kind: ViolationKind::Missing,
3725 });
3726 }
3727 if self.disjointness_witness.is_none() {
3728 return Err(ShapeViolation {
3729 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3730 constraint_iri: "https://uor.foundation/conformance/ParallelShape",
3731 property_iri: "https://uor.foundation/conformance/disjointness_witness",
3732 expected_range: "http://www.w3.org/2002/07/owl#Thing",
3733 min_count: 1,
3734 max_count: 1,
3735 kind: ViolationKind::Missing,
3736 });
3737 }
3738 Ok(Validated::new(ParallelDeclaration {
3739 shape_iri: "https://uor.foundation/conformance/ParallelShape",
3740 }))
3741 }
3742}
3743
3744impl<'a> Default for ParallelDeclarationBuilder<'a> {
3745 fn default() -> Self {
3746 Self::new()
3747 }
3748}
3749
3750impl<'a> ParallelDeclarationBuilder<'a> {
3751 #[inline]
3754 #[must_use]
3755 pub const fn site_partition_len(&self) -> usize {
3756 match self.site_partition {
3757 Some(p) => p.len(),
3758 None => 0,
3759 }
3760 }
3761
3762 #[inline]
3766 #[must_use]
3767 pub const fn site_partition_slice_const(&self) -> &'a [u32] {
3768 match self.site_partition {
3769 Some(p) => p,
3770 None => &[],
3771 }
3772 }
3773
3774 #[inline]
3777 #[must_use]
3778 pub const fn disjointness_witness_const(&self) -> &'a str {
3779 match self.disjointness_witness {
3780 Some(s) => s,
3781 None => "",
3782 }
3783 }
3784}
3785
3786impl<'a> StreamDeclarationBuilder<'a> {
3787 #[inline]
3794 #[must_use]
3795 pub const fn productivity_bound_const(&self) -> u64 {
3796 match self.productivity_witness {
3797 Some(_) => 1,
3798 None => 0,
3799 }
3800 }
3801
3802 #[inline]
3805 #[must_use]
3806 pub const fn seed_slice_const(&self) -> &'a [Term] {
3807 match self.seed {
3808 Some(t) => t,
3809 None => &[],
3810 }
3811 }
3812
3813 #[inline]
3816 #[must_use]
3817 pub const fn step_slice_const(&self) -> &'a [Term] {
3818 match self.step {
3819 Some(t) => t,
3820 None => &[],
3821 }
3822 }
3823
3824 #[inline]
3827 #[must_use]
3828 pub const fn productivity_witness_const(&self) -> &'a str {
3829 match self.productivity_witness {
3830 Some(s) => s,
3831 None => "",
3832 }
3833 }
3834}
3835
3836#[derive(Debug, Clone)]
3839pub struct WittLevelDeclarationBuilder {
3840 bit_width: Option<u32>,
3842 cycle_size: Option<u128>,
3844 predecessor: Option<WittLevel>,
3846}
3847
3848#[derive(Debug, Clone, PartialEq, Eq)]
3850pub struct WittLevelDeclaration {
3851 pub bit_width: u32,
3853 pub predecessor: WittLevel,
3855}
3856
3857impl WittLevelDeclarationBuilder {
3858 #[must_use]
3860 pub const fn new() -> Self {
3861 Self {
3862 bit_width: None,
3863 cycle_size: None,
3864 predecessor: None,
3865 }
3866 }
3867
3868 #[must_use]
3870 pub const fn bit_width(mut self, w: u32) -> Self {
3871 self.bit_width = Some(w);
3872 self
3873 }
3874
3875 #[must_use]
3877 pub const fn cycle_size(mut self, s: u128) -> Self {
3878 self.cycle_size = Some(s);
3879 self
3880 }
3881
3882 #[must_use]
3884 pub const fn predecessor(mut self, level: WittLevel) -> Self {
3885 self.predecessor = Some(level);
3886 self
3887 }
3888
3889 pub fn validate(self) -> Result<Validated<WittLevelDeclaration>, ShapeViolation> {
3893 let bw = match self.bit_width {
3894 Some(w) => w,
3895 None => {
3896 return Err(ShapeViolation {
3897 shape_iri: "https://uor.foundation/conformance/WittLevelShape",
3898 constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
3899 property_iri: "https://uor.foundation/conformance/declaredBitWidth",
3900 expected_range: "http://www.w3.org/2001/XMLSchema#positiveInteger",
3901 min_count: 1,
3902 max_count: 1,
3903 kind: ViolationKind::Missing,
3904 })
3905 }
3906 };
3907 let pred = match self.predecessor {
3908 Some(p) => p,
3909 None => {
3910 return Err(ShapeViolation {
3911 shape_iri: "https://uor.foundation/conformance/WittLevelShape",
3912 constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
3913 property_iri: "https://uor.foundation/conformance/predecessorLevel",
3914 expected_range: "https://uor.foundation/schema/WittLevel",
3915 min_count: 1,
3916 max_count: 1,
3917 kind: ViolationKind::Missing,
3918 })
3919 }
3920 };
3921 Ok(Validated::new(WittLevelDeclaration {
3922 bit_width: bw,
3923 predecessor: pred,
3924 }))
3925 }
3926
3927 pub const fn validate_const(
3931 &self,
3932 ) -> Result<Validated<WittLevelDeclaration, CompileTime>, ShapeViolation> {
3933 let bw = match self.bit_width {
3934 Some(w) => w,
3935 None => {
3936 return Err(ShapeViolation {
3937 shape_iri: "https://uor.foundation/conformance/WittLevelShape",
3938 constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
3939 property_iri: "https://uor.foundation/conformance/declaredBitWidth",
3940 expected_range: "http://www.w3.org/2001/XMLSchema#positiveInteger",
3941 min_count: 1,
3942 max_count: 1,
3943 kind: ViolationKind::Missing,
3944 })
3945 }
3946 };
3947 let pred = match self.predecessor {
3948 Some(p) => p,
3949 None => {
3950 return Err(ShapeViolation {
3951 shape_iri: "https://uor.foundation/conformance/WittLevelShape",
3952 constraint_iri: "https://uor.foundation/conformance/WittLevelShape",
3953 property_iri: "https://uor.foundation/conformance/predecessorLevel",
3954 expected_range: "https://uor.foundation/schema/WittLevel",
3955 min_count: 1,
3956 max_count: 1,
3957 kind: ViolationKind::Missing,
3958 })
3959 }
3960 };
3961 Ok(Validated::new(WittLevelDeclaration {
3962 bit_width: bw,
3963 predecessor: pred,
3964 }))
3965 }
3966}
3967
3968impl Default for WittLevelDeclarationBuilder {
3969 fn default() -> Self {
3970 Self::new()
3971 }
3972}
3973
3974#[derive(Debug, Clone, PartialEq, Eq)]
3978pub struct BoundarySession {
3979 crossing_count: u32,
3981 is_idempotent: bool,
3983}
3984
3985impl BoundarySession {
3986 #[inline]
3988 #[allow(dead_code)]
3989 pub(crate) const fn new(is_idempotent: bool) -> Self {
3990 Self {
3991 crossing_count: 0,
3992 is_idempotent,
3993 }
3994 }
3995
3996 #[inline]
3998 #[must_use]
3999 pub const fn crossing_count(&self) -> u32 {
4000 self.crossing_count
4001 }
4002
4003 #[inline]
4005 #[must_use]
4006 pub const fn is_idempotent(&self) -> bool {
4007 self.is_idempotent
4008 }
4009}
4010
4011#[allow(dead_code)]
4016pub(crate) fn validate_and_mint_coord(
4017 grounded: GroundedCoord,
4018 shape: &Validated<GroundingDeclaration>,
4019 session: &mut BoundarySession,
4020) -> Result<Datum, ShapeViolation> {
4021 let _ = shape; session.crossing_count += 1;
4027 let inner = match grounded.inner {
4028 GroundedCoordInner::W8(b) => DatumInner::W8(b),
4029 GroundedCoordInner::W16(b) => DatumInner::W16(b),
4030 GroundedCoordInner::W24(b) => DatumInner::W24(b),
4031 GroundedCoordInner::W32(b) => DatumInner::W32(b),
4032 GroundedCoordInner::W40(b) => DatumInner::W40(b),
4033 GroundedCoordInner::W48(b) => DatumInner::W48(b),
4034 GroundedCoordInner::W56(b) => DatumInner::W56(b),
4035 GroundedCoordInner::W64(b) => DatumInner::W64(b),
4036 GroundedCoordInner::W72(b) => DatumInner::W72(b),
4037 GroundedCoordInner::W80(b) => DatumInner::W80(b),
4038 GroundedCoordInner::W88(b) => DatumInner::W88(b),
4039 GroundedCoordInner::W96(b) => DatumInner::W96(b),
4040 GroundedCoordInner::W104(b) => DatumInner::W104(b),
4041 GroundedCoordInner::W112(b) => DatumInner::W112(b),
4042 GroundedCoordInner::W120(b) => DatumInner::W120(b),
4043 GroundedCoordInner::W128(b) => DatumInner::W128(b),
4044 };
4045 Ok(Datum { inner })
4046}
4047
4048#[allow(dead_code)]
4056pub(crate) fn validate_and_mint_tuple<const N: usize>(
4057 grounded: GroundedTuple<N>,
4058 shape: &Validated<GroundingDeclaration>,
4059 session: &mut BoundarySession,
4060) -> Result<Datum, ShapeViolation> {
4061 if N == 0 {
4062 return Err(ShapeViolation {
4063 shape_iri: shape.inner().shape_iri,
4064 constraint_iri: shape.inner().shape_iri,
4065 property_iri: "https://uor.foundation/conformance/groundingSourceType",
4066 expected_range: "https://uor.foundation/type/TypeDefinition",
4067 min_count: 1,
4068 max_count: 0,
4069 kind: ViolationKind::CardinalityViolation,
4070 });
4071 }
4072 validate_and_mint_coord(grounded.coords[0].clone(), shape, session)
4076}
4077
4078pub fn mint_datum(level: crate::WittLevel, bytes: &[u8]) -> Result<Datum, ShapeViolation> {
4086 let expected_bytes = (level.witt_length() / 8) as usize;
4087 if bytes.len() != expected_bytes {
4088 return Err(ShapeViolation {
4089 shape_iri: "https://uor.foundation/u/Datum",
4090 constraint_iri: "https://uor.foundation/u/DatumByteWidth",
4091 property_iri: "https://uor.foundation/u/datumBytes",
4092 expected_range: "http://www.w3.org/2001/XMLSchema#nonNegativeInteger",
4093 min_count: expected_bytes as u32,
4094 max_count: expected_bytes as u32,
4095 kind: crate::ViolationKind::CardinalityViolation,
4096 });
4097 }
4098 let inner = match level.witt_length() {
4099 8 => {
4100 let mut buf = [0u8; 1];
4101 let mut i = 0;
4102 while i < 1 {
4103 buf[i] = bytes[i];
4104 i += 1;
4105 }
4106 DatumInner::W8(buf)
4107 }
4108 16 => {
4109 let mut buf = [0u8; 2];
4110 let mut i = 0;
4111 while i < 2 {
4112 buf[i] = bytes[i];
4113 i += 1;
4114 }
4115 DatumInner::W16(buf)
4116 }
4117 24 => {
4118 let mut buf = [0u8; 3];
4119 let mut i = 0;
4120 while i < 3 {
4121 buf[i] = bytes[i];
4122 i += 1;
4123 }
4124 DatumInner::W24(buf)
4125 }
4126 32 => {
4127 let mut buf = [0u8; 4];
4128 let mut i = 0;
4129 while i < 4 {
4130 buf[i] = bytes[i];
4131 i += 1;
4132 }
4133 DatumInner::W32(buf)
4134 }
4135 40 => {
4136 let mut buf = [0u8; 5];
4137 let mut i = 0;
4138 while i < 5 {
4139 buf[i] = bytes[i];
4140 i += 1;
4141 }
4142 DatumInner::W40(buf)
4143 }
4144 48 => {
4145 let mut buf = [0u8; 6];
4146 let mut i = 0;
4147 while i < 6 {
4148 buf[i] = bytes[i];
4149 i += 1;
4150 }
4151 DatumInner::W48(buf)
4152 }
4153 56 => {
4154 let mut buf = [0u8; 7];
4155 let mut i = 0;
4156 while i < 7 {
4157 buf[i] = bytes[i];
4158 i += 1;
4159 }
4160 DatumInner::W56(buf)
4161 }
4162 64 => {
4163 let mut buf = [0u8; 8];
4164 let mut i = 0;
4165 while i < 8 {
4166 buf[i] = bytes[i];
4167 i += 1;
4168 }
4169 DatumInner::W64(buf)
4170 }
4171 72 => {
4172 let mut buf = [0u8; 9];
4173 let mut i = 0;
4174 while i < 9 {
4175 buf[i] = bytes[i];
4176 i += 1;
4177 }
4178 DatumInner::W72(buf)
4179 }
4180 80 => {
4181 let mut buf = [0u8; 10];
4182 let mut i = 0;
4183 while i < 10 {
4184 buf[i] = bytes[i];
4185 i += 1;
4186 }
4187 DatumInner::W80(buf)
4188 }
4189 88 => {
4190 let mut buf = [0u8; 11];
4191 let mut i = 0;
4192 while i < 11 {
4193 buf[i] = bytes[i];
4194 i += 1;
4195 }
4196 DatumInner::W88(buf)
4197 }
4198 96 => {
4199 let mut buf = [0u8; 12];
4200 let mut i = 0;
4201 while i < 12 {
4202 buf[i] = bytes[i];
4203 i += 1;
4204 }
4205 DatumInner::W96(buf)
4206 }
4207 104 => {
4208 let mut buf = [0u8; 13];
4209 let mut i = 0;
4210 while i < 13 {
4211 buf[i] = bytes[i];
4212 i += 1;
4213 }
4214 DatumInner::W104(buf)
4215 }
4216 112 => {
4217 let mut buf = [0u8; 14];
4218 let mut i = 0;
4219 while i < 14 {
4220 buf[i] = bytes[i];
4221 i += 1;
4222 }
4223 DatumInner::W112(buf)
4224 }
4225 120 => {
4226 let mut buf = [0u8; 15];
4227 let mut i = 0;
4228 while i < 15 {
4229 buf[i] = bytes[i];
4230 i += 1;
4231 }
4232 DatumInner::W120(buf)
4233 }
4234 128 => {
4235 let mut buf = [0u8; 16];
4236 let mut i = 0;
4237 while i < 16 {
4238 buf[i] = bytes[i];
4239 i += 1;
4240 }
4241 DatumInner::W128(buf)
4242 }
4243 _ => {
4244 return Err(ShapeViolation {
4245 shape_iri: "https://uor.foundation/u/Datum",
4246 constraint_iri: "https://uor.foundation/u/DatumLevel",
4247 property_iri: "https://uor.foundation/u/datumLevel",
4248 expected_range: "https://uor.foundation/schema/WittLevel",
4249 min_count: 1,
4250 max_count: 1,
4251 kind: crate::ViolationKind::ValueCheck,
4252 })
4253 }
4254 };
4255 Ok(Datum { inner })
4256}
4257
4258#[must_use]
4262pub const fn mint_triad<L>(stratum: u64, spectrum: u64, address: u64) -> Triad<L> {
4263 Triad::new(stratum, spectrum, address)
4264}
4265
4266#[must_use]
4270pub const fn mint_derivation(
4271 step_count: u32,
4272 witt_level_bits: u16,
4273 content_fingerprint: ContentFingerprint,
4274) -> Derivation {
4275 Derivation::new(step_count, witt_level_bits, content_fingerprint)
4276}
4277
4278#[must_use]
4282pub const fn mint_freerank(total: u32, pinned: u32) -> FreeRank {
4283 FreeRank::new(total, pinned)
4284}
4285
4286#[inline]
4317#[must_use]
4318#[allow(clippy::manual_checked_ops)]
4319pub const fn const_ring_eval_w8(op: PrimitiveOp, a: u8, b: u8) -> u8 {
4320 match op {
4321 PrimitiveOp::Add => a.wrapping_add(b),
4322 PrimitiveOp::Sub => a.wrapping_sub(b),
4323 PrimitiveOp::Mul => a.wrapping_mul(b),
4324 PrimitiveOp::Xor => a ^ b,
4325 PrimitiveOp::And => a & b,
4326 PrimitiveOp::Or => a | b,
4327 PrimitiveOp::Le => (a <= b) as u8,
4328 PrimitiveOp::Lt => (a < b) as u8,
4329 PrimitiveOp::Ge => (a >= b) as u8,
4330 PrimitiveOp::Gt => (a > b) as u8,
4331 PrimitiveOp::Concat => 0,
4332 PrimitiveOp::Div => {
4333 if b == 0 {
4334 0
4335 } else {
4336 a / b
4337 }
4338 }
4339 PrimitiveOp::Mod => {
4340 if b == 0 {
4341 0
4342 } else {
4343 a % b
4344 }
4345 }
4346 PrimitiveOp::Pow => const_pow_w8(a, b),
4347 _ => 0,
4348 }
4349}
4350
4351#[inline]
4352#[must_use]
4353pub const fn const_pow_w8(base: u8, exp: u8) -> u8 {
4354 let mut result: u8 = 1;
4355 let mut b: u8 = base;
4356 let mut e: u8 = exp;
4357 while e > 0 {
4358 if (e & 1) == 1 {
4359 result = result.wrapping_mul(b);
4360 }
4361 b = b.wrapping_mul(b);
4362 e >>= 1;
4363 }
4364 result
4365}
4366
4367#[inline]
4368#[must_use]
4369pub const fn const_ring_eval_unary_w8(op: PrimitiveOp, a: u8) -> u8 {
4370 match op {
4371 PrimitiveOp::Neg => 0u8.wrapping_sub(a),
4372 PrimitiveOp::Bnot => !a,
4373 PrimitiveOp::Succ => a.wrapping_add(1),
4374 PrimitiveOp::Pred => a.wrapping_sub(1),
4375 _ => 0,
4376 }
4377}
4378
4379#[inline]
4380#[must_use]
4381#[allow(clippy::manual_checked_ops)]
4382pub const fn const_ring_eval_w16(op: PrimitiveOp, a: u16, b: u16) -> u16 {
4383 match op {
4384 PrimitiveOp::Add => a.wrapping_add(b),
4385 PrimitiveOp::Sub => a.wrapping_sub(b),
4386 PrimitiveOp::Mul => a.wrapping_mul(b),
4387 PrimitiveOp::Xor => a ^ b,
4388 PrimitiveOp::And => a & b,
4389 PrimitiveOp::Or => a | b,
4390 PrimitiveOp::Le => (a <= b) as u16,
4391 PrimitiveOp::Lt => (a < b) as u16,
4392 PrimitiveOp::Ge => (a >= b) as u16,
4393 PrimitiveOp::Gt => (a > b) as u16,
4394 PrimitiveOp::Concat => 0,
4395 PrimitiveOp::Div => {
4396 if b == 0 {
4397 0
4398 } else {
4399 a / b
4400 }
4401 }
4402 PrimitiveOp::Mod => {
4403 if b == 0 {
4404 0
4405 } else {
4406 a % b
4407 }
4408 }
4409 PrimitiveOp::Pow => const_pow_w16(a, b),
4410 _ => 0,
4411 }
4412}
4413
4414#[inline]
4415#[must_use]
4416pub const fn const_pow_w16(base: u16, exp: u16) -> u16 {
4417 let mut result: u16 = 1;
4418 let mut b: u16 = base;
4419 let mut e: u16 = exp;
4420 while e > 0 {
4421 if (e & 1) == 1 {
4422 result = result.wrapping_mul(b);
4423 }
4424 b = b.wrapping_mul(b);
4425 e >>= 1;
4426 }
4427 result
4428}
4429
4430#[inline]
4431#[must_use]
4432pub const fn const_ring_eval_unary_w16(op: PrimitiveOp, a: u16) -> u16 {
4433 match op {
4434 PrimitiveOp::Neg => 0u16.wrapping_sub(a),
4435 PrimitiveOp::Bnot => !a,
4436 PrimitiveOp::Succ => a.wrapping_add(1),
4437 PrimitiveOp::Pred => a.wrapping_sub(1),
4438 _ => 0,
4439 }
4440}
4441
4442#[inline]
4443#[must_use]
4444#[allow(clippy::manual_checked_ops)]
4445pub const fn const_ring_eval_w24(op: PrimitiveOp, a: u32, b: u32) -> u32 {
4446 const MASK: u32 = (u64::MAX >> (64 - 24)) as u32;
4447 match op {
4448 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4449 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4450 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4451 PrimitiveOp::Xor => (a ^ b) & MASK,
4452 PrimitiveOp::And => (a & b) & MASK,
4453 PrimitiveOp::Or => (a | b) & MASK,
4454 PrimitiveOp::Le => (a <= b) as u32,
4455 PrimitiveOp::Lt => (a < b) as u32,
4456 PrimitiveOp::Ge => (a >= b) as u32,
4457 PrimitiveOp::Gt => (a > b) as u32,
4458 PrimitiveOp::Concat => 0,
4459 PrimitiveOp::Div => {
4460 if b == 0 {
4461 0
4462 } else {
4463 (a / b) & MASK
4464 }
4465 }
4466 PrimitiveOp::Mod => {
4467 if b == 0 {
4468 0
4469 } else {
4470 (a % b) & MASK
4471 }
4472 }
4473 PrimitiveOp::Pow => (const_pow_w24(a, b)) & MASK,
4474 _ => 0,
4475 }
4476}
4477
4478#[inline]
4479#[must_use]
4480pub const fn const_pow_w24(base: u32, exp: u32) -> u32 {
4481 const MASK: u32 = (u64::MAX >> (64 - 24)) as u32;
4482 let mut result: u32 = 1;
4483 let mut b: u32 = (base) & MASK;
4484 let mut e: u32 = exp;
4485 while e > 0 {
4486 if (e & 1) == 1 {
4487 result = (result.wrapping_mul(b)) & MASK;
4488 }
4489 b = (b.wrapping_mul(b)) & MASK;
4490 e >>= 1;
4491 }
4492 result
4493}
4494
4495#[inline]
4496#[must_use]
4497pub const fn const_ring_eval_unary_w24(op: PrimitiveOp, a: u32) -> u32 {
4498 const MASK: u32 = (u64::MAX >> (64 - 24)) as u32;
4499 match op {
4500 PrimitiveOp::Neg => (0u32.wrapping_sub(a)) & MASK,
4501 PrimitiveOp::Bnot => (!a) & MASK,
4502 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4503 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4504 _ => 0,
4505 }
4506}
4507
4508#[inline]
4509#[must_use]
4510#[allow(clippy::manual_checked_ops)]
4511pub const fn const_ring_eval_w32(op: PrimitiveOp, a: u32, b: u32) -> u32 {
4512 match op {
4513 PrimitiveOp::Add => a.wrapping_add(b),
4514 PrimitiveOp::Sub => a.wrapping_sub(b),
4515 PrimitiveOp::Mul => a.wrapping_mul(b),
4516 PrimitiveOp::Xor => a ^ b,
4517 PrimitiveOp::And => a & b,
4518 PrimitiveOp::Or => a | b,
4519 PrimitiveOp::Le => (a <= b) as u32,
4520 PrimitiveOp::Lt => (a < b) as u32,
4521 PrimitiveOp::Ge => (a >= b) as u32,
4522 PrimitiveOp::Gt => (a > b) as u32,
4523 PrimitiveOp::Concat => 0,
4524 PrimitiveOp::Div => {
4525 if b == 0 {
4526 0
4527 } else {
4528 a / b
4529 }
4530 }
4531 PrimitiveOp::Mod => {
4532 if b == 0 {
4533 0
4534 } else {
4535 a % b
4536 }
4537 }
4538 PrimitiveOp::Pow => const_pow_w32(a, b),
4539 _ => 0,
4540 }
4541}
4542
4543#[inline]
4544#[must_use]
4545pub const fn const_pow_w32(base: u32, exp: u32) -> u32 {
4546 let mut result: u32 = 1;
4547 let mut b: u32 = base;
4548 let mut e: u32 = exp;
4549 while e > 0 {
4550 if (e & 1) == 1 {
4551 result = result.wrapping_mul(b);
4552 }
4553 b = b.wrapping_mul(b);
4554 e >>= 1;
4555 }
4556 result
4557}
4558
4559#[inline]
4560#[must_use]
4561pub const fn const_ring_eval_unary_w32(op: PrimitiveOp, a: u32) -> u32 {
4562 match op {
4563 PrimitiveOp::Neg => 0u32.wrapping_sub(a),
4564 PrimitiveOp::Bnot => !a,
4565 PrimitiveOp::Succ => a.wrapping_add(1),
4566 PrimitiveOp::Pred => a.wrapping_sub(1),
4567 _ => 0,
4568 }
4569}
4570
4571#[inline]
4572#[must_use]
4573#[allow(clippy::manual_checked_ops)]
4574pub const fn const_ring_eval_w40(op: PrimitiveOp, a: u64, b: u64) -> u64 {
4575 const MASK: u64 = u64::MAX >> (64 - 40);
4576 match op {
4577 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4578 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4579 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4580 PrimitiveOp::Xor => (a ^ b) & MASK,
4581 PrimitiveOp::And => (a & b) & MASK,
4582 PrimitiveOp::Or => (a | b) & MASK,
4583 PrimitiveOp::Le => (a <= b) as u64,
4584 PrimitiveOp::Lt => (a < b) as u64,
4585 PrimitiveOp::Ge => (a >= b) as u64,
4586 PrimitiveOp::Gt => (a > b) as u64,
4587 PrimitiveOp::Concat => 0,
4588 PrimitiveOp::Div => {
4589 if b == 0 {
4590 0
4591 } else {
4592 (a / b) & MASK
4593 }
4594 }
4595 PrimitiveOp::Mod => {
4596 if b == 0 {
4597 0
4598 } else {
4599 (a % b) & MASK
4600 }
4601 }
4602 PrimitiveOp::Pow => (const_pow_w40(a, b)) & MASK,
4603 _ => 0,
4604 }
4605}
4606
4607#[inline]
4608#[must_use]
4609pub const fn const_pow_w40(base: u64, exp: u64) -> u64 {
4610 const MASK: u64 = u64::MAX >> (64 - 40);
4611 let mut result: u64 = 1;
4612 let mut b: u64 = (base) & MASK;
4613 let mut e: u64 = exp;
4614 while e > 0 {
4615 if (e & 1) == 1 {
4616 result = (result.wrapping_mul(b)) & MASK;
4617 }
4618 b = (b.wrapping_mul(b)) & MASK;
4619 e >>= 1;
4620 }
4621 result
4622}
4623
4624#[inline]
4625#[must_use]
4626pub const fn const_ring_eval_unary_w40(op: PrimitiveOp, a: u64) -> u64 {
4627 const MASK: u64 = u64::MAX >> (64 - 40);
4628 match op {
4629 PrimitiveOp::Neg => (0u64.wrapping_sub(a)) & MASK,
4630 PrimitiveOp::Bnot => (!a) & MASK,
4631 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4632 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4633 _ => 0,
4634 }
4635}
4636
4637#[inline]
4638#[must_use]
4639#[allow(clippy::manual_checked_ops)]
4640pub const fn const_ring_eval_w48(op: PrimitiveOp, a: u64, b: u64) -> u64 {
4641 const MASK: u64 = u64::MAX >> (64 - 48);
4642 match op {
4643 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4644 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4645 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4646 PrimitiveOp::Xor => (a ^ b) & MASK,
4647 PrimitiveOp::And => (a & b) & MASK,
4648 PrimitiveOp::Or => (a | b) & MASK,
4649 PrimitiveOp::Le => (a <= b) as u64,
4650 PrimitiveOp::Lt => (a < b) as u64,
4651 PrimitiveOp::Ge => (a >= b) as u64,
4652 PrimitiveOp::Gt => (a > b) as u64,
4653 PrimitiveOp::Concat => 0,
4654 PrimitiveOp::Div => {
4655 if b == 0 {
4656 0
4657 } else {
4658 (a / b) & MASK
4659 }
4660 }
4661 PrimitiveOp::Mod => {
4662 if b == 0 {
4663 0
4664 } else {
4665 (a % b) & MASK
4666 }
4667 }
4668 PrimitiveOp::Pow => (const_pow_w48(a, b)) & MASK,
4669 _ => 0,
4670 }
4671}
4672
4673#[inline]
4674#[must_use]
4675pub const fn const_pow_w48(base: u64, exp: u64) -> u64 {
4676 const MASK: u64 = u64::MAX >> (64 - 48);
4677 let mut result: u64 = 1;
4678 let mut b: u64 = (base) & MASK;
4679 let mut e: u64 = exp;
4680 while e > 0 {
4681 if (e & 1) == 1 {
4682 result = (result.wrapping_mul(b)) & MASK;
4683 }
4684 b = (b.wrapping_mul(b)) & MASK;
4685 e >>= 1;
4686 }
4687 result
4688}
4689
4690#[inline]
4691#[must_use]
4692pub const fn const_ring_eval_unary_w48(op: PrimitiveOp, a: u64) -> u64 {
4693 const MASK: u64 = u64::MAX >> (64 - 48);
4694 match op {
4695 PrimitiveOp::Neg => (0u64.wrapping_sub(a)) & MASK,
4696 PrimitiveOp::Bnot => (!a) & MASK,
4697 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4698 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4699 _ => 0,
4700 }
4701}
4702
4703#[inline]
4704#[must_use]
4705#[allow(clippy::manual_checked_ops)]
4706pub const fn const_ring_eval_w56(op: PrimitiveOp, a: u64, b: u64) -> u64 {
4707 const MASK: u64 = u64::MAX >> (64 - 56);
4708 match op {
4709 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4710 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4711 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4712 PrimitiveOp::Xor => (a ^ b) & MASK,
4713 PrimitiveOp::And => (a & b) & MASK,
4714 PrimitiveOp::Or => (a | b) & MASK,
4715 PrimitiveOp::Le => (a <= b) as u64,
4716 PrimitiveOp::Lt => (a < b) as u64,
4717 PrimitiveOp::Ge => (a >= b) as u64,
4718 PrimitiveOp::Gt => (a > b) as u64,
4719 PrimitiveOp::Concat => 0,
4720 PrimitiveOp::Div => {
4721 if b == 0 {
4722 0
4723 } else {
4724 (a / b) & MASK
4725 }
4726 }
4727 PrimitiveOp::Mod => {
4728 if b == 0 {
4729 0
4730 } else {
4731 (a % b) & MASK
4732 }
4733 }
4734 PrimitiveOp::Pow => (const_pow_w56(a, b)) & MASK,
4735 _ => 0,
4736 }
4737}
4738
4739#[inline]
4740#[must_use]
4741pub const fn const_pow_w56(base: u64, exp: u64) -> u64 {
4742 const MASK: u64 = u64::MAX >> (64 - 56);
4743 let mut result: u64 = 1;
4744 let mut b: u64 = (base) & MASK;
4745 let mut e: u64 = exp;
4746 while e > 0 {
4747 if (e & 1) == 1 {
4748 result = (result.wrapping_mul(b)) & MASK;
4749 }
4750 b = (b.wrapping_mul(b)) & MASK;
4751 e >>= 1;
4752 }
4753 result
4754}
4755
4756#[inline]
4757#[must_use]
4758pub const fn const_ring_eval_unary_w56(op: PrimitiveOp, a: u64) -> u64 {
4759 const MASK: u64 = u64::MAX >> (64 - 56);
4760 match op {
4761 PrimitiveOp::Neg => (0u64.wrapping_sub(a)) & MASK,
4762 PrimitiveOp::Bnot => (!a) & MASK,
4763 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4764 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4765 _ => 0,
4766 }
4767}
4768
4769#[inline]
4770#[must_use]
4771#[allow(clippy::manual_checked_ops)]
4772pub const fn const_ring_eval_w64(op: PrimitiveOp, a: u64, b: u64) -> u64 {
4773 match op {
4774 PrimitiveOp::Add => a.wrapping_add(b),
4775 PrimitiveOp::Sub => a.wrapping_sub(b),
4776 PrimitiveOp::Mul => a.wrapping_mul(b),
4777 PrimitiveOp::Xor => a ^ b,
4778 PrimitiveOp::And => a & b,
4779 PrimitiveOp::Or => a | b,
4780 PrimitiveOp::Le => (a <= b) as u64,
4781 PrimitiveOp::Lt => (a < b) as u64,
4782 PrimitiveOp::Ge => (a >= b) as u64,
4783 PrimitiveOp::Gt => (a > b) as u64,
4784 PrimitiveOp::Concat => 0,
4785 PrimitiveOp::Div => {
4786 if b == 0 {
4787 0
4788 } else {
4789 a / b
4790 }
4791 }
4792 PrimitiveOp::Mod => {
4793 if b == 0 {
4794 0
4795 } else {
4796 a % b
4797 }
4798 }
4799 PrimitiveOp::Pow => const_pow_w64(a, b),
4800 _ => 0,
4801 }
4802}
4803
4804#[inline]
4805#[must_use]
4806pub const fn const_pow_w64(base: u64, exp: u64) -> u64 {
4807 let mut result: u64 = 1;
4808 let mut b: u64 = base;
4809 let mut e: u64 = exp;
4810 while e > 0 {
4811 if (e & 1) == 1 {
4812 result = result.wrapping_mul(b);
4813 }
4814 b = b.wrapping_mul(b);
4815 e >>= 1;
4816 }
4817 result
4818}
4819
4820#[inline]
4821#[must_use]
4822pub const fn const_ring_eval_unary_w64(op: PrimitiveOp, a: u64) -> u64 {
4823 match op {
4824 PrimitiveOp::Neg => 0u64.wrapping_sub(a),
4825 PrimitiveOp::Bnot => !a,
4826 PrimitiveOp::Succ => a.wrapping_add(1),
4827 PrimitiveOp::Pred => a.wrapping_sub(1),
4828 _ => 0,
4829 }
4830}
4831
4832#[inline]
4833#[must_use]
4834#[allow(clippy::manual_checked_ops)]
4835pub const fn const_ring_eval_w72(op: PrimitiveOp, a: u128, b: u128) -> u128 {
4836 const MASK: u128 = u128::MAX >> (128 - 72);
4837 match op {
4838 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4839 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4840 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4841 PrimitiveOp::Xor => (a ^ b) & MASK,
4842 PrimitiveOp::And => (a & b) & MASK,
4843 PrimitiveOp::Or => (a | b) & MASK,
4844 PrimitiveOp::Le => (a <= b) as u128,
4845 PrimitiveOp::Lt => (a < b) as u128,
4846 PrimitiveOp::Ge => (a >= b) as u128,
4847 PrimitiveOp::Gt => (a > b) as u128,
4848 PrimitiveOp::Concat => 0,
4849 PrimitiveOp::Div => {
4850 if b == 0 {
4851 0
4852 } else {
4853 (a / b) & MASK
4854 }
4855 }
4856 PrimitiveOp::Mod => {
4857 if b == 0 {
4858 0
4859 } else {
4860 (a % b) & MASK
4861 }
4862 }
4863 PrimitiveOp::Pow => (const_pow_w72(a, b)) & MASK,
4864 _ => 0,
4865 }
4866}
4867
4868#[inline]
4869#[must_use]
4870pub const fn const_pow_w72(base: u128, exp: u128) -> u128 {
4871 const MASK: u128 = u128::MAX >> (128 - 72);
4872 let mut result: u128 = 1;
4873 let mut b: u128 = (base) & MASK;
4874 let mut e: u128 = exp;
4875 while e > 0 {
4876 if (e & 1) == 1 {
4877 result = (result.wrapping_mul(b)) & MASK;
4878 }
4879 b = (b.wrapping_mul(b)) & MASK;
4880 e >>= 1;
4881 }
4882 result
4883}
4884
4885#[inline]
4886#[must_use]
4887pub const fn const_ring_eval_unary_w72(op: PrimitiveOp, a: u128) -> u128 {
4888 const MASK: u128 = u128::MAX >> (128 - 72);
4889 match op {
4890 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
4891 PrimitiveOp::Bnot => (!a) & MASK,
4892 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4893 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4894 _ => 0,
4895 }
4896}
4897
4898#[inline]
4899#[must_use]
4900#[allow(clippy::manual_checked_ops)]
4901pub const fn const_ring_eval_w80(op: PrimitiveOp, a: u128, b: u128) -> u128 {
4902 const MASK: u128 = u128::MAX >> (128 - 80);
4903 match op {
4904 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4905 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4906 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4907 PrimitiveOp::Xor => (a ^ b) & MASK,
4908 PrimitiveOp::And => (a & b) & MASK,
4909 PrimitiveOp::Or => (a | b) & MASK,
4910 PrimitiveOp::Le => (a <= b) as u128,
4911 PrimitiveOp::Lt => (a < b) as u128,
4912 PrimitiveOp::Ge => (a >= b) as u128,
4913 PrimitiveOp::Gt => (a > b) as u128,
4914 PrimitiveOp::Concat => 0,
4915 PrimitiveOp::Div => {
4916 if b == 0 {
4917 0
4918 } else {
4919 (a / b) & MASK
4920 }
4921 }
4922 PrimitiveOp::Mod => {
4923 if b == 0 {
4924 0
4925 } else {
4926 (a % b) & MASK
4927 }
4928 }
4929 PrimitiveOp::Pow => (const_pow_w80(a, b)) & MASK,
4930 _ => 0,
4931 }
4932}
4933
4934#[inline]
4935#[must_use]
4936pub const fn const_pow_w80(base: u128, exp: u128) -> u128 {
4937 const MASK: u128 = u128::MAX >> (128 - 80);
4938 let mut result: u128 = 1;
4939 let mut b: u128 = (base) & MASK;
4940 let mut e: u128 = exp;
4941 while e > 0 {
4942 if (e & 1) == 1 {
4943 result = (result.wrapping_mul(b)) & MASK;
4944 }
4945 b = (b.wrapping_mul(b)) & MASK;
4946 e >>= 1;
4947 }
4948 result
4949}
4950
4951#[inline]
4952#[must_use]
4953pub const fn const_ring_eval_unary_w80(op: PrimitiveOp, a: u128) -> u128 {
4954 const MASK: u128 = u128::MAX >> (128 - 80);
4955 match op {
4956 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
4957 PrimitiveOp::Bnot => (!a) & MASK,
4958 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
4959 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
4960 _ => 0,
4961 }
4962}
4963
4964#[inline]
4965#[must_use]
4966#[allow(clippy::manual_checked_ops)]
4967pub const fn const_ring_eval_w88(op: PrimitiveOp, a: u128, b: u128) -> u128 {
4968 const MASK: u128 = u128::MAX >> (128 - 88);
4969 match op {
4970 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
4971 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
4972 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
4973 PrimitiveOp::Xor => (a ^ b) & MASK,
4974 PrimitiveOp::And => (a & b) & MASK,
4975 PrimitiveOp::Or => (a | b) & MASK,
4976 PrimitiveOp::Le => (a <= b) as u128,
4977 PrimitiveOp::Lt => (a < b) as u128,
4978 PrimitiveOp::Ge => (a >= b) as u128,
4979 PrimitiveOp::Gt => (a > b) as u128,
4980 PrimitiveOp::Concat => 0,
4981 PrimitiveOp::Div => {
4982 if b == 0 {
4983 0
4984 } else {
4985 (a / b) & MASK
4986 }
4987 }
4988 PrimitiveOp::Mod => {
4989 if b == 0 {
4990 0
4991 } else {
4992 (a % b) & MASK
4993 }
4994 }
4995 PrimitiveOp::Pow => (const_pow_w88(a, b)) & MASK,
4996 _ => 0,
4997 }
4998}
4999
5000#[inline]
5001#[must_use]
5002pub const fn const_pow_w88(base: u128, exp: u128) -> u128 {
5003 const MASK: u128 = u128::MAX >> (128 - 88);
5004 let mut result: u128 = 1;
5005 let mut b: u128 = (base) & MASK;
5006 let mut e: u128 = exp;
5007 while e > 0 {
5008 if (e & 1) == 1 {
5009 result = (result.wrapping_mul(b)) & MASK;
5010 }
5011 b = (b.wrapping_mul(b)) & MASK;
5012 e >>= 1;
5013 }
5014 result
5015}
5016
5017#[inline]
5018#[must_use]
5019pub const fn const_ring_eval_unary_w88(op: PrimitiveOp, a: u128) -> u128 {
5020 const MASK: u128 = u128::MAX >> (128 - 88);
5021 match op {
5022 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
5023 PrimitiveOp::Bnot => (!a) & MASK,
5024 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
5025 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
5026 _ => 0,
5027 }
5028}
5029
5030#[inline]
5031#[must_use]
5032#[allow(clippy::manual_checked_ops)]
5033pub const fn const_ring_eval_w96(op: PrimitiveOp, a: u128, b: u128) -> u128 {
5034 const MASK: u128 = u128::MAX >> (128 - 96);
5035 match op {
5036 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
5037 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
5038 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
5039 PrimitiveOp::Xor => (a ^ b) & MASK,
5040 PrimitiveOp::And => (a & b) & MASK,
5041 PrimitiveOp::Or => (a | b) & MASK,
5042 PrimitiveOp::Le => (a <= b) as u128,
5043 PrimitiveOp::Lt => (a < b) as u128,
5044 PrimitiveOp::Ge => (a >= b) as u128,
5045 PrimitiveOp::Gt => (a > b) as u128,
5046 PrimitiveOp::Concat => 0,
5047 PrimitiveOp::Div => {
5048 if b == 0 {
5049 0
5050 } else {
5051 (a / b) & MASK
5052 }
5053 }
5054 PrimitiveOp::Mod => {
5055 if b == 0 {
5056 0
5057 } else {
5058 (a % b) & MASK
5059 }
5060 }
5061 PrimitiveOp::Pow => (const_pow_w96(a, b)) & MASK,
5062 _ => 0,
5063 }
5064}
5065
5066#[inline]
5067#[must_use]
5068pub const fn const_pow_w96(base: u128, exp: u128) -> u128 {
5069 const MASK: u128 = u128::MAX >> (128 - 96);
5070 let mut result: u128 = 1;
5071 let mut b: u128 = (base) & MASK;
5072 let mut e: u128 = exp;
5073 while e > 0 {
5074 if (e & 1) == 1 {
5075 result = (result.wrapping_mul(b)) & MASK;
5076 }
5077 b = (b.wrapping_mul(b)) & MASK;
5078 e >>= 1;
5079 }
5080 result
5081}
5082
5083#[inline]
5084#[must_use]
5085pub const fn const_ring_eval_unary_w96(op: PrimitiveOp, a: u128) -> u128 {
5086 const MASK: u128 = u128::MAX >> (128 - 96);
5087 match op {
5088 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
5089 PrimitiveOp::Bnot => (!a) & MASK,
5090 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
5091 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
5092 _ => 0,
5093 }
5094}
5095
5096#[inline]
5097#[must_use]
5098#[allow(clippy::manual_checked_ops)]
5099pub const fn const_ring_eval_w104(op: PrimitiveOp, a: u128, b: u128) -> u128 {
5100 const MASK: u128 = u128::MAX >> (128 - 104);
5101 match op {
5102 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
5103 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
5104 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
5105 PrimitiveOp::Xor => (a ^ b) & MASK,
5106 PrimitiveOp::And => (a & b) & MASK,
5107 PrimitiveOp::Or => (a | b) & MASK,
5108 PrimitiveOp::Le => (a <= b) as u128,
5109 PrimitiveOp::Lt => (a < b) as u128,
5110 PrimitiveOp::Ge => (a >= b) as u128,
5111 PrimitiveOp::Gt => (a > b) as u128,
5112 PrimitiveOp::Concat => 0,
5113 PrimitiveOp::Div => {
5114 if b == 0 {
5115 0
5116 } else {
5117 (a / b) & MASK
5118 }
5119 }
5120 PrimitiveOp::Mod => {
5121 if b == 0 {
5122 0
5123 } else {
5124 (a % b) & MASK
5125 }
5126 }
5127 PrimitiveOp::Pow => (const_pow_w104(a, b)) & MASK,
5128 _ => 0,
5129 }
5130}
5131
5132#[inline]
5133#[must_use]
5134pub const fn const_pow_w104(base: u128, exp: u128) -> u128 {
5135 const MASK: u128 = u128::MAX >> (128 - 104);
5136 let mut result: u128 = 1;
5137 let mut b: u128 = (base) & MASK;
5138 let mut e: u128 = exp;
5139 while e > 0 {
5140 if (e & 1) == 1 {
5141 result = (result.wrapping_mul(b)) & MASK;
5142 }
5143 b = (b.wrapping_mul(b)) & MASK;
5144 e >>= 1;
5145 }
5146 result
5147}
5148
5149#[inline]
5150#[must_use]
5151pub const fn const_ring_eval_unary_w104(op: PrimitiveOp, a: u128) -> u128 {
5152 const MASK: u128 = u128::MAX >> (128 - 104);
5153 match op {
5154 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
5155 PrimitiveOp::Bnot => (!a) & MASK,
5156 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
5157 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
5158 _ => 0,
5159 }
5160}
5161
5162#[inline]
5163#[must_use]
5164#[allow(clippy::manual_checked_ops)]
5165pub const fn const_ring_eval_w112(op: PrimitiveOp, a: u128, b: u128) -> u128 {
5166 const MASK: u128 = u128::MAX >> (128 - 112);
5167 match op {
5168 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
5169 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
5170 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
5171 PrimitiveOp::Xor => (a ^ b) & MASK,
5172 PrimitiveOp::And => (a & b) & MASK,
5173 PrimitiveOp::Or => (a | b) & MASK,
5174 PrimitiveOp::Le => (a <= b) as u128,
5175 PrimitiveOp::Lt => (a < b) as u128,
5176 PrimitiveOp::Ge => (a >= b) as u128,
5177 PrimitiveOp::Gt => (a > b) as u128,
5178 PrimitiveOp::Concat => 0,
5179 PrimitiveOp::Div => {
5180 if b == 0 {
5181 0
5182 } else {
5183 (a / b) & MASK
5184 }
5185 }
5186 PrimitiveOp::Mod => {
5187 if b == 0 {
5188 0
5189 } else {
5190 (a % b) & MASK
5191 }
5192 }
5193 PrimitiveOp::Pow => (const_pow_w112(a, b)) & MASK,
5194 _ => 0,
5195 }
5196}
5197
5198#[inline]
5199#[must_use]
5200pub const fn const_pow_w112(base: u128, exp: u128) -> u128 {
5201 const MASK: u128 = u128::MAX >> (128 - 112);
5202 let mut result: u128 = 1;
5203 let mut b: u128 = (base) & MASK;
5204 let mut e: u128 = exp;
5205 while e > 0 {
5206 if (e & 1) == 1 {
5207 result = (result.wrapping_mul(b)) & MASK;
5208 }
5209 b = (b.wrapping_mul(b)) & MASK;
5210 e >>= 1;
5211 }
5212 result
5213}
5214
5215#[inline]
5216#[must_use]
5217pub const fn const_ring_eval_unary_w112(op: PrimitiveOp, a: u128) -> u128 {
5218 const MASK: u128 = u128::MAX >> (128 - 112);
5219 match op {
5220 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
5221 PrimitiveOp::Bnot => (!a) & MASK,
5222 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
5223 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
5224 _ => 0,
5225 }
5226}
5227
5228#[inline]
5229#[must_use]
5230#[allow(clippy::manual_checked_ops)]
5231pub const fn const_ring_eval_w120(op: PrimitiveOp, a: u128, b: u128) -> u128 {
5232 const MASK: u128 = u128::MAX >> (128 - 120);
5233 match op {
5234 PrimitiveOp::Add => (a.wrapping_add(b)) & MASK,
5235 PrimitiveOp::Sub => (a.wrapping_sub(b)) & MASK,
5236 PrimitiveOp::Mul => (a.wrapping_mul(b)) & MASK,
5237 PrimitiveOp::Xor => (a ^ b) & MASK,
5238 PrimitiveOp::And => (a & b) & MASK,
5239 PrimitiveOp::Or => (a | b) & MASK,
5240 PrimitiveOp::Le => (a <= b) as u128,
5241 PrimitiveOp::Lt => (a < b) as u128,
5242 PrimitiveOp::Ge => (a >= b) as u128,
5243 PrimitiveOp::Gt => (a > b) as u128,
5244 PrimitiveOp::Concat => 0,
5245 PrimitiveOp::Div => {
5246 if b == 0 {
5247 0
5248 } else {
5249 (a / b) & MASK
5250 }
5251 }
5252 PrimitiveOp::Mod => {
5253 if b == 0 {
5254 0
5255 } else {
5256 (a % b) & MASK
5257 }
5258 }
5259 PrimitiveOp::Pow => (const_pow_w120(a, b)) & MASK,
5260 _ => 0,
5261 }
5262}
5263
5264#[inline]
5265#[must_use]
5266pub const fn const_pow_w120(base: u128, exp: u128) -> u128 {
5267 const MASK: u128 = u128::MAX >> (128 - 120);
5268 let mut result: u128 = 1;
5269 let mut b: u128 = (base) & MASK;
5270 let mut e: u128 = exp;
5271 while e > 0 {
5272 if (e & 1) == 1 {
5273 result = (result.wrapping_mul(b)) & MASK;
5274 }
5275 b = (b.wrapping_mul(b)) & MASK;
5276 e >>= 1;
5277 }
5278 result
5279}
5280
5281#[inline]
5282#[must_use]
5283pub const fn const_ring_eval_unary_w120(op: PrimitiveOp, a: u128) -> u128 {
5284 const MASK: u128 = u128::MAX >> (128 - 120);
5285 match op {
5286 PrimitiveOp::Neg => (0u128.wrapping_sub(a)) & MASK,
5287 PrimitiveOp::Bnot => (!a) & MASK,
5288 PrimitiveOp::Succ => (a.wrapping_add(1)) & MASK,
5289 PrimitiveOp::Pred => (a.wrapping_sub(1)) & MASK,
5290 _ => 0,
5291 }
5292}
5293
5294#[inline]
5295#[must_use]
5296#[allow(clippy::manual_checked_ops)]
5297pub const fn const_ring_eval_w128(op: PrimitiveOp, a: u128, b: u128) -> u128 {
5298 match op {
5299 PrimitiveOp::Add => a.wrapping_add(b),
5300 PrimitiveOp::Sub => a.wrapping_sub(b),
5301 PrimitiveOp::Mul => a.wrapping_mul(b),
5302 PrimitiveOp::Xor => a ^ b,
5303 PrimitiveOp::And => a & b,
5304 PrimitiveOp::Or => a | b,
5305 PrimitiveOp::Le => (a <= b) as u128,
5306 PrimitiveOp::Lt => (a < b) as u128,
5307 PrimitiveOp::Ge => (a >= b) as u128,
5308 PrimitiveOp::Gt => (a > b) as u128,
5309 PrimitiveOp::Concat => 0,
5310 PrimitiveOp::Div => {
5311 if b == 0 {
5312 0
5313 } else {
5314 a / b
5315 }
5316 }
5317 PrimitiveOp::Mod => {
5318 if b == 0 {
5319 0
5320 } else {
5321 a % b
5322 }
5323 }
5324 PrimitiveOp::Pow => const_pow_w128(a, b),
5325 _ => 0,
5326 }
5327}
5328
5329#[inline]
5330#[must_use]
5331pub const fn const_pow_w128(base: u128, exp: u128) -> u128 {
5332 let mut result: u128 = 1;
5333 let mut b: u128 = base;
5334 let mut e: u128 = exp;
5335 while e > 0 {
5336 if (e & 1) == 1 {
5337 result = result.wrapping_mul(b);
5338 }
5339 b = b.wrapping_mul(b);
5340 e >>= 1;
5341 }
5342 result
5343}
5344
5345#[inline]
5346#[must_use]
5347pub const fn const_ring_eval_unary_w128(op: PrimitiveOp, a: u128) -> u128 {
5348 match op {
5349 PrimitiveOp::Neg => 0u128.wrapping_sub(a),
5350 PrimitiveOp::Bnot => !a,
5351 PrimitiveOp::Succ => a.wrapping_add(1),
5352 PrimitiveOp::Pred => a.wrapping_sub(1),
5353 _ => 0,
5354 }
5355}
5356
5357#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5366pub struct Limbs<const N: usize> {
5367 words: [u64; N],
5369 _sealed: (),
5371}
5372
5373impl<const N: usize> Limbs<N> {
5374 #[inline]
5376 #[must_use]
5377 #[allow(dead_code)]
5378 pub(crate) const fn from_words(words: [u64; N]) -> Self {
5379 Self { words, _sealed: () }
5380 }
5381
5382 #[inline]
5384 #[must_use]
5385 #[allow(dead_code)]
5386 pub(crate) const fn zero() -> Self {
5387 Self {
5388 words: [0u64; N],
5389 _sealed: (),
5390 }
5391 }
5392
5393 #[inline]
5395 #[must_use]
5396 pub const fn words(&self) -> &[u64; N] {
5397 &self.words
5398 }
5399
5400 #[inline]
5402 #[must_use]
5403 #[allow(dead_code)]
5404 pub(crate) const fn wrapping_add(self, other: Self) -> Self {
5405 let mut out = [0u64; N];
5406 let mut carry: u64 = 0;
5407 let mut i = 0;
5408 while i < N {
5409 let (s1, c1) = self.words[i].overflowing_add(other.words[i]);
5410 let (s2, c2) = s1.overflowing_add(carry);
5411 out[i] = s2;
5412 carry = (c1 as u64) | (c2 as u64);
5413 i += 1;
5414 }
5415 Self {
5416 words: out,
5417 _sealed: (),
5418 }
5419 }
5420
5421 #[inline]
5423 #[must_use]
5424 #[allow(dead_code)]
5425 pub(crate) const fn wrapping_sub(self, other: Self) -> Self {
5426 let mut out = [0u64; N];
5427 let mut borrow: u64 = 0;
5428 let mut i = 0;
5429 while i < N {
5430 let (d1, b1) = self.words[i].overflowing_sub(other.words[i]);
5431 let (d2, b2) = d1.overflowing_sub(borrow);
5432 out[i] = d2;
5433 borrow = (b1 as u64) | (b2 as u64);
5434 i += 1;
5435 }
5436 Self {
5437 words: out,
5438 _sealed: (),
5439 }
5440 }
5441
5442 #[inline]
5447 #[must_use]
5448 #[allow(dead_code)]
5449 pub(crate) const fn wrapping_mul(self, other: Self) -> Self {
5450 let mut out = [0u64; N];
5451 let mut i = 0;
5452 while i < N {
5453 let mut carry: u128 = 0;
5454 let mut j = 0;
5455 while j < N - i {
5456 let prod = (self.words[i] as u128) * (other.words[j] as u128)
5457 + (out[i + j] as u128)
5458 + carry;
5459 out[i + j] = prod as u64;
5460 carry = prod >> 64;
5461 j += 1;
5462 }
5463 i += 1;
5464 }
5465 Self {
5466 words: out,
5467 _sealed: (),
5468 }
5469 }
5470
5471 #[inline]
5473 #[must_use]
5474 #[allow(dead_code)]
5475 pub(crate) const fn xor(self, other: Self) -> Self {
5476 let mut out = [0u64; N];
5477 let mut i = 0;
5478 while i < N {
5479 out[i] = self.words[i] ^ other.words[i];
5480 i += 1;
5481 }
5482 Self {
5483 words: out,
5484 _sealed: (),
5485 }
5486 }
5487
5488 #[inline]
5490 #[must_use]
5491 #[allow(dead_code)]
5492 pub(crate) const fn and(self, other: Self) -> Self {
5493 let mut out = [0u64; N];
5494 let mut i = 0;
5495 while i < N {
5496 out[i] = self.words[i] & other.words[i];
5497 i += 1;
5498 }
5499 Self {
5500 words: out,
5501 _sealed: (),
5502 }
5503 }
5504
5505 #[inline]
5507 #[must_use]
5508 #[allow(dead_code)]
5509 pub(crate) const fn or(self, other: Self) -> Self {
5510 let mut out = [0u64; N];
5511 let mut i = 0;
5512 while i < N {
5513 out[i] = self.words[i] | other.words[i];
5514 i += 1;
5515 }
5516 Self {
5517 words: out,
5518 _sealed: (),
5519 }
5520 }
5521
5522 #[inline]
5524 #[must_use]
5525 #[allow(dead_code)]
5526 pub(crate) const fn not(self) -> Self {
5527 let mut out = [0u64; N];
5528 let mut i = 0;
5529 while i < N {
5530 out[i] = !self.words[i];
5531 i += 1;
5532 }
5533 Self {
5534 words: out,
5535 _sealed: (),
5536 }
5537 }
5538
5539 #[inline]
5543 #[must_use]
5544 #[allow(dead_code)]
5545 pub(crate) const fn mask_high_bits(self, bits: u32) -> Self {
5546 let mut out = self.words;
5547 let high_word_idx = (bits / 64) as usize;
5548 let low_bits_in_high_word = bits % 64;
5549 if low_bits_in_high_word != 0 && high_word_idx < N {
5550 let mask = (1u64 << low_bits_in_high_word) - 1;
5551 out[high_word_idx] &= mask;
5552 let mut i = high_word_idx + 1;
5554 while i < N {
5555 out[i] = 0;
5556 i += 1;
5557 }
5558 } else if low_bits_in_high_word == 0 && high_word_idx < N {
5559 let mut i = high_word_idx;
5561 while i < N {
5562 out[i] = 0;
5563 i += 1;
5564 }
5565 }
5566 Self {
5567 words: out,
5568 _sealed: (),
5569 }
5570 }
5571}
5572
5573pub trait OntologyTarget: ontology_target_sealed::Sealed {}
5578
5579#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5581pub struct GroundingCertificate {
5582 witt_bits: u16,
5583 content_fingerprint: ContentFingerprint,
5588}
5589
5590impl GroundingCertificate {
5591 #[inline]
5594 #[must_use]
5595 pub const fn witt_bits(&self) -> u16 {
5596 self.witt_bits
5597 }
5598
5599 #[inline]
5605 #[must_use]
5606 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5607 self.content_fingerprint
5608 }
5609
5610 #[inline]
5615 #[must_use]
5616 #[allow(dead_code)]
5617 pub(crate) const fn with_level_and_fingerprint_const(
5618 witt_bits: u16,
5619 content_fingerprint: ContentFingerprint,
5620 ) -> Self {
5621 Self {
5622 witt_bits,
5623 content_fingerprint,
5624 }
5625 }
5626}
5627
5628#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5630pub struct LiftChainCertificate {
5631 witt_bits: u16,
5632 content_fingerprint: ContentFingerprint,
5637}
5638
5639impl LiftChainCertificate {
5640 #[inline]
5643 #[must_use]
5644 pub const fn witt_bits(&self) -> u16 {
5645 self.witt_bits
5646 }
5647
5648 #[inline]
5654 #[must_use]
5655 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5656 self.content_fingerprint
5657 }
5658
5659 #[inline]
5664 #[must_use]
5665 #[allow(dead_code)]
5666 pub(crate) const fn with_level_and_fingerprint_const(
5667 witt_bits: u16,
5668 content_fingerprint: ContentFingerprint,
5669 ) -> Self {
5670 Self {
5671 witt_bits,
5672 content_fingerprint,
5673 }
5674 }
5675}
5676
5677#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5679pub struct InhabitanceCertificate {
5680 witt_bits: u16,
5681 content_fingerprint: ContentFingerprint,
5686}
5687
5688impl InhabitanceCertificate {
5689 #[inline]
5692 #[must_use]
5693 pub const fn witt_bits(&self) -> u16 {
5694 self.witt_bits
5695 }
5696
5697 #[inline]
5703 #[must_use]
5704 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5705 self.content_fingerprint
5706 }
5707
5708 #[inline]
5713 #[must_use]
5714 #[allow(dead_code)]
5715 pub(crate) const fn with_level_and_fingerprint_const(
5716 witt_bits: u16,
5717 content_fingerprint: ContentFingerprint,
5718 ) -> Self {
5719 Self {
5720 witt_bits,
5721 content_fingerprint,
5722 }
5723 }
5724}
5725
5726#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5728pub struct CompletenessCertificate {
5729 witt_bits: u16,
5730 content_fingerprint: ContentFingerprint,
5735}
5736
5737impl CompletenessCertificate {
5738 #[inline]
5741 #[must_use]
5742 pub const fn witt_bits(&self) -> u16 {
5743 self.witt_bits
5744 }
5745
5746 #[inline]
5752 #[must_use]
5753 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5754 self.content_fingerprint
5755 }
5756
5757 #[inline]
5762 #[must_use]
5763 #[allow(dead_code)]
5764 pub(crate) const fn with_level_and_fingerprint_const(
5765 witt_bits: u16,
5766 content_fingerprint: ContentFingerprint,
5767 ) -> Self {
5768 Self {
5769 witt_bits,
5770 content_fingerprint,
5771 }
5772 }
5773}
5774
5775#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5777pub struct MultiplicationCertificate {
5778 witt_bits: u16,
5779 content_fingerprint: ContentFingerprint,
5784}
5785
5786impl MultiplicationCertificate {
5787 #[inline]
5790 #[must_use]
5791 pub const fn witt_bits(&self) -> u16 {
5792 self.witt_bits
5793 }
5794
5795 #[inline]
5801 #[must_use]
5802 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5803 self.content_fingerprint
5804 }
5805
5806 #[inline]
5811 #[must_use]
5812 #[allow(dead_code)]
5813 pub(crate) const fn with_level_and_fingerprint_const(
5814 witt_bits: u16,
5815 content_fingerprint: ContentFingerprint,
5816 ) -> Self {
5817 Self {
5818 witt_bits,
5819 content_fingerprint,
5820 }
5821 }
5822}
5823
5824#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5826pub struct PartitionCertificate {
5827 witt_bits: u16,
5828 content_fingerprint: ContentFingerprint,
5833}
5834
5835impl PartitionCertificate {
5836 #[inline]
5839 #[must_use]
5840 pub const fn witt_bits(&self) -> u16 {
5841 self.witt_bits
5842 }
5843
5844 #[inline]
5850 #[must_use]
5851 pub const fn content_fingerprint(&self) -> ContentFingerprint {
5852 self.content_fingerprint
5853 }
5854
5855 #[inline]
5860 #[must_use]
5861 #[allow(dead_code)]
5862 pub(crate) const fn with_level_and_fingerprint_const(
5863 witt_bits: u16,
5864 content_fingerprint: ContentFingerprint,
5865 ) -> Self {
5866 Self {
5867 witt_bits,
5868 content_fingerprint,
5869 }
5870 }
5871}
5872
5873#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5875pub struct GenericImpossibilityWitness {
5876 identity: Option<&'static str>,
5881}
5882
5883impl Default for GenericImpossibilityWitness {
5884 #[inline]
5885 fn default() -> Self {
5886 Self { identity: None }
5887 }
5888}
5889
5890impl GenericImpossibilityWitness {
5891 #[inline]
5896 #[must_use]
5897 pub const fn for_identity(identity: &'static str) -> Self {
5898 Self {
5899 identity: Some(identity),
5900 }
5901 }
5902
5903 #[inline]
5905 #[must_use]
5906 pub const fn identity(&self) -> Option<&'static str> {
5907 self.identity
5908 }
5909}
5910
5911#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
5913pub struct InhabitanceImpossibilityWitness {
5914 _private: (),
5915}
5916
5917#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
5919pub struct ConstrainedTypeInput {
5920 _private: (),
5921}
5922
5923impl core::fmt::Display for GenericImpossibilityWitness {
5924 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
5925 match self.identity {
5926 Some(iri) => write!(f, "GenericImpossibilityWitness({iri})"),
5927 None => f.write_str("GenericImpossibilityWitness"),
5928 }
5929 }
5930}
5931impl core::error::Error for GenericImpossibilityWitness {}
5932
5933impl core::fmt::Display for InhabitanceImpossibilityWitness {
5934 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
5935 f.write_str("InhabitanceImpossibilityWitness")
5936 }
5937}
5938impl core::error::Error for InhabitanceImpossibilityWitness {}
5939
5940impl LiftChainCertificate {
5941 #[inline]
5943 #[must_use]
5944 pub const fn target_level(&self) -> WittLevel {
5945 WittLevel::new(self.witt_bits as u32)
5946 }
5947}
5948
5949impl InhabitanceCertificate {
5950 #[inline]
5954 #[must_use]
5955 pub const fn witness(&self) -> Option<&'static [u8]> {
5956 None
5957 }
5958}
5959
5960pub(crate) mod ontology_target_sealed {
5961 pub trait Sealed {}
5963 impl Sealed for super::GroundingCertificate {}
5964 impl Sealed for super::LiftChainCertificate {}
5965 impl Sealed for super::InhabitanceCertificate {}
5966 impl Sealed for super::CompletenessCertificate {}
5967 impl Sealed for super::MultiplicationCertificate {}
5968 impl Sealed for super::PartitionCertificate {}
5969 impl Sealed for super::GenericImpossibilityWitness {}
5970 impl Sealed for super::InhabitanceImpossibilityWitness {}
5971 impl Sealed for super::ConstrainedTypeInput {}
5972 impl Sealed for super::PartitionProductWitness {}
5973 impl Sealed for super::PartitionCoproductWitness {}
5974 impl Sealed for super::CartesianProductWitness {}
5975 impl Sealed for super::CompileUnit<'_> {}
5976}
5977
5978impl OntologyTarget for GroundingCertificate {}
5979impl OntologyTarget for LiftChainCertificate {}
5980impl OntologyTarget for InhabitanceCertificate {}
5981impl OntologyTarget for CompletenessCertificate {}
5982impl OntologyTarget for MultiplicationCertificate {}
5983impl OntologyTarget for PartitionCertificate {}
5984impl OntologyTarget for GenericImpossibilityWitness {}
5985impl OntologyTarget for InhabitanceImpossibilityWitness {}
5986impl OntologyTarget for ConstrainedTypeInput {}
5987impl OntologyTarget for PartitionProductWitness {}
5988impl OntologyTarget for PartitionCoproductWitness {}
5989impl OntologyTarget for CartesianProductWitness {}
5990impl OntologyTarget for CompileUnit<'_> {}
5991
5992#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
5995pub struct CompletenessAuditTrail {
5996 _private: (),
5997}
5998
5999#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
6001pub struct ChainAuditTrail {
6002 _private: (),
6003}
6004
6005#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
6007pub struct GeodesicEvidenceBundle {
6008 _private: (),
6009}
6010
6011#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6017pub struct TransformCertificate {
6018 witt_bits: u16,
6019 content_fingerprint: ContentFingerprint,
6020 _private: (),
6021}
6022
6023impl TransformCertificate {
6024 #[inline]
6028 #[must_use]
6029 #[allow(dead_code)]
6030 pub(crate) const fn with_level_and_fingerprint_const(
6031 witt_bits: u16,
6032 content_fingerprint: ContentFingerprint,
6033 ) -> Self {
6034 Self {
6035 witt_bits,
6036 content_fingerprint,
6037 _private: (),
6038 }
6039 }
6040
6041 #[inline]
6044 #[must_use]
6045 #[allow(dead_code)]
6046 pub(crate) const fn empty_const() -> Self {
6047 Self {
6048 witt_bits: 0,
6049 content_fingerprint: ContentFingerprint::zero(),
6050 _private: (),
6051 }
6052 }
6053
6054 #[inline]
6056 #[must_use]
6057 pub const fn witt_bits(&self) -> u16 {
6058 self.witt_bits
6059 }
6060
6061 #[inline]
6063 #[must_use]
6064 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6065 self.content_fingerprint
6066 }
6067}
6068
6069#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6075pub struct IsometryCertificate {
6076 witt_bits: u16,
6077 content_fingerprint: ContentFingerprint,
6078 _private: (),
6079}
6080
6081impl IsometryCertificate {
6082 #[inline]
6086 #[must_use]
6087 #[allow(dead_code)]
6088 pub(crate) const fn with_level_and_fingerprint_const(
6089 witt_bits: u16,
6090 content_fingerprint: ContentFingerprint,
6091 ) -> Self {
6092 Self {
6093 witt_bits,
6094 content_fingerprint,
6095 _private: (),
6096 }
6097 }
6098
6099 #[inline]
6102 #[must_use]
6103 #[allow(dead_code)]
6104 pub(crate) const fn empty_const() -> Self {
6105 Self {
6106 witt_bits: 0,
6107 content_fingerprint: ContentFingerprint::zero(),
6108 _private: (),
6109 }
6110 }
6111
6112 #[inline]
6114 #[must_use]
6115 pub const fn witt_bits(&self) -> u16 {
6116 self.witt_bits
6117 }
6118
6119 #[inline]
6121 #[must_use]
6122 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6123 self.content_fingerprint
6124 }
6125}
6126
6127#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6133pub struct InvolutionCertificate {
6134 witt_bits: u16,
6135 content_fingerprint: ContentFingerprint,
6136 _private: (),
6137}
6138
6139impl InvolutionCertificate {
6140 #[inline]
6144 #[must_use]
6145 #[allow(dead_code)]
6146 pub(crate) const fn with_level_and_fingerprint_const(
6147 witt_bits: u16,
6148 content_fingerprint: ContentFingerprint,
6149 ) -> Self {
6150 Self {
6151 witt_bits,
6152 content_fingerprint,
6153 _private: (),
6154 }
6155 }
6156
6157 #[inline]
6160 #[must_use]
6161 #[allow(dead_code)]
6162 pub(crate) const fn empty_const() -> Self {
6163 Self {
6164 witt_bits: 0,
6165 content_fingerprint: ContentFingerprint::zero(),
6166 _private: (),
6167 }
6168 }
6169
6170 #[inline]
6172 #[must_use]
6173 pub const fn witt_bits(&self) -> u16 {
6174 self.witt_bits
6175 }
6176
6177 #[inline]
6179 #[must_use]
6180 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6181 self.content_fingerprint
6182 }
6183}
6184
6185#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6191pub struct GeodesicCertificate {
6192 witt_bits: u16,
6193 content_fingerprint: ContentFingerprint,
6194 _private: (),
6195}
6196
6197impl GeodesicCertificate {
6198 #[inline]
6202 #[must_use]
6203 #[allow(dead_code)]
6204 pub(crate) const fn with_level_and_fingerprint_const(
6205 witt_bits: u16,
6206 content_fingerprint: ContentFingerprint,
6207 ) -> Self {
6208 Self {
6209 witt_bits,
6210 content_fingerprint,
6211 _private: (),
6212 }
6213 }
6214
6215 #[inline]
6218 #[must_use]
6219 #[allow(dead_code)]
6220 pub(crate) const fn empty_const() -> Self {
6221 Self {
6222 witt_bits: 0,
6223 content_fingerprint: ContentFingerprint::zero(),
6224 _private: (),
6225 }
6226 }
6227
6228 #[inline]
6230 #[must_use]
6231 pub const fn witt_bits(&self) -> u16 {
6232 self.witt_bits
6233 }
6234
6235 #[inline]
6237 #[must_use]
6238 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6239 self.content_fingerprint
6240 }
6241}
6242
6243#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6249pub struct MeasurementCertificate {
6250 witt_bits: u16,
6251 content_fingerprint: ContentFingerprint,
6252 _private: (),
6253}
6254
6255impl MeasurementCertificate {
6256 #[inline]
6260 #[must_use]
6261 #[allow(dead_code)]
6262 pub(crate) const fn with_level_and_fingerprint_const(
6263 witt_bits: u16,
6264 content_fingerprint: ContentFingerprint,
6265 ) -> Self {
6266 Self {
6267 witt_bits,
6268 content_fingerprint,
6269 _private: (),
6270 }
6271 }
6272
6273 #[inline]
6276 #[must_use]
6277 #[allow(dead_code)]
6278 pub(crate) const fn empty_const() -> Self {
6279 Self {
6280 witt_bits: 0,
6281 content_fingerprint: ContentFingerprint::zero(),
6282 _private: (),
6283 }
6284 }
6285
6286 #[inline]
6288 #[must_use]
6289 pub const fn witt_bits(&self) -> u16 {
6290 self.witt_bits
6291 }
6292
6293 #[inline]
6295 #[must_use]
6296 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6297 self.content_fingerprint
6298 }
6299}
6300
6301#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6307pub struct BornRuleVerification {
6308 witt_bits: u16,
6309 content_fingerprint: ContentFingerprint,
6310 _private: (),
6311}
6312
6313impl BornRuleVerification {
6314 #[inline]
6318 #[must_use]
6319 #[allow(dead_code)]
6320 pub(crate) const fn with_level_and_fingerprint_const(
6321 witt_bits: u16,
6322 content_fingerprint: ContentFingerprint,
6323 ) -> Self {
6324 Self {
6325 witt_bits,
6326 content_fingerprint,
6327 _private: (),
6328 }
6329 }
6330
6331 #[inline]
6334 #[must_use]
6335 #[allow(dead_code)]
6336 pub(crate) const fn empty_const() -> Self {
6337 Self {
6338 witt_bits: 0,
6339 content_fingerprint: ContentFingerprint::zero(),
6340 _private: (),
6341 }
6342 }
6343
6344 #[inline]
6346 #[must_use]
6347 pub const fn witt_bits(&self) -> u16 {
6348 self.witt_bits
6349 }
6350
6351 #[inline]
6353 #[must_use]
6354 pub const fn content_fingerprint(&self) -> ContentFingerprint {
6355 self.content_fingerprint
6356 }
6357}
6358
6359pub trait Certificate: certificate_sealed::Sealed {
6363 const IRI: &'static str;
6365 type Evidence;
6367}
6368
6369pub(crate) mod certificate_sealed {
6370 pub trait Sealed {}
6372 impl Sealed for super::GroundingCertificate {}
6373 impl Sealed for super::LiftChainCertificate {}
6374 impl Sealed for super::InhabitanceCertificate {}
6375 impl Sealed for super::CompletenessCertificate {}
6376 impl Sealed for super::TransformCertificate {}
6377 impl Sealed for super::IsometryCertificate {}
6378 impl Sealed for super::InvolutionCertificate {}
6379 impl Sealed for super::GeodesicCertificate {}
6380 impl Sealed for super::MeasurementCertificate {}
6381 impl Sealed for super::BornRuleVerification {}
6382 impl Sealed for super::MultiplicationCertificate {}
6383 impl Sealed for super::PartitionCertificate {}
6384 impl Sealed for super::GenericImpossibilityWitness {}
6385 impl Sealed for super::InhabitanceImpossibilityWitness {}
6386 impl Sealed for super::PartitionProductWitness {}
6387 impl Sealed for super::PartitionCoproductWitness {}
6388 impl Sealed for super::CartesianProductWitness {}
6389}
6390
6391impl Certificate for GroundingCertificate {
6392 const IRI: &'static str = "https://uor.foundation/cert/GroundingCertificate";
6393 type Evidence = ();
6394}
6395
6396impl Certificate for LiftChainCertificate {
6397 const IRI: &'static str = "https://uor.foundation/cert/LiftChainCertificate";
6398 type Evidence = ChainAuditTrail;
6399}
6400
6401impl Certificate for InhabitanceCertificate {
6402 const IRI: &'static str = "https://uor.foundation/cert/InhabitanceCertificate";
6403 type Evidence = ();
6404}
6405
6406impl Certificate for CompletenessCertificate {
6407 const IRI: &'static str = "https://uor.foundation/cert/CompletenessCertificate";
6408 type Evidence = CompletenessAuditTrail;
6409}
6410
6411impl Certificate for TransformCertificate {
6412 const IRI: &'static str = "https://uor.foundation/cert/TransformCertificate";
6413 type Evidence = ();
6414}
6415
6416impl Certificate for IsometryCertificate {
6417 const IRI: &'static str = "https://uor.foundation/cert/IsometryCertificate";
6418 type Evidence = ();
6419}
6420
6421impl Certificate for InvolutionCertificate {
6422 const IRI: &'static str = "https://uor.foundation/cert/InvolutionCertificate";
6423 type Evidence = ();
6424}
6425
6426impl Certificate for GeodesicCertificate {
6427 const IRI: &'static str = "https://uor.foundation/cert/GeodesicCertificate";
6428 type Evidence = GeodesicEvidenceBundle;
6429}
6430
6431impl Certificate for MeasurementCertificate {
6432 const IRI: &'static str = "https://uor.foundation/cert/MeasurementCertificate";
6433 type Evidence = ();
6434}
6435
6436impl Certificate for BornRuleVerification {
6437 const IRI: &'static str = "https://uor.foundation/cert/BornRuleVerification";
6438 type Evidence = ();
6439}
6440
6441impl Certificate for MultiplicationCertificate {
6442 const IRI: &'static str = "https://uor.foundation/cert/MultiplicationCertificate";
6443 type Evidence = MultiplicationEvidence;
6444}
6445
6446impl Certificate for PartitionCertificate {
6447 const IRI: &'static str = "https://uor.foundation/cert/PartitionCertificate";
6448 type Evidence = ();
6449}
6450
6451impl Certificate for GenericImpossibilityWitness {
6452 const IRI: &'static str = "https://uor.foundation/cert/GenericImpossibilityCertificate";
6453 type Evidence = ();
6454}
6455
6456impl Certificate for InhabitanceImpossibilityWitness {
6457 const IRI: &'static str = "https://uor.foundation/cert/InhabitanceImpossibilityCertificate";
6458 type Evidence = ();
6459}
6460
6461pub(crate) mod certify_const_mint {
6467 use super::{Certificate, ContentFingerprint};
6468 pub trait MintWithLevelFingerprint: Certificate {
6469 fn mint_with_level_fingerprint(
6470 witt_bits: u16,
6471 content_fingerprint: ContentFingerprint,
6472 ) -> Self;
6473 }
6474 impl MintWithLevelFingerprint for super::GroundingCertificate {
6475 #[inline]
6476 fn mint_with_level_fingerprint(
6477 witt_bits: u16,
6478 content_fingerprint: ContentFingerprint,
6479 ) -> Self {
6480 super::GroundingCertificate::with_level_and_fingerprint_const(
6481 witt_bits,
6482 content_fingerprint,
6483 )
6484 }
6485 }
6486 impl MintWithLevelFingerprint for super::LiftChainCertificate {
6487 #[inline]
6488 fn mint_with_level_fingerprint(
6489 witt_bits: u16,
6490 content_fingerprint: ContentFingerprint,
6491 ) -> Self {
6492 super::LiftChainCertificate::with_level_and_fingerprint_const(
6493 witt_bits,
6494 content_fingerprint,
6495 )
6496 }
6497 }
6498 impl MintWithLevelFingerprint for super::InhabitanceCertificate {
6499 #[inline]
6500 fn mint_with_level_fingerprint(
6501 witt_bits: u16,
6502 content_fingerprint: ContentFingerprint,
6503 ) -> Self {
6504 super::InhabitanceCertificate::with_level_and_fingerprint_const(
6505 witt_bits,
6506 content_fingerprint,
6507 )
6508 }
6509 }
6510 impl MintWithLevelFingerprint for super::CompletenessCertificate {
6511 #[inline]
6512 fn mint_with_level_fingerprint(
6513 witt_bits: u16,
6514 content_fingerprint: ContentFingerprint,
6515 ) -> Self {
6516 super::CompletenessCertificate::with_level_and_fingerprint_const(
6517 witt_bits,
6518 content_fingerprint,
6519 )
6520 }
6521 }
6522 impl MintWithLevelFingerprint for super::MultiplicationCertificate {
6523 #[inline]
6524 fn mint_with_level_fingerprint(
6525 witt_bits: u16,
6526 content_fingerprint: ContentFingerprint,
6527 ) -> Self {
6528 super::MultiplicationCertificate::with_level_and_fingerprint_const(
6529 witt_bits,
6530 content_fingerprint,
6531 )
6532 }
6533 }
6534 impl MintWithLevelFingerprint for super::PartitionCertificate {
6535 #[inline]
6536 fn mint_with_level_fingerprint(
6537 witt_bits: u16,
6538 content_fingerprint: ContentFingerprint,
6539 ) -> Self {
6540 super::PartitionCertificate::with_level_and_fingerprint_const(
6541 witt_bits,
6542 content_fingerprint,
6543 )
6544 }
6545 }
6546 impl MintWithLevelFingerprint for super::TransformCertificate {
6547 #[inline]
6548 fn mint_with_level_fingerprint(
6549 witt_bits: u16,
6550 content_fingerprint: ContentFingerprint,
6551 ) -> Self {
6552 super::TransformCertificate::with_level_and_fingerprint_const(
6553 witt_bits,
6554 content_fingerprint,
6555 )
6556 }
6557 }
6558 impl MintWithLevelFingerprint for super::IsometryCertificate {
6559 #[inline]
6560 fn mint_with_level_fingerprint(
6561 witt_bits: u16,
6562 content_fingerprint: ContentFingerprint,
6563 ) -> Self {
6564 super::IsometryCertificate::with_level_and_fingerprint_const(
6565 witt_bits,
6566 content_fingerprint,
6567 )
6568 }
6569 }
6570 impl MintWithLevelFingerprint for super::InvolutionCertificate {
6571 #[inline]
6572 fn mint_with_level_fingerprint(
6573 witt_bits: u16,
6574 content_fingerprint: ContentFingerprint,
6575 ) -> Self {
6576 super::InvolutionCertificate::with_level_and_fingerprint_const(
6577 witt_bits,
6578 content_fingerprint,
6579 )
6580 }
6581 }
6582 impl MintWithLevelFingerprint for super::GeodesicCertificate {
6583 #[inline]
6584 fn mint_with_level_fingerprint(
6585 witt_bits: u16,
6586 content_fingerprint: ContentFingerprint,
6587 ) -> Self {
6588 super::GeodesicCertificate::with_level_and_fingerprint_const(
6589 witt_bits,
6590 content_fingerprint,
6591 )
6592 }
6593 }
6594 impl MintWithLevelFingerprint for super::MeasurementCertificate {
6595 #[inline]
6596 fn mint_with_level_fingerprint(
6597 witt_bits: u16,
6598 content_fingerprint: ContentFingerprint,
6599 ) -> Self {
6600 super::MeasurementCertificate::with_level_and_fingerprint_const(
6601 witt_bits,
6602 content_fingerprint,
6603 )
6604 }
6605 }
6606 impl MintWithLevelFingerprint for super::BornRuleVerification {
6607 #[inline]
6608 fn mint_with_level_fingerprint(
6609 witt_bits: u16,
6610 content_fingerprint: ContentFingerprint,
6611 ) -> Self {
6612 super::BornRuleVerification::with_level_and_fingerprint_const(
6613 witt_bits,
6614 content_fingerprint,
6615 )
6616 }
6617 }
6618}
6619
6620#[derive(Debug, Clone)]
6625pub struct Certified<C: Certificate> {
6626 inner: C,
6628 uor_time: UorTime,
6630 _private: (),
6632}
6633
6634impl<C: Certificate> Certified<C> {
6635 #[inline]
6637 #[must_use]
6638 pub const fn certificate(&self) -> &C {
6639 &self.inner
6640 }
6641
6642 #[inline]
6644 #[must_use]
6645 pub const fn iri(&self) -> &'static str {
6646 C::IRI
6647 }
6648
6649 #[inline]
6655 #[must_use]
6656 pub const fn uor_time(&self) -> UorTime {
6657 self.uor_time
6658 }
6659
6660 #[inline]
6667 #[allow(dead_code)]
6668 pub(crate) const fn new(inner: C) -> Self {
6669 let steps = C::IRI.len() as u64;
6672 let landauer = LandauerBudget::new((steps as f64) * core::f64::consts::LN_2);
6673 let uor_time = UorTime::new(landauer, steps);
6674 Self {
6675 inner,
6676 uor_time,
6677 _private: (),
6678 }
6679 }
6680}
6681
6682#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6688pub struct MulContext {
6689 pub stack_budget_bytes: u64,
6692 pub const_eval: bool,
6696 pub limb_count: usize,
6701}
6702
6703impl MulContext {
6704 #[inline]
6706 #[must_use]
6707 pub const fn new(stack_budget_bytes: u64, const_eval: bool, limb_count: usize) -> Self {
6708 Self {
6709 stack_budget_bytes,
6710 const_eval,
6711 limb_count,
6712 }
6713 }
6714}
6715
6716#[derive(Debug, Clone, Copy, PartialEq)]
6720pub struct MultiplicationEvidence {
6721 splitting_factor: u32,
6722 sub_multiplication_count: u32,
6723 landauer_cost_nats_bits: u64,
6724}
6725
6726impl MultiplicationEvidence {
6727 #[inline]
6729 #[must_use]
6730 pub const fn splitting_factor(&self) -> u32 {
6731 self.splitting_factor
6732 }
6733
6734 #[inline]
6736 #[must_use]
6737 pub const fn sub_multiplication_count(&self) -> u32 {
6738 self.sub_multiplication_count
6739 }
6740
6741 #[inline]
6743 #[must_use]
6744 pub const fn landauer_cost_nats_bits(&self) -> u64 {
6745 self.landauer_cost_nats_bits
6746 }
6747}
6748
6749impl MultiplicationCertificate {
6750 #[inline]
6754 #[must_use]
6755 pub(crate) fn with_evidence(
6756 splitting_factor: u32,
6757 sub_multiplication_count: u32,
6758 landauer_cost_nats_bits: u64,
6759 content_fingerprint: ContentFingerprint,
6760 ) -> Self {
6761 let _ = MultiplicationEvidence {
6762 splitting_factor,
6763 sub_multiplication_count,
6764 landauer_cost_nats_bits,
6765 };
6766 Self::with_level_and_fingerprint_const(32, content_fingerprint)
6767 }
6768}
6769
6770pub const MAX_BETTI_DIMENSION: usize =
6778 <crate::DefaultHostBounds as crate::HostBounds>::BETTI_DIMENSION_MAX;
6779
6780#[derive(Debug)]
6785pub struct SigmaValue<H: HostTypes = crate::DefaultHostTypes> {
6786 value: H::Decimal,
6787 _phantom: core::marker::PhantomData<H>,
6788 _sealed: (),
6789}
6790
6791impl<H: HostTypes> Copy for SigmaValue<H> {}
6792impl<H: HostTypes> Clone for SigmaValue<H> {
6793 #[inline]
6794 fn clone(&self) -> Self {
6795 *self
6796 }
6797}
6798impl<H: HostTypes> PartialEq for SigmaValue<H> {
6799 #[inline]
6800 fn eq(&self, other: &Self) -> bool {
6801 self.value == other.value
6802 }
6803}
6804
6805impl<H: HostTypes> SigmaValue<H> {
6806 #[inline]
6808 #[must_use]
6809 pub const fn value(&self) -> H::Decimal {
6810 self.value
6811 }
6812
6813 #[inline]
6816 #[must_use]
6817 #[allow(dead_code)]
6818 pub(crate) const fn new_unchecked(value: H::Decimal) -> Self {
6819 Self {
6820 value,
6821 _phantom: core::marker::PhantomData,
6822 _sealed: (),
6823 }
6824 }
6825}
6826
6827#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6833pub struct Stratum<L> {
6834 value: u32,
6835 _level: PhantomData<L>,
6836 _sealed: (),
6837}
6838
6839impl<L> Stratum<L> {
6840 #[inline]
6842 #[must_use]
6843 pub const fn as_u32(&self) -> u32 {
6844 self.value
6845 }
6846
6847 #[inline]
6849 #[must_use]
6850 #[allow(dead_code)]
6851 pub(crate) const fn new(value: u32) -> Self {
6852 Self {
6853 value,
6854 _level: PhantomData,
6855 _sealed: (),
6856 }
6857 }
6858}
6859
6860#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6862pub struct DDeltaMetric {
6863 value: i64,
6864 _sealed: (),
6865}
6866
6867impl DDeltaMetric {
6868 #[inline]
6870 #[must_use]
6871 pub const fn as_i64(&self) -> i64 {
6872 self.value
6873 }
6874
6875 #[inline]
6877 #[must_use]
6878 #[allow(dead_code)]
6879 pub(crate) const fn new(value: i64) -> Self {
6880 Self { value, _sealed: () }
6881 }
6882}
6883
6884#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6886pub struct EulerMetric {
6887 value: i64,
6888 _sealed: (),
6889}
6890
6891impl EulerMetric {
6892 #[inline]
6894 #[must_use]
6895 pub const fn as_i64(&self) -> i64 {
6896 self.value
6897 }
6898
6899 #[inline]
6901 #[must_use]
6902 #[allow(dead_code)]
6903 pub(crate) const fn new(value: i64) -> Self {
6904 Self { value, _sealed: () }
6905 }
6906}
6907
6908#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6910pub struct ResidualMetric {
6911 value: u32,
6912 _sealed: (),
6913}
6914
6915impl ResidualMetric {
6916 #[inline]
6918 #[must_use]
6919 pub const fn as_u32(&self) -> u32 {
6920 self.value
6921 }
6922
6923 #[inline]
6925 #[must_use]
6926 #[allow(dead_code)]
6927 pub(crate) const fn new(value: u32) -> Self {
6928 Self { value, _sealed: () }
6929 }
6930}
6931
6932#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6935pub struct BettiMetric {
6936 values: [u32; MAX_BETTI_DIMENSION],
6937 _sealed: (),
6938}
6939
6940impl BettiMetric {
6941 #[inline]
6943 #[must_use]
6944 pub const fn as_array(&self) -> &[u32; MAX_BETTI_DIMENSION] {
6945 &self.values
6946 }
6947
6948 #[inline]
6951 #[must_use]
6952 pub const fn beta(&self, k: usize) -> u32 {
6953 if k < MAX_BETTI_DIMENSION {
6954 self.values[k]
6955 } else {
6956 0
6957 }
6958 }
6959
6960 #[inline]
6962 #[must_use]
6963 #[allow(dead_code)]
6964 pub(crate) const fn new(values: [u32; MAX_BETTI_DIMENSION]) -> Self {
6965 Self {
6966 values,
6967 _sealed: (),
6968 }
6969 }
6970}
6971
6972pub const JACOBIAN_MAX_SITES: usize =
6980 <crate::DefaultHostBounds as crate::HostBounds>::JACOBIAN_SITES_MAX;
6981
6982#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6987pub struct JacobianMetric<L> {
6988 entries: [i64; JACOBIAN_MAX_SITES],
6989 len: u16,
6990 _level: PhantomData<L>,
6991 _sealed: (),
6992}
6993
6994impl<L> JacobianMetric<L> {
6995 #[inline]
6997 #[must_use]
6998 #[allow(dead_code)]
6999 pub(crate) const fn zero(len: u16) -> Self {
7000 Self {
7001 entries: [0i64; JACOBIAN_MAX_SITES],
7002 len,
7003 _level: PhantomData,
7004 _sealed: (),
7005 }
7006 }
7007
7008 #[inline]
7012 #[must_use]
7013 #[allow(dead_code)]
7014 pub(crate) const fn from_entries(entries: [i64; JACOBIAN_MAX_SITES], len: u16) -> Self {
7015 Self {
7016 entries,
7017 len,
7018 _level: PhantomData,
7019 _sealed: (),
7020 }
7021 }
7022
7023 #[inline]
7025 #[must_use]
7026 pub const fn entries(&self) -> &[i64; JACOBIAN_MAX_SITES] {
7027 &self.entries
7028 }
7029
7030 #[inline]
7032 #[must_use]
7033 pub const fn len(&self) -> u16 {
7034 self.len
7035 }
7036
7037 #[inline]
7039 #[must_use]
7040 pub const fn is_empty(&self) -> bool {
7041 self.len == 0
7042 }
7043}
7044
7045#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7049#[non_exhaustive]
7050pub enum PartitionComponent {
7051 Irreducible,
7053 Reducible,
7055 Units,
7057 Exterior,
7059}
7060
7061pub trait GroundedShape: crate::pipeline::__sdk_seal::Sealed {}
7072impl GroundedShape for ConstrainedTypeInput {}
7073
7074#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7083pub struct ContentAddress {
7084 raw: u128,
7085 _sealed: (),
7086}
7087
7088impl ContentAddress {
7089 #[inline]
7093 #[must_use]
7094 pub const fn zero() -> Self {
7095 Self {
7096 raw: 0,
7097 _sealed: (),
7098 }
7099 }
7100
7101 #[inline]
7103 #[must_use]
7104 pub const fn as_u128(&self) -> u128 {
7105 self.raw
7106 }
7107
7108 #[inline]
7110 #[must_use]
7111 pub const fn is_zero(&self) -> bool {
7112 self.raw == 0
7113 }
7114
7115 #[inline]
7119 #[must_use]
7120 pub const fn from_u128(raw: u128) -> Self {
7121 Self { raw, _sealed: () }
7122 }
7123
7124 #[inline]
7132 #[must_use]
7133 pub const fn from_u64_fingerprint(fingerprint: u64) -> Self {
7134 Self {
7135 raw: (fingerprint as u128) << 64,
7136 _sealed: (),
7137 }
7138 }
7139}
7140
7141impl Default for ContentAddress {
7142 #[inline]
7143 fn default() -> Self {
7144 Self::zero()
7145 }
7146}
7147
7148pub const TRACE_REPLAY_FORMAT_VERSION: u16 = 10;
7155
7156pub trait Hasher<const FP_MAX: usize = 32> {
7222 const OUTPUT_BYTES: usize;
7226
7227 fn initial() -> Self;
7229
7230 #[must_use]
7232 fn fold_byte(self, b: u8) -> Self;
7233
7234 #[inline]
7236 #[must_use]
7237 fn fold_bytes(mut self, bytes: &[u8]) -> Self
7238 where
7239 Self: Sized,
7240 {
7241 let mut i = 0;
7242 while i < bytes.len() {
7243 self = self.fold_byte(bytes[i]);
7244 i += 1;
7245 }
7246 self
7247 }
7248
7249 fn finalize(self) -> [u8; FP_MAX];
7253}
7254
7255#[derive(Debug, Clone, Copy)]
7261pub struct HashAxis<H: Hasher>(core::marker::PhantomData<H>);
7262
7263impl<H: Hasher> HashAxis<H> {
7264 pub const KERNEL_HASH: u32 = 0;
7268}
7269
7270impl<H: Hasher> crate::pipeline::__sdk_seal::Sealed for HashAxis<H> {}
7271impl<H: Hasher> crate::pipeline::SubstrateTermBody for HashAxis<H> {
7272 fn body_arena() -> &'static [Term] {
7273 &[]
7274 }
7275}
7276impl<H: Hasher> crate::pipeline::AxisExtension for HashAxis<H> {
7277 const AXIS_ADDRESS: &'static str = "https://uor.foundation/axis/HashAxis";
7278 const MAX_OUTPUT_BYTES: usize = <H as Hasher>::OUTPUT_BYTES;
7279 fn dispatch_kernel(
7280 kernel_id: u32,
7281 input: &[u8],
7282 out: &mut [u8],
7283 ) -> Result<usize, ShapeViolation> {
7284 if kernel_id != Self::KERNEL_HASH {
7285 return Err(ShapeViolation {
7286 shape_iri: "https://uor.foundation/axis/HashAxis",
7287 constraint_iri: "https://uor.foundation/axis/HashAxis/kernelId",
7288 property_iri: "https://uor.foundation/axis/kernelId",
7289 expected_range: "https://uor.foundation/axis/HashAxis/KERNEL_HASH",
7290 min_count: 0,
7291 max_count: 1,
7292 kind: crate::ViolationKind::ValueCheck,
7293 });
7294 }
7295 let mut hasher = <H as Hasher>::initial();
7296 hasher = hasher.fold_bytes(input);
7297 let digest = hasher.finalize();
7298 let n = <H as Hasher>::OUTPUT_BYTES.min(out.len()).min(digest.len());
7299 let mut i = 0;
7300 while i < n {
7301 out[i] = digest[i];
7302 i += 1;
7303 }
7304 Ok(n)
7305 }
7306}
7307
7308#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7321pub struct ContentFingerprint<const FP_MAX: usize = 32> {
7322 bytes: [u8; FP_MAX],
7323 width_bytes: u8,
7324 _sealed: (),
7325}
7326
7327impl<const FP_MAX: usize> ContentFingerprint<FP_MAX> {
7328 #[inline]
7333 #[must_use]
7334 #[allow(dead_code)]
7335 pub(crate) const fn zero() -> Self {
7336 Self {
7337 bytes: [0u8; FP_MAX],
7338 width_bytes: 0,
7339 _sealed: (),
7340 }
7341 }
7342
7343 #[inline]
7345 #[must_use]
7346 pub const fn is_zero(&self) -> bool {
7347 self.width_bytes == 0
7348 }
7349
7350 #[inline]
7352 #[must_use]
7353 pub const fn width_bytes(&self) -> u8 {
7354 self.width_bytes
7355 }
7356
7357 #[inline]
7359 #[must_use]
7360 pub const fn width_bits(&self) -> u16 {
7361 (self.width_bytes as u16) * 8
7362 }
7363
7364 #[inline]
7367 #[must_use]
7368 pub const fn as_bytes(&self) -> &[u8; FP_MAX] {
7369 &self.bytes
7370 }
7371
7372 #[inline]
7376 #[must_use]
7377 pub const fn from_buffer(bytes: [u8; FP_MAX], width_bytes: u8) -> Self {
7378 Self {
7379 bytes,
7380 width_bytes,
7381 _sealed: (),
7382 }
7383 }
7384}
7385
7386impl<const FP_MAX: usize> Default for ContentFingerprint<FP_MAX> {
7387 #[inline]
7388 fn default() -> Self {
7389 Self::zero()
7390 }
7391}
7392
7393#[inline]
7399#[must_use]
7400pub const fn primitive_op_discriminant(op: crate::PrimitiveOp) -> u8 {
7401 match op {
7402 crate::PrimitiveOp::Neg => 0,
7403 crate::PrimitiveOp::Bnot => 1,
7404 crate::PrimitiveOp::Succ => 2,
7405 crate::PrimitiveOp::Pred => 3,
7406 crate::PrimitiveOp::Add => 4,
7407 crate::PrimitiveOp::Sub => 5,
7408 crate::PrimitiveOp::Mul => 6,
7409 crate::PrimitiveOp::Xor => 7,
7410 crate::PrimitiveOp::And => 8,
7411 crate::PrimitiveOp::Or => 9,
7412 crate::PrimitiveOp::Le => 10,
7414 crate::PrimitiveOp::Lt => 11,
7415 crate::PrimitiveOp::Ge => 12,
7416 crate::PrimitiveOp::Gt => 13,
7417 crate::PrimitiveOp::Concat => 14,
7418 crate::PrimitiveOp::Div => 15,
7420 crate::PrimitiveOp::Mod => 16,
7421 crate::PrimitiveOp::Pow => 17,
7422 }
7423}
7424
7425#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7432#[non_exhaustive]
7433pub enum CertificateKind {
7434 Grounding,
7437 TowerCompleteness,
7439 IncrementalCompleteness,
7441 Inhabitance,
7443 Multiplication,
7445 TwoSat,
7447 HornSat,
7449 ResidualVerdict,
7451 CanonicalForm,
7453 TypeSynthesis,
7455 Homotopy,
7457 Monodromy,
7459 Moduli,
7461 JacobianGuided,
7463 Evaluation,
7465 Session,
7467 Superposition,
7469 Measurement,
7471 WittLevel,
7473 DihedralFactorization,
7475 Completeness,
7477 GeodesicValidator,
7479}
7480
7481#[inline]
7486#[must_use]
7487pub const fn certificate_kind_discriminant(kind: CertificateKind) -> u8 {
7488 match kind {
7489 CertificateKind::Grounding => 1,
7490 CertificateKind::TowerCompleteness => 2,
7491 CertificateKind::IncrementalCompleteness => 3,
7492 CertificateKind::Inhabitance => 4,
7493 CertificateKind::Multiplication => 5,
7494 CertificateKind::TwoSat => 6,
7495 CertificateKind::HornSat => 7,
7496 CertificateKind::ResidualVerdict => 8,
7497 CertificateKind::CanonicalForm => 9,
7498 CertificateKind::TypeSynthesis => 10,
7499 CertificateKind::Homotopy => 11,
7500 CertificateKind::Monodromy => 12,
7501 CertificateKind::Moduli => 13,
7502 CertificateKind::JacobianGuided => 14,
7503 CertificateKind::Evaluation => 15,
7504 CertificateKind::Session => 16,
7505 CertificateKind::Superposition => 17,
7506 CertificateKind::Measurement => 18,
7507 CertificateKind::WittLevel => 19,
7508 CertificateKind::DihedralFactorization => 20,
7509 CertificateKind::Completeness => 21,
7510 CertificateKind::GeodesicValidator => 22,
7511 }
7512}
7513
7514pub fn fold_constraint_ref<H: Hasher>(mut hasher: H, c: &crate::pipeline::ConstraintRef) -> H {
7521 use crate::pipeline::ConstraintRef as C;
7522 match c {
7523 C::Residue { modulus, residue } => {
7524 hasher = hasher.fold_byte(1);
7525 hasher = hasher.fold_bytes(&modulus.to_be_bytes());
7526 hasher = hasher.fold_bytes(&residue.to_be_bytes());
7527 }
7528 C::Hamming { bound } => {
7529 hasher = hasher.fold_byte(2);
7530 hasher = hasher.fold_bytes(&bound.to_be_bytes());
7531 }
7532 C::Depth { min, max } => {
7533 hasher = hasher.fold_byte(3);
7534 hasher = hasher.fold_bytes(&min.to_be_bytes());
7535 hasher = hasher.fold_bytes(&max.to_be_bytes());
7536 }
7537 C::Carry { site } => {
7538 hasher = hasher.fold_byte(4);
7539 hasher = hasher.fold_bytes(&site.to_be_bytes());
7540 }
7541 C::Site { position } => {
7542 hasher = hasher.fold_byte(5);
7543 hasher = hasher.fold_bytes(&position.to_be_bytes());
7544 }
7545 C::Affine {
7546 coefficients,
7547 coefficient_count,
7548 bias,
7549 } => {
7550 hasher = hasher.fold_byte(6);
7551 hasher = hasher.fold_bytes(&coefficient_count.to_be_bytes());
7552 let count = *coefficient_count as usize;
7553 let mut i = 0;
7554 while i < count && i < crate::pipeline::AFFINE_MAX_COEFFS {
7555 hasher = hasher.fold_bytes(&coefficients[i].to_be_bytes());
7556 i += 1;
7557 }
7558 hasher = hasher.fold_bytes(&bias.to_be_bytes());
7559 }
7560 C::SatClauses { clauses, num_vars } => {
7561 hasher = hasher.fold_byte(7);
7562 hasher = hasher.fold_bytes(&num_vars.to_be_bytes());
7563 hasher = hasher.fold_bytes(&(clauses.len() as u32).to_be_bytes());
7564 let mut i = 0;
7565 while i < clauses.len() {
7566 let clause = clauses[i];
7567 hasher = hasher.fold_bytes(&(clause.len() as u32).to_be_bytes());
7568 let mut j = 0;
7569 while j < clause.len() {
7570 let (var, neg) = clause[j];
7571 hasher = hasher.fold_bytes(&var.to_be_bytes());
7572 hasher = hasher.fold_byte(if neg { 1 } else { 0 });
7573 j += 1;
7574 }
7575 i += 1;
7576 }
7577 }
7578 C::Bound {
7579 observable_iri,
7580 bound_shape_iri,
7581 args_repr,
7582 } => {
7583 hasher = hasher.fold_byte(8);
7584 hasher = hasher.fold_bytes(observable_iri.as_bytes());
7585 hasher = hasher.fold_byte(0);
7586 hasher = hasher.fold_bytes(bound_shape_iri.as_bytes());
7587 hasher = hasher.fold_byte(0);
7588 hasher = hasher.fold_bytes(args_repr.as_bytes());
7589 hasher = hasher.fold_byte(0);
7590 }
7591 C::Conjunction {
7592 conjuncts,
7593 conjunct_count,
7594 } => {
7595 hasher = hasher.fold_byte(9);
7596 hasher = hasher.fold_bytes(&conjunct_count.to_be_bytes());
7597 let count = *conjunct_count as usize;
7598 let mut i = 0;
7599 while i < count && i < crate::pipeline::CONJUNCTION_MAX_TERMS {
7600 let lifted = conjuncts[i].into_constraint();
7601 hasher = fold_constraint_ref(hasher, &lifted);
7602 i += 1;
7603 }
7604 }
7605 C::Recurse {
7609 shape_iri,
7610 descent_bound,
7611 } => {
7612 hasher = hasher.fold_byte(10);
7613 hasher = hasher.fold_bytes(shape_iri.as_bytes());
7614 hasher = hasher.fold_byte(0);
7615 hasher = hasher.fold_bytes(&descent_bound.to_be_bytes());
7616 }
7617 }
7618 hasher
7619}
7620
7621pub fn fold_unit_digest<H: Hasher>(
7629 mut hasher: H,
7630 level_bits: u16,
7631 budget: u64,
7632 iri: &str,
7633 site_count: usize,
7634 constraints: &[crate::pipeline::ConstraintRef],
7635 kind: CertificateKind,
7636) -> H {
7637 hasher = hasher.fold_bytes(&level_bits.to_be_bytes());
7638 hasher = hasher.fold_bytes(&budget.to_be_bytes());
7639 hasher = hasher.fold_bytes(iri.as_bytes());
7640 hasher = hasher.fold_byte(0);
7641 hasher = hasher.fold_bytes(&(site_count as u64).to_be_bytes());
7642 let mut i = 0;
7643 while i < constraints.len() {
7644 hasher = fold_constraint_ref(hasher, &constraints[i]);
7645 i += 1;
7646 }
7647 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
7648 hasher
7649}
7650
7651pub fn fold_parallel_digest<H: Hasher>(
7655 mut hasher: H,
7656 decl_site_count: u64,
7657 iri: &str,
7658 type_site_count: usize,
7659 constraints: &[crate::pipeline::ConstraintRef],
7660 kind: CertificateKind,
7661) -> H {
7662 hasher = hasher.fold_bytes(&decl_site_count.to_be_bytes());
7663 hasher = hasher.fold_bytes(iri.as_bytes());
7664 hasher = hasher.fold_byte(0);
7665 hasher = hasher.fold_bytes(&(type_site_count as u64).to_be_bytes());
7666 let mut i = 0;
7667 while i < constraints.len() {
7668 hasher = fold_constraint_ref(hasher, &constraints[i]);
7669 i += 1;
7670 }
7671 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
7672 hasher
7673}
7674
7675pub fn fold_stream_digest<H: Hasher>(
7677 mut hasher: H,
7678 productivity_bound: u64,
7679 iri: &str,
7680 constraints: &[crate::pipeline::ConstraintRef],
7681 kind: CertificateKind,
7682) -> H {
7683 hasher = hasher.fold_bytes(&productivity_bound.to_be_bytes());
7684 hasher = hasher.fold_bytes(iri.as_bytes());
7685 hasher = hasher.fold_byte(0);
7686 let mut i = 0;
7687 while i < constraints.len() {
7688 hasher = fold_constraint_ref(hasher, &constraints[i]);
7689 i += 1;
7690 }
7691 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
7692 hasher
7693}
7694
7695pub fn fold_interaction_digest<H: Hasher>(
7697 mut hasher: H,
7698 convergence_seed: u64,
7699 iri: &str,
7700 constraints: &[crate::pipeline::ConstraintRef],
7701 kind: CertificateKind,
7702) -> H {
7703 hasher = hasher.fold_bytes(&convergence_seed.to_be_bytes());
7704 hasher = hasher.fold_bytes(iri.as_bytes());
7705 hasher = hasher.fold_byte(0);
7706 let mut i = 0;
7707 while i < constraints.len() {
7708 hasher = fold_constraint_ref(hasher, &constraints[i]);
7709 i += 1;
7710 }
7711 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
7712 hasher
7713}
7714
7715pub(crate) fn primitive_terminal_reduction<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
7718 witt_bits: u16,
7719) -> Result<(u16, u32, u8), PipelineFailure> {
7720 let outcome = crate::pipeline::run_reduction_stages::<T>(witt_bits)?;
7721 let satisfiable_bit: u8 = if outcome.satisfiable { 1 } else { 0 };
7722 Ok((
7723 outcome.witt_bits,
7724 T::CONSTRAINTS.len() as u32,
7725 satisfiable_bit,
7726 ))
7727}
7728
7729pub(crate) fn fold_terminal_reduction<H: Hasher>(
7731 mut hasher: H,
7732 witt_bits: u16,
7733 constraint_count: u32,
7734 satisfiable_bit: u8,
7735) -> H {
7736 hasher = hasher.fold_bytes(&witt_bits.to_be_bytes());
7737 hasher = hasher.fold_bytes(&constraint_count.to_be_bytes());
7738 hasher = hasher.fold_byte(satisfiable_bit);
7739 hasher
7740}
7741
7742pub fn primitive_simplicial_nerve_betti<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
7775) -> Result<[u32; MAX_BETTI_DIMENSION], GenericImpossibilityWitness> {
7776 primitive_simplicial_nerve_betti_in::<T, crate::pipeline::shape_iri_registry::EmptyShapeRegistry>(
7780 )
7781}
7782
7783pub fn primitive_simplicial_nerve_betti_in<
7800 T: crate::pipeline::ConstrainedTypeShape + ?Sized,
7801 R: crate::pipeline::shape_iri_registry::ShapeRegistryProvider,
7802>() -> Result<[u32; MAX_BETTI_DIMENSION], GenericImpossibilityWitness> {
7803 let mut expanded: [crate::pipeline::ConstraintRef; NERVE_CONSTRAINTS_CAP] =
7806 [crate::pipeline::ConstraintRef::Site { position: 0 }; NERVE_CONSTRAINTS_CAP];
7807 let mut n_expanded: usize = 0;
7808 expand_constraints_in::<R>(T::CONSTRAINTS, u32::MAX, &mut expanded, &mut n_expanded)?;
7809 let n_constraints = n_expanded;
7810 if n_constraints > NERVE_CONSTRAINTS_CAP {
7811 return Err(GenericImpossibilityWitness::for_identity(
7812 "NERVE_CAPACITY_EXCEEDED",
7813 ));
7814 }
7815 let s_all = T::SITE_COUNT;
7816 if s_all > NERVE_SITES_CAP {
7817 return Err(GenericImpossibilityWitness::for_identity(
7818 "NERVE_CAPACITY_EXCEEDED",
7819 ));
7820 }
7821 let n_sites = s_all;
7822 let mut out = [0u32; MAX_BETTI_DIMENSION];
7823 if n_constraints == 0 {
7824 out[0] = 1;
7825 return Ok(out);
7826 }
7827 let mut support = [0u16; NERVE_CONSTRAINTS_CAP];
7829 let mut c = 0;
7830 while c < n_constraints {
7831 support[c] = constraint_site_support_mask_of(&expanded[c], n_sites);
7832 c += 1;
7833 }
7834 let mut c1_pairs_lo = [0u8; NERVE_C1_MAX];
7837 let mut c1_pairs_hi = [0u8; NERVE_C1_MAX];
7838 let mut n_c1: usize = 0;
7839 let mut i = 0;
7840 while i < n_constraints {
7841 let mut j = i + 1;
7842 while j < n_constraints {
7843 if (support[i] & support[j]) != 0 && n_c1 < NERVE_C1_MAX {
7844 c1_pairs_lo[n_c1] = i as u8;
7845 c1_pairs_hi[n_c1] = j as u8;
7846 n_c1 += 1;
7847 }
7848 j += 1;
7849 }
7850 i += 1;
7851 }
7852 let mut c2_i = [0u8; NERVE_C2_MAX];
7854 let mut c2_j = [0u8; NERVE_C2_MAX];
7855 let mut c2_k = [0u8; NERVE_C2_MAX];
7856 let mut n_c2: usize = 0;
7857 let mut i2 = 0;
7858 while i2 < n_constraints {
7859 let mut j2 = i2 + 1;
7860 while j2 < n_constraints {
7861 let mut k2 = j2 + 1;
7862 while k2 < n_constraints {
7863 if (support[i2] & support[j2] & support[k2]) != 0 && n_c2 < NERVE_C2_MAX {
7864 c2_i[n_c2] = i2 as u8;
7865 c2_j[n_c2] = j2 as u8;
7866 c2_k[n_c2] = k2 as u8;
7867 n_c2 += 1;
7868 }
7869 k2 += 1;
7870 }
7871 j2 += 1;
7872 }
7873 i2 += 1;
7874 }
7875 let mut partial_1 = [[0i64; NERVE_C1_MAX]; NERVE_CONSTRAINTS_CAP];
7878 let mut e = 0;
7879 while e < n_c1 {
7880 let lo = c1_pairs_lo[e] as usize;
7881 let hi = c1_pairs_hi[e] as usize;
7882 partial_1[lo][e] = NERVE_RANK_MOD_P - 1; partial_1[hi][e] = 1;
7884 e += 1;
7885 }
7886 let rank_1 = integer_matrix_rank::<NERVE_CONSTRAINTS_CAP, NERVE_C1_MAX>(
7887 &mut partial_1,
7888 n_constraints,
7889 n_c1,
7890 );
7891 let mut partial_2 = [[0i64; NERVE_C2_MAX]; NERVE_C1_MAX];
7894 let mut t = 0;
7895 while t < n_c2 {
7896 let ti = c2_i[t];
7897 let tj = c2_j[t];
7898 let tk = c2_k[t];
7899 let idx_jk = find_pair_index(&c1_pairs_lo, &c1_pairs_hi, n_c1, tj, tk);
7900 let idx_ik = find_pair_index(&c1_pairs_lo, &c1_pairs_hi, n_c1, ti, tk);
7901 let idx_ij = find_pair_index(&c1_pairs_lo, &c1_pairs_hi, n_c1, ti, tj);
7902 if idx_jk < NERVE_C1_MAX {
7903 partial_2[idx_jk][t] = 1;
7904 }
7905 if idx_ik < NERVE_C1_MAX {
7906 partial_2[idx_ik][t] = NERVE_RANK_MOD_P - 1;
7907 }
7908 if idx_ij < NERVE_C1_MAX {
7909 partial_2[idx_ij][t] = 1;
7910 }
7911 t += 1;
7912 }
7913 let rank_2 = integer_matrix_rank::<NERVE_C1_MAX, NERVE_C2_MAX>(&mut partial_2, n_c1, n_c2);
7914 let b0 = (n_constraints - rank_1) as u32;
7916 let cycles_1 = n_c1.saturating_sub(rank_1);
7918 let b1 = cycles_1.saturating_sub(rank_2) as u32;
7919 let b2 = n_c2.saturating_sub(rank_2) as u32;
7921 out[0] = if b0 == 0 { 1 } else { b0 };
7922 if MAX_BETTI_DIMENSION > 1 {
7923 out[1] = b1;
7924 }
7925 if MAX_BETTI_DIMENSION > 2 {
7926 out[2] = b2;
7927 }
7928 Ok(out)
7929}
7930
7931pub fn expand_constraints_in<R: crate::pipeline::shape_iri_registry::ShapeRegistryProvider>(
7946 in_constraints: &[crate::pipeline::ConstraintRef],
7947 descent_remaining: u32,
7948 out_arr: &mut [crate::pipeline::ConstraintRef; NERVE_CONSTRAINTS_CAP],
7949 out_n: &mut usize,
7950) -> Result<(), GenericImpossibilityWitness> {
7951 let mut i = 0;
7952 while i < in_constraints.len() {
7953 match in_constraints[i] {
7954 crate::pipeline::ConstraintRef::Recurse {
7955 shape_iri,
7956 descent_bound,
7957 } => {
7958 let budget = if descent_remaining < descent_bound {
7960 descent_remaining
7961 } else {
7962 descent_bound
7963 };
7964 if budget == 0 {
7965 } else {
7967 match crate::pipeline::shape_iri_registry::lookup_shape_in::<R>(shape_iri) {
7968 Some(registered) => {
7969 expand_constraints_in::<R>(
7970 registered.constraints,
7971 budget - 1,
7972 out_arr,
7973 out_n,
7974 )?;
7975 }
7976 None => {
7977 return Err(GenericImpossibilityWitness::for_identity(
7978 "RECURSE_SHAPE_UNREGISTERED",
7979 ));
7980 }
7981 }
7982 }
7983 }
7984 other => {
7985 if *out_n >= NERVE_CONSTRAINTS_CAP {
7986 return Err(GenericImpossibilityWitness::for_identity(
7987 "NERVE_CAPACITY_EXCEEDED",
7988 ));
7989 }
7990 out_arr[*out_n] = other;
7991 *out_n += 1;
7992 }
7993 }
7994 i += 1;
7995 }
7996 Ok(())
7997}
7998
7999pub const NERVE_CONSTRAINTS_CAP: usize =
8005 <crate::DefaultHostBounds as crate::HostBounds>::NERVE_CONSTRAINTS_MAX;
8006
8007pub const NERVE_SITES_CAP: usize = <crate::DefaultHostBounds as crate::HostBounds>::NERVE_SITES_MAX;
8013
8014pub const NERVE_C1_MAX: usize = 28;
8016
8017pub const NERVE_C2_MAX: usize = 56;
8019
8020pub(crate) const NERVE_RANK_MOD_P: i64 = 1_000_000_007;
8024
8025pub(crate) const fn constraint_site_support_mask_of(
8036 c: &crate::pipeline::ConstraintRef,
8037 n_sites: usize,
8038) -> u16 {
8039 let all_mask: u16 = if n_sites == 0 {
8040 0
8041 } else {
8042 (1u16 << n_sites) - 1
8043 };
8044 match c {
8045 crate::pipeline::ConstraintRef::Site { position } => {
8046 if n_sites == 0 {
8047 0
8048 } else {
8049 1u16 << (*position as usize % n_sites)
8050 }
8051 }
8052 crate::pipeline::ConstraintRef::Carry { site } => {
8053 if n_sites == 0 {
8054 0
8055 } else {
8056 1u16 << (*site as usize % n_sites)
8057 }
8058 }
8059 crate::pipeline::ConstraintRef::Affine {
8060 coefficients,
8061 coefficient_count,
8062 ..
8063 } => {
8064 if n_sites == 0 {
8065 0
8066 } else {
8067 let mut mask: u16 = 0;
8068 let count = *coefficient_count as usize;
8069 let mut i = 0;
8070 while i < count && i < crate::pipeline::AFFINE_MAX_COEFFS && i < n_sites {
8071 if coefficients[i] != 0 {
8072 mask |= 1u16 << i;
8073 }
8074 i += 1;
8075 }
8076 if mask == 0 {
8077 all_mask
8078 } else {
8079 mask
8080 }
8081 }
8082 }
8083 _ => all_mask,
8087 }
8088}
8089
8090pub(crate) const fn find_pair_index(
8093 lo_arr: &[u8; NERVE_C1_MAX],
8094 hi_arr: &[u8; NERVE_C1_MAX],
8095 n_c1: usize,
8096 lo: u8,
8097 hi: u8,
8098) -> usize {
8099 let mut i = 0;
8100 while i < n_c1 {
8101 if lo_arr[i] == lo && hi_arr[i] == hi {
8102 return i;
8103 }
8104 i += 1;
8105 }
8106 NERVE_C1_MAX
8107}
8108
8109pub(crate) const fn integer_matrix_rank<const R: usize, const C: usize>(
8114 matrix: &mut [[i64; C]; R],
8115 rows: usize,
8116 cols: usize,
8117) -> usize {
8118 let p = NERVE_RANK_MOD_P;
8119 let mut r = 0;
8121 while r < rows {
8122 let mut c = 0;
8123 while c < cols {
8124 let v = matrix[r][c] % p;
8125 matrix[r][c] = if v < 0 { v + p } else { v };
8126 c += 1;
8127 }
8128 r += 1;
8129 }
8130 let mut rank: usize = 0;
8131 let mut col: usize = 0;
8132 while col < cols && rank < rows {
8133 let mut pivot_row = rank;
8135 while pivot_row < rows && matrix[pivot_row][col] == 0 {
8136 pivot_row += 1;
8137 }
8138 if pivot_row == rows {
8139 col += 1;
8140 continue;
8141 }
8142 if pivot_row != rank {
8144 let mut k = 0;
8145 while k < cols {
8146 let tmp = matrix[rank][k];
8147 matrix[rank][k] = matrix[pivot_row][k];
8148 matrix[pivot_row][k] = tmp;
8149 k += 1;
8150 }
8151 }
8152 let pivot = matrix[rank][col];
8154 let pivot_inv = mod_pow(pivot, p - 2, p);
8155 let mut k = 0;
8156 while k < cols {
8157 matrix[rank][k] = (matrix[rank][k] * pivot_inv) % p;
8158 k += 1;
8159 }
8160 let mut r2 = 0;
8162 while r2 < rows {
8163 if r2 != rank {
8164 let factor = matrix[r2][col];
8165 if factor != 0 {
8166 let mut kk = 0;
8167 while kk < cols {
8168 let sub = (matrix[rank][kk] * factor) % p;
8169 let mut v = matrix[r2][kk] - sub;
8170 v %= p;
8171 if v < 0 {
8172 v += p;
8173 }
8174 matrix[r2][kk] = v;
8175 kk += 1;
8176 }
8177 }
8178 }
8179 r2 += 1;
8180 }
8181 rank += 1;
8182 col += 1;
8183 }
8184 rank
8185}
8186
8187pub(crate) const fn mod_pow(base: i64, exp: i64, p: i64) -> i64 {
8190 let mut result: i64 = 1;
8191 let mut b = ((base % p) + p) % p;
8192 let mut e = exp;
8193 while e > 0 {
8194 if e & 1 == 1 {
8195 result = (result * b) % p;
8196 }
8197 b = (b * b) % p;
8198 e >>= 1;
8199 }
8200 result
8201}
8202
8203pub(crate) fn fold_betti_tuple<H: Hasher>(mut hasher: H, betti: &[u32; MAX_BETTI_DIMENSION]) -> H {
8205 let mut i = 0;
8206 while i < MAX_BETTI_DIMENSION {
8207 hasher = hasher.fold_bytes(&betti[i].to_be_bytes());
8208 i += 1;
8209 }
8210 hasher
8211}
8212
8213#[must_use]
8215pub(crate) fn primitive_euler_characteristic(betti: &[u32; MAX_BETTI_DIMENSION]) -> i64 {
8216 let mut chi: i64 = 0;
8217 let mut k = 0;
8218 while k < MAX_BETTI_DIMENSION {
8219 let term = betti[k] as i64;
8220 if k % 2 == 0 {
8221 chi += term;
8222 } else {
8223 chi -= term;
8224 }
8225 k += 1;
8226 }
8227 chi
8228}
8229
8230pub(crate) fn primitive_dihedral_signature<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
8241) -> (u32, u32) {
8242 let n = T::SITE_COUNT as u32;
8243 let orbit_size = if n < 2 {
8244 if n == 0 {
8245 1
8246 } else {
8247 2
8248 }
8249 } else {
8250 2 * n
8251 };
8252 let mut rep: u32 = 0;
8258 let mut k = 1u32;
8259 while k < n {
8260 let rot = k % n;
8261 let refl = (n - k) % n;
8262 if rot < rep {
8263 rep = rot;
8264 }
8265 if refl < rep {
8266 rep = refl;
8267 }
8268 k += 1;
8269 }
8270 (orbit_size, rep)
8271}
8272
8273pub(crate) fn fold_dihedral_signature<H: Hasher>(
8275 mut hasher: H,
8276 orbit_size: u32,
8277 representative: u32,
8278) -> H {
8279 hasher = hasher.fold_bytes(&orbit_size.to_be_bytes());
8280 hasher = hasher.fold_bytes(&representative.to_be_bytes());
8281 hasher
8282}
8283
8284pub(crate) fn primitive_curvature_jacobian<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
8289) -> [i32; JACOBIAN_MAX_SITES] {
8290 let mut out = [0i32; JACOBIAN_MAX_SITES];
8291 let mut ci = 0;
8292 while ci < T::CONSTRAINTS.len() {
8293 if let crate::pipeline::ConstraintRef::Site { position } = T::CONSTRAINTS[ci] {
8294 let idx = (position as usize) % JACOBIAN_MAX_SITES;
8295 out[idx] = out[idx].saturating_add(1);
8296 }
8297 ci += 1;
8298 }
8299 let total = T::CONSTRAINTS.len() as i32;
8302 out[0] = out[0].saturating_add(total);
8303 out
8304}
8305
8306#[must_use]
8308pub(crate) fn primitive_dc10_select(jac: &[i32; JACOBIAN_MAX_SITES]) -> usize {
8309 let mut best_idx: usize = 0;
8310 let mut best_abs: i32 = jac[0].unsigned_abs() as i32;
8311 let mut i = 1;
8312 while i < JACOBIAN_MAX_SITES {
8313 let a = jac[i].unsigned_abs() as i32;
8314 if a > best_abs {
8315 best_abs = a;
8316 best_idx = i;
8317 }
8318 i += 1;
8319 }
8320 best_idx
8321}
8322
8323pub(crate) fn fold_jacobian_profile<H: Hasher>(
8325 mut hasher: H,
8326 jac: &[i32; JACOBIAN_MAX_SITES],
8327) -> H {
8328 let mut i = 0;
8329 while i < JACOBIAN_MAX_SITES {
8330 hasher = hasher.fold_bytes(&jac[i].to_be_bytes());
8331 i += 1;
8332 }
8333 hasher
8334}
8335
8336pub(crate) fn primitive_session_binding_signature(bindings: &[Binding]) -> (u32, u64) {
8345 let mut fold: u64 = 0xcbf2_9ce4_8422_2325;
8348 const FNV_PRIME: u64 = 0x0000_0100_0000_01b3;
8349 let mut i = 0;
8350 while i < bindings.len() {
8351 let b = &bindings[i];
8352 fold = fold.wrapping_mul(FNV_PRIME);
8354 fold ^= b.name_index as u64;
8355 fold = fold.wrapping_mul(FNV_PRIME);
8356 fold ^= b.type_index as u64;
8357 fold = fold.wrapping_mul(FNV_PRIME);
8358 fold ^= b.content_address;
8359 i += 1;
8360 }
8361 (bindings.len() as u32, fold)
8362}
8363
8364pub(crate) fn fold_session_signature<H: Hasher>(
8366 mut hasher: H,
8367 binding_count: u32,
8368 fold_address: u64,
8369) -> H {
8370 hasher = hasher.fold_bytes(&binding_count.to_be_bytes());
8371 hasher = hasher.fold_bytes(&fold_address.to_be_bytes());
8372 hasher
8373}
8374
8375pub(crate) fn primitive_measurement_projection(budget: u64) -> (u64, u64) {
8390 let alpha0_bits: u32 = (budget >> 32) as u32;
8394 let alpha1_bits: u32 = (budget & 0xFFFF_FFFF) as u32;
8395 type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
8396 let a0 = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(alpha0_bits)
8397 / <DefaultDecimal as crate::DecimalTranscendental>::from_u32(u32::MAX);
8398 let a1 = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(alpha1_bits)
8399 / <DefaultDecimal as crate::DecimalTranscendental>::from_u32(u32::MAX);
8400 let norm = a0 * a0 + a1 * a1;
8401 let zero = <DefaultDecimal as Default>::default();
8402 let half =
8403 <DefaultDecimal as crate::DecimalTranscendental>::from_bits(0x3FE0_0000_0000_0000_u64);
8404 let p0 = if norm > zero { (a0 * a0) / norm } else { half };
8408 let p1 = if norm > zero { (a1 * a1) / norm } else { half };
8409 if p0 >= p1 {
8410 (
8411 0,
8412 <DefaultDecimal as crate::DecimalTranscendental>::to_bits(p0),
8413 )
8414 } else {
8415 (
8416 1,
8417 <DefaultDecimal as crate::DecimalTranscendental>::to_bits(p1),
8418 )
8419 }
8420}
8421
8422pub(crate) fn fold_born_outcome<H: Hasher>(
8426 mut hasher: H,
8427 outcome_index: u64,
8428 probability_bits: u64,
8429) -> H {
8430 hasher = hasher.fold_bytes(&outcome_index.to_be_bytes());
8431 hasher = hasher.fold_bytes(&probability_bits.to_be_bytes());
8432 hasher
8433}
8434
8435pub(crate) fn primitive_descent_metrics<T: crate::pipeline::ConstrainedTypeShape + ?Sized>(
8443 betti: &[u32; MAX_BETTI_DIMENSION],
8444) -> (u32, u64) {
8445 let chi = primitive_euler_characteristic(betti);
8446 let n = T::SITE_COUNT as i64;
8447 let residual = if n > chi { (n - chi) as u32 } else { 0u32 };
8448 type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
8449 let residual_d = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(residual);
8450 let ln_2 = <DefaultDecimal as crate::DecimalTranscendental>::from_bits(crate::LN_2_BITS);
8451 let entropy = residual_d * ln_2;
8452 (
8453 residual,
8454 <DefaultDecimal as crate::DecimalTranscendental>::to_bits(entropy),
8455 )
8456}
8457
8458pub(crate) fn fold_descent_metrics<H: Hasher>(
8461 mut hasher: H,
8462 residual_count: u32,
8463 entropy_bits: u64,
8464) -> H {
8465 hasher = hasher.fold_bytes(&residual_count.to_be_bytes());
8466 hasher = hasher.fold_bytes(&entropy_bits.to_be_bytes());
8467 hasher
8468}
8469
8470pub const MAX_COHOMOLOGY_DIMENSION: u32 = 32;
8474
8475#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8480pub struct CohomologyClass {
8481 dimension: u32,
8482 fingerprint: ContentFingerprint,
8483 _sealed: (),
8484}
8485
8486impl CohomologyClass {
8487 #[inline]
8491 pub(crate) const fn with_dimension_and_fingerprint(
8492 dimension: u32,
8493 fingerprint: ContentFingerprint,
8494 ) -> Self {
8495 Self {
8496 dimension,
8497 fingerprint,
8498 _sealed: (),
8499 }
8500 }
8501
8502 #[inline]
8504 #[must_use]
8505 pub const fn dimension(&self) -> u32 {
8506 self.dimension
8507 }
8508
8509 #[inline]
8511 #[must_use]
8512 pub const fn fingerprint(&self) -> ContentFingerprint {
8513 self.fingerprint
8514 }
8515
8516 pub fn cup<H: Hasher>(
8525 self,
8526 other: CohomologyClass,
8527 ) -> Result<CohomologyClass, CohomologyError> {
8528 let sum = self.dimension.saturating_add(other.dimension);
8529 if sum > MAX_COHOMOLOGY_DIMENSION {
8530 return Err(CohomologyError::DimensionOverflow {
8531 lhs: self.dimension,
8532 rhs: other.dimension,
8533 });
8534 }
8535 let hasher = H::initial();
8536 let hasher = fold_cup_product(
8537 hasher,
8538 self.dimension,
8539 &self.fingerprint,
8540 other.dimension,
8541 &other.fingerprint,
8542 );
8543 let buf = hasher.finalize();
8544 let fp = ContentFingerprint::from_buffer(buf, H::OUTPUT_BYTES as u8);
8545 Ok(Self::with_dimension_and_fingerprint(sum, fp))
8546 }
8547}
8548
8549#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8552pub enum CohomologyError {
8553 DimensionOverflow { lhs: u32, rhs: u32 },
8555}
8556
8557impl core::fmt::Display for CohomologyError {
8558 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8559 match self {
8560 Self::DimensionOverflow { lhs, rhs } => write!(
8561 f,
8562 "cup product dimension overflow: {lhs} + {rhs} > MAX_COHOMOLOGY_DIMENSION ({})",
8563 MAX_COHOMOLOGY_DIMENSION
8564 ),
8565 }
8566 }
8567}
8568impl core::error::Error for CohomologyError {}
8569
8570#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8574pub struct HomologyClass {
8575 dimension: u32,
8576 fingerprint: ContentFingerprint,
8577 _sealed: (),
8578}
8579
8580impl HomologyClass {
8581 #[inline]
8584 pub(crate) const fn with_dimension_and_fingerprint(
8585 dimension: u32,
8586 fingerprint: ContentFingerprint,
8587 ) -> Self {
8588 Self {
8589 dimension,
8590 fingerprint,
8591 _sealed: (),
8592 }
8593 }
8594
8595 #[inline]
8597 #[must_use]
8598 pub const fn dimension(&self) -> u32 {
8599 self.dimension
8600 }
8601
8602 #[inline]
8604 #[must_use]
8605 pub const fn fingerprint(&self) -> ContentFingerprint {
8606 self.fingerprint
8607 }
8608}
8609
8610pub fn fold_cup_product<H: Hasher>(
8613 mut hasher: H,
8614 lhs_dim: u32,
8615 lhs_fp: &ContentFingerprint,
8616 rhs_dim: u32,
8617 rhs_fp: &ContentFingerprint,
8618) -> H {
8619 hasher = hasher.fold_bytes(&lhs_dim.to_be_bytes());
8620 hasher = hasher.fold_bytes(lhs_fp.as_bytes());
8621 hasher = hasher.fold_bytes(&rhs_dim.to_be_bytes());
8622 hasher = hasher.fold_bytes(rhs_fp.as_bytes());
8623 hasher
8624}
8625
8626pub fn mint_cohomology_class<H: Hasher>(
8633 dimension: u32,
8634 seed: &[u8],
8635) -> Result<CohomologyClass, CohomologyError> {
8636 if dimension > MAX_COHOMOLOGY_DIMENSION {
8637 return Err(CohomologyError::DimensionOverflow {
8638 lhs: dimension,
8639 rhs: 0,
8640 });
8641 }
8642 let mut hasher = H::initial();
8643 hasher = hasher.fold_bytes(&dimension.to_be_bytes());
8644 hasher = hasher.fold_bytes(seed);
8645 let buf = hasher.finalize();
8646 let fp = ContentFingerprint::from_buffer(buf, H::OUTPUT_BYTES as u8);
8647 Ok(CohomologyClass::with_dimension_and_fingerprint(
8648 dimension, fp,
8649 ))
8650}
8651
8652pub fn mint_homology_class<H: Hasher>(
8658 dimension: u32,
8659 seed: &[u8],
8660) -> Result<HomologyClass, CohomologyError> {
8661 if dimension > MAX_COHOMOLOGY_DIMENSION {
8662 return Err(CohomologyError::DimensionOverflow {
8663 lhs: dimension,
8664 rhs: 0,
8665 });
8666 }
8667 let mut hasher = H::initial();
8668 hasher = hasher.fold_bytes(&dimension.to_be_bytes());
8669 hasher = hasher.fold_bytes(seed);
8670 let buf = hasher.finalize();
8671 let fp = ContentFingerprint::from_buffer(buf, H::OUTPUT_BYTES as u8);
8672 Ok(HomologyClass::with_dimension_and_fingerprint(dimension, fp))
8673}
8674
8675pub fn fold_stream_step_digest<H: Hasher>(
8679 mut hasher: H,
8680 productivity_remaining: u64,
8681 rewrite_steps: u64,
8682 seed: u64,
8683 iri: &str,
8684 kind: CertificateKind,
8685) -> H {
8686 hasher = hasher.fold_bytes(&productivity_remaining.to_be_bytes());
8687 hasher = hasher.fold_bytes(&rewrite_steps.to_be_bytes());
8688 hasher = hasher.fold_bytes(&seed.to_be_bytes());
8689 hasher = hasher.fold_bytes(iri.as_bytes());
8690 hasher = hasher.fold_byte(0);
8691 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
8692 hasher
8693}
8694
8695pub fn fold_interaction_step_digest<H: Hasher>(
8700 mut hasher: H,
8701 commutator_acc: &[u64; 4],
8702 peer_step_count: u64,
8703 seed: u64,
8704 iri: &str,
8705 kind: CertificateKind,
8706) -> H {
8707 let mut i = 0;
8708 while i < 4 {
8709 hasher = hasher.fold_bytes(&commutator_acc[i].to_be_bytes());
8710 i += 1;
8711 }
8712 hasher = hasher.fold_bytes(&peer_step_count.to_be_bytes());
8713 hasher = hasher.fold_bytes(&seed.to_be_bytes());
8714 hasher = hasher.fold_bytes(iri.as_bytes());
8715 hasher = hasher.fold_byte(0);
8716 hasher = hasher.fold_byte(certificate_kind_discriminant(kind));
8717 hasher
8718}
8719
8720#[inline]
8730#[must_use]
8731pub const fn unit_address_from_buffer<const FP_MAX: usize>(
8732 buffer: &[u8; FP_MAX],
8733) -> ContentAddress {
8734 let mut bytes = [0u8; 16];
8735 let mut i = 0;
8736 while i < 16 {
8737 bytes[i] = buffer[i];
8738 i += 1;
8739 }
8740 ContentAddress::from_u128(u128::from_be_bytes(bytes))
8741}
8742
8743#[inline]
8748#[must_use]
8749pub const fn str_eq(a: &str, b: &str) -> bool {
8750 let a = a.as_bytes();
8751 let b = b.as_bytes();
8752 if a.len() != b.len() {
8753 return false;
8754 }
8755 let mut i = 0;
8756 while i < a.len() {
8757 if a[i] != b[i] {
8758 return false;
8759 }
8760 i += 1;
8761 }
8762 true
8763}
8764
8765#[derive(Debug, Clone, Copy)]
8768pub struct BindingEntry {
8769 pub address: ContentAddress,
8771 pub bytes: &'static [u8],
8773}
8774
8775#[derive(Debug, Clone, Copy)]
8779pub struct BindingsTable {
8780 pub entries: &'static [BindingEntry],
8782}
8783
8784impl BindingsTable {
8785 pub const fn try_new(entries: &'static [BindingEntry]) -> Result<Self, BindingsTableError> {
8793 let mut i = 1;
8794 while i < entries.len() {
8795 if entries[i].address.as_u128() <= entries[i - 1].address.as_u128() {
8796 return Err(BindingsTableError::Unsorted { at: i });
8797 }
8798 i += 1;
8799 }
8800 Ok(Self { entries })
8801 }
8802}
8803
8804#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8806#[non_exhaustive]
8807pub enum BindingsTableError {
8808 Unsorted {
8811 at: usize,
8813 },
8814}
8815
8816impl core::fmt::Display for BindingsTableError {
8817 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8818 match self {
8819 Self::Unsorted { at } => write!(
8820 f,
8821 "BindingsTable entries not sorted: address at index {at} <= address at index {}",
8822 at - 1,
8823 ),
8824 }
8825 }
8826}
8827
8828impl core::error::Error for BindingsTableError {}
8829
8830#[derive(Debug, Clone)]
8864pub struct Grounded<T: GroundedShape, Tag = T> {
8865 validated: Validated<GroundingCertificate>,
8867 bindings: BindingsTable,
8869 witt_level_bits: u16,
8871 unit_address: ContentAddress,
8873 uor_time: UorTime,
8876 sigma_ppm: u32,
8882 d_delta: i64,
8884 euler_characteristic: i64,
8886 residual_count: u32,
8888 jacobian_entries: [i64; JACOBIAN_MAX_SITES],
8890 jacobian_len: u16,
8892 betti_numbers: [u32; MAX_BETTI_DIMENSION],
8894 content_fingerprint: ContentFingerprint,
8900 output_payload: [u8; crate::pipeline::ROUTE_OUTPUT_BUFFER_BYTES],
8905 output_len: u16,
8907 _phantom: PhantomData<T>,
8909 _tag: PhantomData<Tag>,
8912}
8913
8914impl<T: GroundedShape, Tag> Grounded<T, Tag> {
8915 #[inline]
8919 #[must_use]
8920 pub fn get_binding(&self, address: ContentAddress) -> Option<&'static [u8]> {
8921 self.bindings
8922 .entries
8923 .binary_search_by_key(&address.as_u128(), |e| e.address.as_u128())
8924 .ok()
8925 .map(|i| self.bindings.entries[i].bytes)
8926 }
8927
8928 #[inline]
8930 pub fn iter_bindings(&self) -> impl Iterator<Item = &BindingEntry> + '_ {
8931 self.bindings.entries.iter()
8932 }
8933
8934 #[inline]
8936 #[must_use]
8937 pub const fn witt_level_bits(&self) -> u16 {
8938 self.witt_level_bits
8939 }
8940
8941 #[inline]
8943 #[must_use]
8944 pub const fn unit_address(&self) -> ContentAddress {
8945 self.unit_address
8946 }
8947
8948 #[inline]
8950 #[must_use]
8951 pub const fn certificate(&self) -> &Validated<GroundingCertificate> {
8952 &self.validated
8953 }
8954
8955 #[inline]
8958 #[must_use]
8959 pub const fn d_delta(&self) -> DDeltaMetric {
8960 DDeltaMetric::new(self.d_delta)
8961 }
8962
8963 #[inline]
8965 #[must_use]
8966 pub fn sigma(&self) -> SigmaValue<crate::DefaultHostTypes> {
8967 let value = <f64 as crate::DecimalTranscendental>::from_u32(self.sigma_ppm)
8970 / <f64 as crate::DecimalTranscendental>::from_u32(1_000_000);
8971 SigmaValue::<crate::DefaultHostTypes>::new_unchecked(value)
8972 }
8973
8974 #[inline]
8976 #[must_use]
8977 pub fn jacobian(&self) -> JacobianMetric<T> {
8978 JacobianMetric::from_entries(self.jacobian_entries, self.jacobian_len)
8979 }
8980
8981 #[inline]
8983 #[must_use]
8984 pub const fn betti(&self) -> BettiMetric {
8985 BettiMetric::new(self.betti_numbers)
8986 }
8987
8988 #[inline]
8991 #[must_use]
8992 pub const fn euler(&self) -> EulerMetric {
8993 EulerMetric::new(self.euler_characteristic)
8994 }
8995
8996 #[inline]
8998 #[must_use]
8999 pub const fn residual(&self) -> ResidualMetric {
9000 ResidualMetric::new(self.residual_count)
9001 }
9002
9003 #[inline]
9009 #[must_use]
9010 pub const fn content_fingerprint(&self) -> ContentFingerprint {
9011 self.content_fingerprint
9012 }
9013
9014 #[inline]
9025 #[must_use]
9026 pub const fn derivation(&self) -> Derivation {
9027 Derivation::new(
9028 (self.jacobian_len as u32) + 1,
9029 self.witt_level_bits,
9030 self.content_fingerprint,
9031 )
9032 }
9033
9034 #[inline]
9043 #[must_use]
9044 pub fn tag<NewTag>(self) -> Grounded<T, NewTag> {
9045 Grounded {
9046 validated: self.validated,
9047 bindings: self.bindings,
9048 witt_level_bits: self.witt_level_bits,
9049 unit_address: self.unit_address,
9050 uor_time: self.uor_time,
9051 sigma_ppm: self.sigma_ppm,
9052 d_delta: self.d_delta,
9053 euler_characteristic: self.euler_characteristic,
9054 residual_count: self.residual_count,
9055 jacobian_entries: self.jacobian_entries,
9056 jacobian_len: self.jacobian_len,
9057 betti_numbers: self.betti_numbers,
9058 content_fingerprint: self.content_fingerprint,
9059 output_payload: self.output_payload,
9060 output_len: self.output_len,
9061 _phantom: PhantomData,
9062 _tag: PhantomData,
9063 }
9064 }
9065
9066 #[inline]
9074 #[must_use]
9075 pub fn output_bytes(&self) -> &[u8] {
9076 let len = self.output_len as usize;
9077 &self.output_payload[..len]
9078 }
9079
9080 #[inline]
9087 #[must_use]
9088 pub const fn uor_time(&self) -> UorTime {
9089 self.uor_time
9090 }
9091
9092 #[inline]
9099 #[must_use]
9100 pub const fn triad(&self) -> Triad<T> {
9101 let addr = self.unit_address.as_u128();
9102 let addr_lo = addr as u64;
9103 let addr_hi = (addr >> 64) as u64;
9104 let stratum = if addr_lo == 0 {
9105 0u64
9106 } else {
9107 addr_lo.trailing_zeros() as u64
9108 };
9109 Triad::new(stratum, addr_lo, addr_hi)
9110 }
9111
9112 #[inline]
9120 #[allow(dead_code)]
9121 pub(crate) const fn new_internal(
9122 validated: Validated<GroundingCertificate>,
9123 bindings: BindingsTable,
9124 witt_level_bits: u16,
9125 unit_address: ContentAddress,
9126 content_fingerprint: ContentFingerprint,
9127 ) -> Self {
9128 let bound_count = bindings.entries.len() as u32;
9129 let declared_sites = if witt_level_bits == 0 {
9130 1u32
9131 } else {
9132 witt_level_bits as u32
9133 };
9134 let sigma_ppm = if bound_count >= declared_sites {
9136 1_000_000u32
9137 } else {
9138 let num = (bound_count as u64) * 1_000_000u64;
9140 (num / (declared_sites as u64)) as u32
9141 };
9142 let residual_count = declared_sites.saturating_sub(bound_count);
9144 let d_delta = (witt_level_bits as i64) - (bound_count as i64);
9146 let mut betti = [0u32; MAX_BETTI_DIMENSION];
9148 betti[0] = 1;
9149 let mut k = 1usize;
9150 while k < MAX_BETTI_DIMENSION {
9151 betti[k] = ((witt_level_bits as u32) >> (k - 1)) & 1;
9152 k += 1;
9153 }
9154 let mut euler: i64 = 0;
9156 let mut k = 0usize;
9157 while k < MAX_BETTI_DIMENSION {
9158 if k & 1 == 0 {
9159 euler += betti[k] as i64;
9160 } else {
9161 euler -= betti[k] as i64;
9162 }
9163 k += 1;
9164 }
9165 let mut jac = [0i64; JACOBIAN_MAX_SITES];
9167 let modulus = (witt_level_bits as i64) + 1;
9168 let ua_lo = unit_address.as_u128() as i64;
9169 let mut i = 0usize;
9170 let jac_len = if (witt_level_bits as usize) < JACOBIAN_MAX_SITES {
9171 witt_level_bits as usize
9172 } else {
9173 JACOBIAN_MAX_SITES
9174 };
9175 while i < jac_len {
9176 let raw = ua_lo ^ (i as i64);
9177 let m = if modulus == 0 { 1 } else { modulus };
9179 jac[i] = ((raw % m) + m) % m;
9180 i += 1;
9181 }
9182 let steps = (witt_level_bits as u64) + (bound_count as u64) + (jac_len as u64);
9188 let landauer = LandauerBudget::new((steps as f64) * core::f64::consts::LN_2);
9189 let uor_time = UorTime::new(landauer, steps);
9190 Self {
9191 validated,
9192 bindings,
9193 witt_level_bits,
9194 unit_address,
9195 uor_time,
9196 sigma_ppm,
9197 d_delta,
9198 euler_characteristic: euler,
9199 residual_count,
9200 jacobian_entries: jac,
9201 jacobian_len: jac_len as u16,
9202 betti_numbers: betti,
9203 content_fingerprint,
9204 output_payload: [0u8; crate::pipeline::ROUTE_OUTPUT_BUFFER_BYTES],
9205 output_len: 0,
9206 _phantom: PhantomData,
9207 _tag: PhantomData,
9208 }
9209 }
9210
9211 #[inline]
9217 #[must_use]
9218 pub(crate) fn with_output_bytes(mut self, bytes: &[u8]) -> Self {
9219 let len = bytes.len();
9220 debug_assert!(len <= crate::pipeline::ROUTE_OUTPUT_BUFFER_BYTES);
9221 let copy_len = if len > crate::pipeline::ROUTE_OUTPUT_BUFFER_BYTES {
9222 crate::pipeline::ROUTE_OUTPUT_BUFFER_BYTES
9223 } else {
9224 len
9225 };
9226 let mut i = 0;
9227 while i < copy_len {
9228 self.output_payload[i] = bytes[i];
9229 i += 1;
9230 }
9231 self.output_len = copy_len as u16;
9232 self
9233 }
9234
9235 #[inline]
9246 #[must_use]
9247 pub fn with_bindings(self, bindings: BindingsTable) -> Self {
9248 Self { bindings, ..self }
9249 }
9250
9251 #[inline]
9259 #[must_use]
9260 pub fn as_inhabitance_certificate(
9261 &self,
9262 ) -> crate::pipeline::InhabitanceCertificateView<'_, T, Tag> {
9263 crate::pipeline::InhabitanceCertificateView(self)
9264 }
9265}
9266
9267#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9272pub struct Triad<L> {
9273 stratum: u64,
9275 spectrum: u64,
9277 address: u64,
9279 _level: PhantomData<L>,
9281}
9282
9283impl<L> Triad<L> {
9284 #[inline]
9286 #[must_use]
9287 pub const fn stratum(&self) -> u64 {
9288 self.stratum
9289 }
9290
9291 #[inline]
9293 #[must_use]
9294 pub const fn spectrum(&self) -> u64 {
9295 self.spectrum
9296 }
9297
9298 #[inline]
9300 #[must_use]
9301 pub const fn address(&self) -> u64 {
9302 self.address
9303 }
9304
9305 #[inline]
9307 #[must_use]
9308 #[allow(dead_code)]
9309 pub(crate) const fn new(stratum: u64, spectrum: u64, address: u64) -> Self {
9310 Self {
9311 stratum,
9312 spectrum,
9313 address,
9314 _level: PhantomData,
9315 }
9316 }
9317}
9318
9319#[derive(Debug, Clone, PartialEq)]
9339#[non_exhaustive]
9340pub enum PipelineFailure {
9341 DispatchMiss {
9343 query_iri: &'static str,
9345 table_iri: &'static str,
9347 },
9348 GroundingFailure {
9350 reason_iri: &'static str,
9352 },
9353 ConvergenceStall {
9355 stage_iri: &'static str,
9357 angle_milliradians: i64,
9359 },
9360 ContradictionDetected {
9362 at_step: usize,
9364 trace_iri: &'static str,
9366 },
9367 CoherenceViolation {
9369 site_position: usize,
9371 constraint_iri: &'static str,
9373 },
9374 ShapeMismatch {
9376 expected: &'static str,
9378 got: &'static str,
9380 },
9381 LiftObstructionFailure {
9383 site_position: usize,
9385 obstruction_class_iri: &'static str,
9387 },
9388 ShapeViolation {
9390 report: ShapeViolation,
9392 },
9393}
9394
9395impl core::fmt::Display for PipelineFailure {
9396 fn fmt(&self, ff: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
9397 match self {
9398 Self::DispatchMiss {
9399 query_iri,
9400 table_iri,
9401 } => write!(
9402 ff,
9403 "DispatchMiss(query_iri={:?}, table_iri={:?})",
9404 query_iri, table_iri
9405 ),
9406 Self::GroundingFailure { reason_iri } => {
9407 write!(ff, "GroundingFailure(reason_iri={:?})", reason_iri)
9408 }
9409 Self::ConvergenceStall {
9410 stage_iri,
9411 angle_milliradians,
9412 } => write!(
9413 ff,
9414 "ConvergenceStall(stage_iri={:?}, angle_milliradians={:?})",
9415 stage_iri, angle_milliradians
9416 ),
9417 Self::ContradictionDetected { at_step, trace_iri } => write!(
9418 ff,
9419 "ContradictionDetected(at_step={:?}, trace_iri={:?})",
9420 at_step, trace_iri
9421 ),
9422 Self::CoherenceViolation {
9423 site_position,
9424 constraint_iri,
9425 } => write!(
9426 ff,
9427 "CoherenceViolation(site_position={:?}, constraint_iri={:?})",
9428 site_position, constraint_iri
9429 ),
9430 Self::ShapeMismatch { expected, got } => {
9431 write!(ff, "ShapeMismatch(expected={:?}, got={:?})", expected, got)
9432 }
9433 Self::LiftObstructionFailure {
9434 site_position,
9435 obstruction_class_iri,
9436 } => write!(
9437 ff,
9438 "LiftObstructionFailure(site_position={:?}, obstruction_class_iri={:?})",
9439 site_position, obstruction_class_iri
9440 ),
9441 Self::ShapeViolation { report } => write!(ff, "ShapeViolation({:?})", report),
9442 }
9443 }
9444}
9445
9446impl core::error::Error for PipelineFailure {}
9447
9448pub trait ImpossibilityWitnessKind: impossibility_witness_kind_sealed::Sealed {}
9452
9453mod impossibility_witness_kind_sealed {
9454 pub trait Sealed {}
9456 impl Sealed for super::GenericImpossibilityWitness {}
9457 impl Sealed for super::InhabitanceImpossibilityWitness {}
9458}
9459
9460impl ImpossibilityWitnessKind for GenericImpossibilityWitness {}
9461impl ImpossibilityWitnessKind for InhabitanceImpossibilityWitness {}
9462
9463pub mod resolver {
9467 use super::{
9468 BornRuleVerification,
9469 Certified,
9470 CompileUnit,
9471 CompletenessCertificate,
9472 GenericImpossibilityWitness,
9473 GeodesicCertificate,
9474 GroundingCertificate,
9475 InhabitanceCertificate,
9476 InhabitanceImpossibilityWitness,
9477 InvolutionCertificate,
9478 IsometryCertificate,
9479 LiftChainCertificate,
9480 MeasurementCertificate,
9481 TransformCertificate,
9483 Validated,
9484 WittLevel,
9485 };
9486
9487 pub mod tower_completeness {
9497 use super::*;
9498 pub fn certify<T, P, H>(
9504 input: &Validated<T, P>,
9505 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9506 where
9507 T: crate::pipeline::ConstrainedTypeShape,
9508 P: crate::enforcement::ValidationPhase,
9509 H: crate::enforcement::Hasher,
9510 {
9511 certify_at::<T, P, H>(input, WittLevel::W32)
9512 }
9513
9514 pub fn certify_at<T, P, H>(
9520 input: &Validated<T, P>,
9521 level: WittLevel,
9522 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9523 where
9524 T: crate::pipeline::ConstrainedTypeShape,
9525 P: crate::enforcement::ValidationPhase,
9526 H: crate::enforcement::Hasher,
9527 {
9528 crate::pipeline::run_tower_completeness::<T, H>(input.inner(), level)
9529 .map(|v| Certified::new(*v.inner()))
9530 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
9531 }
9532 }
9533
9534 pub mod incremental_completeness {
9536 use super::*;
9537 pub fn certify<T, P, H>(
9543 input: &Validated<T, P>,
9544 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9545 where
9546 T: crate::pipeline::ConstrainedTypeShape,
9547 P: crate::enforcement::ValidationPhase,
9548 H: crate::enforcement::Hasher,
9549 {
9550 certify_at::<T, P, H>(input, WittLevel::W32)
9551 }
9552
9553 pub fn certify_at<T, P, H>(
9559 input: &Validated<T, P>,
9560 level: WittLevel,
9561 ) -> Result<Certified<LiftChainCertificate>, Certified<GenericImpossibilityWitness>>
9562 where
9563 T: crate::pipeline::ConstrainedTypeShape,
9564 P: crate::enforcement::ValidationPhase,
9565 H: crate::enforcement::Hasher,
9566 {
9567 crate::pipeline::run_incremental_completeness::<T, H>(input.inner(), level)
9568 .map(|v| Certified::new(*v.inner()))
9569 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
9570 }
9571 }
9572
9573 pub mod grounding_aware {
9575 use super::*;
9576 pub fn certify<P, H>(
9582 input: &Validated<CompileUnit, P>,
9583 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9584 where
9585 P: crate::enforcement::ValidationPhase,
9586 H: crate::enforcement::Hasher,
9587 {
9588 certify_at::<P, H>(input, WittLevel::W32)
9589 }
9590
9591 pub fn certify_at<P, H>(
9597 input: &Validated<CompileUnit, P>,
9598 level: WittLevel,
9599 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9600 where
9601 P: crate::enforcement::ValidationPhase,
9602 H: crate::enforcement::Hasher,
9603 {
9604 crate::pipeline::run_grounding_aware::<H>(input.inner(), level)
9605 .map(|v| Certified::new(*v.inner()))
9606 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))
9607 }
9608 }
9609
9610 pub mod inhabitance {
9612 use super::*;
9613 pub fn certify<T, P, H>(
9619 input: &Validated<T, P>,
9620 ) -> Result<Certified<InhabitanceCertificate>, Certified<InhabitanceImpossibilityWitness>>
9621 where
9622 T: crate::pipeline::ConstrainedTypeShape,
9623 P: crate::enforcement::ValidationPhase,
9624 H: crate::enforcement::Hasher,
9625 {
9626 certify_at::<T, P, H>(input, WittLevel::W32)
9627 }
9628
9629 pub fn certify_at<T, P, H>(
9635 input: &Validated<T, P>,
9636 level: WittLevel,
9637 ) -> Result<Certified<InhabitanceCertificate>, Certified<InhabitanceImpossibilityWitness>>
9638 where
9639 T: crate::pipeline::ConstrainedTypeShape,
9640 P: crate::enforcement::ValidationPhase,
9641 H: crate::enforcement::Hasher,
9642 {
9643 crate::pipeline::run_inhabitance::<T, H>(input.inner(), level)
9644 .map(|v: Validated<InhabitanceCertificate>| Certified::new(*v.inner()))
9645 .map_err(|_| Certified::new(InhabitanceImpossibilityWitness::default()))
9646 }
9647 }
9648
9649 pub mod multiplication {
9660 use super::super::{MulContext, MultiplicationCertificate};
9661 use super::*;
9662
9663 pub fn certify<H: crate::enforcement::Hasher>(
9675 context: &MulContext,
9676 ) -> Result<Certified<MultiplicationCertificate>, GenericImpossibilityWitness> {
9677 if context.stack_budget_bytes == 0 {
9678 return Err(GenericImpossibilityWitness::default());
9679 }
9680 let limb_count = context.limb_count.max(1);
9682 let karatsuba_stack_need = limb_count * 8 * 6;
9683 let choose_karatsuba = !context.const_eval
9684 && (context.stack_budget_bytes as usize) >= karatsuba_stack_need;
9685 let mut hasher = H::initial();
9687 hasher = hasher.fold_bytes(&context.stack_budget_bytes.to_be_bytes());
9688 hasher = hasher.fold_byte(if context.const_eval { 1 } else { 0 });
9689 hasher = hasher.fold_bytes(&(limb_count as u64).to_be_bytes());
9690 hasher = hasher.fold_byte(crate::enforcement::certificate_kind_discriminant(
9691 crate::enforcement::CertificateKind::Multiplication,
9692 ));
9693 let buffer = hasher.finalize();
9694 let fp =
9695 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
9696 let cert = if choose_karatsuba {
9697 MultiplicationCertificate::with_evidence(
9698 2,
9699 3,
9700 karatsuba_landauer_cost(limb_count),
9701 fp,
9702 )
9703 } else {
9704 MultiplicationCertificate::with_evidence(
9705 1,
9706 1,
9707 schoolbook_landauer_cost(limb_count),
9708 fp,
9709 )
9710 };
9711 Ok(Certified::new(cert))
9712 }
9713
9714 type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
9716
9717 fn schoolbook_landauer_cost(limb_count: usize) -> u64 {
9721 let n = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(limb_count as u32);
9722 let sixty_four = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(64);
9723 let ln_2 =
9724 <DefaultDecimal as crate::DecimalTranscendental>::from_bits(crate::LN_2_BITS);
9725 (n * n * sixty_four * ln_2).to_bits()
9726 }
9727
9728 fn karatsuba_landauer_cost(limb_count: usize) -> u64 {
9731 let n = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(limb_count as u32);
9732 let two = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(2);
9733 let three = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(3);
9734 let sixty_four = <DefaultDecimal as crate::DecimalTranscendental>::from_u32(64);
9735 let ln_2 =
9736 <DefaultDecimal as crate::DecimalTranscendental>::from_bits(crate::LN_2_BITS);
9737 let n_half = n / two;
9738 (three * n_half * n_half * sixty_four * ln_2).to_bits()
9739 }
9740 }
9741
9742 pub(crate) trait ResolverKernel {
9749 const KIND: crate::enforcement::CertificateKind;
9750 type Cert: crate::enforcement::Certificate;
9753 }
9754
9755 pub mod two_sat_decider {
9773 use super::*;
9774
9775 #[doc(hidden)]
9776 pub struct Kernel;
9777 impl super::ResolverKernel for Kernel {
9778 type Cert = crate::enforcement::GroundingCertificate;
9779 const KIND: crate::enforcement::CertificateKind =
9780 crate::enforcement::CertificateKind::TwoSat;
9781 }
9782
9783 pub fn certify<
9789 T: crate::pipeline::ConstrainedTypeShape,
9790 P: crate::enforcement::ValidationPhase,
9791 H: crate::enforcement::Hasher,
9792 >(
9793 input: &Validated<T, P>,
9794 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9795 {
9796 certify_at::<T, P, H>(input, WittLevel::W32)
9797 }
9798
9799 pub fn certify_at<
9805 T: crate::pipeline::ConstrainedTypeShape,
9806 P: crate::enforcement::ValidationPhase,
9807 H: crate::enforcement::Hasher,
9808 >(
9809 input: &Validated<T, P>,
9810 level: WittLevel,
9811 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9812 {
9813 let _ = input.inner();
9814 let witt_bits = level.witt_length() as u16;
9815 let (tr_bits, tr_constraints, tr_sat) =
9816 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
9817 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
9818 if tr_sat == 0 {
9819 return Err(Certified::new(GenericImpossibilityWitness::default()));
9820 }
9821 let mut hasher = H::initial();
9822 hasher = crate::enforcement::fold_terminal_reduction(
9823 hasher,
9824 tr_bits,
9825 tr_constraints,
9826 tr_sat,
9827 );
9828 hasher = crate::enforcement::fold_unit_digest(
9829 hasher,
9830 witt_bits,
9831 witt_bits as u64,
9832 T::IRI,
9833 T::SITE_COUNT,
9834 T::CONSTRAINTS,
9835 <Kernel as super::ResolverKernel>::KIND,
9836 );
9837 let buffer = hasher.finalize();
9838 let fp =
9839 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
9840 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
9841 Ok(Certified::new(cert))
9842 }
9843 }
9844
9845 pub mod horn_sat_decider {
9863 use super::*;
9864
9865 #[doc(hidden)]
9866 pub struct Kernel;
9867 impl super::ResolverKernel for Kernel {
9868 type Cert = crate::enforcement::GroundingCertificate;
9869 const KIND: crate::enforcement::CertificateKind =
9870 crate::enforcement::CertificateKind::HornSat;
9871 }
9872
9873 pub fn certify<
9879 T: crate::pipeline::ConstrainedTypeShape,
9880 P: crate::enforcement::ValidationPhase,
9881 H: crate::enforcement::Hasher,
9882 >(
9883 input: &Validated<T, P>,
9884 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9885 {
9886 certify_at::<T, P, H>(input, WittLevel::W32)
9887 }
9888
9889 pub fn certify_at<
9895 T: crate::pipeline::ConstrainedTypeShape,
9896 P: crate::enforcement::ValidationPhase,
9897 H: crate::enforcement::Hasher,
9898 >(
9899 input: &Validated<T, P>,
9900 level: WittLevel,
9901 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9902 {
9903 let _ = input.inner();
9904 let witt_bits = level.witt_length() as u16;
9905 let (tr_bits, tr_constraints, tr_sat) =
9906 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
9907 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
9908 if tr_sat == 0 {
9909 return Err(Certified::new(GenericImpossibilityWitness::default()));
9910 }
9911 let mut hasher = H::initial();
9912 hasher = crate::enforcement::fold_terminal_reduction(
9913 hasher,
9914 tr_bits,
9915 tr_constraints,
9916 tr_sat,
9917 );
9918 hasher = crate::enforcement::fold_unit_digest(
9919 hasher,
9920 witt_bits,
9921 witt_bits as u64,
9922 T::IRI,
9923 T::SITE_COUNT,
9924 T::CONSTRAINTS,
9925 <Kernel as super::ResolverKernel>::KIND,
9926 );
9927 let buffer = hasher.finalize();
9928 let fp =
9929 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
9930 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
9931 Ok(Certified::new(cert))
9932 }
9933 }
9934
9935 pub mod residual_verdict {
9953 use super::*;
9954
9955 #[doc(hidden)]
9956 pub struct Kernel;
9957 impl super::ResolverKernel for Kernel {
9958 type Cert = crate::enforcement::GroundingCertificate;
9959 const KIND: crate::enforcement::CertificateKind =
9960 crate::enforcement::CertificateKind::ResidualVerdict;
9961 }
9962
9963 pub fn certify<
9969 T: crate::pipeline::ConstrainedTypeShape,
9970 P: crate::enforcement::ValidationPhase,
9971 H: crate::enforcement::Hasher,
9972 >(
9973 input: &Validated<T, P>,
9974 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9975 {
9976 certify_at::<T, P, H>(input, WittLevel::W32)
9977 }
9978
9979 pub fn certify_at<
9985 T: crate::pipeline::ConstrainedTypeShape,
9986 P: crate::enforcement::ValidationPhase,
9987 H: crate::enforcement::Hasher,
9988 >(
9989 input: &Validated<T, P>,
9990 level: WittLevel,
9991 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
9992 {
9993 let _ = input.inner();
9994 let witt_bits = level.witt_length() as u16;
9995 let (tr_bits, tr_constraints, tr_sat) =
9996 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
9997 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
9998 if tr_sat == 0 {
9999 return Err(Certified::new(GenericImpossibilityWitness::default()));
10000 }
10001 let mut hasher = H::initial();
10002 hasher = crate::enforcement::fold_terminal_reduction(
10003 hasher,
10004 tr_bits,
10005 tr_constraints,
10006 tr_sat,
10007 );
10008 hasher = crate::enforcement::fold_unit_digest(
10009 hasher,
10010 witt_bits,
10011 witt_bits as u64,
10012 T::IRI,
10013 T::SITE_COUNT,
10014 T::CONSTRAINTS,
10015 <Kernel as super::ResolverKernel>::KIND,
10016 );
10017 let buffer = hasher.finalize();
10018 let fp =
10019 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10020 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10021 Ok(Certified::new(cert))
10022 }
10023 }
10024
10025 pub mod canonical_form {
10043 use super::*;
10044
10045 #[doc(hidden)]
10046 pub struct Kernel;
10047 impl super::ResolverKernel for Kernel {
10048 type Cert = crate::enforcement::TransformCertificate;
10049 const KIND: crate::enforcement::CertificateKind =
10050 crate::enforcement::CertificateKind::CanonicalForm;
10051 }
10052
10053 pub fn certify<
10059 T: crate::pipeline::ConstrainedTypeShape,
10060 P: crate::enforcement::ValidationPhase,
10061 H: crate::enforcement::Hasher,
10062 >(
10063 input: &Validated<T, P>,
10064 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10065 {
10066 certify_at::<T, P, H>(input, WittLevel::W32)
10067 }
10068
10069 pub fn certify_at<
10075 T: crate::pipeline::ConstrainedTypeShape,
10076 P: crate::enforcement::ValidationPhase,
10077 H: crate::enforcement::Hasher,
10078 >(
10079 input: &Validated<T, P>,
10080 level: WittLevel,
10081 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10082 {
10083 let _ = input.inner();
10084 let witt_bits = level.witt_length() as u16;
10085 let (tr_bits, tr_constraints, tr_sat) =
10086 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10087 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10088 if tr_sat == 0 {
10089 return Err(Certified::new(GenericImpossibilityWitness::default()));
10090 }
10091 let mut hasher = H::initial();
10092 hasher = crate::enforcement::fold_terminal_reduction(
10093 hasher,
10094 tr_bits,
10095 tr_constraints,
10096 tr_sat,
10097 );
10098 let (tr2_bits, tr2_constraints, tr2_sat) =
10099 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10100 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10101 if tr2_bits != tr_bits || tr2_constraints != tr_constraints || tr2_sat != tr_sat {
10103 return Err(Certified::new(GenericImpossibilityWitness::default()));
10104 }
10105 hasher = crate::enforcement::fold_terminal_reduction(
10106 hasher,
10107 tr2_bits,
10108 tr2_constraints,
10109 tr2_sat,
10110 );
10111 hasher = crate::enforcement::fold_unit_digest(
10112 hasher,
10113 witt_bits,
10114 witt_bits as u64,
10115 T::IRI,
10116 T::SITE_COUNT,
10117 T::CONSTRAINTS,
10118 <Kernel as super::ResolverKernel>::KIND,
10119 );
10120 let buffer = hasher.finalize();
10121 let fp =
10122 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10123 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10124 Ok(Certified::new(cert))
10125 }
10126 }
10127
10128 pub mod type_synthesis {
10146 use super::*;
10147
10148 #[doc(hidden)]
10149 pub struct Kernel;
10150 impl super::ResolverKernel for Kernel {
10151 type Cert = crate::enforcement::TransformCertificate;
10152 const KIND: crate::enforcement::CertificateKind =
10153 crate::enforcement::CertificateKind::TypeSynthesis;
10154 }
10155
10156 pub fn certify<
10162 T: crate::pipeline::ConstrainedTypeShape,
10163 P: crate::enforcement::ValidationPhase,
10164 H: crate::enforcement::Hasher,
10165 >(
10166 input: &Validated<T, P>,
10167 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10168 {
10169 certify_at::<T, P, H>(input, WittLevel::W32)
10170 }
10171
10172 pub fn certify_at<
10178 T: crate::pipeline::ConstrainedTypeShape,
10179 P: crate::enforcement::ValidationPhase,
10180 H: crate::enforcement::Hasher,
10181 >(
10182 input: &Validated<T, P>,
10183 level: WittLevel,
10184 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10185 {
10186 let _ = input.inner();
10187 let witt_bits = level.witt_length() as u16;
10188 let (tr_bits, tr_constraints, tr_sat) =
10189 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10190 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10191 if tr_sat == 0 {
10192 return Err(Certified::new(GenericImpossibilityWitness::default()));
10193 }
10194 let mut hasher = H::initial();
10195 hasher = crate::enforcement::fold_terminal_reduction(
10196 hasher,
10197 tr_bits,
10198 tr_constraints,
10199 tr_sat,
10200 );
10201 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10202 .map_err(crate::enforcement::Certified::new)?;
10203 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
10204 let (residual, entropy) = crate::enforcement::primitive_descent_metrics::<T>(&betti);
10205 hasher = crate::enforcement::fold_descent_metrics(hasher, residual, entropy);
10206 hasher = crate::enforcement::fold_unit_digest(
10207 hasher,
10208 witt_bits,
10209 witt_bits as u64,
10210 T::IRI,
10211 T::SITE_COUNT,
10212 T::CONSTRAINTS,
10213 <Kernel as super::ResolverKernel>::KIND,
10214 );
10215 let buffer = hasher.finalize();
10216 let fp =
10217 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10218 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10219 Ok(Certified::new(cert))
10220 }
10221 }
10222
10223 pub mod homotopy {
10241 use super::*;
10242
10243 #[doc(hidden)]
10244 pub struct Kernel;
10245 impl super::ResolverKernel for Kernel {
10246 type Cert = crate::enforcement::TransformCertificate;
10247 const KIND: crate::enforcement::CertificateKind =
10248 crate::enforcement::CertificateKind::Homotopy;
10249 }
10250
10251 pub fn certify<
10257 T: crate::pipeline::ConstrainedTypeShape,
10258 P: crate::enforcement::ValidationPhase,
10259 H: crate::enforcement::Hasher,
10260 >(
10261 input: &Validated<T, P>,
10262 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10263 {
10264 certify_at::<T, P, H>(input, WittLevel::W32)
10265 }
10266
10267 pub fn certify_at<
10273 T: crate::pipeline::ConstrainedTypeShape,
10274 P: crate::enforcement::ValidationPhase,
10275 H: crate::enforcement::Hasher,
10276 >(
10277 input: &Validated<T, P>,
10278 level: WittLevel,
10279 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10280 {
10281 let _ = input.inner();
10282 let witt_bits = level.witt_length() as u16;
10283 let (tr_bits, tr_constraints, tr_sat) =
10284 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10285 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10286 if tr_sat == 0 {
10287 return Err(Certified::new(GenericImpossibilityWitness::default()));
10288 }
10289 let mut hasher = H::initial();
10290 hasher = crate::enforcement::fold_terminal_reduction(
10291 hasher,
10292 tr_bits,
10293 tr_constraints,
10294 tr_sat,
10295 );
10296 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10297 .map_err(crate::enforcement::Certified::new)?;
10298 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
10299 hasher = crate::enforcement::fold_unit_digest(
10300 hasher,
10301 witt_bits,
10302 witt_bits as u64,
10303 T::IRI,
10304 T::SITE_COUNT,
10305 T::CONSTRAINTS,
10306 <Kernel as super::ResolverKernel>::KIND,
10307 );
10308 let buffer = hasher.finalize();
10309 let fp =
10310 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10311 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10312 Ok(Certified::new(cert))
10313 }
10314 }
10315
10316 pub mod monodromy {
10334 use super::*;
10335
10336 #[doc(hidden)]
10337 pub struct Kernel;
10338 impl super::ResolverKernel for Kernel {
10339 type Cert = crate::enforcement::IsometryCertificate;
10340 const KIND: crate::enforcement::CertificateKind =
10341 crate::enforcement::CertificateKind::Monodromy;
10342 }
10343
10344 pub fn certify<
10350 T: crate::pipeline::ConstrainedTypeShape,
10351 P: crate::enforcement::ValidationPhase,
10352 H: crate::enforcement::Hasher,
10353 >(
10354 input: &Validated<T, P>,
10355 ) -> Result<Certified<IsometryCertificate>, Certified<GenericImpossibilityWitness>>
10356 {
10357 certify_at::<T, P, H>(input, WittLevel::W32)
10358 }
10359
10360 pub fn certify_at<
10366 T: crate::pipeline::ConstrainedTypeShape,
10367 P: crate::enforcement::ValidationPhase,
10368 H: crate::enforcement::Hasher,
10369 >(
10370 input: &Validated<T, P>,
10371 level: WittLevel,
10372 ) -> Result<Certified<IsometryCertificate>, Certified<GenericImpossibilityWitness>>
10373 {
10374 let _ = input.inner();
10375 let witt_bits = level.witt_length() as u16;
10376 let (tr_bits, tr_constraints, tr_sat) =
10377 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10378 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10379 if tr_sat == 0 {
10380 return Err(Certified::new(GenericImpossibilityWitness::default()));
10381 }
10382 let mut hasher = H::initial();
10383 hasher = crate::enforcement::fold_terminal_reduction(
10384 hasher,
10385 tr_bits,
10386 tr_constraints,
10387 tr_sat,
10388 );
10389 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10390 .map_err(crate::enforcement::Certified::new)?;
10391 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
10392 let (orbit_size, representative) =
10393 crate::enforcement::primitive_dihedral_signature::<T>();
10394 hasher =
10395 crate::enforcement::fold_dihedral_signature(hasher, orbit_size, representative);
10396 hasher = crate::enforcement::fold_unit_digest(
10397 hasher,
10398 witt_bits,
10399 witt_bits as u64,
10400 T::IRI,
10401 T::SITE_COUNT,
10402 T::CONSTRAINTS,
10403 <Kernel as super::ResolverKernel>::KIND,
10404 );
10405 let buffer = hasher.finalize();
10406 let fp =
10407 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10408 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10409 Ok(Certified::new(cert))
10410 }
10411 }
10412
10413 pub mod moduli {
10431 use super::*;
10432
10433 #[doc(hidden)]
10434 pub struct Kernel;
10435 impl super::ResolverKernel for Kernel {
10436 type Cert = crate::enforcement::TransformCertificate;
10437 const KIND: crate::enforcement::CertificateKind =
10438 crate::enforcement::CertificateKind::Moduli;
10439 }
10440
10441 pub fn certify<
10447 T: crate::pipeline::ConstrainedTypeShape,
10448 P: crate::enforcement::ValidationPhase,
10449 H: crate::enforcement::Hasher,
10450 >(
10451 input: &Validated<T, P>,
10452 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10453 {
10454 certify_at::<T, P, H>(input, WittLevel::W32)
10455 }
10456
10457 pub fn certify_at<
10463 T: crate::pipeline::ConstrainedTypeShape,
10464 P: crate::enforcement::ValidationPhase,
10465 H: crate::enforcement::Hasher,
10466 >(
10467 input: &Validated<T, P>,
10468 level: WittLevel,
10469 ) -> Result<Certified<TransformCertificate>, Certified<GenericImpossibilityWitness>>
10470 {
10471 let _ = input.inner();
10472 let witt_bits = level.witt_length() as u16;
10473 let (tr_bits, tr_constraints, tr_sat) =
10474 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10475 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10476 if tr_sat == 0 {
10477 return Err(Certified::new(GenericImpossibilityWitness::default()));
10478 }
10479 let mut hasher = H::initial();
10480 hasher = crate::enforcement::fold_terminal_reduction(
10481 hasher,
10482 tr_bits,
10483 tr_constraints,
10484 tr_sat,
10485 );
10486 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
10487 .map_err(crate::enforcement::Certified::new)?;
10488 let automorphisms: u32 = betti[0];
10489 let deformations: u32 = if crate::enforcement::MAX_BETTI_DIMENSION > 1 {
10490 betti[1]
10491 } else {
10492 0
10493 };
10494 let obstructions: u32 = if crate::enforcement::MAX_BETTI_DIMENSION > 2 {
10495 betti[2]
10496 } else {
10497 0
10498 };
10499 hasher = hasher.fold_bytes(&automorphisms.to_be_bytes());
10500 hasher = hasher.fold_bytes(&deformations.to_be_bytes());
10501 hasher = hasher.fold_bytes(&obstructions.to_be_bytes());
10502 hasher = crate::enforcement::fold_unit_digest(
10503 hasher,
10504 witt_bits,
10505 witt_bits as u64,
10506 T::IRI,
10507 T::SITE_COUNT,
10508 T::CONSTRAINTS,
10509 <Kernel as super::ResolverKernel>::KIND,
10510 );
10511 let buffer = hasher.finalize();
10512 let fp =
10513 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10514 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10515 Ok(Certified::new(cert))
10516 }
10517 }
10518
10519 pub mod jacobian_guided {
10537 use super::*;
10538
10539 #[doc(hidden)]
10540 pub struct Kernel;
10541 impl super::ResolverKernel for Kernel {
10542 type Cert = crate::enforcement::GroundingCertificate;
10543 const KIND: crate::enforcement::CertificateKind =
10544 crate::enforcement::CertificateKind::JacobianGuided;
10545 }
10546
10547 pub fn certify<
10553 T: crate::pipeline::ConstrainedTypeShape,
10554 P: crate::enforcement::ValidationPhase,
10555 H: crate::enforcement::Hasher,
10556 >(
10557 input: &Validated<T, P>,
10558 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10559 {
10560 certify_at::<T, P, H>(input, WittLevel::W32)
10561 }
10562
10563 pub fn certify_at<
10569 T: crate::pipeline::ConstrainedTypeShape,
10570 P: crate::enforcement::ValidationPhase,
10571 H: crate::enforcement::Hasher,
10572 >(
10573 input: &Validated<T, P>,
10574 level: WittLevel,
10575 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10576 {
10577 let _ = input.inner();
10578 let witt_bits = level.witt_length() as u16;
10579 let (tr_bits, tr_constraints, tr_sat) =
10580 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10581 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10582 if tr_sat == 0 {
10583 return Err(Certified::new(GenericImpossibilityWitness::default()));
10584 }
10585 let mut hasher = H::initial();
10586 hasher = crate::enforcement::fold_terminal_reduction(
10587 hasher,
10588 tr_bits,
10589 tr_constraints,
10590 tr_sat,
10591 );
10592 let jac = crate::enforcement::primitive_curvature_jacobian::<T>();
10593 hasher = crate::enforcement::fold_jacobian_profile(hasher, &jac);
10594 let selected_site = crate::enforcement::primitive_dc10_select(&jac);
10595 hasher = hasher.fold_bytes(&(selected_site as u32).to_be_bytes());
10596 hasher = crate::enforcement::fold_unit_digest(
10597 hasher,
10598 witt_bits,
10599 witt_bits as u64,
10600 T::IRI,
10601 T::SITE_COUNT,
10602 T::CONSTRAINTS,
10603 <Kernel as super::ResolverKernel>::KIND,
10604 );
10605 let buffer = hasher.finalize();
10606 let fp =
10607 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10608 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10609 Ok(Certified::new(cert))
10610 }
10611 }
10612
10613 pub mod evaluation {
10631 use super::*;
10632
10633 #[doc(hidden)]
10634 pub struct Kernel;
10635 impl super::ResolverKernel for Kernel {
10636 type Cert = crate::enforcement::GroundingCertificate;
10637 const KIND: crate::enforcement::CertificateKind =
10638 crate::enforcement::CertificateKind::Evaluation;
10639 }
10640
10641 pub fn certify<
10647 T: crate::pipeline::ConstrainedTypeShape,
10648 P: crate::enforcement::ValidationPhase,
10649 H: crate::enforcement::Hasher,
10650 >(
10651 input: &Validated<T, P>,
10652 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10653 {
10654 certify_at::<T, P, H>(input, WittLevel::W32)
10655 }
10656
10657 pub fn certify_at<
10663 T: crate::pipeline::ConstrainedTypeShape,
10664 P: crate::enforcement::ValidationPhase,
10665 H: crate::enforcement::Hasher,
10666 >(
10667 input: &Validated<T, P>,
10668 level: WittLevel,
10669 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10670 {
10671 let _ = input.inner();
10672 let witt_bits = level.witt_length() as u16;
10673 let (tr_bits, tr_constraints, tr_sat) =
10674 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
10675 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
10676 if tr_sat == 0 {
10677 return Err(Certified::new(GenericImpossibilityWitness::default()));
10678 }
10679 let mut hasher = H::initial();
10680 hasher = crate::enforcement::fold_terminal_reduction(
10681 hasher,
10682 tr_bits,
10683 tr_constraints,
10684 tr_sat,
10685 );
10686 hasher = crate::enforcement::fold_unit_digest(
10687 hasher,
10688 witt_bits,
10689 witt_bits as u64,
10690 T::IRI,
10691 T::SITE_COUNT,
10692 T::CONSTRAINTS,
10693 <Kernel as super::ResolverKernel>::KIND,
10694 );
10695 let buffer = hasher.finalize();
10696 let fp =
10697 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10698 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10699 Ok(Certified::new(cert))
10700 }
10701 }
10702
10703 pub mod session {
10721 use super::*;
10722
10723 #[doc(hidden)]
10724 pub struct Kernel;
10725 impl super::ResolverKernel for Kernel {
10726 type Cert = crate::enforcement::GroundingCertificate;
10727 const KIND: crate::enforcement::CertificateKind =
10728 crate::enforcement::CertificateKind::Session;
10729 }
10730
10731 pub fn certify<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
10737 input: &Validated<CompileUnit, P>,
10738 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10739 {
10740 certify_at::<P, H>(input, WittLevel::W32)
10741 }
10742
10743 pub fn certify_at<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
10749 input: &Validated<CompileUnit, P>,
10750 level: WittLevel,
10751 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10752 {
10753 let unit = input.inner();
10754 let witt_bits = level.witt_length() as u16;
10755 let budget = unit.thermodynamic_budget();
10756 let result_type_iri = unit.result_type_iri();
10757 let mut hasher = H::initial();
10758 let (binding_count, fold_addr) =
10759 crate::enforcement::primitive_session_binding_signature(unit.bindings());
10760 hasher = crate::enforcement::fold_session_signature(hasher, binding_count, fold_addr);
10761 hasher = crate::enforcement::fold_unit_digest(
10762 hasher,
10763 witt_bits,
10764 budget,
10765 result_type_iri,
10766 0usize,
10767 &[],
10768 <Kernel as super::ResolverKernel>::KIND,
10769 );
10770 let buffer = hasher.finalize();
10771 let fp =
10772 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10773 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10774 Ok(Certified::new(cert))
10775 }
10776 }
10777
10778 pub mod superposition {
10796 use super::*;
10797
10798 #[doc(hidden)]
10799 pub struct Kernel;
10800 impl super::ResolverKernel for Kernel {
10801 type Cert = crate::enforcement::BornRuleVerification;
10802 const KIND: crate::enforcement::CertificateKind =
10803 crate::enforcement::CertificateKind::Superposition;
10804 }
10805
10806 pub fn certify<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
10812 input: &Validated<CompileUnit, P>,
10813 ) -> Result<Certified<BornRuleVerification>, Certified<GenericImpossibilityWitness>>
10814 {
10815 certify_at::<P, H>(input, WittLevel::W32)
10816 }
10817
10818 pub fn certify_at<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
10824 input: &Validated<CompileUnit, P>,
10825 level: WittLevel,
10826 ) -> Result<Certified<BornRuleVerification>, Certified<GenericImpossibilityWitness>>
10827 {
10828 let unit = input.inner();
10829 let witt_bits = level.witt_length() as u16;
10830 let budget = unit.thermodynamic_budget();
10831 let result_type_iri = unit.result_type_iri();
10832 let mut hasher = H::initial();
10833 let (binding_count, fold_addr) =
10834 crate::enforcement::primitive_session_binding_signature(unit.bindings());
10835 hasher = crate::enforcement::fold_session_signature(hasher, binding_count, fold_addr);
10836 let (outcome_index, probability) =
10837 crate::enforcement::primitive_measurement_projection(budget);
10838 hasher = crate::enforcement::fold_born_outcome(hasher, outcome_index, probability);
10839 hasher = crate::enforcement::fold_unit_digest(
10840 hasher,
10841 witt_bits,
10842 budget,
10843 result_type_iri,
10844 0usize,
10845 &[],
10846 <Kernel as super::ResolverKernel>::KIND,
10847 );
10848 let buffer = hasher.finalize();
10849 let fp =
10850 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10851 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10852 Ok(Certified::new(cert))
10853 }
10854 }
10855
10856 pub mod measurement {
10874 use super::*;
10875
10876 #[doc(hidden)]
10877 pub struct Kernel;
10878 impl super::ResolverKernel for Kernel {
10879 type Cert = crate::enforcement::MeasurementCertificate;
10880 const KIND: crate::enforcement::CertificateKind =
10881 crate::enforcement::CertificateKind::Measurement;
10882 }
10883
10884 pub fn certify<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
10890 input: &Validated<CompileUnit, P>,
10891 ) -> Result<Certified<MeasurementCertificate>, Certified<GenericImpossibilityWitness>>
10892 {
10893 certify_at::<P, H>(input, WittLevel::W32)
10894 }
10895
10896 pub fn certify_at<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
10902 input: &Validated<CompileUnit, P>,
10903 level: WittLevel,
10904 ) -> Result<Certified<MeasurementCertificate>, Certified<GenericImpossibilityWitness>>
10905 {
10906 let unit = input.inner();
10907 let witt_bits = level.witt_length() as u16;
10908 let budget = unit.thermodynamic_budget();
10909 let result_type_iri = unit.result_type_iri();
10910 let mut hasher = H::initial();
10911 let (outcome_index, probability) =
10912 crate::enforcement::primitive_measurement_projection(budget);
10913 hasher = crate::enforcement::fold_born_outcome(hasher, outcome_index, probability);
10914 hasher = crate::enforcement::fold_unit_digest(
10915 hasher,
10916 witt_bits,
10917 budget,
10918 result_type_iri,
10919 0usize,
10920 &[],
10921 <Kernel as super::ResolverKernel>::KIND,
10922 );
10923 let buffer = hasher.finalize();
10924 let fp =
10925 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
10926 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
10927 Ok(Certified::new(cert))
10928 }
10929 }
10930
10931 pub mod witt_level_resolver {
10949 use super::*;
10950
10951 #[doc(hidden)]
10952 pub struct Kernel;
10953 impl super::ResolverKernel for Kernel {
10954 type Cert = crate::enforcement::GroundingCertificate;
10955 const KIND: crate::enforcement::CertificateKind =
10956 crate::enforcement::CertificateKind::WittLevel;
10957 }
10958
10959 pub fn certify<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
10965 input: &Validated<CompileUnit, P>,
10966 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10967 {
10968 certify_at::<P, H>(input, WittLevel::W32)
10969 }
10970
10971 pub fn certify_at<P: crate::enforcement::ValidationPhase, H: crate::enforcement::Hasher>(
10977 input: &Validated<CompileUnit, P>,
10978 level: WittLevel,
10979 ) -> Result<Certified<GroundingCertificate>, Certified<GenericImpossibilityWitness>>
10980 {
10981 let unit = input.inner();
10982 let witt_bits = level.witt_length() as u16;
10983 let budget = unit.thermodynamic_budget();
10984 let result_type_iri = unit.result_type_iri();
10985 let mut hasher = H::initial();
10986 hasher = hasher.fold_bytes(&witt_bits.to_be_bytes());
10987 let declared_level_bits = unit.witt_level().witt_length() as u16;
10988 hasher = hasher.fold_bytes(&declared_level_bits.to_be_bytes());
10989 hasher = crate::enforcement::fold_unit_digest(
10990 hasher,
10991 witt_bits,
10992 budget,
10993 result_type_iri,
10994 0usize,
10995 &[],
10996 <Kernel as super::ResolverKernel>::KIND,
10997 );
10998 let buffer = hasher.finalize();
10999 let fp =
11000 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11001 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11002 Ok(Certified::new(cert))
11003 }
11004 }
11005
11006 pub mod dihedral_factorization {
11024 use super::*;
11025
11026 #[doc(hidden)]
11027 pub struct Kernel;
11028 impl super::ResolverKernel for Kernel {
11029 type Cert = crate::enforcement::InvolutionCertificate;
11030 const KIND: crate::enforcement::CertificateKind =
11031 crate::enforcement::CertificateKind::DihedralFactorization;
11032 }
11033
11034 pub fn certify<
11040 T: crate::pipeline::ConstrainedTypeShape,
11041 P: crate::enforcement::ValidationPhase,
11042 H: crate::enforcement::Hasher,
11043 >(
11044 input: &Validated<T, P>,
11045 ) -> Result<Certified<InvolutionCertificate>, Certified<GenericImpossibilityWitness>>
11046 {
11047 certify_at::<T, P, H>(input, WittLevel::W32)
11048 }
11049
11050 pub fn certify_at<
11056 T: crate::pipeline::ConstrainedTypeShape,
11057 P: crate::enforcement::ValidationPhase,
11058 H: crate::enforcement::Hasher,
11059 >(
11060 input: &Validated<T, P>,
11061 level: WittLevel,
11062 ) -> Result<Certified<InvolutionCertificate>, Certified<GenericImpossibilityWitness>>
11063 {
11064 let _ = input.inner();
11065 let witt_bits = level.witt_length() as u16;
11066 let (tr_bits, tr_constraints, tr_sat) =
11067 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
11068 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
11069 if tr_sat == 0 {
11070 return Err(Certified::new(GenericImpossibilityWitness::default()));
11071 }
11072 let mut hasher = H::initial();
11073 hasher = crate::enforcement::fold_terminal_reduction(
11074 hasher,
11075 tr_bits,
11076 tr_constraints,
11077 tr_sat,
11078 );
11079 let (orbit_size, representative) =
11080 crate::enforcement::primitive_dihedral_signature::<T>();
11081 hasher =
11082 crate::enforcement::fold_dihedral_signature(hasher, orbit_size, representative);
11083 hasher = crate::enforcement::fold_unit_digest(
11084 hasher,
11085 witt_bits,
11086 witt_bits as u64,
11087 T::IRI,
11088 T::SITE_COUNT,
11089 T::CONSTRAINTS,
11090 <Kernel as super::ResolverKernel>::KIND,
11091 );
11092 let buffer = hasher.finalize();
11093 let fp =
11094 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11095 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11096 Ok(Certified::new(cert))
11097 }
11098 }
11099
11100 pub mod completeness {
11118 use super::*;
11119
11120 #[doc(hidden)]
11121 pub struct Kernel;
11122 impl super::ResolverKernel for Kernel {
11123 type Cert = crate::enforcement::CompletenessCertificate;
11124 const KIND: crate::enforcement::CertificateKind =
11125 crate::enforcement::CertificateKind::Completeness;
11126 }
11127
11128 pub fn certify<
11134 T: crate::pipeline::ConstrainedTypeShape,
11135 P: crate::enforcement::ValidationPhase,
11136 H: crate::enforcement::Hasher,
11137 >(
11138 input: &Validated<T, P>,
11139 ) -> Result<Certified<CompletenessCertificate>, Certified<GenericImpossibilityWitness>>
11140 {
11141 certify_at::<T, P, H>(input, WittLevel::W32)
11142 }
11143
11144 pub fn certify_at<
11150 T: crate::pipeline::ConstrainedTypeShape,
11151 P: crate::enforcement::ValidationPhase,
11152 H: crate::enforcement::Hasher,
11153 >(
11154 input: &Validated<T, P>,
11155 level: WittLevel,
11156 ) -> Result<Certified<CompletenessCertificate>, Certified<GenericImpossibilityWitness>>
11157 {
11158 let _ = input.inner();
11159 let witt_bits = level.witt_length() as u16;
11160 let (tr_bits, tr_constraints, tr_sat) =
11161 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
11162 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
11163 if tr_sat == 0 {
11164 return Err(Certified::new(GenericImpossibilityWitness::default()));
11165 }
11166 let mut hasher = H::initial();
11167 hasher = crate::enforcement::fold_terminal_reduction(
11168 hasher,
11169 tr_bits,
11170 tr_constraints,
11171 tr_sat,
11172 );
11173 let betti = crate::enforcement::primitive_simplicial_nerve_betti::<T>()
11174 .map_err(crate::enforcement::Certified::new)?;
11175 let chi = crate::enforcement::primitive_euler_characteristic(&betti);
11176 hasher = crate::enforcement::fold_betti_tuple(hasher, &betti);
11177 hasher = hasher.fold_bytes(&chi.to_be_bytes());
11178 hasher = crate::enforcement::fold_unit_digest(
11179 hasher,
11180 witt_bits,
11181 witt_bits as u64,
11182 T::IRI,
11183 T::SITE_COUNT,
11184 T::CONSTRAINTS,
11185 <Kernel as super::ResolverKernel>::KIND,
11186 );
11187 let buffer = hasher.finalize();
11188 let fp =
11189 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11190 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11191 Ok(Certified::new(cert))
11192 }
11193 }
11194
11195 pub mod geodesic_validator {
11213 use super::*;
11214
11215 #[doc(hidden)]
11216 pub struct Kernel;
11217 impl super::ResolverKernel for Kernel {
11218 type Cert = crate::enforcement::GeodesicCertificate;
11219 const KIND: crate::enforcement::CertificateKind =
11220 crate::enforcement::CertificateKind::GeodesicValidator;
11221 }
11222
11223 pub fn certify<
11229 T: crate::pipeline::ConstrainedTypeShape,
11230 P: crate::enforcement::ValidationPhase,
11231 H: crate::enforcement::Hasher,
11232 >(
11233 input: &Validated<T, P>,
11234 ) -> Result<Certified<GeodesicCertificate>, Certified<GenericImpossibilityWitness>>
11235 {
11236 certify_at::<T, P, H>(input, WittLevel::W32)
11237 }
11238
11239 pub fn certify_at<
11245 T: crate::pipeline::ConstrainedTypeShape,
11246 P: crate::enforcement::ValidationPhase,
11247 H: crate::enforcement::Hasher,
11248 >(
11249 input: &Validated<T, P>,
11250 level: WittLevel,
11251 ) -> Result<Certified<GeodesicCertificate>, Certified<GenericImpossibilityWitness>>
11252 {
11253 let _ = input.inner();
11254 let witt_bits = level.witt_length() as u16;
11255 let (tr_bits, tr_constraints, tr_sat) =
11256 crate::enforcement::primitive_terminal_reduction::<T>(witt_bits)
11257 .map_err(|_| Certified::new(GenericImpossibilityWitness::default()))?;
11258 if tr_sat == 0 {
11259 return Err(Certified::new(GenericImpossibilityWitness::default()));
11260 }
11261 let mut hasher = H::initial();
11262 hasher = crate::enforcement::fold_terminal_reduction(
11263 hasher,
11264 tr_bits,
11265 tr_constraints,
11266 tr_sat,
11267 );
11268 let jac = crate::enforcement::primitive_curvature_jacobian::<T>();
11269 hasher = crate::enforcement::fold_jacobian_profile(hasher, &jac);
11270 let selected_site = crate::enforcement::primitive_dc10_select(&jac);
11271 hasher = hasher.fold_bytes(&(selected_site as u32).to_be_bytes());
11272 hasher = crate::enforcement::fold_unit_digest(
11273 hasher,
11274 witt_bits,
11275 witt_bits as u64,
11276 T::IRI,
11277 T::SITE_COUNT,
11278 T::CONSTRAINTS,
11279 <Kernel as super::ResolverKernel>::KIND,
11280 );
11281 let buffer = hasher.finalize();
11282 let fp =
11283 crate::enforcement::ContentFingerprint::from_buffer(buffer, H::OUTPUT_BYTES as u8);
11284 let cert = <<Kernel as super::ResolverKernel>::Cert as crate::enforcement::certify_const_mint::MintWithLevelFingerprint>::mint_with_level_fingerprint(witt_bits, fp);
11285 Ok(Certified::new(cert))
11286 }
11287 }
11288}
11289
11290pub trait RingOp<L> {
11294 type Operand;
11296 fn apply(a: Self::Operand, b: Self::Operand) -> Self::Operand;
11298}
11299
11300pub trait UnaryRingOp<L> {
11304 type Operand;
11306 fn apply(a: Self::Operand) -> Self::Operand;
11308}
11309
11310#[derive(Debug, Default, Clone, Copy)]
11312pub struct Mul<L>(PhantomData<L>);
11313
11314#[derive(Debug, Default, Clone, Copy)]
11316pub struct Add<L>(PhantomData<L>);
11317
11318#[derive(Debug, Default, Clone, Copy)]
11320pub struct Sub<L>(PhantomData<L>);
11321
11322#[derive(Debug, Default, Clone, Copy)]
11324pub struct Xor<L>(PhantomData<L>);
11325
11326#[derive(Debug, Default, Clone, Copy)]
11328pub struct And<L>(PhantomData<L>);
11329
11330#[derive(Debug, Default, Clone, Copy)]
11332pub struct Or<L>(PhantomData<L>);
11333
11334#[derive(Debug, Default, Clone, Copy)]
11336pub struct Neg<L>(PhantomData<L>);
11337
11338#[derive(Debug, Default, Clone, Copy)]
11340pub struct BNot<L>(PhantomData<L>);
11341
11342#[derive(Debug, Default, Clone, Copy)]
11344pub struct Succ<L>(PhantomData<L>);
11345
11346#[derive(Debug, Default, Clone, Copy)]
11348pub struct W8;
11349
11350#[derive(Debug, Default, Clone, Copy)]
11352pub struct W16;
11353
11354#[derive(Debug, Default, Clone, Copy)]
11356pub struct W24;
11357
11358#[derive(Debug, Default, Clone, Copy)]
11360pub struct W32;
11361
11362#[derive(Debug, Default, Clone, Copy)]
11364pub struct W40;
11365
11366#[derive(Debug, Default, Clone, Copy)]
11368pub struct W48;
11369
11370#[derive(Debug, Default, Clone, Copy)]
11372pub struct W56;
11373
11374#[derive(Debug, Default, Clone, Copy)]
11376pub struct W64;
11377
11378#[derive(Debug, Default, Clone, Copy)]
11380pub struct W72;
11381
11382#[derive(Debug, Default, Clone, Copy)]
11384pub struct W80;
11385
11386#[derive(Debug, Default, Clone, Copy)]
11388pub struct W88;
11389
11390#[derive(Debug, Default, Clone, Copy)]
11392pub struct W96;
11393
11394#[derive(Debug, Default, Clone, Copy)]
11396pub struct W104;
11397
11398#[derive(Debug, Default, Clone, Copy)]
11400pub struct W112;
11401
11402#[derive(Debug, Default, Clone, Copy)]
11404pub struct W120;
11405
11406#[derive(Debug, Default, Clone, Copy)]
11408pub struct W128;
11409
11410impl RingOp<W8> for Mul<W8> {
11411 type Operand = u8;
11412 #[inline]
11413 fn apply(a: u8, b: u8) -> u8 {
11414 const_ring_eval_w8(PrimitiveOp::Mul, a, b)
11415 }
11416}
11417
11418impl RingOp<W8> for Add<W8> {
11419 type Operand = u8;
11420 #[inline]
11421 fn apply(a: u8, b: u8) -> u8 {
11422 const_ring_eval_w8(PrimitiveOp::Add, a, b)
11423 }
11424}
11425
11426impl RingOp<W8> for Sub<W8> {
11427 type Operand = u8;
11428 #[inline]
11429 fn apply(a: u8, b: u8) -> u8 {
11430 const_ring_eval_w8(PrimitiveOp::Sub, a, b)
11431 }
11432}
11433
11434impl RingOp<W8> for Xor<W8> {
11435 type Operand = u8;
11436 #[inline]
11437 fn apply(a: u8, b: u8) -> u8 {
11438 const_ring_eval_w8(PrimitiveOp::Xor, a, b)
11439 }
11440}
11441
11442impl RingOp<W8> for And<W8> {
11443 type Operand = u8;
11444 #[inline]
11445 fn apply(a: u8, b: u8) -> u8 {
11446 const_ring_eval_w8(PrimitiveOp::And, a, b)
11447 }
11448}
11449
11450impl RingOp<W8> for Or<W8> {
11451 type Operand = u8;
11452 #[inline]
11453 fn apply(a: u8, b: u8) -> u8 {
11454 const_ring_eval_w8(PrimitiveOp::Or, a, b)
11455 }
11456}
11457
11458impl RingOp<W16> for Mul<W16> {
11459 type Operand = u16;
11460 #[inline]
11461 fn apply(a: u16, b: u16) -> u16 {
11462 const_ring_eval_w16(PrimitiveOp::Mul, a, b)
11463 }
11464}
11465
11466impl RingOp<W16> for Add<W16> {
11467 type Operand = u16;
11468 #[inline]
11469 fn apply(a: u16, b: u16) -> u16 {
11470 const_ring_eval_w16(PrimitiveOp::Add, a, b)
11471 }
11472}
11473
11474impl RingOp<W16> for Sub<W16> {
11475 type Operand = u16;
11476 #[inline]
11477 fn apply(a: u16, b: u16) -> u16 {
11478 const_ring_eval_w16(PrimitiveOp::Sub, a, b)
11479 }
11480}
11481
11482impl RingOp<W16> for Xor<W16> {
11483 type Operand = u16;
11484 #[inline]
11485 fn apply(a: u16, b: u16) -> u16 {
11486 const_ring_eval_w16(PrimitiveOp::Xor, a, b)
11487 }
11488}
11489
11490impl RingOp<W16> for And<W16> {
11491 type Operand = u16;
11492 #[inline]
11493 fn apply(a: u16, b: u16) -> u16 {
11494 const_ring_eval_w16(PrimitiveOp::And, a, b)
11495 }
11496}
11497
11498impl RingOp<W16> for Or<W16> {
11499 type Operand = u16;
11500 #[inline]
11501 fn apply(a: u16, b: u16) -> u16 {
11502 const_ring_eval_w16(PrimitiveOp::Or, a, b)
11503 }
11504}
11505
11506impl RingOp<W24> for Mul<W24> {
11507 type Operand = u32;
11508 #[inline]
11509 fn apply(a: u32, b: u32) -> u32 {
11510 const_ring_eval_w24(PrimitiveOp::Mul, a, b)
11511 }
11512}
11513
11514impl RingOp<W24> for Add<W24> {
11515 type Operand = u32;
11516 #[inline]
11517 fn apply(a: u32, b: u32) -> u32 {
11518 const_ring_eval_w24(PrimitiveOp::Add, a, b)
11519 }
11520}
11521
11522impl RingOp<W24> for Sub<W24> {
11523 type Operand = u32;
11524 #[inline]
11525 fn apply(a: u32, b: u32) -> u32 {
11526 const_ring_eval_w24(PrimitiveOp::Sub, a, b)
11527 }
11528}
11529
11530impl RingOp<W24> for Xor<W24> {
11531 type Operand = u32;
11532 #[inline]
11533 fn apply(a: u32, b: u32) -> u32 {
11534 const_ring_eval_w24(PrimitiveOp::Xor, a, b)
11535 }
11536}
11537
11538impl RingOp<W24> for And<W24> {
11539 type Operand = u32;
11540 #[inline]
11541 fn apply(a: u32, b: u32) -> u32 {
11542 const_ring_eval_w24(PrimitiveOp::And, a, b)
11543 }
11544}
11545
11546impl RingOp<W24> for Or<W24> {
11547 type Operand = u32;
11548 #[inline]
11549 fn apply(a: u32, b: u32) -> u32 {
11550 const_ring_eval_w24(PrimitiveOp::Or, a, b)
11551 }
11552}
11553
11554impl RingOp<W32> for Mul<W32> {
11555 type Operand = u32;
11556 #[inline]
11557 fn apply(a: u32, b: u32) -> u32 {
11558 const_ring_eval_w32(PrimitiveOp::Mul, a, b)
11559 }
11560}
11561
11562impl RingOp<W32> for Add<W32> {
11563 type Operand = u32;
11564 #[inline]
11565 fn apply(a: u32, b: u32) -> u32 {
11566 const_ring_eval_w32(PrimitiveOp::Add, a, b)
11567 }
11568}
11569
11570impl RingOp<W32> for Sub<W32> {
11571 type Operand = u32;
11572 #[inline]
11573 fn apply(a: u32, b: u32) -> u32 {
11574 const_ring_eval_w32(PrimitiveOp::Sub, a, b)
11575 }
11576}
11577
11578impl RingOp<W32> for Xor<W32> {
11579 type Operand = u32;
11580 #[inline]
11581 fn apply(a: u32, b: u32) -> u32 {
11582 const_ring_eval_w32(PrimitiveOp::Xor, a, b)
11583 }
11584}
11585
11586impl RingOp<W32> for And<W32> {
11587 type Operand = u32;
11588 #[inline]
11589 fn apply(a: u32, b: u32) -> u32 {
11590 const_ring_eval_w32(PrimitiveOp::And, a, b)
11591 }
11592}
11593
11594impl RingOp<W32> for Or<W32> {
11595 type Operand = u32;
11596 #[inline]
11597 fn apply(a: u32, b: u32) -> u32 {
11598 const_ring_eval_w32(PrimitiveOp::Or, a, b)
11599 }
11600}
11601
11602impl RingOp<W40> for Mul<W40> {
11603 type Operand = u64;
11604 #[inline]
11605 fn apply(a: u64, b: u64) -> u64 {
11606 const_ring_eval_w40(PrimitiveOp::Mul, a, b)
11607 }
11608}
11609
11610impl RingOp<W40> for Add<W40> {
11611 type Operand = u64;
11612 #[inline]
11613 fn apply(a: u64, b: u64) -> u64 {
11614 const_ring_eval_w40(PrimitiveOp::Add, a, b)
11615 }
11616}
11617
11618impl RingOp<W40> for Sub<W40> {
11619 type Operand = u64;
11620 #[inline]
11621 fn apply(a: u64, b: u64) -> u64 {
11622 const_ring_eval_w40(PrimitiveOp::Sub, a, b)
11623 }
11624}
11625
11626impl RingOp<W40> for Xor<W40> {
11627 type Operand = u64;
11628 #[inline]
11629 fn apply(a: u64, b: u64) -> u64 {
11630 const_ring_eval_w40(PrimitiveOp::Xor, a, b)
11631 }
11632}
11633
11634impl RingOp<W40> for And<W40> {
11635 type Operand = u64;
11636 #[inline]
11637 fn apply(a: u64, b: u64) -> u64 {
11638 const_ring_eval_w40(PrimitiveOp::And, a, b)
11639 }
11640}
11641
11642impl RingOp<W40> for Or<W40> {
11643 type Operand = u64;
11644 #[inline]
11645 fn apply(a: u64, b: u64) -> u64 {
11646 const_ring_eval_w40(PrimitiveOp::Or, a, b)
11647 }
11648}
11649
11650impl RingOp<W48> for Mul<W48> {
11651 type Operand = u64;
11652 #[inline]
11653 fn apply(a: u64, b: u64) -> u64 {
11654 const_ring_eval_w48(PrimitiveOp::Mul, a, b)
11655 }
11656}
11657
11658impl RingOp<W48> for Add<W48> {
11659 type Operand = u64;
11660 #[inline]
11661 fn apply(a: u64, b: u64) -> u64 {
11662 const_ring_eval_w48(PrimitiveOp::Add, a, b)
11663 }
11664}
11665
11666impl RingOp<W48> for Sub<W48> {
11667 type Operand = u64;
11668 #[inline]
11669 fn apply(a: u64, b: u64) -> u64 {
11670 const_ring_eval_w48(PrimitiveOp::Sub, a, b)
11671 }
11672}
11673
11674impl RingOp<W48> for Xor<W48> {
11675 type Operand = u64;
11676 #[inline]
11677 fn apply(a: u64, b: u64) -> u64 {
11678 const_ring_eval_w48(PrimitiveOp::Xor, a, b)
11679 }
11680}
11681
11682impl RingOp<W48> for And<W48> {
11683 type Operand = u64;
11684 #[inline]
11685 fn apply(a: u64, b: u64) -> u64 {
11686 const_ring_eval_w48(PrimitiveOp::And, a, b)
11687 }
11688}
11689
11690impl RingOp<W48> for Or<W48> {
11691 type Operand = u64;
11692 #[inline]
11693 fn apply(a: u64, b: u64) -> u64 {
11694 const_ring_eval_w48(PrimitiveOp::Or, a, b)
11695 }
11696}
11697
11698impl RingOp<W56> for Mul<W56> {
11699 type Operand = u64;
11700 #[inline]
11701 fn apply(a: u64, b: u64) -> u64 {
11702 const_ring_eval_w56(PrimitiveOp::Mul, a, b)
11703 }
11704}
11705
11706impl RingOp<W56> for Add<W56> {
11707 type Operand = u64;
11708 #[inline]
11709 fn apply(a: u64, b: u64) -> u64 {
11710 const_ring_eval_w56(PrimitiveOp::Add, a, b)
11711 }
11712}
11713
11714impl RingOp<W56> for Sub<W56> {
11715 type Operand = u64;
11716 #[inline]
11717 fn apply(a: u64, b: u64) -> u64 {
11718 const_ring_eval_w56(PrimitiveOp::Sub, a, b)
11719 }
11720}
11721
11722impl RingOp<W56> for Xor<W56> {
11723 type Operand = u64;
11724 #[inline]
11725 fn apply(a: u64, b: u64) -> u64 {
11726 const_ring_eval_w56(PrimitiveOp::Xor, a, b)
11727 }
11728}
11729
11730impl RingOp<W56> for And<W56> {
11731 type Operand = u64;
11732 #[inline]
11733 fn apply(a: u64, b: u64) -> u64 {
11734 const_ring_eval_w56(PrimitiveOp::And, a, b)
11735 }
11736}
11737
11738impl RingOp<W56> for Or<W56> {
11739 type Operand = u64;
11740 #[inline]
11741 fn apply(a: u64, b: u64) -> u64 {
11742 const_ring_eval_w56(PrimitiveOp::Or, a, b)
11743 }
11744}
11745
11746impl RingOp<W64> for Mul<W64> {
11747 type Operand = u64;
11748 #[inline]
11749 fn apply(a: u64, b: u64) -> u64 {
11750 const_ring_eval_w64(PrimitiveOp::Mul, a, b)
11751 }
11752}
11753
11754impl RingOp<W64> for Add<W64> {
11755 type Operand = u64;
11756 #[inline]
11757 fn apply(a: u64, b: u64) -> u64 {
11758 const_ring_eval_w64(PrimitiveOp::Add, a, b)
11759 }
11760}
11761
11762impl RingOp<W64> for Sub<W64> {
11763 type Operand = u64;
11764 #[inline]
11765 fn apply(a: u64, b: u64) -> u64 {
11766 const_ring_eval_w64(PrimitiveOp::Sub, a, b)
11767 }
11768}
11769
11770impl RingOp<W64> for Xor<W64> {
11771 type Operand = u64;
11772 #[inline]
11773 fn apply(a: u64, b: u64) -> u64 {
11774 const_ring_eval_w64(PrimitiveOp::Xor, a, b)
11775 }
11776}
11777
11778impl RingOp<W64> for And<W64> {
11779 type Operand = u64;
11780 #[inline]
11781 fn apply(a: u64, b: u64) -> u64 {
11782 const_ring_eval_w64(PrimitiveOp::And, a, b)
11783 }
11784}
11785
11786impl RingOp<W64> for Or<W64> {
11787 type Operand = u64;
11788 #[inline]
11789 fn apply(a: u64, b: u64) -> u64 {
11790 const_ring_eval_w64(PrimitiveOp::Or, a, b)
11791 }
11792}
11793
11794impl RingOp<W72> for Mul<W72> {
11795 type Operand = u128;
11796 #[inline]
11797 fn apply(a: u128, b: u128) -> u128 {
11798 const_ring_eval_w72(PrimitiveOp::Mul, a, b)
11799 }
11800}
11801
11802impl RingOp<W72> for Add<W72> {
11803 type Operand = u128;
11804 #[inline]
11805 fn apply(a: u128, b: u128) -> u128 {
11806 const_ring_eval_w72(PrimitiveOp::Add, a, b)
11807 }
11808}
11809
11810impl RingOp<W72> for Sub<W72> {
11811 type Operand = u128;
11812 #[inline]
11813 fn apply(a: u128, b: u128) -> u128 {
11814 const_ring_eval_w72(PrimitiveOp::Sub, a, b)
11815 }
11816}
11817
11818impl RingOp<W72> for Xor<W72> {
11819 type Operand = u128;
11820 #[inline]
11821 fn apply(a: u128, b: u128) -> u128 {
11822 const_ring_eval_w72(PrimitiveOp::Xor, a, b)
11823 }
11824}
11825
11826impl RingOp<W72> for And<W72> {
11827 type Operand = u128;
11828 #[inline]
11829 fn apply(a: u128, b: u128) -> u128 {
11830 const_ring_eval_w72(PrimitiveOp::And, a, b)
11831 }
11832}
11833
11834impl RingOp<W72> for Or<W72> {
11835 type Operand = u128;
11836 #[inline]
11837 fn apply(a: u128, b: u128) -> u128 {
11838 const_ring_eval_w72(PrimitiveOp::Or, a, b)
11839 }
11840}
11841
11842impl RingOp<W80> for Mul<W80> {
11843 type Operand = u128;
11844 #[inline]
11845 fn apply(a: u128, b: u128) -> u128 {
11846 const_ring_eval_w80(PrimitiveOp::Mul, a, b)
11847 }
11848}
11849
11850impl RingOp<W80> for Add<W80> {
11851 type Operand = u128;
11852 #[inline]
11853 fn apply(a: u128, b: u128) -> u128 {
11854 const_ring_eval_w80(PrimitiveOp::Add, a, b)
11855 }
11856}
11857
11858impl RingOp<W80> for Sub<W80> {
11859 type Operand = u128;
11860 #[inline]
11861 fn apply(a: u128, b: u128) -> u128 {
11862 const_ring_eval_w80(PrimitiveOp::Sub, a, b)
11863 }
11864}
11865
11866impl RingOp<W80> for Xor<W80> {
11867 type Operand = u128;
11868 #[inline]
11869 fn apply(a: u128, b: u128) -> u128 {
11870 const_ring_eval_w80(PrimitiveOp::Xor, a, b)
11871 }
11872}
11873
11874impl RingOp<W80> for And<W80> {
11875 type Operand = u128;
11876 #[inline]
11877 fn apply(a: u128, b: u128) -> u128 {
11878 const_ring_eval_w80(PrimitiveOp::And, a, b)
11879 }
11880}
11881
11882impl RingOp<W80> for Or<W80> {
11883 type Operand = u128;
11884 #[inline]
11885 fn apply(a: u128, b: u128) -> u128 {
11886 const_ring_eval_w80(PrimitiveOp::Or, a, b)
11887 }
11888}
11889
11890impl RingOp<W88> for Mul<W88> {
11891 type Operand = u128;
11892 #[inline]
11893 fn apply(a: u128, b: u128) -> u128 {
11894 const_ring_eval_w88(PrimitiveOp::Mul, a, b)
11895 }
11896}
11897
11898impl RingOp<W88> for Add<W88> {
11899 type Operand = u128;
11900 #[inline]
11901 fn apply(a: u128, b: u128) -> u128 {
11902 const_ring_eval_w88(PrimitiveOp::Add, a, b)
11903 }
11904}
11905
11906impl RingOp<W88> for Sub<W88> {
11907 type Operand = u128;
11908 #[inline]
11909 fn apply(a: u128, b: u128) -> u128 {
11910 const_ring_eval_w88(PrimitiveOp::Sub, a, b)
11911 }
11912}
11913
11914impl RingOp<W88> for Xor<W88> {
11915 type Operand = u128;
11916 #[inline]
11917 fn apply(a: u128, b: u128) -> u128 {
11918 const_ring_eval_w88(PrimitiveOp::Xor, a, b)
11919 }
11920}
11921
11922impl RingOp<W88> for And<W88> {
11923 type Operand = u128;
11924 #[inline]
11925 fn apply(a: u128, b: u128) -> u128 {
11926 const_ring_eval_w88(PrimitiveOp::And, a, b)
11927 }
11928}
11929
11930impl RingOp<W88> for Or<W88> {
11931 type Operand = u128;
11932 #[inline]
11933 fn apply(a: u128, b: u128) -> u128 {
11934 const_ring_eval_w88(PrimitiveOp::Or, a, b)
11935 }
11936}
11937
11938impl RingOp<W96> for Mul<W96> {
11939 type Operand = u128;
11940 #[inline]
11941 fn apply(a: u128, b: u128) -> u128 {
11942 const_ring_eval_w96(PrimitiveOp::Mul, a, b)
11943 }
11944}
11945
11946impl RingOp<W96> for Add<W96> {
11947 type Operand = u128;
11948 #[inline]
11949 fn apply(a: u128, b: u128) -> u128 {
11950 const_ring_eval_w96(PrimitiveOp::Add, a, b)
11951 }
11952}
11953
11954impl RingOp<W96> for Sub<W96> {
11955 type Operand = u128;
11956 #[inline]
11957 fn apply(a: u128, b: u128) -> u128 {
11958 const_ring_eval_w96(PrimitiveOp::Sub, a, b)
11959 }
11960}
11961
11962impl RingOp<W96> for Xor<W96> {
11963 type Operand = u128;
11964 #[inline]
11965 fn apply(a: u128, b: u128) -> u128 {
11966 const_ring_eval_w96(PrimitiveOp::Xor, a, b)
11967 }
11968}
11969
11970impl RingOp<W96> for And<W96> {
11971 type Operand = u128;
11972 #[inline]
11973 fn apply(a: u128, b: u128) -> u128 {
11974 const_ring_eval_w96(PrimitiveOp::And, a, b)
11975 }
11976}
11977
11978impl RingOp<W96> for Or<W96> {
11979 type Operand = u128;
11980 #[inline]
11981 fn apply(a: u128, b: u128) -> u128 {
11982 const_ring_eval_w96(PrimitiveOp::Or, a, b)
11983 }
11984}
11985
11986impl RingOp<W104> for Mul<W104> {
11987 type Operand = u128;
11988 #[inline]
11989 fn apply(a: u128, b: u128) -> u128 {
11990 const_ring_eval_w104(PrimitiveOp::Mul, a, b)
11991 }
11992}
11993
11994impl RingOp<W104> for Add<W104> {
11995 type Operand = u128;
11996 #[inline]
11997 fn apply(a: u128, b: u128) -> u128 {
11998 const_ring_eval_w104(PrimitiveOp::Add, a, b)
11999 }
12000}
12001
12002impl RingOp<W104> for Sub<W104> {
12003 type Operand = u128;
12004 #[inline]
12005 fn apply(a: u128, b: u128) -> u128 {
12006 const_ring_eval_w104(PrimitiveOp::Sub, a, b)
12007 }
12008}
12009
12010impl RingOp<W104> for Xor<W104> {
12011 type Operand = u128;
12012 #[inline]
12013 fn apply(a: u128, b: u128) -> u128 {
12014 const_ring_eval_w104(PrimitiveOp::Xor, a, b)
12015 }
12016}
12017
12018impl RingOp<W104> for And<W104> {
12019 type Operand = u128;
12020 #[inline]
12021 fn apply(a: u128, b: u128) -> u128 {
12022 const_ring_eval_w104(PrimitiveOp::And, a, b)
12023 }
12024}
12025
12026impl RingOp<W104> for Or<W104> {
12027 type Operand = u128;
12028 #[inline]
12029 fn apply(a: u128, b: u128) -> u128 {
12030 const_ring_eval_w104(PrimitiveOp::Or, a, b)
12031 }
12032}
12033
12034impl RingOp<W112> for Mul<W112> {
12035 type Operand = u128;
12036 #[inline]
12037 fn apply(a: u128, b: u128) -> u128 {
12038 const_ring_eval_w112(PrimitiveOp::Mul, a, b)
12039 }
12040}
12041
12042impl RingOp<W112> for Add<W112> {
12043 type Operand = u128;
12044 #[inline]
12045 fn apply(a: u128, b: u128) -> u128 {
12046 const_ring_eval_w112(PrimitiveOp::Add, a, b)
12047 }
12048}
12049
12050impl RingOp<W112> for Sub<W112> {
12051 type Operand = u128;
12052 #[inline]
12053 fn apply(a: u128, b: u128) -> u128 {
12054 const_ring_eval_w112(PrimitiveOp::Sub, a, b)
12055 }
12056}
12057
12058impl RingOp<W112> for Xor<W112> {
12059 type Operand = u128;
12060 #[inline]
12061 fn apply(a: u128, b: u128) -> u128 {
12062 const_ring_eval_w112(PrimitiveOp::Xor, a, b)
12063 }
12064}
12065
12066impl RingOp<W112> for And<W112> {
12067 type Operand = u128;
12068 #[inline]
12069 fn apply(a: u128, b: u128) -> u128 {
12070 const_ring_eval_w112(PrimitiveOp::And, a, b)
12071 }
12072}
12073
12074impl RingOp<W112> for Or<W112> {
12075 type Operand = u128;
12076 #[inline]
12077 fn apply(a: u128, b: u128) -> u128 {
12078 const_ring_eval_w112(PrimitiveOp::Or, a, b)
12079 }
12080}
12081
12082impl RingOp<W120> for Mul<W120> {
12083 type Operand = u128;
12084 #[inline]
12085 fn apply(a: u128, b: u128) -> u128 {
12086 const_ring_eval_w120(PrimitiveOp::Mul, a, b)
12087 }
12088}
12089
12090impl RingOp<W120> for Add<W120> {
12091 type Operand = u128;
12092 #[inline]
12093 fn apply(a: u128, b: u128) -> u128 {
12094 const_ring_eval_w120(PrimitiveOp::Add, a, b)
12095 }
12096}
12097
12098impl RingOp<W120> for Sub<W120> {
12099 type Operand = u128;
12100 #[inline]
12101 fn apply(a: u128, b: u128) -> u128 {
12102 const_ring_eval_w120(PrimitiveOp::Sub, a, b)
12103 }
12104}
12105
12106impl RingOp<W120> for Xor<W120> {
12107 type Operand = u128;
12108 #[inline]
12109 fn apply(a: u128, b: u128) -> u128 {
12110 const_ring_eval_w120(PrimitiveOp::Xor, a, b)
12111 }
12112}
12113
12114impl RingOp<W120> for And<W120> {
12115 type Operand = u128;
12116 #[inline]
12117 fn apply(a: u128, b: u128) -> u128 {
12118 const_ring_eval_w120(PrimitiveOp::And, a, b)
12119 }
12120}
12121
12122impl RingOp<W120> for Or<W120> {
12123 type Operand = u128;
12124 #[inline]
12125 fn apply(a: u128, b: u128) -> u128 {
12126 const_ring_eval_w120(PrimitiveOp::Or, a, b)
12127 }
12128}
12129
12130impl RingOp<W128> for Mul<W128> {
12131 type Operand = u128;
12132 #[inline]
12133 fn apply(a: u128, b: u128) -> u128 {
12134 const_ring_eval_w128(PrimitiveOp::Mul, a, b)
12135 }
12136}
12137
12138impl RingOp<W128> for Add<W128> {
12139 type Operand = u128;
12140 #[inline]
12141 fn apply(a: u128, b: u128) -> u128 {
12142 const_ring_eval_w128(PrimitiveOp::Add, a, b)
12143 }
12144}
12145
12146impl RingOp<W128> for Sub<W128> {
12147 type Operand = u128;
12148 #[inline]
12149 fn apply(a: u128, b: u128) -> u128 {
12150 const_ring_eval_w128(PrimitiveOp::Sub, a, b)
12151 }
12152}
12153
12154impl RingOp<W128> for Xor<W128> {
12155 type Operand = u128;
12156 #[inline]
12157 fn apply(a: u128, b: u128) -> u128 {
12158 const_ring_eval_w128(PrimitiveOp::Xor, a, b)
12159 }
12160}
12161
12162impl RingOp<W128> for And<W128> {
12163 type Operand = u128;
12164 #[inline]
12165 fn apply(a: u128, b: u128) -> u128 {
12166 const_ring_eval_w128(PrimitiveOp::And, a, b)
12167 }
12168}
12169
12170impl RingOp<W128> for Or<W128> {
12171 type Operand = u128;
12172 #[inline]
12173 fn apply(a: u128, b: u128) -> u128 {
12174 const_ring_eval_w128(PrimitiveOp::Or, a, b)
12175 }
12176}
12177
12178impl UnaryRingOp<W8> for Neg<W8> {
12179 type Operand = u8;
12180 #[inline]
12181 fn apply(a: u8) -> u8 {
12182 const_ring_eval_w8(PrimitiveOp::Sub, 0, a)
12183 }
12184}
12185
12186impl UnaryRingOp<W8> for BNot<W8> {
12187 type Operand = u8;
12188 #[inline]
12189 fn apply(a: u8) -> u8 {
12190 const_ring_eval_w8(PrimitiveOp::Xor, a, u8::MAX)
12191 }
12192}
12193
12194impl UnaryRingOp<W8> for Succ<W8> {
12195 type Operand = u8;
12196 #[inline]
12197 fn apply(a: u8) -> u8 {
12198 <Neg<W8> as UnaryRingOp<W8>>::apply(<BNot<W8> as UnaryRingOp<W8>>::apply(a))
12199 }
12200}
12201
12202impl UnaryRingOp<W16> for Neg<W16> {
12203 type Operand = u16;
12204 #[inline]
12205 fn apply(a: u16) -> u16 {
12206 const_ring_eval_w16(PrimitiveOp::Sub, 0, a)
12207 }
12208}
12209
12210impl UnaryRingOp<W16> for BNot<W16> {
12211 type Operand = u16;
12212 #[inline]
12213 fn apply(a: u16) -> u16 {
12214 const_ring_eval_w16(PrimitiveOp::Xor, a, u16::MAX)
12215 }
12216}
12217
12218impl UnaryRingOp<W16> for Succ<W16> {
12219 type Operand = u16;
12220 #[inline]
12221 fn apply(a: u16) -> u16 {
12222 <Neg<W16> as UnaryRingOp<W16>>::apply(<BNot<W16> as UnaryRingOp<W16>>::apply(a))
12223 }
12224}
12225
12226impl UnaryRingOp<W24> for Neg<W24> {
12227 type Operand = u32;
12228 #[inline]
12229 fn apply(a: u32) -> u32 {
12230 const_ring_eval_w24(PrimitiveOp::Sub, 0, a)
12231 }
12232}
12233
12234impl UnaryRingOp<W24> for BNot<W24> {
12235 type Operand = u32;
12236 #[inline]
12237 fn apply(a: u32) -> u32 {
12238 const_ring_eval_w24(PrimitiveOp::Xor, a, 0x00FF_FFFFu32)
12239 }
12240}
12241
12242impl UnaryRingOp<W24> for Succ<W24> {
12243 type Operand = u32;
12244 #[inline]
12245 fn apply(a: u32) -> u32 {
12246 <Neg<W24> as UnaryRingOp<W24>>::apply(<BNot<W24> as UnaryRingOp<W24>>::apply(a))
12247 }
12248}
12249
12250impl UnaryRingOp<W32> for Neg<W32> {
12251 type Operand = u32;
12252 #[inline]
12253 fn apply(a: u32) -> u32 {
12254 const_ring_eval_w32(PrimitiveOp::Sub, 0, a)
12255 }
12256}
12257
12258impl UnaryRingOp<W32> for BNot<W32> {
12259 type Operand = u32;
12260 #[inline]
12261 fn apply(a: u32) -> u32 {
12262 const_ring_eval_w32(PrimitiveOp::Xor, a, u32::MAX)
12263 }
12264}
12265
12266impl UnaryRingOp<W32> for Succ<W32> {
12267 type Operand = u32;
12268 #[inline]
12269 fn apply(a: u32) -> u32 {
12270 <Neg<W32> as UnaryRingOp<W32>>::apply(<BNot<W32> as UnaryRingOp<W32>>::apply(a))
12271 }
12272}
12273
12274impl UnaryRingOp<W40> for Neg<W40> {
12275 type Operand = u64;
12276 #[inline]
12277 fn apply(a: u64) -> u64 {
12278 const_ring_eval_w40(PrimitiveOp::Sub, 0, a)
12279 }
12280}
12281
12282impl UnaryRingOp<W40> for BNot<W40> {
12283 type Operand = u64;
12284 #[inline]
12285 fn apply(a: u64) -> u64 {
12286 const_ring_eval_w40(PrimitiveOp::Xor, a, 0x0000_00FF_FFFF_FFFFu64)
12287 }
12288}
12289
12290impl UnaryRingOp<W40> for Succ<W40> {
12291 type Operand = u64;
12292 #[inline]
12293 fn apply(a: u64) -> u64 {
12294 <Neg<W40> as UnaryRingOp<W40>>::apply(<BNot<W40> as UnaryRingOp<W40>>::apply(a))
12295 }
12296}
12297
12298impl UnaryRingOp<W48> for Neg<W48> {
12299 type Operand = u64;
12300 #[inline]
12301 fn apply(a: u64) -> u64 {
12302 const_ring_eval_w48(PrimitiveOp::Sub, 0, a)
12303 }
12304}
12305
12306impl UnaryRingOp<W48> for BNot<W48> {
12307 type Operand = u64;
12308 #[inline]
12309 fn apply(a: u64) -> u64 {
12310 const_ring_eval_w48(PrimitiveOp::Xor, a, 0x0000_FFFF_FFFF_FFFFu64)
12311 }
12312}
12313
12314impl UnaryRingOp<W48> for Succ<W48> {
12315 type Operand = u64;
12316 #[inline]
12317 fn apply(a: u64) -> u64 {
12318 <Neg<W48> as UnaryRingOp<W48>>::apply(<BNot<W48> as UnaryRingOp<W48>>::apply(a))
12319 }
12320}
12321
12322impl UnaryRingOp<W56> for Neg<W56> {
12323 type Operand = u64;
12324 #[inline]
12325 fn apply(a: u64) -> u64 {
12326 const_ring_eval_w56(PrimitiveOp::Sub, 0, a)
12327 }
12328}
12329
12330impl UnaryRingOp<W56> for BNot<W56> {
12331 type Operand = u64;
12332 #[inline]
12333 fn apply(a: u64) -> u64 {
12334 const_ring_eval_w56(PrimitiveOp::Xor, a, 0x00FF_FFFF_FFFF_FFFFu64)
12335 }
12336}
12337
12338impl UnaryRingOp<W56> for Succ<W56> {
12339 type Operand = u64;
12340 #[inline]
12341 fn apply(a: u64) -> u64 {
12342 <Neg<W56> as UnaryRingOp<W56>>::apply(<BNot<W56> as UnaryRingOp<W56>>::apply(a))
12343 }
12344}
12345
12346impl UnaryRingOp<W64> for Neg<W64> {
12347 type Operand = u64;
12348 #[inline]
12349 fn apply(a: u64) -> u64 {
12350 const_ring_eval_w64(PrimitiveOp::Sub, 0, a)
12351 }
12352}
12353
12354impl UnaryRingOp<W64> for BNot<W64> {
12355 type Operand = u64;
12356 #[inline]
12357 fn apply(a: u64) -> u64 {
12358 const_ring_eval_w64(PrimitiveOp::Xor, a, u64::MAX)
12359 }
12360}
12361
12362impl UnaryRingOp<W64> for Succ<W64> {
12363 type Operand = u64;
12364 #[inline]
12365 fn apply(a: u64) -> u64 {
12366 <Neg<W64> as UnaryRingOp<W64>>::apply(<BNot<W64> as UnaryRingOp<W64>>::apply(a))
12367 }
12368}
12369
12370impl UnaryRingOp<W72> for Neg<W72> {
12371 type Operand = u128;
12372 #[inline]
12373 fn apply(a: u128) -> u128 {
12374 const_ring_eval_w72(PrimitiveOp::Sub, 0, a)
12375 }
12376}
12377
12378impl UnaryRingOp<W72> for BNot<W72> {
12379 type Operand = u128;
12380 #[inline]
12381 fn apply(a: u128) -> u128 {
12382 const_ring_eval_w72(PrimitiveOp::Xor, a, u128::MAX >> (128 - 72))
12383 }
12384}
12385
12386impl UnaryRingOp<W72> for Succ<W72> {
12387 type Operand = u128;
12388 #[inline]
12389 fn apply(a: u128) -> u128 {
12390 <Neg<W72> as UnaryRingOp<W72>>::apply(<BNot<W72> as UnaryRingOp<W72>>::apply(a))
12391 }
12392}
12393
12394impl UnaryRingOp<W80> for Neg<W80> {
12395 type Operand = u128;
12396 #[inline]
12397 fn apply(a: u128) -> u128 {
12398 const_ring_eval_w80(PrimitiveOp::Sub, 0, a)
12399 }
12400}
12401
12402impl UnaryRingOp<W80> for BNot<W80> {
12403 type Operand = u128;
12404 #[inline]
12405 fn apply(a: u128) -> u128 {
12406 const_ring_eval_w80(PrimitiveOp::Xor, a, u128::MAX >> (128 - 80))
12407 }
12408}
12409
12410impl UnaryRingOp<W80> for Succ<W80> {
12411 type Operand = u128;
12412 #[inline]
12413 fn apply(a: u128) -> u128 {
12414 <Neg<W80> as UnaryRingOp<W80>>::apply(<BNot<W80> as UnaryRingOp<W80>>::apply(a))
12415 }
12416}
12417
12418impl UnaryRingOp<W88> for Neg<W88> {
12419 type Operand = u128;
12420 #[inline]
12421 fn apply(a: u128) -> u128 {
12422 const_ring_eval_w88(PrimitiveOp::Sub, 0, a)
12423 }
12424}
12425
12426impl UnaryRingOp<W88> for BNot<W88> {
12427 type Operand = u128;
12428 #[inline]
12429 fn apply(a: u128) -> u128 {
12430 const_ring_eval_w88(PrimitiveOp::Xor, a, u128::MAX >> (128 - 88))
12431 }
12432}
12433
12434impl UnaryRingOp<W88> for Succ<W88> {
12435 type Operand = u128;
12436 #[inline]
12437 fn apply(a: u128) -> u128 {
12438 <Neg<W88> as UnaryRingOp<W88>>::apply(<BNot<W88> as UnaryRingOp<W88>>::apply(a))
12439 }
12440}
12441
12442impl UnaryRingOp<W96> for Neg<W96> {
12443 type Operand = u128;
12444 #[inline]
12445 fn apply(a: u128) -> u128 {
12446 const_ring_eval_w96(PrimitiveOp::Sub, 0, a)
12447 }
12448}
12449
12450impl UnaryRingOp<W96> for BNot<W96> {
12451 type Operand = u128;
12452 #[inline]
12453 fn apply(a: u128) -> u128 {
12454 const_ring_eval_w96(PrimitiveOp::Xor, a, u128::MAX >> (128 - 96))
12455 }
12456}
12457
12458impl UnaryRingOp<W96> for Succ<W96> {
12459 type Operand = u128;
12460 #[inline]
12461 fn apply(a: u128) -> u128 {
12462 <Neg<W96> as UnaryRingOp<W96>>::apply(<BNot<W96> as UnaryRingOp<W96>>::apply(a))
12463 }
12464}
12465
12466impl UnaryRingOp<W104> for Neg<W104> {
12467 type Operand = u128;
12468 #[inline]
12469 fn apply(a: u128) -> u128 {
12470 const_ring_eval_w104(PrimitiveOp::Sub, 0, a)
12471 }
12472}
12473
12474impl UnaryRingOp<W104> for BNot<W104> {
12475 type Operand = u128;
12476 #[inline]
12477 fn apply(a: u128) -> u128 {
12478 const_ring_eval_w104(PrimitiveOp::Xor, a, u128::MAX >> (128 - 104))
12479 }
12480}
12481
12482impl UnaryRingOp<W104> for Succ<W104> {
12483 type Operand = u128;
12484 #[inline]
12485 fn apply(a: u128) -> u128 {
12486 <Neg<W104> as UnaryRingOp<W104>>::apply(<BNot<W104> as UnaryRingOp<W104>>::apply(a))
12487 }
12488}
12489
12490impl UnaryRingOp<W112> for Neg<W112> {
12491 type Operand = u128;
12492 #[inline]
12493 fn apply(a: u128) -> u128 {
12494 const_ring_eval_w112(PrimitiveOp::Sub, 0, a)
12495 }
12496}
12497
12498impl UnaryRingOp<W112> for BNot<W112> {
12499 type Operand = u128;
12500 #[inline]
12501 fn apply(a: u128) -> u128 {
12502 const_ring_eval_w112(PrimitiveOp::Xor, a, u128::MAX >> (128 - 112))
12503 }
12504}
12505
12506impl UnaryRingOp<W112> for Succ<W112> {
12507 type Operand = u128;
12508 #[inline]
12509 fn apply(a: u128) -> u128 {
12510 <Neg<W112> as UnaryRingOp<W112>>::apply(<BNot<W112> as UnaryRingOp<W112>>::apply(a))
12511 }
12512}
12513
12514impl UnaryRingOp<W120> for Neg<W120> {
12515 type Operand = u128;
12516 #[inline]
12517 fn apply(a: u128) -> u128 {
12518 const_ring_eval_w120(PrimitiveOp::Sub, 0, a)
12519 }
12520}
12521
12522impl UnaryRingOp<W120> for BNot<W120> {
12523 type Operand = u128;
12524 #[inline]
12525 fn apply(a: u128) -> u128 {
12526 const_ring_eval_w120(PrimitiveOp::Xor, a, u128::MAX >> (128 - 120))
12527 }
12528}
12529
12530impl UnaryRingOp<W120> for Succ<W120> {
12531 type Operand = u128;
12532 #[inline]
12533 fn apply(a: u128) -> u128 {
12534 <Neg<W120> as UnaryRingOp<W120>>::apply(<BNot<W120> as UnaryRingOp<W120>>::apply(a))
12535 }
12536}
12537
12538impl UnaryRingOp<W128> for Neg<W128> {
12539 type Operand = u128;
12540 #[inline]
12541 fn apply(a: u128) -> u128 {
12542 const_ring_eval_w128(PrimitiveOp::Sub, 0, a)
12543 }
12544}
12545
12546impl UnaryRingOp<W128> for BNot<W128> {
12547 type Operand = u128;
12548 #[inline]
12549 fn apply(a: u128) -> u128 {
12550 const_ring_eval_w128(PrimitiveOp::Xor, a, u128::MAX)
12551 }
12552}
12553
12554impl UnaryRingOp<W128> for Succ<W128> {
12555 type Operand = u128;
12556 #[inline]
12557 fn apply(a: u128) -> u128 {
12558 <Neg<W128> as UnaryRingOp<W128>>::apply(<BNot<W128> as UnaryRingOp<W128>>::apply(a))
12559 }
12560}
12561
12562pub trait ValidLevelEmbedding: valid_level_embedding_sealed::Sealed {}
12565
12566mod valid_level_embedding_sealed {
12567 pub trait Sealed {}
12569 impl Sealed for (super::W8, super::W8) {}
12570 impl Sealed for (super::W8, super::W16) {}
12571 impl Sealed for (super::W8, super::W24) {}
12572 impl Sealed for (super::W8, super::W32) {}
12573 impl Sealed for (super::W8, super::W40) {}
12574 impl Sealed for (super::W8, super::W48) {}
12575 impl Sealed for (super::W8, super::W56) {}
12576 impl Sealed for (super::W8, super::W64) {}
12577 impl Sealed for (super::W8, super::W72) {}
12578 impl Sealed for (super::W8, super::W80) {}
12579 impl Sealed for (super::W8, super::W88) {}
12580 impl Sealed for (super::W8, super::W96) {}
12581 impl Sealed for (super::W8, super::W104) {}
12582 impl Sealed for (super::W8, super::W112) {}
12583 impl Sealed for (super::W8, super::W120) {}
12584 impl Sealed for (super::W8, super::W128) {}
12585 impl Sealed for (super::W16, super::W16) {}
12586 impl Sealed for (super::W16, super::W24) {}
12587 impl Sealed for (super::W16, super::W32) {}
12588 impl Sealed for (super::W16, super::W40) {}
12589 impl Sealed for (super::W16, super::W48) {}
12590 impl Sealed for (super::W16, super::W56) {}
12591 impl Sealed for (super::W16, super::W64) {}
12592 impl Sealed for (super::W16, super::W72) {}
12593 impl Sealed for (super::W16, super::W80) {}
12594 impl Sealed for (super::W16, super::W88) {}
12595 impl Sealed for (super::W16, super::W96) {}
12596 impl Sealed for (super::W16, super::W104) {}
12597 impl Sealed for (super::W16, super::W112) {}
12598 impl Sealed for (super::W16, super::W120) {}
12599 impl Sealed for (super::W16, super::W128) {}
12600 impl Sealed for (super::W24, super::W24) {}
12601 impl Sealed for (super::W24, super::W32) {}
12602 impl Sealed for (super::W24, super::W40) {}
12603 impl Sealed for (super::W24, super::W48) {}
12604 impl Sealed for (super::W24, super::W56) {}
12605 impl Sealed for (super::W24, super::W64) {}
12606 impl Sealed for (super::W24, super::W72) {}
12607 impl Sealed for (super::W24, super::W80) {}
12608 impl Sealed for (super::W24, super::W88) {}
12609 impl Sealed for (super::W24, super::W96) {}
12610 impl Sealed for (super::W24, super::W104) {}
12611 impl Sealed for (super::W24, super::W112) {}
12612 impl Sealed for (super::W24, super::W120) {}
12613 impl Sealed for (super::W24, super::W128) {}
12614 impl Sealed for (super::W32, super::W32) {}
12615 impl Sealed for (super::W32, super::W40) {}
12616 impl Sealed for (super::W32, super::W48) {}
12617 impl Sealed for (super::W32, super::W56) {}
12618 impl Sealed for (super::W32, super::W64) {}
12619 impl Sealed for (super::W32, super::W72) {}
12620 impl Sealed for (super::W32, super::W80) {}
12621 impl Sealed for (super::W32, super::W88) {}
12622 impl Sealed for (super::W32, super::W96) {}
12623 impl Sealed for (super::W32, super::W104) {}
12624 impl Sealed for (super::W32, super::W112) {}
12625 impl Sealed for (super::W32, super::W120) {}
12626 impl Sealed for (super::W32, super::W128) {}
12627 impl Sealed for (super::W40, super::W40) {}
12628 impl Sealed for (super::W40, super::W48) {}
12629 impl Sealed for (super::W40, super::W56) {}
12630 impl Sealed for (super::W40, super::W64) {}
12631 impl Sealed for (super::W40, super::W72) {}
12632 impl Sealed for (super::W40, super::W80) {}
12633 impl Sealed for (super::W40, super::W88) {}
12634 impl Sealed for (super::W40, super::W96) {}
12635 impl Sealed for (super::W40, super::W104) {}
12636 impl Sealed for (super::W40, super::W112) {}
12637 impl Sealed for (super::W40, super::W120) {}
12638 impl Sealed for (super::W40, super::W128) {}
12639 impl Sealed for (super::W48, super::W48) {}
12640 impl Sealed for (super::W48, super::W56) {}
12641 impl Sealed for (super::W48, super::W64) {}
12642 impl Sealed for (super::W48, super::W72) {}
12643 impl Sealed for (super::W48, super::W80) {}
12644 impl Sealed for (super::W48, super::W88) {}
12645 impl Sealed for (super::W48, super::W96) {}
12646 impl Sealed for (super::W48, super::W104) {}
12647 impl Sealed for (super::W48, super::W112) {}
12648 impl Sealed for (super::W48, super::W120) {}
12649 impl Sealed for (super::W48, super::W128) {}
12650 impl Sealed for (super::W56, super::W56) {}
12651 impl Sealed for (super::W56, super::W64) {}
12652 impl Sealed for (super::W56, super::W72) {}
12653 impl Sealed for (super::W56, super::W80) {}
12654 impl Sealed for (super::W56, super::W88) {}
12655 impl Sealed for (super::W56, super::W96) {}
12656 impl Sealed for (super::W56, super::W104) {}
12657 impl Sealed for (super::W56, super::W112) {}
12658 impl Sealed for (super::W56, super::W120) {}
12659 impl Sealed for (super::W56, super::W128) {}
12660 impl Sealed for (super::W64, super::W64) {}
12661 impl Sealed for (super::W64, super::W72) {}
12662 impl Sealed for (super::W64, super::W80) {}
12663 impl Sealed for (super::W64, super::W88) {}
12664 impl Sealed for (super::W64, super::W96) {}
12665 impl Sealed for (super::W64, super::W104) {}
12666 impl Sealed for (super::W64, super::W112) {}
12667 impl Sealed for (super::W64, super::W120) {}
12668 impl Sealed for (super::W64, super::W128) {}
12669 impl Sealed for (super::W72, super::W72) {}
12670 impl Sealed for (super::W72, super::W80) {}
12671 impl Sealed for (super::W72, super::W88) {}
12672 impl Sealed for (super::W72, super::W96) {}
12673 impl Sealed for (super::W72, super::W104) {}
12674 impl Sealed for (super::W72, super::W112) {}
12675 impl Sealed for (super::W72, super::W120) {}
12676 impl Sealed for (super::W72, super::W128) {}
12677 impl Sealed for (super::W80, super::W80) {}
12678 impl Sealed for (super::W80, super::W88) {}
12679 impl Sealed for (super::W80, super::W96) {}
12680 impl Sealed for (super::W80, super::W104) {}
12681 impl Sealed for (super::W80, super::W112) {}
12682 impl Sealed for (super::W80, super::W120) {}
12683 impl Sealed for (super::W80, super::W128) {}
12684 impl Sealed for (super::W88, super::W88) {}
12685 impl Sealed for (super::W88, super::W96) {}
12686 impl Sealed for (super::W88, super::W104) {}
12687 impl Sealed for (super::W88, super::W112) {}
12688 impl Sealed for (super::W88, super::W120) {}
12689 impl Sealed for (super::W88, super::W128) {}
12690 impl Sealed for (super::W96, super::W96) {}
12691 impl Sealed for (super::W96, super::W104) {}
12692 impl Sealed for (super::W96, super::W112) {}
12693 impl Sealed for (super::W96, super::W120) {}
12694 impl Sealed for (super::W96, super::W128) {}
12695 impl Sealed for (super::W104, super::W104) {}
12696 impl Sealed for (super::W104, super::W112) {}
12697 impl Sealed for (super::W104, super::W120) {}
12698 impl Sealed for (super::W104, super::W128) {}
12699 impl Sealed for (super::W112, super::W112) {}
12700 impl Sealed for (super::W112, super::W120) {}
12701 impl Sealed for (super::W112, super::W128) {}
12702 impl Sealed for (super::W120, super::W120) {}
12703 impl Sealed for (super::W120, super::W128) {}
12704 impl Sealed for (super::W128, super::W128) {}
12705}
12706
12707impl ValidLevelEmbedding for (W8, W8) {}
12708impl ValidLevelEmbedding for (W8, W16) {}
12709impl ValidLevelEmbedding for (W8, W24) {}
12710impl ValidLevelEmbedding for (W8, W32) {}
12711impl ValidLevelEmbedding for (W8, W40) {}
12712impl ValidLevelEmbedding for (W8, W48) {}
12713impl ValidLevelEmbedding for (W8, W56) {}
12714impl ValidLevelEmbedding for (W8, W64) {}
12715impl ValidLevelEmbedding for (W8, W72) {}
12716impl ValidLevelEmbedding for (W8, W80) {}
12717impl ValidLevelEmbedding for (W8, W88) {}
12718impl ValidLevelEmbedding for (W8, W96) {}
12719impl ValidLevelEmbedding for (W8, W104) {}
12720impl ValidLevelEmbedding for (W8, W112) {}
12721impl ValidLevelEmbedding for (W8, W120) {}
12722impl ValidLevelEmbedding for (W8, W128) {}
12723impl ValidLevelEmbedding for (W16, W16) {}
12724impl ValidLevelEmbedding for (W16, W24) {}
12725impl ValidLevelEmbedding for (W16, W32) {}
12726impl ValidLevelEmbedding for (W16, W40) {}
12727impl ValidLevelEmbedding for (W16, W48) {}
12728impl ValidLevelEmbedding for (W16, W56) {}
12729impl ValidLevelEmbedding for (W16, W64) {}
12730impl ValidLevelEmbedding for (W16, W72) {}
12731impl ValidLevelEmbedding for (W16, W80) {}
12732impl ValidLevelEmbedding for (W16, W88) {}
12733impl ValidLevelEmbedding for (W16, W96) {}
12734impl ValidLevelEmbedding for (W16, W104) {}
12735impl ValidLevelEmbedding for (W16, W112) {}
12736impl ValidLevelEmbedding for (W16, W120) {}
12737impl ValidLevelEmbedding for (W16, W128) {}
12738impl ValidLevelEmbedding for (W24, W24) {}
12739impl ValidLevelEmbedding for (W24, W32) {}
12740impl ValidLevelEmbedding for (W24, W40) {}
12741impl ValidLevelEmbedding for (W24, W48) {}
12742impl ValidLevelEmbedding for (W24, W56) {}
12743impl ValidLevelEmbedding for (W24, W64) {}
12744impl ValidLevelEmbedding for (W24, W72) {}
12745impl ValidLevelEmbedding for (W24, W80) {}
12746impl ValidLevelEmbedding for (W24, W88) {}
12747impl ValidLevelEmbedding for (W24, W96) {}
12748impl ValidLevelEmbedding for (W24, W104) {}
12749impl ValidLevelEmbedding for (W24, W112) {}
12750impl ValidLevelEmbedding for (W24, W120) {}
12751impl ValidLevelEmbedding for (W24, W128) {}
12752impl ValidLevelEmbedding for (W32, W32) {}
12753impl ValidLevelEmbedding for (W32, W40) {}
12754impl ValidLevelEmbedding for (W32, W48) {}
12755impl ValidLevelEmbedding for (W32, W56) {}
12756impl ValidLevelEmbedding for (W32, W64) {}
12757impl ValidLevelEmbedding for (W32, W72) {}
12758impl ValidLevelEmbedding for (W32, W80) {}
12759impl ValidLevelEmbedding for (W32, W88) {}
12760impl ValidLevelEmbedding for (W32, W96) {}
12761impl ValidLevelEmbedding for (W32, W104) {}
12762impl ValidLevelEmbedding for (W32, W112) {}
12763impl ValidLevelEmbedding for (W32, W120) {}
12764impl ValidLevelEmbedding for (W32, W128) {}
12765impl ValidLevelEmbedding for (W40, W40) {}
12766impl ValidLevelEmbedding for (W40, W48) {}
12767impl ValidLevelEmbedding for (W40, W56) {}
12768impl ValidLevelEmbedding for (W40, W64) {}
12769impl ValidLevelEmbedding for (W40, W72) {}
12770impl ValidLevelEmbedding for (W40, W80) {}
12771impl ValidLevelEmbedding for (W40, W88) {}
12772impl ValidLevelEmbedding for (W40, W96) {}
12773impl ValidLevelEmbedding for (W40, W104) {}
12774impl ValidLevelEmbedding for (W40, W112) {}
12775impl ValidLevelEmbedding for (W40, W120) {}
12776impl ValidLevelEmbedding for (W40, W128) {}
12777impl ValidLevelEmbedding for (W48, W48) {}
12778impl ValidLevelEmbedding for (W48, W56) {}
12779impl ValidLevelEmbedding for (W48, W64) {}
12780impl ValidLevelEmbedding for (W48, W72) {}
12781impl ValidLevelEmbedding for (W48, W80) {}
12782impl ValidLevelEmbedding for (W48, W88) {}
12783impl ValidLevelEmbedding for (W48, W96) {}
12784impl ValidLevelEmbedding for (W48, W104) {}
12785impl ValidLevelEmbedding for (W48, W112) {}
12786impl ValidLevelEmbedding for (W48, W120) {}
12787impl ValidLevelEmbedding for (W48, W128) {}
12788impl ValidLevelEmbedding for (W56, W56) {}
12789impl ValidLevelEmbedding for (W56, W64) {}
12790impl ValidLevelEmbedding for (W56, W72) {}
12791impl ValidLevelEmbedding for (W56, W80) {}
12792impl ValidLevelEmbedding for (W56, W88) {}
12793impl ValidLevelEmbedding for (W56, W96) {}
12794impl ValidLevelEmbedding for (W56, W104) {}
12795impl ValidLevelEmbedding for (W56, W112) {}
12796impl ValidLevelEmbedding for (W56, W120) {}
12797impl ValidLevelEmbedding for (W56, W128) {}
12798impl ValidLevelEmbedding for (W64, W64) {}
12799impl ValidLevelEmbedding for (W64, W72) {}
12800impl ValidLevelEmbedding for (W64, W80) {}
12801impl ValidLevelEmbedding for (W64, W88) {}
12802impl ValidLevelEmbedding for (W64, W96) {}
12803impl ValidLevelEmbedding for (W64, W104) {}
12804impl ValidLevelEmbedding for (W64, W112) {}
12805impl ValidLevelEmbedding for (W64, W120) {}
12806impl ValidLevelEmbedding for (W64, W128) {}
12807impl ValidLevelEmbedding for (W72, W72) {}
12808impl ValidLevelEmbedding for (W72, W80) {}
12809impl ValidLevelEmbedding for (W72, W88) {}
12810impl ValidLevelEmbedding for (W72, W96) {}
12811impl ValidLevelEmbedding for (W72, W104) {}
12812impl ValidLevelEmbedding for (W72, W112) {}
12813impl ValidLevelEmbedding for (W72, W120) {}
12814impl ValidLevelEmbedding for (W72, W128) {}
12815impl ValidLevelEmbedding for (W80, W80) {}
12816impl ValidLevelEmbedding for (W80, W88) {}
12817impl ValidLevelEmbedding for (W80, W96) {}
12818impl ValidLevelEmbedding for (W80, W104) {}
12819impl ValidLevelEmbedding for (W80, W112) {}
12820impl ValidLevelEmbedding for (W80, W120) {}
12821impl ValidLevelEmbedding for (W80, W128) {}
12822impl ValidLevelEmbedding for (W88, W88) {}
12823impl ValidLevelEmbedding for (W88, W96) {}
12824impl ValidLevelEmbedding for (W88, W104) {}
12825impl ValidLevelEmbedding for (W88, W112) {}
12826impl ValidLevelEmbedding for (W88, W120) {}
12827impl ValidLevelEmbedding for (W88, W128) {}
12828impl ValidLevelEmbedding for (W96, W96) {}
12829impl ValidLevelEmbedding for (W96, W104) {}
12830impl ValidLevelEmbedding for (W96, W112) {}
12831impl ValidLevelEmbedding for (W96, W120) {}
12832impl ValidLevelEmbedding for (W96, W128) {}
12833impl ValidLevelEmbedding for (W104, W104) {}
12834impl ValidLevelEmbedding for (W104, W112) {}
12835impl ValidLevelEmbedding for (W104, W120) {}
12836impl ValidLevelEmbedding for (W104, W128) {}
12837impl ValidLevelEmbedding for (W112, W112) {}
12838impl ValidLevelEmbedding for (W112, W120) {}
12839impl ValidLevelEmbedding for (W112, W128) {}
12840impl ValidLevelEmbedding for (W120, W120) {}
12841impl ValidLevelEmbedding for (W120, W128) {}
12842impl ValidLevelEmbedding for (W128, W128) {}
12843
12844#[derive(Debug, Default, Clone, Copy)]
12850pub struct Embed<From, To>(PhantomData<(From, To)>);
12851
12852impl Embed<W8, W8> {
12853 #[inline]
12855 #[must_use]
12856 pub const fn apply(value: u8) -> u8 {
12857 value
12858 }
12859}
12860
12861impl Embed<W8, W16> {
12862 #[inline]
12864 #[must_use]
12865 pub const fn apply(value: u8) -> u16 {
12866 value as u16
12867 }
12868}
12869
12870impl Embed<W8, W24> {
12871 #[inline]
12873 #[must_use]
12874 pub const fn apply(value: u8) -> u32 {
12875 value as u32
12876 }
12877}
12878
12879impl Embed<W8, W32> {
12880 #[inline]
12882 #[must_use]
12883 pub const fn apply(value: u8) -> u32 {
12884 value as u32
12885 }
12886}
12887
12888impl Embed<W8, W40> {
12889 #[inline]
12891 #[must_use]
12892 pub const fn apply(value: u8) -> u64 {
12893 value as u64
12894 }
12895}
12896
12897impl Embed<W8, W48> {
12898 #[inline]
12900 #[must_use]
12901 pub const fn apply(value: u8) -> u64 {
12902 value as u64
12903 }
12904}
12905
12906impl Embed<W8, W56> {
12907 #[inline]
12909 #[must_use]
12910 pub const fn apply(value: u8) -> u64 {
12911 value as u64
12912 }
12913}
12914
12915impl Embed<W8, W64> {
12916 #[inline]
12918 #[must_use]
12919 pub const fn apply(value: u8) -> u64 {
12920 value as u64
12921 }
12922}
12923
12924impl Embed<W8, W72> {
12925 #[inline]
12927 #[must_use]
12928 pub const fn apply(value: u8) -> u128 {
12929 value as u128
12930 }
12931}
12932
12933impl Embed<W8, W80> {
12934 #[inline]
12936 #[must_use]
12937 pub const fn apply(value: u8) -> u128 {
12938 value as u128
12939 }
12940}
12941
12942impl Embed<W8, W88> {
12943 #[inline]
12945 #[must_use]
12946 pub const fn apply(value: u8) -> u128 {
12947 value as u128
12948 }
12949}
12950
12951impl Embed<W8, W96> {
12952 #[inline]
12954 #[must_use]
12955 pub const fn apply(value: u8) -> u128 {
12956 value as u128
12957 }
12958}
12959
12960impl Embed<W8, W104> {
12961 #[inline]
12963 #[must_use]
12964 pub const fn apply(value: u8) -> u128 {
12965 value as u128
12966 }
12967}
12968
12969impl Embed<W8, W112> {
12970 #[inline]
12972 #[must_use]
12973 pub const fn apply(value: u8) -> u128 {
12974 value as u128
12975 }
12976}
12977
12978impl Embed<W8, W120> {
12979 #[inline]
12981 #[must_use]
12982 pub const fn apply(value: u8) -> u128 {
12983 value as u128
12984 }
12985}
12986
12987impl Embed<W8, W128> {
12988 #[inline]
12990 #[must_use]
12991 pub const fn apply(value: u8) -> u128 {
12992 value as u128
12993 }
12994}
12995
12996impl Embed<W16, W16> {
12997 #[inline]
12999 #[must_use]
13000 pub const fn apply(value: u16) -> u16 {
13001 value
13002 }
13003}
13004
13005impl Embed<W16, W24> {
13006 #[inline]
13008 #[must_use]
13009 pub const fn apply(value: u16) -> u32 {
13010 value as u32
13011 }
13012}
13013
13014impl Embed<W16, W32> {
13015 #[inline]
13017 #[must_use]
13018 pub const fn apply(value: u16) -> u32 {
13019 value as u32
13020 }
13021}
13022
13023impl Embed<W16, W40> {
13024 #[inline]
13026 #[must_use]
13027 pub const fn apply(value: u16) -> u64 {
13028 value as u64
13029 }
13030}
13031
13032impl Embed<W16, W48> {
13033 #[inline]
13035 #[must_use]
13036 pub const fn apply(value: u16) -> u64 {
13037 value as u64
13038 }
13039}
13040
13041impl Embed<W16, W56> {
13042 #[inline]
13044 #[must_use]
13045 pub const fn apply(value: u16) -> u64 {
13046 value as u64
13047 }
13048}
13049
13050impl Embed<W16, W64> {
13051 #[inline]
13053 #[must_use]
13054 pub const fn apply(value: u16) -> u64 {
13055 value as u64
13056 }
13057}
13058
13059impl Embed<W16, W72> {
13060 #[inline]
13062 #[must_use]
13063 pub const fn apply(value: u16) -> u128 {
13064 value as u128
13065 }
13066}
13067
13068impl Embed<W16, W80> {
13069 #[inline]
13071 #[must_use]
13072 pub const fn apply(value: u16) -> u128 {
13073 value as u128
13074 }
13075}
13076
13077impl Embed<W16, W88> {
13078 #[inline]
13080 #[must_use]
13081 pub const fn apply(value: u16) -> u128 {
13082 value as u128
13083 }
13084}
13085
13086impl Embed<W16, W96> {
13087 #[inline]
13089 #[must_use]
13090 pub const fn apply(value: u16) -> u128 {
13091 value as u128
13092 }
13093}
13094
13095impl Embed<W16, W104> {
13096 #[inline]
13098 #[must_use]
13099 pub const fn apply(value: u16) -> u128 {
13100 value as u128
13101 }
13102}
13103
13104impl Embed<W16, W112> {
13105 #[inline]
13107 #[must_use]
13108 pub const fn apply(value: u16) -> u128 {
13109 value as u128
13110 }
13111}
13112
13113impl Embed<W16, W120> {
13114 #[inline]
13116 #[must_use]
13117 pub const fn apply(value: u16) -> u128 {
13118 value as u128
13119 }
13120}
13121
13122impl Embed<W16, W128> {
13123 #[inline]
13125 #[must_use]
13126 pub const fn apply(value: u16) -> u128 {
13127 value as u128
13128 }
13129}
13130
13131impl Embed<W24, W24> {
13132 #[inline]
13134 #[must_use]
13135 pub const fn apply(value: u32) -> u32 {
13136 value
13137 }
13138}
13139
13140impl Embed<W24, W32> {
13141 #[inline]
13143 #[must_use]
13144 pub const fn apply(value: u32) -> u32 {
13145 value
13146 }
13147}
13148
13149impl Embed<W24, W40> {
13150 #[inline]
13152 #[must_use]
13153 pub const fn apply(value: u32) -> u64 {
13154 value as u64
13155 }
13156}
13157
13158impl Embed<W24, W48> {
13159 #[inline]
13161 #[must_use]
13162 pub const fn apply(value: u32) -> u64 {
13163 value as u64
13164 }
13165}
13166
13167impl Embed<W24, W56> {
13168 #[inline]
13170 #[must_use]
13171 pub const fn apply(value: u32) -> u64 {
13172 value as u64
13173 }
13174}
13175
13176impl Embed<W24, W64> {
13177 #[inline]
13179 #[must_use]
13180 pub const fn apply(value: u32) -> u64 {
13181 value as u64
13182 }
13183}
13184
13185impl Embed<W24, W72> {
13186 #[inline]
13188 #[must_use]
13189 pub const fn apply(value: u32) -> u128 {
13190 value as u128
13191 }
13192}
13193
13194impl Embed<W24, W80> {
13195 #[inline]
13197 #[must_use]
13198 pub const fn apply(value: u32) -> u128 {
13199 value as u128
13200 }
13201}
13202
13203impl Embed<W24, W88> {
13204 #[inline]
13206 #[must_use]
13207 pub const fn apply(value: u32) -> u128 {
13208 value as u128
13209 }
13210}
13211
13212impl Embed<W24, W96> {
13213 #[inline]
13215 #[must_use]
13216 pub const fn apply(value: u32) -> u128 {
13217 value as u128
13218 }
13219}
13220
13221impl Embed<W24, W104> {
13222 #[inline]
13224 #[must_use]
13225 pub const fn apply(value: u32) -> u128 {
13226 value as u128
13227 }
13228}
13229
13230impl Embed<W24, W112> {
13231 #[inline]
13233 #[must_use]
13234 pub const fn apply(value: u32) -> u128 {
13235 value as u128
13236 }
13237}
13238
13239impl Embed<W24, W120> {
13240 #[inline]
13242 #[must_use]
13243 pub const fn apply(value: u32) -> u128 {
13244 value as u128
13245 }
13246}
13247
13248impl Embed<W24, W128> {
13249 #[inline]
13251 #[must_use]
13252 pub const fn apply(value: u32) -> u128 {
13253 value as u128
13254 }
13255}
13256
13257impl Embed<W32, W32> {
13258 #[inline]
13260 #[must_use]
13261 pub const fn apply(value: u32) -> u32 {
13262 value
13263 }
13264}
13265
13266impl Embed<W32, W40> {
13267 #[inline]
13269 #[must_use]
13270 pub const fn apply(value: u32) -> u64 {
13271 value as u64
13272 }
13273}
13274
13275impl Embed<W32, W48> {
13276 #[inline]
13278 #[must_use]
13279 pub const fn apply(value: u32) -> u64 {
13280 value as u64
13281 }
13282}
13283
13284impl Embed<W32, W56> {
13285 #[inline]
13287 #[must_use]
13288 pub const fn apply(value: u32) -> u64 {
13289 value as u64
13290 }
13291}
13292
13293impl Embed<W32, W64> {
13294 #[inline]
13296 #[must_use]
13297 pub const fn apply(value: u32) -> u64 {
13298 value as u64
13299 }
13300}
13301
13302impl Embed<W32, W72> {
13303 #[inline]
13305 #[must_use]
13306 pub const fn apply(value: u32) -> u128 {
13307 value as u128
13308 }
13309}
13310
13311impl Embed<W32, W80> {
13312 #[inline]
13314 #[must_use]
13315 pub const fn apply(value: u32) -> u128 {
13316 value as u128
13317 }
13318}
13319
13320impl Embed<W32, W88> {
13321 #[inline]
13323 #[must_use]
13324 pub const fn apply(value: u32) -> u128 {
13325 value as u128
13326 }
13327}
13328
13329impl Embed<W32, W96> {
13330 #[inline]
13332 #[must_use]
13333 pub const fn apply(value: u32) -> u128 {
13334 value as u128
13335 }
13336}
13337
13338impl Embed<W32, W104> {
13339 #[inline]
13341 #[must_use]
13342 pub const fn apply(value: u32) -> u128 {
13343 value as u128
13344 }
13345}
13346
13347impl Embed<W32, W112> {
13348 #[inline]
13350 #[must_use]
13351 pub const fn apply(value: u32) -> u128 {
13352 value as u128
13353 }
13354}
13355
13356impl Embed<W32, W120> {
13357 #[inline]
13359 #[must_use]
13360 pub const fn apply(value: u32) -> u128 {
13361 value as u128
13362 }
13363}
13364
13365impl Embed<W32, W128> {
13366 #[inline]
13368 #[must_use]
13369 pub const fn apply(value: u32) -> u128 {
13370 value as u128
13371 }
13372}
13373
13374impl Embed<W40, W40> {
13375 #[inline]
13377 #[must_use]
13378 pub const fn apply(value: u64) -> u64 {
13379 value
13380 }
13381}
13382
13383impl Embed<W40, W48> {
13384 #[inline]
13386 #[must_use]
13387 pub const fn apply(value: u64) -> u64 {
13388 value
13389 }
13390}
13391
13392impl Embed<W40, W56> {
13393 #[inline]
13395 #[must_use]
13396 pub const fn apply(value: u64) -> u64 {
13397 value
13398 }
13399}
13400
13401impl Embed<W40, W64> {
13402 #[inline]
13404 #[must_use]
13405 pub const fn apply(value: u64) -> u64 {
13406 value
13407 }
13408}
13409
13410impl Embed<W40, W72> {
13411 #[inline]
13413 #[must_use]
13414 pub const fn apply(value: u64) -> u128 {
13415 value as u128
13416 }
13417}
13418
13419impl Embed<W40, W80> {
13420 #[inline]
13422 #[must_use]
13423 pub const fn apply(value: u64) -> u128 {
13424 value as u128
13425 }
13426}
13427
13428impl Embed<W40, W88> {
13429 #[inline]
13431 #[must_use]
13432 pub const fn apply(value: u64) -> u128 {
13433 value as u128
13434 }
13435}
13436
13437impl Embed<W40, W96> {
13438 #[inline]
13440 #[must_use]
13441 pub const fn apply(value: u64) -> u128 {
13442 value as u128
13443 }
13444}
13445
13446impl Embed<W40, W104> {
13447 #[inline]
13449 #[must_use]
13450 pub const fn apply(value: u64) -> u128 {
13451 value as u128
13452 }
13453}
13454
13455impl Embed<W40, W112> {
13456 #[inline]
13458 #[must_use]
13459 pub const fn apply(value: u64) -> u128 {
13460 value as u128
13461 }
13462}
13463
13464impl Embed<W40, W120> {
13465 #[inline]
13467 #[must_use]
13468 pub const fn apply(value: u64) -> u128 {
13469 value as u128
13470 }
13471}
13472
13473impl Embed<W40, W128> {
13474 #[inline]
13476 #[must_use]
13477 pub const fn apply(value: u64) -> u128 {
13478 value as u128
13479 }
13480}
13481
13482impl Embed<W48, W48> {
13483 #[inline]
13485 #[must_use]
13486 pub const fn apply(value: u64) -> u64 {
13487 value
13488 }
13489}
13490
13491impl Embed<W48, W56> {
13492 #[inline]
13494 #[must_use]
13495 pub const fn apply(value: u64) -> u64 {
13496 value
13497 }
13498}
13499
13500impl Embed<W48, W64> {
13501 #[inline]
13503 #[must_use]
13504 pub const fn apply(value: u64) -> u64 {
13505 value
13506 }
13507}
13508
13509impl Embed<W48, W72> {
13510 #[inline]
13512 #[must_use]
13513 pub const fn apply(value: u64) -> u128 {
13514 value as u128
13515 }
13516}
13517
13518impl Embed<W48, W80> {
13519 #[inline]
13521 #[must_use]
13522 pub const fn apply(value: u64) -> u128 {
13523 value as u128
13524 }
13525}
13526
13527impl Embed<W48, W88> {
13528 #[inline]
13530 #[must_use]
13531 pub const fn apply(value: u64) -> u128 {
13532 value as u128
13533 }
13534}
13535
13536impl Embed<W48, W96> {
13537 #[inline]
13539 #[must_use]
13540 pub const fn apply(value: u64) -> u128 {
13541 value as u128
13542 }
13543}
13544
13545impl Embed<W48, W104> {
13546 #[inline]
13548 #[must_use]
13549 pub const fn apply(value: u64) -> u128 {
13550 value as u128
13551 }
13552}
13553
13554impl Embed<W48, W112> {
13555 #[inline]
13557 #[must_use]
13558 pub const fn apply(value: u64) -> u128 {
13559 value as u128
13560 }
13561}
13562
13563impl Embed<W48, W120> {
13564 #[inline]
13566 #[must_use]
13567 pub const fn apply(value: u64) -> u128 {
13568 value as u128
13569 }
13570}
13571
13572impl Embed<W48, W128> {
13573 #[inline]
13575 #[must_use]
13576 pub const fn apply(value: u64) -> u128 {
13577 value as u128
13578 }
13579}
13580
13581impl Embed<W56, W56> {
13582 #[inline]
13584 #[must_use]
13585 pub const fn apply(value: u64) -> u64 {
13586 value
13587 }
13588}
13589
13590impl Embed<W56, W64> {
13591 #[inline]
13593 #[must_use]
13594 pub const fn apply(value: u64) -> u64 {
13595 value
13596 }
13597}
13598
13599impl Embed<W56, W72> {
13600 #[inline]
13602 #[must_use]
13603 pub const fn apply(value: u64) -> u128 {
13604 value as u128
13605 }
13606}
13607
13608impl Embed<W56, W80> {
13609 #[inline]
13611 #[must_use]
13612 pub const fn apply(value: u64) -> u128 {
13613 value as u128
13614 }
13615}
13616
13617impl Embed<W56, W88> {
13618 #[inline]
13620 #[must_use]
13621 pub const fn apply(value: u64) -> u128 {
13622 value as u128
13623 }
13624}
13625
13626impl Embed<W56, W96> {
13627 #[inline]
13629 #[must_use]
13630 pub const fn apply(value: u64) -> u128 {
13631 value as u128
13632 }
13633}
13634
13635impl Embed<W56, W104> {
13636 #[inline]
13638 #[must_use]
13639 pub const fn apply(value: u64) -> u128 {
13640 value as u128
13641 }
13642}
13643
13644impl Embed<W56, W112> {
13645 #[inline]
13647 #[must_use]
13648 pub const fn apply(value: u64) -> u128 {
13649 value as u128
13650 }
13651}
13652
13653impl Embed<W56, W120> {
13654 #[inline]
13656 #[must_use]
13657 pub const fn apply(value: u64) -> u128 {
13658 value as u128
13659 }
13660}
13661
13662impl Embed<W56, W128> {
13663 #[inline]
13665 #[must_use]
13666 pub const fn apply(value: u64) -> u128 {
13667 value as u128
13668 }
13669}
13670
13671impl Embed<W64, W64> {
13672 #[inline]
13674 #[must_use]
13675 pub const fn apply(value: u64) -> u64 {
13676 value
13677 }
13678}
13679
13680impl Embed<W64, W72> {
13681 #[inline]
13683 #[must_use]
13684 pub const fn apply(value: u64) -> u128 {
13685 value as u128
13686 }
13687}
13688
13689impl Embed<W64, W80> {
13690 #[inline]
13692 #[must_use]
13693 pub const fn apply(value: u64) -> u128 {
13694 value as u128
13695 }
13696}
13697
13698impl Embed<W64, W88> {
13699 #[inline]
13701 #[must_use]
13702 pub const fn apply(value: u64) -> u128 {
13703 value as u128
13704 }
13705}
13706
13707impl Embed<W64, W96> {
13708 #[inline]
13710 #[must_use]
13711 pub const fn apply(value: u64) -> u128 {
13712 value as u128
13713 }
13714}
13715
13716impl Embed<W64, W104> {
13717 #[inline]
13719 #[must_use]
13720 pub const fn apply(value: u64) -> u128 {
13721 value as u128
13722 }
13723}
13724
13725impl Embed<W64, W112> {
13726 #[inline]
13728 #[must_use]
13729 pub const fn apply(value: u64) -> u128 {
13730 value as u128
13731 }
13732}
13733
13734impl Embed<W64, W120> {
13735 #[inline]
13737 #[must_use]
13738 pub const fn apply(value: u64) -> u128 {
13739 value as u128
13740 }
13741}
13742
13743impl Embed<W64, W128> {
13744 #[inline]
13746 #[must_use]
13747 pub const fn apply(value: u64) -> u128 {
13748 value as u128
13749 }
13750}
13751
13752impl Embed<W72, W72> {
13753 #[inline]
13755 #[must_use]
13756 pub const fn apply(value: u128) -> u128 {
13757 value
13758 }
13759}
13760
13761impl Embed<W72, W80> {
13762 #[inline]
13764 #[must_use]
13765 pub const fn apply(value: u128) -> u128 {
13766 value
13767 }
13768}
13769
13770impl Embed<W72, W88> {
13771 #[inline]
13773 #[must_use]
13774 pub const fn apply(value: u128) -> u128 {
13775 value
13776 }
13777}
13778
13779impl Embed<W72, W96> {
13780 #[inline]
13782 #[must_use]
13783 pub const fn apply(value: u128) -> u128 {
13784 value
13785 }
13786}
13787
13788impl Embed<W72, W104> {
13789 #[inline]
13791 #[must_use]
13792 pub const fn apply(value: u128) -> u128 {
13793 value
13794 }
13795}
13796
13797impl Embed<W72, W112> {
13798 #[inline]
13800 #[must_use]
13801 pub const fn apply(value: u128) -> u128 {
13802 value
13803 }
13804}
13805
13806impl Embed<W72, W120> {
13807 #[inline]
13809 #[must_use]
13810 pub const fn apply(value: u128) -> u128 {
13811 value
13812 }
13813}
13814
13815impl Embed<W72, W128> {
13816 #[inline]
13818 #[must_use]
13819 pub const fn apply(value: u128) -> u128 {
13820 value
13821 }
13822}
13823
13824impl Embed<W80, W80> {
13825 #[inline]
13827 #[must_use]
13828 pub const fn apply(value: u128) -> u128 {
13829 value
13830 }
13831}
13832
13833impl Embed<W80, W88> {
13834 #[inline]
13836 #[must_use]
13837 pub const fn apply(value: u128) -> u128 {
13838 value
13839 }
13840}
13841
13842impl Embed<W80, W96> {
13843 #[inline]
13845 #[must_use]
13846 pub const fn apply(value: u128) -> u128 {
13847 value
13848 }
13849}
13850
13851impl Embed<W80, W104> {
13852 #[inline]
13854 #[must_use]
13855 pub const fn apply(value: u128) -> u128 {
13856 value
13857 }
13858}
13859
13860impl Embed<W80, W112> {
13861 #[inline]
13863 #[must_use]
13864 pub const fn apply(value: u128) -> u128 {
13865 value
13866 }
13867}
13868
13869impl Embed<W80, W120> {
13870 #[inline]
13872 #[must_use]
13873 pub const fn apply(value: u128) -> u128 {
13874 value
13875 }
13876}
13877
13878impl Embed<W80, W128> {
13879 #[inline]
13881 #[must_use]
13882 pub const fn apply(value: u128) -> u128 {
13883 value
13884 }
13885}
13886
13887impl Embed<W88, W88> {
13888 #[inline]
13890 #[must_use]
13891 pub const fn apply(value: u128) -> u128 {
13892 value
13893 }
13894}
13895
13896impl Embed<W88, W96> {
13897 #[inline]
13899 #[must_use]
13900 pub const fn apply(value: u128) -> u128 {
13901 value
13902 }
13903}
13904
13905impl Embed<W88, W104> {
13906 #[inline]
13908 #[must_use]
13909 pub const fn apply(value: u128) -> u128 {
13910 value
13911 }
13912}
13913
13914impl Embed<W88, W112> {
13915 #[inline]
13917 #[must_use]
13918 pub const fn apply(value: u128) -> u128 {
13919 value
13920 }
13921}
13922
13923impl Embed<W88, W120> {
13924 #[inline]
13926 #[must_use]
13927 pub const fn apply(value: u128) -> u128 {
13928 value
13929 }
13930}
13931
13932impl Embed<W88, W128> {
13933 #[inline]
13935 #[must_use]
13936 pub const fn apply(value: u128) -> u128 {
13937 value
13938 }
13939}
13940
13941impl Embed<W96, W96> {
13942 #[inline]
13944 #[must_use]
13945 pub const fn apply(value: u128) -> u128 {
13946 value
13947 }
13948}
13949
13950impl Embed<W96, W104> {
13951 #[inline]
13953 #[must_use]
13954 pub const fn apply(value: u128) -> u128 {
13955 value
13956 }
13957}
13958
13959impl Embed<W96, W112> {
13960 #[inline]
13962 #[must_use]
13963 pub const fn apply(value: u128) -> u128 {
13964 value
13965 }
13966}
13967
13968impl Embed<W96, W120> {
13969 #[inline]
13971 #[must_use]
13972 pub const fn apply(value: u128) -> u128 {
13973 value
13974 }
13975}
13976
13977impl Embed<W96, W128> {
13978 #[inline]
13980 #[must_use]
13981 pub const fn apply(value: u128) -> u128 {
13982 value
13983 }
13984}
13985
13986impl Embed<W104, W104> {
13987 #[inline]
13989 #[must_use]
13990 pub const fn apply(value: u128) -> u128 {
13991 value
13992 }
13993}
13994
13995impl Embed<W104, W112> {
13996 #[inline]
13998 #[must_use]
13999 pub const fn apply(value: u128) -> u128 {
14000 value
14001 }
14002}
14003
14004impl Embed<W104, W120> {
14005 #[inline]
14007 #[must_use]
14008 pub const fn apply(value: u128) -> u128 {
14009 value
14010 }
14011}
14012
14013impl Embed<W104, W128> {
14014 #[inline]
14016 #[must_use]
14017 pub const fn apply(value: u128) -> u128 {
14018 value
14019 }
14020}
14021
14022impl Embed<W112, W112> {
14023 #[inline]
14025 #[must_use]
14026 pub const fn apply(value: u128) -> u128 {
14027 value
14028 }
14029}
14030
14031impl Embed<W112, W120> {
14032 #[inline]
14034 #[must_use]
14035 pub const fn apply(value: u128) -> u128 {
14036 value
14037 }
14038}
14039
14040impl Embed<W112, W128> {
14041 #[inline]
14043 #[must_use]
14044 pub const fn apply(value: u128) -> u128 {
14045 value
14046 }
14047}
14048
14049impl Embed<W120, W120> {
14050 #[inline]
14052 #[must_use]
14053 pub const fn apply(value: u128) -> u128 {
14054 value
14055 }
14056}
14057
14058impl Embed<W120, W128> {
14059 #[inline]
14061 #[must_use]
14062 pub const fn apply(value: u128) -> u128 {
14063 value
14064 }
14065}
14066
14067impl Embed<W128, W128> {
14068 #[inline]
14070 #[must_use]
14071 pub const fn apply(value: u128) -> u128 {
14072 value
14073 }
14074}
14075
14076#[derive(Debug, Default, Clone, Copy)]
14080pub struct W160;
14081
14082#[derive(Debug, Default, Clone, Copy)]
14084pub struct W192;
14085
14086#[derive(Debug, Default, Clone, Copy)]
14088pub struct W224;
14089
14090#[derive(Debug, Default, Clone, Copy)]
14092pub struct W256;
14093
14094#[derive(Debug, Default, Clone, Copy)]
14096pub struct W384;
14097
14098#[derive(Debug, Default, Clone, Copy)]
14100pub struct W448;
14101
14102#[derive(Debug, Default, Clone, Copy)]
14104pub struct W512;
14105
14106#[derive(Debug, Default, Clone, Copy)]
14108pub struct W520;
14109
14110#[derive(Debug, Default, Clone, Copy)]
14112pub struct W528;
14113
14114#[derive(Debug, Default, Clone, Copy)]
14116pub struct W1024;
14117
14118#[derive(Debug, Default, Clone, Copy)]
14120pub struct W2048;
14121
14122#[derive(Debug, Default, Clone, Copy)]
14124pub struct W4096;
14125
14126#[derive(Debug, Default, Clone, Copy)]
14128pub struct W8192;
14129
14130#[derive(Debug, Default, Clone, Copy)]
14132pub struct W12288;
14133
14134#[derive(Debug, Default, Clone, Copy)]
14136pub struct W16384;
14137
14138#[derive(Debug, Default, Clone, Copy)]
14140pub struct W32768;
14141
14142impl RingOp<W160> for Mul<W160> {
14143 type Operand = Limbs<3>;
14144 #[inline]
14145 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14146 a.wrapping_mul(b).mask_high_bits(160)
14147 }
14148}
14149
14150impl RingOp<W160> for Add<W160> {
14151 type Operand = Limbs<3>;
14152 #[inline]
14153 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14154 a.wrapping_add(b).mask_high_bits(160)
14155 }
14156}
14157
14158impl RingOp<W160> for Sub<W160> {
14159 type Operand = Limbs<3>;
14160 #[inline]
14161 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14162 a.wrapping_sub(b).mask_high_bits(160)
14163 }
14164}
14165
14166impl RingOp<W160> for Xor<W160> {
14167 type Operand = Limbs<3>;
14168 #[inline]
14169 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14170 a.xor(b).mask_high_bits(160)
14171 }
14172}
14173
14174impl RingOp<W160> for And<W160> {
14175 type Operand = Limbs<3>;
14176 #[inline]
14177 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14178 a.and(b).mask_high_bits(160)
14179 }
14180}
14181
14182impl RingOp<W160> for Or<W160> {
14183 type Operand = Limbs<3>;
14184 #[inline]
14185 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14186 a.or(b).mask_high_bits(160)
14187 }
14188}
14189
14190impl UnaryRingOp<W160> for Neg<W160> {
14191 type Operand = Limbs<3>;
14192 #[inline]
14193 fn apply(a: Limbs<3>) -> Limbs<3> {
14194 (Limbs::<3>::zero().wrapping_sub(a)).mask_high_bits(160)
14195 }
14196}
14197
14198impl UnaryRingOp<W160> for BNot<W160> {
14199 type Operand = Limbs<3>;
14200 #[inline]
14201 fn apply(a: Limbs<3>) -> Limbs<3> {
14202 (a.not()).mask_high_bits(160)
14203 }
14204}
14205
14206impl UnaryRingOp<W160> for Succ<W160> {
14207 type Operand = Limbs<3>;
14208 #[inline]
14209 fn apply(a: Limbs<3>) -> Limbs<3> {
14210 (a.wrapping_add(Limbs::<3>::from_words([1u64, 0u64, 0u64]))).mask_high_bits(160)
14211 }
14212}
14213
14214impl RingOp<W192> for Mul<W192> {
14215 type Operand = Limbs<3>;
14216 #[inline]
14217 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14218 a.wrapping_mul(b)
14219 }
14220}
14221
14222impl RingOp<W192> for Add<W192> {
14223 type Operand = Limbs<3>;
14224 #[inline]
14225 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14226 a.wrapping_add(b)
14227 }
14228}
14229
14230impl RingOp<W192> for Sub<W192> {
14231 type Operand = Limbs<3>;
14232 #[inline]
14233 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14234 a.wrapping_sub(b)
14235 }
14236}
14237
14238impl RingOp<W192> for Xor<W192> {
14239 type Operand = Limbs<3>;
14240 #[inline]
14241 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14242 a.xor(b)
14243 }
14244}
14245
14246impl RingOp<W192> for And<W192> {
14247 type Operand = Limbs<3>;
14248 #[inline]
14249 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14250 a.and(b)
14251 }
14252}
14253
14254impl RingOp<W192> for Or<W192> {
14255 type Operand = Limbs<3>;
14256 #[inline]
14257 fn apply(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
14258 a.or(b)
14259 }
14260}
14261
14262impl UnaryRingOp<W192> for Neg<W192> {
14263 type Operand = Limbs<3>;
14264 #[inline]
14265 fn apply(a: Limbs<3>) -> Limbs<3> {
14266 Limbs::<3>::zero().wrapping_sub(a)
14267 }
14268}
14269
14270impl UnaryRingOp<W192> for BNot<W192> {
14271 type Operand = Limbs<3>;
14272 #[inline]
14273 fn apply(a: Limbs<3>) -> Limbs<3> {
14274 a.not()
14275 }
14276}
14277
14278impl UnaryRingOp<W192> for Succ<W192> {
14279 type Operand = Limbs<3>;
14280 #[inline]
14281 fn apply(a: Limbs<3>) -> Limbs<3> {
14282 a.wrapping_add(Limbs::<3>::from_words([1u64, 0u64, 0u64]))
14283 }
14284}
14285
14286impl RingOp<W224> for Mul<W224> {
14287 type Operand = Limbs<4>;
14288 #[inline]
14289 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14290 a.wrapping_mul(b).mask_high_bits(224)
14291 }
14292}
14293
14294impl RingOp<W224> for Add<W224> {
14295 type Operand = Limbs<4>;
14296 #[inline]
14297 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14298 a.wrapping_add(b).mask_high_bits(224)
14299 }
14300}
14301
14302impl RingOp<W224> for Sub<W224> {
14303 type Operand = Limbs<4>;
14304 #[inline]
14305 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14306 a.wrapping_sub(b).mask_high_bits(224)
14307 }
14308}
14309
14310impl RingOp<W224> for Xor<W224> {
14311 type Operand = Limbs<4>;
14312 #[inline]
14313 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14314 a.xor(b).mask_high_bits(224)
14315 }
14316}
14317
14318impl RingOp<W224> for And<W224> {
14319 type Operand = Limbs<4>;
14320 #[inline]
14321 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14322 a.and(b).mask_high_bits(224)
14323 }
14324}
14325
14326impl RingOp<W224> for Or<W224> {
14327 type Operand = Limbs<4>;
14328 #[inline]
14329 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14330 a.or(b).mask_high_bits(224)
14331 }
14332}
14333
14334impl UnaryRingOp<W224> for Neg<W224> {
14335 type Operand = Limbs<4>;
14336 #[inline]
14337 fn apply(a: Limbs<4>) -> Limbs<4> {
14338 (Limbs::<4>::zero().wrapping_sub(a)).mask_high_bits(224)
14339 }
14340}
14341
14342impl UnaryRingOp<W224> for BNot<W224> {
14343 type Operand = Limbs<4>;
14344 #[inline]
14345 fn apply(a: Limbs<4>) -> Limbs<4> {
14346 (a.not()).mask_high_bits(224)
14347 }
14348}
14349
14350impl UnaryRingOp<W224> for Succ<W224> {
14351 type Operand = Limbs<4>;
14352 #[inline]
14353 fn apply(a: Limbs<4>) -> Limbs<4> {
14354 (a.wrapping_add(Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64]))).mask_high_bits(224)
14355 }
14356}
14357
14358impl RingOp<W256> for Mul<W256> {
14359 type Operand = Limbs<4>;
14360 #[inline]
14361 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14362 a.wrapping_mul(b)
14363 }
14364}
14365
14366impl RingOp<W256> for Add<W256> {
14367 type Operand = Limbs<4>;
14368 #[inline]
14369 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14370 a.wrapping_add(b)
14371 }
14372}
14373
14374impl RingOp<W256> for Sub<W256> {
14375 type Operand = Limbs<4>;
14376 #[inline]
14377 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14378 a.wrapping_sub(b)
14379 }
14380}
14381
14382impl RingOp<W256> for Xor<W256> {
14383 type Operand = Limbs<4>;
14384 #[inline]
14385 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14386 a.xor(b)
14387 }
14388}
14389
14390impl RingOp<W256> for And<W256> {
14391 type Operand = Limbs<4>;
14392 #[inline]
14393 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14394 a.and(b)
14395 }
14396}
14397
14398impl RingOp<W256> for Or<W256> {
14399 type Operand = Limbs<4>;
14400 #[inline]
14401 fn apply(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
14402 a.or(b)
14403 }
14404}
14405
14406impl UnaryRingOp<W256> for Neg<W256> {
14407 type Operand = Limbs<4>;
14408 #[inline]
14409 fn apply(a: Limbs<4>) -> Limbs<4> {
14410 Limbs::<4>::zero().wrapping_sub(a)
14411 }
14412}
14413
14414impl UnaryRingOp<W256> for BNot<W256> {
14415 type Operand = Limbs<4>;
14416 #[inline]
14417 fn apply(a: Limbs<4>) -> Limbs<4> {
14418 a.not()
14419 }
14420}
14421
14422impl UnaryRingOp<W256> for Succ<W256> {
14423 type Operand = Limbs<4>;
14424 #[inline]
14425 fn apply(a: Limbs<4>) -> Limbs<4> {
14426 a.wrapping_add(Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64]))
14427 }
14428}
14429
14430impl RingOp<W384> for Mul<W384> {
14431 type Operand = Limbs<6>;
14432 #[inline]
14433 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14434 a.wrapping_mul(b)
14435 }
14436}
14437
14438impl RingOp<W384> for Add<W384> {
14439 type Operand = Limbs<6>;
14440 #[inline]
14441 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14442 a.wrapping_add(b)
14443 }
14444}
14445
14446impl RingOp<W384> for Sub<W384> {
14447 type Operand = Limbs<6>;
14448 #[inline]
14449 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14450 a.wrapping_sub(b)
14451 }
14452}
14453
14454impl RingOp<W384> for Xor<W384> {
14455 type Operand = Limbs<6>;
14456 #[inline]
14457 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14458 a.xor(b)
14459 }
14460}
14461
14462impl RingOp<W384> for And<W384> {
14463 type Operand = Limbs<6>;
14464 #[inline]
14465 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14466 a.and(b)
14467 }
14468}
14469
14470impl RingOp<W384> for Or<W384> {
14471 type Operand = Limbs<6>;
14472 #[inline]
14473 fn apply(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
14474 a.or(b)
14475 }
14476}
14477
14478impl UnaryRingOp<W384> for Neg<W384> {
14479 type Operand = Limbs<6>;
14480 #[inline]
14481 fn apply(a: Limbs<6>) -> Limbs<6> {
14482 Limbs::<6>::zero().wrapping_sub(a)
14483 }
14484}
14485
14486impl UnaryRingOp<W384> for BNot<W384> {
14487 type Operand = Limbs<6>;
14488 #[inline]
14489 fn apply(a: Limbs<6>) -> Limbs<6> {
14490 a.not()
14491 }
14492}
14493
14494impl UnaryRingOp<W384> for Succ<W384> {
14495 type Operand = Limbs<6>;
14496 #[inline]
14497 fn apply(a: Limbs<6>) -> Limbs<6> {
14498 a.wrapping_add(Limbs::<6>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64]))
14499 }
14500}
14501
14502impl RingOp<W448> for Mul<W448> {
14503 type Operand = Limbs<7>;
14504 #[inline]
14505 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14506 a.wrapping_mul(b)
14507 }
14508}
14509
14510impl RingOp<W448> for Add<W448> {
14511 type Operand = Limbs<7>;
14512 #[inline]
14513 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14514 a.wrapping_add(b)
14515 }
14516}
14517
14518impl RingOp<W448> for Sub<W448> {
14519 type Operand = Limbs<7>;
14520 #[inline]
14521 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14522 a.wrapping_sub(b)
14523 }
14524}
14525
14526impl RingOp<W448> for Xor<W448> {
14527 type Operand = Limbs<7>;
14528 #[inline]
14529 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14530 a.xor(b)
14531 }
14532}
14533
14534impl RingOp<W448> for And<W448> {
14535 type Operand = Limbs<7>;
14536 #[inline]
14537 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14538 a.and(b)
14539 }
14540}
14541
14542impl RingOp<W448> for Or<W448> {
14543 type Operand = Limbs<7>;
14544 #[inline]
14545 fn apply(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
14546 a.or(b)
14547 }
14548}
14549
14550impl UnaryRingOp<W448> for Neg<W448> {
14551 type Operand = Limbs<7>;
14552 #[inline]
14553 fn apply(a: Limbs<7>) -> Limbs<7> {
14554 Limbs::<7>::zero().wrapping_sub(a)
14555 }
14556}
14557
14558impl UnaryRingOp<W448> for BNot<W448> {
14559 type Operand = Limbs<7>;
14560 #[inline]
14561 fn apply(a: Limbs<7>) -> Limbs<7> {
14562 a.not()
14563 }
14564}
14565
14566impl UnaryRingOp<W448> for Succ<W448> {
14567 type Operand = Limbs<7>;
14568 #[inline]
14569 fn apply(a: Limbs<7>) -> Limbs<7> {
14570 a.wrapping_add(Limbs::<7>::from_words([
14571 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14572 ]))
14573 }
14574}
14575
14576impl RingOp<W512> for Mul<W512> {
14577 type Operand = Limbs<8>;
14578 #[inline]
14579 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14580 a.wrapping_mul(b)
14581 }
14582}
14583
14584impl RingOp<W512> for Add<W512> {
14585 type Operand = Limbs<8>;
14586 #[inline]
14587 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14588 a.wrapping_add(b)
14589 }
14590}
14591
14592impl RingOp<W512> for Sub<W512> {
14593 type Operand = Limbs<8>;
14594 #[inline]
14595 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14596 a.wrapping_sub(b)
14597 }
14598}
14599
14600impl RingOp<W512> for Xor<W512> {
14601 type Operand = Limbs<8>;
14602 #[inline]
14603 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14604 a.xor(b)
14605 }
14606}
14607
14608impl RingOp<W512> for And<W512> {
14609 type Operand = Limbs<8>;
14610 #[inline]
14611 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14612 a.and(b)
14613 }
14614}
14615
14616impl RingOp<W512> for Or<W512> {
14617 type Operand = Limbs<8>;
14618 #[inline]
14619 fn apply(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
14620 a.or(b)
14621 }
14622}
14623
14624impl UnaryRingOp<W512> for Neg<W512> {
14625 type Operand = Limbs<8>;
14626 #[inline]
14627 fn apply(a: Limbs<8>) -> Limbs<8> {
14628 Limbs::<8>::zero().wrapping_sub(a)
14629 }
14630}
14631
14632impl UnaryRingOp<W512> for BNot<W512> {
14633 type Operand = Limbs<8>;
14634 #[inline]
14635 fn apply(a: Limbs<8>) -> Limbs<8> {
14636 a.not()
14637 }
14638}
14639
14640impl UnaryRingOp<W512> for Succ<W512> {
14641 type Operand = Limbs<8>;
14642 #[inline]
14643 fn apply(a: Limbs<8>) -> Limbs<8> {
14644 a.wrapping_add(Limbs::<8>::from_words([
14645 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14646 ]))
14647 }
14648}
14649
14650impl RingOp<W520> for Mul<W520> {
14651 type Operand = Limbs<9>;
14652 #[inline]
14653 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14654 a.wrapping_mul(b).mask_high_bits(520)
14655 }
14656}
14657
14658impl RingOp<W520> for Add<W520> {
14659 type Operand = Limbs<9>;
14660 #[inline]
14661 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14662 a.wrapping_add(b).mask_high_bits(520)
14663 }
14664}
14665
14666impl RingOp<W520> for Sub<W520> {
14667 type Operand = Limbs<9>;
14668 #[inline]
14669 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14670 a.wrapping_sub(b).mask_high_bits(520)
14671 }
14672}
14673
14674impl RingOp<W520> for Xor<W520> {
14675 type Operand = Limbs<9>;
14676 #[inline]
14677 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14678 a.xor(b).mask_high_bits(520)
14679 }
14680}
14681
14682impl RingOp<W520> for And<W520> {
14683 type Operand = Limbs<9>;
14684 #[inline]
14685 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14686 a.and(b).mask_high_bits(520)
14687 }
14688}
14689
14690impl RingOp<W520> for Or<W520> {
14691 type Operand = Limbs<9>;
14692 #[inline]
14693 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14694 a.or(b).mask_high_bits(520)
14695 }
14696}
14697
14698impl UnaryRingOp<W520> for Neg<W520> {
14699 type Operand = Limbs<9>;
14700 #[inline]
14701 fn apply(a: Limbs<9>) -> Limbs<9> {
14702 (Limbs::<9>::zero().wrapping_sub(a)).mask_high_bits(520)
14703 }
14704}
14705
14706impl UnaryRingOp<W520> for BNot<W520> {
14707 type Operand = Limbs<9>;
14708 #[inline]
14709 fn apply(a: Limbs<9>) -> Limbs<9> {
14710 (a.not()).mask_high_bits(520)
14711 }
14712}
14713
14714impl UnaryRingOp<W520> for Succ<W520> {
14715 type Operand = Limbs<9>;
14716 #[inline]
14717 fn apply(a: Limbs<9>) -> Limbs<9> {
14718 (a.wrapping_add(Limbs::<9>::from_words([
14719 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14720 ])))
14721 .mask_high_bits(520)
14722 }
14723}
14724
14725impl RingOp<W528> for Mul<W528> {
14726 type Operand = Limbs<9>;
14727 #[inline]
14728 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14729 a.wrapping_mul(b).mask_high_bits(528)
14730 }
14731}
14732
14733impl RingOp<W528> for Add<W528> {
14734 type Operand = Limbs<9>;
14735 #[inline]
14736 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14737 a.wrapping_add(b).mask_high_bits(528)
14738 }
14739}
14740
14741impl RingOp<W528> for Sub<W528> {
14742 type Operand = Limbs<9>;
14743 #[inline]
14744 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14745 a.wrapping_sub(b).mask_high_bits(528)
14746 }
14747}
14748
14749impl RingOp<W528> for Xor<W528> {
14750 type Operand = Limbs<9>;
14751 #[inline]
14752 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14753 a.xor(b).mask_high_bits(528)
14754 }
14755}
14756
14757impl RingOp<W528> for And<W528> {
14758 type Operand = Limbs<9>;
14759 #[inline]
14760 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14761 a.and(b).mask_high_bits(528)
14762 }
14763}
14764
14765impl RingOp<W528> for Or<W528> {
14766 type Operand = Limbs<9>;
14767 #[inline]
14768 fn apply(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
14769 a.or(b).mask_high_bits(528)
14770 }
14771}
14772
14773impl UnaryRingOp<W528> for Neg<W528> {
14774 type Operand = Limbs<9>;
14775 #[inline]
14776 fn apply(a: Limbs<9>) -> Limbs<9> {
14777 (Limbs::<9>::zero().wrapping_sub(a)).mask_high_bits(528)
14778 }
14779}
14780
14781impl UnaryRingOp<W528> for BNot<W528> {
14782 type Operand = Limbs<9>;
14783 #[inline]
14784 fn apply(a: Limbs<9>) -> Limbs<9> {
14785 (a.not()).mask_high_bits(528)
14786 }
14787}
14788
14789impl UnaryRingOp<W528> for Succ<W528> {
14790 type Operand = Limbs<9>;
14791 #[inline]
14792 fn apply(a: Limbs<9>) -> Limbs<9> {
14793 (a.wrapping_add(Limbs::<9>::from_words([
14794 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14795 ])))
14796 .mask_high_bits(528)
14797 }
14798}
14799
14800impl RingOp<W1024> for Mul<W1024> {
14801 type Operand = Limbs<16>;
14802 #[inline]
14803 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14804 a.wrapping_mul(b)
14805 }
14806}
14807
14808impl RingOp<W1024> for Add<W1024> {
14809 type Operand = Limbs<16>;
14810 #[inline]
14811 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14812 a.wrapping_add(b)
14813 }
14814}
14815
14816impl RingOp<W1024> for Sub<W1024> {
14817 type Operand = Limbs<16>;
14818 #[inline]
14819 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14820 a.wrapping_sub(b)
14821 }
14822}
14823
14824impl RingOp<W1024> for Xor<W1024> {
14825 type Operand = Limbs<16>;
14826 #[inline]
14827 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14828 a.xor(b)
14829 }
14830}
14831
14832impl RingOp<W1024> for And<W1024> {
14833 type Operand = Limbs<16>;
14834 #[inline]
14835 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14836 a.and(b)
14837 }
14838}
14839
14840impl RingOp<W1024> for Or<W1024> {
14841 type Operand = Limbs<16>;
14842 #[inline]
14843 fn apply(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
14844 a.or(b)
14845 }
14846}
14847
14848impl UnaryRingOp<W1024> for Neg<W1024> {
14849 type Operand = Limbs<16>;
14850 #[inline]
14851 fn apply(a: Limbs<16>) -> Limbs<16> {
14852 Limbs::<16>::zero().wrapping_sub(a)
14853 }
14854}
14855
14856impl UnaryRingOp<W1024> for BNot<W1024> {
14857 type Operand = Limbs<16>;
14858 #[inline]
14859 fn apply(a: Limbs<16>) -> Limbs<16> {
14860 a.not()
14861 }
14862}
14863
14864impl UnaryRingOp<W1024> for Succ<W1024> {
14865 type Operand = Limbs<16>;
14866 #[inline]
14867 fn apply(a: Limbs<16>) -> Limbs<16> {
14868 a.wrapping_add(Limbs::<16>::from_words([
14869 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14870 0u64, 0u64,
14871 ]))
14872 }
14873}
14874
14875impl RingOp<W2048> for Mul<W2048> {
14876 type Operand = Limbs<32>;
14877 #[inline]
14878 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14879 a.wrapping_mul(b)
14880 }
14881}
14882
14883impl RingOp<W2048> for Add<W2048> {
14884 type Operand = Limbs<32>;
14885 #[inline]
14886 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14887 a.wrapping_add(b)
14888 }
14889}
14890
14891impl RingOp<W2048> for Sub<W2048> {
14892 type Operand = Limbs<32>;
14893 #[inline]
14894 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14895 a.wrapping_sub(b)
14896 }
14897}
14898
14899impl RingOp<W2048> for Xor<W2048> {
14900 type Operand = Limbs<32>;
14901 #[inline]
14902 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14903 a.xor(b)
14904 }
14905}
14906
14907impl RingOp<W2048> for And<W2048> {
14908 type Operand = Limbs<32>;
14909 #[inline]
14910 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14911 a.and(b)
14912 }
14913}
14914
14915impl RingOp<W2048> for Or<W2048> {
14916 type Operand = Limbs<32>;
14917 #[inline]
14918 fn apply(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
14919 a.or(b)
14920 }
14921}
14922
14923impl UnaryRingOp<W2048> for Neg<W2048> {
14924 type Operand = Limbs<32>;
14925 #[inline]
14926 fn apply(a: Limbs<32>) -> Limbs<32> {
14927 Limbs::<32>::zero().wrapping_sub(a)
14928 }
14929}
14930
14931impl UnaryRingOp<W2048> for BNot<W2048> {
14932 type Operand = Limbs<32>;
14933 #[inline]
14934 fn apply(a: Limbs<32>) -> Limbs<32> {
14935 a.not()
14936 }
14937}
14938
14939impl UnaryRingOp<W2048> for Succ<W2048> {
14940 type Operand = Limbs<32>;
14941 #[inline]
14942 fn apply(a: Limbs<32>) -> Limbs<32> {
14943 a.wrapping_add(Limbs::<32>::from_words([
14944 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14945 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
14946 0u64, 0u64, 0u64, 0u64,
14947 ]))
14948 }
14949}
14950
14951impl RingOp<W4096> for Mul<W4096> {
14952 type Operand = Limbs<64>;
14953 #[inline]
14954 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
14955 a.wrapping_mul(b)
14956 }
14957}
14958
14959impl RingOp<W4096> for Add<W4096> {
14960 type Operand = Limbs<64>;
14961 #[inline]
14962 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
14963 a.wrapping_add(b)
14964 }
14965}
14966
14967impl RingOp<W4096> for Sub<W4096> {
14968 type Operand = Limbs<64>;
14969 #[inline]
14970 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
14971 a.wrapping_sub(b)
14972 }
14973}
14974
14975impl RingOp<W4096> for Xor<W4096> {
14976 type Operand = Limbs<64>;
14977 #[inline]
14978 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
14979 a.xor(b)
14980 }
14981}
14982
14983impl RingOp<W4096> for And<W4096> {
14984 type Operand = Limbs<64>;
14985 #[inline]
14986 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
14987 a.and(b)
14988 }
14989}
14990
14991impl RingOp<W4096> for Or<W4096> {
14992 type Operand = Limbs<64>;
14993 #[inline]
14994 fn apply(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
14995 a.or(b)
14996 }
14997}
14998
14999impl UnaryRingOp<W4096> for Neg<W4096> {
15000 type Operand = Limbs<64>;
15001 #[inline]
15002 fn apply(a: Limbs<64>) -> Limbs<64> {
15003 Limbs::<64>::zero().wrapping_sub(a)
15004 }
15005}
15006
15007impl UnaryRingOp<W4096> for BNot<W4096> {
15008 type Operand = Limbs<64>;
15009 #[inline]
15010 fn apply(a: Limbs<64>) -> Limbs<64> {
15011 a.not()
15012 }
15013}
15014
15015impl UnaryRingOp<W4096> for Succ<W4096> {
15016 type Operand = Limbs<64>;
15017 #[inline]
15018 fn apply(a: Limbs<64>) -> Limbs<64> {
15019 a.wrapping_add(Limbs::<64>::from_words([
15020 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15021 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15022 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15023 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15024 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15025 ]))
15026 }
15027}
15028
15029impl RingOp<W8192> for Mul<W8192> {
15030 type Operand = Limbs<128>;
15031 #[inline]
15032 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15033 a.wrapping_mul(b)
15034 }
15035}
15036
15037impl RingOp<W8192> for Add<W8192> {
15038 type Operand = Limbs<128>;
15039 #[inline]
15040 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15041 a.wrapping_add(b)
15042 }
15043}
15044
15045impl RingOp<W8192> for Sub<W8192> {
15046 type Operand = Limbs<128>;
15047 #[inline]
15048 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15049 a.wrapping_sub(b)
15050 }
15051}
15052
15053impl RingOp<W8192> for Xor<W8192> {
15054 type Operand = Limbs<128>;
15055 #[inline]
15056 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15057 a.xor(b)
15058 }
15059}
15060
15061impl RingOp<W8192> for And<W8192> {
15062 type Operand = Limbs<128>;
15063 #[inline]
15064 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15065 a.and(b)
15066 }
15067}
15068
15069impl RingOp<W8192> for Or<W8192> {
15070 type Operand = Limbs<128>;
15071 #[inline]
15072 fn apply(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
15073 a.or(b)
15074 }
15075}
15076
15077impl UnaryRingOp<W8192> for Neg<W8192> {
15078 type Operand = Limbs<128>;
15079 #[inline]
15080 fn apply(a: Limbs<128>) -> Limbs<128> {
15081 Limbs::<128>::zero().wrapping_sub(a)
15082 }
15083}
15084
15085impl UnaryRingOp<W8192> for BNot<W8192> {
15086 type Operand = Limbs<128>;
15087 #[inline]
15088 fn apply(a: Limbs<128>) -> Limbs<128> {
15089 a.not()
15090 }
15091}
15092
15093impl UnaryRingOp<W8192> for Succ<W8192> {
15094 type Operand = Limbs<128>;
15095 #[inline]
15096 fn apply(a: Limbs<128>) -> Limbs<128> {
15097 a.wrapping_add(Limbs::<128>::from_words([
15098 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15099 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15100 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15101 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15102 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15103 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15104 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15105 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15106 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15107 0u64, 0u64,
15108 ]))
15109 }
15110}
15111
15112impl RingOp<W12288> for Mul<W12288> {
15113 type Operand = Limbs<192>;
15114 #[inline]
15115 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15116 a.wrapping_mul(b)
15117 }
15118}
15119
15120impl RingOp<W12288> for Add<W12288> {
15121 type Operand = Limbs<192>;
15122 #[inline]
15123 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15124 a.wrapping_add(b)
15125 }
15126}
15127
15128impl RingOp<W12288> for Sub<W12288> {
15129 type Operand = Limbs<192>;
15130 #[inline]
15131 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15132 a.wrapping_sub(b)
15133 }
15134}
15135
15136impl RingOp<W12288> for Xor<W12288> {
15137 type Operand = Limbs<192>;
15138 #[inline]
15139 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15140 a.xor(b)
15141 }
15142}
15143
15144impl RingOp<W12288> for And<W12288> {
15145 type Operand = Limbs<192>;
15146 #[inline]
15147 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15148 a.and(b)
15149 }
15150}
15151
15152impl RingOp<W12288> for Or<W12288> {
15153 type Operand = Limbs<192>;
15154 #[inline]
15155 fn apply(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
15156 a.or(b)
15157 }
15158}
15159
15160impl UnaryRingOp<W12288> for Neg<W12288> {
15161 type Operand = Limbs<192>;
15162 #[inline]
15163 fn apply(a: Limbs<192>) -> Limbs<192> {
15164 Limbs::<192>::zero().wrapping_sub(a)
15165 }
15166}
15167
15168impl UnaryRingOp<W12288> for BNot<W12288> {
15169 type Operand = Limbs<192>;
15170 #[inline]
15171 fn apply(a: Limbs<192>) -> Limbs<192> {
15172 a.not()
15173 }
15174}
15175
15176impl UnaryRingOp<W12288> for Succ<W12288> {
15177 type Operand = Limbs<192>;
15178 #[inline]
15179 fn apply(a: Limbs<192>) -> Limbs<192> {
15180 a.wrapping_add(Limbs::<192>::from_words([
15181 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15182 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15183 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15184 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15185 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15186 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15187 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15188 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15189 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15190 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15191 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15192 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15193 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15194 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15195 ]))
15196 }
15197}
15198
15199impl RingOp<W16384> for Mul<W16384> {
15200 type Operand = Limbs<256>;
15201 #[inline]
15202 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15203 a.wrapping_mul(b)
15204 }
15205}
15206
15207impl RingOp<W16384> for Add<W16384> {
15208 type Operand = Limbs<256>;
15209 #[inline]
15210 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15211 a.wrapping_add(b)
15212 }
15213}
15214
15215impl RingOp<W16384> for Sub<W16384> {
15216 type Operand = Limbs<256>;
15217 #[inline]
15218 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15219 a.wrapping_sub(b)
15220 }
15221}
15222
15223impl RingOp<W16384> for Xor<W16384> {
15224 type Operand = Limbs<256>;
15225 #[inline]
15226 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15227 a.xor(b)
15228 }
15229}
15230
15231impl RingOp<W16384> for And<W16384> {
15232 type Operand = Limbs<256>;
15233 #[inline]
15234 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15235 a.and(b)
15236 }
15237}
15238
15239impl RingOp<W16384> for Or<W16384> {
15240 type Operand = Limbs<256>;
15241 #[inline]
15242 fn apply(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
15243 a.or(b)
15244 }
15245}
15246
15247impl UnaryRingOp<W16384> for Neg<W16384> {
15248 type Operand = Limbs<256>;
15249 #[inline]
15250 fn apply(a: Limbs<256>) -> Limbs<256> {
15251 Limbs::<256>::zero().wrapping_sub(a)
15252 }
15253}
15254
15255impl UnaryRingOp<W16384> for BNot<W16384> {
15256 type Operand = Limbs<256>;
15257 #[inline]
15258 fn apply(a: Limbs<256>) -> Limbs<256> {
15259 a.not()
15260 }
15261}
15262
15263impl UnaryRingOp<W16384> for Succ<W16384> {
15264 type Operand = Limbs<256>;
15265 #[inline]
15266 fn apply(a: Limbs<256>) -> Limbs<256> {
15267 a.wrapping_add(Limbs::<256>::from_words([
15268 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15269 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15270 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15271 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15272 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15273 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15274 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15275 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15276 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15277 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15278 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15279 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15280 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15281 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15282 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15283 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15284 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15285 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15286 0u64, 0u64, 0u64, 0u64,
15287 ]))
15288 }
15289}
15290
15291impl RingOp<W32768> for Mul<W32768> {
15292 type Operand = Limbs<512>;
15293 #[inline]
15294 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15295 a.wrapping_mul(b)
15296 }
15297}
15298
15299impl RingOp<W32768> for Add<W32768> {
15300 type Operand = Limbs<512>;
15301 #[inline]
15302 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15303 a.wrapping_add(b)
15304 }
15305}
15306
15307impl RingOp<W32768> for Sub<W32768> {
15308 type Operand = Limbs<512>;
15309 #[inline]
15310 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15311 a.wrapping_sub(b)
15312 }
15313}
15314
15315impl RingOp<W32768> for Xor<W32768> {
15316 type Operand = Limbs<512>;
15317 #[inline]
15318 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15319 a.xor(b)
15320 }
15321}
15322
15323impl RingOp<W32768> for And<W32768> {
15324 type Operand = Limbs<512>;
15325 #[inline]
15326 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15327 a.and(b)
15328 }
15329}
15330
15331impl RingOp<W32768> for Or<W32768> {
15332 type Operand = Limbs<512>;
15333 #[inline]
15334 fn apply(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
15335 a.or(b)
15336 }
15337}
15338
15339impl UnaryRingOp<W32768> for Neg<W32768> {
15340 type Operand = Limbs<512>;
15341 #[inline]
15342 fn apply(a: Limbs<512>) -> Limbs<512> {
15343 Limbs::<512>::zero().wrapping_sub(a)
15344 }
15345}
15346
15347impl UnaryRingOp<W32768> for BNot<W32768> {
15348 type Operand = Limbs<512>;
15349 #[inline]
15350 fn apply(a: Limbs<512>) -> Limbs<512> {
15351 a.not()
15352 }
15353}
15354
15355impl UnaryRingOp<W32768> for Succ<W32768> {
15356 type Operand = Limbs<512>;
15357 #[inline]
15358 fn apply(a: Limbs<512>) -> Limbs<512> {
15359 a.wrapping_add(Limbs::<512>::from_words([
15360 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15361 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15362 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15363 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15364 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15365 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15366 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15367 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15368 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15369 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15370 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15371 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15372 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15373 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15374 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15375 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15376 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15377 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15378 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15379 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15380 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15381 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15382 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15383 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15384 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15385 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15386 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15387 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15388 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15389 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15390 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15391 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15392 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15393 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15394 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15395 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15396 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
15397 ]))
15398 }
15399}
15400
15401#[inline]
15408#[must_use]
15409pub const fn const_ring_eval_w160(op: PrimitiveOp, a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
15410 let raw = match op {
15411 PrimitiveOp::Add => a.wrapping_add(b),
15412 PrimitiveOp::Sub => a.wrapping_sub(b),
15413 PrimitiveOp::Mul => a.wrapping_mul(b),
15414 PrimitiveOp::And => a.and(b),
15415 PrimitiveOp::Or => a.or(b),
15416 PrimitiveOp::Xor => a.xor(b),
15417 PrimitiveOp::Neg => Limbs::<3>::zero().wrapping_sub(a),
15418 PrimitiveOp::Bnot => a.not(),
15419 PrimitiveOp::Succ => a.wrapping_add(limbs_one_3()),
15420 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_3()),
15421 PrimitiveOp::Le => {
15422 if limbs_le_3(a, b) {
15423 limbs_one_3()
15424 } else {
15425 Limbs::<3>::zero()
15426 }
15427 }
15428 PrimitiveOp::Lt => {
15429 if limbs_lt_3(a, b) {
15430 limbs_one_3()
15431 } else {
15432 Limbs::<3>::zero()
15433 }
15434 }
15435 PrimitiveOp::Ge => {
15436 if limbs_le_3(b, a) {
15437 limbs_one_3()
15438 } else {
15439 Limbs::<3>::zero()
15440 }
15441 }
15442 PrimitiveOp::Gt => {
15443 if limbs_lt_3(b, a) {
15444 limbs_one_3()
15445 } else {
15446 Limbs::<3>::zero()
15447 }
15448 }
15449 PrimitiveOp::Concat => Limbs::<3>::zero(),
15450 PrimitiveOp::Div => {
15451 if limbs_is_zero_3(b) {
15452 Limbs::<3>::zero()
15453 } else {
15454 limbs_div_3(a, b)
15455 }
15456 }
15457 PrimitiveOp::Mod => {
15458 if limbs_is_zero_3(b) {
15459 Limbs::<3>::zero()
15460 } else {
15461 limbs_mod_3(a, b)
15462 }
15463 }
15464 PrimitiveOp::Pow => limbs_pow_3(a, b),
15465 };
15466 raw.mask_high_bits(160)
15467}
15468
15469#[inline]
15470#[must_use]
15471pub const fn const_ring_eval_w192(op: PrimitiveOp, a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
15472 match op {
15473 PrimitiveOp::Add => a.wrapping_add(b),
15474 PrimitiveOp::Sub => a.wrapping_sub(b),
15475 PrimitiveOp::Mul => a.wrapping_mul(b),
15476 PrimitiveOp::And => a.and(b),
15477 PrimitiveOp::Or => a.or(b),
15478 PrimitiveOp::Xor => a.xor(b),
15479 PrimitiveOp::Neg => Limbs::<3>::zero().wrapping_sub(a),
15480 PrimitiveOp::Bnot => a.not(),
15481 PrimitiveOp::Succ => a.wrapping_add(limbs_one_3()),
15482 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_3()),
15483 PrimitiveOp::Le => {
15484 if limbs_le_3(a, b) {
15485 limbs_one_3()
15486 } else {
15487 Limbs::<3>::zero()
15488 }
15489 }
15490 PrimitiveOp::Lt => {
15491 if limbs_lt_3(a, b) {
15492 limbs_one_3()
15493 } else {
15494 Limbs::<3>::zero()
15495 }
15496 }
15497 PrimitiveOp::Ge => {
15498 if limbs_le_3(b, a) {
15499 limbs_one_3()
15500 } else {
15501 Limbs::<3>::zero()
15502 }
15503 }
15504 PrimitiveOp::Gt => {
15505 if limbs_lt_3(b, a) {
15506 limbs_one_3()
15507 } else {
15508 Limbs::<3>::zero()
15509 }
15510 }
15511 PrimitiveOp::Concat => Limbs::<3>::zero(),
15512 PrimitiveOp::Div => {
15513 if limbs_is_zero_3(b) {
15514 Limbs::<3>::zero()
15515 } else {
15516 limbs_div_3(a, b)
15517 }
15518 }
15519 PrimitiveOp::Mod => {
15520 if limbs_is_zero_3(b) {
15521 Limbs::<3>::zero()
15522 } else {
15523 limbs_mod_3(a, b)
15524 }
15525 }
15526 PrimitiveOp::Pow => limbs_pow_3(a, b),
15527 }
15528}
15529
15530#[inline]
15531#[must_use]
15532pub const fn const_ring_eval_w224(op: PrimitiveOp, a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
15533 let raw = match op {
15534 PrimitiveOp::Add => a.wrapping_add(b),
15535 PrimitiveOp::Sub => a.wrapping_sub(b),
15536 PrimitiveOp::Mul => a.wrapping_mul(b),
15537 PrimitiveOp::And => a.and(b),
15538 PrimitiveOp::Or => a.or(b),
15539 PrimitiveOp::Xor => a.xor(b),
15540 PrimitiveOp::Neg => Limbs::<4>::zero().wrapping_sub(a),
15541 PrimitiveOp::Bnot => a.not(),
15542 PrimitiveOp::Succ => a.wrapping_add(limbs_one_4()),
15543 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_4()),
15544 PrimitiveOp::Le => {
15545 if limbs_le_4(a, b) {
15546 limbs_one_4()
15547 } else {
15548 Limbs::<4>::zero()
15549 }
15550 }
15551 PrimitiveOp::Lt => {
15552 if limbs_lt_4(a, b) {
15553 limbs_one_4()
15554 } else {
15555 Limbs::<4>::zero()
15556 }
15557 }
15558 PrimitiveOp::Ge => {
15559 if limbs_le_4(b, a) {
15560 limbs_one_4()
15561 } else {
15562 Limbs::<4>::zero()
15563 }
15564 }
15565 PrimitiveOp::Gt => {
15566 if limbs_lt_4(b, a) {
15567 limbs_one_4()
15568 } else {
15569 Limbs::<4>::zero()
15570 }
15571 }
15572 PrimitiveOp::Concat => Limbs::<4>::zero(),
15573 PrimitiveOp::Div => {
15574 if limbs_is_zero_4(b) {
15575 Limbs::<4>::zero()
15576 } else {
15577 limbs_div_4(a, b)
15578 }
15579 }
15580 PrimitiveOp::Mod => {
15581 if limbs_is_zero_4(b) {
15582 Limbs::<4>::zero()
15583 } else {
15584 limbs_mod_4(a, b)
15585 }
15586 }
15587 PrimitiveOp::Pow => limbs_pow_4(a, b),
15588 };
15589 raw.mask_high_bits(224)
15590}
15591
15592#[inline]
15593#[must_use]
15594pub const fn const_ring_eval_w256(op: PrimitiveOp, a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
15595 match op {
15596 PrimitiveOp::Add => a.wrapping_add(b),
15597 PrimitiveOp::Sub => a.wrapping_sub(b),
15598 PrimitiveOp::Mul => a.wrapping_mul(b),
15599 PrimitiveOp::And => a.and(b),
15600 PrimitiveOp::Or => a.or(b),
15601 PrimitiveOp::Xor => a.xor(b),
15602 PrimitiveOp::Neg => Limbs::<4>::zero().wrapping_sub(a),
15603 PrimitiveOp::Bnot => a.not(),
15604 PrimitiveOp::Succ => a.wrapping_add(limbs_one_4()),
15605 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_4()),
15606 PrimitiveOp::Le => {
15607 if limbs_le_4(a, b) {
15608 limbs_one_4()
15609 } else {
15610 Limbs::<4>::zero()
15611 }
15612 }
15613 PrimitiveOp::Lt => {
15614 if limbs_lt_4(a, b) {
15615 limbs_one_4()
15616 } else {
15617 Limbs::<4>::zero()
15618 }
15619 }
15620 PrimitiveOp::Ge => {
15621 if limbs_le_4(b, a) {
15622 limbs_one_4()
15623 } else {
15624 Limbs::<4>::zero()
15625 }
15626 }
15627 PrimitiveOp::Gt => {
15628 if limbs_lt_4(b, a) {
15629 limbs_one_4()
15630 } else {
15631 Limbs::<4>::zero()
15632 }
15633 }
15634 PrimitiveOp::Concat => Limbs::<4>::zero(),
15635 PrimitiveOp::Div => {
15636 if limbs_is_zero_4(b) {
15637 Limbs::<4>::zero()
15638 } else {
15639 limbs_div_4(a, b)
15640 }
15641 }
15642 PrimitiveOp::Mod => {
15643 if limbs_is_zero_4(b) {
15644 Limbs::<4>::zero()
15645 } else {
15646 limbs_mod_4(a, b)
15647 }
15648 }
15649 PrimitiveOp::Pow => limbs_pow_4(a, b),
15650 }
15651}
15652
15653#[inline]
15654#[must_use]
15655pub const fn const_ring_eval_w384(op: PrimitiveOp, a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
15656 match op {
15657 PrimitiveOp::Add => a.wrapping_add(b),
15658 PrimitiveOp::Sub => a.wrapping_sub(b),
15659 PrimitiveOp::Mul => a.wrapping_mul(b),
15660 PrimitiveOp::And => a.and(b),
15661 PrimitiveOp::Or => a.or(b),
15662 PrimitiveOp::Xor => a.xor(b),
15663 PrimitiveOp::Neg => Limbs::<6>::zero().wrapping_sub(a),
15664 PrimitiveOp::Bnot => a.not(),
15665 PrimitiveOp::Succ => a.wrapping_add(limbs_one_6()),
15666 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_6()),
15667 PrimitiveOp::Le => {
15668 if limbs_le_6(a, b) {
15669 limbs_one_6()
15670 } else {
15671 Limbs::<6>::zero()
15672 }
15673 }
15674 PrimitiveOp::Lt => {
15675 if limbs_lt_6(a, b) {
15676 limbs_one_6()
15677 } else {
15678 Limbs::<6>::zero()
15679 }
15680 }
15681 PrimitiveOp::Ge => {
15682 if limbs_le_6(b, a) {
15683 limbs_one_6()
15684 } else {
15685 Limbs::<6>::zero()
15686 }
15687 }
15688 PrimitiveOp::Gt => {
15689 if limbs_lt_6(b, a) {
15690 limbs_one_6()
15691 } else {
15692 Limbs::<6>::zero()
15693 }
15694 }
15695 PrimitiveOp::Concat => Limbs::<6>::zero(),
15696 PrimitiveOp::Div => {
15697 if limbs_is_zero_6(b) {
15698 Limbs::<6>::zero()
15699 } else {
15700 limbs_div_6(a, b)
15701 }
15702 }
15703 PrimitiveOp::Mod => {
15704 if limbs_is_zero_6(b) {
15705 Limbs::<6>::zero()
15706 } else {
15707 limbs_mod_6(a, b)
15708 }
15709 }
15710 PrimitiveOp::Pow => limbs_pow_6(a, b),
15711 }
15712}
15713
15714#[inline]
15715#[must_use]
15716pub const fn const_ring_eval_w448(op: PrimitiveOp, a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
15717 match op {
15718 PrimitiveOp::Add => a.wrapping_add(b),
15719 PrimitiveOp::Sub => a.wrapping_sub(b),
15720 PrimitiveOp::Mul => a.wrapping_mul(b),
15721 PrimitiveOp::And => a.and(b),
15722 PrimitiveOp::Or => a.or(b),
15723 PrimitiveOp::Xor => a.xor(b),
15724 PrimitiveOp::Neg => Limbs::<7>::zero().wrapping_sub(a),
15725 PrimitiveOp::Bnot => a.not(),
15726 PrimitiveOp::Succ => a.wrapping_add(limbs_one_7()),
15727 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_7()),
15728 PrimitiveOp::Le => {
15729 if limbs_le_7(a, b) {
15730 limbs_one_7()
15731 } else {
15732 Limbs::<7>::zero()
15733 }
15734 }
15735 PrimitiveOp::Lt => {
15736 if limbs_lt_7(a, b) {
15737 limbs_one_7()
15738 } else {
15739 Limbs::<7>::zero()
15740 }
15741 }
15742 PrimitiveOp::Ge => {
15743 if limbs_le_7(b, a) {
15744 limbs_one_7()
15745 } else {
15746 Limbs::<7>::zero()
15747 }
15748 }
15749 PrimitiveOp::Gt => {
15750 if limbs_lt_7(b, a) {
15751 limbs_one_7()
15752 } else {
15753 Limbs::<7>::zero()
15754 }
15755 }
15756 PrimitiveOp::Concat => Limbs::<7>::zero(),
15757 PrimitiveOp::Div => {
15758 if limbs_is_zero_7(b) {
15759 Limbs::<7>::zero()
15760 } else {
15761 limbs_div_7(a, b)
15762 }
15763 }
15764 PrimitiveOp::Mod => {
15765 if limbs_is_zero_7(b) {
15766 Limbs::<7>::zero()
15767 } else {
15768 limbs_mod_7(a, b)
15769 }
15770 }
15771 PrimitiveOp::Pow => limbs_pow_7(a, b),
15772 }
15773}
15774
15775#[inline]
15776#[must_use]
15777pub const fn const_ring_eval_w512(op: PrimitiveOp, a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
15778 match op {
15779 PrimitiveOp::Add => a.wrapping_add(b),
15780 PrimitiveOp::Sub => a.wrapping_sub(b),
15781 PrimitiveOp::Mul => a.wrapping_mul(b),
15782 PrimitiveOp::And => a.and(b),
15783 PrimitiveOp::Or => a.or(b),
15784 PrimitiveOp::Xor => a.xor(b),
15785 PrimitiveOp::Neg => Limbs::<8>::zero().wrapping_sub(a),
15786 PrimitiveOp::Bnot => a.not(),
15787 PrimitiveOp::Succ => a.wrapping_add(limbs_one_8()),
15788 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_8()),
15789 PrimitiveOp::Le => {
15790 if limbs_le_8(a, b) {
15791 limbs_one_8()
15792 } else {
15793 Limbs::<8>::zero()
15794 }
15795 }
15796 PrimitiveOp::Lt => {
15797 if limbs_lt_8(a, b) {
15798 limbs_one_8()
15799 } else {
15800 Limbs::<8>::zero()
15801 }
15802 }
15803 PrimitiveOp::Ge => {
15804 if limbs_le_8(b, a) {
15805 limbs_one_8()
15806 } else {
15807 Limbs::<8>::zero()
15808 }
15809 }
15810 PrimitiveOp::Gt => {
15811 if limbs_lt_8(b, a) {
15812 limbs_one_8()
15813 } else {
15814 Limbs::<8>::zero()
15815 }
15816 }
15817 PrimitiveOp::Concat => Limbs::<8>::zero(),
15818 PrimitiveOp::Div => {
15819 if limbs_is_zero_8(b) {
15820 Limbs::<8>::zero()
15821 } else {
15822 limbs_div_8(a, b)
15823 }
15824 }
15825 PrimitiveOp::Mod => {
15826 if limbs_is_zero_8(b) {
15827 Limbs::<8>::zero()
15828 } else {
15829 limbs_mod_8(a, b)
15830 }
15831 }
15832 PrimitiveOp::Pow => limbs_pow_8(a, b),
15833 }
15834}
15835
15836#[inline]
15837#[must_use]
15838pub const fn const_ring_eval_w520(op: PrimitiveOp, a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
15839 let raw = match op {
15840 PrimitiveOp::Add => a.wrapping_add(b),
15841 PrimitiveOp::Sub => a.wrapping_sub(b),
15842 PrimitiveOp::Mul => a.wrapping_mul(b),
15843 PrimitiveOp::And => a.and(b),
15844 PrimitiveOp::Or => a.or(b),
15845 PrimitiveOp::Xor => a.xor(b),
15846 PrimitiveOp::Neg => Limbs::<9>::zero().wrapping_sub(a),
15847 PrimitiveOp::Bnot => a.not(),
15848 PrimitiveOp::Succ => a.wrapping_add(limbs_one_9()),
15849 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_9()),
15850 PrimitiveOp::Le => {
15851 if limbs_le_9(a, b) {
15852 limbs_one_9()
15853 } else {
15854 Limbs::<9>::zero()
15855 }
15856 }
15857 PrimitiveOp::Lt => {
15858 if limbs_lt_9(a, b) {
15859 limbs_one_9()
15860 } else {
15861 Limbs::<9>::zero()
15862 }
15863 }
15864 PrimitiveOp::Ge => {
15865 if limbs_le_9(b, a) {
15866 limbs_one_9()
15867 } else {
15868 Limbs::<9>::zero()
15869 }
15870 }
15871 PrimitiveOp::Gt => {
15872 if limbs_lt_9(b, a) {
15873 limbs_one_9()
15874 } else {
15875 Limbs::<9>::zero()
15876 }
15877 }
15878 PrimitiveOp::Concat => Limbs::<9>::zero(),
15879 PrimitiveOp::Div => {
15880 if limbs_is_zero_9(b) {
15881 Limbs::<9>::zero()
15882 } else {
15883 limbs_div_9(a, b)
15884 }
15885 }
15886 PrimitiveOp::Mod => {
15887 if limbs_is_zero_9(b) {
15888 Limbs::<9>::zero()
15889 } else {
15890 limbs_mod_9(a, b)
15891 }
15892 }
15893 PrimitiveOp::Pow => limbs_pow_9(a, b),
15894 };
15895 raw.mask_high_bits(520)
15896}
15897
15898#[inline]
15899#[must_use]
15900pub const fn const_ring_eval_w528(op: PrimitiveOp, a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
15901 let raw = match op {
15902 PrimitiveOp::Add => a.wrapping_add(b),
15903 PrimitiveOp::Sub => a.wrapping_sub(b),
15904 PrimitiveOp::Mul => a.wrapping_mul(b),
15905 PrimitiveOp::And => a.and(b),
15906 PrimitiveOp::Or => a.or(b),
15907 PrimitiveOp::Xor => a.xor(b),
15908 PrimitiveOp::Neg => Limbs::<9>::zero().wrapping_sub(a),
15909 PrimitiveOp::Bnot => a.not(),
15910 PrimitiveOp::Succ => a.wrapping_add(limbs_one_9()),
15911 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_9()),
15912 PrimitiveOp::Le => {
15913 if limbs_le_9(a, b) {
15914 limbs_one_9()
15915 } else {
15916 Limbs::<9>::zero()
15917 }
15918 }
15919 PrimitiveOp::Lt => {
15920 if limbs_lt_9(a, b) {
15921 limbs_one_9()
15922 } else {
15923 Limbs::<9>::zero()
15924 }
15925 }
15926 PrimitiveOp::Ge => {
15927 if limbs_le_9(b, a) {
15928 limbs_one_9()
15929 } else {
15930 Limbs::<9>::zero()
15931 }
15932 }
15933 PrimitiveOp::Gt => {
15934 if limbs_lt_9(b, a) {
15935 limbs_one_9()
15936 } else {
15937 Limbs::<9>::zero()
15938 }
15939 }
15940 PrimitiveOp::Concat => Limbs::<9>::zero(),
15941 PrimitiveOp::Div => {
15942 if limbs_is_zero_9(b) {
15943 Limbs::<9>::zero()
15944 } else {
15945 limbs_div_9(a, b)
15946 }
15947 }
15948 PrimitiveOp::Mod => {
15949 if limbs_is_zero_9(b) {
15950 Limbs::<9>::zero()
15951 } else {
15952 limbs_mod_9(a, b)
15953 }
15954 }
15955 PrimitiveOp::Pow => limbs_pow_9(a, b),
15956 };
15957 raw.mask_high_bits(528)
15958}
15959
15960#[inline]
15961#[must_use]
15962pub const fn const_ring_eval_w1024(op: PrimitiveOp, a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
15963 match op {
15964 PrimitiveOp::Add => a.wrapping_add(b),
15965 PrimitiveOp::Sub => a.wrapping_sub(b),
15966 PrimitiveOp::Mul => a.wrapping_mul(b),
15967 PrimitiveOp::And => a.and(b),
15968 PrimitiveOp::Or => a.or(b),
15969 PrimitiveOp::Xor => a.xor(b),
15970 PrimitiveOp::Neg => Limbs::<16>::zero().wrapping_sub(a),
15971 PrimitiveOp::Bnot => a.not(),
15972 PrimitiveOp::Succ => a.wrapping_add(limbs_one_16()),
15973 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_16()),
15974 PrimitiveOp::Le => {
15975 if limbs_le_16(a, b) {
15976 limbs_one_16()
15977 } else {
15978 Limbs::<16>::zero()
15979 }
15980 }
15981 PrimitiveOp::Lt => {
15982 if limbs_lt_16(a, b) {
15983 limbs_one_16()
15984 } else {
15985 Limbs::<16>::zero()
15986 }
15987 }
15988 PrimitiveOp::Ge => {
15989 if limbs_le_16(b, a) {
15990 limbs_one_16()
15991 } else {
15992 Limbs::<16>::zero()
15993 }
15994 }
15995 PrimitiveOp::Gt => {
15996 if limbs_lt_16(b, a) {
15997 limbs_one_16()
15998 } else {
15999 Limbs::<16>::zero()
16000 }
16001 }
16002 PrimitiveOp::Concat => Limbs::<16>::zero(),
16003 PrimitiveOp::Div => {
16004 if limbs_is_zero_16(b) {
16005 Limbs::<16>::zero()
16006 } else {
16007 limbs_div_16(a, b)
16008 }
16009 }
16010 PrimitiveOp::Mod => {
16011 if limbs_is_zero_16(b) {
16012 Limbs::<16>::zero()
16013 } else {
16014 limbs_mod_16(a, b)
16015 }
16016 }
16017 PrimitiveOp::Pow => limbs_pow_16(a, b),
16018 }
16019}
16020
16021#[inline]
16022#[must_use]
16023pub const fn const_ring_eval_w2048(op: PrimitiveOp, a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
16024 match op {
16025 PrimitiveOp::Add => a.wrapping_add(b),
16026 PrimitiveOp::Sub => a.wrapping_sub(b),
16027 PrimitiveOp::Mul => a.wrapping_mul(b),
16028 PrimitiveOp::And => a.and(b),
16029 PrimitiveOp::Or => a.or(b),
16030 PrimitiveOp::Xor => a.xor(b),
16031 PrimitiveOp::Neg => Limbs::<32>::zero().wrapping_sub(a),
16032 PrimitiveOp::Bnot => a.not(),
16033 PrimitiveOp::Succ => a.wrapping_add(limbs_one_32()),
16034 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_32()),
16035 PrimitiveOp::Le => {
16036 if limbs_le_32(a, b) {
16037 limbs_one_32()
16038 } else {
16039 Limbs::<32>::zero()
16040 }
16041 }
16042 PrimitiveOp::Lt => {
16043 if limbs_lt_32(a, b) {
16044 limbs_one_32()
16045 } else {
16046 Limbs::<32>::zero()
16047 }
16048 }
16049 PrimitiveOp::Ge => {
16050 if limbs_le_32(b, a) {
16051 limbs_one_32()
16052 } else {
16053 Limbs::<32>::zero()
16054 }
16055 }
16056 PrimitiveOp::Gt => {
16057 if limbs_lt_32(b, a) {
16058 limbs_one_32()
16059 } else {
16060 Limbs::<32>::zero()
16061 }
16062 }
16063 PrimitiveOp::Concat => Limbs::<32>::zero(),
16064 PrimitiveOp::Div => {
16065 if limbs_is_zero_32(b) {
16066 Limbs::<32>::zero()
16067 } else {
16068 limbs_div_32(a, b)
16069 }
16070 }
16071 PrimitiveOp::Mod => {
16072 if limbs_is_zero_32(b) {
16073 Limbs::<32>::zero()
16074 } else {
16075 limbs_mod_32(a, b)
16076 }
16077 }
16078 PrimitiveOp::Pow => limbs_pow_32(a, b),
16079 }
16080}
16081
16082#[inline]
16083#[must_use]
16084pub const fn const_ring_eval_w4096(op: PrimitiveOp, a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
16085 match op {
16086 PrimitiveOp::Add => a.wrapping_add(b),
16087 PrimitiveOp::Sub => a.wrapping_sub(b),
16088 PrimitiveOp::Mul => a.wrapping_mul(b),
16089 PrimitiveOp::And => a.and(b),
16090 PrimitiveOp::Or => a.or(b),
16091 PrimitiveOp::Xor => a.xor(b),
16092 PrimitiveOp::Neg => Limbs::<64>::zero().wrapping_sub(a),
16093 PrimitiveOp::Bnot => a.not(),
16094 PrimitiveOp::Succ => a.wrapping_add(limbs_one_64()),
16095 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_64()),
16096 PrimitiveOp::Le => {
16097 if limbs_le_64(a, b) {
16098 limbs_one_64()
16099 } else {
16100 Limbs::<64>::zero()
16101 }
16102 }
16103 PrimitiveOp::Lt => {
16104 if limbs_lt_64(a, b) {
16105 limbs_one_64()
16106 } else {
16107 Limbs::<64>::zero()
16108 }
16109 }
16110 PrimitiveOp::Ge => {
16111 if limbs_le_64(b, a) {
16112 limbs_one_64()
16113 } else {
16114 Limbs::<64>::zero()
16115 }
16116 }
16117 PrimitiveOp::Gt => {
16118 if limbs_lt_64(b, a) {
16119 limbs_one_64()
16120 } else {
16121 Limbs::<64>::zero()
16122 }
16123 }
16124 PrimitiveOp::Concat => Limbs::<64>::zero(),
16125 PrimitiveOp::Div => {
16126 if limbs_is_zero_64(b) {
16127 Limbs::<64>::zero()
16128 } else {
16129 limbs_div_64(a, b)
16130 }
16131 }
16132 PrimitiveOp::Mod => {
16133 if limbs_is_zero_64(b) {
16134 Limbs::<64>::zero()
16135 } else {
16136 limbs_mod_64(a, b)
16137 }
16138 }
16139 PrimitiveOp::Pow => limbs_pow_64(a, b),
16140 }
16141}
16142
16143#[inline]
16144#[must_use]
16145pub const fn const_ring_eval_w8192(op: PrimitiveOp, a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
16146 match op {
16147 PrimitiveOp::Add => a.wrapping_add(b),
16148 PrimitiveOp::Sub => a.wrapping_sub(b),
16149 PrimitiveOp::Mul => a.wrapping_mul(b),
16150 PrimitiveOp::And => a.and(b),
16151 PrimitiveOp::Or => a.or(b),
16152 PrimitiveOp::Xor => a.xor(b),
16153 PrimitiveOp::Neg => Limbs::<128>::zero().wrapping_sub(a),
16154 PrimitiveOp::Bnot => a.not(),
16155 PrimitiveOp::Succ => a.wrapping_add(limbs_one_128()),
16156 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_128()),
16157 PrimitiveOp::Le => {
16158 if limbs_le_128(a, b) {
16159 limbs_one_128()
16160 } else {
16161 Limbs::<128>::zero()
16162 }
16163 }
16164 PrimitiveOp::Lt => {
16165 if limbs_lt_128(a, b) {
16166 limbs_one_128()
16167 } else {
16168 Limbs::<128>::zero()
16169 }
16170 }
16171 PrimitiveOp::Ge => {
16172 if limbs_le_128(b, a) {
16173 limbs_one_128()
16174 } else {
16175 Limbs::<128>::zero()
16176 }
16177 }
16178 PrimitiveOp::Gt => {
16179 if limbs_lt_128(b, a) {
16180 limbs_one_128()
16181 } else {
16182 Limbs::<128>::zero()
16183 }
16184 }
16185 PrimitiveOp::Concat => Limbs::<128>::zero(),
16186 PrimitiveOp::Div => {
16187 if limbs_is_zero_128(b) {
16188 Limbs::<128>::zero()
16189 } else {
16190 limbs_div_128(a, b)
16191 }
16192 }
16193 PrimitiveOp::Mod => {
16194 if limbs_is_zero_128(b) {
16195 Limbs::<128>::zero()
16196 } else {
16197 limbs_mod_128(a, b)
16198 }
16199 }
16200 PrimitiveOp::Pow => limbs_pow_128(a, b),
16201 }
16202}
16203
16204#[inline]
16205#[must_use]
16206pub const fn const_ring_eval_w12288(op: PrimitiveOp, a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
16207 match op {
16208 PrimitiveOp::Add => a.wrapping_add(b),
16209 PrimitiveOp::Sub => a.wrapping_sub(b),
16210 PrimitiveOp::Mul => a.wrapping_mul(b),
16211 PrimitiveOp::And => a.and(b),
16212 PrimitiveOp::Or => a.or(b),
16213 PrimitiveOp::Xor => a.xor(b),
16214 PrimitiveOp::Neg => Limbs::<192>::zero().wrapping_sub(a),
16215 PrimitiveOp::Bnot => a.not(),
16216 PrimitiveOp::Succ => a.wrapping_add(limbs_one_192()),
16217 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_192()),
16218 PrimitiveOp::Le => {
16219 if limbs_le_192(a, b) {
16220 limbs_one_192()
16221 } else {
16222 Limbs::<192>::zero()
16223 }
16224 }
16225 PrimitiveOp::Lt => {
16226 if limbs_lt_192(a, b) {
16227 limbs_one_192()
16228 } else {
16229 Limbs::<192>::zero()
16230 }
16231 }
16232 PrimitiveOp::Ge => {
16233 if limbs_le_192(b, a) {
16234 limbs_one_192()
16235 } else {
16236 Limbs::<192>::zero()
16237 }
16238 }
16239 PrimitiveOp::Gt => {
16240 if limbs_lt_192(b, a) {
16241 limbs_one_192()
16242 } else {
16243 Limbs::<192>::zero()
16244 }
16245 }
16246 PrimitiveOp::Concat => Limbs::<192>::zero(),
16247 PrimitiveOp::Div => {
16248 if limbs_is_zero_192(b) {
16249 Limbs::<192>::zero()
16250 } else {
16251 limbs_div_192(a, b)
16252 }
16253 }
16254 PrimitiveOp::Mod => {
16255 if limbs_is_zero_192(b) {
16256 Limbs::<192>::zero()
16257 } else {
16258 limbs_mod_192(a, b)
16259 }
16260 }
16261 PrimitiveOp::Pow => limbs_pow_192(a, b),
16262 }
16263}
16264
16265#[inline]
16266#[must_use]
16267pub const fn const_ring_eval_w16384(op: PrimitiveOp, a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
16268 match op {
16269 PrimitiveOp::Add => a.wrapping_add(b),
16270 PrimitiveOp::Sub => a.wrapping_sub(b),
16271 PrimitiveOp::Mul => a.wrapping_mul(b),
16272 PrimitiveOp::And => a.and(b),
16273 PrimitiveOp::Or => a.or(b),
16274 PrimitiveOp::Xor => a.xor(b),
16275 PrimitiveOp::Neg => Limbs::<256>::zero().wrapping_sub(a),
16276 PrimitiveOp::Bnot => a.not(),
16277 PrimitiveOp::Succ => a.wrapping_add(limbs_one_256()),
16278 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_256()),
16279 PrimitiveOp::Le => {
16280 if limbs_le_256(a, b) {
16281 limbs_one_256()
16282 } else {
16283 Limbs::<256>::zero()
16284 }
16285 }
16286 PrimitiveOp::Lt => {
16287 if limbs_lt_256(a, b) {
16288 limbs_one_256()
16289 } else {
16290 Limbs::<256>::zero()
16291 }
16292 }
16293 PrimitiveOp::Ge => {
16294 if limbs_le_256(b, a) {
16295 limbs_one_256()
16296 } else {
16297 Limbs::<256>::zero()
16298 }
16299 }
16300 PrimitiveOp::Gt => {
16301 if limbs_lt_256(b, a) {
16302 limbs_one_256()
16303 } else {
16304 Limbs::<256>::zero()
16305 }
16306 }
16307 PrimitiveOp::Concat => Limbs::<256>::zero(),
16308 PrimitiveOp::Div => {
16309 if limbs_is_zero_256(b) {
16310 Limbs::<256>::zero()
16311 } else {
16312 limbs_div_256(a, b)
16313 }
16314 }
16315 PrimitiveOp::Mod => {
16316 if limbs_is_zero_256(b) {
16317 Limbs::<256>::zero()
16318 } else {
16319 limbs_mod_256(a, b)
16320 }
16321 }
16322 PrimitiveOp::Pow => limbs_pow_256(a, b),
16323 }
16324}
16325
16326#[inline]
16327#[must_use]
16328pub const fn const_ring_eval_w32768(op: PrimitiveOp, a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
16329 match op {
16330 PrimitiveOp::Add => a.wrapping_add(b),
16331 PrimitiveOp::Sub => a.wrapping_sub(b),
16332 PrimitiveOp::Mul => a.wrapping_mul(b),
16333 PrimitiveOp::And => a.and(b),
16334 PrimitiveOp::Or => a.or(b),
16335 PrimitiveOp::Xor => a.xor(b),
16336 PrimitiveOp::Neg => Limbs::<512>::zero().wrapping_sub(a),
16337 PrimitiveOp::Bnot => a.not(),
16338 PrimitiveOp::Succ => a.wrapping_add(limbs_one_512()),
16339 PrimitiveOp::Pred => a.wrapping_sub(limbs_one_512()),
16340 PrimitiveOp::Le => {
16341 if limbs_le_512(a, b) {
16342 limbs_one_512()
16343 } else {
16344 Limbs::<512>::zero()
16345 }
16346 }
16347 PrimitiveOp::Lt => {
16348 if limbs_lt_512(a, b) {
16349 limbs_one_512()
16350 } else {
16351 Limbs::<512>::zero()
16352 }
16353 }
16354 PrimitiveOp::Ge => {
16355 if limbs_le_512(b, a) {
16356 limbs_one_512()
16357 } else {
16358 Limbs::<512>::zero()
16359 }
16360 }
16361 PrimitiveOp::Gt => {
16362 if limbs_lt_512(b, a) {
16363 limbs_one_512()
16364 } else {
16365 Limbs::<512>::zero()
16366 }
16367 }
16368 PrimitiveOp::Concat => Limbs::<512>::zero(),
16369 PrimitiveOp::Div => {
16370 if limbs_is_zero_512(b) {
16371 Limbs::<512>::zero()
16372 } else {
16373 limbs_div_512(a, b)
16374 }
16375 }
16376 PrimitiveOp::Mod => {
16377 if limbs_is_zero_512(b) {
16378 Limbs::<512>::zero()
16379 } else {
16380 limbs_mod_512(a, b)
16381 }
16382 }
16383 PrimitiveOp::Pow => limbs_pow_512(a, b),
16384 }
16385}
16386
16387#[inline]
16389#[must_use]
16390const fn limbs_one_3() -> Limbs<3> {
16391 Limbs::<3>::from_words([1u64, 0u64, 0u64])
16392}
16393
16394#[inline]
16395#[must_use]
16396const fn limbs_one_4() -> Limbs<4> {
16397 Limbs::<4>::from_words([1u64, 0u64, 0u64, 0u64])
16398}
16399
16400#[inline]
16401#[must_use]
16402const fn limbs_one_6() -> Limbs<6> {
16403 Limbs::<6>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16404}
16405
16406#[inline]
16407#[must_use]
16408const fn limbs_one_7() -> Limbs<7> {
16409 Limbs::<7>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16410}
16411
16412#[inline]
16413#[must_use]
16414const fn limbs_one_8() -> Limbs<8> {
16415 Limbs::<8>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16416}
16417
16418#[inline]
16419#[must_use]
16420const fn limbs_one_9() -> Limbs<9> {
16421 Limbs::<9>::from_words([1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64])
16422}
16423
16424#[inline]
16425#[must_use]
16426const fn limbs_one_16() -> Limbs<16> {
16427 Limbs::<16>::from_words([
16428 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16429 0u64,
16430 ])
16431}
16432
16433#[inline]
16434#[must_use]
16435const fn limbs_one_32() -> Limbs<32> {
16436 Limbs::<32>::from_words([
16437 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16438 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16439 0u64, 0u64,
16440 ])
16441}
16442
16443#[inline]
16444#[must_use]
16445const fn limbs_one_64() -> Limbs<64> {
16446 Limbs::<64>::from_words([
16447 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16448 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16449 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16450 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16451 0u64, 0u64, 0u64, 0u64,
16452 ])
16453}
16454
16455#[inline]
16456#[must_use]
16457const fn limbs_one_128() -> Limbs<128> {
16458 Limbs::<128>::from_words([
16459 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16460 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16461 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16462 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16463 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16464 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16465 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16466 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16467 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16468 ])
16469}
16470
16471#[inline]
16472#[must_use]
16473const fn limbs_one_192() -> Limbs<192> {
16474 Limbs::<192>::from_words([
16475 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16476 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16477 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16478 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16479 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16480 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16481 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16482 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16483 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16484 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16485 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16486 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16487 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16488 ])
16489}
16490
16491#[inline]
16492#[must_use]
16493const fn limbs_one_256() -> Limbs<256> {
16494 Limbs::<256>::from_words([
16495 1u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16496 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16497 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16498 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16499 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16500 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16501 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16502 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16503 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16504 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16505 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16506 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16507 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16508 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16509 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16510 0u64, 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,
16513 ])
16514}
16515
16516#[inline]
16517#[must_use]
16518const fn limbs_one_512() -> Limbs<512> {
16519 Limbs::<512>::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, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16525 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16526 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16527 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16528 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16529 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16530 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16531 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16532 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16533 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 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, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16541 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16542 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16543 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16544 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16545 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16546 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16547 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16548 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16549 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16550 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16551 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16552 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16553 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64, 0u64,
16554 0u64, 0u64,
16555 ])
16556}
16557
16558#[inline]
16561#[must_use]
16562const fn limbs_lt_3(a: Limbs<3>, b: Limbs<3>) -> bool {
16563 let aw = a.words();
16564 let bw = b.words();
16565 let mut i = 3;
16566 while i > 0 {
16567 i -= 1;
16568 if aw[i] < bw[i] {
16569 return true;
16570 }
16571 if aw[i] > bw[i] {
16572 return false;
16573 }
16574 }
16575 false
16576}
16577
16578#[inline]
16579#[must_use]
16580const fn limbs_le_3(a: Limbs<3>, b: Limbs<3>) -> bool {
16581 let aw = a.words();
16582 let bw = b.words();
16583 let mut i = 3;
16584 while i > 0 {
16585 i -= 1;
16586 if aw[i] < bw[i] {
16587 return true;
16588 }
16589 if aw[i] > bw[i] {
16590 return false;
16591 }
16592 }
16593 true
16594}
16595
16596#[inline]
16597#[must_use]
16598const fn limbs_lt_4(a: Limbs<4>, b: Limbs<4>) -> bool {
16599 let aw = a.words();
16600 let bw = b.words();
16601 let mut i = 4;
16602 while i > 0 {
16603 i -= 1;
16604 if aw[i] < bw[i] {
16605 return true;
16606 }
16607 if aw[i] > bw[i] {
16608 return false;
16609 }
16610 }
16611 false
16612}
16613
16614#[inline]
16615#[must_use]
16616const fn limbs_le_4(a: Limbs<4>, b: Limbs<4>) -> bool {
16617 let aw = a.words();
16618 let bw = b.words();
16619 let mut i = 4;
16620 while i > 0 {
16621 i -= 1;
16622 if aw[i] < bw[i] {
16623 return true;
16624 }
16625 if aw[i] > bw[i] {
16626 return false;
16627 }
16628 }
16629 true
16630}
16631
16632#[inline]
16633#[must_use]
16634const fn limbs_lt_6(a: Limbs<6>, b: Limbs<6>) -> bool {
16635 let aw = a.words();
16636 let bw = b.words();
16637 let mut i = 6;
16638 while i > 0 {
16639 i -= 1;
16640 if aw[i] < bw[i] {
16641 return true;
16642 }
16643 if aw[i] > bw[i] {
16644 return false;
16645 }
16646 }
16647 false
16648}
16649
16650#[inline]
16651#[must_use]
16652const fn limbs_le_6(a: Limbs<6>, b: Limbs<6>) -> bool {
16653 let aw = a.words();
16654 let bw = b.words();
16655 let mut i = 6;
16656 while i > 0 {
16657 i -= 1;
16658 if aw[i] < bw[i] {
16659 return true;
16660 }
16661 if aw[i] > bw[i] {
16662 return false;
16663 }
16664 }
16665 true
16666}
16667
16668#[inline]
16669#[must_use]
16670const fn limbs_lt_7(a: Limbs<7>, b: Limbs<7>) -> bool {
16671 let aw = a.words();
16672 let bw = b.words();
16673 let mut i = 7;
16674 while i > 0 {
16675 i -= 1;
16676 if aw[i] < bw[i] {
16677 return true;
16678 }
16679 if aw[i] > bw[i] {
16680 return false;
16681 }
16682 }
16683 false
16684}
16685
16686#[inline]
16687#[must_use]
16688const fn limbs_le_7(a: Limbs<7>, b: Limbs<7>) -> bool {
16689 let aw = a.words();
16690 let bw = b.words();
16691 let mut i = 7;
16692 while i > 0 {
16693 i -= 1;
16694 if aw[i] < bw[i] {
16695 return true;
16696 }
16697 if aw[i] > bw[i] {
16698 return false;
16699 }
16700 }
16701 true
16702}
16703
16704#[inline]
16705#[must_use]
16706const fn limbs_lt_8(a: Limbs<8>, b: Limbs<8>) -> bool {
16707 let aw = a.words();
16708 let bw = b.words();
16709 let mut i = 8;
16710 while i > 0 {
16711 i -= 1;
16712 if aw[i] < bw[i] {
16713 return true;
16714 }
16715 if aw[i] > bw[i] {
16716 return false;
16717 }
16718 }
16719 false
16720}
16721
16722#[inline]
16723#[must_use]
16724const fn limbs_le_8(a: Limbs<8>, b: Limbs<8>) -> bool {
16725 let aw = a.words();
16726 let bw = b.words();
16727 let mut i = 8;
16728 while i > 0 {
16729 i -= 1;
16730 if aw[i] < bw[i] {
16731 return true;
16732 }
16733 if aw[i] > bw[i] {
16734 return false;
16735 }
16736 }
16737 true
16738}
16739
16740#[inline]
16741#[must_use]
16742const fn limbs_lt_9(a: Limbs<9>, b: Limbs<9>) -> bool {
16743 let aw = a.words();
16744 let bw = b.words();
16745 let mut i = 9;
16746 while i > 0 {
16747 i -= 1;
16748 if aw[i] < bw[i] {
16749 return true;
16750 }
16751 if aw[i] > bw[i] {
16752 return false;
16753 }
16754 }
16755 false
16756}
16757
16758#[inline]
16759#[must_use]
16760const fn limbs_le_9(a: Limbs<9>, b: Limbs<9>) -> bool {
16761 let aw = a.words();
16762 let bw = b.words();
16763 let mut i = 9;
16764 while i > 0 {
16765 i -= 1;
16766 if aw[i] < bw[i] {
16767 return true;
16768 }
16769 if aw[i] > bw[i] {
16770 return false;
16771 }
16772 }
16773 true
16774}
16775
16776#[inline]
16777#[must_use]
16778const fn limbs_lt_16(a: Limbs<16>, b: Limbs<16>) -> bool {
16779 let aw = a.words();
16780 let bw = b.words();
16781 let mut i = 16;
16782 while i > 0 {
16783 i -= 1;
16784 if aw[i] < bw[i] {
16785 return true;
16786 }
16787 if aw[i] > bw[i] {
16788 return false;
16789 }
16790 }
16791 false
16792}
16793
16794#[inline]
16795#[must_use]
16796const fn limbs_le_16(a: Limbs<16>, b: Limbs<16>) -> bool {
16797 let aw = a.words();
16798 let bw = b.words();
16799 let mut i = 16;
16800 while i > 0 {
16801 i -= 1;
16802 if aw[i] < bw[i] {
16803 return true;
16804 }
16805 if aw[i] > bw[i] {
16806 return false;
16807 }
16808 }
16809 true
16810}
16811
16812#[inline]
16813#[must_use]
16814const fn limbs_lt_32(a: Limbs<32>, b: Limbs<32>) -> bool {
16815 let aw = a.words();
16816 let bw = b.words();
16817 let mut i = 32;
16818 while i > 0 {
16819 i -= 1;
16820 if aw[i] < bw[i] {
16821 return true;
16822 }
16823 if aw[i] > bw[i] {
16824 return false;
16825 }
16826 }
16827 false
16828}
16829
16830#[inline]
16831#[must_use]
16832const fn limbs_le_32(a: Limbs<32>, b: Limbs<32>) -> bool {
16833 let aw = a.words();
16834 let bw = b.words();
16835 let mut i = 32;
16836 while i > 0 {
16837 i -= 1;
16838 if aw[i] < bw[i] {
16839 return true;
16840 }
16841 if aw[i] > bw[i] {
16842 return false;
16843 }
16844 }
16845 true
16846}
16847
16848#[inline]
16849#[must_use]
16850const fn limbs_lt_64(a: Limbs<64>, b: Limbs<64>) -> bool {
16851 let aw = a.words();
16852 let bw = b.words();
16853 let mut i = 64;
16854 while i > 0 {
16855 i -= 1;
16856 if aw[i] < bw[i] {
16857 return true;
16858 }
16859 if aw[i] > bw[i] {
16860 return false;
16861 }
16862 }
16863 false
16864}
16865
16866#[inline]
16867#[must_use]
16868const fn limbs_le_64(a: Limbs<64>, b: Limbs<64>) -> bool {
16869 let aw = a.words();
16870 let bw = b.words();
16871 let mut i = 64;
16872 while i > 0 {
16873 i -= 1;
16874 if aw[i] < bw[i] {
16875 return true;
16876 }
16877 if aw[i] > bw[i] {
16878 return false;
16879 }
16880 }
16881 true
16882}
16883
16884#[inline]
16885#[must_use]
16886const fn limbs_lt_128(a: Limbs<128>, b: Limbs<128>) -> bool {
16887 let aw = a.words();
16888 let bw = b.words();
16889 let mut i = 128;
16890 while i > 0 {
16891 i -= 1;
16892 if aw[i] < bw[i] {
16893 return true;
16894 }
16895 if aw[i] > bw[i] {
16896 return false;
16897 }
16898 }
16899 false
16900}
16901
16902#[inline]
16903#[must_use]
16904const fn limbs_le_128(a: Limbs<128>, b: Limbs<128>) -> bool {
16905 let aw = a.words();
16906 let bw = b.words();
16907 let mut i = 128;
16908 while i > 0 {
16909 i -= 1;
16910 if aw[i] < bw[i] {
16911 return true;
16912 }
16913 if aw[i] > bw[i] {
16914 return false;
16915 }
16916 }
16917 true
16918}
16919
16920#[inline]
16921#[must_use]
16922const fn limbs_lt_192(a: Limbs<192>, b: Limbs<192>) -> bool {
16923 let aw = a.words();
16924 let bw = b.words();
16925 let mut i = 192;
16926 while i > 0 {
16927 i -= 1;
16928 if aw[i] < bw[i] {
16929 return true;
16930 }
16931 if aw[i] > bw[i] {
16932 return false;
16933 }
16934 }
16935 false
16936}
16937
16938#[inline]
16939#[must_use]
16940const fn limbs_le_192(a: Limbs<192>, b: Limbs<192>) -> bool {
16941 let aw = a.words();
16942 let bw = b.words();
16943 let mut i = 192;
16944 while i > 0 {
16945 i -= 1;
16946 if aw[i] < bw[i] {
16947 return true;
16948 }
16949 if aw[i] > bw[i] {
16950 return false;
16951 }
16952 }
16953 true
16954}
16955
16956#[inline]
16957#[must_use]
16958const fn limbs_lt_256(a: Limbs<256>, b: Limbs<256>) -> bool {
16959 let aw = a.words();
16960 let bw = b.words();
16961 let mut i = 256;
16962 while i > 0 {
16963 i -= 1;
16964 if aw[i] < bw[i] {
16965 return true;
16966 }
16967 if aw[i] > bw[i] {
16968 return false;
16969 }
16970 }
16971 false
16972}
16973
16974#[inline]
16975#[must_use]
16976const fn limbs_le_256(a: Limbs<256>, b: Limbs<256>) -> bool {
16977 let aw = a.words();
16978 let bw = b.words();
16979 let mut i = 256;
16980 while i > 0 {
16981 i -= 1;
16982 if aw[i] < bw[i] {
16983 return true;
16984 }
16985 if aw[i] > bw[i] {
16986 return false;
16987 }
16988 }
16989 true
16990}
16991
16992#[inline]
16993#[must_use]
16994const fn limbs_lt_512(a: Limbs<512>, b: Limbs<512>) -> bool {
16995 let aw = a.words();
16996 let bw = b.words();
16997 let mut i = 512;
16998 while i > 0 {
16999 i -= 1;
17000 if aw[i] < bw[i] {
17001 return true;
17002 }
17003 if aw[i] > bw[i] {
17004 return false;
17005 }
17006 }
17007 false
17008}
17009
17010#[inline]
17011#[must_use]
17012const fn limbs_le_512(a: Limbs<512>, b: Limbs<512>) -> bool {
17013 let aw = a.words();
17014 let bw = b.words();
17015 let mut i = 512;
17016 while i > 0 {
17017 i -= 1;
17018 if aw[i] < bw[i] {
17019 return true;
17020 }
17021 if aw[i] > bw[i] {
17022 return false;
17023 }
17024 }
17025 true
17026}
17027
17028#[inline]
17031#[must_use]
17032const fn limbs_is_zero_3(a: Limbs<3>) -> bool {
17033 let aw = a.words();
17034 let mut i = 0usize;
17035 while i < 3 {
17036 if aw[i] != 0 {
17037 return false;
17038 }
17039 i += 1;
17040 }
17041 true
17042}
17043
17044#[inline]
17045#[must_use]
17046const fn limbs_shl1_3(a: Limbs<3>) -> Limbs<3> {
17047 let aw = a.words();
17048 let mut out = [0u64; 3];
17049 let mut carry: u64 = 0;
17050 let mut i = 0usize;
17051 while i < 3 {
17052 let v = aw[i];
17053 out[i] = (v << 1) | carry;
17054 carry = v >> 63;
17055 i += 1;
17056 }
17057 Limbs::<3>::from_words(out)
17058}
17059
17060#[inline]
17061#[must_use]
17062const fn limbs_set_bit0_3(a: Limbs<3>) -> Limbs<3> {
17063 let aw = a.words();
17064 let mut out = [0u64; 3];
17065 let mut i = 0usize;
17066 while i < 3 {
17067 out[i] = aw[i];
17068 i += 1;
17069 }
17070 out[0] |= 1u64;
17071 Limbs::<3>::from_words(out)
17072}
17073
17074#[inline]
17075#[must_use]
17076const fn limbs_bit_msb_3(a: Limbs<3>, msb_index: usize) -> u64 {
17077 let aw = a.words();
17078 let total_bits = 3 * 64;
17079 let lsb_index = total_bits - 1 - msb_index;
17080 let word = lsb_index / 64;
17081 let bit = lsb_index % 64;
17082 (aw[word] >> bit) & 1u64
17083}
17084
17085#[inline]
17086#[must_use]
17087const fn limbs_divmod_3(a: Limbs<3>, b: Limbs<3>) -> (Limbs<3>, Limbs<3>) {
17088 let mut q = Limbs::<3>::zero();
17089 let mut r = Limbs::<3>::zero();
17090 let total_bits = 3 * 64;
17091 let mut i = 0usize;
17092 while i < total_bits {
17093 r = limbs_shl1_3(r);
17094 if limbs_bit_msb_3(a, i) == 1 {
17095 r = limbs_set_bit0_3(r);
17096 }
17097 if limbs_le_3(b, r) {
17098 r = r.wrapping_sub(b);
17099 q = limbs_shl1_3(q);
17100 q = limbs_set_bit0_3(q);
17101 } else {
17102 q = limbs_shl1_3(q);
17103 }
17104 i += 1;
17105 }
17106 (q, r)
17107}
17108
17109#[inline]
17110#[must_use]
17111const fn limbs_div_3(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
17112 let (q, _) = limbs_divmod_3(a, b);
17113 q
17114}
17115
17116#[inline]
17117#[must_use]
17118const fn limbs_mod_3(a: Limbs<3>, b: Limbs<3>) -> Limbs<3> {
17119 let (_, r) = limbs_divmod_3(a, b);
17120 r
17121}
17122
17123#[inline]
17124#[must_use]
17125const fn limbs_pow_3(base: Limbs<3>, exp: Limbs<3>) -> Limbs<3> {
17126 let mut result = limbs_one_3();
17127 let mut b = base;
17128 let ew = exp.words();
17129 let mut word = 0usize;
17130 while word < 3 {
17131 let mut bit = 0u32;
17132 while bit < 64 {
17133 if ((ew[word] >> bit) & 1u64) == 1u64 {
17134 result = result.wrapping_mul(b);
17135 }
17136 b = b.wrapping_mul(b);
17137 bit += 1;
17138 }
17139 word += 1;
17140 }
17141 result
17142}
17143
17144#[inline]
17145#[must_use]
17146const fn limbs_is_zero_4(a: Limbs<4>) -> bool {
17147 let aw = a.words();
17148 let mut i = 0usize;
17149 while i < 4 {
17150 if aw[i] != 0 {
17151 return false;
17152 }
17153 i += 1;
17154 }
17155 true
17156}
17157
17158#[inline]
17159#[must_use]
17160const fn limbs_shl1_4(a: Limbs<4>) -> Limbs<4> {
17161 let aw = a.words();
17162 let mut out = [0u64; 4];
17163 let mut carry: u64 = 0;
17164 let mut i = 0usize;
17165 while i < 4 {
17166 let v = aw[i];
17167 out[i] = (v << 1) | carry;
17168 carry = v >> 63;
17169 i += 1;
17170 }
17171 Limbs::<4>::from_words(out)
17172}
17173
17174#[inline]
17175#[must_use]
17176const fn limbs_set_bit0_4(a: Limbs<4>) -> Limbs<4> {
17177 let aw = a.words();
17178 let mut out = [0u64; 4];
17179 let mut i = 0usize;
17180 while i < 4 {
17181 out[i] = aw[i];
17182 i += 1;
17183 }
17184 out[0] |= 1u64;
17185 Limbs::<4>::from_words(out)
17186}
17187
17188#[inline]
17189#[must_use]
17190const fn limbs_bit_msb_4(a: Limbs<4>, msb_index: usize) -> u64 {
17191 let aw = a.words();
17192 let total_bits = 4 * 64;
17193 let lsb_index = total_bits - 1 - msb_index;
17194 let word = lsb_index / 64;
17195 let bit = lsb_index % 64;
17196 (aw[word] >> bit) & 1u64
17197}
17198
17199#[inline]
17200#[must_use]
17201const fn limbs_divmod_4(a: Limbs<4>, b: Limbs<4>) -> (Limbs<4>, Limbs<4>) {
17202 let mut q = Limbs::<4>::zero();
17203 let mut r = Limbs::<4>::zero();
17204 let total_bits = 4 * 64;
17205 let mut i = 0usize;
17206 while i < total_bits {
17207 r = limbs_shl1_4(r);
17208 if limbs_bit_msb_4(a, i) == 1 {
17209 r = limbs_set_bit0_4(r);
17210 }
17211 if limbs_le_4(b, r) {
17212 r = r.wrapping_sub(b);
17213 q = limbs_shl1_4(q);
17214 q = limbs_set_bit0_4(q);
17215 } else {
17216 q = limbs_shl1_4(q);
17217 }
17218 i += 1;
17219 }
17220 (q, r)
17221}
17222
17223#[inline]
17224#[must_use]
17225const fn limbs_div_4(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
17226 let (q, _) = limbs_divmod_4(a, b);
17227 q
17228}
17229
17230#[inline]
17231#[must_use]
17232const fn limbs_mod_4(a: Limbs<4>, b: Limbs<4>) -> Limbs<4> {
17233 let (_, r) = limbs_divmod_4(a, b);
17234 r
17235}
17236
17237#[inline]
17238#[must_use]
17239const fn limbs_pow_4(base: Limbs<4>, exp: Limbs<4>) -> Limbs<4> {
17240 let mut result = limbs_one_4();
17241 let mut b = base;
17242 let ew = exp.words();
17243 let mut word = 0usize;
17244 while word < 4 {
17245 let mut bit = 0u32;
17246 while bit < 64 {
17247 if ((ew[word] >> bit) & 1u64) == 1u64 {
17248 result = result.wrapping_mul(b);
17249 }
17250 b = b.wrapping_mul(b);
17251 bit += 1;
17252 }
17253 word += 1;
17254 }
17255 result
17256}
17257
17258#[inline]
17259#[must_use]
17260const fn limbs_is_zero_6(a: Limbs<6>) -> bool {
17261 let aw = a.words();
17262 let mut i = 0usize;
17263 while i < 6 {
17264 if aw[i] != 0 {
17265 return false;
17266 }
17267 i += 1;
17268 }
17269 true
17270}
17271
17272#[inline]
17273#[must_use]
17274const fn limbs_shl1_6(a: Limbs<6>) -> Limbs<6> {
17275 let aw = a.words();
17276 let mut out = [0u64; 6];
17277 let mut carry: u64 = 0;
17278 let mut i = 0usize;
17279 while i < 6 {
17280 let v = aw[i];
17281 out[i] = (v << 1) | carry;
17282 carry = v >> 63;
17283 i += 1;
17284 }
17285 Limbs::<6>::from_words(out)
17286}
17287
17288#[inline]
17289#[must_use]
17290const fn limbs_set_bit0_6(a: Limbs<6>) -> Limbs<6> {
17291 let aw = a.words();
17292 let mut out = [0u64; 6];
17293 let mut i = 0usize;
17294 while i < 6 {
17295 out[i] = aw[i];
17296 i += 1;
17297 }
17298 out[0] |= 1u64;
17299 Limbs::<6>::from_words(out)
17300}
17301
17302#[inline]
17303#[must_use]
17304const fn limbs_bit_msb_6(a: Limbs<6>, msb_index: usize) -> u64 {
17305 let aw = a.words();
17306 let total_bits = 6 * 64;
17307 let lsb_index = total_bits - 1 - msb_index;
17308 let word = lsb_index / 64;
17309 let bit = lsb_index % 64;
17310 (aw[word] >> bit) & 1u64
17311}
17312
17313#[inline]
17314#[must_use]
17315const fn limbs_divmod_6(a: Limbs<6>, b: Limbs<6>) -> (Limbs<6>, Limbs<6>) {
17316 let mut q = Limbs::<6>::zero();
17317 let mut r = Limbs::<6>::zero();
17318 let total_bits = 6 * 64;
17319 let mut i = 0usize;
17320 while i < total_bits {
17321 r = limbs_shl1_6(r);
17322 if limbs_bit_msb_6(a, i) == 1 {
17323 r = limbs_set_bit0_6(r);
17324 }
17325 if limbs_le_6(b, r) {
17326 r = r.wrapping_sub(b);
17327 q = limbs_shl1_6(q);
17328 q = limbs_set_bit0_6(q);
17329 } else {
17330 q = limbs_shl1_6(q);
17331 }
17332 i += 1;
17333 }
17334 (q, r)
17335}
17336
17337#[inline]
17338#[must_use]
17339const fn limbs_div_6(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
17340 let (q, _) = limbs_divmod_6(a, b);
17341 q
17342}
17343
17344#[inline]
17345#[must_use]
17346const fn limbs_mod_6(a: Limbs<6>, b: Limbs<6>) -> Limbs<6> {
17347 let (_, r) = limbs_divmod_6(a, b);
17348 r
17349}
17350
17351#[inline]
17352#[must_use]
17353const fn limbs_pow_6(base: Limbs<6>, exp: Limbs<6>) -> Limbs<6> {
17354 let mut result = limbs_one_6();
17355 let mut b = base;
17356 let ew = exp.words();
17357 let mut word = 0usize;
17358 while word < 6 {
17359 let mut bit = 0u32;
17360 while bit < 64 {
17361 if ((ew[word] >> bit) & 1u64) == 1u64 {
17362 result = result.wrapping_mul(b);
17363 }
17364 b = b.wrapping_mul(b);
17365 bit += 1;
17366 }
17367 word += 1;
17368 }
17369 result
17370}
17371
17372#[inline]
17373#[must_use]
17374const fn limbs_is_zero_7(a: Limbs<7>) -> bool {
17375 let aw = a.words();
17376 let mut i = 0usize;
17377 while i < 7 {
17378 if aw[i] != 0 {
17379 return false;
17380 }
17381 i += 1;
17382 }
17383 true
17384}
17385
17386#[inline]
17387#[must_use]
17388const fn limbs_shl1_7(a: Limbs<7>) -> Limbs<7> {
17389 let aw = a.words();
17390 let mut out = [0u64; 7];
17391 let mut carry: u64 = 0;
17392 let mut i = 0usize;
17393 while i < 7 {
17394 let v = aw[i];
17395 out[i] = (v << 1) | carry;
17396 carry = v >> 63;
17397 i += 1;
17398 }
17399 Limbs::<7>::from_words(out)
17400}
17401
17402#[inline]
17403#[must_use]
17404const fn limbs_set_bit0_7(a: Limbs<7>) -> Limbs<7> {
17405 let aw = a.words();
17406 let mut out = [0u64; 7];
17407 let mut i = 0usize;
17408 while i < 7 {
17409 out[i] = aw[i];
17410 i += 1;
17411 }
17412 out[0] |= 1u64;
17413 Limbs::<7>::from_words(out)
17414}
17415
17416#[inline]
17417#[must_use]
17418const fn limbs_bit_msb_7(a: Limbs<7>, msb_index: usize) -> u64 {
17419 let aw = a.words();
17420 let total_bits = 7 * 64;
17421 let lsb_index = total_bits - 1 - msb_index;
17422 let word = lsb_index / 64;
17423 let bit = lsb_index % 64;
17424 (aw[word] >> bit) & 1u64
17425}
17426
17427#[inline]
17428#[must_use]
17429const fn limbs_divmod_7(a: Limbs<7>, b: Limbs<7>) -> (Limbs<7>, Limbs<7>) {
17430 let mut q = Limbs::<7>::zero();
17431 let mut r = Limbs::<7>::zero();
17432 let total_bits = 7 * 64;
17433 let mut i = 0usize;
17434 while i < total_bits {
17435 r = limbs_shl1_7(r);
17436 if limbs_bit_msb_7(a, i) == 1 {
17437 r = limbs_set_bit0_7(r);
17438 }
17439 if limbs_le_7(b, r) {
17440 r = r.wrapping_sub(b);
17441 q = limbs_shl1_7(q);
17442 q = limbs_set_bit0_7(q);
17443 } else {
17444 q = limbs_shl1_7(q);
17445 }
17446 i += 1;
17447 }
17448 (q, r)
17449}
17450
17451#[inline]
17452#[must_use]
17453const fn limbs_div_7(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
17454 let (q, _) = limbs_divmod_7(a, b);
17455 q
17456}
17457
17458#[inline]
17459#[must_use]
17460const fn limbs_mod_7(a: Limbs<7>, b: Limbs<7>) -> Limbs<7> {
17461 let (_, r) = limbs_divmod_7(a, b);
17462 r
17463}
17464
17465#[inline]
17466#[must_use]
17467const fn limbs_pow_7(base: Limbs<7>, exp: Limbs<7>) -> Limbs<7> {
17468 let mut result = limbs_one_7();
17469 let mut b = base;
17470 let ew = exp.words();
17471 let mut word = 0usize;
17472 while word < 7 {
17473 let mut bit = 0u32;
17474 while bit < 64 {
17475 if ((ew[word] >> bit) & 1u64) == 1u64 {
17476 result = result.wrapping_mul(b);
17477 }
17478 b = b.wrapping_mul(b);
17479 bit += 1;
17480 }
17481 word += 1;
17482 }
17483 result
17484}
17485
17486#[inline]
17487#[must_use]
17488const fn limbs_is_zero_8(a: Limbs<8>) -> bool {
17489 let aw = a.words();
17490 let mut i = 0usize;
17491 while i < 8 {
17492 if aw[i] != 0 {
17493 return false;
17494 }
17495 i += 1;
17496 }
17497 true
17498}
17499
17500#[inline]
17501#[must_use]
17502const fn limbs_shl1_8(a: Limbs<8>) -> Limbs<8> {
17503 let aw = a.words();
17504 let mut out = [0u64; 8];
17505 let mut carry: u64 = 0;
17506 let mut i = 0usize;
17507 while i < 8 {
17508 let v = aw[i];
17509 out[i] = (v << 1) | carry;
17510 carry = v >> 63;
17511 i += 1;
17512 }
17513 Limbs::<8>::from_words(out)
17514}
17515
17516#[inline]
17517#[must_use]
17518const fn limbs_set_bit0_8(a: Limbs<8>) -> Limbs<8> {
17519 let aw = a.words();
17520 let mut out = [0u64; 8];
17521 let mut i = 0usize;
17522 while i < 8 {
17523 out[i] = aw[i];
17524 i += 1;
17525 }
17526 out[0] |= 1u64;
17527 Limbs::<8>::from_words(out)
17528}
17529
17530#[inline]
17531#[must_use]
17532const fn limbs_bit_msb_8(a: Limbs<8>, msb_index: usize) -> u64 {
17533 let aw = a.words();
17534 let total_bits = 8 * 64;
17535 let lsb_index = total_bits - 1 - msb_index;
17536 let word = lsb_index / 64;
17537 let bit = lsb_index % 64;
17538 (aw[word] >> bit) & 1u64
17539}
17540
17541#[inline]
17542#[must_use]
17543const fn limbs_divmod_8(a: Limbs<8>, b: Limbs<8>) -> (Limbs<8>, Limbs<8>) {
17544 let mut q = Limbs::<8>::zero();
17545 let mut r = Limbs::<8>::zero();
17546 let total_bits = 8 * 64;
17547 let mut i = 0usize;
17548 while i < total_bits {
17549 r = limbs_shl1_8(r);
17550 if limbs_bit_msb_8(a, i) == 1 {
17551 r = limbs_set_bit0_8(r);
17552 }
17553 if limbs_le_8(b, r) {
17554 r = r.wrapping_sub(b);
17555 q = limbs_shl1_8(q);
17556 q = limbs_set_bit0_8(q);
17557 } else {
17558 q = limbs_shl1_8(q);
17559 }
17560 i += 1;
17561 }
17562 (q, r)
17563}
17564
17565#[inline]
17566#[must_use]
17567const fn limbs_div_8(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
17568 let (q, _) = limbs_divmod_8(a, b);
17569 q
17570}
17571
17572#[inline]
17573#[must_use]
17574const fn limbs_mod_8(a: Limbs<8>, b: Limbs<8>) -> Limbs<8> {
17575 let (_, r) = limbs_divmod_8(a, b);
17576 r
17577}
17578
17579#[inline]
17580#[must_use]
17581const fn limbs_pow_8(base: Limbs<8>, exp: Limbs<8>) -> Limbs<8> {
17582 let mut result = limbs_one_8();
17583 let mut b = base;
17584 let ew = exp.words();
17585 let mut word = 0usize;
17586 while word < 8 {
17587 let mut bit = 0u32;
17588 while bit < 64 {
17589 if ((ew[word] >> bit) & 1u64) == 1u64 {
17590 result = result.wrapping_mul(b);
17591 }
17592 b = b.wrapping_mul(b);
17593 bit += 1;
17594 }
17595 word += 1;
17596 }
17597 result
17598}
17599
17600#[inline]
17601#[must_use]
17602const fn limbs_is_zero_9(a: Limbs<9>) -> bool {
17603 let aw = a.words();
17604 let mut i = 0usize;
17605 while i < 9 {
17606 if aw[i] != 0 {
17607 return false;
17608 }
17609 i += 1;
17610 }
17611 true
17612}
17613
17614#[inline]
17615#[must_use]
17616const fn limbs_shl1_9(a: Limbs<9>) -> Limbs<9> {
17617 let aw = a.words();
17618 let mut out = [0u64; 9];
17619 let mut carry: u64 = 0;
17620 let mut i = 0usize;
17621 while i < 9 {
17622 let v = aw[i];
17623 out[i] = (v << 1) | carry;
17624 carry = v >> 63;
17625 i += 1;
17626 }
17627 Limbs::<9>::from_words(out)
17628}
17629
17630#[inline]
17631#[must_use]
17632const fn limbs_set_bit0_9(a: Limbs<9>) -> Limbs<9> {
17633 let aw = a.words();
17634 let mut out = [0u64; 9];
17635 let mut i = 0usize;
17636 while i < 9 {
17637 out[i] = aw[i];
17638 i += 1;
17639 }
17640 out[0] |= 1u64;
17641 Limbs::<9>::from_words(out)
17642}
17643
17644#[inline]
17645#[must_use]
17646const fn limbs_bit_msb_9(a: Limbs<9>, msb_index: usize) -> u64 {
17647 let aw = a.words();
17648 let total_bits = 9 * 64;
17649 let lsb_index = total_bits - 1 - msb_index;
17650 let word = lsb_index / 64;
17651 let bit = lsb_index % 64;
17652 (aw[word] >> bit) & 1u64
17653}
17654
17655#[inline]
17656#[must_use]
17657const fn limbs_divmod_9(a: Limbs<9>, b: Limbs<9>) -> (Limbs<9>, Limbs<9>) {
17658 let mut q = Limbs::<9>::zero();
17659 let mut r = Limbs::<9>::zero();
17660 let total_bits = 9 * 64;
17661 let mut i = 0usize;
17662 while i < total_bits {
17663 r = limbs_shl1_9(r);
17664 if limbs_bit_msb_9(a, i) == 1 {
17665 r = limbs_set_bit0_9(r);
17666 }
17667 if limbs_le_9(b, r) {
17668 r = r.wrapping_sub(b);
17669 q = limbs_shl1_9(q);
17670 q = limbs_set_bit0_9(q);
17671 } else {
17672 q = limbs_shl1_9(q);
17673 }
17674 i += 1;
17675 }
17676 (q, r)
17677}
17678
17679#[inline]
17680#[must_use]
17681const fn limbs_div_9(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
17682 let (q, _) = limbs_divmod_9(a, b);
17683 q
17684}
17685
17686#[inline]
17687#[must_use]
17688const fn limbs_mod_9(a: Limbs<9>, b: Limbs<9>) -> Limbs<9> {
17689 let (_, r) = limbs_divmod_9(a, b);
17690 r
17691}
17692
17693#[inline]
17694#[must_use]
17695const fn limbs_pow_9(base: Limbs<9>, exp: Limbs<9>) -> Limbs<9> {
17696 let mut result = limbs_one_9();
17697 let mut b = base;
17698 let ew = exp.words();
17699 let mut word = 0usize;
17700 while word < 9 {
17701 let mut bit = 0u32;
17702 while bit < 64 {
17703 if ((ew[word] >> bit) & 1u64) == 1u64 {
17704 result = result.wrapping_mul(b);
17705 }
17706 b = b.wrapping_mul(b);
17707 bit += 1;
17708 }
17709 word += 1;
17710 }
17711 result
17712}
17713
17714#[inline]
17715#[must_use]
17716const fn limbs_is_zero_16(a: Limbs<16>) -> bool {
17717 let aw = a.words();
17718 let mut i = 0usize;
17719 while i < 16 {
17720 if aw[i] != 0 {
17721 return false;
17722 }
17723 i += 1;
17724 }
17725 true
17726}
17727
17728#[inline]
17729#[must_use]
17730const fn limbs_shl1_16(a: Limbs<16>) -> Limbs<16> {
17731 let aw = a.words();
17732 let mut out = [0u64; 16];
17733 let mut carry: u64 = 0;
17734 let mut i = 0usize;
17735 while i < 16 {
17736 let v = aw[i];
17737 out[i] = (v << 1) | carry;
17738 carry = v >> 63;
17739 i += 1;
17740 }
17741 Limbs::<16>::from_words(out)
17742}
17743
17744#[inline]
17745#[must_use]
17746const fn limbs_set_bit0_16(a: Limbs<16>) -> Limbs<16> {
17747 let aw = a.words();
17748 let mut out = [0u64; 16];
17749 let mut i = 0usize;
17750 while i < 16 {
17751 out[i] = aw[i];
17752 i += 1;
17753 }
17754 out[0] |= 1u64;
17755 Limbs::<16>::from_words(out)
17756}
17757
17758#[inline]
17759#[must_use]
17760const fn limbs_bit_msb_16(a: Limbs<16>, msb_index: usize) -> u64 {
17761 let aw = a.words();
17762 let total_bits = 16 * 64;
17763 let lsb_index = total_bits - 1 - msb_index;
17764 let word = lsb_index / 64;
17765 let bit = lsb_index % 64;
17766 (aw[word] >> bit) & 1u64
17767}
17768
17769#[inline]
17770#[must_use]
17771const fn limbs_divmod_16(a: Limbs<16>, b: Limbs<16>) -> (Limbs<16>, Limbs<16>) {
17772 let mut q = Limbs::<16>::zero();
17773 let mut r = Limbs::<16>::zero();
17774 let total_bits = 16 * 64;
17775 let mut i = 0usize;
17776 while i < total_bits {
17777 r = limbs_shl1_16(r);
17778 if limbs_bit_msb_16(a, i) == 1 {
17779 r = limbs_set_bit0_16(r);
17780 }
17781 if limbs_le_16(b, r) {
17782 r = r.wrapping_sub(b);
17783 q = limbs_shl1_16(q);
17784 q = limbs_set_bit0_16(q);
17785 } else {
17786 q = limbs_shl1_16(q);
17787 }
17788 i += 1;
17789 }
17790 (q, r)
17791}
17792
17793#[inline]
17794#[must_use]
17795const fn limbs_div_16(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
17796 let (q, _) = limbs_divmod_16(a, b);
17797 q
17798}
17799
17800#[inline]
17801#[must_use]
17802const fn limbs_mod_16(a: Limbs<16>, b: Limbs<16>) -> Limbs<16> {
17803 let (_, r) = limbs_divmod_16(a, b);
17804 r
17805}
17806
17807#[inline]
17808#[must_use]
17809const fn limbs_pow_16(base: Limbs<16>, exp: Limbs<16>) -> Limbs<16> {
17810 let mut result = limbs_one_16();
17811 let mut b = base;
17812 let ew = exp.words();
17813 let mut word = 0usize;
17814 while word < 16 {
17815 let mut bit = 0u32;
17816 while bit < 64 {
17817 if ((ew[word] >> bit) & 1u64) == 1u64 {
17818 result = result.wrapping_mul(b);
17819 }
17820 b = b.wrapping_mul(b);
17821 bit += 1;
17822 }
17823 word += 1;
17824 }
17825 result
17826}
17827
17828#[inline]
17829#[must_use]
17830const fn limbs_is_zero_32(a: Limbs<32>) -> bool {
17831 let aw = a.words();
17832 let mut i = 0usize;
17833 while i < 32 {
17834 if aw[i] != 0 {
17835 return false;
17836 }
17837 i += 1;
17838 }
17839 true
17840}
17841
17842#[inline]
17843#[must_use]
17844const fn limbs_shl1_32(a: Limbs<32>) -> Limbs<32> {
17845 let aw = a.words();
17846 let mut out = [0u64; 32];
17847 let mut carry: u64 = 0;
17848 let mut i = 0usize;
17849 while i < 32 {
17850 let v = aw[i];
17851 out[i] = (v << 1) | carry;
17852 carry = v >> 63;
17853 i += 1;
17854 }
17855 Limbs::<32>::from_words(out)
17856}
17857
17858#[inline]
17859#[must_use]
17860const fn limbs_set_bit0_32(a: Limbs<32>) -> Limbs<32> {
17861 let aw = a.words();
17862 let mut out = [0u64; 32];
17863 let mut i = 0usize;
17864 while i < 32 {
17865 out[i] = aw[i];
17866 i += 1;
17867 }
17868 out[0] |= 1u64;
17869 Limbs::<32>::from_words(out)
17870}
17871
17872#[inline]
17873#[must_use]
17874const fn limbs_bit_msb_32(a: Limbs<32>, msb_index: usize) -> u64 {
17875 let aw = a.words();
17876 let total_bits = 32 * 64;
17877 let lsb_index = total_bits - 1 - msb_index;
17878 let word = lsb_index / 64;
17879 let bit = lsb_index % 64;
17880 (aw[word] >> bit) & 1u64
17881}
17882
17883#[inline]
17884#[must_use]
17885const fn limbs_divmod_32(a: Limbs<32>, b: Limbs<32>) -> (Limbs<32>, Limbs<32>) {
17886 let mut q = Limbs::<32>::zero();
17887 let mut r = Limbs::<32>::zero();
17888 let total_bits = 32 * 64;
17889 let mut i = 0usize;
17890 while i < total_bits {
17891 r = limbs_shl1_32(r);
17892 if limbs_bit_msb_32(a, i) == 1 {
17893 r = limbs_set_bit0_32(r);
17894 }
17895 if limbs_le_32(b, r) {
17896 r = r.wrapping_sub(b);
17897 q = limbs_shl1_32(q);
17898 q = limbs_set_bit0_32(q);
17899 } else {
17900 q = limbs_shl1_32(q);
17901 }
17902 i += 1;
17903 }
17904 (q, r)
17905}
17906
17907#[inline]
17908#[must_use]
17909const fn limbs_div_32(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
17910 let (q, _) = limbs_divmod_32(a, b);
17911 q
17912}
17913
17914#[inline]
17915#[must_use]
17916const fn limbs_mod_32(a: Limbs<32>, b: Limbs<32>) -> Limbs<32> {
17917 let (_, r) = limbs_divmod_32(a, b);
17918 r
17919}
17920
17921#[inline]
17922#[must_use]
17923const fn limbs_pow_32(base: Limbs<32>, exp: Limbs<32>) -> Limbs<32> {
17924 let mut result = limbs_one_32();
17925 let mut b = base;
17926 let ew = exp.words();
17927 let mut word = 0usize;
17928 while word < 32 {
17929 let mut bit = 0u32;
17930 while bit < 64 {
17931 if ((ew[word] >> bit) & 1u64) == 1u64 {
17932 result = result.wrapping_mul(b);
17933 }
17934 b = b.wrapping_mul(b);
17935 bit += 1;
17936 }
17937 word += 1;
17938 }
17939 result
17940}
17941
17942#[inline]
17943#[must_use]
17944const fn limbs_is_zero_64(a: Limbs<64>) -> bool {
17945 let aw = a.words();
17946 let mut i = 0usize;
17947 while i < 64 {
17948 if aw[i] != 0 {
17949 return false;
17950 }
17951 i += 1;
17952 }
17953 true
17954}
17955
17956#[inline]
17957#[must_use]
17958const fn limbs_shl1_64(a: Limbs<64>) -> Limbs<64> {
17959 let aw = a.words();
17960 let mut out = [0u64; 64];
17961 let mut carry: u64 = 0;
17962 let mut i = 0usize;
17963 while i < 64 {
17964 let v = aw[i];
17965 out[i] = (v << 1) | carry;
17966 carry = v >> 63;
17967 i += 1;
17968 }
17969 Limbs::<64>::from_words(out)
17970}
17971
17972#[inline]
17973#[must_use]
17974const fn limbs_set_bit0_64(a: Limbs<64>) -> Limbs<64> {
17975 let aw = a.words();
17976 let mut out = [0u64; 64];
17977 let mut i = 0usize;
17978 while i < 64 {
17979 out[i] = aw[i];
17980 i += 1;
17981 }
17982 out[0] |= 1u64;
17983 Limbs::<64>::from_words(out)
17984}
17985
17986#[inline]
17987#[must_use]
17988const fn limbs_bit_msb_64(a: Limbs<64>, msb_index: usize) -> u64 {
17989 let aw = a.words();
17990 let total_bits = 64 * 64;
17991 let lsb_index = total_bits - 1 - msb_index;
17992 let word = lsb_index / 64;
17993 let bit = lsb_index % 64;
17994 (aw[word] >> bit) & 1u64
17995}
17996
17997#[inline]
17998#[must_use]
17999const fn limbs_divmod_64(a: Limbs<64>, b: Limbs<64>) -> (Limbs<64>, Limbs<64>) {
18000 let mut q = Limbs::<64>::zero();
18001 let mut r = Limbs::<64>::zero();
18002 let total_bits = 64 * 64;
18003 let mut i = 0usize;
18004 while i < total_bits {
18005 r = limbs_shl1_64(r);
18006 if limbs_bit_msb_64(a, i) == 1 {
18007 r = limbs_set_bit0_64(r);
18008 }
18009 if limbs_le_64(b, r) {
18010 r = r.wrapping_sub(b);
18011 q = limbs_shl1_64(q);
18012 q = limbs_set_bit0_64(q);
18013 } else {
18014 q = limbs_shl1_64(q);
18015 }
18016 i += 1;
18017 }
18018 (q, r)
18019}
18020
18021#[inline]
18022#[must_use]
18023const fn limbs_div_64(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
18024 let (q, _) = limbs_divmod_64(a, b);
18025 q
18026}
18027
18028#[inline]
18029#[must_use]
18030const fn limbs_mod_64(a: Limbs<64>, b: Limbs<64>) -> Limbs<64> {
18031 let (_, r) = limbs_divmod_64(a, b);
18032 r
18033}
18034
18035#[inline]
18036#[must_use]
18037const fn limbs_pow_64(base: Limbs<64>, exp: Limbs<64>) -> Limbs<64> {
18038 let mut result = limbs_one_64();
18039 let mut b = base;
18040 let ew = exp.words();
18041 let mut word = 0usize;
18042 while word < 64 {
18043 let mut bit = 0u32;
18044 while bit < 64 {
18045 if ((ew[word] >> bit) & 1u64) == 1u64 {
18046 result = result.wrapping_mul(b);
18047 }
18048 b = b.wrapping_mul(b);
18049 bit += 1;
18050 }
18051 word += 1;
18052 }
18053 result
18054}
18055
18056#[inline]
18057#[must_use]
18058const fn limbs_is_zero_128(a: Limbs<128>) -> bool {
18059 let aw = a.words();
18060 let mut i = 0usize;
18061 while i < 128 {
18062 if aw[i] != 0 {
18063 return false;
18064 }
18065 i += 1;
18066 }
18067 true
18068}
18069
18070#[inline]
18071#[must_use]
18072const fn limbs_shl1_128(a: Limbs<128>) -> Limbs<128> {
18073 let aw = a.words();
18074 let mut out = [0u64; 128];
18075 let mut carry: u64 = 0;
18076 let mut i = 0usize;
18077 while i < 128 {
18078 let v = aw[i];
18079 out[i] = (v << 1) | carry;
18080 carry = v >> 63;
18081 i += 1;
18082 }
18083 Limbs::<128>::from_words(out)
18084}
18085
18086#[inline]
18087#[must_use]
18088const fn limbs_set_bit0_128(a: Limbs<128>) -> Limbs<128> {
18089 let aw = a.words();
18090 let mut out = [0u64; 128];
18091 let mut i = 0usize;
18092 while i < 128 {
18093 out[i] = aw[i];
18094 i += 1;
18095 }
18096 out[0] |= 1u64;
18097 Limbs::<128>::from_words(out)
18098}
18099
18100#[inline]
18101#[must_use]
18102const fn limbs_bit_msb_128(a: Limbs<128>, msb_index: usize) -> u64 {
18103 let aw = a.words();
18104 let total_bits = 128 * 64;
18105 let lsb_index = total_bits - 1 - msb_index;
18106 let word = lsb_index / 64;
18107 let bit = lsb_index % 64;
18108 (aw[word] >> bit) & 1u64
18109}
18110
18111#[inline]
18112#[must_use]
18113const fn limbs_divmod_128(a: Limbs<128>, b: Limbs<128>) -> (Limbs<128>, Limbs<128>) {
18114 let mut q = Limbs::<128>::zero();
18115 let mut r = Limbs::<128>::zero();
18116 let total_bits = 128 * 64;
18117 let mut i = 0usize;
18118 while i < total_bits {
18119 r = limbs_shl1_128(r);
18120 if limbs_bit_msb_128(a, i) == 1 {
18121 r = limbs_set_bit0_128(r);
18122 }
18123 if limbs_le_128(b, r) {
18124 r = r.wrapping_sub(b);
18125 q = limbs_shl1_128(q);
18126 q = limbs_set_bit0_128(q);
18127 } else {
18128 q = limbs_shl1_128(q);
18129 }
18130 i += 1;
18131 }
18132 (q, r)
18133}
18134
18135#[inline]
18136#[must_use]
18137const fn limbs_div_128(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
18138 let (q, _) = limbs_divmod_128(a, b);
18139 q
18140}
18141
18142#[inline]
18143#[must_use]
18144const fn limbs_mod_128(a: Limbs<128>, b: Limbs<128>) -> Limbs<128> {
18145 let (_, r) = limbs_divmod_128(a, b);
18146 r
18147}
18148
18149#[inline]
18150#[must_use]
18151const fn limbs_pow_128(base: Limbs<128>, exp: Limbs<128>) -> Limbs<128> {
18152 let mut result = limbs_one_128();
18153 let mut b = base;
18154 let ew = exp.words();
18155 let mut word = 0usize;
18156 while word < 128 {
18157 let mut bit = 0u32;
18158 while bit < 64 {
18159 if ((ew[word] >> bit) & 1u64) == 1u64 {
18160 result = result.wrapping_mul(b);
18161 }
18162 b = b.wrapping_mul(b);
18163 bit += 1;
18164 }
18165 word += 1;
18166 }
18167 result
18168}
18169
18170#[inline]
18171#[must_use]
18172const fn limbs_is_zero_192(a: Limbs<192>) -> bool {
18173 let aw = a.words();
18174 let mut i = 0usize;
18175 while i < 192 {
18176 if aw[i] != 0 {
18177 return false;
18178 }
18179 i += 1;
18180 }
18181 true
18182}
18183
18184#[inline]
18185#[must_use]
18186const fn limbs_shl1_192(a: Limbs<192>) -> Limbs<192> {
18187 let aw = a.words();
18188 let mut out = [0u64; 192];
18189 let mut carry: u64 = 0;
18190 let mut i = 0usize;
18191 while i < 192 {
18192 let v = aw[i];
18193 out[i] = (v << 1) | carry;
18194 carry = v >> 63;
18195 i += 1;
18196 }
18197 Limbs::<192>::from_words(out)
18198}
18199
18200#[inline]
18201#[must_use]
18202const fn limbs_set_bit0_192(a: Limbs<192>) -> Limbs<192> {
18203 let aw = a.words();
18204 let mut out = [0u64; 192];
18205 let mut i = 0usize;
18206 while i < 192 {
18207 out[i] = aw[i];
18208 i += 1;
18209 }
18210 out[0] |= 1u64;
18211 Limbs::<192>::from_words(out)
18212}
18213
18214#[inline]
18215#[must_use]
18216const fn limbs_bit_msb_192(a: Limbs<192>, msb_index: usize) -> u64 {
18217 let aw = a.words();
18218 let total_bits = 192 * 64;
18219 let lsb_index = total_bits - 1 - msb_index;
18220 let word = lsb_index / 64;
18221 let bit = lsb_index % 64;
18222 (aw[word] >> bit) & 1u64
18223}
18224
18225#[inline]
18226#[must_use]
18227const fn limbs_divmod_192(a: Limbs<192>, b: Limbs<192>) -> (Limbs<192>, Limbs<192>) {
18228 let mut q = Limbs::<192>::zero();
18229 let mut r = Limbs::<192>::zero();
18230 let total_bits = 192 * 64;
18231 let mut i = 0usize;
18232 while i < total_bits {
18233 r = limbs_shl1_192(r);
18234 if limbs_bit_msb_192(a, i) == 1 {
18235 r = limbs_set_bit0_192(r);
18236 }
18237 if limbs_le_192(b, r) {
18238 r = r.wrapping_sub(b);
18239 q = limbs_shl1_192(q);
18240 q = limbs_set_bit0_192(q);
18241 } else {
18242 q = limbs_shl1_192(q);
18243 }
18244 i += 1;
18245 }
18246 (q, r)
18247}
18248
18249#[inline]
18250#[must_use]
18251const fn limbs_div_192(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
18252 let (q, _) = limbs_divmod_192(a, b);
18253 q
18254}
18255
18256#[inline]
18257#[must_use]
18258const fn limbs_mod_192(a: Limbs<192>, b: Limbs<192>) -> Limbs<192> {
18259 let (_, r) = limbs_divmod_192(a, b);
18260 r
18261}
18262
18263#[inline]
18264#[must_use]
18265const fn limbs_pow_192(base: Limbs<192>, exp: Limbs<192>) -> Limbs<192> {
18266 let mut result = limbs_one_192();
18267 let mut b = base;
18268 let ew = exp.words();
18269 let mut word = 0usize;
18270 while word < 192 {
18271 let mut bit = 0u32;
18272 while bit < 64 {
18273 if ((ew[word] >> bit) & 1u64) == 1u64 {
18274 result = result.wrapping_mul(b);
18275 }
18276 b = b.wrapping_mul(b);
18277 bit += 1;
18278 }
18279 word += 1;
18280 }
18281 result
18282}
18283
18284#[inline]
18285#[must_use]
18286const fn limbs_is_zero_256(a: Limbs<256>) -> bool {
18287 let aw = a.words();
18288 let mut i = 0usize;
18289 while i < 256 {
18290 if aw[i] != 0 {
18291 return false;
18292 }
18293 i += 1;
18294 }
18295 true
18296}
18297
18298#[inline]
18299#[must_use]
18300const fn limbs_shl1_256(a: Limbs<256>) -> Limbs<256> {
18301 let aw = a.words();
18302 let mut out = [0u64; 256];
18303 let mut carry: u64 = 0;
18304 let mut i = 0usize;
18305 while i < 256 {
18306 let v = aw[i];
18307 out[i] = (v << 1) | carry;
18308 carry = v >> 63;
18309 i += 1;
18310 }
18311 Limbs::<256>::from_words(out)
18312}
18313
18314#[inline]
18315#[must_use]
18316const fn limbs_set_bit0_256(a: Limbs<256>) -> Limbs<256> {
18317 let aw = a.words();
18318 let mut out = [0u64; 256];
18319 let mut i = 0usize;
18320 while i < 256 {
18321 out[i] = aw[i];
18322 i += 1;
18323 }
18324 out[0] |= 1u64;
18325 Limbs::<256>::from_words(out)
18326}
18327
18328#[inline]
18329#[must_use]
18330const fn limbs_bit_msb_256(a: Limbs<256>, msb_index: usize) -> u64 {
18331 let aw = a.words();
18332 let total_bits = 256 * 64;
18333 let lsb_index = total_bits - 1 - msb_index;
18334 let word = lsb_index / 64;
18335 let bit = lsb_index % 64;
18336 (aw[word] >> bit) & 1u64
18337}
18338
18339#[inline]
18340#[must_use]
18341const fn limbs_divmod_256(a: Limbs<256>, b: Limbs<256>) -> (Limbs<256>, Limbs<256>) {
18342 let mut q = Limbs::<256>::zero();
18343 let mut r = Limbs::<256>::zero();
18344 let total_bits = 256 * 64;
18345 let mut i = 0usize;
18346 while i < total_bits {
18347 r = limbs_shl1_256(r);
18348 if limbs_bit_msb_256(a, i) == 1 {
18349 r = limbs_set_bit0_256(r);
18350 }
18351 if limbs_le_256(b, r) {
18352 r = r.wrapping_sub(b);
18353 q = limbs_shl1_256(q);
18354 q = limbs_set_bit0_256(q);
18355 } else {
18356 q = limbs_shl1_256(q);
18357 }
18358 i += 1;
18359 }
18360 (q, r)
18361}
18362
18363#[inline]
18364#[must_use]
18365const fn limbs_div_256(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
18366 let (q, _) = limbs_divmod_256(a, b);
18367 q
18368}
18369
18370#[inline]
18371#[must_use]
18372const fn limbs_mod_256(a: Limbs<256>, b: Limbs<256>) -> Limbs<256> {
18373 let (_, r) = limbs_divmod_256(a, b);
18374 r
18375}
18376
18377#[inline]
18378#[must_use]
18379const fn limbs_pow_256(base: Limbs<256>, exp: Limbs<256>) -> Limbs<256> {
18380 let mut result = limbs_one_256();
18381 let mut b = base;
18382 let ew = exp.words();
18383 let mut word = 0usize;
18384 while word < 256 {
18385 let mut bit = 0u32;
18386 while bit < 64 {
18387 if ((ew[word] >> bit) & 1u64) == 1u64 {
18388 result = result.wrapping_mul(b);
18389 }
18390 b = b.wrapping_mul(b);
18391 bit += 1;
18392 }
18393 word += 1;
18394 }
18395 result
18396}
18397
18398#[inline]
18399#[must_use]
18400const fn limbs_is_zero_512(a: Limbs<512>) -> bool {
18401 let aw = a.words();
18402 let mut i = 0usize;
18403 while i < 512 {
18404 if aw[i] != 0 {
18405 return false;
18406 }
18407 i += 1;
18408 }
18409 true
18410}
18411
18412#[inline]
18413#[must_use]
18414const fn limbs_shl1_512(a: Limbs<512>) -> Limbs<512> {
18415 let aw = a.words();
18416 let mut out = [0u64; 512];
18417 let mut carry: u64 = 0;
18418 let mut i = 0usize;
18419 while i < 512 {
18420 let v = aw[i];
18421 out[i] = (v << 1) | carry;
18422 carry = v >> 63;
18423 i += 1;
18424 }
18425 Limbs::<512>::from_words(out)
18426}
18427
18428#[inline]
18429#[must_use]
18430const fn limbs_set_bit0_512(a: Limbs<512>) -> Limbs<512> {
18431 let aw = a.words();
18432 let mut out = [0u64; 512];
18433 let mut i = 0usize;
18434 while i < 512 {
18435 out[i] = aw[i];
18436 i += 1;
18437 }
18438 out[0] |= 1u64;
18439 Limbs::<512>::from_words(out)
18440}
18441
18442#[inline]
18443#[must_use]
18444const fn limbs_bit_msb_512(a: Limbs<512>, msb_index: usize) -> u64 {
18445 let aw = a.words();
18446 let total_bits = 512 * 64;
18447 let lsb_index = total_bits - 1 - msb_index;
18448 let word = lsb_index / 64;
18449 let bit = lsb_index % 64;
18450 (aw[word] >> bit) & 1u64
18451}
18452
18453#[inline]
18454#[must_use]
18455const fn limbs_divmod_512(a: Limbs<512>, b: Limbs<512>) -> (Limbs<512>, Limbs<512>) {
18456 let mut q = Limbs::<512>::zero();
18457 let mut r = Limbs::<512>::zero();
18458 let total_bits = 512 * 64;
18459 let mut i = 0usize;
18460 while i < total_bits {
18461 r = limbs_shl1_512(r);
18462 if limbs_bit_msb_512(a, i) == 1 {
18463 r = limbs_set_bit0_512(r);
18464 }
18465 if limbs_le_512(b, r) {
18466 r = r.wrapping_sub(b);
18467 q = limbs_shl1_512(q);
18468 q = limbs_set_bit0_512(q);
18469 } else {
18470 q = limbs_shl1_512(q);
18471 }
18472 i += 1;
18473 }
18474 (q, r)
18475}
18476
18477#[inline]
18478#[must_use]
18479const fn limbs_div_512(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
18480 let (q, _) = limbs_divmod_512(a, b);
18481 q
18482}
18483
18484#[inline]
18485#[must_use]
18486const fn limbs_mod_512(a: Limbs<512>, b: Limbs<512>) -> Limbs<512> {
18487 let (_, r) = limbs_divmod_512(a, b);
18488 r
18489}
18490
18491#[inline]
18492#[must_use]
18493const fn limbs_pow_512(base: Limbs<512>, exp: Limbs<512>) -> Limbs<512> {
18494 let mut result = limbs_one_512();
18495 let mut b = base;
18496 let ew = exp.words();
18497 let mut word = 0usize;
18498 while word < 512 {
18499 let mut bit = 0u32;
18500 while bit < 64 {
18501 if ((ew[word] >> bit) & 1u64) == 1u64 {
18502 result = result.wrapping_mul(b);
18503 }
18504 b = b.wrapping_mul(b);
18505 bit += 1;
18506 }
18507 word += 1;
18508 }
18509 result
18510}
18511
18512pub trait FragmentMarker: fragment_sealed::Sealed {}
18516
18517mod fragment_sealed {
18518 pub trait Sealed {}
18520 impl Sealed for super::Is2SatShape {}
18521 impl Sealed for super::IsHornShape {}
18522 impl Sealed for super::IsResidualFragment {}
18523}
18524
18525#[derive(Debug, Default, Clone, Copy)]
18527pub struct Is2SatShape;
18528impl FragmentMarker for Is2SatShape {}
18529
18530#[derive(Debug, Default, Clone, Copy)]
18532pub struct IsHornShape;
18533impl FragmentMarker for IsHornShape {}
18534
18535#[derive(Debug, Default, Clone, Copy)]
18537pub struct IsResidualFragment;
18538impl FragmentMarker for IsResidualFragment {}
18539
18540#[derive(Debug, Clone, Copy)]
18543pub struct DispatchRule {
18544 pub predicate_iri: &'static str,
18546 pub target_resolver_iri: &'static str,
18548 pub priority: u32,
18550}
18551
18552pub type DispatchTable = &'static [DispatchRule];
18554
18555pub const INHABITANCE_DISPATCH_TABLE: DispatchTable = &[
18557 DispatchRule {
18558 predicate_iri: "https://uor.foundation/predicate/Is2SatShape",
18559 target_resolver_iri: "https://uor.foundation/resolver/TwoSatDecider",
18560 priority: 0,
18561 },
18562 DispatchRule {
18563 predicate_iri: "https://uor.foundation/predicate/IsHornShape",
18564 target_resolver_iri: "https://uor.foundation/resolver/HornSatDecider",
18565 priority: 1,
18566 },
18567 DispatchRule {
18568 predicate_iri: "https://uor.foundation/predicate/IsResidualFragment",
18569 target_resolver_iri: "https://uor.foundation/resolver/ResidualVerdictResolver",
18570 priority: 2,
18571 },
18572];
18573
18574impl<T: OntologyTarget> core::ops::Deref for Validated<T> {
18579 type Target = T;
18580 #[inline]
18581 fn deref(&self) -> &T {
18582 &self.inner
18583 }
18584}
18585
18586mod bound_constraint_sealed {
18587 pub trait ObservableSealed {}
18589 pub trait BoundShapeSealed {}
18591}
18592
18593pub trait Observable: bound_constraint_sealed::ObservableSealed {
18598 const IRI: &'static str;
18600}
18601
18602pub trait BoundShape: bound_constraint_sealed::BoundShapeSealed {
18606 const IRI: &'static str;
18608}
18609
18610#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18612pub struct ValueModObservable;
18613impl bound_constraint_sealed::ObservableSealed for ValueModObservable {}
18614impl Observable for ValueModObservable {
18615 const IRI: &'static str = "https://uor.foundation/observable/ValueModObservable";
18616}
18617
18618#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18620pub struct HammingMetric;
18621impl bound_constraint_sealed::ObservableSealed for HammingMetric {}
18622impl Observable for HammingMetric {
18623 const IRI: &'static str = "https://uor.foundation/observable/HammingMetric";
18624}
18625
18626#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18628pub struct DerivationDepthObservable;
18629impl bound_constraint_sealed::ObservableSealed for DerivationDepthObservable {}
18630impl Observable for DerivationDepthObservable {
18631 const IRI: &'static str = "https://uor.foundation/derivation/DerivationDepthObservable";
18632}
18633
18634#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18636pub struct CarryDepthObservable;
18637impl bound_constraint_sealed::ObservableSealed for CarryDepthObservable {}
18638impl Observable for CarryDepthObservable {
18639 const IRI: &'static str = "https://uor.foundation/carry/CarryDepthObservable";
18640}
18641
18642#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18644pub struct FreeRankObservable;
18645impl bound_constraint_sealed::ObservableSealed for FreeRankObservable {}
18646impl Observable for FreeRankObservable {
18647 const IRI: &'static str = "https://uor.foundation/partition/FreeRankObservable";
18648}
18649
18650#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18652pub struct EqualBound;
18653impl bound_constraint_sealed::BoundShapeSealed for EqualBound {}
18654impl BoundShape for EqualBound {
18655 const IRI: &'static str = "https://uor.foundation/type/EqualBound";
18656}
18657
18658#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18660pub struct LessEqBound;
18661impl bound_constraint_sealed::BoundShapeSealed for LessEqBound {}
18662impl BoundShape for LessEqBound {
18663 const IRI: &'static str = "https://uor.foundation/type/LessEqBound";
18664}
18665
18666#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18668pub struct GreaterEqBound;
18669impl bound_constraint_sealed::BoundShapeSealed for GreaterEqBound {}
18670impl BoundShape for GreaterEqBound {
18671 const IRI: &'static str = "https://uor.foundation/type/GreaterEqBound";
18672}
18673
18674#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18676pub struct RangeContainBound;
18677impl bound_constraint_sealed::BoundShapeSealed for RangeContainBound {}
18678impl BoundShape for RangeContainBound {
18679 const IRI: &'static str = "https://uor.foundation/type/RangeContainBound";
18680}
18681
18682#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18684pub struct ResidueClassBound;
18685impl bound_constraint_sealed::BoundShapeSealed for ResidueClassBound {}
18686impl BoundShape for ResidueClassBound {
18687 const IRI: &'static str = "https://uor.foundation/type/ResidueClassBound";
18688}
18689
18690#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18692pub struct AffineEqualBound;
18693impl bound_constraint_sealed::BoundShapeSealed for AffineEqualBound {}
18694impl BoundShape for AffineEqualBound {
18695 const IRI: &'static str = "https://uor.foundation/type/AffineEqualBound";
18696}
18697
18698#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18702pub enum BoundArgValue {
18703 U64(u64),
18705 I64(i64),
18707 Bytes32([u8; 32]),
18709}
18710
18711#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18717pub struct BoundArguments {
18718 entries: [Option<BoundArgEntry>; 8],
18719}
18720
18721#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18723pub struct BoundArgEntry {
18724 pub name: &'static str,
18726 pub value: BoundArgValue,
18728}
18729
18730impl BoundArguments {
18731 #[inline]
18733 #[must_use]
18734 pub const fn empty() -> Self {
18735 Self { entries: [None; 8] }
18736 }
18737
18738 #[inline]
18740 #[must_use]
18741 pub const fn single(name: &'static str, value: BoundArgValue) -> Self {
18742 let mut entries = [None; 8];
18743 entries[0] = Some(BoundArgEntry { name, value });
18744 Self { entries }
18745 }
18746
18747 #[inline]
18749 #[must_use]
18750 pub const fn pair(
18751 first: (&'static str, BoundArgValue),
18752 second: (&'static str, BoundArgValue),
18753 ) -> Self {
18754 let mut entries = [None; 8];
18755 entries[0] = Some(BoundArgEntry {
18756 name: first.0,
18757 value: first.1,
18758 });
18759 entries[1] = Some(BoundArgEntry {
18760 name: second.0,
18761 value: second.1,
18762 });
18763 Self { entries }
18764 }
18765
18766 #[inline]
18768 #[must_use]
18769 pub const fn entries(&self) -> &[Option<BoundArgEntry>; 8] {
18770 &self.entries
18771 }
18772}
18773
18774#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18779pub struct BoundConstraint<O: Observable, B: BoundShape> {
18780 observable: O,
18781 bound: B,
18782 args: BoundArguments,
18783 _sealed: (),
18784}
18785
18786impl<O: Observable, B: BoundShape> BoundConstraint<O, B> {
18787 #[inline]
18790 #[must_use]
18791 pub(crate) const fn from_parts(observable: O, bound: B, args: BoundArguments) -> Self {
18792 Self {
18793 observable,
18794 bound,
18795 args,
18796 _sealed: (),
18797 }
18798 }
18799
18800 #[inline]
18802 #[must_use]
18803 pub const fn observable(&self) -> &O {
18804 &self.observable
18805 }
18806
18807 #[inline]
18809 #[must_use]
18810 pub const fn bound(&self) -> &B {
18811 &self.bound
18812 }
18813
18814 #[inline]
18816 #[must_use]
18817 pub const fn args(&self) -> &BoundArguments {
18818 &self.args
18819 }
18820}
18821
18822#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18826pub struct Conjunction<const N: usize> {
18827 len: usize,
18828 _sealed: (),
18829}
18830
18831impl<const N: usize> Conjunction<N> {
18832 #[inline]
18834 #[must_use]
18835 pub const fn new(len: usize) -> Self {
18836 Self { len, _sealed: () }
18837 }
18838
18839 #[inline]
18841 #[must_use]
18842 pub const fn len(&self) -> usize {
18843 self.len
18844 }
18845
18846 #[inline]
18848 #[must_use]
18849 pub const fn is_empty(&self) -> bool {
18850 self.len == 0
18851 }
18852}
18853
18854pub type ResidueConstraint = BoundConstraint<ValueModObservable, ResidueClassBound>;
18857
18858impl ResidueConstraint {
18859 #[inline]
18861 #[must_use]
18862 pub const fn new(modulus: u64, residue: u64) -> Self {
18863 let args = BoundArguments::pair(
18864 ("modulus", BoundArgValue::U64(modulus)),
18865 ("residue", BoundArgValue::U64(residue)),
18866 );
18867 BoundConstraint::from_parts(ValueModObservable, ResidueClassBound, args)
18868 }
18869}
18870
18871pub type HammingConstraint = BoundConstraint<HammingMetric, LessEqBound>;
18874
18875impl HammingConstraint {
18876 #[inline]
18878 #[must_use]
18879 pub const fn new(bound: u64) -> Self {
18880 let args = BoundArguments::single("bound", BoundArgValue::U64(bound));
18881 BoundConstraint::from_parts(HammingMetric, LessEqBound, args)
18882 }
18883}
18884
18885pub type DepthConstraint = BoundConstraint<DerivationDepthObservable, LessEqBound>;
18888
18889impl DepthConstraint {
18890 #[inline]
18892 #[must_use]
18893 pub const fn new(min_depth: u64, max_depth: u64) -> Self {
18894 let args = BoundArguments::pair(
18895 ("min_depth", BoundArgValue::U64(min_depth)),
18896 ("max_depth", BoundArgValue::U64(max_depth)),
18897 );
18898 BoundConstraint::from_parts(DerivationDepthObservable, LessEqBound, args)
18899 }
18900}
18901
18902pub type CarryConstraint = BoundConstraint<CarryDepthObservable, LessEqBound>;
18905
18906impl CarryConstraint {
18907 #[inline]
18909 #[must_use]
18910 pub const fn new(bound: u64) -> Self {
18911 let args = BoundArguments::single("bound", BoundArgValue::U64(bound));
18912 BoundConstraint::from_parts(CarryDepthObservable, LessEqBound, args)
18913 }
18914}
18915
18916pub type SiteConstraint = BoundConstraint<FreeRankObservable, LessEqBound>;
18919
18920impl SiteConstraint {
18921 #[inline]
18923 #[must_use]
18924 pub const fn new(site_index: u64) -> Self {
18925 let args = BoundArguments::single("site_index", BoundArgValue::U64(site_index));
18926 BoundConstraint::from_parts(FreeRankObservable, LessEqBound, args)
18927 }
18928}
18929
18930pub type AffineConstraint = BoundConstraint<ValueModObservable, AffineEqualBound>;
18933
18934impl AffineConstraint {
18935 #[inline]
18937 #[must_use]
18938 pub const fn new(offset: u64) -> Self {
18939 let args = BoundArguments::single("offset", BoundArgValue::U64(offset));
18940 BoundConstraint::from_parts(ValueModObservable, AffineEqualBound, args)
18941 }
18942}
18943
18944pub type CompositeConstraint<const N: usize> = Conjunction<N>;
18947
18948#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18950pub struct Query {
18951 address: ContentAddress,
18952 _sealed: (),
18953}
18954
18955impl Query {
18956 #[inline]
18958 #[must_use]
18959 pub const fn address(&self) -> ContentAddress {
18960 self.address
18961 }
18962
18963 #[inline]
18965 #[must_use]
18966 #[allow(dead_code)]
18967 pub(crate) const fn new(address: ContentAddress) -> Self {
18968 Self {
18969 address,
18970 _sealed: (),
18971 }
18972 }
18973}
18974
18975#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18977pub struct Coordinate<L> {
18978 stratum: u64,
18979 spectrum: u64,
18980 address: u64,
18981 _level: PhantomData<L>,
18982 _sealed: (),
18983}
18984
18985impl<L> Coordinate<L> {
18986 #[inline]
18988 #[must_use]
18989 pub const fn stratum(&self) -> u64 {
18990 self.stratum
18991 }
18992
18993 #[inline]
18995 #[must_use]
18996 pub const fn spectrum(&self) -> u64 {
18997 self.spectrum
18998 }
18999
19000 #[inline]
19002 #[must_use]
19003 pub const fn address(&self) -> u64 {
19004 self.address
19005 }
19006
19007 #[inline]
19009 #[must_use]
19010 #[allow(dead_code)]
19011 pub(crate) const fn new(stratum: u64, spectrum: u64, address: u64) -> Self {
19012 Self {
19013 stratum,
19014 spectrum,
19015 address,
19016 _level: PhantomData,
19017 _sealed: (),
19018 }
19019 }
19020}
19021
19022#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19024pub struct BindingQuery {
19025 address: ContentAddress,
19026 _sealed: (),
19027}
19028
19029impl BindingQuery {
19030 #[inline]
19032 #[must_use]
19033 pub const fn address(&self) -> ContentAddress {
19034 self.address
19035 }
19036
19037 #[inline]
19039 #[must_use]
19040 #[allow(dead_code)]
19041 pub(crate) const fn new(address: ContentAddress) -> Self {
19042 Self {
19043 address,
19044 _sealed: (),
19045 }
19046 }
19047}
19048
19049#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19052pub struct Partition {
19053 component: PartitionComponent,
19054 _sealed: (),
19055}
19056
19057impl Partition {
19058 #[inline]
19060 #[must_use]
19061 pub const fn component(&self) -> PartitionComponent {
19062 self.component
19063 }
19064
19065 #[inline]
19067 #[must_use]
19068 #[allow(dead_code)]
19069 pub(crate) const fn new(component: PartitionComponent) -> Self {
19070 Self {
19071 component,
19072 _sealed: (),
19073 }
19074 }
19075}
19076
19077#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19082pub struct TraceEvent {
19083 step_index: u32,
19085 op: PrimitiveOp,
19087 target: ContentAddress,
19089 _sealed: (),
19091}
19092
19093impl TraceEvent {
19094 #[inline]
19096 #[must_use]
19097 pub const fn step_index(&self) -> u32 {
19098 self.step_index
19099 }
19100
19101 #[inline]
19103 #[must_use]
19104 pub const fn op(&self) -> PrimitiveOp {
19105 self.op
19106 }
19107
19108 #[inline]
19110 #[must_use]
19111 pub const fn target(&self) -> ContentAddress {
19112 self.target
19113 }
19114
19115 #[inline]
19117 #[must_use]
19118 #[allow(dead_code)]
19119 pub(crate) const fn new(step_index: u32, op: PrimitiveOp, target: ContentAddress) -> Self {
19120 Self {
19121 step_index,
19122 op,
19123 target,
19124 _sealed: (),
19125 }
19126 }
19127}
19128
19129#[derive(Debug, Clone, Copy)]
19138pub struct Trace<const TR_MAX: usize = 256> {
19139 events: [Option<TraceEvent>; TR_MAX],
19140 len: u16,
19141 witt_level_bits: u16,
19145 content_fingerprint: ContentFingerprint,
19152 _sealed: (),
19153}
19154
19155impl<const TR_MAX: usize> Trace<TR_MAX> {
19156 #[inline]
19158 #[must_use]
19159 pub const fn empty() -> Self {
19160 Self {
19161 events: [None; TR_MAX],
19162 len: 0,
19163 witt_level_bits: 0,
19164 content_fingerprint: ContentFingerprint::zero(),
19165 _sealed: (),
19166 }
19167 }
19168
19169 #[inline]
19175 #[must_use]
19176 #[allow(dead_code)]
19177 pub(crate) const fn from_replay_events_const(
19178 events: [Option<TraceEvent>; TR_MAX],
19179 len: u16,
19180 witt_level_bits: u16,
19181 content_fingerprint: ContentFingerprint,
19182 ) -> Self {
19183 Self {
19184 events,
19185 len,
19186 witt_level_bits,
19187 content_fingerprint,
19188 _sealed: (),
19189 }
19190 }
19191
19192 #[inline]
19194 #[must_use]
19195 pub const fn len(&self) -> u16 {
19196 self.len
19197 }
19198
19199 #[inline]
19201 #[must_use]
19202 pub const fn is_empty(&self) -> bool {
19203 self.len == 0
19204 }
19205
19206 #[inline]
19208 #[must_use]
19209 pub fn event(&self, index: usize) -> Option<&TraceEvent> {
19210 self.events.get(index).and_then(|e| e.as_ref())
19211 }
19212
19213 #[inline]
19216 #[must_use]
19217 pub const fn witt_level_bits(&self) -> u16 {
19218 self.witt_level_bits
19219 }
19220
19221 #[inline]
19226 #[must_use]
19227 pub const fn content_fingerprint(&self) -> ContentFingerprint {
19228 self.content_fingerprint
19229 }
19230
19231 pub fn try_from_events(
19243 events: &[TraceEvent],
19244 witt_level_bits: u16,
19245 content_fingerprint: ContentFingerprint,
19246 ) -> Result<Self, ReplayError> {
19247 if events.is_empty() {
19248 return Err(ReplayError::EmptyTrace);
19249 }
19250 if events.len() > TR_MAX {
19251 return Err(ReplayError::CapacityExceeded {
19252 declared: TR_MAX as u16,
19253 provided: events.len() as u32,
19254 });
19255 }
19256 let mut i = 0usize;
19257 while i < events.len() {
19258 let e = &events[i];
19259 if e.step_index() as usize != i {
19260 return Err(ReplayError::OutOfOrderEvent { index: i });
19261 }
19262 if e.target().is_zero() {
19263 return Err(ReplayError::ZeroTarget { index: i });
19264 }
19265 i += 1;
19266 }
19267 let mut arr = [None; TR_MAX];
19268 let mut j = 0usize;
19269 while j < events.len() {
19270 arr[j] = Some(events[j]);
19271 j += 1;
19272 }
19273 Ok(Self {
19274 events: arr,
19275 len: events.len() as u16,
19276 witt_level_bits,
19277 content_fingerprint,
19278 _sealed: (),
19279 })
19280 }
19281}
19282
19283impl<const TR_MAX: usize> Default for Trace<TR_MAX> {
19284 #[inline]
19285 fn default() -> Self {
19286 Self::empty()
19287 }
19288}
19289
19290impl Derivation {
19295 #[inline]
19330 #[must_use]
19331 pub fn replay<const TR_MAX: usize>(&self) -> Trace<TR_MAX> {
19332 let steps = self.step_count() as usize;
19333 let len = if steps > TR_MAX { TR_MAX } else { steps };
19334 let mut events = [None; TR_MAX];
19335 let fp = self.content_fingerprint.as_bytes();
19341 let seed =
19342 u64::from_be_bytes([fp[0], fp[1], fp[2], fp[3], fp[4], fp[5], fp[6], fp[7]]) as u128;
19343 let nonzero_seed = seed | 1u128;
19344 let mut i = 0usize;
19345 while i < len {
19346 let target_raw = nonzero_seed ^ ((i as u128) + 1u128);
19347 events[i] = Some(TraceEvent::new(
19348 i as u32,
19349 crate::PrimitiveOp::Add,
19350 ContentAddress::from_u128(target_raw),
19351 ));
19352 i += 1;
19353 }
19354 Trace::from_replay_events_const(
19360 events,
19361 len as u16,
19362 self.witt_level_bits,
19363 self.content_fingerprint,
19364 )
19365 }
19366}
19367
19368#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19370#[non_exhaustive]
19371pub enum ReplayError {
19372 EmptyTrace,
19374 OutOfOrderEvent {
19376 index: usize,
19378 },
19379 ZeroTarget {
19381 index: usize,
19383 },
19384 NonContiguousSteps {
19390 declared: u16,
19392 last_step: u32,
19396 },
19397 CapacityExceeded {
19404 declared: u16,
19406 provided: u32,
19408 },
19409}
19410
19411impl core::fmt::Display for ReplayError {
19412 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
19413 match self {
19414 Self::EmptyTrace => f.write_str("trace was empty; nothing to replay"),
19415 Self::OutOfOrderEvent { index } => write!(
19416 f,
19417 "event at index {index} has out-of-order step index",
19418 ),
19419 Self::ZeroTarget { index } => write!(
19420 f,
19421 "event at index {index} has a zero ContentAddress target",
19422 ),
19423 Self::NonContiguousSteps { declared, last_step } => write!(
19424 f,
19425 "trace declares {declared} events but step indices skip values \
19426 (last step {last_step})",
19427 ),
19428 Self::CapacityExceeded { declared, provided } => write!(
19429 f,
19430 "trace capacity exceeded: tried to pack {provided} events into a buffer of {declared}",
19431 ),
19432 }
19433 }
19434}
19435
19436impl core::error::Error for ReplayError {}
19437
19438pub mod replay {
19445 use super::{Certified, GroundingCertificate, ReplayError, Trace};
19446
19447 pub fn certify_from_trace<const TR_MAX: usize>(
19475 trace: &Trace<TR_MAX>,
19476 ) -> Result<Certified<GroundingCertificate>, ReplayError> {
19477 let len = trace.len() as usize;
19478 if len == 0 {
19479 return Err(ReplayError::EmptyTrace);
19480 }
19481 let mut last_step: i64 = -1;
19484 let mut max_step_index: u32 = 0;
19485 let mut i = 0usize;
19486 while i < len {
19487 let event = match trace.event(i) {
19488 Some(e) => e,
19489 None => return Err(ReplayError::OutOfOrderEvent { index: i }),
19490 };
19491 let step_index = event.step_index();
19492 if (step_index as i64) <= last_step {
19493 return Err(ReplayError::OutOfOrderEvent { index: i });
19494 }
19495 if event.target().is_zero() {
19496 return Err(ReplayError::ZeroTarget { index: i });
19497 }
19498 if step_index > max_step_index {
19499 max_step_index = step_index;
19500 }
19501 last_step = step_index as i64;
19502 i += 1;
19503 }
19504 if (max_step_index as u16).saturating_add(1) != trace.len() {
19505 return Err(ReplayError::NonContiguousSteps {
19506 declared: trace.len(),
19507 last_step: max_step_index,
19508 });
19509 }
19510 Ok(Certified::new(
19518 GroundingCertificate::with_level_and_fingerprint_const(
19519 trace.witt_level_bits(),
19520 trace.content_fingerprint(),
19521 ),
19522 ))
19523 }
19524}
19525
19526#[derive(Debug, Clone, Copy, Default)]
19531pub struct InteractionDeclarationBuilder {
19532 peer_protocol: Option<u128>,
19533 convergence_predicate: Option<u128>,
19534 commutator_state_class: Option<u128>,
19535}
19536
19537impl InteractionDeclarationBuilder {
19538 #[inline]
19540 #[must_use]
19541 pub const fn new() -> Self {
19542 Self {
19543 peer_protocol: None,
19544 convergence_predicate: None,
19545 commutator_state_class: None,
19546 }
19547 }
19548
19549 #[inline]
19551 #[must_use]
19552 pub const fn peer_protocol(mut self, address: u128) -> Self {
19553 self.peer_protocol = Some(address);
19554 self
19555 }
19556
19557 #[inline]
19559 #[must_use]
19560 pub const fn convergence_predicate(mut self, address: u128) -> Self {
19561 self.convergence_predicate = Some(address);
19562 self
19563 }
19564
19565 #[inline]
19567 #[must_use]
19568 pub const fn commutator_state_class(mut self, address: u128) -> Self {
19569 self.commutator_state_class = Some(address);
19570 self
19571 }
19572
19573 pub fn validate(&self) -> Result<Validated<InteractionShape>, ShapeViolation> {
19577 self.validate_common().map(|_| {
19578 Validated::new(InteractionShape {
19579 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19580 })
19581 })
19582 }
19583
19584 pub const fn validate_const(
19588 &self,
19589 ) -> Result<Validated<InteractionShape, CompileTime>, ShapeViolation> {
19590 if self.peer_protocol.is_none() {
19591 return Err(ShapeViolation {
19592 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19593 constraint_iri: "https://uor.foundation/conformance/InteractionShape",
19594 property_iri: "https://uor.foundation/interaction/peerProtocol",
19595 expected_range: "http://www.w3.org/2002/07/owl#Thing",
19596 min_count: 1,
19597 max_count: 1,
19598 kind: ViolationKind::Missing,
19599 });
19600 }
19601 if self.convergence_predicate.is_none() {
19602 return Err(ShapeViolation {
19603 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19604 constraint_iri: "https://uor.foundation/conformance/InteractionShape",
19605 property_iri: "https://uor.foundation/interaction/convergencePredicate",
19606 expected_range: "http://www.w3.org/2002/07/owl#Thing",
19607 min_count: 1,
19608 max_count: 1,
19609 kind: ViolationKind::Missing,
19610 });
19611 }
19612 if self.commutator_state_class.is_none() {
19613 return Err(ShapeViolation {
19614 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19615 constraint_iri: "https://uor.foundation/conformance/InteractionShape",
19616 property_iri: "https://uor.foundation/interaction/commutatorStateClass",
19617 expected_range: "http://www.w3.org/2002/07/owl#Thing",
19618 min_count: 1,
19619 max_count: 1,
19620 kind: ViolationKind::Missing,
19621 });
19622 }
19623 Ok(Validated::new(InteractionShape {
19624 shape_iri: "https://uor.foundation/conformance/InteractionShape",
19625 }))
19626 }
19627
19628 fn validate_common(&self) -> Result<(), ShapeViolation> {
19629 self.validate_const().map(|_| ())
19630 }
19631}
19632
19633#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19635pub struct InteractionShape {
19636 pub shape_iri: &'static str,
19638}
19639
19640#[cfg(feature = "observability")]
19646pub fn subscribe_trace_events<F>(handler: F) -> ObservabilitySubscription<F>
19647where
19648 F: FnMut(&TraceEvent),
19649{
19650 ObservabilitySubscription {
19651 handler,
19652 _sealed: (),
19653 }
19654}
19655
19656#[cfg(feature = "observability")]
19657#[cfg(feature = "observability")]
19659pub struct ObservabilitySubscription<F: FnMut(&TraceEvent)> {
19660 handler: F,
19661 _sealed: (),
19662}
19663
19664#[cfg(feature = "observability")]
19665impl<F: FnMut(&TraceEvent)> ObservabilitySubscription<F> {
19666 pub fn emit(&mut self, event: &TraceEvent) {
19668 (self.handler)(event);
19669 }
19670}
19671
19672#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19678#[non_exhaustive]
19679pub enum ConstraintKind {
19680 Residue,
19682 Carry,
19684 Depth,
19686 Hamming,
19688 Site,
19690 Affine,
19692}
19693
19694#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19696pub struct CarryProfile {
19697 chain_length: u32,
19698 max_depth: u32,
19699 _sealed: (),
19700}
19701
19702impl CarryProfile {
19703 #[inline]
19705 #[must_use]
19706 pub const fn chain_length(&self) -> u32 {
19707 self.chain_length
19708 }
19709
19710 #[inline]
19712 #[must_use]
19713 pub const fn max_depth(&self) -> u32 {
19714 self.max_depth
19715 }
19716
19717 #[inline]
19719 #[must_use]
19720 #[allow(dead_code)]
19721 pub(crate) const fn new(chain_length: u32, max_depth: u32) -> Self {
19722 Self {
19723 chain_length,
19724 max_depth,
19725 _sealed: (),
19726 }
19727 }
19728}
19729
19730#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19733pub struct CarryEvent {
19734 left_bits: u16,
19735 right_bits: u16,
19736 _sealed: (),
19737}
19738
19739impl CarryEvent {
19740 #[inline]
19742 #[must_use]
19743 pub const fn left_bits(&self) -> u16 {
19744 self.left_bits
19745 }
19746
19747 #[inline]
19749 #[must_use]
19750 pub const fn right_bits(&self) -> u16 {
19751 self.right_bits
19752 }
19753
19754 #[inline]
19756 #[must_use]
19757 #[allow(dead_code)]
19758 pub(crate) const fn new(left_bits: u16, right_bits: u16) -> Self {
19759 Self {
19760 left_bits,
19761 right_bits,
19762 _sealed: (),
19763 }
19764 }
19765}
19766
19767#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19769pub struct ConvergenceLevel<L> {
19770 valuation: u32,
19771 _level: PhantomData<L>,
19772 _sealed: (),
19773}
19774
19775impl<L> ConvergenceLevel<L> {
19776 #[inline]
19778 #[must_use]
19779 pub const fn valuation(&self) -> u32 {
19780 self.valuation
19781 }
19782
19783 #[inline]
19785 #[must_use]
19786 #[allow(dead_code)]
19787 pub(crate) const fn new(valuation: u32) -> Self {
19788 Self {
19789 valuation,
19790 _level: PhantomData,
19791 _sealed: (),
19792 }
19793 }
19794}
19795
19796#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19799#[non_exhaustive]
19800pub enum DivisionAlgebraWitness {
19801 Real,
19803 Complex,
19805 Quaternion,
19807 Octonion,
19809}
19810
19811#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19813pub struct MonoidalProduct<L, R> {
19814 _left: PhantomData<L>,
19815 _right: PhantomData<R>,
19816 _sealed: (),
19817}
19818
19819impl<L, R> MonoidalProduct<L, R> {
19820 #[inline]
19822 #[must_use]
19823 #[allow(dead_code)]
19824 pub(crate) const fn new() -> Self {
19825 Self {
19826 _left: PhantomData,
19827 _right: PhantomData,
19828 _sealed: (),
19829 }
19830 }
19831}
19832
19833#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19835pub struct MonoidalUnit<L> {
19836 _level: PhantomData<L>,
19837 _sealed: (),
19838}
19839
19840impl<L> MonoidalUnit<L> {
19841 #[inline]
19843 #[must_use]
19844 #[allow(dead_code)]
19845 pub(crate) const fn new() -> Self {
19846 Self {
19847 _level: PhantomData,
19848 _sealed: (),
19849 }
19850 }
19851}
19852
19853#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19857pub struct OperadComposition {
19858 outer_type_iri: &'static str,
19859 inner_type_iri: &'static str,
19860 composed_site_count: u32,
19861 _sealed: (),
19862}
19863
19864impl OperadComposition {
19865 #[inline]
19867 #[must_use]
19868 pub const fn outer_type_iri(&self) -> &'static str {
19869 self.outer_type_iri
19870 }
19871
19872 #[inline]
19874 #[must_use]
19875 pub const fn inner_type_iri(&self) -> &'static str {
19876 self.inner_type_iri
19877 }
19878
19879 #[inline]
19881 #[must_use]
19882 pub const fn composed_site_count(&self) -> u32 {
19883 self.composed_site_count
19884 }
19885
19886 #[inline]
19888 #[must_use]
19889 #[allow(dead_code)]
19890 pub(crate) const fn new(
19891 outer_type_iri: &'static str,
19892 inner_type_iri: &'static str,
19893 composed_site_count: u32,
19894 ) -> Self {
19895 Self {
19896 outer_type_iri,
19897 inner_type_iri,
19898 composed_site_count,
19899 _sealed: (),
19900 }
19901 }
19902}
19903
19904pub const RECURSION_TRACE_MAX_DEPTH: usize =
19910 <crate::DefaultHostBounds as crate::HostBounds>::RECURSION_TRACE_DEPTH_MAX;
19911
19912#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19915pub struct RecursionTrace {
19916 depth: u32,
19917 measure: [u32; RECURSION_TRACE_MAX_DEPTH],
19918 _sealed: (),
19919}
19920
19921impl RecursionTrace {
19922 #[inline]
19924 #[must_use]
19925 pub const fn depth(&self) -> u32 {
19926 self.depth
19927 }
19928
19929 #[inline]
19931 #[must_use]
19932 pub const fn measure(&self) -> &[u32; RECURSION_TRACE_MAX_DEPTH] {
19933 &self.measure
19934 }
19935
19936 #[inline]
19938 #[must_use]
19939 #[allow(dead_code)]
19940 pub(crate) const fn new(depth: u32, measure: [u32; RECURSION_TRACE_MAX_DEPTH]) -> Self {
19941 Self {
19942 depth,
19943 measure,
19944 _sealed: (),
19945 }
19946 }
19947}
19948
19949#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19951pub struct AddressRegion {
19952 base: u128,
19953 extent: u64,
19954 _sealed: (),
19955}
19956
19957impl AddressRegion {
19958 #[inline]
19960 #[must_use]
19961 pub const fn base(&self) -> u128 {
19962 self.base
19963 }
19964
19965 #[inline]
19967 #[must_use]
19968 pub const fn extent(&self) -> u64 {
19969 self.extent
19970 }
19971
19972 #[inline]
19974 #[must_use]
19975 #[allow(dead_code)]
19976 pub(crate) const fn new(base: u128, extent: u64) -> Self {
19977 Self {
19978 base,
19979 extent,
19980 _sealed: (),
19981 }
19982 }
19983}
19984
19985#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19987pub struct LinearBudget {
19988 sites_remaining: u64,
19989 _sealed: (),
19990}
19991
19992impl LinearBudget {
19993 #[inline]
19995 #[must_use]
19996 pub const fn sites_remaining(&self) -> u64 {
19997 self.sites_remaining
19998 }
19999
20000 #[inline]
20002 #[must_use]
20003 #[allow(dead_code)]
20004 pub(crate) const fn new(sites_remaining: u64) -> Self {
20005 Self {
20006 sites_remaining,
20007 _sealed: (),
20008 }
20009 }
20010}
20011
20012#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20014pub struct LeaseAllocation {
20015 site_count: u32,
20016 scope_hash: u128,
20017 _sealed: (),
20018}
20019
20020impl LeaseAllocation {
20021 #[inline]
20023 #[must_use]
20024 pub const fn site_count(&self) -> u32 {
20025 self.site_count
20026 }
20027
20028 #[inline]
20030 #[must_use]
20031 pub const fn scope_hash(&self) -> u128 {
20032 self.scope_hash
20033 }
20034
20035 #[inline]
20037 #[must_use]
20038 #[allow(dead_code)]
20039 pub(crate) const fn new(site_count: u32, scope_hash: u128) -> Self {
20040 Self {
20041 site_count,
20042 scope_hash,
20043 _sealed: (),
20044 }
20045 }
20046}
20047
20048#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
20050pub struct TotalMarker;
20051
20052#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
20054pub struct InvertibleMarker;
20055
20056#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
20058pub struct PreservesStructureMarker;
20059
20060mod marker_tuple_sealed {
20061 pub trait Sealed {}
20063}
20064
20065pub trait MarkerTuple: marker_tuple_sealed::Sealed {}
20070
20071impl marker_tuple_sealed::Sealed for () {}
20072impl MarkerTuple for () {}
20073impl marker_tuple_sealed::Sealed for (TotalMarker,) {}
20074impl MarkerTuple for (TotalMarker,) {}
20075impl marker_tuple_sealed::Sealed for (TotalMarker, InvertibleMarker) {}
20076impl MarkerTuple for (TotalMarker, InvertibleMarker) {}
20077impl marker_tuple_sealed::Sealed for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {}
20078impl MarkerTuple for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {}
20079impl marker_tuple_sealed::Sealed for (InvertibleMarker,) {}
20080impl MarkerTuple for (InvertibleMarker,) {}
20081impl marker_tuple_sealed::Sealed for (InvertibleMarker, PreservesStructureMarker) {}
20082impl MarkerTuple for (InvertibleMarker, PreservesStructureMarker) {}
20083
20084pub trait MarkerIntersection<Other: MarkerTuple>: MarkerTuple {
20091 type Output: MarkerTuple;
20093}
20094
20095impl MarkerIntersection<()> for () {
20096 type Output = ();
20097}
20098impl MarkerIntersection<(TotalMarker,)> for () {
20099 type Output = ();
20100}
20101impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for () {
20102 type Output = ();
20103}
20104impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)> for () {
20105 type Output = ();
20106}
20107impl MarkerIntersection<(InvertibleMarker,)> for () {
20108 type Output = ();
20109}
20110impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for () {
20111 type Output = ();
20112}
20113impl MarkerIntersection<()> for (TotalMarker,) {
20114 type Output = ();
20115}
20116impl MarkerIntersection<(TotalMarker,)> for (TotalMarker,) {
20117 type Output = (TotalMarker,);
20118}
20119impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (TotalMarker,) {
20120 type Output = (TotalMarker,);
20121}
20122impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20123 for (TotalMarker,)
20124{
20125 type Output = (TotalMarker,);
20126}
20127impl MarkerIntersection<(InvertibleMarker,)> for (TotalMarker,) {
20128 type Output = ();
20129}
20130impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for (TotalMarker,) {
20131 type Output = ();
20132}
20133impl MarkerIntersection<()> for (TotalMarker, InvertibleMarker) {
20134 type Output = ();
20135}
20136impl MarkerIntersection<(TotalMarker,)> for (TotalMarker, InvertibleMarker) {
20137 type Output = (TotalMarker,);
20138}
20139impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (TotalMarker, InvertibleMarker) {
20140 type Output = (TotalMarker, InvertibleMarker);
20141}
20142impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20143 for (TotalMarker, InvertibleMarker)
20144{
20145 type Output = (TotalMarker, InvertibleMarker);
20146}
20147impl MarkerIntersection<(InvertibleMarker,)> for (TotalMarker, InvertibleMarker) {
20148 type Output = (InvertibleMarker,);
20149}
20150impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
20151 for (TotalMarker, InvertibleMarker)
20152{
20153 type Output = (InvertibleMarker,);
20154}
20155impl MarkerIntersection<()> for (TotalMarker, InvertibleMarker, PreservesStructureMarker) {
20156 type Output = ();
20157}
20158impl MarkerIntersection<(TotalMarker,)>
20159 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20160{
20161 type Output = (TotalMarker,);
20162}
20163impl MarkerIntersection<(TotalMarker, InvertibleMarker)>
20164 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20165{
20166 type Output = (TotalMarker, InvertibleMarker);
20167}
20168impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20169 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20170{
20171 type Output = (TotalMarker, InvertibleMarker, PreservesStructureMarker);
20172}
20173impl MarkerIntersection<(InvertibleMarker,)>
20174 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20175{
20176 type Output = (InvertibleMarker,);
20177}
20178impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
20179 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20180{
20181 type Output = (InvertibleMarker, PreservesStructureMarker);
20182}
20183impl MarkerIntersection<()> for (InvertibleMarker,) {
20184 type Output = ();
20185}
20186impl MarkerIntersection<(TotalMarker,)> for (InvertibleMarker,) {
20187 type Output = ();
20188}
20189impl MarkerIntersection<(TotalMarker, InvertibleMarker)> for (InvertibleMarker,) {
20190 type Output = (InvertibleMarker,);
20191}
20192impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20193 for (InvertibleMarker,)
20194{
20195 type Output = (InvertibleMarker,);
20196}
20197impl MarkerIntersection<(InvertibleMarker,)> for (InvertibleMarker,) {
20198 type Output = (InvertibleMarker,);
20199}
20200impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)> for (InvertibleMarker,) {
20201 type Output = (InvertibleMarker,);
20202}
20203impl MarkerIntersection<()> for (InvertibleMarker, PreservesStructureMarker) {
20204 type Output = ();
20205}
20206impl MarkerIntersection<(TotalMarker,)> for (InvertibleMarker, PreservesStructureMarker) {
20207 type Output = ();
20208}
20209impl MarkerIntersection<(TotalMarker, InvertibleMarker)>
20210 for (InvertibleMarker, PreservesStructureMarker)
20211{
20212 type Output = (InvertibleMarker,);
20213}
20214impl MarkerIntersection<(TotalMarker, InvertibleMarker, PreservesStructureMarker)>
20215 for (InvertibleMarker, PreservesStructureMarker)
20216{
20217 type Output = (InvertibleMarker, PreservesStructureMarker);
20218}
20219impl MarkerIntersection<(InvertibleMarker,)> for (InvertibleMarker, PreservesStructureMarker) {
20220 type Output = (InvertibleMarker,);
20221}
20222impl MarkerIntersection<(InvertibleMarker, PreservesStructureMarker)>
20223 for (InvertibleMarker, PreservesStructureMarker)
20224{
20225 type Output = (InvertibleMarker, PreservesStructureMarker);
20226}
20227
20228pub trait MarkersImpliedBy<Map: GroundingMapKind>: MarkerTuple {}
20234
20235#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20238pub struct MarkerBits(u8);
20239
20240impl MarkerBits {
20241 pub const TOTAL: Self = Self(1);
20243 pub const INVERTIBLE: Self = Self(2);
20245 pub const PRESERVES_STRUCTURE: Self = Self(4);
20247 pub const NONE: Self = Self(0);
20249
20250 #[inline]
20252 #[must_use]
20253 pub const fn from_u8(bits: u8) -> Self {
20254 Self(bits)
20255 }
20256
20257 #[inline]
20259 #[must_use]
20260 pub const fn as_u8(&self) -> u8 {
20261 self.0
20262 }
20263
20264 #[inline]
20266 #[must_use]
20267 pub const fn union(self, other: Self) -> Self {
20268 Self(self.0 | other.0)
20269 }
20270
20271 #[inline]
20273 #[must_use]
20274 pub const fn intersection(self, other: Self) -> Self {
20275 Self(self.0 & other.0)
20276 }
20277
20278 #[inline]
20280 #[must_use]
20281 pub const fn contains(&self, other: Self) -> bool {
20282 (self.0 & other.0) == other.0
20283 }
20284}
20285
20286#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20292#[non_exhaustive]
20293pub enum GroundingPrimitiveOp {
20294 ReadBytes,
20296 InterpretLeInteger,
20298 InterpretBeInteger,
20300 Digest,
20306 DecodeUtf8,
20312 DecodeJson,
20318 SelectField,
20320 SelectIndex,
20322 ConstValue,
20328 Then,
20330 MapErr,
20332 AndThen,
20334}
20335
20336pub const MAX_OP_CHAIN_DEPTH: usize =
20343 <crate::DefaultHostBounds as crate::HostBounds>::OP_CHAIN_DEPTH_MAX;
20344
20345#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20355pub struct GroundingPrimitive<Out, Markers: MarkerTuple = ()> {
20356 op: GroundingPrimitiveOp,
20357 markers: MarkerBits,
20358 chain: [GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH],
20359 chain_len: u8,
20360 _out: PhantomData<Out>,
20361 _markers: PhantomData<Markers>,
20362 _sealed: (),
20363}
20364
20365impl<Out, Markers: MarkerTuple> GroundingPrimitive<Out, Markers> {
20366 #[inline]
20368 #[must_use]
20369 pub const fn op(&self) -> GroundingPrimitiveOp {
20370 self.op
20371 }
20372
20373 #[inline]
20375 #[must_use]
20376 pub const fn markers(&self) -> MarkerBits {
20377 self.markers
20378 }
20379
20380 #[inline]
20383 #[must_use]
20384 pub fn chain(&self) -> &[GroundingPrimitiveOp] {
20385 &self.chain[..self.chain_len as usize]
20386 }
20387
20388 #[inline]
20392 #[must_use]
20393 #[allow(dead_code)]
20394 pub(crate) const fn from_parts(op: GroundingPrimitiveOp, markers: MarkerBits) -> Self {
20395 Self {
20396 op,
20397 markers,
20398 chain: [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH],
20399 chain_len: 0,
20400 _out: PhantomData,
20401 _markers: PhantomData,
20402 _sealed: (),
20403 }
20404 }
20405
20406 #[inline]
20409 #[must_use]
20410 #[allow(dead_code)]
20411 pub(crate) const fn from_parts_with_chain(
20412 op: GroundingPrimitiveOp,
20413 markers: MarkerBits,
20414 chain: [GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH],
20415 chain_len: u8,
20416 ) -> Self {
20417 Self {
20418 op,
20419 markers,
20420 chain,
20421 chain_len,
20422 _out: PhantomData,
20423 _markers: PhantomData,
20424 _sealed: (),
20425 }
20426 }
20427}
20428
20429pub mod combinators {
20435 use super::{
20436 GroundingPrimitive, GroundingPrimitiveOp, InvertibleMarker, MarkerBits, MarkerIntersection,
20437 MarkerTuple, PreservesStructureMarker, TotalMarker, MAX_OP_CHAIN_DEPTH,
20438 };
20439
20440 fn compose_chain<A, B, MA: MarkerTuple, MB: MarkerTuple>(
20444 first: &GroundingPrimitive<A, MA>,
20445 second: &GroundingPrimitive<B, MB>,
20446 ) -> ([GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH], u8) {
20447 let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
20448 let mut len: usize = 0;
20449 for &op in first.chain() {
20450 if len >= MAX_OP_CHAIN_DEPTH {
20451 return (chain, len as u8);
20452 }
20453 chain[len] = op;
20454 len += 1;
20455 }
20456 if len < MAX_OP_CHAIN_DEPTH {
20457 chain[len] = first.op();
20458 len += 1;
20459 }
20460 for &op in second.chain() {
20461 if len >= MAX_OP_CHAIN_DEPTH {
20462 return (chain, len as u8);
20463 }
20464 chain[len] = op;
20465 len += 1;
20466 }
20467 if len < MAX_OP_CHAIN_DEPTH {
20468 chain[len] = second.op();
20469 len += 1;
20470 }
20471 (chain, len as u8)
20472 }
20473
20474 fn map_err_chain<A, M: MarkerTuple>(
20476 first: &GroundingPrimitive<A, M>,
20477 ) -> ([GroundingPrimitiveOp; MAX_OP_CHAIN_DEPTH], u8) {
20478 let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
20479 let mut len: usize = 0;
20480 for &op in first.chain() {
20481 if len >= MAX_OP_CHAIN_DEPTH {
20482 return (chain, len as u8);
20483 }
20484 chain[len] = op;
20485 len += 1;
20486 }
20487 if len < MAX_OP_CHAIN_DEPTH {
20488 chain[len] = first.op();
20489 len += 1;
20490 }
20491 (chain, len as u8)
20492 }
20493
20494 #[inline]
20496 #[must_use]
20497 pub const fn read_bytes<Out>() -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker)> {
20498 GroundingPrimitive::from_parts(
20499 GroundingPrimitiveOp::ReadBytes,
20500 MarkerBits::TOTAL.union(MarkerBits::INVERTIBLE),
20501 )
20502 }
20503
20504 #[inline]
20506 #[must_use]
20507 pub const fn interpret_le_integer<Out>(
20508 ) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
20509 GroundingPrimitive::from_parts(
20510 GroundingPrimitiveOp::InterpretLeInteger,
20511 MarkerBits::TOTAL
20512 .union(MarkerBits::INVERTIBLE)
20513 .union(MarkerBits::PRESERVES_STRUCTURE),
20514 )
20515 }
20516
20517 #[inline]
20519 #[must_use]
20520 pub const fn interpret_be_integer<Out>(
20521 ) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
20522 GroundingPrimitive::from_parts(
20523 GroundingPrimitiveOp::InterpretBeInteger,
20524 MarkerBits::TOTAL
20525 .union(MarkerBits::INVERTIBLE)
20526 .union(MarkerBits::PRESERVES_STRUCTURE),
20527 )
20528 }
20529
20530 #[inline]
20532 #[must_use]
20533 pub const fn digest<Out>() -> GroundingPrimitive<Out, (TotalMarker,)> {
20534 GroundingPrimitive::from_parts(GroundingPrimitiveOp::Digest, MarkerBits::TOTAL)
20535 }
20536
20537 #[inline]
20539 #[must_use]
20540 pub const fn decode_utf8<Out>(
20541 ) -> GroundingPrimitive<Out, (InvertibleMarker, PreservesStructureMarker)> {
20542 GroundingPrimitive::from_parts(
20543 GroundingPrimitiveOp::DecodeUtf8,
20544 MarkerBits::INVERTIBLE.union(MarkerBits::PRESERVES_STRUCTURE),
20545 )
20546 }
20547
20548 #[inline]
20550 #[must_use]
20551 pub const fn decode_json<Out>(
20552 ) -> GroundingPrimitive<Out, (InvertibleMarker, PreservesStructureMarker)> {
20553 GroundingPrimitive::from_parts(
20554 GroundingPrimitiveOp::DecodeJson,
20555 MarkerBits::INVERTIBLE.union(MarkerBits::PRESERVES_STRUCTURE),
20556 )
20557 }
20558
20559 #[inline]
20561 #[must_use]
20562 pub const fn select_field<Out>() -> GroundingPrimitive<Out, (InvertibleMarker,)> {
20563 GroundingPrimitive::from_parts(GroundingPrimitiveOp::SelectField, MarkerBits::INVERTIBLE)
20564 }
20565
20566 #[inline]
20568 #[must_use]
20569 pub const fn select_index<Out>() -> GroundingPrimitive<Out, (InvertibleMarker,)> {
20570 GroundingPrimitive::from_parts(GroundingPrimitiveOp::SelectIndex, MarkerBits::INVERTIBLE)
20571 }
20572
20573 #[inline]
20575 #[must_use]
20576 pub const fn const_value<Out>(
20577 ) -> GroundingPrimitive<Out, (TotalMarker, InvertibleMarker, PreservesStructureMarker)> {
20578 GroundingPrimitive::from_parts(
20579 GroundingPrimitiveOp::ConstValue,
20580 MarkerBits::TOTAL
20581 .union(MarkerBits::INVERTIBLE)
20582 .union(MarkerBits::PRESERVES_STRUCTURE),
20583 )
20584 }
20585
20586 #[inline]
20591 #[must_use]
20592 pub fn then<A, B, MA, MB>(
20593 first: GroundingPrimitive<A, MA>,
20594 second: GroundingPrimitive<B, MB>,
20595 ) -> GroundingPrimitive<B, <MA as MarkerIntersection<MB>>::Output>
20596 where
20597 MA: MarkerTuple + MarkerIntersection<MB>,
20598 MB: MarkerTuple,
20599 {
20600 let (chain, chain_len) = compose_chain(&first, &second);
20601 GroundingPrimitive::from_parts_with_chain(
20602 GroundingPrimitiveOp::Then,
20603 first.markers().intersection(second.markers()),
20604 chain,
20605 chain_len,
20606 )
20607 }
20608
20609 #[inline]
20613 #[must_use]
20614 pub fn map_err<A, M: MarkerTuple>(first: GroundingPrimitive<A, M>) -> GroundingPrimitive<A, M> {
20615 let (chain, chain_len) = map_err_chain(&first);
20616 GroundingPrimitive::from_parts_with_chain(
20617 GroundingPrimitiveOp::MapErr,
20618 first.markers(),
20619 chain,
20620 chain_len,
20621 )
20622 }
20623
20624 #[inline]
20627 #[must_use]
20628 pub fn and_then<A, B, MA, MB>(
20629 first: GroundingPrimitive<A, MA>,
20630 second: GroundingPrimitive<B, MB>,
20631 ) -> GroundingPrimitive<B, <MA as MarkerIntersection<MB>>::Output>
20632 where
20633 MA: MarkerTuple + MarkerIntersection<MB>,
20634 MB: MarkerTuple,
20635 {
20636 let (chain, chain_len) = compose_chain(&first, &second);
20637 GroundingPrimitive::from_parts_with_chain(
20638 GroundingPrimitiveOp::AndThen,
20639 first.markers().intersection(second.markers()),
20640 chain,
20641 chain_len,
20642 )
20643 }
20644}
20645
20646#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20652pub struct GroundingProgram<Out, Map: GroundingMapKind> {
20653 primitive: GroundingPrimitive<Out>,
20654 _map: PhantomData<Map>,
20655 _sealed: (),
20656}
20657
20658impl<Out, Map: GroundingMapKind> GroundingProgram<Out, Map> {
20659 #[inline]
20681 #[must_use]
20682 pub fn from_primitive<Markers>(primitive: GroundingPrimitive<Out, Markers>) -> Self
20683 where
20684 Markers: MarkerTuple + MarkersImpliedBy<Map>,
20685 {
20686 let mut chain = [GroundingPrimitiveOp::ReadBytes; MAX_OP_CHAIN_DEPTH];
20689 let src = primitive.chain();
20690 let mut i = 0;
20691 while i < src.len() && i < MAX_OP_CHAIN_DEPTH {
20692 chain[i] = src[i];
20693 i += 1;
20694 }
20695 let erased = GroundingPrimitive::<Out, ()>::from_parts_with_chain(
20696 primitive.op(),
20697 primitive.markers(),
20698 chain,
20699 i as u8,
20700 );
20701 Self {
20702 primitive: erased,
20703 _map: PhantomData,
20704 _sealed: (),
20705 }
20706 }
20707
20708 #[inline]
20710 #[must_use]
20711 pub const fn primitive(&self) -> &GroundingPrimitive<Out> {
20712 &self.primitive
20713 }
20714}
20715
20716impl<Map: GroundingMapKind> GroundingProgram<GroundedCoord, Map> {
20729 #[inline]
20733 #[must_use]
20734 pub fn run(&self, external: &[u8]) -> Option<GroundedCoord> {
20735 match self.primitive.op() {
20736 GroundingPrimitiveOp::Then | GroundingPrimitiveOp::AndThen => {
20737 let chain = self.primitive.chain();
20738 if chain.is_empty() {
20739 return None;
20740 }
20741 let mut last: Option<GroundedCoord> = None;
20742 for &op in chain {
20743 match interpret_leaf_op(op, external) {
20744 Some(c) => last = Some(c),
20745 None => return None,
20746 }
20747 }
20748 last
20749 }
20750 GroundingPrimitiveOp::MapErr => self
20751 .primitive
20752 .chain()
20753 .first()
20754 .and_then(|&op| interpret_leaf_op(op, external)),
20755 leaf => interpret_leaf_op(leaf, external),
20756 }
20757 }
20758}
20759
20760impl<const N: usize, Map: GroundingMapKind> GroundingProgram<GroundedTuple<N>, Map> {
20767 #[inline]
20769 #[must_use]
20770 pub fn run(&self, external: &[u8]) -> Option<GroundedTuple<N>> {
20771 if N == 0 || external.is_empty() || external.len() % N != 0 {
20772 return None;
20773 }
20774 let window = external.len() / N;
20775 let mut coords: [GroundedCoord; N] = [const { GroundedCoord::w8(0) }; N];
20776 let mut i = 0usize;
20777 while i < N {
20778 let start = i * window;
20779 let end = start + window;
20780 let sub = &external[start..end];
20781 let outcome = match self.primitive.op() {
20786 GroundingPrimitiveOp::Then | GroundingPrimitiveOp::AndThen => {
20787 let chain = self.primitive.chain();
20788 if chain.is_empty() {
20789 return None;
20790 }
20791 let mut last: Option<GroundedCoord> = None;
20792 for &op in chain {
20793 match interpret_leaf_op(op, sub) {
20794 Some(c) => last = Some(c),
20795 None => return None,
20796 }
20797 }
20798 last
20799 }
20800 GroundingPrimitiveOp::MapErr => self
20801 .primitive
20802 .chain()
20803 .first()
20804 .and_then(|&op| interpret_leaf_op(op, sub)),
20805 leaf => interpret_leaf_op(leaf, sub),
20806 };
20807 match outcome {
20808 Some(c) => {
20809 coords[i] = c;
20810 }
20811 None => {
20812 return None;
20813 }
20814 }
20815 i += 1;
20816 }
20817 Some(GroundedTuple::new(coords))
20818 }
20819}
20820
20821#[inline]
20825fn interpret_leaf_op(op: GroundingPrimitiveOp, external: &[u8]) -> Option<GroundedCoord> {
20826 match op {
20827 GroundingPrimitiveOp::ReadBytes | GroundingPrimitiveOp::InterpretLeInteger => {
20828 external.first().map(|&b| GroundedCoord::w8(b))
20829 }
20830 GroundingPrimitiveOp::InterpretBeInteger => external.last().map(|&b| GroundedCoord::w8(b)),
20831 GroundingPrimitiveOp::Digest => {
20832 external.first().map(|&b| GroundedCoord::w8(b))
20839 }
20840 GroundingPrimitiveOp::DecodeUtf8 => {
20841 match external.first() {
20847 Some(&b) if b < 0x80 => Some(GroundedCoord::w8(b)),
20848 _ => None,
20849 }
20850 }
20851 GroundingPrimitiveOp::DecodeJson => {
20852 match external.first() {
20854 Some(&b) if b == b'-' || b.is_ascii_digit() => Some(GroundedCoord::w8(b)),
20855 _ => None,
20856 }
20857 }
20858 GroundingPrimitiveOp::ConstValue => Some(GroundedCoord::w8(0)),
20859 GroundingPrimitiveOp::SelectField | GroundingPrimitiveOp::SelectIndex => {
20860 external.first().map(|&b| GroundedCoord::w8(b))
20863 }
20864 GroundingPrimitiveOp::Then
20865 | GroundingPrimitiveOp::AndThen
20866 | GroundingPrimitiveOp::MapErr => {
20867 None
20870 }
20871 }
20872}
20873
20874impl MarkersImpliedBy<DigestGroundingMap> for (TotalMarker,) {}
20878impl MarkersImpliedBy<BinaryGroundingMap> for (TotalMarker, InvertibleMarker) {}
20879impl MarkersImpliedBy<DigestGroundingMap> for (TotalMarker, InvertibleMarker) {}
20880impl MarkersImpliedBy<BinaryGroundingMap>
20881 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20882{
20883}
20884impl MarkersImpliedBy<DigestGroundingMap>
20885 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20886{
20887}
20888impl MarkersImpliedBy<IntegerGroundingMap>
20889 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20890{
20891}
20892impl MarkersImpliedBy<JsonGroundingMap>
20893 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20894{
20895}
20896impl MarkersImpliedBy<Utf8GroundingMap>
20897 for (TotalMarker, InvertibleMarker, PreservesStructureMarker)
20898{
20899}
20900impl MarkersImpliedBy<JsonGroundingMap> for (InvertibleMarker, PreservesStructureMarker) {}
20901impl MarkersImpliedBy<Utf8GroundingMap> for (InvertibleMarker, PreservesStructureMarker) {}
20902
20903#[doc(hidden)]
20908pub mod __test_helpers {
20909 use super::{ContentAddress, ContentFingerprint, MulContext, Trace, TraceEvent, Validated};
20910
20911 #[must_use]
20917 pub fn trace_from_events<const TR_MAX: usize>(events: &[TraceEvent]) -> Trace<TR_MAX> {
20918 trace_with_fingerprint(events, 0, ContentFingerprint::zero())
20919 }
20920
20921 #[must_use]
20925 pub fn trace_with_fingerprint<const TR_MAX: usize>(
20926 events: &[TraceEvent],
20927 witt_level_bits: u16,
20928 content_fingerprint: ContentFingerprint,
20929 ) -> Trace<TR_MAX> {
20930 let mut arr = [None; TR_MAX];
20931 let n = events.len().min(TR_MAX);
20932 let mut i = 0;
20933 while i < n {
20934 arr[i] = Some(events[i]);
20935 i += 1;
20936 }
20937 Trace::from_replay_events_const(arr, n as u16, witt_level_bits, content_fingerprint)
20941 }
20942
20943 #[must_use]
20945 pub fn trace_event(step_index: u32, target: u128) -> TraceEvent {
20946 TraceEvent::new(
20947 step_index,
20948 crate::PrimitiveOp::Add,
20949 ContentAddress::from_u128(target),
20950 )
20951 }
20952
20953 #[must_use]
20955 pub fn mul_context(stack_budget_bytes: u64, const_eval: bool, limb_count: usize) -> MulContext {
20956 MulContext::new(stack_budget_bytes, const_eval, limb_count)
20957 }
20958
20959 #[must_use]
20963 pub fn validated_runtime<T>(inner: T) -> Validated<T> {
20964 Validated::new(inner)
20965 }
20966}
20967
20968type DefaultDecimal = <crate::DefaultHostTypes as crate::HostTypes>::Decimal;
20977
20978#[inline]
20979const fn pc_entropy_tolerance(expected: DefaultDecimal) -> DefaultDecimal {
20980 let magnitude = if expected < 0.0 { -expected } else { expected };
20981 let scale = if magnitude > 1.0 { magnitude } else { 1.0 };
20982 1024.0 * <DefaultDecimal>::EPSILON * scale
20983}
20984
20985#[inline]
20990fn pc_entropy_input_is_valid(value: DefaultDecimal) -> bool {
20991 value.is_finite() && value >= 0.0
20992}
20993
20994#[inline]
20999fn pc_entropy_additivity_holds(actual: DefaultDecimal, expected: DefaultDecimal) -> bool {
21000 if !pc_entropy_input_is_valid(actual) || !pc_entropy_input_is_valid(expected) {
21001 return false;
21002 }
21003 let diff = actual - expected;
21004 let diff_abs = if diff < 0.0 { -diff } else { diff };
21005 diff_abs <= pc_entropy_tolerance(expected)
21006}
21007
21008#[derive(Debug, Clone, Copy, PartialEq)]
21013pub struct PartitionProductEvidence {
21014 pub left_site_budget: u16,
21016 pub right_site_budget: u16,
21018 pub left_total_site_count: u16,
21020 pub right_total_site_count: u16,
21022 pub left_euler: i32,
21024 pub right_euler: i32,
21026 pub left_entropy_nats_bits: u64,
21028 pub right_entropy_nats_bits: u64,
21030 pub source_witness_fingerprint: ContentFingerprint,
21032}
21033
21034#[derive(Debug, Clone, Copy, PartialEq)]
21037pub struct PartitionCoproductEvidence {
21038 pub left_site_budget: u16,
21039 pub right_site_budget: u16,
21040 pub left_total_site_count: u16,
21041 pub right_total_site_count: u16,
21042 pub left_euler: i32,
21043 pub right_euler: i32,
21044 pub left_entropy_nats_bits: u64,
21045 pub right_entropy_nats_bits: u64,
21046 pub left_betti: [u32; MAX_BETTI_DIMENSION],
21047 pub right_betti: [u32; MAX_BETTI_DIMENSION],
21048 pub source_witness_fingerprint: ContentFingerprint,
21049}
21050
21051#[derive(Debug, Clone, Copy, PartialEq)]
21057pub struct CartesianProductEvidence {
21058 pub left_site_budget: u16,
21059 pub right_site_budget: u16,
21060 pub left_total_site_count: u16,
21061 pub right_total_site_count: u16,
21062 pub left_euler: i32,
21063 pub right_euler: i32,
21064 pub left_betti: [u32; MAX_BETTI_DIMENSION],
21065 pub right_betti: [u32; MAX_BETTI_DIMENSION],
21066 pub left_entropy_nats_bits: u64,
21067 pub right_entropy_nats_bits: u64,
21068 pub combined_entropy_nats_bits: u64,
21069 pub source_witness_fingerprint: ContentFingerprint,
21070}
21071
21072#[derive(Debug, Clone, Copy, PartialEq)]
21078pub struct PartitionProductMintInputs {
21079 pub witt_bits: u16,
21080 pub left_fingerprint: ContentFingerprint,
21081 pub right_fingerprint: ContentFingerprint,
21082 pub left_site_budget: u16,
21083 pub right_site_budget: u16,
21084 pub left_total_site_count: u16,
21085 pub right_total_site_count: u16,
21086 pub left_euler: i32,
21087 pub right_euler: i32,
21088 pub left_entropy_nats_bits: u64,
21089 pub right_entropy_nats_bits: u64,
21090 pub combined_site_budget: u16,
21091 pub combined_site_count: u16,
21092 pub combined_euler: i32,
21093 pub combined_entropy_nats_bits: u64,
21094 pub combined_fingerprint: ContentFingerprint,
21095}
21096
21097#[derive(Debug, Clone, Copy)]
21109pub struct PartitionCoproductMintInputs {
21110 pub witt_bits: u16,
21111 pub left_fingerprint: ContentFingerprint,
21112 pub right_fingerprint: ContentFingerprint,
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 combined_site_budget: u16,
21124 pub combined_site_count: u16,
21125 pub combined_euler: i32,
21126 pub combined_entropy_nats_bits: u64,
21127 pub combined_betti: [u32; MAX_BETTI_DIMENSION],
21128 pub combined_fingerprint: ContentFingerprint,
21129 pub combined_constraints: &'static [crate::pipeline::ConstraintRef],
21130 pub left_constraint_count: usize,
21131 pub tag_site: u16,
21132}
21133
21134#[derive(Debug, Clone, Copy, PartialEq)]
21137pub struct CartesianProductMintInputs {
21138 pub witt_bits: u16,
21139 pub left_fingerprint: ContentFingerprint,
21140 pub right_fingerprint: ContentFingerprint,
21141 pub left_site_budget: u16,
21142 pub right_site_budget: u16,
21143 pub left_total_site_count: u16,
21144 pub right_total_site_count: u16,
21145 pub left_euler: i32,
21146 pub right_euler: i32,
21147 pub left_betti: [u32; MAX_BETTI_DIMENSION],
21148 pub right_betti: [u32; MAX_BETTI_DIMENSION],
21149 pub left_entropy_nats_bits: u64,
21150 pub right_entropy_nats_bits: u64,
21151 pub combined_site_budget: u16,
21152 pub combined_site_count: u16,
21153 pub combined_euler: i32,
21154 pub combined_betti: [u32; MAX_BETTI_DIMENSION],
21155 pub combined_entropy_nats_bits: u64,
21156 pub combined_fingerprint: ContentFingerprint,
21157}
21158
21159#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21166pub struct PartitionProductWitness {
21167 witt_bits: u16,
21168 content_fingerprint: ContentFingerprint,
21169 left_fingerprint: ContentFingerprint,
21170 right_fingerprint: ContentFingerprint,
21171 combined_site_budget: u16,
21172 combined_site_count: u16,
21173}
21174
21175impl PartitionProductWitness {
21176 #[inline]
21178 #[must_use]
21179 pub const fn witt_bits(&self) -> u16 {
21180 self.witt_bits
21181 }
21182 #[inline]
21184 #[must_use]
21185 pub const fn content_fingerprint(&self) -> ContentFingerprint {
21186 self.content_fingerprint
21187 }
21188 #[inline]
21190 #[must_use]
21191 pub const fn left_fingerprint(&self) -> ContentFingerprint {
21192 self.left_fingerprint
21193 }
21194 #[inline]
21196 #[must_use]
21197 pub const fn right_fingerprint(&self) -> ContentFingerprint {
21198 self.right_fingerprint
21199 }
21200 #[inline]
21202 #[must_use]
21203 pub const fn combined_site_budget(&self) -> u16 {
21204 self.combined_site_budget
21205 }
21206 #[inline]
21208 #[must_use]
21209 pub const fn combined_site_count(&self) -> u16 {
21210 self.combined_site_count
21211 }
21212 #[inline]
21214 #[must_use]
21215 #[allow(clippy::too_many_arguments)]
21216 pub(crate) const fn with_level_fingerprints_and_sites(
21217 witt_bits: u16,
21218 content_fingerprint: ContentFingerprint,
21219 left_fingerprint: ContentFingerprint,
21220 right_fingerprint: ContentFingerprint,
21221 combined_site_budget: u16,
21222 combined_site_count: u16,
21223 ) -> Self {
21224 Self {
21225 witt_bits,
21226 content_fingerprint,
21227 left_fingerprint,
21228 right_fingerprint,
21229 combined_site_budget,
21230 combined_site_count,
21231 }
21232 }
21233}
21234
21235#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21241pub struct PartitionCoproductWitness {
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 tag_site_index: u16,
21249}
21250
21251impl PartitionCoproductWitness {
21252 #[inline]
21253 #[must_use]
21254 pub const fn witt_bits(&self) -> u16 {
21255 self.witt_bits
21256 }
21257 #[inline]
21258 #[must_use]
21259 pub const fn content_fingerprint(&self) -> ContentFingerprint {
21260 self.content_fingerprint
21261 }
21262 #[inline]
21263 #[must_use]
21264 pub const fn left_fingerprint(&self) -> ContentFingerprint {
21265 self.left_fingerprint
21266 }
21267 #[inline]
21268 #[must_use]
21269 pub const fn right_fingerprint(&self) -> ContentFingerprint {
21270 self.right_fingerprint
21271 }
21272 #[inline]
21274 #[must_use]
21275 pub const fn combined_site_budget(&self) -> u16 {
21276 self.combined_site_budget
21277 }
21278 #[inline]
21280 #[must_use]
21281 pub const fn combined_site_count(&self) -> u16 {
21282 self.combined_site_count
21283 }
21284 #[inline]
21287 #[must_use]
21288 pub const fn tag_site_index(&self) -> u16 {
21289 self.tag_site_index
21290 }
21291 #[inline]
21292 #[must_use]
21293 #[allow(clippy::too_many_arguments)]
21294 pub(crate) const fn with_level_fingerprints_sites_and_tag(
21295 witt_bits: u16,
21296 content_fingerprint: ContentFingerprint,
21297 left_fingerprint: ContentFingerprint,
21298 right_fingerprint: ContentFingerprint,
21299 combined_site_budget: u16,
21300 combined_site_count: u16,
21301 tag_site_index: u16,
21302 ) -> Self {
21303 Self {
21304 witt_bits,
21305 content_fingerprint,
21306 left_fingerprint,
21307 right_fingerprint,
21308 combined_site_budget,
21309 combined_site_count,
21310 tag_site_index,
21311 }
21312 }
21313}
21314
21315#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21324pub struct CartesianProductWitness {
21325 witt_bits: u16,
21326 content_fingerprint: ContentFingerprint,
21327 left_fingerprint: ContentFingerprint,
21328 right_fingerprint: ContentFingerprint,
21329 combined_site_budget: u16,
21330 combined_site_count: u16,
21331 combined_euler: i32,
21332 combined_betti: [u32; MAX_BETTI_DIMENSION],
21333}
21334
21335impl CartesianProductWitness {
21336 #[inline]
21337 #[must_use]
21338 pub const fn witt_bits(&self) -> u16 {
21339 self.witt_bits
21340 }
21341 #[inline]
21342 #[must_use]
21343 pub const fn content_fingerprint(&self) -> ContentFingerprint {
21344 self.content_fingerprint
21345 }
21346 #[inline]
21347 #[must_use]
21348 pub const fn left_fingerprint(&self) -> ContentFingerprint {
21349 self.left_fingerprint
21350 }
21351 #[inline]
21352 #[must_use]
21353 pub const fn right_fingerprint(&self) -> ContentFingerprint {
21354 self.right_fingerprint
21355 }
21356 #[inline]
21357 #[must_use]
21358 pub const fn combined_site_budget(&self) -> u16 {
21359 self.combined_site_budget
21360 }
21361 #[inline]
21362 #[must_use]
21363 pub const fn combined_site_count(&self) -> u16 {
21364 self.combined_site_count
21365 }
21366 #[inline]
21367 #[must_use]
21368 pub const fn combined_euler(&self) -> i32 {
21369 self.combined_euler
21370 }
21371 #[inline]
21372 #[must_use]
21373 pub const fn combined_betti(&self) -> [u32; MAX_BETTI_DIMENSION] {
21374 self.combined_betti
21375 }
21376 #[inline]
21377 #[must_use]
21378 #[allow(clippy::too_many_arguments)]
21379 pub(crate) const fn with_level_fingerprints_and_invariants(
21380 witt_bits: u16,
21381 content_fingerprint: ContentFingerprint,
21382 left_fingerprint: ContentFingerprint,
21383 right_fingerprint: ContentFingerprint,
21384 combined_site_budget: u16,
21385 combined_site_count: u16,
21386 combined_euler: i32,
21387 combined_betti: [u32; MAX_BETTI_DIMENSION],
21388 ) -> Self {
21389 Self {
21390 witt_bits,
21391 content_fingerprint,
21392 left_fingerprint,
21393 right_fingerprint,
21394 combined_site_budget,
21395 combined_site_count,
21396 combined_euler,
21397 combined_betti,
21398 }
21399 }
21400}
21401
21402impl Certificate for PartitionProductWitness {
21403 const IRI: &'static str = "https://uor.foundation/partition/PartitionProduct";
21404 type Evidence = PartitionProductEvidence;
21405}
21406
21407impl Certificate for PartitionCoproductWitness {
21408 const IRI: &'static str = "https://uor.foundation/partition/PartitionCoproduct";
21409 type Evidence = PartitionCoproductEvidence;
21410}
21411
21412impl Certificate for CartesianProductWitness {
21413 const IRI: &'static str = "https://uor.foundation/partition/CartesianPartitionProduct";
21414 type Evidence = CartesianProductEvidence;
21415}
21416
21417impl core::fmt::Display for PartitionProductWitness {
21418 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21419 f.write_str("PartitionProductWitness")
21420 }
21421}
21422impl core::error::Error for PartitionProductWitness {}
21423
21424impl core::fmt::Display for PartitionCoproductWitness {
21425 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21426 f.write_str("PartitionCoproductWitness")
21427 }
21428}
21429impl core::error::Error for PartitionCoproductWitness {}
21430
21431impl core::fmt::Display for CartesianProductWitness {
21432 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21433 f.write_str("CartesianProductWitness")
21434 }
21435}
21436impl core::error::Error for CartesianProductWitness {}
21437
21438pub trait VerifiedMint: Certificate {
21448 type Inputs;
21450 type Error;
21454 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error>
21462 where
21463 Self: Sized;
21464}
21465
21466#[allow(clippy::too_many_arguments)]
21471fn pc_classify_constraint(
21472 c: &crate::pipeline::ConstraintRef,
21473 in_left_region: bool,
21474 tag_site: u16,
21475 max_depth: u32,
21476 left_pins: &mut u32,
21477 right_pins: &mut u32,
21478 left_bias_ok: &mut bool,
21479 right_bias_ok: &mut bool,
21480) -> Result<(), GenericImpossibilityWitness> {
21481 match c {
21482 crate::pipeline::ConstraintRef::Site { position } => {
21483 if (*position as u16) >= tag_site {
21484 return Err(GenericImpossibilityWitness::for_identity(
21485 "https://uor.foundation/op/ST_6",
21486 ));
21487 }
21488 }
21489 crate::pipeline::ConstraintRef::Carry { site } => {
21490 if (*site as u16) >= tag_site {
21491 return Err(GenericImpossibilityWitness::for_identity(
21492 "https://uor.foundation/op/ST_6",
21493 ));
21494 }
21495 }
21496 crate::pipeline::ConstraintRef::Affine { coefficients, coefficient_count, bias } => {
21497 let count = *coefficient_count as usize;
21498 let mut nonzero_count: u32 = 0;
21499 let mut nonzero_index: usize = 0;
21500 let mut max_nonzero_index: usize = 0;
21501 let mut i: usize = 0;
21502 while i < count && i < crate::pipeline::AFFINE_MAX_COEFFS {
21503 if coefficients[i] != 0 {
21504 nonzero_count = nonzero_count.saturating_add(1);
21505 nonzero_index = i;
21506 if i > max_nonzero_index { max_nonzero_index = i; }
21507 }
21508 i += 1;
21509 }
21510 let touches_tag_site = nonzero_count > 0
21511 && (max_nonzero_index as u16) >= tag_site;
21512 let is_canonical_tag_pinner = nonzero_count == 1
21513 && (nonzero_index as u16) == tag_site
21514 && coefficients[nonzero_index] == 1;
21515 if is_canonical_tag_pinner {
21516 if *bias != 0 && *bias != -1 {
21517 return Err(GenericImpossibilityWitness::for_identity(
21518 "https://uor.foundation/foundation/CoproductTagEncoding",
21519 ));
21520 }
21521 if in_left_region {
21522 *left_pins = left_pins.saturating_add(1);
21523 if *bias != 0 { *left_bias_ok = false; }
21524 } else {
21525 *right_pins = right_pins.saturating_add(1);
21526 if *bias != -1 { *right_bias_ok = false; }
21527 }
21528 } else if touches_tag_site {
21529 let nonzero_only_at_tag_site = nonzero_count == 1
21530 && (nonzero_index as u16) == tag_site;
21531 if nonzero_only_at_tag_site {
21532 return Err(GenericImpossibilityWitness::for_identity(
21533 "https://uor.foundation/foundation/CoproductTagEncoding",
21534 ));
21535 } else {
21536 return Err(GenericImpossibilityWitness::for_identity(
21537 "https://uor.foundation/op/ST_6",
21538 ));
21539 }
21540 }
21541 }
21542 crate::pipeline::ConstraintRef::Conjunction { conjuncts, conjunct_count } => {
21543 if max_depth == 0 {
21544 return Err(GenericImpossibilityWitness::for_identity(
21545 "https://uor.foundation/op/ST_6",
21546 ));
21547 }
21548 let count = *conjunct_count as usize;
21549 let mut idx: usize = 0;
21550 while idx < count && idx < crate::pipeline::CONJUNCTION_MAX_TERMS {
21551 let lifted = conjuncts[idx].into_constraint();
21552 pc_classify_constraint(
21553 &lifted,
21554 in_left_region,
21555 tag_site,
21556 max_depth - 1,
21557 left_pins,
21558 right_pins,
21559 left_bias_ok,
21560 right_bias_ok,
21561 )?;
21562 idx += 1;
21563 }
21564 }
21565 crate::pipeline::ConstraintRef::Residue { .. }
21566 | crate::pipeline::ConstraintRef::Hamming { .. }
21567 | crate::pipeline::ConstraintRef::Depth { .. }
21568 | crate::pipeline::ConstraintRef::SatClauses { .. }
21569 | crate::pipeline::ConstraintRef::Bound { .. }
21570 | crate::pipeline::ConstraintRef::Recurse { .. } => {
21573 }
21575 }
21576 Ok(())
21577}
21578
21579pub(crate) fn validate_coproduct_structure(
21590 combined_constraints: &[crate::pipeline::ConstraintRef],
21591 left_constraint_count: usize,
21592 tag_site: u16,
21593) -> Result<(), GenericImpossibilityWitness> {
21594 let mut left_pins: u32 = 0;
21595 let mut right_pins: u32 = 0;
21596 let mut left_bias_ok: bool = true;
21597 let mut right_bias_ok: bool = true;
21598 let mut idx: usize = 0;
21599 while idx < combined_constraints.len() {
21600 let in_left_region = idx < left_constraint_count;
21601 pc_classify_constraint(
21602 &combined_constraints[idx],
21603 in_left_region,
21604 tag_site,
21605 NERVE_CONSTRAINTS_CAP as u32,
21606 &mut left_pins,
21607 &mut right_pins,
21608 &mut left_bias_ok,
21609 &mut right_bias_ok,
21610 )?;
21611 idx += 1;
21612 }
21613 if left_pins != 1 || right_pins != 1 {
21614 return Err(GenericImpossibilityWitness::for_identity(
21615 "https://uor.foundation/op/ST_6",
21616 ));
21617 }
21618 if !left_bias_ok || !right_bias_ok {
21619 return Err(GenericImpossibilityWitness::for_identity(
21620 "https://uor.foundation/op/ST_7",
21621 ));
21622 }
21623 Ok(())
21624}
21625
21626#[allow(clippy::too_many_arguments)]
21631pub(crate) fn pc_primitive_partition_product(
21632 witt_bits: u16,
21633 left_fingerprint: ContentFingerprint,
21634 right_fingerprint: ContentFingerprint,
21635 left_site_budget: u16,
21636 right_site_budget: u16,
21637 left_total_site_count: u16,
21638 right_total_site_count: u16,
21639 left_euler: i32,
21640 right_euler: i32,
21641 left_entropy_nats_bits: u64,
21642 right_entropy_nats_bits: u64,
21643 combined_site_budget: u16,
21644 combined_site_count: u16,
21645 combined_euler: i32,
21646 combined_entropy_nats_bits: u64,
21647 combined_fingerprint: ContentFingerprint,
21648) -> Result<PartitionProductWitness, GenericImpossibilityWitness> {
21649 let left_entropy_nats =
21650 <f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
21651 let right_entropy_nats =
21652 <f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
21653 let combined_entropy_nats =
21654 <f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
21655 if combined_site_budget != left_site_budget.saturating_add(right_site_budget) {
21656 return Err(GenericImpossibilityWitness::for_identity(
21657 "https://uor.foundation/op/PT_1",
21658 ));
21659 }
21660 if combined_site_count != left_total_site_count.saturating_add(right_total_site_count) {
21661 return Err(GenericImpossibilityWitness::for_identity(
21662 "https://uor.foundation/foundation/ProductLayoutWidth",
21663 ));
21664 }
21665 if combined_euler != left_euler.saturating_add(right_euler) {
21666 return Err(GenericImpossibilityWitness::for_identity(
21667 "https://uor.foundation/op/PT_3",
21668 ));
21669 }
21670 if !pc_entropy_input_is_valid(left_entropy_nats)
21671 || !pc_entropy_input_is_valid(right_entropy_nats)
21672 || !pc_entropy_input_is_valid(combined_entropy_nats)
21673 {
21674 return Err(GenericImpossibilityWitness::for_identity(
21675 "https://uor.foundation/op/PT_4",
21676 ));
21677 }
21678 let expected_entropy = left_entropy_nats + right_entropy_nats;
21679 if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
21680 return Err(GenericImpossibilityWitness::for_identity(
21681 "https://uor.foundation/op/PT_4",
21682 ));
21683 }
21684 Ok(PartitionProductWitness::with_level_fingerprints_and_sites(
21685 witt_bits,
21686 combined_fingerprint,
21687 left_fingerprint,
21688 right_fingerprint,
21689 combined_site_budget,
21690 combined_site_count,
21691 ))
21692}
21693
21694#[allow(clippy::too_many_arguments)]
21699pub(crate) fn pc_primitive_partition_coproduct(
21700 witt_bits: u16,
21701 left_fingerprint: ContentFingerprint,
21702 right_fingerprint: ContentFingerprint,
21703 left_site_budget: u16,
21704 right_site_budget: u16,
21705 left_total_site_count: u16,
21706 right_total_site_count: u16,
21707 left_euler: i32,
21708 right_euler: i32,
21709 left_entropy_nats_bits: u64,
21710 right_entropy_nats_bits: u64,
21711 left_betti: [u32; MAX_BETTI_DIMENSION],
21712 right_betti: [u32; MAX_BETTI_DIMENSION],
21713 combined_site_budget: u16,
21714 combined_site_count: u16,
21715 combined_euler: i32,
21716 combined_entropy_nats_bits: u64,
21717 combined_betti: [u32; MAX_BETTI_DIMENSION],
21718 combined_fingerprint: ContentFingerprint,
21719 combined_constraints: &[crate::pipeline::ConstraintRef],
21720 left_constraint_count: usize,
21721 tag_site: u16,
21722) -> Result<PartitionCoproductWitness, GenericImpossibilityWitness> {
21723 let left_entropy_nats =
21724 <f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
21725 let right_entropy_nats =
21726 <f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
21727 let combined_entropy_nats =
21728 <f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
21729 let expected_budget = if left_site_budget > right_site_budget {
21730 left_site_budget
21731 } else {
21732 right_site_budget
21733 };
21734 if combined_site_budget != expected_budget {
21735 return Err(GenericImpossibilityWitness::for_identity(
21736 "https://uor.foundation/op/ST_1",
21737 ));
21738 }
21739 let max_total = if left_total_site_count > right_total_site_count {
21740 left_total_site_count
21741 } else {
21742 right_total_site_count
21743 };
21744 let expected_total = max_total.saturating_add(1);
21745 if combined_site_count != expected_total {
21746 return Err(GenericImpossibilityWitness::for_identity(
21747 "https://uor.foundation/foundation/CoproductLayoutWidth",
21748 ));
21749 }
21750 if !pc_entropy_input_is_valid(left_entropy_nats)
21751 || !pc_entropy_input_is_valid(right_entropy_nats)
21752 || !pc_entropy_input_is_valid(combined_entropy_nats)
21753 {
21754 return Err(GenericImpossibilityWitness::for_identity(
21755 "https://uor.foundation/op/ST_2",
21756 ));
21757 }
21758 let max_operand_entropy = if left_entropy_nats > right_entropy_nats {
21759 left_entropy_nats
21760 } else {
21761 right_entropy_nats
21762 };
21763 let expected_entropy = core::f64::consts::LN_2 + max_operand_entropy;
21764 if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
21765 return Err(GenericImpossibilityWitness::for_identity(
21766 "https://uor.foundation/op/ST_2",
21767 ));
21768 }
21769 if tag_site != max_total {
21770 return Err(GenericImpossibilityWitness::for_identity(
21771 "https://uor.foundation/foundation/CoproductLayoutWidth",
21772 ));
21773 }
21774 validate_coproduct_structure(combined_constraints, left_constraint_count, tag_site)?;
21775 if combined_euler != left_euler.saturating_add(right_euler) {
21776 return Err(GenericImpossibilityWitness::for_identity(
21777 "https://uor.foundation/op/ST_9",
21778 ));
21779 }
21780 let mut k: usize = 0;
21781 while k < MAX_BETTI_DIMENSION {
21782 if combined_betti[k] != left_betti[k].saturating_add(right_betti[k]) {
21783 return Err(GenericImpossibilityWitness::for_identity(
21784 "https://uor.foundation/op/ST_10",
21785 ));
21786 }
21787 k += 1;
21788 }
21789 Ok(
21790 PartitionCoproductWitness::with_level_fingerprints_sites_and_tag(
21791 witt_bits,
21792 combined_fingerprint,
21793 left_fingerprint,
21794 right_fingerprint,
21795 combined_site_budget,
21796 combined_site_count,
21797 max_total,
21798 ),
21799 )
21800}
21801
21802#[allow(clippy::too_many_arguments)]
21807pub(crate) fn pc_primitive_cartesian_product(
21808 witt_bits: u16,
21809 left_fingerprint: ContentFingerprint,
21810 right_fingerprint: ContentFingerprint,
21811 left_site_budget: u16,
21812 right_site_budget: u16,
21813 left_total_site_count: u16,
21814 right_total_site_count: u16,
21815 left_euler: i32,
21816 right_euler: i32,
21817 left_betti: [u32; MAX_BETTI_DIMENSION],
21818 right_betti: [u32; MAX_BETTI_DIMENSION],
21819 left_entropy_nats_bits: u64,
21820 right_entropy_nats_bits: u64,
21821 combined_site_budget: u16,
21822 combined_site_count: u16,
21823 combined_euler: i32,
21824 combined_betti: [u32; MAX_BETTI_DIMENSION],
21825 combined_entropy_nats_bits: u64,
21826 combined_fingerprint: ContentFingerprint,
21827) -> Result<CartesianProductWitness, GenericImpossibilityWitness> {
21828 let left_entropy_nats =
21829 <f64 as crate::DecimalTranscendental>::from_bits(left_entropy_nats_bits);
21830 let right_entropy_nats =
21831 <f64 as crate::DecimalTranscendental>::from_bits(right_entropy_nats_bits);
21832 let combined_entropy_nats =
21833 <f64 as crate::DecimalTranscendental>::from_bits(combined_entropy_nats_bits);
21834 if combined_site_budget != left_site_budget.saturating_add(right_site_budget) {
21835 return Err(GenericImpossibilityWitness::for_identity(
21836 "https://uor.foundation/op/CPT_1",
21837 ));
21838 }
21839 if combined_site_count != left_total_site_count.saturating_add(right_total_site_count) {
21840 return Err(GenericImpossibilityWitness::for_identity(
21841 "https://uor.foundation/foundation/CartesianLayoutWidth",
21842 ));
21843 }
21844 if combined_euler != left_euler.saturating_mul(right_euler) {
21845 return Err(GenericImpossibilityWitness::for_identity(
21846 "https://uor.foundation/op/CPT_3",
21847 ));
21848 }
21849 let kunneth = crate::pipeline::kunneth_compose(&left_betti, &right_betti);
21850 let mut k: usize = 0;
21851 while k < MAX_BETTI_DIMENSION {
21852 if combined_betti[k] != kunneth[k] {
21853 return Err(GenericImpossibilityWitness::for_identity(
21854 "https://uor.foundation/op/CPT_4",
21855 ));
21856 }
21857 k += 1;
21858 }
21859 if !pc_entropy_input_is_valid(left_entropy_nats)
21860 || !pc_entropy_input_is_valid(right_entropy_nats)
21861 || !pc_entropy_input_is_valid(combined_entropy_nats)
21862 {
21863 return Err(GenericImpossibilityWitness::for_identity(
21864 "https://uor.foundation/op/CPT_5",
21865 ));
21866 }
21867 let expected_entropy = left_entropy_nats + right_entropy_nats;
21868 if !pc_entropy_additivity_holds(combined_entropy_nats, expected_entropy) {
21869 return Err(GenericImpossibilityWitness::for_identity(
21870 "https://uor.foundation/op/CPT_5",
21871 ));
21872 }
21873 Ok(
21874 CartesianProductWitness::with_level_fingerprints_and_invariants(
21875 witt_bits,
21876 combined_fingerprint,
21877 left_fingerprint,
21878 right_fingerprint,
21879 combined_site_budget,
21880 combined_site_count,
21881 combined_euler,
21882 combined_betti,
21883 ),
21884 )
21885}
21886
21887impl VerifiedMint for PartitionProductWitness {
21888 type Inputs = PartitionProductMintInputs;
21889 type Error = GenericImpossibilityWitness;
21890 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
21891 pc_primitive_partition_product(
21892 inputs.witt_bits,
21893 inputs.left_fingerprint,
21894 inputs.right_fingerprint,
21895 inputs.left_site_budget,
21896 inputs.right_site_budget,
21897 inputs.left_total_site_count,
21898 inputs.right_total_site_count,
21899 inputs.left_euler,
21900 inputs.right_euler,
21901 inputs.left_entropy_nats_bits,
21902 inputs.right_entropy_nats_bits,
21903 inputs.combined_site_budget,
21904 inputs.combined_site_count,
21905 inputs.combined_euler,
21906 inputs.combined_entropy_nats_bits,
21907 inputs.combined_fingerprint,
21908 )
21909 }
21910}
21911
21912impl VerifiedMint for PartitionCoproductWitness {
21913 type Inputs = PartitionCoproductMintInputs;
21914 type Error = GenericImpossibilityWitness;
21915 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
21916 pc_primitive_partition_coproduct(
21917 inputs.witt_bits,
21918 inputs.left_fingerprint,
21919 inputs.right_fingerprint,
21920 inputs.left_site_budget,
21921 inputs.right_site_budget,
21922 inputs.left_total_site_count,
21923 inputs.right_total_site_count,
21924 inputs.left_euler,
21925 inputs.right_euler,
21926 inputs.left_entropy_nats_bits,
21927 inputs.right_entropy_nats_bits,
21928 inputs.left_betti,
21929 inputs.right_betti,
21930 inputs.combined_site_budget,
21931 inputs.combined_site_count,
21932 inputs.combined_euler,
21933 inputs.combined_entropy_nats_bits,
21934 inputs.combined_betti,
21935 inputs.combined_fingerprint,
21936 inputs.combined_constraints,
21937 inputs.left_constraint_count,
21938 inputs.tag_site,
21939 )
21940 }
21941}
21942
21943impl VerifiedMint for CartesianProductWitness {
21944 type Inputs = CartesianProductMintInputs;
21945 type Error = GenericImpossibilityWitness;
21946 fn mint_verified(inputs: Self::Inputs) -> Result<Self, Self::Error> {
21947 pc_primitive_cartesian_product(
21948 inputs.witt_bits,
21949 inputs.left_fingerprint,
21950 inputs.right_fingerprint,
21951 inputs.left_site_budget,
21952 inputs.right_site_budget,
21953 inputs.left_total_site_count,
21954 inputs.right_total_site_count,
21955 inputs.left_euler,
21956 inputs.right_euler,
21957 inputs.left_betti,
21958 inputs.right_betti,
21959 inputs.left_entropy_nats_bits,
21960 inputs.right_entropy_nats_bits,
21961 inputs.combined_site_budget,
21962 inputs.combined_site_count,
21963 inputs.combined_euler,
21964 inputs.combined_betti,
21965 inputs.combined_entropy_nats_bits,
21966 inputs.combined_fingerprint,
21967 )
21968 }
21969}
21970
21971#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21978pub struct PartitionRecord<H: crate::HostTypes> {
21979 pub site_budget: u16,
21981 pub euler: i32,
21983 pub betti: [u32; MAX_BETTI_DIMENSION],
21985 pub entropy_nats_bits: u64,
21987 _phantom: core::marker::PhantomData<H>,
21988}
21989
21990impl<H: crate::HostTypes> PartitionRecord<H> {
21991 #[inline]
21994 #[must_use]
21995 pub const fn new(
21996 site_budget: u16,
21997 euler: i32,
21998 betti: [u32; MAX_BETTI_DIMENSION],
21999 entropy_nats_bits: u64,
22000 ) -> Self {
22001 Self {
22002 site_budget,
22003 euler,
22004 betti,
22005 entropy_nats_bits,
22006 _phantom: core::marker::PhantomData,
22007 }
22008 }
22009}
22010
22011pub trait PartitionResolver<H: crate::HostTypes> {
22016 fn resolve(&self, fp: ContentFingerprint) -> Option<PartitionRecord<H>>;
22020}
22021
22022#[derive(Debug)]
22028pub struct PartitionHandle<H: crate::HostTypes> {
22029 fingerprint: ContentFingerprint,
22030 _phantom: core::marker::PhantomData<H>,
22031}
22032impl<H: crate::HostTypes> Copy for PartitionHandle<H> {}
22033impl<H: crate::HostTypes> Clone for PartitionHandle<H> {
22034 #[inline]
22035 fn clone(&self) -> Self {
22036 *self
22037 }
22038}
22039impl<H: crate::HostTypes> PartialEq for PartitionHandle<H> {
22040 #[inline]
22041 fn eq(&self, other: &Self) -> bool {
22042 self.fingerprint == other.fingerprint
22043 }
22044}
22045impl<H: crate::HostTypes> Eq for PartitionHandle<H> {}
22046impl<H: crate::HostTypes> core::hash::Hash for PartitionHandle<H> {
22047 #[inline]
22048 fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
22049 self.fingerprint.hash(state);
22050 }
22051}
22052
22053impl<H: crate::HostTypes> PartitionHandle<H> {
22054 #[inline]
22056 #[must_use]
22057 pub const fn from_fingerprint(fingerprint: ContentFingerprint) -> Self {
22058 Self {
22059 fingerprint,
22060 _phantom: core::marker::PhantomData,
22061 }
22062 }
22063 #[inline]
22065 #[must_use]
22066 pub const fn fingerprint(&self) -> ContentFingerprint {
22067 self.fingerprint
22068 }
22069 #[inline]
22072 pub fn resolve_with<R: PartitionResolver<H>>(
22073 &self,
22074 resolver: &R,
22075 ) -> Option<PartitionRecord<H>> {
22076 resolver.resolve(self.fingerprint)
22077 }
22078}
22079
22080#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22084pub struct NullElement<H: HostTypes> {
22085 _phantom: core::marker::PhantomData<H>,
22086}
22087impl<H: HostTypes> Default for NullElement<H> {
22088 fn default() -> Self {
22089 Self {
22090 _phantom: core::marker::PhantomData,
22091 }
22092 }
22093}
22094impl<H: HostTypes> crate::kernel::address::Element<H> for NullElement<H> {
22095 fn length(&self) -> u64 {
22096 0
22097 }
22098 fn addresses(&self) -> &H::HostString {
22099 H::EMPTY_HOST_STRING
22100 }
22101 fn digest(&self) -> &H::HostString {
22102 H::EMPTY_HOST_STRING
22103 }
22104 fn digest_algorithm(&self) -> &H::HostString {
22105 H::EMPTY_HOST_STRING
22106 }
22107 fn canonical_bytes(&self) -> &H::WitnessBytes {
22108 H::EMPTY_WITNESS_BYTES
22109 }
22110 fn witt_length(&self) -> u64 {
22111 0
22112 }
22113}
22114
22115#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22117pub struct NullDatum<H: HostTypes> {
22118 element: NullElement<H>,
22119 _phantom: core::marker::PhantomData<H>,
22120}
22121impl<H: HostTypes> Default for NullDatum<H> {
22122 fn default() -> Self {
22123 Self {
22124 element: NullElement::default(),
22125 _phantom: core::marker::PhantomData,
22126 }
22127 }
22128}
22129impl<H: HostTypes> crate::kernel::schema::Datum<H> for NullDatum<H> {
22130 fn value(&self) -> u64 {
22131 0
22132 }
22133 fn witt_length(&self) -> u64 {
22134 0
22135 }
22136 fn stratum(&self) -> u64 {
22137 0
22138 }
22139 fn spectrum(&self) -> u64 {
22140 0
22141 }
22142 type Element = NullElement<H>;
22143 fn element(&self) -> &Self::Element {
22144 &self.element
22145 }
22146}
22147
22148#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22150pub struct NullTermExpression<H: HostTypes> {
22151 _phantom: core::marker::PhantomData<H>,
22152}
22153impl<H: HostTypes> Default for NullTermExpression<H> {
22154 fn default() -> Self {
22155 Self {
22156 _phantom: core::marker::PhantomData,
22157 }
22158 }
22159}
22160impl<H: HostTypes> crate::kernel::schema::TermExpression<H> for NullTermExpression<H> {}
22161
22162#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22165pub struct NullSiteIndex<H: HostTypes> {
22166 _phantom: core::marker::PhantomData<H>,
22167}
22168impl<H: HostTypes> Default for NullSiteIndex<H> {
22169 fn default() -> Self {
22170 Self {
22171 _phantom: core::marker::PhantomData,
22172 }
22173 }
22174}
22175impl<H: HostTypes> crate::bridge::partition::SiteIndex<H> for NullSiteIndex<H> {
22176 fn site_position(&self) -> u64 {
22177 0
22178 }
22179 fn site_state(&self) -> u64 {
22180 0
22181 }
22182 type SiteIndexTarget = NullSiteIndex<H>;
22183 fn ancilla_site(&self) -> &Self::SiteIndexTarget {
22184 self
22185 }
22186}
22187
22188#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22192pub struct NullTagSite<H: HostTypes> {
22193 ancilla: NullSiteIndex<H>,
22194}
22195impl<H: HostTypes> Default for NullTagSite<H> {
22196 fn default() -> Self {
22197 Self {
22198 ancilla: NullSiteIndex::default(),
22199 }
22200 }
22201}
22202impl<H: HostTypes> crate::bridge::partition::SiteIndex<H> for NullTagSite<H> {
22203 fn site_position(&self) -> u64 {
22204 0
22205 }
22206 fn site_state(&self) -> u64 {
22207 0
22208 }
22209 type SiteIndexTarget = NullSiteIndex<H>;
22210 fn ancilla_site(&self) -> &Self::SiteIndexTarget {
22211 &self.ancilla
22212 }
22213}
22214impl<H: HostTypes> crate::bridge::partition::TagSite<H> for NullTagSite<H> {
22215 fn tag_value(&self) -> bool {
22216 false
22217 }
22218}
22219
22220#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22223pub struct NullSiteBinding<H: HostTypes> {
22224 constraint: NullConstraint<H>,
22225 site_index: NullSiteIndex<H>,
22226}
22227impl<H: HostTypes> Default for NullSiteBinding<H> {
22228 fn default() -> Self {
22229 Self {
22230 constraint: NullConstraint::default(),
22231 site_index: NullSiteIndex::default(),
22232 }
22233 }
22234}
22235impl<H: HostTypes> crate::bridge::partition::SiteBinding<H> for NullSiteBinding<H> {
22236 type Constraint = NullConstraint<H>;
22237 fn pinned_by(&self) -> &Self::Constraint {
22238 &self.constraint
22239 }
22240 type SiteIndex = NullSiteIndex<H>;
22241 fn pins_coordinate(&self) -> &Self::SiteIndex {
22242 &self.site_index
22243 }
22244}
22245
22246#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22249pub struct NullConstraint<H: HostTypes> {
22250 _phantom: core::marker::PhantomData<H>,
22251}
22252impl<H: HostTypes> Default for NullConstraint<H> {
22253 fn default() -> Self {
22254 Self {
22255 _phantom: core::marker::PhantomData,
22256 }
22257 }
22258}
22259impl<H: HostTypes> crate::user::type_::Constraint<H> for NullConstraint<H> {
22260 fn metric_axis(&self) -> MetricAxis {
22261 MetricAxis::Vertical
22262 }
22263 type SiteIndex = NullSiteIndex<H>;
22264 fn pins_sites(&self) -> &[Self::SiteIndex] {
22265 &[]
22266 }
22267 fn crossing_cost(&self) -> u64 {
22268 0
22269 }
22270}
22271
22272#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22275pub struct NullFreeRank<H: HostTypes> {
22276 _phantom: core::marker::PhantomData<H>,
22277}
22278impl<H: HostTypes> Default for NullFreeRank<H> {
22279 fn default() -> Self {
22280 Self {
22281 _phantom: core::marker::PhantomData,
22282 }
22283 }
22284}
22285impl<H: HostTypes> crate::bridge::partition::FreeRank<H> for NullFreeRank<H> {
22286 fn total_sites(&self) -> u64 {
22287 0
22288 }
22289 fn pinned_count(&self) -> u64 {
22290 0
22291 }
22292 fn free_rank(&self) -> u64 {
22293 0
22294 }
22295 fn is_closed(&self) -> bool {
22296 true
22297 }
22298 type SiteIndex = NullSiteIndex<H>;
22299 fn has_site(&self) -> &[Self::SiteIndex] {
22300 &[]
22301 }
22302 type SiteBinding = NullSiteBinding<H>;
22303 fn has_binding(&self) -> &[Self::SiteBinding] {
22304 &[]
22305 }
22306 fn reversible_strategy(&self) -> bool {
22307 false
22308 }
22309}
22310
22311#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22314pub struct NullIrreducibleSet<H: HostTypes> {
22315 _phantom: core::marker::PhantomData<H>,
22316}
22317impl<H: HostTypes> Default for NullIrreducibleSet<H> {
22318 fn default() -> Self {
22319 Self {
22320 _phantom: core::marker::PhantomData,
22321 }
22322 }
22323}
22324impl<H: HostTypes> crate::bridge::partition::Component<H> for NullIrreducibleSet<H> {
22325 type Datum = NullDatum<H>;
22326 fn member(&self) -> &[Self::Datum] {
22327 &[]
22328 }
22329 fn cardinality(&self) -> u64 {
22330 0
22331 }
22332}
22333impl<H: HostTypes> crate::bridge::partition::IrreducibleSet<H> for NullIrreducibleSet<H> {}
22334
22335#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22338pub struct NullReducibleSet<H: HostTypes> {
22339 _phantom: core::marker::PhantomData<H>,
22340}
22341impl<H: HostTypes> Default for NullReducibleSet<H> {
22342 fn default() -> Self {
22343 Self {
22344 _phantom: core::marker::PhantomData,
22345 }
22346 }
22347}
22348impl<H: HostTypes> crate::bridge::partition::Component<H> for NullReducibleSet<H> {
22349 type Datum = NullDatum<H>;
22350 fn member(&self) -> &[Self::Datum] {
22351 &[]
22352 }
22353 fn cardinality(&self) -> u64 {
22354 0
22355 }
22356}
22357impl<H: HostTypes> crate::bridge::partition::ReducibleSet<H> for NullReducibleSet<H> {}
22358
22359#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22362pub struct NullUnitGroup<H: HostTypes> {
22363 _phantom: core::marker::PhantomData<H>,
22364}
22365impl<H: HostTypes> Default for NullUnitGroup<H> {
22366 fn default() -> Self {
22367 Self {
22368 _phantom: core::marker::PhantomData,
22369 }
22370 }
22371}
22372impl<H: HostTypes> crate::bridge::partition::Component<H> for NullUnitGroup<H> {
22373 type Datum = NullDatum<H>;
22374 fn member(&self) -> &[Self::Datum] {
22375 &[]
22376 }
22377 fn cardinality(&self) -> u64 {
22378 0
22379 }
22380}
22381impl<H: HostTypes> crate::bridge::partition::UnitGroup<H> for NullUnitGroup<H> {}
22382
22383#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22387pub struct NullComplement<H: HostTypes> {
22388 term: NullTermExpression<H>,
22389}
22390impl<H: HostTypes> Default for NullComplement<H> {
22391 fn default() -> Self {
22392 Self {
22393 term: NullTermExpression::default(),
22394 }
22395 }
22396}
22397impl<H: HostTypes> crate::bridge::partition::Component<H> for NullComplement<H> {
22398 type Datum = NullDatum<H>;
22399 fn member(&self) -> &[Self::Datum] {
22400 &[]
22401 }
22402 fn cardinality(&self) -> u64 {
22403 0
22404 }
22405}
22406impl<H: HostTypes> crate::bridge::partition::Complement<H> for NullComplement<H> {
22407 type TermExpression = NullTermExpression<H>;
22408 fn exterior_criteria(&self) -> &Self::TermExpression {
22409 &self.term
22410 }
22411}
22412
22413#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22416pub struct NullTypeDefinition<H: HostTypes> {
22417 element: NullElement<H>,
22418}
22419impl<H: HostTypes> Default for NullTypeDefinition<H> {
22420 fn default() -> Self {
22421 Self {
22422 element: NullElement::default(),
22423 }
22424 }
22425}
22426impl<H: HostTypes> crate::user::type_::TypeDefinition<H> for NullTypeDefinition<H> {
22427 type Element = NullElement<H>;
22428 fn content_address(&self) -> &Self::Element {
22429 &self.element
22430 }
22431}
22432
22433#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22442pub struct NullPartition<H: HostTypes> {
22443 irreducibles: NullIrreducibleSet<H>,
22444 reducibles: NullReducibleSet<H>,
22445 units: NullUnitGroup<H>,
22446 exterior: NullComplement<H>,
22447 free_rank: NullFreeRank<H>,
22448 tag_site: NullTagSite<H>,
22449 source_type: NullTypeDefinition<H>,
22450 fingerprint: ContentFingerprint,
22451}
22452
22453impl<H: HostTypes> NullPartition<H> {
22454 #[inline]
22457 #[must_use]
22458 pub fn from_fingerprint(fingerprint: ContentFingerprint) -> Self {
22459 Self {
22460 irreducibles: NullIrreducibleSet::default(),
22461 reducibles: NullReducibleSet::default(),
22462 units: NullUnitGroup::default(),
22463 exterior: NullComplement::default(),
22464 free_rank: NullFreeRank::default(),
22465 tag_site: NullTagSite::default(),
22466 source_type: NullTypeDefinition::default(),
22467 fingerprint,
22468 }
22469 }
22470 #[inline]
22472 #[must_use]
22473 pub const fn fingerprint(&self) -> ContentFingerprint {
22474 self.fingerprint
22475 }
22476 pub const ABSENT: NullPartition<H> = NullPartition {
22479 irreducibles: NullIrreducibleSet {
22480 _phantom: core::marker::PhantomData,
22481 },
22482 reducibles: NullReducibleSet {
22483 _phantom: core::marker::PhantomData,
22484 },
22485 units: NullUnitGroup {
22486 _phantom: core::marker::PhantomData,
22487 },
22488 exterior: NullComplement {
22489 term: NullTermExpression {
22490 _phantom: core::marker::PhantomData,
22491 },
22492 },
22493 free_rank: NullFreeRank {
22494 _phantom: core::marker::PhantomData,
22495 },
22496 tag_site: NullTagSite {
22497 ancilla: NullSiteIndex {
22498 _phantom: core::marker::PhantomData,
22499 },
22500 },
22501 source_type: NullTypeDefinition {
22502 element: NullElement {
22503 _phantom: core::marker::PhantomData,
22504 },
22505 },
22506 fingerprint: ContentFingerprint::zero(),
22507 };
22508}
22509
22510impl<H: HostTypes> crate::bridge::partition::Partition<H> for NullPartition<H> {
22511 type IrreducibleSet = NullIrreducibleSet<H>;
22512 fn irreducibles(&self) -> &Self::IrreducibleSet {
22513 &self.irreducibles
22514 }
22515 type ReducibleSet = NullReducibleSet<H>;
22516 fn reducibles(&self) -> &Self::ReducibleSet {
22517 &self.reducibles
22518 }
22519 type UnitGroup = NullUnitGroup<H>;
22520 fn units(&self) -> &Self::UnitGroup {
22521 &self.units
22522 }
22523 type Complement = NullComplement<H>;
22524 fn exterior(&self) -> &Self::Complement {
22525 &self.exterior
22526 }
22527 fn density(&self) -> H::Decimal {
22528 H::EMPTY_DECIMAL
22529 }
22530 type TypeDefinition = NullTypeDefinition<H>;
22531 fn source_type(&self) -> &Self::TypeDefinition {
22532 &self.source_type
22533 }
22534 fn witt_length(&self) -> u64 {
22535 0
22536 }
22537 type FreeRank = NullFreeRank<H>;
22538 fn site_budget(&self) -> &Self::FreeRank {
22539 &self.free_rank
22540 }
22541 fn is_exhaustive(&self) -> bool {
22542 true
22543 }
22544 type TagSite = NullTagSite<H>;
22545 fn tag_site_of(&self) -> &Self::TagSite {
22546 &self.tag_site
22547 }
22548 fn product_category_level(&self) -> &H::HostString {
22549 H::EMPTY_HOST_STRING
22550 }
22551}
22552
22553impl<H: HostTypes> crate::bridge::partition::PartitionProduct<H> for PartitionProductWitness {
22554 type Partition = NullPartition<H>;
22555 fn left_factor(&self) -> Self::Partition {
22556 NullPartition::from_fingerprint(self.left_fingerprint)
22557 }
22558 fn right_factor(&self) -> Self::Partition {
22559 NullPartition::from_fingerprint(self.right_fingerprint)
22560 }
22561}
22562
22563impl<H: HostTypes> crate::bridge::partition::PartitionCoproduct<H> for PartitionCoproductWitness {
22564 type Partition = NullPartition<H>;
22565 fn left_summand(&self) -> Self::Partition {
22566 NullPartition::from_fingerprint(self.left_fingerprint)
22567 }
22568 fn right_summand(&self) -> Self::Partition {
22569 NullPartition::from_fingerprint(self.right_fingerprint)
22570 }
22571}
22572
22573impl<H: HostTypes> crate::bridge::partition::CartesianPartitionProduct<H>
22574 for CartesianProductWitness
22575{
22576 type Partition = NullPartition<H>;
22577 fn left_cartesian_factor(&self) -> Self::Partition {
22578 NullPartition::from_fingerprint(self.left_fingerprint)
22579 }
22580 fn right_cartesian_factor(&self) -> Self::Partition {
22581 NullPartition::from_fingerprint(self.right_fingerprint)
22582 }
22583}
22584
22585pub mod prelude {
22592 pub use super::calibrations;
22593 pub use super::Add;
22594 pub use super::And;
22595 pub use super::BNot;
22596 pub use super::BinaryGroundingMap;
22597 pub use super::BindingEntry;
22598 pub use super::BindingsTable;
22599 pub use super::BornRuleVerification;
22600 pub use super::Calibration;
22601 pub use super::CalibrationError;
22602 pub use super::CanonicalTimingPolicy;
22603 pub use super::Certificate;
22604 pub use super::Certified;
22605 pub use super::ChainAuditTrail;
22606 pub use super::CompileTime;
22607 pub use super::CompileUnit;
22608 pub use super::CompileUnitBuilder;
22609 pub use super::CompletenessAuditTrail;
22610 pub use super::CompletenessCertificate;
22611 pub use super::ConstrainedTypeInput;
22612 pub use super::ContentAddress;
22613 pub use super::ContentFingerprint;
22614 pub use super::Datum;
22615 pub use super::DigestGroundingMap;
22616 pub use super::Embed;
22617 pub use super::FragmentMarker;
22618 pub use super::GenericImpossibilityWitness;
22619 pub use super::GeodesicCertificate;
22620 pub use super::GeodesicEvidenceBundle;
22621 pub use super::Grounded;
22622 pub use super::GroundedCoord;
22623 pub use super::GroundedShape;
22624 pub use super::GroundedTuple;
22625 pub use super::GroundedValue;
22626 pub use super::Grounding;
22627 pub use super::GroundingCertificate;
22628 pub use super::GroundingExt;
22629 pub use super::GroundingMapKind;
22630 pub use super::GroundingProgram;
22631 pub use super::Hasher;
22632 pub use super::ImpossibilityWitnessKind;
22633 pub use super::InhabitanceCertificate;
22634 pub use super::InhabitanceImpossibilityWitness;
22635 pub use super::IntegerGroundingMap;
22636 pub use super::Invertible;
22637 pub use super::InvolutionCertificate;
22638 pub use super::IsometryCertificate;
22639 pub use super::JsonGroundingMap;
22640 pub use super::LandauerBudget;
22641 pub use super::LiftChainCertificate;
22642 pub use super::MeasurementCertificate;
22643 pub use super::Mul;
22644 pub use super::Nanos;
22645 pub use super::Neg;
22646 pub use super::OntologyTarget;
22647 pub use super::Or;
22648 pub use super::PipelineFailure;
22649 pub use super::PreservesMetric;
22650 pub use super::PreservesStructure;
22651 pub use super::RingOp;
22652 pub use super::Runtime;
22653 pub use super::ShapeViolation;
22654 pub use super::Sub;
22655 pub use super::Succ;
22656 pub use super::Term;
22657 pub use super::TermArena;
22658 pub use super::TimingPolicy;
22659 pub use super::Total;
22660 pub use super::TransformCertificate;
22661 pub use super::Triad;
22662 pub use super::UnaryRingOp;
22663 pub use super::UorTime;
22664 pub use super::Utf8GroundingMap;
22665 pub use super::ValidLevelEmbedding;
22666 pub use super::Validated;
22667 pub use super::ValidationPhase;
22668 pub use super::Xor;
22669 pub use super::W16;
22670 pub use super::W8;
22671 pub use crate::pipeline::empty_bindings_table;
22672 pub use crate::pipeline::{
22673 validate_constrained_type, validate_constrained_type_const, ConstrainedTypeShape,
22674 ConstraintRef, FragmentKind,
22675 };
22676 pub use crate::{DecimalTranscendental, DefaultHostTypes, HostTypes, WittLevel};
22677}