Geometric Algebra (GA) is a fascinating concept, but :
"x + pi/2*e0 - e1**2"
to mean \( x + \frac{\pi}{2}\mathbf{e_0} - \mathbf{e_1}^2 \)
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.
One can build a very generic geometric algebra
by taking a vectorial space of infinite (though countable)
dimension, with both positive-squared vectors
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.
M = pi/2 * e0∧e1 - a·b + 2.1*no∧ni∧ē3This will produce an AST.
This subsection is yet to be written
For now, you can look at the code
That part is actually easy, thanks to the excellent PEG.js library.
To write the grammar, I took inspiration from the javascript example.