Hello HN,<p>I was learning JavaScript by completing challenges on CoderByte[0], where one of the hard challenges was to find the point where two lines intersect. The lines were defined by two sets of points, and you had to return your answers as rationals, not floats. The challenge isn't timed, so I got a little carried away: ended up making a Fraction class, Equation class, etc. This first iteration could only solve linear equations, but I decided to expand it out into a library that could solve higher order polynomials and manipulate expressions.<p>On a related note, solving cubics is actually kind of hard. This guy Cardano[1] figured it out[2] in the 1500s, but his solution was incomplete because he wasn't aware of imaginary numbers at the time. I then found you could solve cubics with some trig[3] and decided to go that route. Anyway, hope you enjoy, and of course I am interested in your feedback.<p>[0] <a href="http://coderbyte.com/" rel="nofollow">http://coderbyte.com/</a><p>[1] <a href="https://en.wikipedia.org/wiki/Gerolamo_Cardano" rel="nofollow">https://en.wikipedia.org/wiki/Gerolamo_Cardano</a><p>[2] <a href="https://en.wikipedia.org/wiki/Cubic_function#Cardano.27s_method" rel="nofollow">https://en.wikipedia.org/wiki/Cubic_function#Cardano.27s_met...</a><p>[3] <a href="http://www.nickalls.org/dick/papers/maths/cubic1993.pdf" rel="nofollow">http://www.nickalls.org/dick/papers/maths/cubic1993.pdf</a>
This is so well done! There are so many little touches here that delights me like the keyboard shortcuts for jumping right in and the LaTeX support. Even though this started off as a learning project for you, know that this is probably better than 95% of the API documentation I read from more professional development teams.<p>Jason Long's Cayman Theme was unfamiliar to me until I saw your citation. Kudos to your good taste.<p>Documentation is pretty good. It probably skews more towards developers with experience using other libraries, but I think that's fine for a first version. If you want to kick it up some more, I'd love to see more practical examples that might inspire me to use it out in the wild. Also, it took me awhile to figure out what to do with the keyboard shortcut. Something more explicit or even a small screencast would be nice.<p>I see that you also work on the RNeo4j library, which looks super cool. Queueing that up in the future to play with...since R is a much better place for me to feed that graphing library data. Thank you so much for sharing this!
This seems like a good start towards a symbolic math library like SymPy[0] for JavaScript. There's lots of cool client-side applications for such a library, something like Mathway[1] or WolframAlpha[2] that doesn't need to hit a server to do the symbolic computation.<p>[0] <a href="http://www.sympy.org/" rel="nofollow">http://www.sympy.org/</a><p>[1] <a href="https://mathway.com/" rel="nofollow">https://mathway.com/</a><p>[2] <a href="http://www.wolframalpha.com/" rel="nofollow">http://www.wolframalpha.com/</a>
Nice work Nicole! :-)<p>I work on a similar library for C# (Symbolism [1]).<p>Consider allowing for variable elimination in sets of equations. (See this problem for an example: <a href="https://gist.github.com/dharmatech/a14d1a29a7d4c0728d37" rel="nofollow">https://gist.github.com/dharmatech/a14d1a29a7d4c0728d37</a>)<p>[1] <a href="https://github.com/dharmatech/Symbolism/" rel="nofollow">https://github.com/dharmatech/Symbolism/</a>
this looks really neat and it must have been a lot of fun to build!<p>it's not a feature request because I don't have a use case for this quite yet, but how complex would it be to parse a string that contains a formula? for example, it seems useful to be able to load equations by just sending the string "2x - 3 = 4" to a function.<p>that sounds like a fun problem to solve as well. maybe useful to the library too. just a thought! great work on this library and thanks for publishing.
I also created an algebra npm package, it implements what I learned at Algebra first year course at Università Degli Studi di Genova: <a href="http://g14n.info/algebra/" rel="nofollow">http://g14n.info/algebra/</a>
There are powerful tools out there that can do this type of computation and more in a breeze. I have personally worked on SaturnAPI [0], which is a RESTful API for Matlab/Octave. You can build your own APIs to do almost any calculation imaginable. If anyone needs to solve equations, definitely give it a shot. You can solve all sorts of equations, linear and non-linear [1].<p>[0] <a href="https://saturnapi.com/" rel="nofollow">https://saturnapi.com/</a><p>[1] <a href="http://www.mathworks.com/help/symbolic/equation-solving.html" rel="nofollow">http://www.mathworks.com/help/symbolic/equation-solving.html</a>
the API is really clear and aesthetic. the whole work seems self contained. it is just awesome. im excited to think about an addition for matrices and combinatorics and calculus as well. this deserves to become like a Magma for js. unlike quite a lot of Shown HN this already seems complete, even the documentation, so aside from hoping it expands I feel there isnt much missing to point out. maybe a calculator graphical interface to produce expressions? oh and defnitely big num support!
So it's like an early-stage CAS written in Javascript?<p>E.g. Sage math (<a href="http://www.sagemath.org/" rel="nofollow">http://www.sagemath.org/</a>)
Hi does anyone know how to download Algebra.js ?<p>I clicked the "Download .min.js" tab on the Algebra.js.org page but was given this error message :<p><a href="http://algebra.js.org/javascripts/algebra.min.js" rel="nofollow">http://algebra.js.org/javascripts/algebra.min.js</a>
it would be cool to have<p><pre><code> new CompoundExpression( "x^2 - xy + 5" )
</code></pre>
or even<p><pre><code> new PolishSquarefree("+")("+")("^")("x")(2)("-xy")(5)
</code></pre>
or even<p><pre><code> new Polish("+")("-")("^")("x")(2)(".")("x")("y")(5)</code></pre>