arithmoi-0.8.0.0: Efficient basic number-theoretic functions.

Copyright(c) 2018 Alexandre Rodrigues Baldé
LicenseMIT
MaintainerAlexandre Rodrigues Baldé <alexandrer_b@outlook.com>
StabilityProvisional
PortabilityNon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

Math.NumberTheory.Euclidean

Description

This module exports a class to represent Euclidean domains.

Synopsis

Documentation

class (Eq a, Num a) => Euclidean a where #

A class to represent a Euclidean domain, which is basically an Integral without toInteger.

Minimal complete definition

quotRem, divMod

Methods

quotRem :: a -> a -> (a, a) #

When restriced to a subring of the Euclidean domain a isomorphic to Integer, this function should match quotRem for Integers.

divMod :: a -> a -> (a, a) #

When restriced to a subring of the Euclidean domain a isomorphic to Integer, this function should match divMod for Integers.

quot :: a -> a -> a #

rem :: a -> a -> a #

div :: a -> a -> a #

mod :: a -> a -> a #

gcd :: a -> a -> a #

gcd x y is the greatest number that divides both x and y.

lcm :: a -> a -> a #

lcm x y is the smallest number that both x and y divide.

coprime :: a -> a -> Bool #

Test whether two numbers are coprime .

extendedGCD :: a -> a -> (a, a, a) #

Calculate the greatest common divisor of two numbers and coefficients for the linear combination.

For signed types satisfies:

case extendedGCD a b of
  (d, u, v) -> u*a + v*b == d
               && d == gcd a b

For unsigned and bounded types the property above holds, but since u and v must also be unsigned, the result may look weird. E. g., on 64-bit architecture

extendedGCD (2 :: Word) (3 :: Word) == (1, 2^64-1, 1)

For unsigned and unbounded types (like Natural) the result is undefined.

For signed types we also have

abs u < abs b || abs b <= 1

abs v < abs a || abs a <= 1

(except if one of a and b is minBound of a signed type).

Instances
Euclidean Int # 
Instance details

Defined in Math.NumberTheory.Euclidean

Methods

quotRem :: Int -> Int -> (Int, Int) #

divMod :: Int -> Int -> (Int, Int) #

quot :: Int -> Int -> Int #

rem :: Int -> Int -> Int #

div :: Int -> Int -> Int #

mod :: Int -> Int -> Int #

gcd :: Int -> Int -> Int #

lcm :: Int -> Int -> Int #

coprime :: Int -> Int -> Bool #

extendedGCD :: Int -> Int -> (Int, Int, Int) #

Euclidean Integer # 
Instance details

Defined in Math.NumberTheory.Euclidean

Euclidean Natural # 
Instance details

Defined in Math.NumberTheory.Euclidean

Euclidean Word # 
Instance details

Defined in Math.NumberTheory.Euclidean

Methods

quotRem :: Word -> Word -> (Word, Word) #

divMod :: Word -> Word -> (Word, Word) #

quot :: Word -> Word -> Word #

rem :: Word -> Word -> Word #

div :: Word -> Word -> Word #

mod :: Word -> Word -> Word #

gcd :: Word -> Word -> Word #

lcm :: Word -> Word -> Word #

coprime :: Word -> Word -> Bool #

extendedGCD :: Word -> Word -> (Word, Word, Word) #

Euclidean GaussianInteger # 
Instance details

Defined in Math.NumberTheory.Quadratic.GaussianIntegers

Euclidean EisensteinInteger # 
Instance details

Defined in Math.NumberTheory.Quadratic.EisensteinIntegers

Integral a => Euclidean (WrappedIntegral a) # 
Instance details

Defined in Math.NumberTheory.Euclidean

newtype WrappedIntegral a #

Wrapper around Integral, which has an Eucledian instance.

Constructors

WrappedIntegral 

Fields

Instances
Enum a => Enum (WrappedIntegral a) # 
Instance details

Defined in Math.NumberTheory.Euclidean

Eq a => Eq (WrappedIntegral a) # 
Instance details

Defined in Math.NumberTheory.Euclidean

Integral a => Integral (WrappedIntegral a) # 
Instance details

Defined in Math.NumberTheory.Euclidean

Num a => Num (WrappedIntegral a) # 
Instance details

Defined in Math.NumberTheory.Euclidean

Ord a => Ord (WrappedIntegral a) # 
Instance details

Defined in Math.NumberTheory.Euclidean

Real a => Real (WrappedIntegral a) # 
Instance details

Defined in Math.NumberTheory.Euclidean

Show a => Show (WrappedIntegral a) # 
Instance details

Defined in Math.NumberTheory.Euclidean

Integral a => Euclidean (WrappedIntegral a) # 
Instance details

Defined in Math.NumberTheory.Euclidean