1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
use crate::Error;
/// # General Information
///
/// Every struct defined to behave like a function must have a way to be evaluated. In one dimention, all it takes is to obtain a value x
/// and return another value y.
///
/// # Functions
///
/// * `evaluate(...)` - Evaluation of a 1D function.
///
pub trait Function1D {
/// Evaluation of a 1D function.
fn evaluate(&self, x: f64) -> f64;
}
/// # General Information
///
/// Every struct defined to behave like a function must have a way to be evaluated. In two dimentions, all it takes is to obtain a value (x,y)
/// and return another value (z,w).
///
/// # Functions
///
/// * `evaluate(...)` - Evaluation of a 2D function.
///
pub trait Function2D {
/// Evaluation of a 2D function.
fn evaluate(&self, x: f64, y: f64) -> f64;
}
/// # General Information
///
/// Methods a 2D vector function should have ( F: R^2 -> R^2 )
///
/// # Functions
///
/// * `evaluate(...)` - Evaluation of a 2D vector function ( F: R^2 -> R^2 )
///
pub trait Function2D2D {
/// Evaluation of a 2D vector function
fn evaluate(&self, x: f64, y: f64) -> (f64,f64);
}
/// # General Information
///
/// Every differentiable 1D function-like struct must implement this trait. It is important to know which kind of function will result from differentiating.
/// Such a function needs to become a struct that represents a family of it's kind and also implements the trait `Function1D`.
///
/// # Functions
///
/// * `differentiate(...)` - Results in a function product of differentiation.
///
pub trait Differentiable1D<T>: Function1D
where
T: Function1D
{
/// Results in a function product of differentiation.
fn differentiate(&self) -> Result<T,Error>;
}
/// # General Information
///
/// Every differentiable 2D function-like struct must implement this trait. It is important to know which kind of function will result from differentiating.
/// Such a function needs to become a struct that represents a family of it's kind and also implements the trait `Function2D`.
/// A function completely differentiable in 2 dimentions is differentiable on every entry. The converse is not always true.
///
/// # Functions
///
/// * `differentiate_x(...)` - Differentiate with respect to x
/// * `differentiate_y(...)` - Differentiate with respect to y
///
pub trait Differentiable2D<T,V>: Function2D
where
T: Function2D,
V: Function2D
{
fn differentiate_x(&self) -> Result<T,Error>;
fn differentiate_y(&self) -> Result<T,Error>;
}
/// # General Information
///
/// The composition, given `f`, the function on which this trait is implemented, and `g`, the function inside the trait's only function, is done like:
/// ```f(g(x))```
/// All composable functions need to implement this trait. When a functions needs to be composed with another, the latter one needs to be specified a priori,
/// and the result of the composition needs to be known. This means that the trait Composable<latter, result> needs to be implemented.
///
/// # Functions
///
/// * `compose(...)` - Returns a function from the composition of the two functions involved. Consumes functions.
pub trait Composable1D<T, U>
where
T: Function1D,
U: Function1D,
{
/// Returns a function from the composition of the two functions involved. Consumes functions
fn compose(self, other: T) -> Result<U,Error>;
}
/// # General Information
///
/// The composition, given `f`, the function on which this trait is implemented, and `g`, the function inside the trait's only function, is done like:
/// ```f(g(x,y))```
/// All composable functions need to implement this trait. When a functions needs to be composed with another, the latter one needs to be specified a priori,
/// and the result of the composition needs to be known. This means that the trait Composable<latter, result> needs to be implemented.
///
/// # Functions
///
/// * `compose(...)` - Returns a function from the composition of the two functions involved. Consumes functions.
pub trait Composable2D<T,V>
where
T: Function2D2D,
V: Function2D
{
fn compose(self,other: T) -> Result<V,Error>;
}