Provides operations on basis blades using bitmask encoding.
A basis blade is represented as an integer bitmask where each bit indicates whether a basis vector is present.
For example, in a 3-dimensional algebra:
e1 -> 001
e2 -> 010
e3 -> 100
e12 -> 011
e13 -> 101
e123 -> 111This representation allows basis blade operations such as multiplication, grading, and dual computation to be performed efficiently using bitwise operations.
Blade multiplication is determined by two factors:
- the sign caused by reordering basis vectors into canonical order
- the metric contribution from repeated basis vectors
Summary
Functions
Calculates the sign contribution of dualizing a blade.
Returns the grade of a basis blade.
Returns the basis vector indices contained in a blade mask.
Returns a human-readable representation of a blade mask using the given basis identifiers.
Multiplies two basis blades using the given metric signature.
Calculates the sign required to reorder two blades into canonical order.
Functions
Calculates the sign contribution of dualizing a blade.
The dual of a blade is computed relative to the pseudoscalar of the algebra. This function determines the sign introduced when moving the blade and its complement into canonical order.
Returns the grade of a basis blade.
The grade is the number of basis vectors contained in the blade. It is calculated by counting the number of set bits in the blade mask.
Examples
iex> Galixir.Blade.grade(0b011)
2
iex> Galixir.Blade.grade(0b111)
3
Returns the basis vector indices contained in a blade mask.
Each set bit in the mask corresponds to a basis vector. Indices are zero-based and follow the ordering used by the algebra signature.
Examples
iex> Galixir.Blade.indices(0b001)
[0]
iex> Galixir.Blade.indices(0b101)
[0, 2]
iex> Galixir.Blade.indices(0b111)
[0, 1, 2]
Returns a human-readable representation of a blade mask using the given basis identifiers.
The bases tuple defines the labels corresponding to bit positions in the mask.
Examples
iex> Galixir.Blade.inspect(0b001, {1, 2, 3})
"e1"
iex> Galixir.Blade.inspect(0b101, {1, 2, 3})
"e13"
iex> Galixir.Blade.inspect(0b1000, {1, 2, 3, 0})
"e0"
iex> Galixir.Blade.inspect(0, {1, 2, 3})
"1"
Multiplies two basis blades using the given metric signature.
Returns a tuple containing:
- the scalar coefficient (
1,-1, or0) - the resulting blade mask
The multiplication consists of:
- Reordering basis vectors into canonical order, producing a sign.
- Applying the metric for basis vectors appearing in both blades.
- Combining the remaining basis vectors using XOR.
Examples
iex> Galixir.Blade.multiply(0b001, 0b010, {1, 1, 1})
{1, 3}
iex> Galixir.Blade.multiply(0b001, 0b001, {1, 1, 1})
{1, 0}Signature
The signature defines the square of each basis vector:
{1, -1, 0}represents:
e1² = 1
e2² = -1
e3² = 0
Calculates the sign required to reorder two blades into canonical order.
When multiplying blades, basis vectors from the left blade must be moved before those from the right blade. Each swap changes the sign of the result.
Returns:
1when an even number of swaps is required-1when an odd number of swaps is required