fact stringlengths 6 3.84k | type stringclasses 11 values | library stringclasses 32 values | imports listlengths 1 14 | filename stringlengths 20 95 | symbolic_name stringlengths 1 90 | docstring stringlengths 7 20k ⌀ |
|---|---|---|---|---|---|---|
exists_card_fiber_lt_of_card_lt_nsmul (hb : ↑(card α) < card β • b) :
∃ y : β, #{x | f x = y} < b :=
let ⟨y, _, h⟩ := Finset.exists_card_fiber_lt_of_card_lt_nsmul (f := f) hb
⟨y, h⟩ | theorem | Combinatorics | [
"Mathlib.Algebra.Module.BigOperators",
"Mathlib.Algebra.Order.Ring.Nat",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Order.Preorder.Finite"
] | Mathlib/Combinatorics/Pigeonhole.lean | exists_card_fiber_lt_of_card_lt_nsmul | The strong pigeonhole principle for finitely many pigeons and pigeonholes. There is a pigeonhole
with at most as many pigeons as the floor of the average number of pigeons across all pigeonholes. |
exists_card_fiber_lt_of_card_lt_mul (hn : card α < card β * n) :
∃ y : β, #{x | f x = y} < n :=
exists_card_fiber_lt_of_card_lt_nsmul _ hn | theorem | Combinatorics | [
"Mathlib.Algebra.Module.BigOperators",
"Mathlib.Algebra.Order.Ring.Nat",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Order.Preorder.Finite"
] | Mathlib/Combinatorics/Pigeonhole.lean | exists_card_fiber_lt_of_card_lt_mul | The strong pigeonhole principle for finitely many pigeons and pigeonholes.
There is a pigeonhole with at most as many pigeons as
the floor of the average number of pigeons across all pigeonholes.
("The minimum is at most the mean" specialized to integers.)
More formally, given a function `f` between finite types `α` and `β` and a number `n` such that
`card α < card β * n`, there exists an element `y : β` such that its preimage has less than `n`
elements. |
exists_le_card_fiber_of_nsmul_le_card [Nonempty β] (hb : card β • b ≤ card α) :
∃ y : β, b ≤ #{x | f x = y} :=
let ⟨y, _, h⟩ :=
exists_le_card_fiber_of_nsmul_le_card_of_maps_to (fun _ _ => mem_univ _) univ_nonempty hb
⟨y, h⟩ | theorem | Combinatorics | [
"Mathlib.Algebra.Module.BigOperators",
"Mathlib.Algebra.Order.Ring.Nat",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Order.Preorder.Finite"
] | Mathlib/Combinatorics/Pigeonhole.lean | exists_le_card_fiber_of_nsmul_le_card | The strong pigeonhole principle for finitely many pigeons and pigeonholes. Given a function `f`
between finite types `α` and `β` and a number `b` such that `card β • b ≤ card α`, there exists an
element `y : β` such that its preimage has at least `b` elements.
See also `Fintype.exists_lt_card_fiber_of_nsmul_lt_card` for a stronger statement. |
exists_le_card_fiber_of_mul_le_card [Nonempty β] (hn : card β * n ≤ card α) :
∃ y : β, n ≤ #{x | f x = y} :=
exists_le_card_fiber_of_nsmul_le_card _ hn | theorem | Combinatorics | [
"Mathlib.Algebra.Module.BigOperators",
"Mathlib.Algebra.Order.Ring.Nat",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Order.Preorder.Finite"
] | Mathlib/Combinatorics/Pigeonhole.lean | exists_le_card_fiber_of_mul_le_card | The strong pigeonhole principle for finitely many pigeons and pigeonholes. Given a function `f`
between finite types `α` and `β` and a number `n` such that `card β * n ≤ card α`, there exists an
element `y : β` such that its preimage has at least `n` elements. See also
`Fintype.exists_lt_card_fiber_of_mul_lt_card` for a stronger statement. |
exists_card_fiber_le_of_card_le_nsmul [Nonempty β] (hb : ↑(card α) ≤ card β • b) :
∃ y : β, #{x | f x = y} ≤ b :=
let ⟨y, _, h⟩ := Finset.exists_card_fiber_le_of_card_le_nsmul univ_nonempty hb
⟨y, h⟩ | theorem | Combinatorics | [
"Mathlib.Algebra.Module.BigOperators",
"Mathlib.Algebra.Order.Ring.Nat",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Order.Preorder.Finite"
] | Mathlib/Combinatorics/Pigeonhole.lean | exists_card_fiber_le_of_card_le_nsmul | The strong pigeonhole principle for finitely many pigeons and pigeonholes. Given a function `f`
between finite types `α` and `β` and a number `b` such that `card α ≤ card β • b`, there exists an
element `y : β` such that its preimage has at most `b` elements.
See also `Fintype.exists_card_fiber_lt_of_card_lt_nsmul` for a stronger statement. |
exists_card_fiber_le_of_card_le_mul [Nonempty β] (hn : card α ≤ card β * n) :
∃ y : β, #{x | f x = y} ≤ n :=
exists_card_fiber_le_of_card_le_nsmul _ hn | theorem | Combinatorics | [
"Mathlib.Algebra.Module.BigOperators",
"Mathlib.Algebra.Order.Ring.Nat",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Order.Preorder.Finite"
] | Mathlib/Combinatorics/Pigeonhole.lean | exists_card_fiber_le_of_card_le_mul | The strong pigeonhole principle for finitely many pigeons and pigeonholes. Given a function `f`
between finite types `α` and `β` and a number `n` such that `card α ≤ card β * n`, there exists an
element `y : β` such that its preimage has at most `n` elements. See also
`Fintype.exists_card_fiber_lt_of_card_lt_mul` for a stronger statement. |
exists_lt_modEq_of_infinite {s : Set ℕ} (hs : s.Infinite) {k : ℕ} (hk : 0 < k) :
∃ m ∈ s, ∃ n ∈ s, m < n ∧ m ≡ n [MOD k] :=
(hs.exists_lt_map_eq_of_mapsTo fun n _ => show n % k ∈ Iio k from Nat.mod_lt n hk) <|
finite_lt_nat k | theorem | Combinatorics | [
"Mathlib.Algebra.Module.BigOperators",
"Mathlib.Algebra.Order.Ring.Nat",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Order.Preorder.Finite"
] | Mathlib/Combinatorics/Pigeonhole.lean | exists_lt_modEq_of_infinite | If `s` is an infinite set of natural numbers and `k > 0`, then `s` contains two elements `m < n`
that are equal mod `k`. |
noncomputable schnirelmannDensity (A : Set ℕ) [DecidablePred (· ∈ A)] : ℝ :=
⨅ n : {n : ℕ // 0 < n}, #{a ∈ Ioc 0 n | a ∈ A} / n | def | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity | The Schnirelmann density is defined as the infimum of |A ∩ {1, ..., n}| / n as n ranges over
the positive naturals. |
schnirelmannDensity_nonneg : 0 ≤ schnirelmannDensity A :=
Real.iInf_nonneg (fun _ => by positivity) | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_nonneg | null |
schnirelmannDensity_le_div {n : ℕ} (hn : n ≠ 0) :
schnirelmannDensity A ≤ #{a ∈ Ioc 0 n | a ∈ A} / n :=
ciInf_le ⟨0, fun _ ⟨_, hx⟩ => hx ▸ by positivity⟩ (⟨n, hn.bot_lt⟩ : {n : ℕ // 0 < n}) | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_le_div | null |
schnirelmannDensity_mul_le_card_filter {n : ℕ} :
schnirelmannDensity A * n ≤ #{a ∈ Ioc 0 n | a ∈ A} := by
rcases eq_or_ne n 0 with rfl | hn
· simp
exact (le_div_iff₀ (by positivity)).1 (schnirelmannDensity_le_div hn) | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_mul_le_card_filter | For any natural `n`, the Schnirelmann density multiplied by `n` is bounded by `|A ∩ {1, ..., n}|`.
Note this property fails for the natural density. |
schnirelmannDensity_le_of_le {x : ℝ} (n : ℕ) (hn : n ≠ 0)
(hx : #{a ∈ Ioc 0 n | a ∈ A} / n ≤ x) : schnirelmannDensity A ≤ x :=
(schnirelmannDensity_le_div hn).trans hx | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_le_of_le | To show the Schnirelmann density is upper bounded by `x`, it suffices to show
`|A ∩ {1, ..., n}| / n ≤ x`, for any chosen positive value of `n`.
We provide `n` explicitly here to make this lemma more easily usable in `apply` or `refine`.
This lemma is analogous to `ciInf_le_of_le`. |
schnirelmannDensity_le_one : schnirelmannDensity A ≤ 1 :=
schnirelmannDensity_le_of_le 1 one_ne_zero <|
by rw [Nat.cast_one, div_one, Nat.cast_le_one]; exact card_filter_le _ _ | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_le_one | null |
schnirelmannDensity_le_of_notMem {k : ℕ} (hk : k ∉ A) :
schnirelmannDensity A ≤ 1 - (k⁻¹ : ℝ) := by
rcases k.eq_zero_or_pos with rfl | hk'
· simpa using schnirelmannDensity_le_one
apply schnirelmannDensity_le_of_le k hk'.ne'
rw [← one_div, one_sub_div (Nat.cast_pos.2 hk').ne']
gcongr
rw [← Nat.cast_pred hk', Nat.cast_le]
suffices {a ∈ Ioc 0 k | a ∈ A} ⊆ Ioo 0 k from (card_le_card this).trans_eq (by simp)
rw [← Ioo_insert_right hk', filter_insert, if_neg hk]
exact filter_subset _ _
@[deprecated (since := "2025-05-23")]
alias schnirelmannDensity_le_of_not_mem := schnirelmannDensity_le_of_notMem | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_le_of_notMem | If `k` is omitted from the set, its Schnirelmann density is upper bounded by `1 - k⁻¹`. |
schnirelmannDensity_eq_zero_of_one_notMem (h : 1 ∉ A) : schnirelmannDensity A = 0 :=
((schnirelmannDensity_le_of_notMem h).trans (by simp)).antisymm schnirelmannDensity_nonneg
@[deprecated (since := "2025-05-23")]
alias schnirelmannDensity_eq_zero_of_one_not_mem := schnirelmannDensity_eq_zero_of_one_notMem | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_eq_zero_of_one_notMem | The Schnirelmann density of a set not containing `1` is `0`. |
schnirelmannDensity_le_of_subset {B : Set ℕ} [DecidablePred (· ∈ B)] (h : A ⊆ B) :
schnirelmannDensity A ≤ schnirelmannDensity B :=
ciInf_mono ⟨0, fun _ ⟨_, hx⟩ ↦ hx ▸ by positivity⟩ fun _ ↦ by
gcongr; exact h | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_le_of_subset | The Schnirelmann density is increasing with the set. |
schnirelmannDensity_eq_one_iff : schnirelmannDensity A = 1 ↔ {0}ᶜ ⊆ A := by
rw [le_antisymm_iff, and_iff_right schnirelmannDensity_le_one]
constructor
· rw [← not_imp_not, not_le]
simp only [Set.not_subset, forall_exists_index, and_imp]
intro x hx hx'
apply (schnirelmannDensity_le_of_notMem hx').trans_lt
simpa only [one_div, sub_lt_self_iff, inv_pos, Nat.cast_pos, pos_iff_ne_zero] using hx
· intro h
refine le_ciInf fun ⟨n, hn⟩ => ?_
rw [one_le_div (Nat.cast_pos.2 hn), Nat.cast_le, filter_true_of_mem, Nat.card_Ioc, Nat.sub_zero]
rintro x hx
exact h (mem_Ioc.1 hx).1.ne' | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_eq_one_iff | The Schnirelmann density of `A` is `1` if and only if `A` contains all the positive naturals. |
schnirelmannDensity_eq_one_iff_of_zero_mem (hA : 0 ∈ A) :
schnirelmannDensity A = 1 ↔ A = Set.univ := by
rw [schnirelmannDensity_eq_one_iff]
constructor
· refine fun h => Set.eq_univ_of_forall fun x => ?_
rcases eq_or_ne x 0 with rfl | hx
· exact hA
· exact h hx
· rintro rfl
exact Set.subset_univ {0}ᶜ | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_eq_one_iff_of_zero_mem | The Schnirelmann density of `A` containing `0` is `1` if and only if `A` is the naturals. |
le_schnirelmannDensity_iff {x : ℝ} :
x ≤ schnirelmannDensity A ↔ ∀ n : ℕ, 0 < n → x ≤ #{a ∈ Ioc 0 n | a ∈ A} / n :=
(le_ciInf_iff ⟨0, fun _ ⟨_, hx⟩ => hx ▸ by positivity⟩).trans Subtype.forall | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | le_schnirelmannDensity_iff | null |
schnirelmannDensity_lt_iff {x : ℝ} :
schnirelmannDensity A < x ↔ ∃ n : ℕ, 0 < n ∧ #{a ∈ Ioc 0 n | a ∈ A} / n < x := by
rw [← not_le, le_schnirelmannDensity_iff]; simp | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_lt_iff | null |
schnirelmannDensity_le_iff_forall {x : ℝ} :
schnirelmannDensity A ≤ x ↔
∀ ε : ℝ, 0 < ε → ∃ n : ℕ, 0 < n ∧ #{a ∈ Ioc 0 n | a ∈ A} / n < x + ε := by
rw [le_iff_forall_pos_lt_add]
simp only [schnirelmannDensity_lt_iff] | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_le_iff_forall | null |
schnirelmannDensity_congr' {B : Set ℕ} [DecidablePred (· ∈ B)]
(h : ∀ n > 0, n ∈ A ↔ n ∈ B) : schnirelmannDensity A = schnirelmannDensity B := by
rw [schnirelmannDensity, schnirelmannDensity]; congr; ext ⟨n, hn⟩; congr 3; ext x; simp_all | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_congr' | null |
@[simp] schnirelmannDensity_insert_zero [DecidablePred (· ∈ insert 0 A)] :
schnirelmannDensity (insert 0 A) = schnirelmannDensity A :=
schnirelmannDensity_congr' (by aesop) | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_insert_zero | The Schnirelmann density is unaffected by adding `0`. |
schnirelmannDensity_diff_singleton_zero [DecidablePred (· ∈ A \ {0})] :
schnirelmannDensity (A \ {0}) = schnirelmannDensity A :=
schnirelmannDensity_congr' (by aesop) | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_diff_singleton_zero | The Schnirelmann density is unaffected by removing `0`. |
schnirelmannDensity_congr {B : Set ℕ} [DecidablePred (· ∈ B)] (h : A = B) :
schnirelmannDensity A = schnirelmannDensity B :=
schnirelmannDensity_congr' (by simp_all) | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_congr | null |
exists_of_schnirelmannDensity_eq_zero {ε : ℝ} (hε : 0 < ε) (hA : schnirelmannDensity A = 0) :
∃ n, 0 < n ∧ #{a ∈ Ioc 0 n | a ∈ A} / n < ε := by
by_contra! h
rw [← le_schnirelmannDensity_iff] at h
linarith | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | exists_of_schnirelmannDensity_eq_zero | If the Schnirelmann density is `0`, there is a positive natural for which
`|A ∩ {1, ..., n}| / n < ε`, for any positive `ε`.
Note this cannot be improved to `∃ᶠ n : ℕ in atTop`, as can be seen by `A = {1}ᶜ`. |
@[simp] schnirelmannDensity_empty : schnirelmannDensity ∅ = 0 :=
schnirelmannDensity_eq_zero_of_one_notMem (by simp) | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_empty | null |
schnirelmannDensity_finset (A : Finset ℕ) : schnirelmannDensity A = 0 := by
refine le_antisymm ?_ schnirelmannDensity_nonneg
simp only [schnirelmannDensity_le_iff_forall, zero_add]
intro ε hε
wlog hε₁ : ε ≤ 1 generalizing ε
· obtain ⟨n, hn, hn'⟩ := this 1 zero_lt_one le_rfl
exact ⟨n, hn, hn'.trans_le (le_of_not_ge hε₁)⟩
let n : ℕ := ⌊#A / ε⌋₊ + 1
have hn : 0 < n := Nat.succ_pos _
use n, hn
rw [div_lt_iff₀ (Nat.cast_pos.2 hn), ← div_lt_iff₀' hε, Nat.cast_add_one]
exact (Nat.lt_floor_add_one _).trans_le' <| by gcongr; simp [subset_iff] | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_finset | The Schnirelmann density of any finset is `0`. |
schnirelmannDensity_finite {A : Set ℕ} [DecidablePred (· ∈ A)] (hA : A.Finite) :
schnirelmannDensity A = 0 := by simpa using schnirelmannDensity_finset hA.toFinset
@[simp] lemma schnirelmannDensity_univ : schnirelmannDensity Set.univ = 1 :=
(schnirelmannDensity_eq_one_iff_of_zero_mem (by simp)).2 (by simp) | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_finite | The Schnirelmann density of any finite set is `0`. |
schnirelmannDensity_setOf_even : schnirelmannDensity (setOf Even) = 0 :=
schnirelmannDensity_eq_zero_of_one_notMem <| by simp | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_setOf_even | null |
schnirelmannDensity_setOf_prime : schnirelmannDensity (setOf Nat.Prime) = 0 :=
schnirelmannDensity_eq_zero_of_one_notMem <| by simp [Nat.not_prime_one] | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_setOf_prime | null |
schnirelmannDensity_setOf_mod_eq_one {m : ℕ} (hm : m ≠ 1) :
schnirelmannDensity {n | n % m = 1} = (m⁻¹ : ℝ) := by
rcases m.eq_zero_or_pos with rfl | hm'
· simp only [Nat.cast_zero, inv_zero]
refine schnirelmannDensity_finite ?_
simp
apply le_antisymm (schnirelmannDensity_le_of_le m hm'.ne' _) _
· rw [← one_div, ← @Nat.cast_one ℝ]
gcongr
simp only [Set.mem_setOf_eq, card_le_one_iff_subset_singleton, subset_iff,
mem_filter, mem_Ioc, mem_singleton, and_imp]
use 1
intro x _ hxm h
rcases eq_or_lt_of_le hxm with rfl | hxm'
· simp at h
rwa [Nat.mod_eq_of_lt hxm'] at h
rw [le_schnirelmannDensity_iff]
intro n hn
simp only [Set.mem_setOf_eq]
have : (Icc 0 ((n - 1) / m)).image (· * m + 1) ⊆ {x ∈ Ioc 0 n | x % m = 1} := by
simp only [subset_iff, mem_image, forall_exists_index, mem_filter, mem_Ioc, mem_Icc, and_imp]
rintro _ y _ hy' rfl
have hm : 2 ≤ m := hm.lt_of_le' hm'
simp only [Nat.mul_add_mod', Nat.mod_eq_of_lt hm, add_pos_iff, or_true, and_true, true_and,
← Nat.le_sub_iff_add_le hn, zero_lt_one]
exact Nat.mul_le_of_le_div _ _ _ hy'
rw [le_div_iff₀ (Nat.cast_pos.2 hn), mul_comm, ← div_eq_mul_inv]
apply (Nat.cast_le.2 (card_le_card this)).trans'
rw [card_image_of_injective, Nat.card_Icc, Nat.sub_zero, div_le_iff₀ (Nat.cast_pos.2 hm'),
← Nat.cast_mul, Nat.cast_le, add_one_mul (α := ℕ)]
· have := @Nat.lt_div_mul_add n.pred m hm'
rwa [← Nat.succ_le, Nat.succ_pred hn.ne'] at this
intro a b
simp [hm'.ne'] | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_setOf_mod_eq_one | The Schnirelmann density of the set of naturals which are `1 mod m` is `m⁻¹`, for any `m ≠ 1`.
Note that if `m = 1`, this set is empty. |
schnirelmannDensity_setOf_modeq_one {m : ℕ} :
schnirelmannDensity {n | n ≡ 1 [MOD m]} = (m⁻¹ : ℝ) := by
rcases eq_or_ne m 1 with rfl | hm
· simp [Nat.modEq_one]
rw [← schnirelmannDensity_setOf_mod_eq_one hm]
apply schnirelmannDensity_congr
ext n
simp only [Set.mem_setOf_eq, Nat.ModEq, Nat.one_mod_eq_one.mpr hm] | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_setOf_modeq_one | null |
schnirelmannDensity_setOf_Odd : schnirelmannDensity (setOf Odd) = 2⁻¹ := by
have h : setOf Odd = {n | n % 2 = 1} := Set.ext fun _ => Nat.odd_iff
simp only [h]
rw [schnirelmannDensity_setOf_mod_eq_one (by norm_num1), Nat.cast_two] | lemma | Combinatorics | [
"Mathlib.Algebra.Order.Ring.Abs",
"Mathlib.Data.Nat.ModEq",
"Mathlib.Data.Nat.Prime.Defs",
"Mathlib.Data.Real.Archimedean",
"Mathlib.Order.Interval.Finset.Nat"
] | Mathlib/Combinatorics/Schnirelmann.lean | schnirelmannDensity_setOf_Odd | null |
ack : ℕ → ℕ → ℕ
| 0, n => n + 1
| m + 1, 0 => ack m 1
| m + 1, n + 1 => ack m (ack (m + 1) n)
@[simp] | def | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack | The two-argument Ackermann function, defined so that
- `ack 0 n = n + 1`
- `ack (m + 1) 0 = ack m 1`
- `ack (m + 1) (n + 1) = ack m (ack (m + 1) n)`.
This is of interest as both a fast-growing function, and as an example of a recursive function that
isn't primitive recursive. |
ack_zero (n : ℕ) : ack 0 n = n + 1 := by rw [ack]
@[simp] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_zero | null |
ack_succ_zero (m : ℕ) : ack (m + 1) 0 = ack m 1 := by rw [ack]
@[simp] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_succ_zero | null |
ack_succ_succ (m n : ℕ) : ack (m + 1) (n + 1) = ack m (ack (m + 1) n) := by rw [ack]
@[simp] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_succ_succ | null |
ack_one (n : ℕ) : ack 1 n = n + 2 := by
induction n with
| zero => simp
| succ n IH => simp [IH]
@[simp] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_one | null |
ack_two (n : ℕ) : ack 2 n = 2 * n + 3 := by
induction n with
| zero => simp
| succ n IH => simpa [mul_succ]
@[simp] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_two | null |
ack_three (n : ℕ) : ack 3 n = 2 ^ (n + 3) - 3 := by
induction n with
| zero => simp
| succ n IH =>
rw [ack_succ_succ, IH, ack_two, Nat.succ_add, Nat.pow_succ 2 (n + 3), mul_comm _ 2,
Nat.mul_sub_left_distrib, ← Nat.sub_add_comm, two_mul 3, Nat.add_sub_add_right]
calc 2 * 3
_ ≤ 2 * 2 ^ 3 := by simp
_ ≤ 2 * 2 ^ (n + 3) := by gcongr <;> omega | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_three | null |
ack_pos : ∀ m n, 0 < ack m n
| 0, n => by simp
| m + 1, 0 => by
rw [ack_succ_zero]
apply ack_pos
| m + 1, n + 1 => by
rw [ack_succ_succ]
apply ack_pos | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_pos | null |
one_lt_ack_succ_left : ∀ m n, 1 < ack (m + 1) n
| 0, n => by simp
| m + 1, 0 => by
rw [ack_succ_zero]
apply one_lt_ack_succ_left
| m + 1, n + 1 => by
rw [ack_succ_succ]
apply one_lt_ack_succ_left | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | one_lt_ack_succ_left | null |
one_lt_ack_succ_right : ∀ m n, 1 < ack m (n + 1)
| 0, n => by simp
| m + 1, n => one_lt_ack_succ_left m (n + 1) | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | one_lt_ack_succ_right | null |
ack_strictMono_right : ∀ m, StrictMono (ack m)
| 0, n₁, n₂, h => by simpa using h
| m + 1, 0, n + 1, _h => by
rw [ack_succ_zero, ack_succ_succ]
exact ack_strictMono_right _ (one_lt_ack_succ_left m n)
| m + 1, n₁ + 1, n₂ + 1, h => by
rw [ack_succ_succ, ack_succ_succ]
apply ack_strictMono_right _ (ack_strictMono_right _ _)
rwa [add_lt_add_iff_right] at h | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_strictMono_right | null |
ack_mono_right (m : ℕ) : Monotone (ack m) :=
(ack_strictMono_right m).monotone | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_mono_right | null |
ack_injective_right (m : ℕ) : Function.Injective (ack m) :=
(ack_strictMono_right m).injective
@[simp] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_injective_right | null |
ack_lt_iff_right {m n₁ n₂ : ℕ} : ack m n₁ < ack m n₂ ↔ n₁ < n₂ :=
(ack_strictMono_right m).lt_iff_lt
@[simp] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_lt_iff_right | null |
ack_le_iff_right {m n₁ n₂ : ℕ} : ack m n₁ ≤ ack m n₂ ↔ n₁ ≤ n₂ :=
(ack_strictMono_right m).le_iff_le
@[simp] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_le_iff_right | null |
ack_inj_right {m n₁ n₂ : ℕ} : ack m n₁ = ack m n₂ ↔ n₁ = n₂ :=
(ack_injective_right m).eq_iff | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_inj_right | null |
max_ack_right (m n₁ n₂ : ℕ) : ack m (max n₁ n₂) = max (ack m n₁) (ack m n₂) :=
(ack_mono_right m).map_max | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | max_ack_right | null |
add_lt_ack : ∀ m n, m + n < ack m n
| 0, n => by simp
| m + 1, 0 => by simpa using add_lt_ack m 1
| m + 1, n + 1 =>
calc
m + 1 + n + 1 ≤ m + (m + n + 2) := by omega
_ < ack m (m + n + 2) := add_lt_ack _ _
_ ≤ ack m (ack (m + 1) n) :=
ack_mono_right m <| le_of_eq_of_le (by rw [succ_eq_add_one]; ring_nf)
<| succ_le_of_lt <| add_lt_ack (m + 1) n
_ = ack (m + 1) (n + 1) := (ack_succ_succ m n).symm | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | add_lt_ack | null |
add_add_one_le_ack (m n : ℕ) : m + n + 1 ≤ ack m n :=
succ_le_of_lt (add_lt_ack m n) | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | add_add_one_le_ack | null |
lt_ack_left (m n : ℕ) : m < ack m n :=
(self_le_add_right m n).trans_lt <| add_lt_ack m n | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | lt_ack_left | null |
lt_ack_right (m n : ℕ) : n < ack m n :=
(self_le_add_left n m).trans_lt <| add_lt_ack m n | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | lt_ack_right | null |
private ack_strict_mono_left' : ∀ {m₁ m₂} (n), m₁ < m₂ → ack m₁ n < ack m₂ n
| m, 0, _ => fun h => (not_lt_zero m h).elim
| 0, m + 1, 0 => fun _h => by simpa using one_lt_ack_succ_right m 0
| 0, m + 1, n + 1 => fun h => by
rw [ack_zero, ack_succ_succ]
apply lt_of_le_of_lt (le_trans _ <| add_le_add_left (add_add_one_le_ack _ _) m) (add_lt_ack _ _)
omega
| m₁ + 1, m₂ + 1, 0 => fun h => by
simpa using ack_strict_mono_left' 1 ((add_lt_add_iff_right 1).1 h)
| m₁ + 1, m₂ + 1, n + 1 => fun h => by
rw [ack_succ_succ, ack_succ_succ]
exact
(ack_strict_mono_left' _ <| (add_lt_add_iff_right 1).1 h).trans
(ack_strictMono_right _ <| ack_strict_mono_left' n h) | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_strict_mono_left' | null |
ack_strictMono_left (n : ℕ) : StrictMono fun m => ack m n := fun _m₁ _m₂ =>
ack_strict_mono_left' n | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_strictMono_left | null |
ack_mono_left (n : ℕ) : Monotone fun m => ack m n :=
(ack_strictMono_left n).monotone | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_mono_left | null |
ack_injective_left (n : ℕ) : Function.Injective fun m => ack m n :=
(ack_strictMono_left n).injective
@[simp] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_injective_left | null |
ack_lt_iff_left {m₁ m₂ n : ℕ} : ack m₁ n < ack m₂ n ↔ m₁ < m₂ :=
(ack_strictMono_left n).lt_iff_lt
@[simp] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_lt_iff_left | null |
ack_le_iff_left {m₁ m₂ n : ℕ} : ack m₁ n ≤ ack m₂ n ↔ m₁ ≤ m₂ :=
(ack_strictMono_left n).le_iff_le
@[simp] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_le_iff_left | null |
ack_inj_left {m₁ m₂ n : ℕ} : ack m₁ n = ack m₂ n ↔ m₁ = m₂ :=
(ack_injective_left n).eq_iff | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_inj_left | null |
max_ack_left (m₁ m₂ n : ℕ) : ack (max m₁ m₂) n = max (ack m₁ n) (ack m₂ n) :=
(ack_mono_left n).map_max
@[gcongr] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | max_ack_left | null |
ack_le_ack {m₁ m₂ n₁ n₂ : ℕ} (hm : m₁ ≤ m₂) (hn : n₁ ≤ n₂) : ack m₁ n₁ ≤ ack m₂ n₂ :=
(ack_mono_left n₁ hm).trans <| ack_mono_right m₂ hn | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_le_ack | null |
ack_succ_right_le_ack_succ_left (m n : ℕ) : ack m (n + 1) ≤ ack (m + 1) n := by
rcases n with - | n
· simp
· rw [ack_succ_succ]
apply ack_mono_right m (le_trans _ <| add_add_one_le_ack _ n)
cutsat | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_succ_right_le_ack_succ_left | null |
private sq_le_two_pow_add_one_minus_three (n : ℕ) : n ^ 2 ≤ 2 ^ (n + 1) - 3 := by
induction n with
| zero => simp
| succ k hk =>
rcases k with - | k
· simp
· rw [add_sq, Nat.pow_succ 2, mul_comm _ 2, two_mul (2 ^ _),
add_tsub_assoc_of_le, add_comm (2 ^ _), add_assoc]
· apply Nat.add_le_add hk
norm_num
apply succ_le_of_lt
rw [Nat.pow_succ, mul_comm _ 2, mul_lt_mul_iff_right₀ (zero_lt_two' ℕ)]
exact Nat.lt_two_pow_self
· rw [Nat.pow_succ, Nat.pow_succ]
linarith [one_le_pow k 2 zero_lt_two] | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | sq_le_two_pow_add_one_minus_three | null |
ack_add_one_sq_lt_ack_add_three : ∀ m n, (ack m n + 1) ^ 2 ≤ ack (m + 3) n
| 0, n => by simpa using sq_le_two_pow_add_one_minus_three (n + 2)
| m + 1, 0 => by
rw [ack_succ_zero, ack_succ_zero]
apply ack_add_one_sq_lt_ack_add_three
| m + 1, n + 1 => by
rw [ack_succ_succ, ack_succ_succ]
apply (ack_add_one_sq_lt_ack_add_three _ _).trans (ack_mono_right _ <| ack_mono_left _ _)
cutsat | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_add_one_sq_lt_ack_add_three | null |
ack_ack_lt_ack_max_add_two (m n k : ℕ) : ack m (ack n k) < ack (max m n + 2) k :=
calc
ack m (ack n k) ≤ ack (max m n) (ack n k) := ack_mono_left _ (le_max_left _ _)
_ < ack (max m n) (ack (max m n + 1) k) :=
ack_strictMono_right _ <| ack_strictMono_left k <| lt_succ_of_le <| le_max_right m n
_ = ack (max m n + 1) (k + 1) := (ack_succ_succ _ _).symm
_ ≤ ack (max m n + 2) k := ack_succ_right_le_ack_succ_left _ _ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_ack_lt_ack_max_add_two | null |
ack_add_one_sq_lt_ack_add_four (m n : ℕ) : ack m ((n + 1) ^ 2) < ack (m + 4) n :=
calc
ack m ((n + 1) ^ 2) < ack m ((ack m n + 1) ^ 2) :=
ack_strictMono_right m <| Nat.pow_lt_pow_left (succ_lt_succ <| lt_ack_right m n) two_ne_zero
_ ≤ ack m (ack (m + 3) n) := ack_mono_right m <| ack_add_one_sq_lt_ack_add_three m n
_ ≤ ack (m + 2) (ack (m + 3) n) := ack_mono_left _ <| by cutsat
_ = ack (m + 3) (n + 1) := (ack_succ_succ _ n).symm
_ ≤ ack (m + 4) n := ack_succ_right_le_ack_succ_left _ n | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_add_one_sq_lt_ack_add_four | null |
ack_pair_lt (m n k : ℕ) : ack m (pair n k) < ack (m + 4) (max n k) :=
(ack_strictMono_right m <| pair_lt_max_add_one_sq n k).trans <|
ack_add_one_sq_lt_ack_add_four _ _ | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | ack_pair_lt | null |
exists_lt_ack_of_nat_primrec {f : ℕ → ℕ} (hf : Nat.Primrec f) :
∃ m, ∀ n, f n < ack m n := by
induction hf with
| zero => exact ⟨0, ack_pos 0⟩
| succ =>
refine ⟨1, fun n => ?_⟩
rw [succ_eq_one_add]
apply add_lt_ack
| left =>
refine ⟨0, fun n => ?_⟩
rw [ack_zero, Nat.lt_succ_iff]
exact unpair_left_le n
| right =>
refine ⟨0, fun n => ?_⟩
rw [ack_zero, Nat.lt_succ_iff]
exact unpair_right_le n
| pair hf hg IHf IHg =>
obtain ⟨a, ha⟩ := IHf; obtain ⟨b, hb⟩ := IHg
refine
⟨max a b + 3, fun n =>
(pair_lt_max_add_one_sq _ _).trans_le <|
(Nat.pow_le_pow_left (add_le_add_right ?_ _) 2).trans <|
ack_add_one_sq_lt_ack_add_three _ _⟩
rw [max_ack_left]
exact max_le_max (ha n).le (hb n).le
| comp hf hg IHf IHg =>
obtain ⟨a, ha⟩ := IHf; obtain ⟨b, hb⟩ := IHg
exact
⟨max a b + 2, fun n =>
(ha _).trans <| (ack_strictMono_right a <| hb n).trans <| ack_ack_lt_ack_max_add_two a b n⟩
| @prec f g hf hg IHf IHg =>
obtain ⟨a, ha⟩ := IHf; obtain ⟨b, hb⟩ := IHg
have :
∀ {m n},
rec (f m) (fun y IH => g <| pair m <| pair y IH) n < ack (max a b + 9) (m + n) := by
intro m n
induction n with
| zero => -- The base case is easy.
apply (ha m).trans (ack_strictMono_left m <| (le_max_left a b).trans_lt _)
cutsat
| succ n IH => -- We get rid of the first `pair`.
simp only
apply (hb _).trans ((ack_pair_lt _ _ _).trans_le _)
rcases lt_or_ge _ m with h₁ | h₁
· rw [max_eq_left h₁.le]
gcongr <;> omega
rw [max_eq_right h₁]
apply (ack_pair_lt _ _ _).le.trans
rcases lt_or_ge _ n with h₂ | h₂
· rw [max_eq_left h₂.le, add_assoc]
exact
... | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | exists_lt_ack_of_nat_primrec | If `f` is primitive recursive, there exists `m` such that `f n < ack m n` for all `n`. |
not_nat_primrec_ack_self : ¬Nat.Primrec fun n => ack n n := fun h => by
obtain ⟨m, hm⟩ := exists_lt_ack_of_nat_primrec h
exact (hm m).false | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | not_nat_primrec_ack_self | null |
not_primrec_ack_self : ¬Primrec fun n => ack n n := by
rw [Primrec.nat_iff]
exact not_nat_primrec_ack_self | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | not_primrec_ack_self | null |
not_primrec₂_ack : ¬Primrec₂ ack := fun h =>
not_primrec_ack_self <| h.comp Primrec.id Primrec.id | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | not_primrec₂_ack | The Ackermann function is not primitive recursive. |
pappAck : ℕ → Code
| 0 => .succ
| n + 1 => step (pappAck n)
where
/-- Yields single recursion step on `pappAck`. -/
step (c : Code) : Code :=
.curry (.prec (.comp c (.const 1)) (.comp c (.comp .right .right))) 0 | def | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | pappAck | The code for the partially applied Ackermann function.
This is used to prove that the Ackermann function is computable. |
primrec_pappAck_step : Primrec pappAck.step := by
apply_rules
[Code.primrec₂_curry.comp, Code.primrec₂_prec.comp, Code.primrec₂_comp.comp,
_root_.Primrec.id, Primrec.const]
@[simp] | lemma | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | primrec_pappAck_step | null |
eval_pappAck_step_zero (c : Code) : (pappAck.step c).eval 0 = c.eval 1 := by
simp [pappAck.step, Code.eval]
@[simp] | lemma | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | eval_pappAck_step_zero | null |
eval_pappAck_step_succ (c : Code) (n) :
(pappAck.step c).eval (n + 1) = ((pappAck.step c).eval n).bind c.eval := by
simp [pappAck.step, Code.eval] | lemma | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | eval_pappAck_step_succ | null |
primrec_pappAck : Primrec pappAck := by
suffices Primrec (Nat.rec Code.succ (fun _ c => pappAck.step c)) by
convert this using 2 with n; induction n <;> simp [pappAck, *]
apply_rules [Primrec.nat_rec₁, primrec_pappAck_step.comp, Primrec.snd]
@[simp] | lemma | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | primrec_pappAck | null |
eval_pappAck (m n) : (pappAck m).eval n = Part.some (ack m n) := by
induction m, n using ack.induct with
| case1 n => simp [Code.eval, pappAck]
| case2 m hm => simp [pappAck, hm]
| case3 m n hmn₁ hmn₂ => dsimp only [pappAck] at *; simp [hmn₁, hmn₂] | lemma | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | eval_pappAck | null |
_root_.computable₂_ack : Computable₂ ack := by
apply _root_.Partrec.of_eq_tot
(f := fun p : ℕ × ℕ => (pappAck p.1).eval p.2) (g := fun p : ℕ × ℕ => ack p.1 p.2)
· change Partrec₂ (fun m n => (pappAck m).eval n)
apply_rules only
[Code.eval_part.comp₂, Computable.fst, Computable.snd, primrec_pappAck.to_comp.comp]
· simp | theorem | Computability | [
"Mathlib.Computability.PartrecCode",
"Mathlib.Tactic.Ring",
"Mathlib.Tactic.Linarith"
] | Mathlib/Computability/Ackermann.lean | _root_.computable₂_ack | The Ackermann function is computable. |
@[ext]
ContextFreeRule (T N : Type*) where
/-- Input nonterminal a.k.a. left-hand side. -/
input : N
/-- Output string a.k.a. right-hand side. -/
output : List (Symbol T N)
deriving DecidableEq, Repr
attribute [nolint unusedArguments] instReprContextFreeRule.repr | structure | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | ContextFreeRule | Rule that rewrites a single nonterminal to any string (a list of symbols). |
ContextFreeGrammar (T : Type*) where
/-- Type of nonterminals. -/
NT : Type
/-- Initial nonterminal. -/
initial : NT
/-- Rewrite rules. -/
rules : Finset (ContextFreeRule T NT)
variable {T : Type*} | structure | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | ContextFreeGrammar | Context-free grammar that generates words over the alphabet `T` (a type of terminals). |
Rewrites (r : ContextFreeRule T N) : List (Symbol T N) → List (Symbol T N) → Prop
/-- The replacement is at the start of the remaining string. -/
| head (s : List (Symbol T N)) :
r.Rewrites (Symbol.nonterminal r.input :: s) (r.output ++ s)
/-- There is a replacement later in the string. -/
| cons (x : Symbol T N) {s₁ s₂ : List (Symbol T N)} (hrs : Rewrites r s₁ s₂) :
r.Rewrites (x :: s₁) (x :: s₂) | inductive | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Rewrites | Inductive definition of a single application of a given context-free rule `r` to a string `u`;
`r.Rewrites u v` means that the `r` sends `u` to `v` (there may be multiple such strings `v`). |
Rewrites.exists_parts (hr : r.Rewrites u v) :
∃ p q : List (Symbol T N),
u = p ++ [Symbol.nonterminal r.input] ++ q ∧ v = p ++ r.output ++ q := by
induction hr with
| head s =>
use [], s
simp
| cons x _ ih =>
rcases ih with ⟨p', q', rfl, rfl⟩
use x :: p', q'
simp | lemma | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Rewrites.exists_parts | null |
Rewrites.input_output : r.Rewrites [.nonterminal r.input] r.output := by
simpa using head [] | lemma | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Rewrites.input_output | null |
rewrites_of_exists_parts (r : ContextFreeRule T N) (p q : List (Symbol T N)) :
r.Rewrites (p ++ [Symbol.nonterminal r.input] ++ q) (p ++ r.output ++ q) := by
induction p with
| nil => exact Rewrites.head q
| cons d l ih => exact Rewrites.cons d ih | lemma | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | rewrites_of_exists_parts | null |
rewrites_iff :
r.Rewrites u v ↔ ∃ p q : List (Symbol T N),
u = p ++ [Symbol.nonterminal r.input] ++ q ∧ v = p ++ r.output ++ q :=
⟨Rewrites.exists_parts, by rintro ⟨p, q, rfl, rfl⟩; apply rewrites_of_exists_parts⟩ | theorem | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | rewrites_iff | Rule `r` rewrites string `u` is to string `v` iff they share both a prefix `p` and postfix `q`
such that the remaining middle part of `u` is the input of `r` and the remaining middle part
of `u` is the output of `r`. |
Rewrites.nonterminal_input_mem : r.Rewrites u v → .nonterminal r.input ∈ u := by
simp +contextual [rewrites_iff, List.append_assoc] | lemma | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Rewrites.nonterminal_input_mem | null |
Rewrites.append_left (hvw : r.Rewrites u v) (p : List (Symbol T N)) :
r.Rewrites (p ++ u) (p ++ v) := by
rw [rewrites_iff] at *
rcases hvw with ⟨x, y, hxy⟩
use p ++ x, y
simp_all | lemma | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Rewrites.append_left | Add extra prefix to context-free rewriting. |
Rewrites.append_right (hvw : r.Rewrites u v) (p : List (Symbol T N)) :
r.Rewrites (u ++ p) (v ++ p) := by
rw [rewrites_iff] at *
rcases hvw with ⟨x, y, hxy⟩
use x, y ++ p
simp_all | lemma | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Rewrites.append_right | Add extra postfix to context-free rewriting. |
Produces (g : ContextFreeGrammar T) (u v : List (Symbol T g.NT)) : Prop :=
∃ r ∈ g.rules, r.Rewrites u v | def | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Produces | Given a context-free grammar `g` and strings `u` and `v`
`g.Produces u v` means that one step of a context-free transformation by a rule from `g` sends
`u` to `v`. |
Derives (g : ContextFreeGrammar T) :
List (Symbol T g.NT) → List (Symbol T g.NT) → Prop :=
Relation.ReflTransGen g.Produces | abbrev | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Derives | Given a context-free grammar `g` and strings `u` and `v`
`g.Derives u v` means that `g` can transform `u` to `v` in some number of rewriting steps. |
Generates (g : ContextFreeGrammar T) (s : List (Symbol T g.NT)) : Prop :=
g.Derives [Symbol.nonterminal g.initial] s | def | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Generates | Given a context-free grammar `g` and a string `s`
`g.Generates s` means that `g` can transform its initial nonterminal to `s` in some number of
rewriting steps. |
language (g : ContextFreeGrammar T) : Language T :=
{ w : List T | g.Generates (w.map Symbol.terminal) } | def | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | language | The language (set of words) that can be generated by a given context-free grammar `g`. |
@[simp]
mem_language_iff (g : ContextFreeGrammar T) (w : List T) :
w ∈ g.language ↔ g.Derives [Symbol.nonterminal g.initial] (w.map Symbol.terminal) := by
rfl
variable {g : ContextFreeGrammar T}
@[refl] | lemma | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | mem_language_iff | A given word `w` belongs to the language generated by a given context-free grammar `g` iff
`g` can derive the word `w` (wrapped as a string) from the initial nonterminal of `g` in some
number of steps. |
Derives.refl (w : List (Symbol T g.NT)) : g.Derives w w :=
Relation.ReflTransGen.refl | lemma | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Derives.refl | null |
Produces.single {v w : List (Symbol T g.NT)} (hvw : g.Produces v w) : g.Derives v w :=
Relation.ReflTransGen.single hvw
@[trans] | lemma | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Produces.single | null |
Derives.trans {u v w : List (Symbol T g.NT)} (huv : g.Derives u v) (hvw : g.Derives v w) :
g.Derives u w :=
Relation.ReflTransGen.trans huv hvw | lemma | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Derives.trans | null |
Derives.trans_produces {u v w : List (Symbol T g.NT)}
(huv : g.Derives u v) (hvw : g.Produces v w) :
g.Derives u w :=
huv.trans hvw.single | lemma | Computability | [
"Mathlib.Computability.Language"
] | Mathlib/Computability/ContextFreeGrammar.lean | Derives.trans_produces | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.