[ANN] Grassmann.jl : Conformal geometric algebra


Grassmann algebra, Clifford algebra, and conformal geometric algebra are powerful algebraic tools

To help bring conformal geometric algebra to julia, the Grassmann library now provides most of the basic tools needed to begin working with a fully generalized MultiVector algebra.

This package is a work in progress providing the necessary tools to work with arbitrary dual MultiVector elements with optional origin. Due to the parametric type system for the generating VectorSpace , the Julia compiler can fully preallocate and often cache values efficiently. Both static and mutable vector types are supported.

It is currently possible to do both high-performance numerical computations with Grassmann and it is also currently possible to use symbolic scalar coefficients when the Reduce package is also loaded.

Fully general products available for high-performance and sparse computation include ∧,∨,⋅,* (exterior, regressive, interior, geometric). Some unary operations include complementleft , complementright , reverse, involve , conj , and adjoint .

Notable features

What’s particularly special about Grassmann is its ability to handle caching and code generation in a tiered multi-stage setup and the ability to easily handle the creation of extra specialized methods to replace composite or dynamic dispatch scenarios with more efficient code.

This can work up to N=62 indices in the VectorSpace, reaching a 4,611,686,018,427,387,904 dimensional TensorAlgebra space, which is much beyond what Julia arrays can handle natively.

julia> using Grassmann

julia> i,j,k = complementright.((-Λ(3).v1,-Λ(3).v2,-Λ(3).v3))
(-1v₂₃, 1v₁₃, -1v₁₂)

julia> @btime i^2, j^2, k^2, i*j*k
  158.925 ns (5 allocations: 112 bytes)
(-1v, -1v, -1v, -1v)

julia> @btime -(j+k) * (j+k)
  176.233 ns (8 allocations: 240 bytes)

julia> @btime -(j+k) * i
  111.394 ns (6 allocations: 192 bytes)
0 - 1v₁₂ - 1v₁₃

The Grassmann package is fully general, and includes number systems such as quaternions 1,i,j,k.

Design, code generation

Due to the abstract generality of the product algebra code generation, it is possible to extend the Grassmann library to include additional high performance products with few extra definitions. Operations on ultra-sparse representations for very high dimensional algebras will be gaining further performance enhancements in future updates, while the standard lower dimensional algebras already are highly performant and optimized. Thanks to the design of the product algebra code generation, any additional optimizations to the type stability will automatically enhance all the different products simultaneously. Likewise, any new product formulas will be able to quickly gain from the setup of all of the existing optimizations.

Calculating some bivectors

There are are a variety of resources online which help with the introduction to the subject. One notable video useful for just about anybody interested in geometric algebra was posted by @waldyrious

Some of the examples in that video can be verified using Reduce, Grassmann in julia

julia> using Reduce,Grassmann; basis"4"
Reduce (Free CSL version, revision 4590), 11-May-18 ...
(⟨++++⟩, v, v₁, v₂, v₃, v₄, v₁₂, v₁₃, v₁₄, v₂₃, v₂₄, v₃₄, v₁₂₃, v₁₂₄, v₁₃₄, v₂₃₄, v₁₂₃₄)

julia> P,Q = :px*v1 + :py*v2 + :pz* v3 + v4, :qx*v1 + :qy*v2 + :qz*v3 + v4
(pxv₁ + pyv₂ + pzv₃ + 1.0v₄, qxv₁ + qyv₂ + qzv₃ + 1.0v₄)

julia> P∧Q
0.0 + (px * qy - py * qx)v₁₂ + (px * qz - pz * qx)v₁₃ + (px - qx)v₁₄ + (py * qz - pz * qy)v₂₃ + (py - qy)v₂₄ + (pz - qz)v₃₄

julia> R = :rx*v1 + :ry*v2 + :rz*v3 + v4
rxv₁ + ryv₂ + rzv₃ + 1.0v₄

julia> P∧Q∧R
0.0 + ((px * qy - py * qx) * rz - ((px * qz - pz * qx) * ry - (py * qz - pz * qy) * rx))v₁₂₃ + (((px * qy - py * qx) + (py - qy) * rx) - (px - qx) * ry)v₁₂₄ + (((px * qz - pz * qx) + (pz - qz) * rx) - (px - qx) * rz)v₁₃₄ + (((py * qz - pz * qy) + (pz - qz) * ry) - (py - qy) * rz)v₂₃₄

In this example, the exterior product of points is inspected and compared with inner,cross products.

It is my hope to use absorb of the feedback from the geomtric algebra community when making ongoing improvements to help refine the package’s source code generation and sparse specialization.


For a gentler introduction, I would recommend The Vector Algebra War: a historical perspective (video, 13min). As someone lacking rigorous mathematical background, I find that this sort of layman-friendly introductions greatly help motivate the initial exploration of this field, and consumption of more advanced materials.

For those more familiar with the concepts used in GA, the Ganja.js Cheat Sheets provide some really nice and comprehensive reference sheets.

It may also be worth noting the (abandoned?) package GeoAlg.jl by @andrioni:

work-in-progress straight port of Fontijne’s reference implementation of geometric algebra utilities to Julia.


Thank you. I can’t wait to try this out!

Daniel Fontijne’s OpenGL GAViewer still has one of the best graphic displays for multivectors I have seen, but its development has been defunct for a while now. I’ve scanned through his source and most of the drawing takes place in only a few methods. It might be nice to merge Grassmann.jl with GAViewer’s color/display methods on top of Makie.jl to explore multivectors and spaces. I’ve been waiting for Makie’s WebGL backend before tackling something like this.


There is also pyganja based on ganja.js for visualization, perhaps that would be easier to port since in Julia we already have python interoperability?

The Grassmann package is going to remain a separate package, it is intended for the abstract mathematical representation aspect of geometric algebra. Any visualization library would best be placed into a separate repository, since visualization requires additional many dependencies.

Perhaps you could get started on such a repository? related issue on using SymPy with Grassmann

1 Like

Looks great! So this is now more of a Geometric / Clifford Algebra package than a Grassmann Algebra package? Do you plan on supporting custom metrics in as a generalization to just specifying the signature?

I had tried doing something similar a while ago but got stuck figuring out a satisfactory way of supporting non-diagonal metrics.

1 Like

Roughly speaking, these algebras of Geometric / Clifford / Grassmann types are all fundamentally the same thing, with slightly different notations, formalisms, and preferences. The package itself implements conformal geometric algebra and it is named after Grassmann, who is often not adequately cited for his role in the invention of linear algebra and many other related subjects.

Yes, I do have an interest in that regard… but it is much lower on my list of design priorities. My primary goal was to get started an initial setup intended for high performance. The current setup helps facilitate the highest performance possible for most standard conformal geometric algebras.

There are a couple of ideas I got for that, but I have other goals first. You could open an issue for it?


To those interested, I opened up a new pull-request to discuss the sign value of LinearAlgebra.I when interpreted as a generalized universal pseudoscalar value

Since LinearAlgebra.I has a sign associated to it, I would like to interpret that as a minus sign, which is helpful in the theory and expressiveness of various formulas, but am opening it for discussion