My favorites | Sign in
Project Logo
                

Status

2009-08-13: mpmath 0.13 released. See the announcement and changelog for details.

(Older news)

About mpmath

Mpmath is a pure-Python library for multiprecision floating-point arithmetic. It provides an extensive set of transcendental functions, unlimited exponent sizes, complex numbers, interval arithmetic, numerical integration and differentiation, root-finding, linear algebra, and much more. Almost any calculation can be performed just as well at 10-digit or 1000-digit precision, and in many cases mpmath implements asymptotically fast algorithms that scale well for extremely high precision work. If available, mpmath will (optionally) use gmpy to speed up high precision operations.

Mpmath is free (BSD license) and easy to install or include in other software due to being written entirely in Python with no additional dependencies. It runs on Python 2.4, 2.5 and 2.6. It can be used as a library, interactively via the Python interpreter, or via SymPy which uses it for numerical evaluation of symbolic expressions. Mpmath is also available in Sage.

If matplotlib is available, mpmath also provides a convenient plotting interface. The three images below were generated by the commands plot([fresnels, fresnelc]), cplot(fresnels), and the mandelbrot.py script. See the function gallery for more images.

Documentation

The documentation provides installation instructions and extensive interactive examples.

Main documentation, development version (HTML)

Main documentation, 0.13 release (HTML)

List of features

Arithmetic:

Functions:

High-level features:

High-precision examples

A few different ways to compute pi (here to 50 decimal places): directly, as special values of various functions, using quadrature of the unit circle, quadrature of a Gaussian integral, accelerated summation of the slowly convergent Leibniz series, a limit of a sequence, and root-finding. To test mpmath, you can paste the following directly into an interactive Python session:

from mpmath import *
mp.dps = 50
print pi
print 2*asinh(j).imag
print gamma(0.5)**2
print sqrt(6*zeta(2))
print quad(lambda x: 4*sqrt(1-x**2), [0, 1])
print quad(lambda x: exp(-x**2), [-inf, inf]) ** 2
print nsum(lambda n: 4*(-1)**n/(2*n+1), [0, inf])
print limit(lambda n: 2**(4*n+1)*factorial(n)**4/(2*n+1)/factorial(2*n)**2, inf)
print findroot(sin, 3.14)

Each command should print 3.1415926535897932384626433832795028841971693993751.

Some additional demo scripts are available:

Some example computations with high precision:

Projects using mpmath









Hosted by Google Code