Hacker News new | ask | show | jobs
by wyager 1471 days ago
GA is more general than (and superior to) quaternions (the even subalgebra of G3). However, it requires a powerful type system and compiler to compile general GA expressions to something as efficient as quaternions. C++ won't cut it. You might be able to get clever by defining a special numerically indexed type for Gn or its even subalgebras; C++ could probably do that. But it wouldn't be as nice as fully generic GA.
2 comments

What do you mean by powerful type system and compiler? Do you mean an optimizing compiler that can eliminate the redundant zero terms when multiplying multivectors with many zero grades?
Correct. Quaternions have 4 elements and a small number of multiplications. G3 has 8 elements and more multiplications. This gets worse quickly in higher dimensions.
for general GA yes but for the GA needed to replace quaternions in 3D?

I'm far from good at math but the GA article linked above has this comparision of quaternion code vs rotor (GA) code

https://marctenbosch.com/quaternions/code.htm

Operations in G3 have a bunch of extra work compared to operations on quaternions alone due to the presence of odd grades. However, if your values are quaternionic, these grades should always be zero, so you can safely elide the operations. The compiler just has to be smart enough to see this.

The basis of G3 is 1,x,y,z,xy,xz,yz,xyz. Quaternions only have 1,xy,xz,yz. Quaternion multiplications are closed; xyyz = xz, xyxz = -yz, xzyz = -xy. xyxy=-1. If your compiler is smart enough to figure out that x,y,z,xyz are always zero, you can save the extraneous operations.