diff -r 9f2214c961cb -r cf8ef9463664 src/mapping.rs --- a/src/mapping.rs Fri Apr 28 14:02:18 2023 +0300 +++ b/src/mapping.rs Tue Jul 18 15:44:10 2023 +0300 @@ -51,11 +51,21 @@ /// Trait for calculation the differential of `Self` as a mathematical function on `X`. -pub trait Differentiable { +pub trait Differentiable : Apply { type Output; /// Compute the differential of `self` at `x`. - fn differential(&self, x : X) -> Self::Output; + fn differential(&self, x : X) -> >::Output; + + /// Compute the linearisation error of `self` at `x` for `y`. + fn linearisation_error(&self, x : X, y : X) -> >::Output { + let z = x.clone(); + self.linearisation_error_gen(x, y, z) + } + + /// Compute the linearisation error of `self` at `x` for `y`, with + /// derivative calculated at `z` + fn linearisation_error_gen(&self, x : X, y : X, z : X) -> >::Output; } @@ -63,15 +73,15 @@ /// `Differential`. /// /// This is automatically implemented when the relevant [`Differentiate`] are implemented. -pub trait DifferentiableMapping +pub trait DifferentiableMapping : Mapping + Differentiable - + for<'a> Differentiable<&'a Domain, Output=Self::Differential>{ + + for<'a> Differentiable<&'a Domain, Output=Self::Differential> { type Differential; } -impl DifferentiableMapping for T +impl DifferentiableMapping for T where T : Mapping + Differentiable + for<'a> Differentiable<&'a Domain, Output=Differential> { @@ -111,7 +121,24 @@ type Output = M::Differential; - fn differential(&self, x : Domain) -> Self::Output { - self.components.iter().map(|c| c.differential(x)).sum() + fn differential(&self, x : Domain) -> M::Differential { + self.components + .iter() + .map(|c| c.differential(x)) + .sum() + } + + fn linearisation_error(&self, x : Domain, y : Domain) -> M::Codomain { + self.components + .iter() + .map(|c| c.linearisation_error(x, y)) + .sum() + } + + fn linearisation_error_gen(&self, x : Domain, y : Domain, z : Domain) -> M::Codomain { + self.components + .iter() + .map(|c| c.linearisation_error_gen(x, y, z)) + .sum() } }