1#![allow(clippy::module_name_repetitions)]
25
26use crate::bridge::derivation::DerivationDepthObservable;
27use crate::bridge::observable::{JacobianObservable, LandauerBudget, Observable, ThermoObservable};
28use crate::bridge::partition::FreeRankObservable;
29use crate::enforcement::{Validated, ValidationPhase};
30use crate::enums::MeasurementUnit;
31use crate::kernel::carry::CarryDepthObservable;
32use crate::pipeline::ConstrainedTypeShape;
33use crate::{DecimalTranscendental, HostTypes};
34
35pub struct ValidatedLandauerView<T, Phase: ValidationPhase>(
47 core::marker::PhantomData<(fn() -> T, Phase)>,
48);
49
50pub struct ValidatedJacobianView<T, Phase: ValidationPhase>(
54 core::marker::PhantomData<(fn() -> T, Phase)>,
55);
56
57pub struct ValidatedCarryDepthView<T, Phase: ValidationPhase>(
61 core::marker::PhantomData<(fn() -> T, Phase)>,
62);
63
64pub struct ValidatedDerivationDepthView<T, Phase: ValidationPhase>(
68 core::marker::PhantomData<(fn() -> T, Phase)>,
69);
70
71pub struct ValidatedFreeRankView<T, Phase: ValidationPhase>(
75 core::marker::PhantomData<(fn() -> T, Phase)>,
76);
77
78macro_rules! impl_view_traits {
84 ($name:ident, $label:literal) => {
85 impl<T, Phase: ValidationPhase> core::fmt::Debug for $name<T, Phase> {
86 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
87 f.write_str($label)
88 }
89 }
90 impl<T, Phase: ValidationPhase> Default for $name<T, Phase> {
91 #[inline]
92 fn default() -> Self {
93 Self(core::marker::PhantomData)
94 }
95 }
96 impl<T, Phase: ValidationPhase> Clone for $name<T, Phase> {
97 #[inline]
98 fn clone(&self) -> Self {
99 *self
100 }
101 }
102 impl<T, Phase: ValidationPhase> Copy for $name<T, Phase> {}
103 impl<T, Phase: ValidationPhase> PartialEq for $name<T, Phase> {
104 #[inline]
105 fn eq(&self, _other: &Self) -> bool {
106 true
107 }
108 }
109 impl<T, Phase: ValidationPhase> Eq for $name<T, Phase> {}
110 impl<T, Phase: ValidationPhase> core::hash::Hash for $name<T, Phase> {
111 #[inline]
112 fn hash<S: core::hash::Hasher>(&self, _state: &mut S) {}
113 }
114 };
115}
116
117impl_view_traits!(ValidatedLandauerView, "ValidatedLandauerView");
118impl_view_traits!(ValidatedJacobianView, "ValidatedJacobianView");
119impl_view_traits!(ValidatedCarryDepthView, "ValidatedCarryDepthView");
120impl_view_traits!(ValidatedDerivationDepthView, "ValidatedDerivationDepthView");
121impl_view_traits!(ValidatedFreeRankView, "ValidatedFreeRankView");
122
123impl<T, Phase: ValidationPhase> ValidatedLandauerView<T, Phase> {
126 #[inline]
129 #[must_use]
130 pub const fn new() -> Self {
131 Self(core::marker::PhantomData)
132 }
133}
134
135impl<T, Phase: ValidationPhase> ValidatedJacobianView<T, Phase> {
136 #[inline]
139 #[must_use]
140 pub const fn new() -> Self {
141 Self(core::marker::PhantomData)
142 }
143}
144
145impl<T, Phase: ValidationPhase> ValidatedCarryDepthView<T, Phase> {
146 #[inline]
149 #[must_use]
150 pub const fn new() -> Self {
151 Self(core::marker::PhantomData)
152 }
153}
154
155impl<T, Phase: ValidationPhase> ValidatedDerivationDepthView<T, Phase> {
156 #[inline]
159 #[must_use]
160 pub const fn new() -> Self {
161 Self(core::marker::PhantomData)
162 }
163}
164
165impl<T, Phase: ValidationPhase> ValidatedFreeRankView<T, Phase> {
166 #[inline]
169 #[must_use]
170 pub const fn new() -> Self {
171 Self(core::marker::PhantomData)
172 }
173}
174
175impl<T, Phase: ValidationPhase> Validated<T, Phase>
179where
180 T: ConstrainedTypeShape,
181{
182 #[inline]
184 #[must_use]
185 pub const fn as_landauer(&self) -> ValidatedLandauerView<T, Phase> {
186 ValidatedLandauerView::new()
187 }
188
189 #[inline]
191 #[must_use]
192 pub const fn as_jacobian(&self) -> ValidatedJacobianView<T, Phase> {
193 ValidatedJacobianView::new()
194 }
195
196 #[inline]
198 #[must_use]
199 pub const fn as_carry_depth(&self) -> ValidatedCarryDepthView<T, Phase> {
200 ValidatedCarryDepthView::new()
201 }
202
203 #[inline]
205 #[must_use]
206 pub const fn as_derivation_depth(&self) -> ValidatedDerivationDepthView<T, Phase> {
207 ValidatedDerivationDepthView::new()
208 }
209
210 #[inline]
212 #[must_use]
213 pub const fn as_free_rank(&self) -> ValidatedFreeRankView<T, Phase> {
214 ValidatedFreeRankView::new()
215 }
216}
217
218#[inline]
224fn empty_source<H: HostTypes>() -> &'static H::HostString {
225 H::EMPTY_HOST_STRING
226}
227
228#[inline]
229fn empty_target<H: HostTypes>() -> &'static H::HostString {
230 H::EMPTY_HOST_STRING
231}
232
233impl<T, Phase, H> Observable<H> for ValidatedLandauerView<T, Phase>
235where
236 T: ConstrainedTypeShape,
237 Phase: ValidationPhase,
238 H: HostTypes,
239{
240 #[inline]
241 fn value(&self) -> H::Decimal {
242 <Self as LandauerBudget<H>>::landauer_nats(self)
243 }
244 #[inline]
245 fn source(&self) -> &H::HostString {
246 empty_source::<H>()
247 }
248 #[inline]
249 fn target(&self) -> &H::HostString {
250 empty_target::<H>()
251 }
252 #[inline]
253 fn has_unit(&self) -> MeasurementUnit {
254 MeasurementUnit::default()
255 }
256}
257
258impl<T, Phase, H> ThermoObservable<H> for ValidatedLandauerView<T, Phase>
259where
260 T: ConstrainedTypeShape,
261 Phase: ValidationPhase,
262 H: HostTypes,
263{
264 #[inline]
265 fn hardness_estimate(&self) -> H::Decimal {
266 H::EMPTY_DECIMAL
267 }
268}
269
270impl<T, Phase, H> LandauerBudget<H> for ValidatedLandauerView<T, Phase>
271where
272 T: ConstrainedTypeShape,
273 Phase: ValidationPhase,
274 H: HostTypes,
275{
276 #[inline]
277 fn landauer_nats(&self) -> H::Decimal {
278 let nerve = match crate::enforcement::primitive_simplicial_nerve_betti::<T>() {
279 Ok(b) => b,
280 Err(_) => return H::EMPTY_DECIMAL,
281 };
282 let (_residual, entropy_bits) = crate::enforcement::primitive_descent_metrics::<T>(&nerve);
283 <H::Decimal as DecimalTranscendental>::from_bits(entropy_bits)
284 }
285}
286
287impl<T, Phase, H> Observable<H> for ValidatedJacobianView<T, Phase>
289where
290 T: ConstrainedTypeShape,
291 Phase: ValidationPhase,
292 H: HostTypes,
293{
294 #[inline]
295 fn value(&self) -> H::Decimal {
296 let jac = crate::enforcement::primitive_curvature_jacobian::<T>();
297 let mut sum: u64 = 0;
298 let mut i = 0;
299 while i < jac.len() {
300 sum = sum.saturating_add(u64::from(jac[i].unsigned_abs()));
301 i += 1;
302 }
303 <H::Decimal as DecimalTranscendental>::from_u64(sum)
304 }
305 #[inline]
306 fn source(&self) -> &H::HostString {
307 empty_source::<H>()
308 }
309 #[inline]
310 fn target(&self) -> &H::HostString {
311 empty_target::<H>()
312 }
313 #[inline]
314 fn has_unit(&self) -> MeasurementUnit {
315 MeasurementUnit::default()
316 }
317}
318
319impl<T, Phase, H> JacobianObservable<H> for ValidatedJacobianView<T, Phase>
320where
321 T: ConstrainedTypeShape,
322 Phase: ValidationPhase,
323 H: HostTypes,
324{
325}
326
327impl<T, Phase, H> Observable<H> for ValidatedCarryDepthView<T, Phase>
329where
330 T: ConstrainedTypeShape,
331 Phase: ValidationPhase,
332 H: HostTypes,
333{
334 #[inline]
335 fn value(&self) -> H::Decimal {
336 let (orbit_size, _period) = crate::enforcement::primitive_dihedral_signature::<T>();
337 <H::Decimal as DecimalTranscendental>::from_u32(orbit_size)
338 }
339 #[inline]
340 fn source(&self) -> &H::HostString {
341 empty_source::<H>()
342 }
343 #[inline]
344 fn target(&self) -> &H::HostString {
345 empty_target::<H>()
346 }
347 #[inline]
348 fn has_unit(&self) -> MeasurementUnit {
349 MeasurementUnit::default()
350 }
351}
352
353impl<T, Phase, H> CarryDepthObservable<H> for ValidatedCarryDepthView<T, Phase>
354where
355 T: ConstrainedTypeShape,
356 Phase: ValidationPhase,
357 H: HostTypes,
358{
359}
360
361impl<T, Phase, H> Observable<H> for ValidatedDerivationDepthView<T, Phase>
363where
364 T: ConstrainedTypeShape,
365 Phase: ValidationPhase,
366 H: HostTypes,
367{
368 #[inline]
369 fn value(&self) -> H::Decimal {
370 match crate::enforcement::primitive_terminal_reduction::<T>(8u16) {
372 Ok((_witt, length, _sat)) => <H::Decimal as DecimalTranscendental>::from_u32(length),
373 Err(_) => H::EMPTY_DECIMAL,
374 }
375 }
376 #[inline]
377 fn source(&self) -> &H::HostString {
378 empty_source::<H>()
379 }
380 #[inline]
381 fn target(&self) -> &H::HostString {
382 empty_target::<H>()
383 }
384 #[inline]
385 fn has_unit(&self) -> MeasurementUnit {
386 MeasurementUnit::default()
387 }
388}
389
390impl<T, Phase, H> DerivationDepthObservable<H> for ValidatedDerivationDepthView<T, Phase>
391where
392 T: ConstrainedTypeShape,
393 Phase: ValidationPhase,
394 H: HostTypes,
395{
396}
397
398impl<T, Phase, H> Observable<H> for ValidatedFreeRankView<T, Phase>
400where
401 T: ConstrainedTypeShape,
402 Phase: ValidationPhase,
403 H: HostTypes,
404{
405 #[inline]
406 fn value(&self) -> H::Decimal {
407 let nerve = match crate::enforcement::primitive_simplicial_nerve_betti::<T>() {
408 Ok(b) => b,
409 Err(_) => return H::EMPTY_DECIMAL,
410 };
411 let (residual, _entropy_bits) = crate::enforcement::primitive_descent_metrics::<T>(&nerve);
412 <H::Decimal as DecimalTranscendental>::from_u32(residual)
413 }
414 #[inline]
415 fn source(&self) -> &H::HostString {
416 empty_source::<H>()
417 }
418 #[inline]
419 fn target(&self) -> &H::HostString {
420 empty_target::<H>()
421 }
422 #[inline]
423 fn has_unit(&self) -> MeasurementUnit {
424 MeasurementUnit::default()
425 }
426}
427
428impl<T, Phase, H> FreeRankObservable<H> for ValidatedFreeRankView<T, Phase>
429where
430 T: ConstrainedTypeShape,
431 Phase: ValidationPhase,
432 H: HostTypes,
433{
434}