Clifford.JS

A Javascript library for geometric algebra

Work In Progress

github

The Problem

Geometric Algebra (GA) is a fascinating concept, but :

  • It's tough to implement efficiently
  • The existing JS library ( versor ) is cumbersome

The Goal

  • Hide the complicated typing system from the main API (unlike with versor)
  • Parse "x + pi/2*e0 - e1**2" to mean \( x + \frac{\pi}{2}\mathbf{e_0} - \mathbf{e_1}^2 \)
  • Be ultra-generic : infinite dimensions, conformal...
  • Use a sophisticated cache system for optimization
  • Do a bit of formal calculus for real parameters

Quick Primer on Geometric Algebra

Down arrow

A geometric algebra is an associative algebra with a twist :

There exists a vectorial subspace for which all elements have a real square

In other words : $$\forall \mathbf{v}\in\mathcal{V},\; \mathbf{v}^2\in\mathbb{R}$$

Although all associative algebras have a natural vectorial space structure, we reserve the word vector to the elements of the vectorial subspace.

We usually denote vectors with a lowercase, bold roman letter.

A generic element of the algebra is called a multivector.

Multiplication is called the geometric product.

It is noted just like the usual multiplication, with the multiplication sign `*`.

For vectors (and for vectors only !), the geometric product is decomposed into a symetric and an anti-symetric part :

$$\mathbf{uv} = \mathbf{u}\cdot\mathbf{v} +\mathbf{u}\wedge\mathbf{v}$$

They are called the inner product and the outer product.

  • The inner product defines a scalar product in the usual sense of the expression.
  • Only the outer product is easily generalized to any element of the algebra. It is fully associative and anti-symetric.
  • Along with the geometric product, those two operations are the main tools of GA

One can build a very generic geometric algebra by taking a vectorial space of infinite (though countable) dimension, with both positive-squared vectors (\(\mathbf{v}^2 \gt 0\)) and negative-squared ones (\(\mathbf{v}^2 \lt 0\))

Such algebra is called the Universal Algebra

This is what we want to implement

The vector space of the universal algebra has a basis which is made of euclidean vectors $$(\mathbf{e_0},\mathbf{e_1},\ldots)$$ and anti-euclidean ones $$(\mathbf{\bar{e}_0},\mathbf{\bar{e}_1},\ldots)$$ such that $$\mathbf{e_i}\cdot\mathbf{e_j} = \delta_{ij}$$ $$\mathbf{\bar{e}_i}\cdot\mathbf{\bar{e}_j} = -\delta_{ij}$$ $$\mathbf{\bar{e}_i}\cdot\mathbf{e_j} = \mathbf{e_i}\cdot\mathbf{\bar{e}_j} = 0 $$

The linear combination of an euclidean vector with an anti-euclidean one can have a null square. Such vector is called a null vector.

Two particular null vectors are important for the so-called conformal model, which will be discussed later. For now, you can just remember the names and notations for those two : they are called origin and infinity and noted \(o\) and \(\infty\). In the JS code we'll note them `no` and `ni`.

The geometric product of several distinct base vectors is equal to its outer product : $$ \mathbf{b_{i_1}}\mathbf{b_{i_2}}\ldots\mathbf{b_{i_n}} = \mathbf{b_{i_1}}\wedge\mathbf{b_{i_2}}\wedge\ldots\wedge\mathbf{b_{i_n}} $$ where \(\mathbf{b}\) is a placeholder for either \(\mathbf{e}\), \(\mathbf{\bar{e}}\), \(o\) or \(\infty\).

Such product forms an irreducible multivector. It is called a basis blade.

All basis blades form a base of the algebra in the vectorial sense. Our goal is to be able to write any multivector in that base.

This was the bare minimum you need to know in order to understand the rest of this slideshow.

A good entry point to learn more about geometric algebra is the Wikipedia article.

Notable authors on the subject are for instance David Hestenes and Chris Doran. Pablo Colapinto is also notable for having written Versor, a highly efficient library in C++, that was then translated to javascript.

Strategy

  • Write an Object-Oriented Model reflecting most characteristics of the Universal Algebra
  • Write a grammar to parse expressions such as :
    M = pi/2 * e0∧e1 - a·b + 2.1*no∧ni∧ē3
    This will produce an AST.
  • Translate this AST into a structure in the object model.
  • Process this object structure to perform symbolic calculus

The Object Model

Down arrow

This subsection is yet to be written

For now, you can look at the code

The Grammar

That part is actually easy, thanks to the excellent PEG.js library.

To write the grammar, I took inspiration from the javascript example.

What works now

  • the parser works fine (see test.js file)
  • the object model is rich enough to perform basic arithmetics and simplifications on basis blades, which is encouraging for the feasability of the whole concept

TODO

  • Improve the object model : complete classes for involution, scaled multivectors, better `simplify()` methods...
  • Design an efficient caching system, for we don't want to compute the same kind of operations twice!