diophantine: A quadratic diophantine equation solving library.

[ gpl, library, math ] [ Propose Tags ]

A library for solving quadratic diophantine equations.

This library is designed to solve for equations where:

  • the form is: ax^2 + bxy + cy^2 + dx + ey + f = 0

  • a,b,c,d,e,f are integers.

  • soltutions are restricted to x and y are also integers.

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 joejev@gmail.com.

[Skip to Readme]


[Last Documentation]

  • Math
    • Math.Diophantine


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,
Dependencies base (>=4.6 && <4.7) [details]
License GPL-2.0-only
Copyright Joe Jevnik 2013
Author Joe Jevnik
Maintainer joejev@gmail.com
Category Math
Home page https://github.com/llllllllll/Math.Diophantine
Source repo head: git clone https://github.com/llllllllll/Math.Diophantine.git
Uploaded by joejev at 2013-12-08T23:44:59Z
Distributions NixOS:
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 2557 total (1 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
Successful builds reported [all 6 reports]

Readme for diophantine-

[back to package description]


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
	( Equation(..)          -- instance of: Show
    , Solution(..)          -- instance of: Eq, Show
    , Z
    , specializeEquation    -- :: Equation -> Equation
    , toMaybeList           -- :: Solution -> Maybe [(Integer,Integer)]
    , mergeSolutions        -- :: Solution -> Solution -> Solution
    , solve                 -- :: Equation -> Solution
    , solveLinear           -- :: Equation -> Solution
    , solveSimpleHyperbolic -- :: Equation -> Solution
    , solveEliptical        -- :: Equation -> Solution
    , solveParabolic        -- :: Equation -> Solution

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

  • GeneralEquation Z Z Z Z Z Z - where the six Integers coincide with the six coefficients.
  • LinearEquation Z Z Z - where the 3 integers are d, e, and f.
  • SimpleHyperbolicEquation Z Z Z Z - where the 3 integers are b, d, e, and f.
  • ElipticalEquation Z Z Z Z Z Z - where the six Integers coincide with the six coefficients.
  • ParabolicEquation Z Z Z Z Z Z - where the six Integers coincide with the six coefficients.
  • HyperbolicEquation Z Z Z Z Z Z - where the six Integers coincide with the six coefficients.

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:

  • ZxZ - ZxZ is the cartesian product of Z and Z, or the set of all pairs of integers. This Solution denotes cases where all pairs will satisfy your equation, such as 0x + 0y = 0.
  • NoSolutions - This Solution denotes that for all (x,y) in Z cross Z, no pair satisfies the equation.
  • SolutionSet [(Z,Z)] - This Solution denotes that for all pairs (x,y) in this set, they will satisfy the given equation.


  • Finish the implementation of solveHyperbolic
  • Write an equation parser from a string.