diff -r d7c0f431cbd6 -r c5f70e767511 src/bisection_tree/support.rs --- a/src/bisection_tree/support.rs Mon Dec 30 09:49:08 2024 -0500 +++ b/src/bisection_tree/support.rs Tue Dec 31 08:48:50 2024 -0500 @@ -13,21 +13,7 @@ use crate::loc::Loc; use super::aggregator::Bounds; use crate::norms::{Norm, L1, L2, Linfinity}; - -/// A trait for encoding constant [`Float`] values -pub trait Constant : Copy + Sync + Send + 'static + std::fmt::Debug + Into { - /// The type of the value - type Type : Float; - /// Returns the value of the constant - fn value(&self) -> Self::Type; -} - -impl Constant for F { - type Type = F; - #[inline] - fn value(&self) -> F { *self } -} - +pub use crate::operator_arithmetic::{Weighted, Constant}; /// A trait for working with the supports of [`Apply`]s. /// @@ -64,12 +50,6 @@ fn shift(self, x : Loc) -> Shift { Shift { shift : x, base_fn : self } } - - /// Multiply `self` by the scalar `a`. - #[inline] - fn weigh>(self, a : C) -> Weighted { - Weighted { weight : a, base_fn : self } - } } /// Trait for globally analysing a property `A` of a [`Apply`]. @@ -204,40 +184,6 @@ impl_shift_norm!(L1 L2 Linfinity); -/// Weighting of a [`Support`] and [`Apply`] by scalar multiplication; -/// output of [`Support::weigh`]. -#[derive(Copy,Clone,Debug,Serialize)] -pub struct Weighted { - /// The weight - pub weight : C, - /// The base [`Support`] or [`Apply`] being weighted. - pub base_fn : T, -} - -impl<'a, T, V, F : Float, C, const N : usize> Mapping> for Weighted -where T : Mapping, Codomain=V>, - V : Space + std::ops::Mul, - C : Constant { - type Codomain = V; - - #[inline] - fn apply>>(&self, x : I) -> Self::Codomain { - self.base_fn.apply(x) * self.weight.value() - } -} - -impl<'a, T, V, F : Float, C, const N : usize> DifferentiableImpl> for Weighted -where T : DifferentiableMapping, DerivativeDomain=V>, - V : Space + std::ops::Mul, - C : Constant { - type Derivative = V; - - #[inline] - fn differential_impl>>(&self, x : I) -> Self::Derivative { - self.base_fn.differential(x) * self.weight.value() - } -} - impl<'a, T, F : Float, C, const N : usize> Support for Weighted where T : Support, C : Constant {