Are there any open source math programs out there that have an interactive terminal and that work on linux?

So for example you could enter two matrices and specify an operation such as multiply and it would then return the answer or a error message specifying why an answer can't be computed? I am just looking for something that can perform basic matrix operations and modular arithmetic.

  • 4,981
  • 22
  • 62
  • 79

14 Answers14


Sage is basically a Python program/interpreter that aims to be an open-source mathematical suite (ala Mathematica and Magma etc.). There are many algorithms implemented as a direct part of Sage, as well as wrapping many other open-source mathematics packages, all into a single interface (the user never has to tell which package or algorithm to use for a given computation: it makes the decisions itself). It includes GP/Pari and maxima, and so does symbolic manipulations and number theory at least as well as them.

It has a command-line mode, as well as a web notebook interface (as an example, a public server run by the main developers).

And, although this might not be relevant since your use-case sounds very simple, the syntax is just Python with a small preprocessing step to facilitate some technical details and allow some extra notation (like [1..4] which expands to [1,2,3,4]), so many people already know it and, if not, learning it is very easy.

As a slight tangent, Sage is actually the origin of the increasingly popular Cython language for writing fast "Python", and even offers an easy and transparent method of using Cython for sections of code in the notebook.

  • 797
  • 7
  • 10
  • 1
    +1. A single program which will do both matrix computations and modular arithmetic as per OP request. –  Aug 03 '12 at 12:29
  • 2
    @J.D. As is Pari/GP - as single program that will do both matrix computations and modular arithmetic as per OP request :) – Old John Aug 03 '12 at 12:40
  • In my Cryptography class, we used Sage for everything. The professor would spend the second part of pretty much every lecture giving Sage examples relating to the first part of the lecture. It's a very powerful tool. – dspyz Aug 04 '12 at 04:37
  • 1
    @PeterSheldrick Under windows, you might want to give [Spyder](https://code.google.com/p/spyderlib/wiki/Features) (there's also a Linux version) a try, it's part of [PythonXY](http://www.pythonxy.com) – Tobias Kienzler Aug 04 '12 at 07:43
  • @PeterSheldrick if you can set up a Sage server, you can use the web notebook interface on windows or anywhere else! – TJ Ellis Aug 05 '12 at 19:17
  • 2
    I feel it's a bit disingenuous to say that Sage is just a wrapper for a bunch of packages. It's certainly this, but Sage also sports a wide variety of algorithms implemented in Sage by the developers. – JSchlather Aug 05 '12 at 19:30
  • @JacobSchlather, I agree that it wasn't good. I've (hopefully) made the answer better. :) – huon Aug 05 '12 at 19:46

I am aware of two packets that might help You:

  1. Octave - free clone of Matlab,
  2. maxima - a packet for symbolic computations.

Octave is good when you want to do numerical calculations and you can accept numerical errors. Especially good for matrix/vector operations. I think this is what you want. Maxima is rather for symbolic computations. Both of them have text interface. If you want more user-friendly interface for the latter one, try wxMaxima.

Konrad Sakowski
  • 518
  • 3
  • 13
  • what type of syntax does maxima use? – Magpie Aug 03 '12 at 16:38
  • 1
    Maxima requires multiplication to be explicitly expressed (so xx is always one variable/symbol with a two-letter name instead of being x*x). You can assign expressions or equations to variable names with the colon operator ':', and certain matrix operations like cross-product '~' require an extra package to be loaded and must be passed as an argument to the express() function to get an actual result. Other than that, the syntax and functionality is similar to most CAS software or calculators. It's useful for dealing with differential equations, but I'd use something else for numerical work. – James O'Doherty Aug 04 '12 at 07:22

For modular arithmetic and much more by way of number theory, I would strong recommend GP/Pari from here.

It does a huge variety of operations mostly relevant to number theory, but not limited to that area. It should be easily installable on most versions of Linux.

Added: just checked, and it also does a wide variety of vector/matrix and linear algebra stuff.

Old John
  • 19,181
  • 3
  • 55
  • 107

I recommend numpy and scipy, which are packages for Python. The advantage over many dedicated mathematical packages is that they are packages for a well established language, meaning that they may easily integrated with all the other things you do with computers, such as generating images, reports, web pages, or interacting with a desktop application.

The ipython program provides a very useful shell for direct interaction with the packages. What's more, matplotlib is integrated with ipython through the command line switch

ipython --pylab

Look seriously at numpy, if you're interest is in matrices there are tools here which make your life very easy.

  • 1
    I second this. If the "terminal" can be in an IDE, [spyder](https://code.google.com/p/spyderlib/wiki/Features) is a great addition to this suggestion – Tobias Kienzler Aug 03 '12 at 17:50
  • I second numpy/ipython. Also in the future if you need more advanced data visualization you can get inline graphical plotting of data using [ipython/qtconsole](http://ipython.org/ipython-doc/dev/interactive/qtconsole.html) – Trevor Boyd Smith Aug 03 '12 at 20:55

Yes, GNU Octave, the open source terminal equivalent of MATLAB. Most MATLAB code can be used in Octave directly, and their computation times are roughly equivalent. Octave can plot but does not have a GUI terminal.

  • 1,821
  • 11
  • 16

Scilab is a good opensourced Matlab-like software. If you know Matlab, Scilab is very similar.

  • 181
  • 4
  • 8

I suggest a computer algebra system, maxima, whose license is GPL, therefore it's entirely FREE. It specializes in symbolic operations but also offers numerical capablities.

If you hate command line interface, you can choose wxmaxima. It's just a good frontend of maxima.

And if you're a common lisp programmer, you can choose embeddable maxima. It provides the freedom of mixture between common lisp programs and maxima functions. I got this from an answer to my post

  • 9,328
  • 1
  • 26
  • 77

Depending on my use-case I either use Calc; the C-style arbitrary precision calculator or bc.

(Both are available on Linux/OSX/Windows)


Example matrix assignment:

mat [2][3] = {{1,2,3},{4,5,6}}

Documentation for multiplication of matrices:

A * B

Multiplication is defined provided certain conditions by the dimensions and shapes of A and B are satisfied. If both have dimension 2 and the column-index-list for A is the same as the row-index-list for B, C = A * B is defined in the usual way so that for i in the row-index-list of A and j in the column-index-list for B,

                     C[i,j] =  Sum A[i,k] * B[k,j]

the sum being over k in the column-index-list of A. The same formula is used so long as the number of columns in A is the same as the number of rows in B and k is taken to refer to the offset from matmin(A,2) and matmin(B,1), respectively, for A and B. If the multiplications and additions required cannot be performed, an execution error may occur or the result for C may contain one or more error-values as elements.

If A or B has dimension zero, the result for A * B is simply that of multiplying the elements of the other matrix on the left by A[] or on the right by B[].

If both A and B have dimension 1, A * B is defined if A and B have the same size; the result has the same index-list as A and each element is the product of corresponding elements of A and B. If A and B have the same index-list, this multiplication is consistent with multiplication of 2D matrices if A and B are taken to represent 2D matrices for which the off-diagonal elements are zero and the diagonal elements are those of A and B. the real and complex numbers.

If A is of dimension 1 and B is of dimension 2, A * B is defined if the number of rows in B is the same as the size of A. The result has the same index-lists as B; each row of B is multiplied on the left by the corresponding element of A.

If A is of dimension 2 and B is of dimension 1, A * B is defined if number of columns in A is the same as the size of A. The result has the same index-lists as A; each column of A is multiplied on the right by the corresponding element of B.

The algebra of additions and multiplications involving both one- and two-dimensional matrices is particularly simple when all the elements are real or complex numbers and all the index-lists are the same, as occurs, for example, if for some positive integer n, all the matrices start as mat [n] or mat [n,n].

Samuel Marks
  • 151
  • 4

In addition to the various heavy-weight tools already named, you should also take a look at Euler Math Toolbox. It is a free, portable, and open source math environment that supports both matrix operations and symbolic manipulation.

It has a straightforward notebook page usage model, with results, plots, and graphics interspersed with the commands and equations that produce them. It is also extensible via Python for those so inclined.

An interesting alternative for some applications is Geogebra. It is an interactive geometry, algebra, and calculus application, intended for teachers and students.

Another interesting alternative to the well known tools is GSL Shell. This is a tool that wraps the Lua language around the Gnu Scientific Library. It supports a wide array of numeric methods on vectors and scalars. Being based on Lua, the syntax is distinctly different in flavor from the MATLAB inspired Octave or any of the tools based on Python. But that flavor might be to your liking.

  • 143
  • 4

The Julia language is an interesting up and coming numerical mathematics language that's been getting a lot of attention in recent months. It's sort of a mix of Matlab, R, and common Lisp.

Nick Alger
  • 16,798
  • 11
  • 59
  • 85

A simple but quite functional alternative would be Genius. It has various numerical and plotting capabilities and a programming language (GEL).

Ilmo Euro
  • 131
  • 4

Its already a feature of your terminal. Simply encapsulate your equation in $(( )) , for example ...

bash> echo $((1 + 1))

I only know this coz Im a programmer not a mathematician. :)

Have fun, Eugene.

  • 129
  • 3


FreeMat is a free environment for rapid engineering and scientific prototyping and data processing. It is similar to commercial systems


Take a look at PARI/GP. But it's rather specific.

  • 321
  • 1
  • 10