Free computer algebra with Maxima

Maximum Math

© Roodni, Fotolia

© Roodni, Fotolia

Author(s):

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.

Read full article as PDF:

054-057_maxima.pdf  (898.14 kB)

Related content

  • KDE SC 4.4

    Version 4.4 sees the KDe Software Compilation reach a status on par with the user friendliness and stability of good old KDe 3.5. On top of this, many features are new.

  • Perl: Plotting GPS Data

    Perl hackers take to the hills with a navigation system that provides a graphical rendering of a hiking tour.

  • Perl: Reading GPS Data

    With a small GPS receiver on his wrist, Mike has been jogging through San Francisco neighborhoods. While catching his breath, safe at home, he visualizes the data he acquired while running with Perl.

  • Neural Networks

    3, 4, 8, 11… ? A neural network can complete this series without knowledge of the underlying algorithm – by a kind of virtual gut feeling. We’ll show you how neural networks solve problems by simulating the behavior of a human brain.

  • SuperCollider

    SuperCollider is a versatile and powerful sound generator that can be used to create, filter, and modulate sound. In this article, we tackle the basics.

comments powered by Disqus

Direct Download

Read full article as PDF:

054-057_maxima.pdf  (898.14 kB)

News