DualMultivector

Struct DualMultivector 

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

Source

pub fn zero() -> DualMultivector<T, P, Q, R>

Create zero dual multivector

Source

pub fn from_dual_coefficients( coeffs: Vec<DualNumber<T>>, ) -> DualMultivector<T, P, Q, R>

Create from dual number coefficients

Source

pub fn new_variables(values: &[T]) -> DualMultivector<T, P, Q, R>

Create dual multivector where each coefficient is a variable

Source

pub fn new_variable(values: &[T]) -> DualMultivector<T, P, Q, R>

Create dual multivector where each coefficient is a variable - alias

Source

pub fn constant_mv(mv: &Multivector<P, Q, R>) -> DualMultivector<T, P, Q, R>

Create constant dual multivector from Multivector

Source

pub fn constant(values: &[T]) -> DualMultivector<T, P, Q, R>

Create constant dual multivector from slice

Source

pub fn get(&self, index: usize) -> DualNumber<T>

Get coefficient at index

Source

pub fn set(&mut self, index: usize, value: DualNumber<T>)

Set coefficient at index

Source

pub fn value(&self) -> Multivector<P, Q, R>

Get the value part (without derivatives)

Source

pub fn derivative(&self) -> Multivector<P, Q, R>

Get the derivative part

Source

pub fn real_part(&self) -> Multivector<P, Q, R>

Get the real part (value) as a Multivector

Source

pub fn magnitude(&self) -> T

Compute magnitude of the real part

Source

pub fn from_real_multivector( mv: Multivector<P, Q, R>, ) -> DualMultivector<T, P, Q, R>

Create from real multivector (alias for constant_mv)

Source

pub fn scalar(value: DualNumber<T>) -> DualMultivector<T, P, Q, R>

Create scalar dual multivector from DualNumber

Source

pub fn basis_vector( index: usize, ) -> Result<DualMultivector<T, P, Q, R>, &'static str>

Create a basis vector (unit vector in given direction)

Source

pub fn grade(&self) -> usize

Get the grade of the multivector (highest grade component with non-zero coefficient)

Source

pub fn geometric_product( &self, other: &DualMultivector<T, P, Q, R>, ) -> DualMultivector<T, P, Q, R>

Geometric product with automatic differentiation

Source

pub fn reverse(&self) -> DualMultivector<T, P, Q, R>

Reverse with automatic differentiation

Source

pub fn grade_projection(&self, grade: usize) -> DualMultivector<T, P, Q, R>

Grade projection with automatic differentiation

Source

pub fn norm_squared(&self) -> DualNumber<T>

Dual number norm (with automatic differentiation)

Source

pub fn norm(&self) -> DualNumber<T>

Dual number norm

Source

pub fn normalize(&self) -> DualMultivector<T, P, Q, R>

Normalize with automatic differentiation

Source

pub fn exp(&self) -> DualMultivector<T, P, Q, R>

Exponential map with automatic differentiation

Source

pub fn map<F, G>(&self, f: F, df: G) -> DualMultivector<T, P, Q, R>
where F: Fn(T) -> T, G: Fn(T) -> T,

Apply a function element-wise with automatic differentiation

Source

pub fn forward_mode_ad<F>(&self, f: F) -> (T, DualMultivector<T, P, Q, R>)
where F: Fn(DualMultivector<T, P, Q, R>) -> 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 a DualMultivector and returns a DualMultivector
§Returns

A tuple containing:

  • The scalar value of the function at the input point
  • The full DualMultivector result 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,

Source§

type Output = DualMultivector<T, P, Q, R>

The resulting type after applying the + operator.
Source§

fn add(self, other: DualMultivector<T, P, Q, R>) -> DualMultivector<T, P, Q, R>

Performs the + operation. Read more
Source§

impl<T, const P: usize, const Q: usize, const R: usize> Clone for DualMultivector<T, P, Q, R>
where T: Clone + Float,

Source§

fn clone(&self) -> DualMultivector<T, P, Q, R>

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<T, const P: usize, const Q: usize, const R: usize> Debug for DualMultivector<T, P, Q, R>
where T: Debug + Float,

Source§

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

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

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>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: DualNumber<T>) -> DualMultivector<T, P, Q, R>

Performs the * operation. Read more
Source§

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>

The resulting type after applying the - operator.
Source§

fn sub(self, other: DualMultivector<T, P, Q, R>) -> DualMultivector<T, P, Q, R>

Performs the - operation. Read more

Auto 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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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, 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.