The diophantine package

[Tags: gpl, library]

A library for solving quadratic diophantine equations.

This library is designed to solve for equations where:

This library breaks down equations based on their type to solve them most efficiently. This library supports linear, simple hyperbolic, eliptical, and parabolic equations, with hyperbolics on the way.

Please send feedback or bugs to

[Skip to ReadMe]


Change logNone available
Dependenciesarray (>=, base (>=4.7 && <5) [details]
CopyrightJoe Jevnik 2014
AuthorJoe Jevnik
MaintainerJoe Jevnik <>
Home page
Source repositoryhead: git clone
UploadedMon Nov 24 03:48:25 UTC 2014 by joejev
Downloads546 total (27 in last 30 days)
0 []
StatusDocs uploaded by user
Build status unknown [no reports yet]




Maintainers' corner

For package maintainers and hackage trustees

Readme for diophantine-


A quadratic diophantine equation solving library for haskell.


This library is designed to solve for equations in the form of:

ax^2 + bxy + cy^2 + dx + ey + f = 0

Throughout the library, the variables (a,b,c,d,e,f) will always refer to these coefficients. This library will also use the alias:

type Z = Integer

to shorten the type declerations of the data types and functions.


To install the library, just use cabal along with the provided install files.


import the library with:

import module Math.Diophantine

The most import function of this library is solve :: Equation -> Either SolveError Solution. The types of equations that this library can solve are defined by the different instances of Equation:

For most cases, one will want to call solve with a GeneralEquation. A GeneralEquation is used when one does not know the type of equation before hand, or wants to take advantage of the libraries ability to detirmine what kind of form it fits best. One can call specializeEquation to convert a GeneralEquation into the best specialized equation that it matches. This function is called within solve, so one can pass any type of function to solve. The specific functions will try to match to a GeneralEquation if they can; however, they will throw an error if they cannot. The error behavior exists only because these functions should only be called directly if and only if you know at compile time that this function will only ever recieve the proper form. One may want to use these directly for a speed increase, or to clarify a section of code. The solve* functions will return a Solution. Solutions are as follows:

There is also a readEquation :: String -> Either ParseError Equation and solveString :: String -> Either SolveError Solution for parsing equations out of strings. This will do some basic simplification of the equation.