Skip to main content

galaga_matrix

Matrix representations for galaga Clifford algebras.

Status: published to PyPI alongside galaga. Released as part of the monorepo.

What it does

Every multivector in a Clifford algebra can be represented as a matrix. This package provides to_matrix / from_matrix conversions, spinor-column conversions for supported even subalgebras, quaternion-block output for selected quaternionic signatures, and a MatrixRepr wrapper with LaTeX rendering for use in marimo notebooks and Jupyter.

The canonical spinor-column API is to_spinor_column / from_spinor_column. to_spinor_matrix / from_spinor_matrix are compatibility aliases.

Two modes

Mode Matrix size Entries Works for Roundtrips
left-regular 2ⁿ × 2ⁿ real any Cl(p,q,r) always
compact 2^⌊n/2⌋ × 2^⌊n/2⌋ complex non-degenerate Cl(p,q) only when the selected representation is injective

Quick start

from galaga import Algebra
from galaga_matrix import to_matrix, from_matrix, MatrixRepr

# Pauli matrices from Cl(3,0)
cl3 = Algebra(3)
e1, e2, e3 = cl3.basis_vectors()

mat = to_matrix(e1, mode="compact")   # returns MatrixRepr (2×2 Pauli σ₁)
mat @ mat                              # MatrixRepr: σ₁² = I
mat.inv()                              # MatrixRepr: σ₁⁻¹ = σ₁
mat.trace()                            # 0 (traceless)
mat.mv                                 # back to Multivector

# Named MV gets automatic ρ(name) symbolic name
R = (e1 * e2).name(latex=r"\hat{B}")
M = to_matrix(R, mode="compact")
M.latex()                              # "\\rho(\\hat{B}) = \\begin{pmatrix}..."
M.expr.latex()                         # "\\rho(\\hat{B})"

# from_matrix can infer algebra and mode from MatrixRepr
from_matrix(M)                         # MV named ρ⁻¹(ρ(B̂))
from_matrix(cl3, M.mat, mode="compact")  # unnamed MV (raw array)

# Dirac matrices from Cl(1,3)
sta = Algebra(1, 3)
g0 = sta.basis_vectors()[0]
to_matrix(g0, mode="compact")  # 4×4 Dirac γ⁰

# Left-regular works for everything, including PGA
pga = Algebra(2, 0, 1)
v = pga.basis_vectors()[0]
to_matrix(v)  # 8×8 real matrix

MatrixRepr

MatrixRepr is a transparent numpy proxy that wraps a matrix with:

  • All arithmetic operations@, +, -, *, /, ** return MatrixRepr
  • Linear algebra.T, .H, .conj(), .trace(), .det(), .inv()
  • Numpy interopnp.add(M, N), np.conj(M) etc. return MatrixRepr via __array_ufunc__
  • Symbolic naming.name() gives matrices the same naming and expression-tree behavior as multivectors
  • Metadata propagationalgebra, mode, basis, and kind pass through operations
  • IndexingM[i,j] for elements, M[0:2, 0:2] for submatrices
  • Rendering.latex(), ._repr_latex_() for notebooks
  • Escape hatch.mat gives the raw numpy array
  • Roundtrip.mv converts back to a Multivector (requires algebra=)
  • FactoriesMatrixRepr.identity(k), MatrixRepr.zeros((m,n)), .kron(other)

Auto-naming

to_matrix(named_mv) names the result as ρ(name) and gives it a symbolic representation-map expression. from_matrix(named_matrix) can infer the algebra and mode from MatrixRepr and names the recovered MV as ρ⁻¹(name-or-expression). Raw arrays still need from_matrix(alg, array, mode=...). Unnamed inputs pass through without new names. Quaternion-block mode uses ρ_{\mathbb{H}}(name).

Works in galaga_marimo t-strings:

gm.md(t"""
The Pauli matrix: {to_matrix(e1, mode="compact"):block}
""")

Named special cases

The compact representation produces the standard textbook matrices:

  • Cl(3,0): 2×2 Pauli matrices (σ₁, σ₂, σ₃)
  • Cl(0,3): 2×2 with iσ₁, iσ₂, iσ₃
  • Cl(1,3): 4×4 Dirac matrices (γ⁰, γ¹, γ², γ³) in the Dirac representation
  • Cl(3,1): 4×4 Dirac matrices in the mostly-plus convention

All other non-degenerate signatures are handled by the general periodicity recursion.

Limitations

  • Degenerate algebras (r > 0): only left-regular mode works. compact raises NotImplementedError.
  • Double algebras (Cl(p,q) where (q−p) mod 8 ∈ {3, 7}): to_matrix compact works, but from_matrix compact raises if the selected compact representation is not injective. Use left-regular for exact inverse conversion. See Double Clifford Algebras.
  • Quaternion output: to_quaternion_matrix and quaternion spinor conversions use explicit quaternion-block bases. They currently support Cl(0,2) and Cl(1,3), and reject double algebras such as Cl(0,3).
  • Spinor roundtrip: spinor conversions are rank-checked for the actual reference-column map. Signatures whose even subalgebra is not injective under that map raise TypeError.
  • No caching: blade matrices are rebuilt on every call. Fine for interactive use, not for hot loops.

Architecture decisions

See docs/adrs/.

Tests

PYTHONPATH=.:packages/galaga_matrix uv run pytest packages/galaga_matrix/tests/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

galaga_matrix-1.7.6.tar.gz (80.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

galaga_matrix-1.7.6-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file galaga_matrix-1.7.6.tar.gz.

File metadata

  • Download URL: galaga_matrix-1.7.6.tar.gz
  • Upload date:
  • Size: 80.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for galaga_matrix-1.7.6.tar.gz
Algorithm Hash digest
SHA256 67d8700b3ef3cd93f4c3aecb36e6946c9b42e6381cbea0a909cb46a7dcb6a353
MD5 cd3b193c6428e1092936311c837d6bcb
BLAKE2b-256 8c38acb59dfb965c48be1278a8aefb53dd297d6bfbb4a0fd3fb136724f08c83f

See more details on using hashes here.

File details

Details for the file galaga_matrix-1.7.6-py3-none-any.whl.

File metadata

  • Download URL: galaga_matrix-1.7.6-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for galaga_matrix-1.7.6-py3-none-any.whl
Algorithm Hash digest
SHA256 dcd1954ab161c168e205a384f126df35e7e30f8e34c9ea78000ca3b2f21f386d
MD5 0e29798dbc9947f9e12d26a89fb19999
BLAKE2b-256 b4c5842e077026456749fe8f7c98e6219e7b56ef7db1b123770050fa734ea4e1

See more details on using hashes here.

Release history Release notifications | RSS feed

1.8.1

2 files

1.8.0

2 files

This release

1.7.6 This release

2 files

1.7.5

2 files

1.7.4

2 files

1.7.3

2 files

1.7.2

2 files

1.7.1

2 files

1.7.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page