MyNixOS website logo
Description

A quadratic diophantine equation solving library.

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.

  • Solutions 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 [email protected].

Math.Diophantine

A quadratic diophantine equation solving library for haskell.

Overview:

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.

Installation:

To install the library, just use cabal along with the provided install files.

Use:

import the library with:

import module Math.Diophantine

The most import function of this library is solve :: Equation -> Either SolveError 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.

There is also a readEquation :: String -> Either ParseError Equation and solveString :: String -> Either SolveError Solution for parsing equations out of strings. This will do some basic simplification of the equation.

TODO:

  • Finish the implementation of solveHyperbolic.
Metadata

Version

0.2.1.0

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows