modular-arithmetic

A type for integers modulo some constant. https://github.com/TikhonJelvis/modular-arithmetic

Latest on Hackage:1.2.1.2

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD3 licensed and maintained by Tikhon Jelvis

Modular Arithmetic

Hackage package Build Status

This package provides a type for integers modulo some constant, usually written as ℤ/n.

Here is a quick example:

>>> 10 * 11 :: ℤ/7
5

It also works correctly with negative numeric literals:

>>> (-10) * 11 :: ℤ/7
2

Modular division is an inverse of modular multiplication. It is defined when divisor is coprime to modulus:

>>> 7 `div` 3 :: ℤ/16
13
>>> 3 * 13 :: ℤ/16
7

Changes

1.2.1.2

  • exported the / type operator with ExplicitNamespaces enabled to support GHC 8. Should be backwards compatible through GHC 7.6.

1.2.1.1

  • added a basic test suite with doctests

1.2.1.0

  • changed Integral implementation: quotRem now uses modular inversion!
  • added inv for modular inversion
  • added SomeMod data type for modular number with unknown modulus
  • added modVal and someModVal helpers similar to ones in GHC.TypeLits
Depends on:
Used by 2 packages:
comments powered byDisqus