Skip to main content

Clifford and Geometric Algebra with TensorFlow

Project description

TFGA - TensorFlow Geometric Algebra

Build status PyPI

GitHub | Docs | Benchmarks

Python package for Geometric / Clifford Algebra with TensorFlow 2.

This project is a work in progress. Its API may change and the examples aren't polished yet.

Pull requests and suggestions either by opening an issue or by sending me an email are welcome.

Installation

Install using pip: pip install tfga

Requirements:

  • Python 3
  • tensorflow 2
  • numpy

Basic usage

There are two ways to use this library. In both ways we first create a GeometricAlgebra instance given a metric. Then we can either work on tf.Tensor instances directly where the last axis is assumed to correspond to the algebra's blades.

import tensorflow as tf
from tfga import GeometricAlgebra

# Create an algebra with 3 basis vectors given their metric.
# Contains geometric algebra operations.
ga = GeometricAlgebra(metric=[1, 1, 1])

# Create geometric algebra tf.Tensor for vector blades (ie. e_0 + e_1 + e_2).
# Represented as tf.Tensor with shape [8] (one value for each blade of the algebra).
# tf.Tensor: [0, 1, 1, 1, 0, 0, 0, 0]
ordinary_vector = ga.from_tensor_with_kind(tf.ones(3), kind="vector")

# 5 + 5 e_01 + 5 e_02 + 5 e_12
quaternion = ga.from_tensor_with_kind(tf.fill(dims=4, value=5), kind="even")

# 5 + 1 e_0 + 1 e_1 + 1 e_2 + 5 e_01 + 5 e_02 + 5 e_12
multivector = ordinary_vector + quaternion

# Inner product e_0 | (e_0 + e_1 + e_2) = 1
# ga.print is like print, but has extra formatting for geometric algebra tf.Tensor instances.
ga.print(ga.inner_prod(ga.e0, ordinary_vector))

# Exterior product e_0 ^ e_1 = e_01.
ga.print(ga.ext_prod(ga.e0, ga.e1))

# Grade reversal ~(5 + 5 e_01 + 5 e_02 + 5 e_12)
# = 5 + 5 e_10 + 5 e_20 + 5 e_21
# = 5 - 5 e_01 - 5 e_02 - 5 e_12
ga.print(ga.reversion(quaternion))

# tf.Tensor 5
ga.print(quaternion[0])

# tf.Tensor of shape [1]: -5 (ie. reversed sign of e_01 component)
ga.print(ga.select_blades(quaternion, "10"))

# tf.Tensor of shape [8] with only e_01 component equal to 5
ga.print(ga.keep_blades(quaternion, "10"))

Alternatively we can convert the geometric algebra tf.Tensor instance to MultiVector instances which wrap the operations and provide operator overrides for convenience. This can be done by using the __call__ operator of the GeometricAlgebra instance.

# Create geometric algebra tf.Tensor instances
a = ga.e123
b = ga.e1

# Wrap them as `MultiVector` instances
mv_a = ga(a)
mv_b = ga(b)

# Reversion ((~mv_a).tensor equivalent to ga.reversion(a))
print(~mv_a)

# Geometric / inner / exterior product
print(mv_a * mv_b)
print(mv_a | mv_b)
print(mv_a ^ mv_b)

Notebooks

Generic examples

Quantum Electrodynamics using Geometric Algebra

Projective Geometric Algebra

Project details


Download files

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

Source Distribution

tfga-0.1.10.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

tfga-0.1.10-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file tfga-0.1.10.tar.gz.

File metadata

  • Download URL: tfga-0.1.10.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for tfga-0.1.10.tar.gz
Algorithm Hash digest
SHA256 6dd7428afbcfb8e01bd1a870e89248be6a79ad7b5023ce1a5283f1fdbcd00ceb
MD5 e84989ba9e63d3135a6fe18f63391302
BLAKE2b-256 93aabfd857dfbecd752da4b98d1ad377fd989bd2b9e643ab94b04e882ed3a010

See more details on using hashes here.

File details

Details for the file tfga-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: tfga-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for tfga-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 12ad818752de8484303e94a32bc27daf109e9bebd926a1ee15010d12c2c8726a
MD5 4e4847eac4ed815ae960dd19bd354d6c
BLAKE2b-256 c7ef8237c4b6ac4a6faac3cb4a31f6e65143d253ba8700c07afc1d275bee9af3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page