Basic operations on the natural numbers #
This file contains:
- some basic lemmas about natural numbers
- extra recursors:
leRecOn
,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
This file should not depend on anything defined in Mathlib (except for notation), so that it can be upstreamed to Batteries easily.
See note [foundational algebra order theory].
succ
, pred
#
Alias of the forward direction of Nat.le_succ_iff
.
pred
#
add
#
Alias of Nat.add_right_cancel_iff
.
Alias of Nat.add_left_cancel_iff
.
sub
#
A version of Nat.sub_succ
in the form _ - 1
instead of Nat.pred _
.
mul
#
Alias of Nat.mul_sub_left_distrib
.
Alias of Nat.mul_sub_right_distrib
.
div
#
A version of Nat.div_lt_self
using successors, rather than additional hypotheses.
pow
#
TODO #
- Rename
Nat.pow_le_pow_of_le_left
toNat.pow_le_pow_left
, protect it, remove the alias - Rename
Nat.pow_le_pow_of_le_right
toNat.pow_le_pow_right
, protect it, remove the alias
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 ≥ n
,
there is a map from C n
to each C m
, n ≤ m
.
This is a version of Nat.le.rec
that works for Sort u
.
Similarly to Nat.le.rec
, it can be used as
induction hle using Nat.leRec with
| refl => sorry
| le_succ_of_le hle ih => sorry
Equations
- One or more equations did not get rendered due to their size.
Instances For
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 Nat.leRec
.
Equations
- Nat.leRecOn h of_succ self = Nat.leRec self (fun (x : ℕ) (x_1 : n ≤ x) => of_succ) h
Instances For
Recursion principle based on <
.
Equations
- Nat.strongRec' H x✝ = H x✝ fun (m : ℕ) (x : m < x✝) => Nat.strongRec' H m
Instances For
Recursion principle based on <
applied to some natural number.
Equations
- n.strongRecOn' h = Nat.strongRec' h n
Instances For
Induction principle starting at a non-zero number.
To use in an induction proof, the syntax is induction n, hn using Nat.le_induction
(or the same
for induction'
).
This is an alias of Nat.leRec
, specialized to Prop
.
Induction principle deriving the next case from the two previous ones.
Equations
- Nat.twoStepInduction zero one more 0 = zero
- Nat.twoStepInduction zero one more 1 = one
- Nat.twoStepInduction zero one more n.succ.succ = more n (Nat.twoStepInduction zero one more n) (Nat.twoStepInduction zero one more (n + 1))
Instances For
Decreasing induction: if P (k+1)
implies P k
for all k < n
, then P n
implies P m
for
all m ≤ n
.
Also works for functions to Sort*
.
For a version also assuming m ≤ k
, see Nat.decreasingInduction'
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given P : ℕ → ℕ → Sort*
, if for all m n : ℕ
we can extend P
from the rectangle
strictly below (m, n)
to P m n
, 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 < x✝¹) (x_2 : y < x✝) => Nat.strongSubRecursion H x y
Instances For
Given P : ℕ → ℕ → Sort*
, if we have P m 0
and P 0 n
for all m n : ℕ
, and for any
m n : ℕ
we can extend P
from (m, n + 1)
and (m + 1, n)
to (m + 1, n + 1)
then we have
P m n
for all m n : ℕ
.
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 n.succ n_1.succ = H n n_1 (Nat.pincerRecursion Ha0 H0b H n n_1.succ) (Nat.pincerRecursion Ha0 H0b H n.succ n_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 Nat.decreasingInduction
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a predicate on two naturals P : ℕ → ℕ → Prop
, P a b
is true for all a < b
if
P (a + 1) (a + 1)
is true for all a
, P 0 (b + 1)
is true for all b
and for all
a < b
, P (a + 1) b
is true and P a (b + 1)
is true implies P (a + 1) (b + 1)
is true.
mod
, dvd
#
special case of mul_dvd_mul_iff_left
for ℕ
.
Duplicated here to keep simple imports for this file.
special case of mul_dvd_mul_iff_right
for ℕ
.
Duplicated here to keep simple imports for this file.
Decidability of predicates #
Equations
- lo.decidableLoHi hi P = decidable_of_iff (∀ (x : ℕ), x < hi - lo → P (lo + x)) ⋯
Equations
- lo.decidableLoHiLe hi P = decidable_of_iff (∀ (x : ℕ), lo ≤ x → x < hi + 1 → P x) ⋯