Copyright | Joe Jevnik 2013 |
---|---|
License | GPL-2 |
Maintainer | joejev@gmail.org |
Stability | stable |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
A module for solving quadratic diophantine equations.
- data Equation = GeneralEquation Z Z Z Z Z Z
- data Solution
- = ZxZ
- | NoSolutions
- | SolutionSet [(Z, Z)]
- type Z = Integer
- data SolveError
- data ParseError
- readEquation :: String -> Either ParseError Equation
- specializeEquation :: Equation -> Equation
- toMaybeList :: Solution -> Maybe [(Z, Z)]
- mergeSolutions :: Solution -> Solution -> Solution
- solve :: Equation -> Either SolveError Solution
- solveString :: String -> Either SolveError Solution
Data
A way to setup an equation in the form of:
ax^2 + bxy + cy^2 + dx + ey + f = 0
The results of attempting to solve an Equation
.
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. |
data SolveError Source
A way to report an error in solving.
SolveError ParseError | Represents a read error when reading the equation from a string. |
HyperbolicError | The error when you try to solve a hyperbolic equation. |
data ParseError Source
The types of parse erros that can occur.
PowerOutOfBounds | We are only solving quadratics. |
BadGrammar | Not a valid equation type. |
Show ParseError | Pretty print instance for |
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
.
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)]