Portability | GHC |
---|---|
Stability | stable |
Maintainer | joejev@gmail.org |
Safe Haskell | Safe-Inferred |
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
- = SolveError ReadError
- | HyperbolicError
- readEquation :: String -> Either ReadError Equation
- specializeEquation :: Equation -> Equation
- toMaybeList :: Solution -> Maybe [(Z, Z)]
- mergeSolutions :: Solution -> Solution -> Solution
- solve :: Equation -> 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 ReadError | Represents a read error when reading the equation from a string. |
HyperbolicError | The error when you try to solve a hyperbolic equation. |
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.