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
instances #
Equations
- nat.comm_semiring = {add := nat.add, add_assoc := nat.add_assoc, zero := 0, zero_add := nat.zero_add, add_zero := nat.add_zero, nsmul := λ (m n : ℕ), m * n, nsmul_zero' := nat.zero_mul, nsmul_succ' := nat.comm_semiring._proof_1, add_comm := nat.add_comm, mul := nat.mul, left_distrib := nat.left_distrib, right_distrib := nat.right_distrib, zero_mul := nat.zero_mul, mul_zero := nat.mul_zero, mul_assoc := nat.mul_assoc, one := 1, one_mul := nat.one_mul, mul_one := nat.mul_one, npow := semiring.npow._default 1 nat.mul nat.one_mul nat.mul_one, npow_zero' := nat.comm_semiring._proof_2, npow_succ' := nat.comm_semiring._proof_3, mul_comm := nat.mul_comm}
Equations
- nat.linear_ordered_semiring = {add := comm_semiring.add nat.comm_semiring, add_assoc := _, zero := comm_semiring.zero nat.comm_semiring, zero_add := _, add_zero := _, nsmul := comm_semiring.nsmul nat.comm_semiring, nsmul_zero' := _, nsmul_succ' := _, add_comm := _, mul := comm_semiring.mul nat.comm_semiring, left_distrib := _, right_distrib := _, zero_mul := _, mul_zero := _, mul_assoc := _, one := comm_semiring.one nat.comm_semiring, one_mul := _, mul_one := _, npow := comm_semiring.npow nat.comm_semiring, npow_zero' := _, npow_succ' := _, add_left_cancel := nat.add_left_cancel, le := linear_order.le nat.linear_order, lt := nat.lt, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, add_le_add_left := nat.add_le_add_left, le_of_add_le_add_left := nat.le_of_add_le_add_left, zero_le_one := nat.linear_ordered_semiring._proof_1, mul_lt_mul_of_pos_left := nat.mul_lt_mul_of_pos_left, mul_lt_mul_of_pos_right := nat.mul_lt_mul_of_pos_right, le_total := _, decidable_le := linear_order.decidable_le nat.linear_order, decidable_eq := nat.decidable_eq, decidable_lt := linear_order.decidable_lt nat.linear_order, max := max nat.linear_order, max_def := _, min := min nat.linear_order, min_def := _, exists_pair_ne := nat.linear_ordered_semiring._proof_2}
Equations
- nat.linear_ordered_cancel_add_comm_monoid = {add := linear_ordered_semiring.add nat.linear_ordered_semiring, add_assoc := _, add_left_cancel := nat.add_left_cancel, zero := linear_ordered_semiring.zero nat.linear_ordered_semiring, zero_add := _, add_zero := _, nsmul := linear_ordered_semiring.nsmul nat.linear_ordered_semiring, nsmul_zero' := _, nsmul_succ' := _, add_comm := _, le := linear_ordered_semiring.le nat.linear_ordered_semiring, lt := linear_ordered_semiring.lt nat.linear_ordered_semiring, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, add_le_add_left := _, le_of_add_le_add_left := _, le_total := _, decidable_le := linear_ordered_semiring.decidable_le nat.linear_ordered_semiring, decidable_eq := linear_ordered_semiring.decidable_eq nat.linear_ordered_semiring, decidable_lt := linear_ordered_semiring.decidable_lt nat.linear_ordered_semiring, max := linear_ordered_semiring.max nat.linear_ordered_semiring, max_def := _, min := linear_ordered_semiring.min nat.linear_ordered_semiring, min_def := _}
Equations
- nat.linear_ordered_comm_monoid_with_zero = {le := linear_ordered_semiring.le nat.linear_ordered_semiring, lt := linear_ordered_semiring.lt nat.linear_ordered_semiring, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, le_total := _, decidable_le := linear_ordered_semiring.decidable_le nat.linear_ordered_semiring, decidable_eq := linear_ordered_semiring.decidable_eq nat.linear_ordered_semiring, decidable_lt := linear_ordered_semiring.decidable_lt nat.linear_ordered_semiring, max := linear_ordered_semiring.max nat.linear_ordered_semiring, max_def := _, min := linear_ordered_semiring.min nat.linear_ordered_semiring, min_def := _, mul := linear_ordered_semiring.mul nat.linear_ordered_semiring, mul_assoc := _, one := linear_ordered_semiring.one nat.linear_ordered_semiring, one_mul := _, mul_one := _, npow := linear_ordered_semiring.npow nat.linear_ordered_semiring, npow_zero' := _, npow_succ' := _, mul_comm := nat.linear_ordered_comm_monoid_with_zero._proof_1, mul_le_mul_left := nat.linear_ordered_comm_monoid_with_zero._proof_2, zero := linear_ordered_semiring.zero nat.linear_ordered_semiring, zero_mul := _, mul_zero := _, zero_le_one := _}
Equations
- nat.ordered_comm_semiring = {add := comm_semiring.add nat.comm_semiring, add_assoc := _, zero := comm_semiring.zero nat.comm_semiring, zero_add := _, add_zero := _, nsmul := comm_semiring.nsmul nat.comm_semiring, nsmul_zero' := _, nsmul_succ' := _, add_comm := _, mul := comm_semiring.mul nat.comm_semiring, left_distrib := _, right_distrib := _, zero_mul := _, mul_zero := _, mul_assoc := _, one := comm_semiring.one nat.comm_semiring, one_mul := _, mul_one := _, npow := comm_semiring.npow nat.comm_semiring, npow_zero' := _, npow_succ' := _, add_left_cancel := _, le := linear_ordered_semiring.le nat.linear_ordered_semiring, lt := linear_ordered_semiring.lt nat.linear_ordered_semiring, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, add_le_add_left := _, le_of_add_le_add_left := _, zero_le_one := _, mul_lt_mul_of_pos_left := _, mul_lt_mul_of_pos_right := _, mul_comm := _}
Extra instances to short-circuit type class resolution
Equations
Equations
Equations
Equations
Equations
Equations
Equations
- nat.order_bot = {bot := 0, bot_le := nat.zero_le}
Equations
- nat.canonically_ordered_comm_semiring = {add := ordered_add_comm_monoid.add infer_instance, add_assoc := nat.canonically_ordered_comm_semiring._proof_1, zero := ordered_add_comm_monoid.zero infer_instance, zero_add := nat.canonically_ordered_comm_semiring._proof_2, add_zero := nat.canonically_ordered_comm_semiring._proof_3, nsmul := ordered_add_comm_monoid.nsmul infer_instance, nsmul_zero' := nat.canonically_ordered_comm_semiring._proof_4, nsmul_succ' := nat.canonically_ordered_comm_semiring._proof_5, add_comm := nat.canonically_ordered_comm_semiring._proof_6, le := ordered_add_comm_monoid.le infer_instance, lt := ordered_add_comm_monoid.lt infer_instance, le_refl := nat.canonically_ordered_comm_semiring._proof_7, le_trans := nat.canonically_ordered_comm_semiring._proof_8, lt_iff_le_not_le := nat.canonically_ordered_comm_semiring._proof_9, le_antisymm := nat.canonically_ordered_comm_semiring._proof_10, add_le_add_left := nat.canonically_ordered_comm_semiring._proof_11, bot := order_bot.bot nat.order_bot, bot_le := _, le_iff_exists_add := nat.canonically_ordered_comm_semiring._proof_12, mul := linear_ordered_semiring.mul infer_instance, left_distrib := nat.canonically_ordered_comm_semiring._proof_13, right_distrib := nat.canonically_ordered_comm_semiring._proof_14, zero_mul := nat.canonically_ordered_comm_semiring._proof_15, mul_zero := nat.canonically_ordered_comm_semiring._proof_16, mul_assoc := nat.canonically_ordered_comm_semiring._proof_17, one := linear_ordered_semiring.one infer_instance, one_mul := nat.canonically_ordered_comm_semiring._proof_18, mul_one := nat.canonically_ordered_comm_semiring._proof_19, npow := linear_ordered_semiring.npow infer_instance, npow_zero' := nat.canonically_ordered_comm_semiring._proof_20, npow_succ' := nat.canonically_ordered_comm_semiring._proof_21, mul_comm := nat.canonically_ordered_comm_semiring._proof_22, eq_zero_or_eq_zero_of_mul_eq_zero := nat.canonically_ordered_comm_semiring._proof_23}
Equations
- nat.canonically_linear_ordered_add_monoid = {add := canonically_ordered_add_monoid.add infer_instance, add_assoc := nat.canonically_linear_ordered_add_monoid._proof_1, zero := canonically_ordered_add_monoid.zero infer_instance, zero_add := nat.canonically_linear_ordered_add_monoid._proof_2, add_zero := nat.canonically_linear_ordered_add_monoid._proof_3, nsmul := canonically_ordered_add_monoid.nsmul infer_instance, nsmul_zero' := nat.canonically_linear_ordered_add_monoid._proof_4, nsmul_succ' := nat.canonically_linear_ordered_add_monoid._proof_5, add_comm := nat.canonically_linear_ordered_add_monoid._proof_6, le := canonically_ordered_add_monoid.le infer_instance, lt := canonically_ordered_add_monoid.lt infer_instance, le_refl := nat.canonically_linear_ordered_add_monoid._proof_7, le_trans := nat.canonically_linear_ordered_add_monoid._proof_8, lt_iff_le_not_le := nat.canonically_linear_ordered_add_monoid._proof_9, le_antisymm := nat.canonically_linear_ordered_add_monoid._proof_10, add_le_add_left := nat.canonically_linear_ordered_add_monoid._proof_11, bot := canonically_ordered_add_monoid.bot infer_instance, bot_le := nat.canonically_linear_ordered_add_monoid._proof_12, le_iff_exists_add := nat.canonically_linear_ordered_add_monoid._proof_13, le_total := _, decidable_le := linear_order.decidable_le nat.linear_order, decidable_eq := linear_order.decidable_eq nat.linear_order, decidable_lt := linear_order.decidable_lt nat.linear_order, max := max nat.linear_order, max_def := _, min := min nat.linear_order, min_def := _}
Equations
- nat.subtype.semilattice_sup s = {sup := lattice.sup linear_order.to_lattice, le := linear_order.le (subtype.linear_order s), lt := linear_order.lt (subtype.linear_order s), le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, le_sup_left := _, le_sup_right := _, sup_le := _}
Equations
- nat.cancel_comm_monoid_with_zero = {mul := comm_monoid_with_zero.mul infer_instance, mul_assoc := nat.cancel_comm_monoid_with_zero._proof_1, one := comm_monoid_with_zero.one infer_instance, one_mul := nat.cancel_comm_monoid_with_zero._proof_2, mul_one := nat.cancel_comm_monoid_with_zero._proof_3, npow := comm_monoid_with_zero.npow infer_instance, npow_zero' := nat.cancel_comm_monoid_with_zero._proof_4, npow_succ' := nat.cancel_comm_monoid_with_zero._proof_5, mul_comm := nat.cancel_comm_monoid_with_zero._proof_6, zero := comm_monoid_with_zero.zero infer_instance, zero_mul := nat.cancel_comm_monoid_with_zero._proof_7, mul_zero := nat.cancel_comm_monoid_with_zero._proof_8, mul_left_cancel_of_ne_zero := nat.cancel_comm_monoid_with_zero._proof_9, mul_right_cancel_of_ne_zero := nat.cancel_comm_monoid_with_zero._proof_10}
Inject some simple facts into the type class system.
This fact
should not be confused with the factorial function nat.fact
!
The units of the natural numbers as a monoid
and add_monoid
#
Equations
- nat.unique_units = {to_inhabited := {default := 1}, uniq := nat.units_eq_one}
Equations
- nat.unique_add_units = {to_inhabited := {default := 0}, uniq := nat.add_units_eq_zero}
Equalities and inequalities involving zero and one #
succ
#
add
#
pred
#
sub
#
Most lemmas come from the has_ordered_sub
instance on ℕ
.
Equations
- nat.has_ordered_sub = {tsub_le_iff_right := nat.has_ordered_sub._proof_1}
A version of nat.sub_succ
in the form _ - 1
instead of nat.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 le_rec_on'
.
Equations
- nat.le_rec_on H next x = _.by_cases (λ (h : n ≤ m), next (nat.le_rec_on h next x)) (λ (h : n = m + 1), h.rec_on x)
- nat.le_rec_on H next x = _.rec_on x
Recursion principle based on <
.
Equations
- nat.strong_rec' H n = H n (λ (m : ℕ) (hm : m < n), nat.strong_rec' H m)
Recursion principle based on <
applied to some natural number.
Equations
- n.strong_rec_on' h = nat.strong_rec' h n
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.decreasing_induction h mn hP = nat.le_rec_on mn (λ (k : ℕ) (ih : P k → P m) (hsk : P (k + 1)), ih (h k hsk)) (λ (h : P m), h) hP
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.le_rec_on' H next x = _.by_cases (λ (h : n ≤ m), next h (nat.le_rec_on' h next x)) (λ (h : n = m + 1), h.rec_on x)
- nat.le_rec_on' H next x = _.rec_on x
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
- nat.decreasing_induction' h mn hP = nat.le_rec_on' mn (λ (n : ℕ) (mn : m ≤ n) (ih : (Π (k : ℕ), k < n → m ≤ k → P (k + 1) → P k) → P n → P m) (h : Π (k : ℕ), k < n + 1 → m ≤ k → P (k + 1) → P k) (hP : P (n + 1)), ih (λ (k : ℕ) (hk : k < n), h k _) (h n _ mn hP)) (λ (h : Π (k : ℕ), k < m → m ≤ k → P (k + 1) → P k) (hP : P m), hP) h hP
div
#
A version of nat.div_lt_self
using successors, rather than additional hypotheses.
mod
, dvd
#
dvd
is injective in the left argument
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.find_greatest P (n + 1) = ite (P (n + 1)) (n + 1) (nat.find_greatest P n)
- nat.find_greatest P 0 = 0
bodd_div2
and bodd
#
decidability of predicates #
Equations
- n.decidable_ball_lt P = nat.rec (λ (P : Π (k : ℕ), k < 0 → Prop) (H : Π (n : ℕ) (h : n < 0), decidable (P n h)), is_true _) (λ (n : ℕ) (IH : Π (P : Π (k : ℕ), k < n → Prop) [H : Π (n_1 : ℕ) (h : n_1 < n), decidable (P n_1 h)], decidable (∀ (n_1 : ℕ) (h : n_1 < n), P n_1 h)) (P : Π (k : ℕ), k < n.succ → Prop) (H : Π (n_1 : ℕ) (h : n_1 < n.succ), decidable (P n_1 h)), (IH (λ (k : ℕ) (h : k < n), P k _)).cases_on (λ (h : ¬∀ (n_1 : ℕ) (h : n_1 < n), (λ (k : ℕ) (h : k < n), P k _) n_1 h), is_false _) (λ (h : ∀ (n_1 : ℕ) (h : n_1 < n), (λ (k : ℕ) (h : k < n), P k _) n_1 h), dite (P n _) (λ (p : P n _), is_true _) (λ (p : ¬P n _), is_false _))) n P
Equations
- nat.decidable_forall_fin P = decidable_of_iff (∀ (k : ℕ) (h : k < n), P ⟨k, h⟩) _
Equations
- lo.decidable_lo_hi hi P = decidable_of_iff (∀ (x : ℕ), x < hi - lo → P (lo + x)) _
Equations
- lo.decidable_lo_hi_le hi P = decidable_of_iff (∀ (x : ℕ), lo ≤ x → x < hi + 1 → P x) _
Equations
- nat.decidable_exists_lt (n + 1) = decidable_of_decidable_of_iff or.decidable _
- nat.decidable_exists_lt 0 = is_false nat.decidable_exists_lt._main._proof_1
Equations
- nat.decidable_exists_le = λ (n : ℕ), decidable_of_iff (∃ (m : ℕ), m < n + 1 ∧ P m) _