Hacker News new | past | comments | ask | show | jobs | submit login
Maxima: A computer algebra system written in Common Lisp (maxima.sourceforge.io)
267 points by ducktective on Feb 6, 2023 | hide | past | favorite | 66 comments



Maxima enabled me to make my color space [HSLuv](https://www.hsluv.org/). I encoded CIELUV <-> RGB transformation functions into Maxima, ran `solve` and converted the output back into code. It's great to be able to commit [Maxima code](https://github.com/hsluv/hsluv/tree/master/math) into your repository and not leave the math as an "exercise to the reader".


That’s a really nice way to do it. Also, I really like HSVLuv; it’s a really nice idea.


Quick note to avoid disappointment: maxima itself is a text application. wxMaxima is a graphical front-end with conventional math notation. Output only. You'll frequently encounter text/command-line options, though. E.g., when you pick a command like differentiate from the menu, and you want to apply it to the previous result, you'll have to enter something like %o10 (no need to guess; you'll see the reference in the output). Idk if there's a better GUI.


An alternative is to run maxima from jupyter: https://github.com/robert-dodier/maxima-jupyter.


Wow! This is fantastic! I got really frustrated with maxima frontends and just ended up sticking with Mathematica, but I'm going to give this a shot


Sagemath uses maxima internally, so Jupyter notebook backed by Sagemath kernel might be useful?


What is Sagemath then? I have used it many times and I assumed it was a CAS alternative to Maxima. Is it actually just a big library built on top of Maxima? Sort of like how LaTeX is a library on top of TeX?


Sagemath used a collection of libraries.

From the front page:

> SageMath is a free open-source mathematics software system licensed under the GPL. It builds on top of many existing open-source packages: NumPy, SciPy, matplotlib, Sympy, Maxima, GAP, FLINT, R and many more. Access their combined power through a common, Python-based language or directly via interfaces or wrappers.

For once "many more" really means "many more".


In this case, Sagemath contains a domain that interfaces heavily with Maxima.

By default Symbolic Calculus, which is a pretty common use-case since the space of integral-tables is huge and complicated, makes pretty heavy use of calls to Maxima as a backend, but it can slip over to SymPy, and some others pretty easily.

Sagemath is, a little rough to use as a novice-y math guy, really quirky especially since Python isn't as up-front with typing as I would like, and I've run into some lazy-evaluation confusion as well, but if your time is worthless, use-case restricted it can be an alternative to paying out the nose for Mathematica.


While I generally agree with you, but I'd like to point out that Sagemath is more than a "Mathematica alternative". It seems like Sagemath is a better fit for some fields like cryptography, given its strong support for operations related to abstract algebra.


Sagemath is, a little rough to use as a novice-y math guy

Yeah I mainly used it in my real analysis, complex analysis, and differential geometry classes. Also used it a bit in an intro cryptography class to play around with some rings and solve assignment problems.

I'm using Python right now in a neural networks class and I hate it. It's absolutely horrible to debug. You press run and then your neural network starts training and then craps out with divide-by-0 after a long time and no clue as to where the offending code might be.


> Yeah I mainly used it in my real analysis, complex analysis, and differential geometry classes.

Any pointers to how one would use it for real analysis?

Thanks.



In college, I used to use Maxima with KDE's Cantor as a frontend.

https://cantor.kde.org/


There's also imaxima a mode for Emacs that will format the output as rendered LaTeX.


Does that still work or is it abandoned? Do you know how to install it on doomemacs (I'm not an emacs or doomacs gurú)


It does still work! Not sure if actively maintained though...

I think the process is a bit different depending on your OS. On Linux it's often bundled as a package for example on Ubuntu it's called maxima-emacs. I only use pretty vanilla Emacs so I'm not sure how that would interact with Doomemacs. You could try the manual install directions from the page perhaps [0].

[0] https://sites.google.com/site/imaximaimath/tutorial-of-imaxi...


There is also maxima.el in MELPA https://melpa.org/#/maxima


       rlwrap maxima. Use your Emacs keybindings from the shell (actually, readline) into it.


imaxima is a Maxima mode for Emacs which renders equations in the Emacs buffer:

https://sites.google.com/site/imaximaimath/

> Imaxima provides a graphical user interface front-end for the computer algebra system Maxima in an Emacs buffer. Imaxima processes the output from Maxima with LaTeX to beautifully render the mathematical formula. It inserts the rendered math formula image in the buffer.


Reduce is another lisp based computer algebra system from the prehistoric times, now open sourced.

https://en.wikipedia.org/wiki/Reduce_(computer_algebra_syste...

https://reduce-algebra.sourceforge.io/

I paid money for a Reduce release for RISCOS back in the last ice age. I recollect having to register my licence with the Rand Corporation for some reason.


Reduce is awesome! Dozens of specialized packages[1]. My favourite two packages are

1. The Source Code Optimization Package, SCOPE. It will take an expression or group of expression and produce a simpler set of expressions that minimize the use of arithmetic expressions.

2. The coeff2 package[3]. Tell coeff2 what the variables are and it will rewrite your expression as a simpler expression in terms of the variables alone and represent mush the others into constants.

I could not do what I do without it these two packages. Beats Maxima IMO.

[1] https://reduce-algebra.sourceforge.io/documentation.php#cont...

[2] https://reduce-algebra.sourceforge.io/reduce38-docs/scope.pd...

[3] https://reduce-algebra.sourceforge.io/manual/manualse136.htm...


I like maxima and used to use it (through the interface wxmaxima or KDE Cantor) for solving my physics problem. I am no expert in CAS, just use them for simple problem solving.

However, since I stumbled upon this blog post by Thingwy https://thingwy.blogspot.com/2015/07/maxima-versus-mathemati..., I find myself uneasy when using maxima. I quote Thingwy:

    “Maxima gets elementary math wrong, it knows very little about integration, it is weak on simplifying expressions, it fails on trivial equations, it is slow, Maxima usage is discouraged by CAS power users. In summary: do not go and waist your time or wreck your nerves using Maxima. JUST DON'T DO IT”
Since this was in 2015, I want to know the situation now, and the comments of experts on the issues raised by the blog poste.

(Excuse my bad English)


I’m a bit suspicious of the section saying “Maxima is slow” blaming linked lists. Maxima is built on Common Lisp which definitely has arrays and vectors, so the claims made there seem a bit uninformed. I don’t really know enough math to judge the rest, though.


I'm extremely suspicious of that explanation. It would be nice to see a few benchmarks.

Anectote time: I used Mathematica many years ago. One surprising thing was that when you update the content of a vector, Mathematica creates a new vector and copies the content of the old vector. If you just copy an algorithm from C to Mathematica, it may be N times slower because it's creating a lot of intermediate vectors. So you must rewrite your code using "fold", or something like that. It was a long time ago, so I'm not sure if they have already added some trick to optimize code from people like me that don't know what they are doing. If Mathematica or Maxima has this trick but the other doesn't, it may cause a huge difference of time between algorithm that look very similar. Anyway, this is totally unrelated to lists.


Checked the examples and Maxima still fails. It's even more disheartening that author mentions towards the end that had reported those issues years before they wrote the article. I had also used Maxima before and, though unsurprisingly found it less polished than Mathematica, got the job done without issues. But will probably refrain from recommending it. Would also like to see how other systems tackle those examples.


I checked the failing limt one and it worked fine. Maybe it was fixed recently?

  ;;; Loading #P"/usr/lib/ecl-21.2.1/sb-bsd-sockets.fas"
  ;;; Loading #P"/usr/lib/ecl-21.2.1/sockets.fas"
  Maxima 5.46.0 https://maxima.sourceforge.io
  using Lisp ECL 21.2.1
  Distributed under the GNU Public License. See the file COPYING.
  Dedicated to the memory of William Schelter.
  The function bug_report() provides bug reporting information.
  (%i1) declare(a,real);
  (%o1)                                done
  (%i2) declare(b,real);
  (%o2)                                done
  (%i3) assume(a>b,b>0);
  (%o3)                           [a > b, b > 0]
  (%i4) limit(log(b-a+%i*eta),eta,0,plus);
  (%o4)                         log(a - b) + %i %pi
  (%i5) limit(log(b-a+%i*eta),eta,0,minus);
  (%o5)                         log(a - b) - %i %pi


Version I've installed is 5.45.1 and gets "log(b - a) + %i %pi" and "log(b - a) - %i %pi", so should be. Gave changelog for 5.46.0 a look but not sure whether it had a direct fix for this or was indirectly fixed due to one of the other closed bugs.


Hmm, there is a weird fix with the limits, could be #484: limit(x=0,x,0) wrong


My university course uses Maxima for optimization modules and essentially none of the examples from the textbook work as they should. Official documentation is sparse and often unhelpful too. The functions output Lisp stacktraces if you do something wrong, rather than actually catching errors and printing some human-friendly message that describes the problem and which particular argument caused it without having to dig into Maxima source code. It would be great CAS software if it was a bit more polished, but unfortunately that is unlikely to ever change - it hasn't in the last 4 years that I've used it at least.


> it knows very little about integration

Somewhat related: I've read before that the FOSS CAS Axiom has the only kinda complete implementation of the Risch algorithm for integration. Axiom looks harder to use, but maybe it's an option.

(I don't know anything about the topic)


The axiom implementation isn't complete either and doesn't handle mixed algebraic transcendental functions like sqrt(atan(x)), from what I understand.

The Sympy implementation handles the purely transcendental case and does best effort on the algebraic extensions. It's a lot more ergonomic than fricas/axiom though.


Plus points:

Does not suffer from the time limits of free wolfram and the nlp parsing issues in general with wolfram

Negative points:

Somewhat more limited repertoire, and things sometimes need to be rephrased or rearranged to trick an answer out of it.


Surprisingly, the command to plot solutions of odes is much better and more interactive than Mathematica’s despite the interface being “uglier”.


It uses gnuplot I think as its frontend. Gnuplot is quite powerful if you understand it and can trick it correctly.

Regarding the interface being ugly it kinda also depends on which graphical frontend gnuplot is using, there are multiple. I like the Qt one.



Except when it doesn't work. I tried using it a few months ago on both Windows and WSL, but I had to give up and resort to run a Maxima kernel on EIN.¹

I was going to try again before commenting, but I broke my WSL setup last week and didn't have time to fix it yet, but I sure will try it again next month.

¹ http://millejoh.github.io/emacs-ipython-notebook/


Interesting. I just downloaded Maxima on Android and also WolframAlpha. Three latter is light years ahead.


Does it even run locally?


Well there’s a surprise


It's also available as an Android app, MaximaOnAndroid. I love having it on my phone, even though I rarely actually use it :)


> I love having it on my phone, even though I rarely actually use it

I understand.


I'd like to make calls to Maxima with s-expressions and get s-expressions back. Is there a way to embed Maxima, say by having its Common Lisp host running on top of, say, a Clojure environment (really anything JVM or JS or Python or .Net, anything with clean in-process interop)? I know SageMath accomplishes something like this by calling out to Maxima from its Python-based environment...


Ahh, the macsyma days. You could do real tensor calculus with it.


Cadabra does that extremely well:

https://cadabra.science/notebooks/tensor_monomials.html

did publish an article with a Lagrangian of order 40 in the fields with it. 10k pages of calculations.


ahh, yes indeed, it can do GR tensors too [0]

can't believe somebody wrote this in C/C++!

[0] https://arxiv.org/abs/1912.08839


Cadabra author here. The choice for C++ was intentional and is part of the design to separate the maths language (LaTeX), programming language (python) and implementation language (C++). This has advantages (eg. notation looks natural for mathematicians/physicists, programming the system uses a language already familiar to many, and it can still run algorithms at C++ speeds) and disadvantages (eg. some things become much more involved to implement). As always, it depends a lot on what you do with the system whether this is good or bad. Cadabra is not for everyone, but it does some things much nicer (IMHO) than other CAS systems.


its an intriguing combination of languages and maybe one that would serve well other projects. Combining python and C++ is clearly common, but expressing algorithms / expressions as latex hits another sweet spot.

Makes sense to have a performant "backend". My experience with macsyma is, ahem, quite a bit dated, but I still remember it would choke on large calculations and needed careful massaging of intermediate steps.


How does it compare to SymPy?


Maxima is a surprisingly good alternative to SymPy. We had to learn that the hard way at my job. Both systems offer similar functionality, but it turns out Maxima is typically 50-200x as fast as SymPy for many tasks (I guess because it was written at a time when computers were slow and expensive). For our application, switching from SymPy to Maxima shortened the time-to-solution from hours to minutes.

Also, it shows that Maxima has been in use for a very long time, and maintained by very bright people. I have yet to encounter a bug in Maxima. And I have already encountered plenty of bugs and inconsistent behavior in SymPy.


Maxima sees serious 'more free' versions of computational algorithms that migrate out from less free acedemic systems.

On the computational real actual algebra side (ie. a bit past computing a quadractic at 'x') a number of things that appear in Magma follow into Maxima (but not all the things, although with time they will come).

https://en.wikipedia.org/wiki/Hidden_Field_Equations

https://en.wikipedia.org/wiki/Gr%C3%B6bner_basis

    The first HFE cryptosystem challenge of J. Patarin is solved by Magma in 82.5 seconds, using 1.3GB memory; with 4 threads the time taken is just 29.0 seconds. This involves solving a system of 80 quadratic equations in 80 variables over GF(2) (each input polynomial has about 1600 terms). The challenge was first solved by J.-C. Faugère in 52 hours on an 1GHz Alpha in 2002 using his unpublished F5/2 algorithm. At the time of writing, there is apparently still no publically-available software besides Magma which can solve the challenge.
http://magma.maths.usyd.edu.au/magma/overview/2/27/13/#subsu...

https://maxima.sourceforge.io/docs/manual/maxima_257.html

    Notes on the grobner package: The code is a little bit out of date now. Modern implementation use the fast F4 algorithm described in "A new efficient algorithm for computing Gröbner bases (F4)" Jean-Charles Faugère
( *NB a somewhat old example, I'm not keeping up on the comp.algebra lists and I'm assuming here the online manuals are up to date )


If you need programmability or interoperability, Sympy is way nicer. If you just want an interactive symbolic calculator, Maxima is fine but sometimes quirky (has odd conventions due mainly to its age). As heisig points out, Maxima can be quite a bit faster (but I run into slow things with it too). Using Maxima via Sage is in some ways the best of both worlds.

You may also be interested in SymEngine: https://github.com/symengine/symengine



From FOSS CAS Fricas seems to fair best. But damn, Mathematica is on another level. And somehow Rubi looks even more impressive and puts a foundation for shareable high-quality integration to other systems.



with a bit of elbow greece you can also integrate it with your common lisp application. and i mean this entirely, not just in an api sense


GREASE


ela re


Do you have any reference/tutorial on how to do this?



If Maxima doesn't suit you, Yacas has a both a cli and QT interfaces akin to Maxima's design, and both output to Gnuplot.


I wish one could use these libraries inside common lisp as opposed to having some badly designed language on top of it.

Sure, technically you can use it (see Maxima), but the weird ways in which it needs to be written is completely off-putting and not in line with (modern and ancient) Common Lisp programming guidelines.


I use Maxima's GRTensor package for GR computations, such as computing the Einstein tensor of a metric. This only involves differential equations with real-valued functions, so it would not trigger the complex number issues that are described in the article.


How does Maxima compare to something like Xcas[1]?

[1]: https://www-fourier.ujf-grenoble.fr/~parisse/giac.html


https://www.12000.org/my_notes/CAS_integration_tests/reports...

Giac/Xcas is slightly worse at symbolic integration than Maxima, and both are dramatically worse than Mathematica.

FriCAS, an Axiom fork, is the best open source CAS on those benchmarks.


CLIM-based client for Maxima: https://github.com/lokedhs/maxima-client




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

Search: