diophantine-0.2.1.0: A quadratic diophantine equation solving library.

CopyrightJoe Jevnik 2013
LicenseGPL-2
Maintainerjoejev@gmail.org
Stabilitystable
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

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 = Integer Source

An alias for Integer, used to shorten type signatures.

data SolveError Source

A way to report an error in solving.

Constructors

SolveError ParseError

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

HyperbolicError

The error when you try to solve a hyperbolic equation.

Instances

data ParseError Source

The types of parse erros that can occur.

Constructors

PowerOutOfBounds

We are only solving quadratics.

BadGrammar

Not a valid equation type.

Instances

Show ParseError

Pretty print instance for ParseErrors.

Utilities

readEquation :: String -> Either ParseError Equation Source

Reads an equation from a string returning an Equation or ParseError.

specializeEquation :: Equation -> Equation Source

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 -> Solution Source

Merges two Solutions into one.

Equation Solving

solve :: Equation -> Either SolveError Solution Source

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)]

solveString :: String -> Either SolveError Solution Source

Read an Equation out of a String, and then solve it. This can fail because the string is not a valid equation.