Skip to main content

E-Graph Geometric Algebra (EGGA)

PyPI

Symbolic Geometric Algebra with E-Graphs

Things you can do with this library

  • Simplify expressions
  • Prove equalities
  • Solve for variables

Things that are supported

  • Any signature
  • Arbitrary number of basis vectors
  • Symplectic Geometric Algebra (aka Weyl Algebras)
  • Derivatives
  • Add your own expression types and rules (with egglog)

Based on the Python bindings for egglog

Setup

Supports Python 3.8 and higher.

pip install egga

Usage

The first step is to create a GeometricAlgebra object with a given signature. You can then use its basis vectors as well as functions exposed by it. Use the utility methods provided to do things like simplification and equation solving. In some cases you might need to interface with egglog directly. Below are some examples for common use-cases.

Simplification

from egga.geometric_algebra import GeometricAlgebra
from egga.utils import simplify

ga = GeometricAlgebra(signature=[1.0, 1.0])
e_0, e_1 = ga.basis_vectors
e_01 = e_0 * e_1

# Build an expression to simplify
expr = e_01 * e_0 * ~e_01

# Prints Simplified: -e("0")
print("Simplified:", simplify(ga, expr))

Equation solving

from egglog import union

from egga.geometric_algebra import GeometricAlgebra
from egga.utils import simplify

# Pass eq_solve=True to enable the equation solving rules.
# Add a cost to variable to it gets rewritten to something else.
ga = GeometricAlgebra(signature=[1.0, 1.0], eq_solve=True, costs={"variable": 1_000})

e_0, e_1 = ga.basis_vectors
e_01 = e_0 * e_1

# Solve e_01 * x * ~e_01 = e_0 for x
x = ga.expr_cls.variable("x")
lhs = e_01 * x * ~e_01
rhs = -e_0

# Make LHS equal to RHS
ga.egraph.register(union(lhs).with_(rhs))

assert str(simplify(ga, x)) == str(ga.expr_cls.e("0"))

Equality check

from egga.geometric_algebra import GeometricAlgebra
from egga.utils import check_equality

ga = GeometricAlgebra(signature=[1.0, 1.0])
e_0, e_1 = ga.basis_vectors
e_01 = e_0 * e_1

# Build an lhs to check for equality to an rhs
lhs = e_01 * e_01
rhs = ga.expr_cls.scalar_literal(-1.0)

assert check_equality(ga, lhs, rhs)

The /examples as well as the /tests directories contain more examples.

List of expressions

Operators

Code Description
x_1 + x_2 Addition of x_1 and x_2
x_1 - x_2 Subtraction of x_1 and x_2
x_1 * x_2 Multiplication of x_1 and x_2 (aka the Geometric Product)
x_1 ^ x_2 Wedge / exterior / outer product of x_1 and x_2
x_1 | x_2 Inner ("fat dot") product of x_1 and x_2
-x_1 Negation of x_1
~x_1 Reversion of x_1
x_1 ** x_2 x_1 to the power of x_2
x_1 / x_2 x_1 divided by x_2 (more generally, x_1 right-multiplied by the inverse of x_2)

Functions

Code Description
inverse(x) Multiplicative inverse of x
grade_involution(x) Grade involution of x
clifford_conjugation(x) Clifford conjugate of x
scalar(x) Mark x as a scalar
scalar_literal(f) Create a scalar constant
scalar_variable(s) Create a scalar variable
e(s) Basis vector
e2(s_1, s_2) Basis bivector
e3(s_1, s_2, s_3) Basis trivector
variable(s) Create a variable
cos(x) Cos of x
sin(x) Sin of x
cosh(x) Cosh of x
sinh(x) Sinh of x
exp(x) Exponential function of x
grade(x) Grade of x
mix_grades(x_1, x_2) Represents the mixture of two grades. If x_1 and x_2 are the same, this will be simplified to x_1.
select_grade(x_1, x_2) Selects the grade x_2 part of x_1
abs(x) Absolute value of x
rotor(x_1, x_2) Shorthand for exp(scalar_literal(-0.5) * scalar(x_2) * x_1)
sandwich(x_1, x_2) Shorthand for x_1 * x_2 * ~x_1
diff(x_1, x_2) Derivative of x_1 with respect to x_2

Unsupported but exists, might or might not work

Code Description
boolean(x) Mark x as a boolean
x_1.equal(x_2) Whether x_1 equals x_2
x_1.not_equal(x_2) Whether x_1 does not equal x_2

Caveats

  • Egraphs are bad with associativity (combined with commutativity?) so things can blow up
  • Most operations aren't "fully" implemented (eg. pow only supports powers of two right now)

Contributing

Code contributions as well as suggestions and comments about things that don't work yet are appreciated. You can reach me by email at tora@warlock.ai or in the Bivector Discord.

Metadata

Release files for egga 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for egga 0.1.9
File Size Uploaded
egga-0.1.9.tar.gz 12.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for egga 0.1.9
File Interpreter ABI Platform
egga-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / egga-0.1.9.tar.gz

Download URL egga-0.1.9.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
944603a330f7afdc44184f941bc7a0e6661dc6939163992c66fc3d5633cad8d7
BLAKE2b-256 checksum
How to use checksums
353c60565727d0865a459a654c93c03e1afd7fba2cb48e1f3fe597bbeaca14b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.8.18 Linux/6.2.0-1012-azure

Release files / egga-0.1.9-py3-none-any.whl

Download URL egga-0.1.9-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6bb21a485f3a8142a60b46e35fb1c80b500ab8eb6121043a160c799b34cdb6af
BLAKE2b-256 checksum
How to use checksums
fa8702e8c6818f9de7e3c7ea32e1935c4b29194f6508631694390532ed7f0cc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.8.18 Linux/6.2.0-1012-azure

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release 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