diophantine-0.2.0.0: A quadratic diophantine equation solving library.

PortabilityGHC
Stabilitystable
Maintainerjoejev@gmail.org
Safe HaskellSafe-Inferred

Math.Diophantine

Contents

Description

A module for solving quadratic diophantine equations.

Synopsis

Data

data Equation Source

A way to setup an equation in the form of:

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

Constructors

GeneralEquation Z Z Z Z Z Z

A general quadratic diophantine equation.

Instances

data Solution Source

The results of attempting to solve an Equation.

Constructors

ZxZ

All Integer pairs satisfy the equation.

NoSolutions

For all (x,y) in ZxZ

SolutionSet [(Z, Z)]

The set of pairs (x,y) that satisfy the equation. These are not in any particular order, and may contain duplicates.

Instances

type Z = IntegerSource

An alias for Integer, used to shorten type signatures.

data SolveError Source

A way to report an error in solving.

Constructors

SolveError ReadError

Represents a read error when reading the equation from a string.

HyperbolicError

The error when you try to solve a hyperbolic equation.

Instances

Utilities

readEquation :: String -> Either ReadError EquationSource

Reads an Equation as a String. Equations must be set equal to 0. Order of the terms does not matter expect for constant term, and = 0, which should come last if given. Returns 'Either ReadError Equation'

>>> readEquation "-5y + 2x - 3xy + 2"
-3xy + 2x + -5y + 2 = 0
>>> readEquation  "2xy + x + 1 = 0"
2xy + x + 1 = 0

specializeEquation :: Equation -> EquationSource

Detirmines what kind of equation form a GeneralEquation fits. If you pass a non GeneralEquation to this function, it is the same as id.

toMaybeList :: Solution -> Maybe [(Z, Z)]Source

Extracts the list of solution pairs from a Solution.

mergeSolutions :: Solution -> Solution -> SolutionSource

Merges two Solutions into one.

Equation Solving

solve :: Equation -> Either SolveError SolutionSource

Determines what type of equation to solve for, and then calls the appropriate solve function. Example:

>>> solve (GeneralEquation 1 2 3 3 5 0)
[(-3,0),(-2,-1),(0,0),(1,-1)]