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 16digit 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 aptget install maxima wxmaxima gnuplot to install the full set of packages. Unfortunately, the Ubuntu repository only offers the secondtolast 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, 2^{31}).
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 2^{170}:
1496577676626844588240573268701473812127674924007424
wxMaxima just outputs the first and last digits in even larger numbers and lets you know the total number of digits. For example, 13^{220} 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(377^{220}) finds the first prime number that follows 377^{220} 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
News

LinuxCon North America Convenes in Toronto, Canada
Linux Foundation's big event celebrates the 25th anniversary of Linux

Linux Turns 25
Linux has evolved from a “won’t be a professional” project to one of the most professional software projects in the history of computers.

Mirantis Joins Hands with SUSE To Offer RHEL Support; Red Hat Not Happy
Competitors get in the game with RHEL without Red Hat

Linux on Windows 10 Poses a Security Risk
Security researchers have already notified Microsoft; some fixes are available

Mirantis to Refactor OpenStack Fuel for Kubernetes
The company is collaborating with Google and Intel to use Kubernetes as an engine for Fuel

Canonical Joins Document Foundation Advisory Board
The upcoming release of LibreOffice will be available as a snap package

SUSE Joins the Microsoft Test Drive Program
Customers can take a free test drive of SLES for HPC on the Azure Cloud

SiFive Launches a Line of Open Source Chips
San Franciscobased chip company announces their first fully open source chip platform.

Fedora 24 Released
The whole distro gets rebuilt on glibc 2.3

Canonical Announces CrossDistro Support for Snaps
Ubuntu Vendor tries to solve app packaging and distribution problem across distributions.