Hacker News new | past | comments | ask | show | jobs | submit login
Ganja.js: Geometric Algebra Generator for JavaScript, C++, C#, Rust, Python (github.com/enkimute)
212 points by pizza on Dec 18, 2020 | hide | past | favorite | 83 comments



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.


> 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.


It's also the name of the second largest city in Azerbaijan.

In high school, my school hosted some exchange students from "Ganja school #5". As we were standing at LAX airport waiting for the Azeri students to arrive, a couple of surfer dudes wearing board shorts and Hawaiian shirts walked by and stared at our sign:

"Ganja school .... duuuuuude .... I wanna go there!"


To add, Ganja pronounced with very short sound of "a" means bald :)

Ganja as hemp is mostly pronounced as Gaanjaa, but accepted spellings are Ganja.


It's not really political correctness as much as it is morality. We've been conditioned to believe marijuana is bad, unfortunately.


> We've been conditioned to believe marijuana is bad

Well, you'll have a really hard time convincing people that it's good. (Unless they already have a vested interest in rationalizing their decisions.)

Nobody ever got smarter from smoking too much weed.


http://marijuana-uses.com/mr-x/

Carl Sagan: Cannabis enables nonmusicians to know a little about what it is like to be a musician, and nonartists to grasp the joys of art. But I am neither an artist nor a musician. What about my own scientific work? ... I have made a conscious effort to think of a few particularly difficult current problems in my field when high. It works, at least to a degree. I find I can bring to bear, for example, a range of relevant experimental facts which appear to be mutually inconsistent.


You're repeating something you've been indoctrinated to believe, that you haven't given any thought to, so yes it's going to be difficult to convince you and others like you otherwise.


Like anything you can overdo it. I regret smoking so much in my youth. I also regret drinking so much, and eating so much pizza and chocolate, and spending all day surfing (the web, sadly, not the waves). I was doing all those things before I became old enough to buy cannabis (although cannabis did exaggerate them somewhat).

It does seem like the cannabis had a negative effect on my memory and emotional stability (I was high basically the entire day for several years while my brain was still developing). And many of my worst paranoid delusions ever have been on uncomfortably high doses of cannabis. But so have some of the most beautiful and dare I say spiritual experiences of my life, and I wouldn't take those back.

I do wish I'd waited until I was older though, and in a better place emotionally (I was using it as a painkiller, if you will.)

All things considered though, I'm a much bigger fan of psilocybin and LSD. Rather than worsening my addictions they made me quit a lot of unhealthy things I was doing. I also found microdosing to be very beneficial.

For comparison, you can conduct a business meeting on a small dose of LSD and find that it actually helps you pay attention and think clearly, while even small doses of cannabis will interfere with something as trivial as a trip to the corner store.


> Nobody ever got smarter from smoking too much weed.

What about having fun or relaxing? Most recreational substances or activities aren’t supposed to “make you smarter”.


Its a drug and should be promoted as such. Lets not swing the pendulum the other way. I can't be convinced putting smoke in your lungs is not harmful.


Everyone knows it's a drug. It also has a handful of applications in medicine, but so do a lot of drugs. Doesn't mean it's for everyone. As a recreational drug, the societal and personal harm associated with consuming marijuana is rather low. And nobody with any integrity is acting as though smoking something isn't bad for your lungs.

Weed has already thoroughly permeated society, no use trying to turn back the clock there. We should just stop arresting people for it and stop making it so you have to take unnecessary risks to get it.


If smoke is the problem you can eat or vaporize it for example.


Smoke is merely 1 of 100 ways to consume cannabis.


That's a very prejudiced opinion, and you should critically review it.


A headier pot certainly makes my mind sharper. Now, a pot with a heavy body load, that's more of the stereotypical "lazy stoner". But to say "nobody ever got smarter from smoking...weed" is kind of short-sighted.


The negation of bad isn't "good". It's "not bad".


Correct. You have to smoke exactly the right amount.


I don't think that's it, either. I think it's that the word "ganja", in United States parlance, is sort of puerile and gets uttered ironically more than it does unironically. I think that most of us not caring about weed anymore is what makes the oblique reference to it kind of passe and eye-rolly.


On the one hand you're somewhat right: there are certainly many of those who fear marijuana with the only reason being that it is among "the drugs"; but is marijuana abuse not the greater issue of the two? Certainly you can agree that inhaling any smoke is bad for the lungs, for a start?


You can use marijuana/cannabis without smoke in a million different ways.


Commenters without a substantial or interesting contribution to make tend to focus on things like names.


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?


The obvious answer is the one I assume you deliberately glossed over… Marijuana is still highly "political" in many, many places.


Should have named it "WearAMaskDuringAPandemic.js". No way that's going to turn political...


It’s a clever joke because exterior algebra (https://en.m.wikipedia.org/wiki/Exterior_algebra) is also knows as Grassman algebra, named after Hermann Grassmann (https://en.m.wikipedia.org/wiki/Hermann_Grassmann)


It effectively makes the license "don't use this in an educational setting", unfortunately.


Then again, the substance it refers to is perfectly legal in several of countries (and a number of states in the US). By that metric, Wine should be avoided too.


Cigarettes are legal in every state in the US, but naming something “cigarette.js” when it has nothing to do with them won’t help.


cigar.js is actually a good name for a lib.


...nor hurt.


I didn't give any metric.

By yours, semen is perfectly legal in several countries (and a number of states in the US). That doesn't make it appropriate as a name in an educational setting.

Or, "Today we are going to be using Wine" doesn't need quite so much careful disambiguation.


> semen is perfectly legal in several countries (and a number of states in the US)

Ah, yes, Illinois made semen illegal in 1923, as we all know. I now run around hiding from the cops.


What educational setting, primary school? Congratulations on your precocious children!


[flagged]


Yes, please, let's continue the race to the bottom where anything that could possibly offend anyone, anywhere, is excised and removed from usage.


What language is that? And that issue appears for a number of words in a variety of different languages. While it’s not exactly a minefield matrix, is it really so bad that the makers of a thing don’t know how to check the meaning of their word in every language?


Urdu/Hindi. So your basically excluding about 2 billion right off the bat. And as for your other point, it's not like the word just happened to be offensive, he deliberately sought out something he knew would be controversial.


I am an Indian and knows Hindi. I am curious to know how it is offensive or an insult. And among students it may earn some giggles and nothing more. And for South India, which probably has the infrastructure to use a library like this, Hindi isn't even the medium for communication.


Thanks for this background info. I also agree with your assessment - so far its just gotten some giggles and maybe even some extra attention from students who are not always easy to motivate when it comes to math. Its also racked up quite a few references in scientific publications (as its the only library offering these types of easy visualizations) - so it does appear most can appreciate it for the silly joke it was meant to be.


That's interesting. Could you please elaborate how it is an insult? Genuinely curious.


It's not. Ganja could mean either marijuana or "bald" depending on how you pronounce it. Not offensive or an insult which would "exclude 2 billion people" either way.


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


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?"


Geometric algebra is very general: it can model straight Euclidean space, non-Euclidean geometry, projective geometry (the familiar homogeneous coordinate system) and also conformal geometry. Some of the earlier applications of geometric algebra to computer graphics were based on conformal geometry (eg https://rjw57.github.io/phd-thesis/rjw-thesis.pdf) because it can model more interesting things than projective geometry, but it is more computationally expensive than projective geometry.

WRT community, the https://bivector.net web site has a discussion forum for people interested in geometric algebra. I’m still a newbie so I don’t know the territory very well, but it is still fairly hard to get to grips with geometric algebra: there isn’t a lot of tutorial material and there’s still a lot of variation in details of notation and choice of basic operators, which is confusing for a beginner.

I have been collecting links recently: see https://dotat.at/:/?q=geometric+algebra


As a beginner, these are questions that lead to a big rabbit hole for me.

1. Yes, it seems Projective Geometric Algebra is new enough that the terminology and symbols are still being debated.

2. Yes, people who "get" it seem pretty convinced. I think the newish PGA is attractive for convincing real-time graphics software engineers and hardware engineers. For example, it has 16 floats in R(3,0,1) too.

3. The community is there to help spread the knowledge and to help as you start finding out about all the other Geometric Algebras. And overcoming the Euclidean mindset is tough.

This is the first bit of higher-than-Calc math I've worked at in a long while and it feels like it's bending my mind in a good way, like Lisp did.


It’s a community dedicated to discussion and promotion of geometric algebra.


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.


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.


About time this project gets some love. One of the most mind-blowing bits of code I've ever encountered.


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?


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


Maybe it simpler that quaternions (debatable) or simpler than learning all of the concepts you've mentioned separately, but I wouldn't really call it a "simple framework".


I think that simple should be understood here as easy to use. As a crude analogy, the mechanical principles underlying a car with an automatic shift aren't simple, but the abstraction it provides makes driving much easier to learn.

A more mathematically grounded example could be the complex plane compared to the real line: when encountered for the first time, it is not simple in any way, but it offers a clean solution to many (originally real valued) problems (perhaps by the fact that it is algebraically closed?).

NB: the author of this library also made a very interesting presentation of geometric algebra (using this library as vehicle) for SIGGRAPH 2019: https://www.youtube.com/watch?v=tX4H_ctggYo

It has been posted a few times on HN before.


I agree that if you only need one specific part, than your needs are better met by using just one of the other frameworks. But in my experience that is rarely ever the case. Usually I have to work with at least 3 or 4 different ones. You don't even have to use all of the possibilities for a unified framework to be simpler already. So the word "simple" is meant in relation to the fragmented alternatives.


This[1] can probably give you some insight into the applications side of things.

1 => https://blog.ycombinator.com/joan-lasenby-on-applications-of...


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.


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.


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...


They were designed with touchscreens in mind - I agree tho that it didn't work out exactly as I wanted. Someone did make a playthrough video of it :

https://www.youtube.com/watch?v=UzEytSmwEpk&ab_channel=probi...


Accommodating touchscreens is great. If anything it seemed that the manipulations for points and those for lines are reversed? I kept getting an average when I was expecting a connecting line or an intersection? This may represent something deeper in GA that I haven't internalized yet. Nevertheless, it is possible to complete the game if one keeps trying.


I love the name! Don't let anyone tell you different!


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)


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'.)


Is there any easy tutorial for Geometric Algebra? Is it possible to learn it in like an afternoon? How can I learn it?


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_



Can I make a scene graph using PGA?


If you are interested in geometric algebra for the Julia language, you may want to check out Grassmann.jl also:

https://github.com/chakravala/Grassmann.jl


> Grassman

I'm starting to see a pattern in those names


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


[flagged]


Honestly, your tired tirade against cannabis is much more tiring. You obviously have no idea what you’re going on and on about, but you don’t let ignorance stop you from trying to limit the freedoms of others.


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...


That’s the joke, yes. GA is sometimes called Grassmann algebra hence the “grass” reference.


I thought Grassmann algebra consisted of only scalars, vectors, bivectors, etc. but not their linear combinations. So a mixed scalar plus vector is not an element of a Grassmann algebra. An alternative name is exterior algebra. You get Clifford algebra / Geometric Algebra (two names for the same thing) by taking closure under sums and considering a more general product.

[edit: It appears I'm right: https://en.wikipedia.org/wiki/Exterior_algebra]


That is in fact the case however enki employed some artistic license.


Grassmann algebra and exterior algebra are synonyms.


I said so in the comment if you read it.


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.


https://en.m.wikipedia.org/wiki/Ganja_(cannabis)

> 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".


Which got absorved into Portuguese as ganza.


> 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


> 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!


Fwiw I don’t really see a problem with the language the GP was complaining about. It’s pretty common for words to be heavily overloaded and ambiguous in mathematics and while this is often annoying and you may try to avoid this sort of issue, I don’t think you should be obliged to do that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: