IdrisDoc: Data.Nat.DivMod

# Data.Nat.DivMod

Euclidean division using primitive recursion/induction.

data DivMod : (dividend : Nat) -> (divisor : Nat) -> Type

  The result of euclidean division of natural numbers

  dividend

    the dividend

  divisor

    the divisor

  MkDivMod : (quotient : Nat) -> (remainder : Nat) -> (remainderSmall : LT remainder divisor) -> DivMod (remainder + quotient * divisor) divisor

    The result of division. The order of operations and operands in the
    result type was picked to not require any explicit proofs.

    divisor

      the divisor

    quotient

      the quotient

    remainder

      the remainder

    remainderSmall

      proof that the remainder is in the range
      `[0 .. divisor - 1]`

SmDivModn : (hyp : DivMod m n) -> DivMod (S m) n

  The inductive step, taking a division of `m` to a division of `S m`

  n

    the divisor

  m

    the dividend in the inductive hypothesis

  hyp

    the inductive hypothesis

ZDivModSn : DivMod 0 (S n)

  The base case, dividing zero by a successor.

  n

    the predecessor of the divisor

divMod : (dividend : Nat) -> (predDivisor : Nat) -> DivMod dividend (S predDivisor)

  Euclidean division. Note that this takes the predecessor of the divisor to
  avoid division by zero.

  dividend

    the dividend

  predDivisor

    the predecessor of the desired divisor

stepLT : (mLten : LTE m n) -> Either (m = n) (LT m n)

  Given a number less than or equal to a bound, is it equal, or less?

  n

    the greater or equal number

  m

    the lesser or equal number

  mLten

    proof that `m` is less than or equal to `n`