top | item 25471046

Ganja.js: Geometric Algebra Generator for JavaScript, C++, C#, Rust, Python

212 points| pizza | 5 years ago |github.com | reply

83 comments

order
[+] s1k3s|5 years ago|reply
You had to name it Ganja, didn't you?

Edit: on second thought, good for you! Screw all the politically correctness BS that invades our software development stuff. There's no place for that in science.

[+] joshuamcginnis|5 years ago|reply
> Ganja is a Hindi name for hemp, derived from the word ganjha, from the Sanskrit gañjā, referring to a "powerful preparation from cannabis sativa". The term ganja, one of the oldest and most commonly used synonyms for marijuana in the English language, dates to before 1689.

I had hoped there would be a more direct association between the Hindi name and the underlying mathematics given Indian mathematics emerged as early as 1200 BC. Would make for a perfect reverse-psychology alibi.

[+] whalesalad|5 years ago|reply
It's not really political correctness as much as it is morality. We've been conditioned to believe marijuana is bad, unfortunately.
[+] supplemonte|5 years ago|reply
Commenters without a substantial or interesting contribution to make tend to focus on things like names.
[+] iso8859-1|5 years ago|reply
There is lots of place for politics in science, universities have internal politics also.

Ganja is the second largest city in Azerbaijan, why is it such a political statement?

[+] throwaway2245|5 years ago|reply
It effectively makes the license "don't use this in an educational setting", unfortunately.
[+] adamnemecek|5 years ago|reply
You should check out the bivector community dedicated to geometric algebra https://bivector.net/.

Check out a demo https://observablehq.com/@enkimute/animated-orbits

Join the discord https://discord.gg/vGY6pPk.

Enki (the guy behind bivector) also gave a talk on GA at SIGGRAPH 2019 https://www.youtube.com/watch?v=tX4H_ctggYo

[+] iamwil|5 years ago|reply
I thought this was called projective geometric algebra. Is the projective part optional? Or it refers to a specific thing.

Why would there be a bivector community? Is it something relatively new, so there's a sense of "we're convinced, but other people aren't yet?"

[+] kortex|5 years ago|reply
A libary for generating code for not just quaternions, not just dual quats, but arbitrary Clifford algebras? Be still, my beating heart!

I love geometric numbers. I wish they were introduced earlier in school, I would've actually enjoyed linear algebra class.

[+] magnio|5 years ago|reply
That intro in the README is wonderful. The three succinct paragraphs answer different questions, which is easily identified by the adverb in bold, and contain the appropriate information for each of them. It reminds me of axios.com articles, which are to the point and easy to find the relevant details.
[+] tmcw|5 years ago|reply
About time this project gets some love. One of the most mind-blowing bits of code I've ever encountered.
[+] newtonfractal|5 years ago|reply
Can someone speak to what the applications of geometric algebra are?

I see this topic show up often on HN, but no mathematicians I know in real life care about it, or even know about it. From googling geometric algebra and related terms, it just seems like more linear algebra to me - why the different name?

[+] Lichtso|5 years ago|reply
The way I see it mainly for these reasons:

  - You get one unified simple framework which replaces or incorporates vector, matrix, complex, quaternion, tensor and spin algebra (all of which would otherwise need their own incompatible notations). [1]
  - Objects and transformations of objects can be expressed by the same multivectors. In the computer graphics of today you would have let's say: Vectors for points and translations, quaternions for interpolatable rotations, matrices for chaining up transformations and you would have separate objects for rays, planes, etc. But in geometric algebra all of that can be expressed by one class: The multivector. [2] [3]
  - It generalizes the same way in all dimensions (which is not true for e.g. vector algebra and the cross product).
  - One can easily derive geometric calculus from geometric algebra, thus have derivatives and integrals (which is a lot harder to do when you have 6 different frameworks and notation systems)
  - Bonus: Because it is unified, it has less edge cases and you need less workarounds, possibly making it also more stable / robust.
It would be interesting if anyone could contribute if there are serious downsides except for not being widely used (mostly for historic reasons I guess).

[1]: https://en.wikipedia.org/wiki/Geometric_calculus#/media/File... [2]: http://projectivegeometricalgebra.org/projgeomalg.pdf [3]: https://bivector.net/3DPGA.pdf

[+] peeterjoot|5 years ago|reply
Geometric algebra has some striking electromagnetism applications. We are able to eliminate the chaotic mess of signs, divergences and curls that we have in Maxwell's equations and write it as a single equation, that essentially has the structure D F = J, where D is a differential operator, F = E + I B is a combined electromagnetic field, and J contains the charge and current densities.

Geometric algebra is not unique as a mechanism to grouping Maxwell's equations into a more coherent structure. This can also be done with both the tensor formalism and differential forms. Each of these can encode Maxwell's equations into a single equation for the electric sources, plus an additional equation for the (zero) magnetic sources. So the fact that we can write all of Maxwell's equations as a single equation, when compared to the tensor formalism or differential forms, is only an incremental improvement.

However, some interesting opportunities are made available by putting Maxwell's equations into this single equation form. In particular, the system of equations is put into a form that we can invert using a Green's function for the differential operator. This gives us a way to solve all of Maxwell's equations in one fell swoop. It's well known that this is possible for the statics equations of electromagnetism, but we can also do this for the time dependent case, and obtain Jefimenko's solution of Maxwell's equation ( https://en.wikipedia.org/wiki/Jefimenko's_equations ) directly. That solution can be obtained without first having to resort to solving the second order potential equation, and differentiating those fields to find the electric and magnetic fields.

The geometric algebra form of the Jefimenko's solution is much simpler than the conventional form, because it is expressed in terms of a single electromagnetic field variable (F = E + I B). There are many other such examples, where things become simpler to express when the fields are grouped logically into a single entity.

A great reference that explores electrodynamics and many other geometric algebra physics topics is Doran and Lasenby's "Geometric Algebra for Physicists" ( https://www.cambridge.org/core/books/geometric-algebra-for-p... ).

Be warned that the reference above is a tough read. I have a for dummies exploration of some of the electromagnetism applications of geometric algebra in my book (free pdf available here: http://peeterjoot.com/writing/geometric-algebra-for-electric... ). I don't use the explicitly relativistic invariant form of Maxwell's equations used in Doran and Lasenby -- it is beautiful, but makes things somewhat more inaccessible. My book is fairly small, and is grouped into three pieces (geometric algebra basics, integration theory, and finally applications to electromagnetism.) I don't touch the mixed signature (projective, conformal, and relativistic) geometric algebras that ganja supports, as I tried to keep things as simple as possible.

[+] JackFr|5 years ago|reply
I found the “wedge game” completely inscrutable. Read it closely a few times and was completely unable to figure out what I was supposed to do or how to do it.
[+] jessaustin|5 years ago|reply
It's like geometric construction games, except you can't use a compass. You can draw lines between points, project lines through points, and "average" both lines and points. The dragging motions aren't completely intuitive...
[+] ogogmad|5 years ago|reply
Mandelbar over the complex numbers: https://en.wikipedia.org/wiki/Tricorn_(mathematics)

Mandelbar over the split-complex numbers: https://imgur.com/PkzY7B6 (admittedly, a bit underwhelming)

[+] danwills|5 years ago|reply
Maybe there's interesting things to see if you change the parameter settings a bit? One thing that can be particularly interesting is using an exponent other than 2.0, regular Mandelbrot is quite interesting (dense and full of 'cuts') on a power of -1.55 for example (I call it 'negandel'.)
[+] HugoDaniel|5 years ago|reply
Is there any easy tutorial for Geometric Algebra? Is it possible to learn it in like an afternoon? How can I learn it?
[+] jcora|5 years ago|reply
No lol it's not possible to learn any math subject in depth in an afternoon, unless you mean "get a surface overview that you'll forget most things about in a couple of weeks". Proper foundations for non-Euclidean geometry are at least a one-semestre undergrad class level of work, which will take you at least several weeks if you do _only that_
[+] gfxgirl|5 years ago|reply
Can I make a scene graph using PGA?
[+] ankurcha|5 years ago|reply
Let's name the library ganja so that no one takes it seriously....good move. I am all for being edgy and stuff but this sounds like a twenty something trying too hard :-D
[+] vmurthy|5 years ago|reply
As an aside : In India, we refer to cannabis as ganja [0]. In case you are concerned about naming...

[0] https://www.google.com/search?q=ganja+meaning&oq=ganja+meani...

[+] adamnemecek|5 years ago|reply
That’s the joke, yes. GA is sometimes called Grassmann algebra hence the “grass” reference.
[+] hutzlibu|5 years ago|reply
Pretty much all over the world I heard cannabis refered to as ganja. But I didn't know yet, it was because of that city.
[+] pjmlp|5 years ago|reply
Which got absorved into Portuguese as ganza.
[+] yudlejoza|5 years ago|reply
> Mathematically, an algebra generated by ganja.js is ...

You're generating code that relates to a certain algebra, likely for providing API for doing calculations based on that algebra (so an algebra library). Why would you call that 'algebra generated by ganja.js'?

Generators [0], generating sets/functions [1][2], have precise definitions within mathematics, and they have zero relation to code generation. So they have zero relation to what ganja.js is doing (i.e., generating code). No offense, but you should know better.

[0] https://en.wikipedia.org/wiki/Generator_(category_theory)

[1] https://en.wikipedia.org/wiki/Generator_(mathematics)

[2] https://en.wikipedia.org/wiki/Generating_function

[+] enkimute|5 years ago|reply
> You're generating code that relates to a certain algebra, likely for providing API for doing calculations based on that algebra (so an algebra library). Why would you call that 'algebra generated by ganja.js'?

The 'generated by' in that sentence is referring to the code generation - not the mathematical generators. I'll change 'algebra' to 'algebra implementation' to make that more clear. (I figured the very sentence 'an algebra generated by ganja.js' disambiguates the interpretation, but I'm happy to stand corrected.)

Ganja can create numerical implementations for a wide range of algebras (not just 'a certain algebra'), including any associative algebra (you can give it a Cayley table), although the focus is on Clifford Algebras, and providing the ability to stay close to the mathematical syntax. In order to do that it provides operator overloading, algebraic literals, etc .. (all features that do not natively exist in javascript). Because it is not 'a certain algebra', but a wide range, for which the code is only generated at runtime - it seemed a reasonable way of describing what is going on.

Thanks for letting me know it confused you - will fix it right away!