pub struct Jet<const N: usize> { /* private fields */ }Expand description
Const-generic Taylor-mode forward AD type.
Stores the value and $N$ normalized Taylor coefficients:
value= $f(a) = c_0$deriv[k]= $f^{(k+1)}(a) / (k+1)! = c_{k+1}$
So Jet<1> stores $(c_0, c_1) = (f(a),, f’(a))$,
and Jet<2> stores $(c_0, c_1, c_2) = (f(a),, f’(a),, f’’(a)/2)$.
Implementations§
Source§impl<const N: usize> Jet<N>
impl<const N: usize> Jet<N>
Sourcepub fn new(value: f64, deriv: [f64; N]) -> Self
pub fn new(value: f64, deriv: [f64; N]) -> Self
Create a Jet from raw value and normalized Taylor coefficient array.
Sourcepub fn var(x: f64) -> Self
pub fn var(x: f64) -> Self
Create an independent variable jet at point x.
Sets deriv[0] = 1.0 (the 1st normalized coefficient), rest zero.
§Examples
use peroxide::fuga::*;
let x = Jet::<2>::var(3.0);
assert_eq!(x.value(), 3.0);
assert_eq!(x.dx(), 1.0); // dx/dx = 1
assert_eq!(x.ddx(), 0.0); // d²x/dx² = 0Sourcepub fn dx(&self) -> f64
pub fn dx(&self) -> f64
First derivative $f’(a)$.
§Examples
use peroxide::fuga::*;
let x = Jet::<1>::var(2.0);
let y = x.powi(3); // x^3
assert_eq!(y.dx(), 12.0); // 3*x^2 = 3*4 = 12Sourcepub fn ddx(&self) -> f64
pub fn ddx(&self) -> f64
Second derivative $f’’(a)$.
§Examples
use peroxide::fuga::*;
let x = Jet::<2>::var(2.0);
let y = x.powi(3); // x^3
assert_eq!(y.ddx(), 12.0); // 6*x = 6*2 = 12Sourcepub fn derivative(&self, order: usize) -> f64
pub fn derivative(&self, order: usize) -> f64
Returns $f^{(\mathrm{order})}(a)$, the raw (factorial-scaled) derivative of given order.
- order = 0: $f(a)$
- order = 1: $f’(a)$ =
deriv[0] - order = k: $f^{(k)}(a)$ =
deriv[k-1]$\times, k!$
Internally computes taylor_coeff(k) $\times, k!$.
§Examples
use peroxide::fuga::*;
let x = Jet::<3>::var(0.0);
let y = x.exp();
// All derivatives of exp at 0 are 1
assert!((y.derivative(0) - 1.0).abs() < 1e-15);
assert!((y.derivative(1) - 1.0).abs() < 1e-15);
assert!((y.derivative(2) - 1.0).abs() < 1e-15);
assert!((y.derivative(3) - 1.0).abs() < 1e-15);Sourcepub fn taylor_coeff(&self, k: usize) -> f64
pub fn taylor_coeff(&self, k: usize) -> f64
Returns the $k$-th normalized Taylor coefficient $c_k = f^{(k)}(a) / k!$.
- $k = 0$: $c_0 = f(a)$
- $k \ge 1$: $c_k$ =
deriv[k-1]
Trait Implementations§
Source§impl<const N: usize> ExpLogOps for Jet<N>
impl<const N: usize> ExpLogOps for Jet<N>
Source§fn exp(&self) -> Self
fn exp(&self) -> Self
$\exp(a)$ using the normalized recurrence: $z_0 = e^{a_0}$, $z_n = \frac{1}{n}\sum_{k=1}^{n} k, a_k, z_{n-k}$
Source§fn ln(&self) -> Self
fn ln(&self) -> Self
$\ln(a)$ using the normalized recurrence: $z_0 = \ln(a_0)$, $z_n = \frac{1}{a_0}\left(a_n - \frac{1}{n}\sum_{k=1}^{n-1} k, z_k, a_{n-k}\right)$
type Float = f64
fn log(&self, base: f64) -> Self
fn log2(&self) -> Self
fn log10(&self) -> Self
Source§impl<const N: usize> PartialOrd for Jet<N>
impl<const N: usize> PartialOrd for Jet<N>
Source§impl<const N: usize> PowOps for Jet<N>
impl<const N: usize> PowOps for Jet<N>
Source§impl<F: Fn(Jet<2>) -> Jet<2>> StableFn<Jet<2>> for ADFn<F>
Scalar version: F works with Jet<2>, target is Jet<2>.
impl<F: Fn(Jet<2>) -> Jet<2>> StableFn<Jet<2>> for ADFn<F>
Scalar version: F works with Jet<2>, target is Jet<2>.
Source§impl<const N: usize> TrigOps for Jet<N>
impl<const N: usize> TrigOps for Jet<N>
Source§fn sin_cos(&self) -> (Self, Self)
fn sin_cos(&self) -> (Self, Self)
$\sin$ and $\cos$ computed together via coupled normalized recurrence: $s_0 = \sin(a_0)$, $c_0 = \cos(a_0)$, $s_n = \frac{1}{n}\sum_{k=1}^{n} k, a_k, c_{n-k}$, $c_n = -\frac{1}{n}\sum_{k=1}^{n} k, a_k, s_{n-k}$
Source§fn sinh(&self) -> Self
fn sinh(&self) -> Self
$\sinh$ and $\cosh$ via coupled normalized recurrence (same as $\sin/\cos$ but no negative on $\cosh$): $s_n = \frac{1}{n}\sum_{k=1}^{n} k, a_k, c_{n-k}$, $c_n = \frac{1}{n}\sum_{k=1}^{n} k, a_k, s_{n-k}$
fn sin(&self) -> Self
fn cos(&self) -> Self
fn tan(&self) -> Self
fn cosh(&self) -> Self
fn tanh(&self) -> Self
fn asin(&self) -> Self
fn acos(&self) -> Self
fn atan(&self) -> Self
fn asinh(&self) -> Self
fn acosh(&self) -> Self
fn atanh(&self) -> Self
fn asin_acos(&self) -> (Self, Self)
fn asinh_acosh(&self) -> (Self, Self)
impl<const N: usize> Copy for Jet<N>
impl<const N: usize> StructuralPartialEq for Jet<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for Jet<N>
impl<const N: usize> RefUnwindSafe for Jet<N>
impl<const N: usize> Send for Jet<N>
impl<const N: usize> Sync for Jet<N>
impl<const N: usize> Unpin for Jet<N>
impl<const N: usize> UnwindSafe for Jet<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more