MultiVector Class API Reference¶
MultiVector is the core data type in geometric algebra, representing multivectors (linear combinations of scalars, vectors, bivectors, etc.).
Class Definition¶
class MultiVector:
"""
Multivector class, representing multivector elements in geometric algebra.
Can be a linear combination of scalars, vectors, bivectors, trivectors, etc.
"""
Constructor Methods¶
zeros(config)¶
Create a zero multivector.
Parameters: config - Algebra configuration object
Returns: Zero-valued MultiVector
one(config)¶
Create the unit multivector (scalar 1).
Returns: Unit scalar MultiVector
from_scalar(config, scalar)¶
Create a multivector from a scalar value.
Parameters:
- config - Algebra configuration
- scalar - Scalar value
Returns: Scalar MultiVector
Example:
alg = nblade.Algebra.euclidean(3)
s = nblade.MultiVector.from_scalar(alg.config, 5.0)
# Or use the convenience method
s = alg.scalar(5.0)
basis_vector(config, i)¶
Create basis vector e_i.
Parameters:
- config - Algebra configuration
- i - Basis vector index (0-based)
Returns: Basis vector MultiVector
from_coefficients(config, coefficients)¶
Create a multivector from a coefficient array.
@classmethod
def from_coefficients(cls, config: AlgebraConfig, coefficients: List[float]) -> MultiVector
Parameters:
- config - Algebra configuration
- coefficients - Coefficient array for all basis elements
Returns: MultiVector
Example:
# Coefficient order in 3D: [scalar, e1, e2, e3, e12, e13, e23, e123]
coeffs = [1.0, 2.0, 3.0, 4.0, 0.5, 0.0, 0.0, 0.1]
mv = nblade.MultiVector.from_coefficients(alg.config, coeffs)
from_numpy(config, array)¶
Create a multivector from a NumPy array.
Parameters:
- config - Algebra configuration
- array - NumPy array
Returns: MultiVector
Properties¶
config¶
Returns the associated algebra configuration.
Basic Operations¶
Geometric Product geometric_product()¶
Compute the geometric product with another multivector.
Operator: *
Example:
a = alg.vector([1, 0, 0])
b = alg.vector([0, 1, 0])
# Method call
product = a.geometric_product(b)
# Or use operator
product = a * b
Outer Product outer_product()¶
Compute the outer product (wedge product).
Operator: ^
Example:
Left Inner Product left_inner()¶
Compute the left inner product (left contraction).
Operator: |
Note: In non-Euclidean signatures (e.g., spacetime G(1,3,0)),
(A | B).scalar_part()returns the Euclidean inner product. UseA.norm_squared()or(A * B).scalar_part()for the metric-respecting result.
Example:
Right Inner Product right_inner()¶
Compute the right inner product (right contraction).
Example:
Grade Operations¶
grade(r)¶
Extract the r-grade part.
Parameters: r - Grade (0=scalar, 1=vector, 2=bivector, ...)
Returns: MultiVector of specified grade
Example:
# Mixed multivector
mv = alg.scalar(1.0) + e1 + (e1 ^ e2)
scalar = mv.grade(0) # Scalar part
vector = mv.grade(1) # Vector part
bivector = mv.grade(2) # Bivector part
even_part()¶
Extract the even-grade part.
Returns: Even-grade components (scalar + bivector + quadvector + ...)
odd_part()¶
Extract the odd-grade part.
Returns: Odd-grade components (vector + trivector + ...)
scalar_part()¶
Extract the scalar part.
Returns: Scalar value
Example:
coefficients()¶
Get coefficients for all basis elements.
Returns: NumPy array of coefficients for all basis elements
Involution Operations¶
grade_involution()¶
Grade involution.
Multiply r-grade elements by (-1)^r.
Operator: ~ (Note: In Python ~ is bitwise NOT, so use the method)
Example:
reversion()¶
Reversion.
Multiply r-grade elements by (-1)^(r(r-1)/2).
Example:
v = alg.vector([1, 2, 3])
rev = v.reversion() # v (vectors are unchanged)
B = e1 ^ e2
B_rev = B.reversion() # -B (bivectors flip sign)
clifford_conjugate()¶
Clifford conjugate.
Equal to grade involution + reversion.
Example:
Dual Operations¶
dual()¶
Hodge dual.
Maps k-vectors to (n-k)-vectors.
Example:
v = alg.vector([1, 2, 3])
dual_v = v.dual() # Bivector
# In 3D, the dual establishes the connection between cross product and outer product
# a × b = (a ∧ b).dual()
inverse_dual()¶
Inverse dual.
Example:
Norm and Inverse¶
norm()¶
Compute the norm.
Returns: |A| = sqrt(₀)
Example:
norm_squared()¶
Compute the squared norm.
Returns: |A|²
inverse()¶
Compute the multiplicative inverse.
Returns: A⁻¹ such that A * A⁻¹ = 1
Exceptions: Raises exception if not invertible
Note: The formula
A⁻¹ = rev(A)/|A|²is only valid for pure-grade multivectors (e.g., vectors, bivectors, trivectors). For mixed-grade elements like1 + e1 + e2∧e3, the result may not be the true inverse.
Example:
v = alg.vector([1, 2, 3])
v_inv = v.inverse()
# Verify
product = v * v_inv
print(product.scalar_part()) # Approximately 1
is_invertible()¶
Check if invertible.
Geometric Operations¶
project_to(blade)¶
Project onto the subspace represented by a blade.
Parameters: blade - Blade representing the target subspace
Returns: Projected MultiVector
Example:
v = alg.vector([1, 2, 3])
e1 = alg.basis_vector(0)
proj = v.project_to(e1) # Project onto x-axis
print(proj) # e1
reject_from(blade)¶
Reject from the subspace represented by a blade.
Returns: Orthogonal component
Example:
v = alg.vector([1, 2, 3])
e1 = alg.basis_vector(0)
reject = v.reject_from(e1) # Component perpendicular to x-axis
# v = proj + reject
reflect_in(blade)¶
Reflect in the hyperplane represented by a blade.
Formula: v' = -n v n (where n is the normal vector)
Example:
v = alg.vector([1, 2, 3])
e1 = alg.basis_vector(0)
reflected = v.reflect_in(e1) # Reflect in yz plane
# x component is negated
rotate_by(rotor)¶
Rotate using a rotor.
Parameters: rotor - Rotation rotor
Returns: Rotated MultiVector
Formula: v' = R v R†
Example:
import math
alg = nblade.Algebra.euclidean(3)
e1, e2, e3 = alg.basis_vectors()
# Create rotor
plane = e1 ^ e2
rotor = alg.rotor(plane, math.pi / 4)
# Rotate
rotated = e1.rotate_by(rotor)
Other Operations¶
scale(factor)¶
Scalar multiplication.
Parameters: factor - Scale factor
Returns: Scaled MultiVector
add(other)¶
Addition.
Operator: +
commutator(other)¶
Commutator [A, B] = (AB - BA) / 2.
scalar_product(other)¶
Scalar product
get_coefficient(index)¶
Get a single coefficient at the given basis blade index.
Parameters: index - Basis blade index (0 for scalar, 1 for e1, 3 for e1∧e2, etc.)
Returns: Coefficient value
Example:
v = alg.vector([1, 2, 3])
print(v.get_coefficient(1)) # 1.0 (e1 coefficient)
print(v.get_coefficient(3)) # 0.0 (no e1∧e2 component)
is_zero()¶
Check if zero.
__eq__() / __ne__()¶
Equality comparison. Two multivectors are equal if their difference is zero.
Operator: ==, !=
Example:
Operator Overloads¶
| Operator | Method | Description |
|---|---|---|
a + b |
add |
Addition |
a - b |
__sub__ |
Subtraction |
a * b |
geometric_product |
Geometric product |
a ^ b |
outer_product |
Outer product |
a \| b |
left_inner |
Left inner product |
-a |
__neg__ |
Negation |
~a |
grade_involution |
Grade involution |
a == b |
__eq__ |
Equality check |
a != b |
__ne__ |
Inequality check |
Complete Example¶
import nblade
import math
# Create algebra
alg = nblade.Algebra.euclidean(3)
e1, e2, e3 = alg.basis_vectors()
# Create vectors
v = alg.vector([1.0, 2.0, 3.0])
w = alg.vector([4.0, 5.0, 6.0])
# Basic operations
print("Geometric product:", v * w)
print("Outer product:", v ^ w)
print("Inner product:", v | w)
# Grade operations
mixed = alg.scalar(1.0) + v + (e1 ^ e2)
print("Scalar part:", mixed.grade(0))
print("Vector part:", mixed.grade(1))
# Rotation
rotor = alg.rotor(e1 ^ e2, math.pi / 4)
rotated = v.rotate_by(rotor)
print("Rotated:", rotated)
# Norm and inverse
print("Norm:", v.norm())
print("Inverse:", v.inverse())
# Projection and rejection
proj = v.project_to(e1)
reject = v.reject_from(e1)
print("Projection:", proj)
print("Rejection:", reject)