Maxima (Computer Algebra)

Spread the love

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.

Omega-Math’s web interface to Maxima. Used here to calculate the first 10 elements of p(n), the number of ways to partition integer n, using a generating function comprising a truncated series of polynomials up to degree n=10



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:

  1. Run the installer, accepting defaults (but feel free to install to any preferred directory).
  2. 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.
  3. 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"$

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

  5. to see details of your current Maxima/wxMaxima installation, run:

    wxbuild_info()$;

Building Proficiency

The following resources will help you up the learning ramp.

Cheat Sheets / Ready Reference Sheets

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

  1. Antonio Cangiano’s 10-minute Tutorial for Solving Math Problems with Maxima is a good next step.
  2. 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.
  3. Paul Lutus’ Symbolic Mathematics Using Maxima: A Leisurely Tutorial in 9 parts.

Advanced Guides

  1. 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.
  2. 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)

  1. Gilberto Urroz’s Maxima Book (Science & Engineering Applications): Comprehensive, each chapter organized by mathematical area.
  2. 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.
  3. Edwin Woollet’s 15 chapter Maxima By Example: a leisurely description of Maxima’s capabilities.

System Documentation

  1. Maxima Manual: 1000+ page (5MB) comprehensive manual and listing of all mathematical functions and capabilities built into Maxima.
  2. 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.
  3. 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.

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

  1. Engineering Problems: Javed Alam’s 22 sessions of Maxima for solving real-world Engineering problems
  2. Differential Equations & Fourier Analysis: Paul Lutus’s differential equations and circuit theory and Fourier (Spectral) Analysis.
  3. Differential Equations (First Order ODEs): Gregory Astley’s Using Maxima for Plotting Direction Fields of First Order ODEs
  4. Tensors: Tensor Algebra in Maxima
  5. 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.
  6. Calculus: Leon Brin’s Maxima and the Calculus

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.

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

  2. Combinations & Permutations, useful definitions:
    c(n,k):=binomial(n,k);
    p(n,k):=c(n,k)*k!;

  3. Discrete Mathematics: verification & validation of recurrence relation using binomial coefficients: Finite Summation by Recurrence Relations, Part 1 and Part 2.
  4. Linear Algebra/Matrix Manipulation: Finite Summation by Recurrence Relations, Part 3.
  5. Example Maxima script: iterative solution to finite sums recurrence relation sumkp_recurrence.mac
  6. 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.

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


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!

22 comments to Maxima (Computer Algebra)

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Your comments are valued! (Please indulge the gatekeeping question as spam-bots cannot (yet) do simple arithmetic...) - required

Optionally add an image (JPEG only)

 

Stats: 1,066,417 article views since 2010 (March update)

Dear Readers:

Welcome to the conversation!  We publish long-form pieces as well as a curated collection of spotlighted articles covering a broader range of topics.   Notifications for new long-form articles are through the feeds (you can join below).  We love hearing from you.  Feel free to leave your thoughts in comments, or use the contact information to reach us!

Reading List…

Looking for the best long-form articles on this site? Below is a curated list by the main topics covered.

Mathematics-History & Philosophy

  1. What is Mathematics?
  2. Prehistoric Origins of Mathematics
  3. The Mathematics of Uruk & Susa (3500-3000 BCE)
  4. How Algebra Became Abstract: George Peacock & the Birth of Modern Algebra (England, 1830)
  5. The Rise of Mathematical Logic: from Laws of Thoughts to Foundations for Mathematics
  6. Mathematical Finance and The Rise of the Modern Financial Marketplace
  7. A Course in the Philosophy and Foundations of Mathematics
  8. The Development of Mathematics
  9. Catalysts in the Development of Mathematics
  10. Characteristics of Modern Mathematics

Electronic & Software Engineering

  1. Electronics in the Junior School - Gateway to Technology
  2. Coding for Pre-Schoolers - A Turtle Logo in Forth
  3. Experimenting with Microcontrollers - an Arduino development kit for under £12
  4. Making Sensors Talk for under £5, and Voice Controlled Hardware
  5. Computer Programming: A brief survey from the 1940s to the present
  6. Forth, Lisp, & Ruby: languages that make it easy to write your own domain specific language (DSL)
  7. Programming Microcontrollers: Low Power, Small Footprints & Fast Prototypes
  8. Building a 13-key pure analog electronic piano.
  9. TinyPhoto: Embedded Graphics and Low-Fat Computing
  10. Computing / Software Toolkits
  11. Assembly Language programming (Part 1 | Part 2 | Part 3)
  12. Bare Bones Programming: The C Language

Pure & Applied Mathematics

  1. Fuzzy Classifiers & Quantile Statistics Techniques in Continuous Data Monitoring
  2. LOGIC in a Nutshell: Theory & Applications (including a FORTH simulator and digital circuit design)
  3. Finite Summation of Integer Powers: (Part 1 | Part 2 | Part 3)
  4. The Mathematics of Duelling
  5. A Radar Tracking Approach to Data Mining
  6. Analysis of Visitor Statistics: Data Mining in-the-Small
  7. Why Zero Raised to the Zero Power IS One

Technology: Sensors & Intelligent Systems

  1. Knowledge Engineering & the Emerging Technologies of the Next Decade
  2. Sensors and Systems
  3. Unmanned Autonomous Systems & Networks of Sensors
  4. The Advance of Marine Micro-ROVs

Math Education

  1. Teaching Enriched Mathematics, Part 1
  2. Teaching Enriched Mathematics, Part 2: Levelling Student Success Factors
  3. A Course in the Philosophy and Foundations of Mathematics
  4. Logic, Proof, and Professional Communication: five reflections
  5. Good mathematical technique and the case for mathematical insight

Explore…

Timeline