Free computer algebra with Maxima
Maximum Math

© Roodni, Fotolia
This free algebra tool helps you keep ahead of the calculations.
The Maxima [1] Computer Algebra System (CAS) is a free tool for solving and simplifying mathematical equations. Originally created in the 1960s as a commercial program (Macsyma), Maxima is now included by many Linux distributions, although a Windows version is also available.
Maxima's preference for the command line reveals its Unix roots, but if you prefer a GUI, never fear. WxMaxima [2] offers a Maxima GUI interface that provides menus, mouse input, and graphical output.
In the simplest of all cases, you can use Maxima just like a pocket calculator: typing 101*27 at the prompt will give you 2727. Input starts with a prompt of %i (for input), and output with %o (for output).
Output
The output window numbers the lines and gives you the ability to perform further computations on previous results. For instance, to divide the result of this first simple example by 84, just enter %/84; the percent sign represents the last output.
To calculate with older results, type the line number after the percent sign, for example, %o3. The result of this first experiment might surprise you, 2727/84 results in 909/28 – the fraction is mathematically reduced to its simplest form.
To request decimal notation, add numer (for numeric) to the calculation. This option gives you a 16-digit approximation with the last digit rounded. If this is not accurate enough for you, you can specify a degree of floating point precision of 60 with the command fpprec:60, which is available in the menu at the top below Numeric.
Then you must typecast the result as a big float, using bfloat(%) or bfloat(909/28).This approach lets you view as many decimal places as you like, but only makes sense for fractions with very short periods.
If you really want to see the first 3,000 decimal places of pi (Maxima has a %pi constant for this), you would just type fpprec:3000, followed by \%pi,numer.
Of course, the system can resolve fractions. Entering:
outputs the exact result: 7/5.
Installation
Maxima is available from its homepage on Sourceforge [1] for Linux and other operating systems. The current version is 5.14.0. Most Linux distributions include Maxima and the wxMaxima GUI by default. On Ubuntu 8.04, for example, users can just apt-get install maxima wxmaxima gnuplot to install the full set of packages. Unfortunately, the Ubuntu repository only offers the second-to-last version – although this should be fine for getting started. If necessary, you can download the source code or the latest RPM package from the Maxima page [2].
Big Numbers
Another typical Maxima task is precise calculations with very large numbers. Pocket calculators and spreadsheets automatically switch to an exponential notation as of a certain size of number (for example, 231).
In contrast to this, wxMaxima gives users the ability to calculate with numbers of any size; the limit is basically defined by the amount of RAM you have available.
For example, the program has no trouble writing out the number 2170:
1496577676626844588240573268701473812127674924007424
wxMaxima just outputs the first and last digits in even larger numbers and lets you know the total number of digits. For example, 13220 results in a number with about 250 digits, of which just the first and last 30 are output.
If you want to see all the digits, you can do so by issuing the set_display(ascii) command. The factorial of 1,500 (1500!) will fill the screen with a number comprising over 4000 digits. To restore the more convenient reduced notation, just tell Maxima to set_display(xml).
The program implements not only the factorial function, but also a number of prime number functions that allow for interesting experiments, especially in combination with calculations involving large numbers. For example, the primep() function checks whether a number is a prime number. primep(788367353713) returns true (the number is a prime number), whereas a test of 788367353643 returns false.
Factoring tells you which prime factors the second figure comprises: factor(788367353643) returns the factors 3 * 3 * 733 * 119503919. A number built out of many prime factors will give you a far more impressive list: try factor(5000!).
Searching for a large prime number (which is sometimes necessary with cryptographic applications) is fairly simple. The instruction p1:next_prime(377220) finds the first prime number that follows 377220 and stores it in a variable dubbed p1 – this is a figure with about 500 digits.
Calling the function p2:next_prime(%) finds the next prime number and stores it as p2. Depending on your computer, this could take a couple of seconds.
The product of the two prime numbers (p1*p2) is a useful basis for part of an RSA key. However, using consecutive prime numbers is not recommended in production environments.
The following is an example of a composite number:
345862011780410397876013873188202447214134147993527728038112440197322495509204470242935323783165385289930823657232278711064866624396026528162520366869362889027847958124572048492902238930631589988184826133619274368192339977782807717735312582897230196328769838321209122609377462417318508826015697895512065549020013940594309185368543866142627334637083672548438918468553728549604911185025083035795738981546908678540702875792312840910506614178563476224312376011581158579070227159596612897837865541697908514794385246878768150137301974631020508238553705918725815721502791333002836671068519210347427534113281007898764644175589677906569910366868727657616275090844456345270852746790478521245034979650230712487412014882245913487037099190364226621719562272089742807613919578158325332361890921677816966011968781104142713267093080704641916493691780983794152328256135894898253264957641101560408631873470108837849577534668782072859228734103104199834644775463040487237495558910707470179588781884923881018390446977360885215482029883283976880008163640733890944133463087709320026714183311160400564555642278016518244662185883042717413
Again, this number is the product of two large prime numbers. If you don't need your computer for a while, you can ask it to discover the prime factors.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
Escuelas Linux 8.0 is Now Available
Just in time for its 25th anniversary, the developers of Escuelas Linux have released the latest version.
-
LibreOffice 7.5 has Arrived Loaded with New Features and Improvements
The favorite office suite of the Linux community has a new release that includes some visual refreshing and new features across all modules.
-
The Next Major Release of Elementary OS Has Arrived
It's been over a year since the developers of elementary OS released version 6.1 (Jólnir) but they've finally made their latest release (Horus) available with a renewed focus on the user.
-
KDE Plasma 5.27 Beta Is Ready for Testing
The latest beta iteration of the KDE Plasma desktop is now available and includes some important additions and fixes.
-
Netrunner OS 23 Is Now Available
The latest version of this Linux distribution is now based on Debian Bullseye and is ready for installation and finally hits the KDE 5.20 branch of the desktop.
-
New Linux Distribution Built for Gamers
With a Gnome desktop that offers different layouts and a custom kernel, PikaOS is a great option for gamers of all types.
-
System76 Beefs Up Popular Pangolin Laptop
The darling of open-source-powered laptops and desktops will soon drop a new AMD Ryzen 7-powered version of their popular Pangolin laptop.
-
Nobara Project Is a Modified Version of Fedora with User-Friendly Fixes
If you're looking for a version of Fedora that includes third-party and proprietary packages, look no further than the Nobara Project.
-
Gnome 44 Now Has a Release Date
Gnome 44 will be officially released on March 22, 2023.
-
Nitrux 2.6 Available with Kernel 6.1 and a Major Change
The developers of Nitrux have officially released version 2.6 of their Linux distribution with plenty of new features to excite users.