If you haven’t done so already, you may want to start by reading the Preface to the Computing Series: Software as a Force Multiplier, Sections 1-3.
Maxima: a Computer Algebra System (CAS) for symbolic computation
Last updated: Feb 19, 2023 (fixed links). Nov 11, 2022 (added omega-math’s excellent web interface, and generating function calculation of the partition of integers problem).
Maxima is a computer algebra system (CAS) for symbolic computation that is free, open source, runs on multiple operating systems (Win,Mac,Linux), and covers a wide range of mathematical capabilities and graphical capabilities. These include algebraic simplification, polynomials, methods from calculus, matrix equations, differential equations, number theory, combinatorics, hypergeometric functions, tensors, gravitational physics, PDEs, nonlinear systems, plus including 2-D/3-D plotting and animation. With a large and responsive user community, there is plenty of help to get up the learning curve, and with its active developer base, Maxima and its ecosystem continue to gain capability, including a fantastic web interface by Omega-Math/Vroom-Labs (see the screenshot below, r0*0). The result is a free, versatile, powerful mathematical computing package for engineers, scientists, mathematicians, programmers, and students. This article will help you get started with Maxima and set you up with resources to flatten the learning curve.
Maxima and the Alternatives
Maxima is a free/open-source computer algebra system (CAS) with functionality covering a large part of mathematics and analytical engineering, originating in 1982 as the open-source alternative to MIT’s Macsyma system. It is readily available with a fantastic web front end by Omega-Math/Vroom-Labs, and easily installed desktop versions for all three major operating systems. A free/open-source alternative is SageMath however running this on Windows requires installing Windows Subsystem for Linux (WSL) (easy, one command, make sure you have 16GB RAM machine, running Windows 10 or 11). SageMath has launched CoCalc which is effectively Sage in the Cloud, under CEO William Stein, based in Seattle (founded 2013). 2023 marks a big increase in the power of CoCalc: it is now integrated with ChatGPT 3.5 (free) and ChatGPT 4 (cents per query), Machine Learning, Neural Networks, with capabilities in Statistics, Big Data Analytics, production of Dashboards, LaTeX, a number of dynamic programming languages built in as different evaluation kernels, and more! Commercial alternatives are Mathematica, Maple and Magma, but the licensing fees are not cheap (you might find trial or student versions). Mobile apps have also been released, e.g. Maple’s Maple Calculator. If you’ve used alternatives and find them much better than Maxima, feel free to leave your views on the comparison in the comments at the end of this article.
Installing & Using Maxima
The fastest way to get up and running with Maxima is to use the fantastic web front end by Omega-Math/Vroom-Labs. This presents a simple user interface, with a calculator like layout, and allows you to just get going without installation, learning specialized syntax, etc. It has all the bells and whistles for those who already know Maxima, so that advanced users will have that power to hand.
To run Maxima, from your desktop computer, you can download the
latest installer for Windows and other OS’s from the Maxima project page. This will look something like maxima-clisp-sbcl-5.41.0-win64.exe which (as of Oct 2017) included in it both the computational engine (Maxima) and the graphical user interface (wxMaxima). (Installation pre-requisites)
Installation on Windows is straight-forward:
- Run the installer, accepting defaults (but feel free to install to any preferred directory).
- Firewall exception for wxMaxima: when you first run wxMaxima, if your firewall software complains that a socket is being opened, allow always. This is a local socket that wxMaxima (the user-friendly graphical front end) uses to communicate with Maxima (the computation engine). Ref: detailed installation walkthrough. This also explains how to get Greek fonts to display properly in your Maxima session.
- run a 2D plot to test your installation:
f(x):= 3*x+3$
plot2d(f(x), [x,-50,50])$
If you get a strange error such as ‘temp directory not found’, create a usable temp directory using the command:
maxima_tempdir : "C:/totalprogs/Maxima/temp"$
- a few basics to get the flavor:
Example 1: polynomial expansion: telescoping series
expand((1+x+x^2+x^3+x^4)*(1-x));
Result: 1-x^5
Remarks: ending statement with ; shows output, ending with $ suppresses output
- to see details of your current Maxima/wxMaxima installation, run:
wxbuild_info()$;
The following resources will help you up the learning ramp.
Cheat Sheets / Ready Reference Sheets
- A Maxima CheatSheet / Ready Reference Sheet – Start with this succinct cheat sheat / command reference table by Ruben Puentedura. It will give you the basic commands you can work through to get a feel for the language.
- Mathematica / Maxima Syntax Conversion Chart: Harvard University, Department of Mathematics – If you are already familiar with Mathematica, this syntax conversion chart help you get you going quickly.
For more detailed guides, see “Building Proficiency” below.
Application Examples
Over the past 10 years (updated in 2023), I’ve used Maxima in a variety of discrete maths research problem. Below are some useful examples and code illustrating a few areas that may be of interest to others.
- Theory of Polynomial Roots
Consider a monic polynomial of degree 3 with rational coefficients p(x).
By the Fundamental Theorem of Algebra (Gauss), p(x) will have exactly 3 (possibly complex) roots a1,a2,a3.
So we can write the polynomial in terms of the roots as follows:
(x-a1)*(x-a2)*(x-a3)
expand(%)
ratsimp(%)
Result: you see the polynomial written as a function of the three roots a1, a2, a3
You see the form of the coefficients in terms of sum of product combinations of the roots by size of the term: trace = a1 + a2 + a3, determinant = a1*a2*a3, and the other combinations in between. - Combinations & Permutations, useful definitions:
c(n,k):=binomial(n,k);
p(n,k):=c(n,k)*k!; - Discrete Mathematics: verification & validation of recurrence relation using binomial coefficients: Finite Summation by Recurrence Relations, Part 1 and Part 2.
- Linear Algebra/Matrix Manipulation: Finite Summation by Recurrence Relations, Part 3.
- Example Maxima script: iterative solution to finite sums recurrence relation sumkp_recurrence.mac
- Combinatorics – Generating Functions:
Consider an illustrative problem of cataloguing fruit baskets that can be made from 2 Apples, 3 Bananas, or 4 Cantaloupes. Apples are $1, Bananas are $2, Cantaloupes $4. The generating function below lists the 60 (=3x4x5) possible fruit baskets that can be made, including the empty fruit basket (no fruit).
All combinations of a fruit basket:
expand((1+A+A^2)*(1+B+B^2+B^3)*(1+C+C^2+C^3+C^4));
What are the sizes, sizes/costs, and costs/compositions (i.e. which fruits to put in) of the fruit baskets? The power of the generating function approach is that you can read off details of the choices from the coefficients of the relevant expanded series.
Showing size (x) of baskets:
expand((1+x+x^2)*(1+x+x^2+x^3)*(1+x+x^2+x^3+x^4));
Showing size (x) and cost (y) of baskets:
expand((1+y*x+y^2*x^2)*(1+y^2*x+y^4*x^2+y^6*x^3)*(1+y^4*x+y^8*x^2+y^12*x^3+y^16*x^4));
Showing cost (y) and composition (A,B,C) of baskets:
expand((1+y*A+y^2*A^2)*(1+y^2*B+y^4*B^2+y^6*B^3)*(1+y^4*C+y^8*C^2+y^12*C^3+y^16*C^4));
From the above, it is easy to see that the most expensive fruit basket is the full fruit basket of 9 fruits at $24. Less obvious: 1) there are 22 choices of fruit baskets with either 5 or 4 fruits, of which the most expensive is $18 [4 cantaloupes & 1 banana] and 2) the least expensive is $6 [2 apples & 2 bananas]. Less obvious problem with many more combinations possible can be handled with the same approach.
- Combinatorics – Partition function:
Here’s an example of a truncated generating function that correctly gives the coefficients p(n) up to n=10 for the partition problem up to integer n.
expr:
(1+x+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9+x^10)*
(1+x^2+x^4+x^6+x^8+x^10)*
(1+x^3+x^6+x^9)*
(1+x^4+x^8)*
(1+x^5+x^10)*
(1+x^6)*
(1+x^7)*
(1+x^8)*
(1+x^9)*
(1+x^10);
powerdisp:true;
expand(expr);
Here’s the two-variable generating function that gives p(n,k) as the coefficients, i.e. number of ways to partition n into k parts.
expr:
(1+k*x+k^2*x^2+k^3*x^3+k^4*x^4+k^5*x^5+k^6*x^6+k^7*x^7+k^8*x^8+k^9*x^9+k^10*x^10)*
(1+k*x^2+k^2*x^4+k^3*x^6+k^4*x^8+k^5*x^10)*
(1+k^1*x^3+k^2*x^6+k^3*x^9)*
(1+k*x^4+k^2*x^8)*
(1+k^1*x^5+k^2*x^10)*
(1+k*x^6)*
(1+k*x^7)*
(1+k*x^8)*
(1+k*x^9)*
(1+k*x^10);
powerdisp:true;
expand(expr);
- Solving Algebraic (Nonlinear) Systems of Equations
A American colleague of mine recently asked to check a solution to a curious system of 4 nonlinear algebraic equations.
Without much more information, I threw it into Maxima (wxMaxima v17.0) and got three numerical solutions.
Total elapsed time? 2 minutes. Another example of Maxima’s value as an symbolic calculator.
algsys(
[
(x+y+z)*t=1,
(2*x+y+z)*(t-2)=1,
(x+3*y+z)*(t-3)=1,
(x+y+4*z)*(t-4)=1
], [x,y,z,t]);
Three numerical solutions:
[x=1.859008365639665,y=-1.098952690501986,z=-0.3503503503503503,t=2.44077834179357],
[x=0.3619915308610291,y=0.7611952791495773,z=-0.8418458781362007,t=3.554406288787753],
[x=0.04370603203113307,y=0.03955473900356641,z=0.04432037496553626,t=7.838148667601683]
Rounding to 3 places:
[x=1.859, y=-1.099,z=-0.350,t=2.441],
[x=0.362, y=0.761, z=-0.842,t=3.554],
[x=0.0437,y=0.0396,z=0.0443,t=7.838]
Learning through Applications
Maxima makes it easy to work through hairy symbolic computations accurately leaving more time for applications and research. Below are examples.
Topics by Example
- Engineering Problems: Javed Alam’s 22 sessions of Maxima for solving real-world Engineering problems
- Differential Equations & Fourier Analysis: Paul Lutus’s differential equations and circuit theory and Fourier (Spectral) Analysis.
- Differential Equations (First Order ODEs): Gregory Astley’s Using Maxima for Plotting Direction Fields of First Order ODEs
- Tensors: Tensor Algebra in Maxima
- Calculus 1 & 2: Zak Hannan’s wxMaxima for Calculus. Two open-texts for wxMaxima that can be used as lab manuals for first-year calculus or “by-example” references for students learning wxMaxima independently.
- Calculus: Leon Brin’s Maxima and the Calculus
Building Proficiency ‘from the Ground Up’
The following resources will help you up the learning ramp.
Cheat Sheets / Ready Reference Sheets
- A Maxima CheatSheet / Ready Reference Sheet – Start with this succinct cheat sheat / command reference table by Ruben Puentedura. It will give you the basic commands you can work through to get a feel for the language.
- Mathematica / Maxima Syntax Conversion Chart: Harvard University, Department of Mathematics – If you are already familiar with Mathematica, this syntax conversion chart help you get you going quickly.
Basic Guides
- Antonio Cangiano’s 10-minute Tutorial for Solving Math Problems with Maxima is a good next step.
- Richard Rand’s Introduction to Maxima (PDF), is a more advanced (but still whirlwind) tour of maxima, including a discussion of writing subroutines/scripts/programs.
- Paul Lutus’ Symbolic Mathematics Using Maxima: A Leisurely Tutorial in 9 parts.
Advanced Guides
- Robert Dodier’s Minimal Maxima (PDF) breaks down the syntactical, evaluation, and data structures underlying Maxima. A good understanding of this is essential when you are trying to go beyond using Maxima as a powerful calculator, or when writing your own functions/subroutines in Maxima.
- Maxima mailing list is a responsive, expert community that can not only help you in a jam, but also raise the level of your proficiency and your familiarity with idiomatic Maxima (that intangible called Maxima style).
“Book-Style” Tutorials (PDF or HTML)
- Gilberto Urroz’s Maxima Book (Science & Engineering Applications): Comprehensive, each chapter organized by mathematical area.
- The Maxima Book (2003), P. de Souza, R. Fateman, J. Moses, C. Yapp: Comprehensive, well-written, well-organized. Not the most up-to-date, but the organization, comprehensiveness, and quality of the material makes this a valuable reference.
- Edwin Woollet’s 15 chapter Maxima By Example: a leisurely description of Maxima’s capabilities.
System Documentation
- Maxima Manual: 1000+ page (5MB) comprehensive manual and listing of all mathematical functions and capabilities built into Maxima.
- Maxima Homepage: Maxima is a system for the manipulation of symbolic and numerical expressions, including differentiation, integration, Taylor series, Laplace transforms, ordinary differential equations, systems of linear equations, polynomials, and sets, lists, vectors, matrices, and tensors. Maxima yields high precision numeric results by using exact fractions, arbitrary precision integers, and variable precision floating point numbers. Maxima can plot functions and data in two and three dimensions.
- wxMaxima Homepage: A Windows GUI for Maxima
Getting Help
The Maxima mailing list is a responsive, expert community that can not only help you out of a jam, but also raise the level of your proficiency and your familiarity with “natural” Maxima programming style.
Contribute!
Feel free to leave a comment if you have a super application, find a great user resource, or just want to share what you’ve been doing with Maxima!
Wonderful article, thanks a lot !!
A very helpful and suggestive article. Thank you.
Came across your blog when writing up this one from a somewhat different perspective http://thingwy.blogspot.de/
You write “…Maxima is a mathematical computing package that ought to be in the toolbelt of every programmer, engineering, scientist, and mathematician…” For a different point of see the above link.
@gerd, Thanks for sharing your blog article. I should say that I have encountered no issues in Maxima’s ability to perform elementary or advanced symbolical calculations – see for example Finite Summations of Integer Powers. Your idea of “elementary” is (in my view) a bit of a stretch when your simplest example of a defect is the “branch cut behavior of an elementary function in the complex plane”. It is possible that Maxima has implementation issues around certain advanced calculations compared to the commercial (and quite expensive) Mathematica. However, apart from these advanced areas, Maxima in my view is a useful choice for those wanting an open source CAS platform that is essentially zero cost.
Many thanks for sharing this fine write-up. Very inspiring! (as always, btw)
I ran into this post what seems like ages ago in the early stages of research for my sabbatical project Spring 2015! Thank you, by the way, for consolidating such a helpful bunch of links — it saved me a lot of work. After four months of writing, I released two CC-BY-NC-SA open-texts for wxMaxima that can be used as lab manuals for first-year calculus or “by-example” references for students learning wxMaxima independently. The e-book is free, and the LaTeX source is available for those who wish to create derivative works. http://wxmaximafor.wordpress.com/
Thanks!
Zak Hannan
Instructor of Math and Physics
Solano Community College, Fairfield, CA
@Zak — your lab manuals for a two-year calculus sequence are an excellent resource for learning Maxima at the same time as Calculus. Thanks for announcing them here.
@Assad: my pleasure! I am looking forward to being an active member of the Maxima community now that it has become part of my daily life.
– Zak
Appreciate this post. Let me try it out.
Took me time to read all the comments, however I really loved the article. It proved to be very useful to me and I’m positive to all of the commenters here! It’s good when you can not only learn, but are also engaged! In my language, there aren’t many good sources like this.
Lovely just what I was searching for. Thanks to the author for taking his time on this one.
thanks for this great resource!
[…] relations to find a closed form solution to the sum-of-powers problem for integer . We use Maxima, a free computer algebra package, to crunch through messy expressions and reach an accurate […]
There is a web interface for Maxima at: http://www.omega-math.com
A quick reference is at: http://www.omega-math.com/nhome/qr.jsp
The web interface eliminates installations on local devices: http://www.vroomlab.com/nhome/
(EDIT) An example using Omega-CAS for a constructive proof of Feuerbach’s Nine Point Theorem is given here: https://vroomlab.wordpress.com/2018/01/23/a-constructive-proof-of-feuerbachs-theorem-using-a-computer-algebra-system/
Michael, cool stuff!! Thanks for sharing. I’ve added an extra link to your comment, to illustrate Omega-CAS being used to prove the Nine Points Theorem.
Assad-
check out “Viva Rocketry!”, a series of my blogs on the mathematics of rocketry (using maxima)
https://vroomlab.wordpress.com/2018/11/10/viva-rocketry/
@Michael – nice!! 🙂
EDIT:
Just gave it a test spin: love what you’ve built here. Clean, slick, and takes away the clunkiness of desktop Maxima using wxMaxima. Perfect when all you really need/want is Maxima in a no-fuss calculator.
The info mentioned in this article include several of the most effective and this makes them easily accessible in one place.
Example of maxima animation: a missile strikes a fighter jet/balloon 🙂
https://vroomlab.wordpress.com/2023/01/17/seek-lock-strike-animated-2/
Neat example showcasing animation capabilities within Maxima. Another great post Michael. 🙂
Assad-
Antonio Cangiano’s 10-minute Tutorial for Solving Math Problems with Maxima has a new link: https://mathblog.com/a-10-minute-tutorial-for-solving-math-problems-with-maxima/
The current link on this page is dead.
Igor.
Fixed this link and tested and fixed all others as well. Thank you Igor! 🙂
Assad
Linear Programming using maxima:
http://nuomegamath.wordpress.com/2023/08/10