Division of natural numbers, discarding the remainder. Division by 0 returns 0. Usually accessed
via the / operator.
This operation is sometimes called “floor division.”
This function is overridden at runtime with an efficient implementation. This definition is the logical model.
Examples:
21 / 3 = 721 / 5 = 40 / 22 = 05 / 0 = 0
Equations
- x.div y = if hy : 0 < y then Nat.div.go y hy (x + 1) x ⋯ else 0
Instances For
Equations
- Nat.div.go y hy 0 x hfuel_2 = ⋯.elim
- Nat.div.go y hy fuel_2.succ x hfuel_2 = if h : y ≤ x then Nat.div.go y hy fuel_2 (x - y) ⋯ + 1 else 0
Instances For
An induction principle customized for reasoning about the recursion pattern of natural number division by iterated subtraction.
Equations
- Nat.div.inductionOn x y ind base = if h : 0 < y ∧ y ≤ x then ind x y h (Nat.div.inductionOn (x - y) y ind base) else base x y h
Instances For
Division of two divisible natural numbers. Division by 0 returns 0.
This operation uses an optimized implementation, specialized for two divisible natural numbers.
This function is overridden at runtime with an efficient implementation. This definition is the logical model.
Examples:
Nat.divExact 21 3 (by decide) = 7Nat.divExact 0 22 (by decide) = 0Nat.divExact 0 0 (by decide) = 0
Instances For
The modulo operator, which computes the remainder when dividing one natural number by another.
Usually accessed via the % operator. When the divisor is 0, the result is the dividend rather
than an error.
This is the core implementation of Nat.mod. It computes the correct result for any two closed
natural numbers, but it does not have some convenient definitional
reductions when the Nats contain free variables. The wrapper
Nat.mod handles those cases specially and then calls Nat.modCore.
This function is overridden at runtime with an efficient implementation. This definition is the logical model.
Equations
- x.modCore y = if hy : 0 < y then Nat.modCore.go y hy (x + 1) x ⋯ else x
Instances For
Equations
- Nat.modCore.go y hy 0 x hfuel_2 = ⋯.elim
- Nat.modCore.go y hy fuel_2.succ x hfuel_2 = if h : y ≤ x then Nat.modCore.go y hy fuel_2 (x - y) ⋯ else x
Instances For
The modulo operator, which computes the remainder when dividing one natural number by another.
Usually accessed via the % operator. When the divisor is 0, the result is the dividend rather
than an error.
Nat.mod is a wrapper around Nat.modCore that special-cases two situations, giving better
definitional reductions:
Nat.mod 0 mshould reduce tom, for all termsm : Nat.Nat.mod n (m + n + 1)should reduce tonfor concreteNatliteralsn.
These reductions help Fin n literals work well, because the OfNat instance for Fin uses
Nat.mod. In particular, (0 : Fin (n + 1)).val should reduce definitionally to 0. Nat.modCore
can handle all numbers, but its definitional reductions are not as convenient.
This function is overridden at runtime with an efficient implementation. This definition is the logical model.
Examples:
7 % 2 = 19 % 3 = 05 % 7 = 55 % 0 = 5show ∀ (n : Nat), 0 % n = 0 from fun _ => rflshow ∀ (m : Nat), 5 % (m + 6) = 5 from fun _ => rfl
Instances For
An induction principle customized for reasoning about the recursion pattern of Nat.mod.
Equations
- Nat.mod.inductionOn x y ind base = Nat.div.inductionOn x y ind base