l3lab/ntp-mathlib huggingface dataset:
/-- The Schnirelmann density of `A` is `1` if and only if `A` contains all the positive naturals. -/
lemma 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, true_and, and_imp, Set.mem_singleton_iff]
    intro x hx hx'
    apply (schnirelmannDensity_le_of_not_mem 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
    

Proof state:
case mpr
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
h : {0}ᶜ ⊆ A
x✝ : { n // 0 < n }
n : ℕ
hn : 0 < n
x : ℕ
hx : x ∈ Ioc 0 ↑{ val := n, property := hn }
⊢ x ∈ A

Next tactic:
exact h (mem_Ioc.1 hx).1.ne'
/-- The Schnirelmann density of `A` containing `0` is `1` if and only if `A` is the naturals. -/
lemma schnirelmannDensity_eq_one_iff_of_zero_mem (hA : 0 ∈ A) :
    schnirelmannDensity A = 1 ↔ A = Set.univ := by
  

Proof state:
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
hA : 0 ∈ A
⊢ schnirelmannDensity A = 1 ↔ A = Set.univ

Next tactic:
rw [schnirelmannDensity_eq_one_iff]
/-- The Schnirelmann density of `A` containing `0` is `1` if and only if `A` is the naturals. -/
lemma schnirelmannDensity_eq_one_iff_of_zero_mem (hA : 0 ∈ A) :
    schnirelmannDensity A = 1 ↔ A = Set.univ := by
  rw [schnirelmannDensity_eq_one_iff]
  

Proof state:
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
hA : 0 ∈ A
⊢ {0}ᶜ ⊆ A ↔ A = Set.univ

Next tactic:
constructor
/-- The Schnirelmann density of `A` containing `0` is `1` if and only if `A` is the naturals. -/
lemma schnirelmannDensity_eq_one_iff_of_zero_mem (hA : 0 ∈ A) :
    schnirelmannDensity A = 1 ↔ A = Set.univ := by
  rw [schnirelmannDensity_eq_one_iff]
  constructor
  · 

Proof state:
case mp
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
hA : 0 ∈ A
⊢ {0}ᶜ ⊆ A → A = Set.univ

Next tactic:
refine fun h => Set.eq_univ_of_forall fun x => ?_
/-- The Schnirelmann density of `A` containing `0` is `1` if and only if `A` is the naturals. -/
lemma 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 => ?_
    

Proof state:
case mp
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
hA : 0 ∈ A
h : {0}ᶜ ⊆ A
x : ℕ
⊢ x ∈ A

Next tactic:
rcases eq_or_ne x 0 with rfl | hx
/-- The Schnirelmann density of `A` containing `0` is `1` if and only if `A` is the naturals. -/
lemma 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
    · 

Proof state:
case mp.inl
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
hA : 0 ∈ A
h : {0}ᶜ ⊆ A
⊢ 0 ∈ A

Next tactic:
exact hA
/-- The Schnirelmann density of `A` containing `0` is `1` if and only if `A` is the naturals. -/
lemma 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
    · 

Proof state:
case mp.inr
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
hA : 0 ∈ A
h : {0}ᶜ ⊆ A
x : ℕ
hx : x ≠ 0
⊢ x ∈ A

Next tactic:
exact h hx
/-- The Schnirelmann density of `A` containing `0` is `1` if and only if `A` is the naturals. -/
lemma 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
  · 

Proof state:
case mpr
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
hA : 0 ∈ A
⊢ A = Set.univ → {0}ᶜ ⊆ A

Next tactic:
rintro rfl
/-- The Schnirelmann density of `A` containing `0` is `1` if and only if `A` is the naturals. -/
lemma 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
    

Proof state:
case mpr
inst✝ : DecidablePred fun x => x ∈ Set.univ
hA : 0 ∈ Set.univ
⊢ {0}ᶜ ⊆ Set.univ

Next tactic:
exact Set.subset_univ {0}ᶜ
lemma le_schnirelmannDensity_iff {x : ℝ} :
    x ≤ schnirelmannDensity A ↔ ∀ n : ℕ, 0 < n → x ≤ ((Ioc 0 n).filter (· ∈ A)).card / n :=
  (le_ciInf_iff ⟨0, fun _ ⟨_, hx⟩ => hx ▸ by 

Proof state:
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
x x✝¹ : ℝ
x✝ : x✝¹ ∈ Set.range fun n => ↑(card (filter (fun x => x ∈ A) (Ioc 0 ↑n))) / ↑↑n
w✝ : { n // 0 < n }
hx : (fun n => ↑(card (filter (fun x => x ∈ A) (Ioc 0 ↑n))) / ↑↑n) w✝ = x✝¹
⊢ 0 ≤ (fun n => ↑(card (filter (fun x => x ∈ A) (Ioc 0 ↑n))) / ↑↑n) w✝

Next tactic:
positivity
lemma schnirelmannDensity_lt_iff {x : ℝ} :
    schnirelmannDensity A < x ↔ ∃ n : ℕ, 0 < n ∧ ((Ioc 0 n).filter (· ∈ A)).card / n < x :=
  by 

Proof state:
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
x : ℝ
⊢ schnirelmannDensity A < x ↔ ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ A) (Ioc 0 n))) / ↑n < x

Next tactic:
rw [← not_le, le_schnirelmannDensity_iff]
lemma schnirelmannDensity_lt_iff {x : ℝ} :
    schnirelmannDensity A < x ↔ ∃ n : ℕ, 0 < n ∧ ((Ioc 0 n).filter (· ∈ A)).card / n < x :=
  by rw [← not_le, le_schnirelmannDensity_iff]; 

Proof state:
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
x : ℝ
⊢ (¬∀ (n : ℕ), 0 < n → x ≤ ↑(card (filter (fun x => x ∈ A) (Ioc 0 n))) / ↑n) ↔
    ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ A) (Ioc 0 n))) / ↑n < x

Next tactic:
simp
lemma schnirelmannDensity_le_iff_forall {x : ℝ} :
    schnirelmannDensity A ≤ x ↔
      ∀ ε : ℝ, 0 < ε → ∃ n : ℕ, 0 < n ∧ ((Ioc 0 n).filter (· ∈ A)).card / n < x + ε := by
  

Proof state:
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
x : ℝ
⊢ schnirelmannDensity A ≤ x ↔ ∀ (ε : ℝ), 0 < ε → ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ A) (Ioc 0 n))) / ↑n < x + ε

Next tactic:
rw [le_iff_forall_pos_lt_add]
lemma schnirelmannDensity_le_iff_forall {x : ℝ} :
    schnirelmannDensity A ≤ x ↔
      ∀ ε : ℝ, 0 < ε → ∃ n : ℕ, 0 < n ∧ ((Ioc 0 n).filter (· ∈ A)).card / n < x + ε := by
  rw [le_iff_forall_pos_lt_add]
  

Proof state:
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
x : ℝ
⊢ (∀ (ε : ℝ), 0 < ε → schnirelmannDensity A < x + ε) ↔
    ∀ (ε : ℝ), 0 < ε → ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ A) (Ioc 0 n))) / ↑n < x + ε

Next tactic:
simp only [schnirelmannDensity_lt_iff]
lemma schnirelmannDensity_congr' {B : Set ℕ} [DecidablePred (· ∈ B)]
    (h : ∀ n > 0, n ∈ A ↔ n ∈ B) : schnirelmannDensity A = schnirelmannDensity B :=
  by 

Proof state:
A : Set ℕ
inst✝¹ : DecidablePred fun x => x ∈ A
B : Set ℕ
inst✝ : DecidablePred fun x => x ∈ B
h : ∀ n > 0, n ∈ A ↔ n ∈ B
⊢ schnirelmannDensity A = schnirelmannDensity B

Next tactic:
rw [schnirelmannDensity, schnirelmannDensity]
lemma schnirelmannDensity_congr' {B : Set ℕ} [DecidablePred (· ∈ B)]
    (h : ∀ n > 0, n ∈ A ↔ n ∈ B) : schnirelmannDensity A = schnirelmannDensity B :=
  by rw [schnirelmannDensity, schnirelmannDensity]; 

Proof state:
A : Set ℕ
inst✝¹ : DecidablePred fun x => x ∈ A
B : Set ℕ
inst✝ : DecidablePred fun x => x ∈ B
h : ∀ n > 0, n ∈ A ↔ n ∈ B
⊢ ⨅ n, ↑(card (filter (fun x => x ∈ A) (Ioc 0 ↑n))) / ↑↑n = ⨅ n, ↑(card (filter (fun x => x ∈ B) (Ioc 0 ↑n))) / ↑↑n

Next tactic:
congr
lemma schnirelmannDensity_congr' {B : Set ℕ} [DecidablePred (· ∈ B)]
    (h : ∀ n > 0, n ∈ A ↔ n ∈ B) : schnirelmannDensity A = schnirelmannDensity B :=
  by rw [schnirelmannDensity, schnirelmannDensity]; congr; 

Proof state:
case e_s
A : Set ℕ
inst✝¹ : DecidablePred fun x => x ∈ A
B : Set ℕ
inst✝ : DecidablePred fun x => x ∈ B
h : ∀ n > 0, n ∈ A ↔ n ∈ B
⊢ (fun n => ↑(card (filter (fun x => x ∈ A) (Ioc 0 ↑n))) / ↑↑n) = fun n =>
    ↑(card (filter (fun x => x ∈ B) (Ioc 0 ↑n))) / ↑↑n

Next tactic:
ext ⟨n, hn⟩
lemma 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⟩; 

Proof state:
case e_s.h.mk
A : Set ℕ
inst✝¹ : DecidablePred fun x => x ∈ A
B : Set ℕ
inst✝ : DecidablePred fun x => x ∈ B
h : ∀ n > 0, n ∈ A ↔ n ∈ B
n : ℕ
hn : 0 < n
⊢ ↑(card (filter (fun x => x ∈ A) (Ioc 0 ↑{ val := n, property := hn }))) / ↑↑{ val := n, property := hn } =
    ↑(card (filter (fun x => x ∈ B) (Ioc 0 ↑{ val := n, property := hn }))) / ↑↑{ val := n, property := hn }

Next tactic:
congr 3
lemma 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; 

Proof state:
case e_s.h.mk.e_a.e_a.e_s
A : Set ℕ
inst✝¹ : DecidablePred fun x => x ∈ A
B : Set ℕ
inst✝ : DecidablePred fun x => x ∈ B
h : ∀ n > 0, n ∈ A ↔ n ∈ B
n : ℕ
hn : 0 < n
⊢ filter (fun x => x ∈ A) (Ioc 0 ↑{ val := n, property := hn }) =
    filter (fun x => x ∈ B) (Ioc 0 ↑{ val := n, property := hn })

Next tactic:
ext x
lemma 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; 

Proof state:
case e_s.h.mk.e_a.e_a.e_s.a
A : Set ℕ
inst✝¹ : DecidablePred fun x => x ∈ A
B : Set ℕ
inst✝ : DecidablePred fun x => x ∈ B
h : ∀ n > 0, n ∈ A ↔ n ∈ B
n : ℕ
hn : 0 < n
x : ℕ
⊢ x ∈ filter (fun x => x ∈ A) (Ioc 0 ↑{ val := n, property := hn }) ↔
    x ∈ filter (fun x => x ∈ B) (Ioc 0 ↑{ val := n, property := hn })

Next tactic:
aesop
/-- The Schnirelmann density is unaffected by adding `0`. -/
@[simp] lemma schnirelmannDensity_insert_zero [DecidablePred (· ∈ insert 0 A)] :
    schnirelmannDensity (insert 0 A) = schnirelmannDensity A :=
  schnirelmannDensity_congr' (by 

Proof state:
A : Set ℕ
inst✝¹ : DecidablePred fun x => x ∈ A
inst✝ : DecidablePred fun x => x ∈ insert 0 A
⊢ ∀ n > 0, n ∈ insert 0 A ↔ n ∈ A

Next tactic:
aesop
/-- The Schnirelmann density is unaffected by removing `0`. -/
lemma schnirelmannDensity_diff_singleton_zero [DecidablePred (· ∈ A \ {0})] :
    schnirelmannDensity (A \ {0}) = schnirelmannDensity A :=
  schnirelmannDensity_congr' (by 

Proof state:
A : Set ℕ
inst✝¹ : DecidablePred fun x => x ∈ A
inst✝ : DecidablePred fun x => x ∈ A \ {0}
⊢ ∀ n > 0, n ∈ A \ {0} ↔ n ∈ A

Next tactic:
aesop
lemma schnirelmannDensity_congr {B : Set ℕ} [DecidablePred (· ∈ B)] (h : A = B) :
    schnirelmannDensity A = schnirelmannDensity B :=
  schnirelmannDensity_congr' (by 

Proof state:
A : Set ℕ
inst✝¹ : DecidablePred fun x => x ∈ A
B : Set ℕ
inst✝ : DecidablePred fun x => x ∈ B
h : A = B
⊢ ∀ n > 0, n ∈ A ↔ n ∈ B

Next tactic:
aesop
/--
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}ᶜ`.
-/
lemma exists_of_schnirelmannDensity_eq_zero {ε : ℝ} (hε : 0 < ε) (hA : schnirelmannDensity A = 0) :
    ∃ n, 0 < n ∧ ((Ioc 0 n).filter (· ∈ A)).card / n < ε := by
  

Proof state:
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
ε : ℝ
hε : 0 < ε
hA : schnirelmannDensity A = 0
⊢ ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ A) (Ioc 0 n))) / ↑n < ε

Next tactic:
by_contra! h
/--
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}ᶜ`.
-/
lemma exists_of_schnirelmannDensity_eq_zero {ε : ℝ} (hε : 0 < ε) (hA : schnirelmannDensity A = 0) :
    ∃ n, 0 < n ∧ ((Ioc 0 n).filter (· ∈ A)).card / n < ε := by
  by_contra! h
  

Proof state:
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
ε : ℝ
hε : 0 < ε
hA : schnirelmannDensity A = 0
h : ∀ (n : ℕ), 0 < n → ε ≤ ↑(card (filter (fun x => x ∈ A) (Ioc 0 n))) / ↑n
⊢ False

Next tactic:
rw [← le_schnirelmannDensity_iff] at h
/--
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}ᶜ`.
-/
lemma exists_of_schnirelmannDensity_eq_zero {ε : ℝ} (hε : 0 < ε) (hA : schnirelmannDensity A = 0) :
    ∃ n, 0 < n ∧ ((Ioc 0 n).filter (· ∈ A)).card / n < ε := by
  by_contra! h
  rw [← le_schnirelmannDensity_iff] at h
  

Proof state:
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
ε : ℝ
hε : 0 < ε
hA : schnirelmannDensity A = 0
h : ε ≤ schnirelmannDensity A
⊢ False

Next tactic:
linarith
@[simp] lemma schnirelmannDensity_empty : schnirelmannDensity ∅ = 0 :=
  schnirelmannDensity_eq_zero_of_one_not_mem (by 

Proof state:
⊢ 1 ∉ ∅

Next tactic:
simp
/-- The Schnirelmann density of any finset is `0`. -/
lemma schnirelmannDensity_finset (A : Finset ℕ) : schnirelmannDensity A = 0 := by
  

Proof state:
A : Finset ℕ
⊢ schnirelmannDensity ↑A = 0

Next tactic:
refine le_antisymm ?_ schnirelmannDensity_nonneg
/-- The Schnirelmann density of any finset is `0`. -/
lemma schnirelmannDensity_finset (A : Finset ℕ) : schnirelmannDensity A = 0 := by
  refine le_antisymm ?_ schnirelmannDensity_nonneg
  

Proof state:
A : Finset ℕ
⊢ schnirelmannDensity ↑A ≤ 0

Next tactic:
simp only [schnirelmannDensity_le_iff_forall, zero_add]
/-- The Schnirelmann density of any finset is `0`. -/
lemma schnirelmannDensity_finset (A : Finset ℕ) : schnirelmannDensity A = 0 := by
  refine le_antisymm ?_ schnirelmannDensity_nonneg
  simp only [schnirelmannDensity_le_iff_forall, zero_add]
  

Proof state:
A : Finset ℕ
⊢ ∀ (ε : ℝ), 0 < ε → ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ↑n < ε

Next tactic:
intro ε hε
/-- The Schnirelmann density of any finset is `0`. -/
lemma schnirelmannDensity_finset (A : Finset ℕ) : schnirelmannDensity A = 0 := by
  refine le_antisymm ?_ schnirelmannDensity_nonneg
  simp only [schnirelmannDensity_le_iff_forall, zero_add]
  intro ε hε
  

Proof state:
A : Finset ℕ
ε : ℝ
hε : 0 < ε
⊢ ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ↑n < ε

Next tactic:
wlog hε₁ : ε ≤ 1 generalizing ε
/-- The Schnirelmann density of any finset is `0`. -/
lemma 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 ε
  · 

Proof state:
case inr
A : Finset ℕ
ε : ℝ
hε : 0 < ε
this : ∀ (ε : ℝ), 0 < ε → ε ≤ 1 → ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ↑n < ε
hε₁ : ¬ε ≤ 1
⊢ ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ↑n < ε

Next tactic:
obtain ⟨n, hn, hn'⟩ := this 1 zero_lt_one le_rfl
/-- The Schnirelmann density of any finset is `0`. -/
lemma 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
    

Proof state:
case inr.intro.intro
A : Finset ℕ
ε : ℝ
hε : 0 < ε
this : ∀ (ε : ℝ), 0 < ε → ε ≤ 1 → ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ↑n < ε
hε₁ : ¬ε ≤ 1
n : ℕ
hn : 0 < n
hn' : ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ↑n < 1
⊢ ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ↑n < ε

Next tactic:
exact ⟨n, hn, hn'.trans_le (le_of_not_le hε₁)⟩
/-- The Schnirelmann density of any finset is `0`. -/
lemma 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_le hε₁)⟩
  

Proof state:
A : Finset ℕ
ε : ℝ
hε : 0 < ε
hε₁ : ε ≤ 1
⊢ ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ↑n < ε

Next tactic:
let n : ℕ := ⌊A.card / ε⌋₊ + 1
/-- The Schnirelmann density of any finset is `0`. -/
lemma 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_le hε₁)⟩
  let n : ℕ := ⌊A.card / ε⌋₊ + 1
  

Proof state:
A : Finset ℕ
ε : ℝ
hε : 0 < ε
hε₁ : ε ≤ 1
n : ℕ := ⌊↑(card A) / ε⌋₊ + 1
⊢ ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ↑n < ε

Next tactic:
have hn : 0 < n := Nat.succ_pos _
/-- The Schnirelmann density of any finset is `0`. -/
lemma 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_le hε₁)⟩
  let n : ℕ := ⌊A.card / ε⌋₊ + 1
  have hn : 0 < n := Nat.succ_pos _
  

Proof state:
A : Finset ℕ
ε : ℝ
hε : 0 < ε
hε₁ : ε ≤ 1
n : ℕ := ⌊↑(card A) / ε⌋₊ + 1
hn : 0 < n
⊢ ∃ n, 0 < n ∧ ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ↑n < ε

Next tactic:
use n, hn
/-- The Schnirelmann density of any finset is `0`. -/
lemma 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_le hε₁)⟩
  let n : ℕ := ⌊A.card / ε⌋₊ + 1
  have hn : 0 < n := Nat.succ_pos _
  use n, hn
  

Proof state:
case right
A : Finset ℕ
ε : ℝ
hε : 0 < ε
hε₁ : ε ≤ 1
n : ℕ := ⌊↑(card A) / ε⌋₊ + 1
hn : 0 < n
⊢ ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ↑n < ε

Next tactic:
rw [div_lt_iff (Nat.cast_pos.2 hn), ← div_lt_iff' hε, Nat.cast_add_one]
/-- The Schnirelmann density of any finset is `0`. -/
lemma 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_le hε₁)⟩
  let n : ℕ := ⌊A.card / ε⌋₊ + 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]
  

Proof state:
case right
A : Finset ℕ
ε : ℝ
hε : 0 < ε
hε₁ : ε ≤ 1
n : ℕ := ⌊↑(card A) / ε⌋₊ + 1
hn : 0 < n
⊢ ↑(card (filter (fun x => x ∈ ↑A) (Ioc 0 n))) / ε < ↑⌊↑(card A) / ε⌋₊ + 1

Next tactic:
exact (Nat.lt_floor_add_one _).trans_le' <| div_le_div_of_le hε.le <| Nat.cast_le.2 <|
    card_le_of_subset <| by simp [subset_iff]
/-- The Schnirelmann density of any finset is `0`. -/
lemma 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_le hε₁)⟩
  let n : ℕ := ⌊A.card / ε⌋₊ + 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' <| div_le_div_of_le hε.le <| Nat.cast_le.2 <|
    card_le_of_subset <| by 

Proof state:
A : Finset ℕ
ε : ℝ
hε : 0 < ε
hε₁ : ε ≤ 1
n : ℕ := ⌊↑(card A) / ε⌋₊ + 1
hn : 0 < n
⊢ filter (fun x => x ∈ ↑A) (Ioc 0 n) ⊆ A

Next tactic:
simp [subset_iff]
/-- The Schnirelmann density of any finite set is `0`. -/
lemma schnirelmannDensity_finite {A : Set ℕ} [DecidablePred (· ∈ A)] (hA : A.Finite) :
    schnirelmannDensity A = 0 := by 

Proof state:
A : Set ℕ
inst✝ : DecidablePred fun x => x ∈ A
hA : Set.Finite A
⊢ schnirelmannDensity A = 0

Next tactic:
simpa using schnirelmannDensity_finset hA.toFinset
@[simp] lemma schnirelmannDensity_univ : schnirelmannDensity Set.univ = 1 :=
  (schnirelmannDensity_eq_one_iff_of_zero_mem (by 

Proof state:
⊢ 0 ∈ Set.univ

Next tactic:
simp
@[simp] lemma schnirelmannDensity_univ : schnirelmannDensity Set.univ = 1 :=
  (schnirelmannDensity_eq_one_iff_of_zero_mem (by simp)).2 (by 

Proof state:
⊢ Set.univ = Set.univ

Next tactic:
simp
lemma schnirelmannDensity_setOf_even : schnirelmannDensity (setOf Even) = 0 :=
  schnirelmannDensity_eq_zero_of_one_not_mem $ by 

Proof state:
⊢ 1 ∉ setOf Even

Next tactic:
simp
lemma schnirelmannDensity_setOf_prime : schnirelmannDensity (setOf Nat.Prime) = 0 :=
  schnirelmannDensity_eq_zero_of_one_not_mem $ by 

Proof state:
⊢ 1 ∉ setOf Nat.Prime

Next tactic:
simp [Nat.not_prime_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.
-/
lemma schnirelmannDensity_setOf_mod_eq_one {m : ℕ} (hm : m ≠ 1) :
    schnirelmannDensity {n | n % m = 1} = (m⁻¹ : ℝ) := by
  

Proof state:
m : ℕ
hm : m ≠ 1
⊢ schnirelmannDensity {n | n % m = 1} = (↑m)⁻¹

Next tactic:
rcases m.eq_zero_or_pos with rfl | hm'
/--
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.
-/
lemma 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'
  · 

Proof state:
case inl
hm : 0 ≠ 1
⊢ schnirelmannDensity {n | n % 0 = 1} = (↑0)⁻¹

Next tactic:
simp only [Nat.cast_zero, inv_zero]
/--
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.
-/
lemma 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]
    

Proof state:
case inl
hm : 0 ≠ 1
⊢ schnirelmannDensity {n | n % 0 = 1} = 0

Next tactic:
refine schnirelmannDensity_finite ?_
/--
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.
-/
lemma 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 ?_
    

Proof state:
case inl
hm : 0 ≠ 1
⊢ Set.Finite {n | n % 0 = 1}

Next tactic:
simp
/--
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.
-/
lemma 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
  

Proof state:
case inr
m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ schnirelmannDensity {n | n % m = 1} = (↑m)⁻¹

Next tactic:
apply le_antisymm (schnirelmannDensity_le_of_le m hm'.ne' _) _
/--
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.
-/
lemma 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' _) _
  · 

Proof state:
m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ ↑(card (filter (fun x => x ∈ {n | n % m = 1}) (Ioc 0 m))) / ↑m ≤ (↑m)⁻¹

Next tactic:
rw [← one_div]