pub struct DualMultivector<T, const P: usize, const Q: usize, const R: usize>where
T: Float,{ /* private fields */ }Expand description
Multivector with dual number coefficients for automatic differentiation
Implementations§
Source§impl<T, const P: usize, const Q: usize, const R: usize> DualMultivector<T, P, Q, R>where
T: Float,
impl<T, const P: usize, const Q: usize, const R: usize> DualMultivector<T, P, Q, R>where
T: Float,
Sourcepub fn zero() -> DualMultivector<T, P, Q, R>
pub fn zero() -> DualMultivector<T, P, Q, R>
Create zero dual multivector
Sourcepub fn from_dual_coefficients(
coeffs: Vec<DualNumber<T>>,
) -> DualMultivector<T, P, Q, R>
pub fn from_dual_coefficients( coeffs: Vec<DualNumber<T>>, ) -> DualMultivector<T, P, Q, R>
Create from dual number coefficients
Sourcepub fn new_variables(values: &[T]) -> DualMultivector<T, P, Q, R>
pub fn new_variables(values: &[T]) -> DualMultivector<T, P, Q, R>
Create dual multivector where each coefficient is a variable
Sourcepub fn new_variable(values: &[T]) -> DualMultivector<T, P, Q, R>
pub fn new_variable(values: &[T]) -> DualMultivector<T, P, Q, R>
Create dual multivector where each coefficient is a variable - alias
Sourcepub fn constant_mv(mv: &Multivector<P, Q, R>) -> DualMultivector<T, P, Q, R>
pub fn constant_mv(mv: &Multivector<P, Q, R>) -> DualMultivector<T, P, Q, R>
Create constant dual multivector from Multivector
Sourcepub fn constant(values: &[T]) -> DualMultivector<T, P, Q, R>
pub fn constant(values: &[T]) -> DualMultivector<T, P, Q, R>
Create constant dual multivector from slice
Sourcepub fn get(&self, index: usize) -> DualNumber<T>
pub fn get(&self, index: usize) -> DualNumber<T>
Get coefficient at index
Sourcepub fn set(&mut self, index: usize, value: DualNumber<T>)
pub fn set(&mut self, index: usize, value: DualNumber<T>)
Set coefficient at index
Sourcepub fn value(&self) -> Multivector<P, Q, R>
pub fn value(&self) -> Multivector<P, Q, R>
Get the value part (without derivatives)
Sourcepub fn derivative(&self) -> Multivector<P, Q, R>
pub fn derivative(&self) -> Multivector<P, Q, R>
Get the derivative part
Sourcepub fn real_part(&self) -> Multivector<P, Q, R>
pub fn real_part(&self) -> Multivector<P, Q, R>
Get the real part (value) as a Multivector
Sourcepub fn from_real_multivector(
mv: Multivector<P, Q, R>,
) -> DualMultivector<T, P, Q, R>
pub fn from_real_multivector( mv: Multivector<P, Q, R>, ) -> DualMultivector<T, P, Q, R>
Create from real multivector (alias for constant_mv)
Sourcepub fn scalar(value: DualNumber<T>) -> DualMultivector<T, P, Q, R>
pub fn scalar(value: DualNumber<T>) -> DualMultivector<T, P, Q, R>
Create scalar dual multivector from DualNumber
Sourcepub fn basis_vector(
index: usize,
) -> Result<DualMultivector<T, P, Q, R>, &'static str>
pub fn basis_vector( index: usize, ) -> Result<DualMultivector<T, P, Q, R>, &'static str>
Create a basis vector (unit vector in given direction)
Sourcepub fn grade(&self) -> usize
pub fn grade(&self) -> usize
Get the grade of the multivector (highest grade component with non-zero coefficient)
Sourcepub fn geometric_product(
&self,
other: &DualMultivector<T, P, Q, R>,
) -> DualMultivector<T, P, Q, R>
pub fn geometric_product( &self, other: &DualMultivector<T, P, Q, R>, ) -> DualMultivector<T, P, Q, R>
Geometric product with automatic differentiation
Sourcepub fn reverse(&self) -> DualMultivector<T, P, Q, R>
pub fn reverse(&self) -> DualMultivector<T, P, Q, R>
Reverse with automatic differentiation
Sourcepub fn grade_projection(&self, grade: usize) -> DualMultivector<T, P, Q, R>
pub fn grade_projection(&self, grade: usize) -> DualMultivector<T, P, Q, R>
Grade projection with automatic differentiation
Sourcepub fn norm_squared(&self) -> DualNumber<T>
pub fn norm_squared(&self) -> DualNumber<T>
Dual number norm (with automatic differentiation)
Sourcepub fn norm(&self) -> DualNumber<T>
pub fn norm(&self) -> DualNumber<T>
Dual number norm
Sourcepub fn normalize(&self) -> DualMultivector<T, P, Q, R>
pub fn normalize(&self) -> DualMultivector<T, P, Q, R>
Normalize with automatic differentiation
Sourcepub fn exp(&self) -> DualMultivector<T, P, Q, R>
pub fn exp(&self) -> DualMultivector<T, P, Q, R>
Exponential map with automatic differentiation
Sourcepub fn map<F, G>(&self, f: F, df: G) -> DualMultivector<T, P, Q, R>
pub fn map<F, G>(&self, f: F, df: G) -> DualMultivector<T, P, Q, R>
Apply a function element-wise with automatic differentiation
Sourcepub fn forward_mode_ad<F>(&self, f: F) -> (T, DualMultivector<T, P, Q, R>)
pub fn forward_mode_ad<F>(&self, f: F) -> (T, DualMultivector<T, P, Q, R>)
Forward-mode automatic differentiation
Computes both the value and gradient of a function using dual numbers. Forward-mode AD propagates derivatives alongside function evaluation, allowing exact derivative computation without finite differences.
§Parameters
f: A function that takes aDualMultivectorand returns aDualMultivector
§Returns
A tuple containing:
- The scalar value of the function at the input point
- The full
DualMultivectorresult containing all partial derivatives
§Example
use amari_dual::{DualMultivector, DualNumber};
let input = DualMultivector::<f64, 3, 0, 0>::scalar(DualNumber::constant(2.0));
let (value, gradient) = input.forward_mode_ad(|x| {
x.geometric_product(&x) // x^2 in geometric algebra
});
// Computes geometric square and its derivative§How it works
The dual number coefficients automatically track derivatives through all arithmetic operations via operator overloading. The ‘dual’ part of each number carries the derivative information, which is propagated according to the chain rule during computation.
Trait Implementations§
Source§impl<T, const P: usize, const Q: usize, const R: usize> Add for DualMultivector<T, P, Q, R>where
T: Float,
impl<T, const P: usize, const Q: usize, const R: usize> Add for DualMultivector<T, P, Q, R>where
T: Float,
Source§type Output = DualMultivector<T, P, Q, R>
type Output = DualMultivector<T, P, Q, R>
+ operator.Source§fn add(self, other: DualMultivector<T, P, Q, R>) -> DualMultivector<T, P, Q, R>
fn add(self, other: DualMultivector<T, P, Q, R>) -> DualMultivector<T, P, Q, R>
+ operation. Read moreSource§impl<T, const P: usize, const Q: usize, const R: usize> Clone for DualMultivector<T, P, Q, R>
impl<T, const P: usize, const Q: usize, const R: usize> Clone for DualMultivector<T, P, Q, R>
Source§fn clone(&self) -> DualMultivector<T, P, Q, R>
fn clone(&self) -> DualMultivector<T, P, Q, R>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T, const P: usize, const Q: usize, const R: usize> Debug for DualMultivector<T, P, Q, R>
impl<T, const P: usize, const Q: usize, const R: usize> Debug for DualMultivector<T, P, Q, R>
Source§impl<T, const P: usize, const Q: usize, const R: usize> Mul<DualNumber<T>> for DualMultivector<T, P, Q, R>where
T: Float,
impl<T, const P: usize, const Q: usize, const R: usize> Mul<DualNumber<T>> for DualMultivector<T, P, Q, R>where
T: Float,
Source§type Output = DualMultivector<T, P, Q, R>
type Output = DualMultivector<T, P, Q, R>
* operator.Source§fn mul(self, scalar: DualNumber<T>) -> DualMultivector<T, P, Q, R>
fn mul(self, scalar: DualNumber<T>) -> DualMultivector<T, P, Q, R>
* operation. Read moreSource§impl<T, const P: usize, const Q: usize, const R: usize> Sub for DualMultivector<T, P, Q, R>where
T: Float,
impl<T, const P: usize, const Q: usize, const R: usize> Sub for DualMultivector<T, P, Q, R>where
T: Float,
Source§type Output = DualMultivector<T, P, Q, R>
type Output = DualMultivector<T, P, Q, R>
- operator.Source§fn sub(self, other: DualMultivector<T, P, Q, R>) -> DualMultivector<T, P, Q, R>
fn sub(self, other: DualMultivector<T, P, Q, R>) -> DualMultivector<T, P, Q, R>
- operation. Read moreAuto Trait Implementations§
impl<T, const P: usize, const Q: usize, const R: usize> Freeze for DualMultivector<T, P, Q, R>
impl<T, const P: usize, const Q: usize, const R: usize> RefUnwindSafe for DualMultivector<T, P, Q, R>where
T: RefUnwindSafe,
impl<T, const P: usize, const Q: usize, const R: usize> Send for DualMultivector<T, P, Q, R>where
T: Send,
impl<T, const P: usize, const Q: usize, const R: usize> Sync for DualMultivector<T, P, Q, R>where
T: Sync,
impl<T, const P: usize, const Q: usize, const R: usize> Unpin for DualMultivector<T, P, Q, R>where
T: Unpin,
impl<T, const P: usize, const Q: usize, const R: usize> UnwindSafe for DualMultivector<T, P, Q, R>where
T: UnwindSafe,
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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.