4 ms·
I once saw a critique of the use of geometric algebra in software in that they said it was "untyped" - disparate mathematical objects (scalars, vectors, etc) ar
by nextaccountic 3y ago
I once saw a critique of the use of geometric algebra in software in that they said it was "untyped" - disparate mathematical objects (scalars, vectors, etc) are 'unified' as the same thing, which prevents some errors to be caught at compile time or even at runtime.
For example, adding a scalar and a vector is a meaningful operation in geometric algebra, but it's most likely a programming error if it happens in the overwhelming majority of code. Linear algebra packages in most languages can often detect this error at compile time, or, for dynamic languages, at least detect it at runtime. But if you run a geometric algebra library it can't detect this kind of error, because this would be a legitimate (albeit error prone) operation.
What do geometric algebra enthusiasts think about this?
- DrDroop 3y agoSome GA libraries[1][2] define types for the different kind of objects (grades), although they are time consuming to implement and fixed in the number of dimensions they describe. But you are right that the most implementation combine all grades into a single array, but the biggest problem with those is that the size of the array in 2^n with n the number of dimensions. To work in 3D you probably want to use R(3,0,1) for all rigid transformation or even R(4,0,1), but that brings the total number of 16 or 32 floats to just represent a point. Imho the biggest problem in GA for CS is the lack of a good ecosystem of tools. Ganja.js is nice, probably the best in class when it comes to API design, but is completely useless when trying to work with other JS libraries because ganja.js has it's own weird transpiler. [1]https://www.jeremyong.com/klein/ https://www.jeremyong.com/klein/ [2]https://github.com/wrnrlr/g3 https://github.com/wrnrlr/g3
- nextaccountic 3y ago> Some GA libraries[1][2] define types for the different kind of objects (grades) That's nice! This reminds of me things like, linear algebra libraries that will type-check matrices so that a 2x2 matrix can't be added to a 2x3 matrix (but then you can have a dynamic matrix that will error only in runtime), like https://nalgebra.org/ https://nalgebra.org/ and others.
- Lichtso 3y agoThe GA community in general is very small. So yes, tooling could be better, but IMO that is not even the problem. The lack of understanding how to use it is, because GA is not explicitly taught in schools or universities. I have written a compiler which generates SIMD ready typed code for the desired GAs. You can then use that output as a normal library for your application. https://github.com/Lichtso/geometric_algebra https://github.com/Lichtso/geometric_algebra
- okaleniuk 3y agoI think, type inference is a poor man's model checking. And it makes exactly as much sense as your model does. There is no such thing as a universal model. https://wordsandbuttons.online/static_typing_isnt_free.html https://wordsandbuttons.online/static_typing_isnt_free.html Adding scalar and a vector may be a breach of model but it may also have several different meanings each of them pragmatic in its own context. It may mean concatenation, as with C++ strings or adding the same scalar to every vector's element as with APL tensors. Geometric algebra imposes its own type relations and has all the rights to do so.
- LightMachine 3y agoAs someone who has been studying type theory and developing strongly typed programming languages, that is a very strange take to me. It isn't untyped, it has a type: the GeometricAlgebra type, which just happens to have a very rich structure. Complaining about that is like complaining that Int isn't split into two types because it has negative and positive values. That makes no sense at all.
- chpatrick 3y agoThe fact is thay in real world linear algebra code there are distinct mathematical objects that you do want to keep separate and not mix up. It's already too easy to add the wrong vectors or forget to invert something without also making it possible to do nonsense operations. That being said I can't see why you can't make newtypes over the one geometric algebra type. But at that point, what's the advantage over plain old vectors and matrices?
- Nevermark 3y ago1) Sub-typing a clean general type for all kinds of special purposes. vs. 2) Having to create or acquire lots of separate types for all the specialized types you (or others) need, along with all their operations, probably in inconsistent ways, and leaving potential types missing, including not having the general type. Also, the separate type path does not help you cognitively understand the real relationships between the separately crafted types. A really easy example is the convenience of having a big (unlimited size) integer type that can be parameterized to any size subtype you want. You get all the arithmetic operations across all those fixed sizes for free, because those algorithms are just easily auto optimized versions of the general operations. A good system could even auto optimize for an operation that took two integers of different fixed sizes. Clean concrete closed general types are the powerhouse wonders of the mathematical world. They are just as great for algorithm use. As long as you can subtype.
- chpatrick 3y agoI can certainly see the mathematical appeal but as an end user I'm still not convinced. If you're still dealing with rotations, points lines etc as subtypes, do you care whether they're all implemented internally the same way or as they are now with vectors quaternions matrices etc? Is geometric algebra even more efficient than these or is it purely aesthetic? What I'm saying is, if my code is strongly typed and deals with these various geometric objects, what benefit do I get if they're internally implemented with geometric algebra as opposed to how they are now?
- hamish_todd 3y ago>"untyped" It's amazing because that's the diametric opposite of what I'd consider to be true this is what the non-GA approach does, and which we avoid! The modern approach to GA, eg https://en.wikipedia.org/wiki/Plane-based_geometric_algebra https://en.wikipedia.org/wiki/Plane-based_geometric_algebra, distinguishes planes-through-the-origin, points, lines-through-the-origin, and lines-at-infinity. These four different types all get called "vectors" in the ordinary mindset. The cross product is said to take in two "vectors" and give you a "vector", but in reality it's generally taking two planes and giving you a line. This is talked about in the fourth paragraph of the wiki article :)
- ath92 3y agoI’d never seen this explanation of what a cross product is before. It really clicked for me, even just reading it as text. Thanks!
- nextaccountic 3y agoMy question was more like, will all those four mathematical objects (alongside other stuff like scalars) be represented as a single data type in a given library that implements geometric algebra, or will they be given distinct data types? Someone else answered that they might be given a single data type, but it's possible to give more precise types, which seem cool! (do you have any library to mention, alongside the ones already mentioned?)
- at_compile_time 3y agoI think that's one downside to that kind of implementation. Computational performance and everything either requiring heap allocation or 2^n values, most of which which are zero are others problems. My implementation generates a struct for each grade, even and odd grades (which perform transformations), and then a multivector type with everything. If you mistakenly add a scalar and a vector, you'll immediately see unexpected types in your inline type hints. The downside to my approach is a combinatorial explosion in the number of types and operations between them. Anyone know a seamless way to do lazy code generation in Rust?
- ogogmad 3y agoThis makes me better appreciate why Homotopy Type Theory might be useful in a type system: It allows for a simple but inefficient version of a type to coexist with a faster variant of that type. The type system could be made aware that those are two different ways of representing the same mathematical object. Have GA people tried anything along this direction?
- nextaccountic 3y ago> This makes me better appreciate why Homotopy Type Theory might be useful in a type system: It allows for a simple but inefficient version of a type to coexist with a faster variant of that type. The type system could be made aware that those are two different ways of representing the same mathematical object. Okay I've been thinking a lot about this problem of multiple representations. Is there any language that actually uses this equivalence of types as a way to select between different ways to represent the same data? An use case would be something like, a smart list type that will select between a growable linear vector, a copy on write persistent list, etc. and select between them based on a) which operations you do to the list (for example, if you use it in a linear fashion, it doesn't need to be persistent), and b) user annotations in code. Another use case is to define unary peano numbers like data Nat = Zero | Succ Nat and have the type system understand automatically this doesn't need to be stored like this, and is in fact the same as a (big) int. Some languages have special-casing for this, but this could work generically as well.
- itishappy 3y agoGA has stronger types than the vector math taught in school, we just don't have an intuition for it. Here's an example: Traditional vector math gives the output of the cross-product of two vectors the same type. (That's why it's only meaningful in 3d.) The input and output lives in the same space, you can presumably do meaningful math with them and get a result that's still a vector. The types do not help us. GA treats this operation differently. The cross-product-equivalent-operation returns a completely different type. Sure, you can add the inputs and outputs, but that returns a third type! If we built an intuition for this type system, it would help us.
- phkahler 3y agoIn geometry code (from my own experience) I use a cross product specifically to get a vector perpendicular to two other vectors. There are other times like calculating the area of a triangle in 3-space that involve taking the magnitude of the cross product or whatever. I don't see how any of this solves hard problems. You need to know a formula to compute what you want regardless of the underlying representation. I also think the more abstract you get, the smaller portion of the population can understand and work with it. Lots of people understand numbers. Some of those understand vectors. Some of those can understand a transformation matrix. Some of those can understand quaternions. Some of those can understand GA. I'm not sure it's a question of teaching it earlier in school either. Go watch the 3-blue-one-brown video on visualizing quaternion rotation, and try to really appreciate how abstract and hard to understand that is compared to multiplying s set of (ortho-normal) basis vectors by some coordinates to do rotation. Then remember that quaternions are in some sense a subset of the GA abstractions people want us to use. This isn't going to happen any time soon.
- ogogmad 3y agoThat might partially be true, but GA can mostly be given an API that hides the gory and confusing algebra. This is actually quite a natural thing to do. The idea is pretty much that in 3D you can begin with reflections through planes, which most people do understand, and then represent other Euclidean transformations as straightforward compositions of those. Once you have an API for transformations, then a geometric figure like a point or a line can be represented by the reflection (which is a transformation again) through it.
- ogogmad 3y agoIn a dependently typed language, these would be different sigma types. Specialisations of functions to them, and the corresponding proofs of correctness, could be computed automatically over these sigma types, likely using techniques in automatic theorem proving and/or LLMs. Good question!