#![allow(clippy::module_name_repetitions)]
use crate::bridge::derivation::DerivationDepthObservable;
use crate::bridge::observable::{JacobianObservable, LandauerBudget, Observable, ThermoObservable};
use crate::bridge::partition::FreeRankObservable;
use crate::enforcement::{Validated, ValidationPhase};
use crate::enums::MeasurementUnit;
use crate::kernel::carry::CarryDepthObservable;
use crate::pipeline::ConstrainedTypeShape;
use crate::{DecimalTranscendental, HostTypes};
pub struct ValidatedLandauerView<T, Phase: ValidationPhase>(
core::marker::PhantomData<(fn() -> T, Phase)>,
);
pub struct ValidatedJacobianView<T, Phase: ValidationPhase>(
core::marker::PhantomData<(fn() -> T, Phase)>,
);
pub struct ValidatedCarryDepthView<T, Phase: ValidationPhase>(
core::marker::PhantomData<(fn() -> T, Phase)>,
);
pub struct ValidatedDerivationDepthView<T, Phase: ValidationPhase>(
core::marker::PhantomData<(fn() -> T, Phase)>,
);
pub struct ValidatedFreeRankView<T, Phase: ValidationPhase>(
core::marker::PhantomData<(fn() -> T, Phase)>,
);
macro_rules! impl_view_traits {
($name:ident, $label:literal) => {
impl<T, Phase: ValidationPhase> core::fmt::Debug for $name<T, Phase> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str($label)
}
}
impl<T, Phase: ValidationPhase> Default for $name<T, Phase> {
#[inline]
fn default() -> Self {
Self(core::marker::PhantomData)
}
}
impl<T, Phase: ValidationPhase> Clone for $name<T, Phase> {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl<T, Phase: ValidationPhase> Copy for $name<T, Phase> {}
impl<T, Phase: ValidationPhase> PartialEq for $name<T, Phase> {
#[inline]
fn eq(&self, _other: &Self) -> bool {
true
}
}
impl<T, Phase: ValidationPhase> Eq for $name<T, Phase> {}
impl<T, Phase: ValidationPhase> core::hash::Hash for $name<T, Phase> {
#[inline]
fn hash<S: core::hash::Hasher>(&self, _state: &mut S) {}
}
};
}
impl_view_traits!(ValidatedLandauerView, "ValidatedLandauerView");
impl_view_traits!(ValidatedJacobianView, "ValidatedJacobianView");
impl_view_traits!(ValidatedCarryDepthView, "ValidatedCarryDepthView");
impl_view_traits!(ValidatedDerivationDepthView, "ValidatedDerivationDepthView");
impl_view_traits!(ValidatedFreeRankView, "ValidatedFreeRankView");
impl<T, Phase: ValidationPhase> ValidatedLandauerView<T, Phase> {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self(core::marker::PhantomData)
}
}
impl<T, Phase: ValidationPhase> ValidatedJacobianView<T, Phase> {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self(core::marker::PhantomData)
}
}
impl<T, Phase: ValidationPhase> ValidatedCarryDepthView<T, Phase> {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self(core::marker::PhantomData)
}
}
impl<T, Phase: ValidationPhase> ValidatedDerivationDepthView<T, Phase> {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self(core::marker::PhantomData)
}
}
impl<T, Phase: ValidationPhase> ValidatedFreeRankView<T, Phase> {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self(core::marker::PhantomData)
}
}
impl<T, Phase: ValidationPhase> Validated<T, Phase>
where
T: ConstrainedTypeShape,
{
#[inline]
#[must_use]
pub const fn as_landauer(&self) -> ValidatedLandauerView<T, Phase> {
ValidatedLandauerView::new()
}
#[inline]
#[must_use]
pub const fn as_jacobian(&self) -> ValidatedJacobianView<T, Phase> {
ValidatedJacobianView::new()
}
#[inline]
#[must_use]
pub const fn as_carry_depth(&self) -> ValidatedCarryDepthView<T, Phase> {
ValidatedCarryDepthView::new()
}
#[inline]
#[must_use]
pub const fn as_derivation_depth(&self) -> ValidatedDerivationDepthView<T, Phase> {
ValidatedDerivationDepthView::new()
}
#[inline]
#[must_use]
pub const fn as_free_rank(&self) -> ValidatedFreeRankView<T, Phase> {
ValidatedFreeRankView::new()
}
}
#[inline]
fn empty_source<H: HostTypes>() -> &'static H::HostString {
H::EMPTY_HOST_STRING
}
#[inline]
fn empty_target<H: HostTypes>() -> &'static H::HostString {
H::EMPTY_HOST_STRING
}
impl<T, Phase, H> Observable<H> for ValidatedLandauerView<T, Phase>
where
T: ConstrainedTypeShape,
Phase: ValidationPhase,
H: HostTypes,
{
#[inline]
fn value(&self) -> H::Decimal {
<Self as LandauerBudget<H>>::landauer_nats(self)
}
#[inline]
fn source(&self) -> &H::HostString {
empty_source::<H>()
}
#[inline]
fn target(&self) -> &H::HostString {
empty_target::<H>()
}
#[inline]
fn has_unit(&self) -> MeasurementUnit {
MeasurementUnit::default()
}
}
impl<T, Phase, H> ThermoObservable<H> for ValidatedLandauerView<T, Phase>
where
T: ConstrainedTypeShape,
Phase: ValidationPhase,
H: HostTypes,
{
#[inline]
fn hardness_estimate(&self) -> H::Decimal {
H::EMPTY_DECIMAL
}
}
impl<T, Phase, H> LandauerBudget<H> for ValidatedLandauerView<T, Phase>
where
T: ConstrainedTypeShape,
Phase: ValidationPhase,
H: HostTypes,
{
#[inline]
fn landauer_nats(&self) -> H::Decimal {
let nerve = match crate::enforcement::primitive_simplicial_nerve_betti::<T>() {
Ok(b) => b,
Err(_) => return H::EMPTY_DECIMAL,
};
let (_residual, entropy_bits) = crate::enforcement::primitive_descent_metrics::<T>(&nerve);
<H::Decimal as DecimalTranscendental>::from_bits(entropy_bits)
}
}
impl<T, Phase, H> Observable<H> for ValidatedJacobianView<T, Phase>
where
T: ConstrainedTypeShape,
Phase: ValidationPhase,
H: HostTypes,
{
#[inline]
fn value(&self) -> H::Decimal {
let jac = crate::enforcement::primitive_curvature_jacobian::<T>();
let mut sum: u64 = 0;
let mut i = 0;
while i < jac.len() {
sum = sum.saturating_add(u64::from(jac[i].unsigned_abs()));
i += 1;
}
<H::Decimal as DecimalTranscendental>::from_u64(sum)
}
#[inline]
fn source(&self) -> &H::HostString {
empty_source::<H>()
}
#[inline]
fn target(&self) -> &H::HostString {
empty_target::<H>()
}
#[inline]
fn has_unit(&self) -> MeasurementUnit {
MeasurementUnit::default()
}
}
impl<T, Phase, H> JacobianObservable<H> for ValidatedJacobianView<T, Phase>
where
T: ConstrainedTypeShape,
Phase: ValidationPhase,
H: HostTypes,
{
}
impl<T, Phase, H> Observable<H> for ValidatedCarryDepthView<T, Phase>
where
T: ConstrainedTypeShape,
Phase: ValidationPhase,
H: HostTypes,
{
#[inline]
fn value(&self) -> H::Decimal {
let (orbit_size, _period) = crate::enforcement::primitive_dihedral_signature::<T>();
<H::Decimal as DecimalTranscendental>::from_u32(orbit_size)
}
#[inline]
fn source(&self) -> &H::HostString {
empty_source::<H>()
}
#[inline]
fn target(&self) -> &H::HostString {
empty_target::<H>()
}
#[inline]
fn has_unit(&self) -> MeasurementUnit {
MeasurementUnit::default()
}
}
impl<T, Phase, H> CarryDepthObservable<H> for ValidatedCarryDepthView<T, Phase>
where
T: ConstrainedTypeShape,
Phase: ValidationPhase,
H: HostTypes,
{
}
impl<T, Phase, H> Observable<H> for ValidatedDerivationDepthView<T, Phase>
where
T: ConstrainedTypeShape,
Phase: ValidationPhase,
H: HostTypes,
{
#[inline]
fn value(&self) -> H::Decimal {
match crate::enforcement::primitive_terminal_reduction::<T>(8u16) {
Ok((_witt, length, _sat)) => <H::Decimal as DecimalTranscendental>::from_u32(length),
Err(_) => H::EMPTY_DECIMAL,
}
}
#[inline]
fn source(&self) -> &H::HostString {
empty_source::<H>()
}
#[inline]
fn target(&self) -> &H::HostString {
empty_target::<H>()
}
#[inline]
fn has_unit(&self) -> MeasurementUnit {
MeasurementUnit::default()
}
}
impl<T, Phase, H> DerivationDepthObservable<H> for ValidatedDerivationDepthView<T, Phase>
where
T: ConstrainedTypeShape,
Phase: ValidationPhase,
H: HostTypes,
{
}
impl<T, Phase, H> Observable<H> for ValidatedFreeRankView<T, Phase>
where
T: ConstrainedTypeShape,
Phase: ValidationPhase,
H: HostTypes,
{
#[inline]
fn value(&self) -> H::Decimal {
let nerve = match crate::enforcement::primitive_simplicial_nerve_betti::<T>() {
Ok(b) => b,
Err(_) => return H::EMPTY_DECIMAL,
};
let (residual, _entropy_bits) = crate::enforcement::primitive_descent_metrics::<T>(&nerve);
<H::Decimal as DecimalTranscendental>::from_u32(residual)
}
#[inline]
fn source(&self) -> &H::HostString {
empty_source::<H>()
}
#[inline]
fn target(&self) -> &H::HostString {
empty_target::<H>()
}
#[inline]
fn has_unit(&self) -> MeasurementUnit {
MeasurementUnit::default()
}
}
impl<T, Phase, H> FreeRankObservable<H> for ValidatedFreeRankView<T, Phase>
where
T: ConstrainedTypeShape,
Phase: ValidationPhase,
H: HostTypes,
{
}