Galixir.Blade (galixir v0.16.0)

Copy Markdown View Source

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

This 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

dual_sign(mask, dimension)

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.

grade(mask)

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

indices(mask)

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]

inspect(mask, bases)

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"

multiply(a, b, signature)

Multiplies two basis blades using the given metric signature.

Returns a tuple containing:

  • the scalar coefficient (1, -1, or 0)
  • the resulting blade mask

The multiplication consists of:

  1. Reordering basis vectors into canonical order, producing a sign.
  2. Applying the metric for basis vectors appearing in both blades.
  3. 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

swap_sign(a, b)

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:

  • 1 when an even number of swaps is required
  • -1 when an odd number of swaps is required