Skip to main content

Diophantine

Unit Test Status Unit Test Coverage

Author: Thomas G. Close (tom.g.close@gmail.com)

Diophantine (http://github.com/tclose/Diophantine) is a Python package for finding small (integer) solutions of systems of diophantine equations (see http://en.wikipedia.org/wiki/Diophantine_equation). It is based on PHP code by Keith Matthews (see www.number-theory.org) that implements the algorithm described in https://github.com/tclose/Diophantine/blob/master/algorithm.pdf (see http://www.numbertheory.org/lll.html for a list of associated publications), which uses the LLL algorithm to calculate the Hermite-normal-form described in the paper:

Extended gcd and Hermite normal form algorithms via lattice basis reduction, G. Havas, B.S. Majewski, K.R. Matthews, Experimental Mathematics, Vol 7 (1998) 125-136

(please cite this paper if you use this code in a scientific publication)

There are two branches of this code in the GitHub repository (see https://github.com/tclose/Diophantine.git), ‘master’, which uses the sympy library and therefore uses arbitrarily long integer representations, and ‘numpy’, which uses the numpy library, which is faster but can suffer from integer overflow errors despite using int64 representations

To find small solutions to a system of diophantine equations, A x = b, where A is a M x N matrix of coefficents, b is a M x 1 vector and x is the N x 1 vector, use the ‘solve’ method in the module, e.g.

>>> from sympy import Matrix
>>> from diophantine import solve
>>> A = Matrix([[1, 0, 0, 2], [0, 2, 3, 5], [2, 0, 3, 1], [-6, -1, 0, 2],
                [0, 1, 1, 1], [-1, 2, 0,1], [-1, -2, 1, 0]]).T
>>> b = Matrix([1, 1, 1, 1])
>>> solve(A, b)
[Matrix([
[-1],
[ 1],
[ 0],
[ 0],
[-1],
[-1],
[-1]])]

The returned solution vector will tend to be one with the smallest norms. If multiple solutions with the same norm are found they will all be returned. If there are no solutions the empty list will be returned.

Diophantine is released under the MIT Licence (see Licence for details)

Installation

Diophantine is available from the Python Package Index (http://pypi.python.org) and can be installed with the command

pip install diophantine

Alternatively, the master branch can be installed from using the setuptools install command

python setup.py install

from a clone of the GitHub repository (https://github.com/tclose/Diophantine) or simply adding the cloned directory to your PYTHONPATH.

Release files for Diophantine 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Diophantine 0.2.0
File Size Uploaded
Diophantine-0.2.0.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Diophantine 0.2.0
File Interpreter ABI Platform
Diophantine-0.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 17.0 kB

Release files / Diophantine-0.2.0.tar.gz

Download URL Diophantine-0.2.0.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c9ad7026ca0d26dffd3e5754bf550020789212b892d80c4a5ce6ae6548ffa196
BLAKE2b-256 checksum
How to use checksums
e178c95b809d675dc1bda65e547a7a53ba9c8ad6053644b56500fd959ac9d1fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Diophantine-0.2.0-py2.py3-none-any.whl

Download URL Diophantine-0.2.0-py2.py3-none-any.whl
Size 9.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
70e00e728ebfb2ed426ef98591a78edf8e3c87fbd5f1080b26494ae65ec83d5d
BLAKE2b-256 checksum
How to use checksums
bddb92ebaf5f25d87b181139846b9452a94fa7f14c3b664fbdc320c4b106288f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page