Skip to content

Geometric Algebra

This section describes the public Python API of pytanga — the Python interface to TanGA's geometric algebra engine. For the interactive 3D/2D visualizer, see the Visualization section.

2D + 3D algebras

TANGA supports both 2D and 3D geometric algebras. Use BasisE2(), "P2", "N2", or "PGA2" for 2D; "E3", "P3", "N3", or "PGA3" for 3D.

Topics

Guide What you will learn
Environment & Setup Installation prerequisites, uv environment, automatic C++ compilation and caching
Algebra submodule Algebra, MV, duals, modulus arithmetic, galgebra bridge — the core GA types and operations
Basis classes How BasisE2, BasisP2, BasisN2, BasisPGA2 (2D) and BasisE3, BasisP3, BasisN3, BasisPGA3 (3D) expose named blades
BladeMask Construction, properties, set operations — the foundational type labelling all matrix and tensor axes
Matrix Operations MVMatrix, MVProductMatrix — product‑matrix and blade‑mask pipeline
Equation Solving solve, solve_lsq, solve_mod — automatic blade‑mask derivation and linear system solving via free functions
Tensor Operations MVTensor, MVLabeledTensor, product_tensor() — label‑driven tensor contractions, broadcasts, and slicing
Geometry Submodule Point, Line, Plane, Rotor, Motor — algebra-independent entity/operator types usable in 2D and 3D, analyze() and create() pipelines
Quadrics BasisQ2/BasisQ3 conic & quadric spaces, point reconstruction, the 7→8 point effect

Quick Start

import pytanga

# Euclidean 3D algebra
alg = pytanga.Algebra(3, 0)

# Create multivectors
a = alg("e1 + 2 e2")
b = alg("e2 + e3")

# Geometric product
print(a * b)

# Outer product
print(a ^ b)

For named blades use a Basis class and construct multivectors from strings:

from pytanga.basis import BasisE3

E3 = BasisE3()
v  = E3("e1 + 2 e2 + 3 e3")
w  = E3("e2")
print(v * w)

AI-Tool Documentation Access

When pytanga is installed as a dependency, the markdown documentation and example scripts are packaged with the wheel. AI coding tools can make them available via:

import pytanga

pytanga.install_docs()     # copies docs to .dep-docs/pytanga/
pytanga.install_examples() # copies examples to .dep-examples/pytanga/
pytanga.install_info()     # installs docs and examples in one call

install_docs() copies the packaged _docs/ directory (or the local docs/ in a source checkout) to .dep-docs/pytanga/. AI tools can then read e.g. .dep-docs/pytanga/py/ga/geometry/entities.md without needing the full tanga source.

install_examples() copies the packaged _examples/ directory (or the local py/examples/ in a source checkout) to .dep-examples/pytanga/. AI tools can then reference e.g. .dep-examples/pytanga/geometry/e3_entities.py for usage examples.

install_info() runs install_docs() followed by install_examples(). Each function removes any previously installed copy first, so the target is always a faithful mirror of the packaged docs/examples, and it raises an error (after printing a message) if the old copy cannot be removed or the new one cannot be written.

All three functions are idempotent — call them again to refresh the copies.

Example Scripts

All runnable examples — grouped by topic and searchable by keyword, with full source code on each page — are listed in the Examples section. Geometric algebra examples live under Examples → Geometric Algebra.

Background

For the mathematical background of the null-vector embedding used in BasisN3, BasisPGA3, BasisN2, and BasisPGA2, see pga_null_embedding.md.