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 to_vec(&self) -> Vec<f64>

Convert coefficients to owned vector

Useful for interoperability with other libraries and serialization.

Source

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

Grade projection with alternative name for clarity

Alias for grade_projection that emphasizes the projection operation.

Source

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

Wedge product (alias for outer product)

The wedge product ∧ is the antisymmetric outer product, fundamental to exterior algebra and differential forms.

Source

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

Dot product (alias for inner product)

The dot product · is the grade-lowering inner product, generalizing the vector dot product to all grades.

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 grade_magnitude(&self, grade: usize) -> f64

Compute the magnitude of a specific grade component.

This extracts the k-vector part and computes its magnitude. Useful for determining grade dominance in holographic representations.

§Arguments
  • grade - The grade to compute magnitude for (0=scalar, 1=vector, 2=bivector, etc.)
§Returns

The magnitude of the grade-k component, or 0.0 if no such component exists.

§Example
use amari_core::Multivector;
let mv = Multivector::<3,0,0>::basis_vector(0) + Multivector::<3,0,0>::scalar(2.0);
assert!((mv.grade_magnitude(0) - 2.0).abs() < 1e-10);  // scalar part
assert!((mv.grade_magnitude(1) - 1.0).abs() < 1e-10);  // vector part
Source

pub fn grade_spectrum(&self) -> Vec<f64>

Get all grade magnitudes as a vector.

Returns the magnitude of each grade component from 0 to DIM. This provides a “grade spectrum” view of the multivector.

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