Multivector

Struct Multivector 

Source
pub struct Multivector<const P: usize, const Q: usize, const R: usize> { /* private fields */ }
Expand description

A multivector in a Clifford algebra Cl(P,Q,R)

§Type Parameters

  • P: Number of basis vectors that square to +1
  • Q: Number of basis vectors that square to -1
  • R: Number of basis vectors that square to 0

Implementations§

Source§

impl<const P: usize, const Q: usize, const R: usize> Multivector<P, Q, R>

Source

pub const DIM: usize

Total dimension of the algebra’s vector space

Source

pub const BASIS_COUNT: usize

Total number of basis blades (2^DIM)

Source

pub fn zero() -> Self

Create a new zero multivector

Source

pub fn scalar(value: f64) -> Self

Create a scalar multivector

Source

pub fn from_vector(vector: &Vector<P, Q, R>) -> Self

Create multivector from vector

Source

pub fn from_bivector(bivector: &Bivector<P, Q, R>) -> Self

Create multivector from bivector

Source

pub fn basis_vector(i: usize) -> Self

Create a basis vector e_i (i starts from 0)

Source

pub fn from_coefficients(coefficients: Vec<f64>) -> Self

Create a multivector from coefficients

Source

pub fn from_slice(coefficients: &[f64]) -> Self

Create a multivector from a slice (convenience for tests)

Source

pub fn get(&self, index: usize) -> f64

Get coefficient for a specific basis blade (by index)

Source

pub fn set(&mut self, index: usize, value: f64)

Set coefficient for a specific basis blade

Source

pub fn scalar_part(&self) -> f64

Get the scalar part (grade 0)

Source

pub fn set_scalar(&mut self, value: f64)

Set the scalar part

Source

pub fn vector_part(&self) -> Vector<P, Q, R>

Get vector part as a Vector type

Source

pub fn bivector_part(&self) -> Self

Get bivector part as a Multivector (grade 2 projection)

Source

pub fn bivector_type(&self) -> Bivector<P, Q, R>

Get bivector part as a Bivector type wrapper

Source

pub fn trivector_part(&self) -> f64

Get trivector part (scalar for 3D)

Source

pub fn set_vector_component(&mut self, index: usize, value: f64)

Set vector component

Source

pub fn set_bivector_component(&mut self, index: usize, value: f64)

Set bivector component

Source

pub fn vector_component(&self, index: usize) -> f64

Get vector component

Source

pub fn as_slice(&self) -> &[f64]

Get coefficients as slice for comparison

Source

pub fn add(&self, other: &Self) -> Self

Add method for convenience

Source

pub fn grade(&self) -> usize

Get the grade of a multivector (returns the highest non-zero grade)

Source

pub fn outer_product_with_vector(&self, other: &Vector<P, Q, R>) -> Self

Outer product with a vector (convenience method)

Source

pub fn geometric_product(&self, rhs: &Self) -> Self

Geometric product with another multivector

The geometric product is the fundamental operation in geometric algebra, combining both the inner and outer products.

Source

pub fn geometric_product_scalar(&self, rhs: &Self) -> Self

Scalar implementation of geometric product (fallback)

Source

pub fn inner_product(&self, rhs: &Self) -> Self

Inner product (grade-lowering, dot product for vectors)

Source

pub fn outer_product(&self, rhs: &Self) -> Self

Outer product (wedge product, grade-raising)

Source

pub fn scalar_product(&self, rhs: &Self) -> f64

Scalar product (grade-0 part of geometric product)

Source

pub fn reverse(&self) -> Self

Reverse operation (reverses order of basis vectors in each blade)

Source

pub fn grade_projection(&self, grade: usize) -> Self

Grade projection - extract components of a specific grade

Source

pub fn is_zero(&self) -> bool

Check if this is (approximately) zero

Source

pub fn norm_squared(&self) -> f64

Compute the norm squared (scalar product with reverse)

Source

pub fn magnitude(&self) -> f64

Compute the magnitude (length) of this multivector

The magnitude is defined as |a| = √(a·ã) where ã is the reverse of a. This provides the natural norm inherited from the underlying vector space.

§Mathematical Properties
  • Always non-negative: |a| ≥ 0
  • Zero iff a = 0: |a| = 0 ⟺ a = 0
  • Sub-multiplicative: |ab| ≤ |a||b|
§Examples
use amari_core::Multivector;
let v = Multivector::<3,0,0>::basis_vector(0);
assert_eq!(v.magnitude(), 1.0);
Source

pub fn norm(&self) -> f64

Compute the norm (magnitude) of this multivector

Note: This method is maintained for backward compatibility. New code should prefer magnitude() for clarity.

Source

pub fn abs(&self) -> f64

Absolute value (same as magnitude/norm for multivectors)

Source

pub fn approx_eq(&self, other: &Self, epsilon: f64) -> bool

Approximate equality comparison

Source

pub fn normalize(&self) -> Option<Self>

Normalize this multivector

Source

pub fn inverse(&self) -> Option<Self>

Compute multiplicative inverse if it exists

Source

pub fn exp(&self) -> Self

Exponential map for bivectors (creates rotors)

For a bivector B, exp(B) creates a rotor that performs rotation in the plane defined by B.

Source

pub fn left_contraction(&self, other: &Self) -> Self

Left contraction: a ⌟ b

Generalized inner product where the grade of the result is |grade(b) - grade(a)|. The left operand’s grade is reduced.

Source

pub fn right_contraction(&self, other: &Self) -> Self

Right contraction: a ⌞ b

Generalized inner product where the grade of the result is |grade(a) - grade(b)|. The right operand’s grade is reduced.

Source

pub fn hodge_dual(&self) -> Self

Hodge dual: ⋆a

Maps k-vectors to (n-k)-vectors in n-dimensional space. Essential for electromagnetic field theory and differential forms. In 3D: scalar -> pseudoscalar, vector -> bivector, bivector -> vector, pseudoscalar -> scalar

Trait Implementations§

Source§

impl<const P: usize, const Q: usize, const R: usize> Add for &Multivector<P, Q, R>

Source§

type Output = Multivector<P, Q, R>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Multivector<P, Q, R>

Performs the + operation. Read more
Source§

impl<const P: usize, const Q: usize, const R: usize> Add for Multivector<P, Q, R>

Source§

type Output = Multivector<P, Q, R>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<const P: usize, const Q: usize, const R: usize> Clone for Multivector<P, Q, R>

Source§

fn clone(&self) -> Multivector<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<const P: usize, const Q: usize, const R: usize> Debug for Multivector<P, Q, R>

Source§

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

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

impl<const P: usize, const Q: usize, const R: usize> Mul<f64> for &Multivector<P, Q, R>

Source§

type Output = Multivector<P, Q, R>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: f64) -> Multivector<P, Q, R>

Performs the * operation. Read more
Source§

impl<const P: usize, const Q: usize, const R: usize> Mul<f64> for Multivector<P, Q, R>

Source§

type Output = Multivector<P, Q, R>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: f64) -> Self

Performs the * operation. Read more
Source§

impl<const P: usize, const Q: usize, const R: usize> Neg for Multivector<P, Q, R>

Source§

type Output = Multivector<P, Q, R>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<const P: usize, const Q: usize, const R: usize> PartialEq for Multivector<P, Q, R>

Source§

fn eq(&self, other: &Multivector<P, Q, R>) -> 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 P: usize, const Q: usize, const R: usize> Sub for &Multivector<P, Q, R>

Source§

type Output = Multivector<P, Q, R>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Multivector<P, Q, R>

Performs the - operation. Read more
Source§

impl<const P: usize, const Q: usize, const R: usize> Sub for Multivector<P, Q, R>

Source§

type Output = Multivector<P, Q, R>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<const P: usize, const Q: usize, const R: usize> Zero for Multivector<P, Q, R>

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<const P: usize, const Q: usize, const R: usize> StructuralPartialEq for Multivector<P, Q, R>

Auto Trait Implementations§

§

impl<const P: usize, const Q: usize, const R: usize> Freeze for Multivector<P, Q, R>

§

impl<const P: usize, const Q: usize, const R: usize> RefUnwindSafe for Multivector<P, Q, R>

§

impl<const P: usize, const Q: usize, const R: usize> Send for Multivector<P, Q, R>

§

impl<const P: usize, const Q: usize, const R: usize> Sync for Multivector<P, Q, R>

§

impl<const P: usize, const Q: usize, const R: usize> Unpin for Multivector<P, Q, R>

§

impl<const P: usize, const Q: usize, const R: usize> UnwindSafe for Multivector<P, Q, R>

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.