| Safe Haskell | Safe-Inferred | 
|---|---|
| Language | Haskell98 | 
Algebra.IntegralDomain
Contents
Synopsis
- class C a => C a
 - div, mod :: C a => a -> a -> a
 - div, mod :: C a => a -> a -> a
 - divMod :: C a => a -> a -> (a, a)
 - divModZero :: (C a, C a) => a -> a -> (a, a)
 - divides :: (C a, C a) => a -> a -> Bool
 - sameResidueClass :: (C a, C a) => a -> a -> a -> Bool
 - divChecked :: (C a, C a) => a -> a -> a
 - safeDiv :: (C a, C a) => a -> a -> a
 - even :: (C a, C a) => a -> Bool
 - odd :: (C a, C a) => a -> Bool
 - divUp :: C a => a -> a -> a
 - roundDown :: C a => a -> a -> a
 - roundUp :: C a => a -> a -> a
 - decomposeVarPositional :: (C a, C a) => [a] -> a -> [a]
 - decomposeVarPositionalInf :: C a => [a] -> a -> [a]
 - propInverse :: (Eq a, C a, C a) => a -> a -> Property
 - propMultipleDiv :: (Eq a, C a, C a) => a -> a -> Property
 - propMultipleMod :: (Eq a, C a, C a) => a -> a -> Property
 - propProjectAddition :: (Eq a, C a, C a) => a -> a -> a -> Property
 - propProjectMultiplication :: (Eq a, C a, C a) => a -> a -> a -> Property
 - propUniqueRepresentative :: (Eq a, C a, C a) => a -> a -> a -> Property
 - propZeroRepresentative :: (Eq a, C a, C a) => a -> Property
 - propSameResidueClass :: (Eq a, C a, C a) => a -> a -> a -> Property
 
Class
IntegralDomain corresponds to a commutative ring,
where a  picks a canonical element
of the equivalence class of mod ba in the ideal generated by b.
div and mod satisfy the laws
                        a * b === b * a
(a `div` b) * b + (a `mod` b) === a
              (a+k*b) `mod` b === a `mod` b
                    0 `mod` b === 0Typical examples of IntegralDomain include integers and
polynomials over a field.
Note that for a field, there is a canonical instance
defined by the above rules; e.g.,
instance IntegralDomain.C Rational where
    divMod a b =
       if isZero b
         then (undefined,a)
         else (a\/b,0)It shall be noted, that div, mod, divMod have a parameter order
which is unfortunate for partial application.
But it is adapted to mathematical conventions,
where the operators are used in infix notation.
Instances
| C Int Source # | |
| C Int8 Source # | |
| C Int16 Source # | |
| C Int32 Source # | |
| C Int64 Source # | |
| C Integer Source # | |
| C Word Source # | |
| C Word8 Source # | |
| C Word16 Source # | |
| C Word32 Source # | |
| C Word64 Source # | |
| C T Source # | |
| (Ord a, C a) => C (T a) Source # | |
| Integral a => C (T a) Source # | |
| (Ord a, C a, C a) => C (T a) Source # | 
  | 
| (C a, C a) => C (T a) Source # | |
| (C a, C a) => C (T a) Source # | The   | 
| C a => C (T a) Source # | |
| C a => C (T a) Source # | |
divMod :: C a => a -> a -> (a, a) Source #
\n (QC.NonZero m) -> let (q,r) = divMod n m in n == (q*m+r :: Integer)
Derived functions
divModZero :: (C a, C a) => a -> a -> (a, a) Source #
Allows division by zero. If the divisor is zero, then the dividend is returned as remainder.
divChecked :: (C a, C a) => a -> a -> a Source #
Returns the result of the division, if divisible. Otherwise undefined.
safeDiv :: (C a, C a) => a -> a -> a Source #
Deprecated: use divChecked instead
Returns the result of the division, if divisible. Otherwise undefined.
divUp :: C a => a -> a -> a Source #
divUp n m is similar to div
but it rounds up the quotient,
such that divUp n m * m = roundUp n m.
roundDown :: C a => a -> a -> a Source #
roundDown n m rounds n down to the next multiple of m.
That is, roundDown n m is the greatest multiple of m
that is at most n.
The parameter order is consistent with div and friends,
but maybe not useful for partial application.
\n (QC.NonZero m) -> div n m * m == (roundDown n m :: Integer)
roundUp :: C a => a -> a -> a Source #
roundUp n m rounds n up to the next multiple of m.
That is, roundUp n m is the greatest multiple of m
that is at most n.
\n (QC.NonZero m) -> divUp n m * m == (roundUp n m :: Integer)
\n (QC.Positive m) -> let x = roundDown n m in n-m < x && x <= (n :: Integer)
\n (QC.NonZero m) -> - roundDown n m == (roundUp (-n) m :: Integer)
Algorithms
decomposeVarPositional :: (C a, C a) => [a] -> a -> [a] Source #
decomposeVarPositional [b0,b1,b2,...] x
decomposes x into a positional representation with mixed bases
x0 + b0*(x1 + b1*(x2 + b2*x3))
E.g. decomposeVarPositional (repeat 10) 123 == [3,2,1]
decomposeVarPositionalInf :: C a => [a] -> a -> [a] Source #