Free computer algebra with Maxima
Maximum Math
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
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.