Jet

Struct Jet 

Source
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>

Source

pub fn new(value: f64, deriv: [f64; N]) -> Self

Create a Jet from raw value and normalized Taylor coefficient array.

Source

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² = 0
Source

pub fn constant(x: f64) -> Self

Create a constant jet (all derivatives zero).

Source

pub fn value(&self) -> f64

The function value $f(a)$.

Source

pub fn x(&self) -> f64

Alias for value() — backward compatibility.

Source

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 = 12
Source

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 = 12
Source

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);
Source

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]
Source§

impl<const N: usize> Jet<N>

Source

pub fn sinh_cosh(&self) -> (Self, Self)

Compute $\sinh$ and $\cosh$ together via the coupled normalized recurrence.

Trait Implementations§

Source§

impl<const N: usize> Add<Jet<N>> for f64

Source§

type Output = Jet<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Jet<N>) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: usize> Add<f64> for Jet<N>

Source§

type Output = Jet<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f64) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: usize> Add for Jet<N>

Source§

type Output = Jet<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Jet<N>) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: usize> Clone for Jet<N>

Source§

fn clone(&self) -> Jet<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for Jet<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Display for Jet<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Div<Jet<N>> for f64

Source§

type Output = Jet<N>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Jet<N>) -> Self::Output

Performs the / operation. Read more
Source§

impl<const N: usize> Div<f64> for Jet<N>

Source§

type Output = Jet<N>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self::Output

Performs the / operation. Read more
Source§

impl<const N: usize> Div for Jet<N>

Source§

fn div(self, rhs: Jet<N>) -> Self::Output

Division using normalized Taylor coefficient recurrence: $z_0 = a_0 / b_0$, $z_n = \frac{1}{b_0}\left(a_n - \sum_{k=1}^{n} b_k , z_{n-k}\right)$

Source§

type Output = Jet<N>

The resulting type after applying the / operator.
Source§

impl<const N: usize> ExpLogOps for Jet<N>

Source§

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

$\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)$

Source§

type Float = f64

Source§

fn log(&self, base: f64) -> Self

Source§

fn log2(&self) -> Self

Source§

fn log10(&self) -> Self

Source§

impl<const N: usize> From<Jet<N>> for f64

Source§

fn from(j: Jet<N>) -> f64

Converts to this type from the input type.
Source§

impl<const N: usize> From<f64> for Jet<N>

Source§

fn from(v: f64) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> Index<usize> for Jet<N>

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<const N: usize> IndexMut<usize> for Jet<N>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<const N: usize> Mul<Jet<N>> for f64

Source§

type Output = Jet<N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Jet<N>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize> Mul<f64> for Jet<N>

Source§

type Output = Jet<N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize> Mul for Jet<N>

Source§

fn mul(self, rhs: Jet<N>) -> Self::Output

Multiplication using normalized Taylor coefficient convolution: $z_n = \sum_{k=0}^{n} c_k \cdot d_{n-k}$. No binomial coefficients needed due to normalization convention.

Source§

type Output = Jet<N>

The resulting type after applying the * operator.
Source§

impl<const N: usize> Neg for Jet<N>

Source§

type Output = Jet<N>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<const N: usize> PartialEq for Jet<N>

Source§

fn eq(&self, other: &Jet<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialOrd for Jet<N>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const N: usize> PowOps for Jet<N>

Source§

fn powi(&self, n: i32) -> Self

Integer power via repeated multiplication.

Source§

fn powf(&self, f: f64) -> Self

Float power: exp(f * ln(self))

Source§

fn pow(&self, rhs: Self) -> Self

Jet power: exp(rhs * ln(self))

Source§

fn sqrt(&self) -> Self

Square root using direct recurrence from $z^2 = a$: $z_0 = \sqrt{a_0}$, $z_n = \frac{1}{2,z_0}\left(a_n - \sum_{k=1}^{n-1} z_k, z_{n-k}\right)$

Source§

type Float = f64

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>.

Source§

type Output = Jet<2>

Source§

fn call_stable(&self, target: Jet<2>) -> Jet<2>

Source§

impl<const N: usize> Sub<Jet<N>> for f64

Source§

type Output = Jet<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Jet<N>) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: usize> Sub<f64> for Jet<N>

Source§

type Output = Jet<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f64) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: usize> Sub for Jet<N>

Source§

type Output = Jet<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Jet<N>) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: usize> TrigOps for Jet<N>

Source§

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

$\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}$

Source§

fn sin(&self) -> Self

Source§

fn cos(&self) -> Self

Source§

fn tan(&self) -> Self

Source§

fn cosh(&self) -> Self

Source§

fn tanh(&self) -> Self

Source§

fn asin(&self) -> Self

Source§

fn acos(&self) -> Self

Source§

fn atan(&self) -> Self

Source§

fn asinh(&self) -> Self

Source§

fn acosh(&self) -> Self

Source§

fn atanh(&self) -> Self

§

fn asin_acos(&self) -> (Self, Self)

§

fn asinh_acosh(&self) -> (Self, Self)

Source§

impl<const N: usize> Copy for Jet<N>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

§

impl<T> Ungil for T
where T: Send,