Basic operations on the natural numbers #
This file contains:
- instances on the natural numbers
- some basic lemmas about natural numbers
- extra recursors:
le_rec_on,le_induction: recursion and induction principles starting at non-zero numbersdecreasing_induction: recursion growing downwardsle_rec_on',decreasing_induction': versions with slightly weaker assumptionsstrong_rec': recursion based on strong inequalities
- decidability instances on predicates about the natural numbers
Many theorems that used to live in this file have been moved to Data.Nat.Order,
so that this file requires fewer imports.
For each section here there is a corresponding section in that file with additional results.
It may be possible to move some of these results here, by tweaking their proofs.
instances #
Equations
Extra instances to short-circuit type class resolution and ensure computability
Equations
- Nat.addCommSemigroup = inferInstance
Equations
- Nat.cancelCommMonoidWithZero = let src := inferInstance; CancelCommMonoidWithZero.mk
Recursion and forall/exists #
succ #
add #
pred #
mul #
Recursion and induction principles #
This section is here due to dependencies -- the lemmas here require some of the lemmas proved above, and some of the results in later sections depend on the definitions in this section.
Recursion starting at a non-zero number: given a map C k → C (k+1) for each k,
there is a map from C n to each C m, n ≤ m. For a version where the assumption is only made
when k ≥ n, see leRecOn.
Equations
- Nat.leRecOn H x x_1 = Eq.recOn (_ : n = 0) x_1
- Nat.leRecOn H x x_1 = Or.by_cases (_ : n ≤ m ∨ n = Nat.succ m) (fun h => x m (Nat.leRecOn h x x_1)) fun h => Eq.recOn h x_1
Instances For
Recursion principle based on <.
Equations
- Nat.strongRec' H x = H x fun m x => Nat.strongRec' H m
Instances For
Recursion principle based on < applied to some natural number.
Equations
- Nat.strongRecOn' n h = Nat.strongRec' h n
Instances For
Induction principle starting at a non-zero number. For maps to a Sort* see le_rec_on.
To use in an induction proof, the syntax is induction n, hn using Nat.le_induction (or the same
for induction').
Decreasing induction: if P (k+1) implies P k, then P n implies P m for all m ≤ n.
Also works for functions to Sort*. For a version assuming only the assumption for k < n, see
decreasing_induction'.
Equations
- Nat.decreasingInduction h mn hP = Nat.leRecOn (fun x => P x → P m) m n mn (fun {k} ih hsk => ih (h k hsk)) (fun h => h) hP
Instances For
Given P : ℕ → ℕ → Sort*, if for all a b : ℕ we can extend P from the rectangle
strictly below (a,b) to P a b, then we have P n m for all n m : ℕ.
Note that for non-Prop output it is preferable to use the equation compiler directly if possible,
since this produces equation lemmas.
Equations
- Nat.strongSubRecursion H x x = H x x fun x y x_1 x_2 => Nat.strongSubRecursion H x y
Instances For
Given P : ℕ → ℕ → Sort*, if we have P i 0 and P 0 i for all i : ℕ,
and for any x y : ℕ we can extend P from (x,y+1) and (x+1,y) to (x+1,y+1)
then we have P n m for all n m : ℕ.
Note that for non-Prop output it is preferable to use the equation compiler directly if possible,
since this produces equation lemmas.
Equations
- Nat.pincerRecursion Ha0 H0b H x 0 = Ha0 x
- Nat.pincerRecursion Ha0 H0b H 0 x = H0b x
- Nat.pincerRecursion Ha0 H0b H (Nat.succ a) (Nat.succ b) = H a b (Nat.pincerRecursion Ha0 H0b H a (Nat.succ b)) (Nat.pincerRecursion Ha0 H0b H (Nat.succ a) b)
Instances For
Recursion starting at a non-zero number: given a map C k → C (k+1) for each k ≥ n,
there is a map from C n to each C m, n ≤ m.
Equations
- Nat.leRecOn' H x x_1 = Eq.recOn (_ : n = 0) x_1
- Nat.leRecOn' H x x_1 = Or.by_cases (_ : n ≤ m ∨ n = Nat.succ m) (fun h => x m h (Nat.leRecOn' h x x_1)) fun h => Eq.recOn h x_1
Instances For
Decreasing induction: if P (k+1) implies P k for all m ≤ k < n, then P n implies P m.
Also works for functions to Sort*. Weakens the assumptions of decreasing_induction.
Equations
- One or more equations did not get rendered due to their size.
Instances For
div #
A version of Nat.div_lt_self using successors, rather than additional hypotheses.
mod, dvd #
find #
find_greatest #
find_greatest P b is the largest i ≤ bound such that P i holds, or 0 if no such i
exists
Equations
- Nat.findGreatest P 0 = 0
- Nat.findGreatest P (Nat.succ n) = if P (n + 1) then n + 1 else Nat.findGreatest P n
Instances For
decidability of predicates #
Equations
- Nat.decidableForallFin P = decidable_of_iff ((k : ℕ) → (h : k < n) → P { val := k, isLt := h }) (_ : ((k : ℕ) → (h : k < n) → P { val := k, isLt := h }) ↔ (i : Fin n) → P i)