IdrisDoc: Data.Nat.DivMod.IteratedSubtraction

# Data.Nat.DivMod.IteratedSubtraction

Division of natural numbers, by iterated subtraction using well-founded
recursion

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

  The result of division on natural numbers.

  dividend

    the dividend

  divisor

    the divisor

  DivModRes : (quotient : Nat) -> (remainder : Fin divisor) -> (ok : dividend = finToNat remainder + quotient * divisor) -> DivMod dividend divisor

    The result of division, with a quotient and a remainder.

    dividend

      the dividend

    divisor

      the divisor

    quotient

      the quotient

    remainder

      the remainder (bounded by the divisor)

    ok

      the fact that this is, in fact, a result of division

data LT' : (n : Nat) -> (m : Nat) -> Type

  A strict less-than relation on `Nat`.

  n

    the smaller number

  m

    the larger number

  LTSucc : LT' n (S n)

    n < 1 + n

  LTStep : LT' n m -> LT' n (S m)

    n < m implies that n < m + 1

LTZeroLeast : LT' 0 (S n)

  Zero is less than any non-zero number.

divMod : (dividend : Nat) -> (divisor : Nat) -> {auto nonzero : So (not (decAsBool (decEq divisor 0)))} -> DivMod dividend divisor

  Division and modulus on `Nat`, inspired by the definition in the
  Agda standard library.

  This uses well-founded recursion on `LT'`.

  dividend

    the dividend

  divisor

    the divisor

  nonzero

    division by zero is nonsense

ltSuccSucc : LT' n m -> LT' (S n) (S m)

  If n < m, then 1 + n < 1 + m

ltToLTE : LT' n m -> LTE (S n) m

  Convert from LT' to LTE

lteToLt' : LTE (S n) m -> LT' n m

  If n + 1 < m, then n < m

minusLT' : (x : Nat) -> (y : Nat) -> LT' (minus x y) (S x)

  Subtraction gives a result that is actually smaller.