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 downwardsstrong_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, add_comm := nat.add_comm, mul := nat.mul, mul_assoc := nat.mul_assoc, one := 1, one_mul := nat.one_mul, mul_one := nat.mul_one, zero_mul := nat.zero_mul, mul_zero := nat.mul_zero, left_distrib := nat.left_distrib, right_distrib := nat.right_distrib, mul_comm := nat.mul_comm}
Equations
- nat.decidable_linear_ordered_semiring = {add := comm_semiring.add nat.comm_semiring, add_assoc := _, zero := comm_semiring.zero nat.comm_semiring, zero_add := _, add_zero := _, add_comm := _, mul := comm_semiring.mul nat.comm_semiring, mul_assoc := _, one := comm_semiring.one nat.comm_semiring, one_mul := _, mul_one := _, zero_mul := _, mul_zero := _, left_distrib := _, right_distrib := _, add_left_cancel := nat.add_left_cancel, add_right_cancel := nat.add_right_cancel, le := decidable_linear_order.le nat.decidable_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, 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 := _, zero_lt_one := nat.decidable_linear_ordered_semiring._proof_1, decidable_le := decidable_linear_order.decidable_le nat.decidable_linear_order, decidable_eq := nat.decidable_eq, decidable_lt := decidable_linear_order.decidable_lt nat.decidable_linear_order}
Equations
- nat.decidable_linear_ordered_cancel_add_comm_monoid = {add := decidable_linear_ordered_semiring.add nat.decidable_linear_ordered_semiring, add_assoc := _, zero := decidable_linear_ordered_semiring.zero nat.decidable_linear_ordered_semiring, zero_add := _, add_zero := _, add_comm := _, add_left_cancel := nat.add_left_cancel, add_right_cancel := _, le := decidable_linear_ordered_semiring.le nat.decidable_linear_ordered_semiring, lt := decidable_linear_ordered_semiring.lt nat.decidable_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 := decidable_linear_ordered_semiring.decidable_le nat.decidable_linear_ordered_semiring, decidable_eq := decidable_linear_ordered_semiring.decidable_eq nat.decidable_linear_ordered_semiring, decidable_lt := decidable_linear_ordered_semiring.decidable_lt nat.decidable_linear_ordered_semiring}
Extra instances to short-circuit type class resolution
Equations
Equations
Equations
Equations
Equations
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, add_comm := nat.canonically_ordered_comm_semiring._proof_4, le := ordered_add_comm_monoid.le infer_instance, lt := ordered_add_comm_monoid.lt infer_instance, le_refl := nat.canonically_ordered_comm_semiring._proof_5, le_trans := nat.canonically_ordered_comm_semiring._proof_6, lt_iff_le_not_le := nat.canonically_ordered_comm_semiring._proof_7, le_antisymm := nat.canonically_ordered_comm_semiring._proof_8, add_le_add_left := nat.canonically_ordered_comm_semiring._proof_9, lt_of_add_lt_add_left := nat.canonically_ordered_comm_semiring._proof_10, bot := 0, bot_le := nat.zero_le, le_iff_exists_add := nat.canonically_ordered_comm_semiring._proof_11, mul := linear_ordered_semiring.mul infer_instance, mul_assoc := nat.canonically_ordered_comm_semiring._proof_12, one := linear_ordered_semiring.one infer_instance, one_mul := nat.canonically_ordered_comm_semiring._proof_13, mul_one := 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, left_distrib := nat.canonically_ordered_comm_semiring._proof_17, right_distrib := nat.canonically_ordered_comm_semiring._proof_18, mul_comm := nat.canonically_ordered_comm_semiring._proof_19, exists_pair_ne := _, eq_zero_or_eq_zero_of_mul_eq_zero := nat.canonically_ordered_comm_semiring._proof_20}
Equations
- nat.subtype.semilattice_sup_bot s = {bot := ⟨nat.find _, _⟩, 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 := _, bot_le := _, sup := lattice.sup lattice_of_decidable_linear_order, le_sup_left := _, le_sup_right := _, sup_le := _}
Equations
- nat.comm_cancel_monoid_with_zero = {mul := comm_monoid_with_zero.mul infer_instance, mul_assoc := nat.comm_cancel_monoid_with_zero._proof_1, one := comm_monoid_with_zero.one infer_instance, one_mul := nat.comm_cancel_monoid_with_zero._proof_2, mul_one := nat.comm_cancel_monoid_with_zero._proof_3, mul_comm := nat.comm_cancel_monoid_with_zero._proof_4, zero := comm_monoid_with_zero.zero infer_instance, zero_mul := nat.comm_cancel_monoid_with_zero._proof_5, mul_zero := nat.comm_cancel_monoid_with_zero._proof_6, mul_left_cancel_of_ne_zero := nat.comm_cancel_monoid_with_zero._proof_7, mul_right_cancel_of_ne_zero := nat.comm_cancel_monoid_with_zero._proof_8}
Inject some simple facts into the type class system.
This fact
should not be confused with the factorial function nat.fact
!
Recursion and set.range
The units of the natural numbers as a monoid
and add_monoid
Equalities and inequalities involving zero and one
succ
add
pred
sub
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
.
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*
.
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
div
A version of nat.div_lt_self
using successors, rather than additional hypotheses.
mod
, dvd
pow
pow
and 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.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
shiftl
and shiftr
size
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) _