Setting up mpmath
=================

Download and installation
-------------------------

Installer
.........

The mpmath setup files can be downloaded from the `mpmath download page <http://code.google.com/p/mpmath/downloads/list>`_ or the `Python Package Index <http://pypi.python.org/pypi/mpmath/>`_. Download the source package (available as both .zip and .tar.gz), extract it, open the extracted directory, and run

    ``python setup.py install``

If you are using Windows, you can download the binary installer

    ``mpmath-(version).win32.exe``

from the mpmath website or the Python Package Index. Run the installer and follow the instructions.

Using setuptools
................

If you have `setuptools <http://pypi.python.org/pypi/setuptools>`_ installed, you can download and install mpmath in one step by running:

    ``easy_install mpmath``

or

    ``python -m easy_install mpmath``

If you have an old version of mpmath installed already, you may have to pass ``easy_install`` the ``-U`` flag to force an upgrade.


Debian/Ubuntu
.............

Debian and Ubuntu users can install mpmath with

    ``sudo apt-get install python-mpmath``

See `debian <http://packages.debian.org/python-mpmath>`_ and `ubuntu <https://launchpad.net/ubuntu/+source/mpmath>`_ package information; please verify that you are getting the latest version.

OpenSUSE
........

Mpmath is provided in the "Science" repository for all recent versions of `openSUSE <http://www.opensuse.org/>`_. To add this repository to the YAST software management tool, see http://en.opensuse.org/Add_Package_Repositories_to_YaST and use one of the following repository URLs:

  * http://download.opensuse.org/repositories/science/openSUSE_10.2/
  * http://download.opensuse.org/repositories/science/openSUSE_10.3/
  * http://download.opensuse.org/repositories/science/openSUSE_11.0/

Current development version
...........................

See  http://code.google.com/p/mpmath/source/checkout for instructions on how to check out the mpmath Subversion repository. The source code can also be browsed online from the Google Code page.

Checking that it works
......................

After the setup has completed, you should be able to fire up the interactive Python interpreter and do the following::

    >>> from mpmath import *
    >>> mp.dps = 50
    >>> print mpf(2) ** mpf('0.5')
    1.4142135623730950488016887242096980785696718753769
    >>> print 2*pi
    6.2831853071795864769252867665590057683943387987502

*Note: if you have mpmath 0.6 or earlier installed, you may have to either first uninstall the old version, or manually delete the obsolete mpmath/lib directory. Otherwise this directory will be imported erroneously.*

Using gmpy (optional)
---------------------

By default, mpmath uses Python integers internally. If `gmpy <http://code.google.com/p/gmpy/>`_ version 1.03 or later is installed on your system, mpmath will automatically detect it and transparently use gmpy integers intead. This makes mpmath much faster at high precision (approximately above 100 digits).

To verify that mpmath uses gmpy, check the internal MODE variable is not equal to 'python':

    >>> import mpmath.settings
    >>> mpmath.settings.MODE
    'gmpy'

The gmpy mode can be disabled by setting the MPMATH_NOGMPY environment variable. Note that the mode cannot be switched during runtime; mpmath must be re-imported for this change to take effect.

Running tests
-------------

It is recommended that you run mpmath's full set of unit tests to make sure everything works. The tests are located in the ``tests`` subdirectory of the main mpmath directory. They can be run in the interactive interpreter using the ``runtests()`` function::

    import mpmath
    mpmath.runtests()

Alternatively, they can be run from the ``tests`` directory via

    ``python runtests.py``

The tests should finish in about a minute. If you have `psyco <http://psyco.sourceforge.net/>`_ installed, the tests can also be run with

    ``python runtests.py -psyco``

which will cut the running time in half.

If any test fails, please send a detailed bug report to the `mpmath issue tracker <http://code.google.com/p/sympy/issues/list>`_. The tests can also be run with `py.test <http://codespeak.net/py/dist/>`_. This will sometimes generate more useful information in case of a failure.

To run the tests with support for gmpy disabled, use

    ``python runtests.py -nogmpy``

To enable extra diagnostics, use

    ``python runtests.py -strict``

Compiling the documentation
---------------------------

If you downloaded the source package, the text source for these documentation pages is included in the ``doc`` directory. The documentation can be compiled to pretty HTML using `Sphinx <http://sphinx.pocoo.org/>`_. Go to the ``doc`` directory and run

    ``python build.py``

You can also test that all the interactive examples in the documentation work by running

    ``python run_doctest.py``

(The doctests may take several minutes.)

Finally, some additional demo scripts are available in the ``demo`` directory included in the source package.
