Theorem: schnirelmannDensity_setOf_mod_eq_one
File: Mathlib/Combinatorics/Schnirelmann.lean

tactic: rcases m.eq_zero_or_pos with rfl | hm'
state_before: m : ℕ
hm : m ≠ 1
⊢ schnirelmannDensity {n | n % m = 1} = (↑m)⁻¹
state_after: case inl
hm : 0 ≠ 1
⊢ schnirelmannDensity {n | n % 0 = 1} = (↑0)⁻¹

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

tactic: apply le_antisymm (schnirelmannDensity_le_of_le m hm'.ne' _) _
state_before: case inr
m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ schnirelmannDensity {n | n % m = 1} = (↑m)⁻¹
state_after: m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ ↑(filter (fun x => x ∈ {n | n % m = 1}) (Ioc 0 m)).card / ↑m ≤ (↑m)⁻¹

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

tactic: rw [le_schnirelmannDensity_iff]
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ (↑m)⁻¹ ≤ schnirelmannDensity {n | n % m = 1}
state_after: m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ ∀ (n : ℕ), 0 < n → (↑m)⁻¹ ≤ ↑(filter (fun x => x ∈ {n | n % m = 1}) (Ioc 0 n)).card / ↑n

tactic: intro n hn
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ ∀ (n : ℕ), 0 < n → (↑m)⁻¹ ≤ ↑(filter (fun x => x ∈ {n | n % m = 1}) (Ioc 0 n)).card / ↑n
state_after: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
⊢ (↑m)⁻¹ ≤ ↑(filter (fun x => x ∈ {n | n % m = 1}) (Ioc 0 n)).card / ↑n

tactic: simp only [Set.mem_setOf_eq]
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
⊢ (↑m)⁻¹ ≤ ↑(filter (fun x => x ∈ {n | n % m = 1}) (Ioc 0 n)).card / ↑n
state_after: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
⊢ (↑m)⁻¹ ≤ ↑(filter (fun x => x % m = 1) (Ioc 0 n)).card / ↑n

tactic: rw [le_div_iff (Nat.cast_pos.2 hn), mul_comm, ← div_eq_mul_inv]
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
⊢ (↑m)⁻¹ ≤ ↑(filter (fun x => x % m = 1) (Ioc 0 n)).card / ↑n
state_after: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
⊢ ↑n / ↑m ≤ ↑(filter (fun x => x % m = 1) (Ioc 0 n)).card

tactic: apply (Nat.cast_le.2 (card_le_card this)).trans'
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
⊢ ↑n / ↑m ≤ ↑(filter (fun x => x % m = 1) (Ioc 0 n)).card
state_after: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
⊢ ↑n / ↑m ≤ ↑(image (fun x => x * m + 1) (Icc 0 ((n - 1) / m))).card

tactic: 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 (α := ℕ)]
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
⊢ ↑n / ↑m ≤ ↑(image (fun x => x * m + 1) (Icc 0 ((n - 1) / m))).card
state_after: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
⊢ n ≤ (n - 1) / m * m + m

case H
m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
⊢ Function.Injective fun x => x * m + 1

tactic: intro a b
state_before: case H
m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
⊢ Function.Injective fun x => x * m + 1
state_after: case H
m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
a b : ℕ
⊢ (fun x => x * m + 1) a = (fun x => x * m + 1) b → a = b

tactic: simp [hm'.ne']
state_before: case H
m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
a b : ℕ
⊢ (fun x => x * m + 1) a = (fun x => x * m + 1) b → a = b
state_after: no goals

tactic: simp only [Nat.cast_zero, inv_zero]
state_before: case inl
hm : 0 ≠ 1
⊢ schnirelmannDensity {n | n % 0 = 1} = (↑0)⁻¹
state_after: case inl
hm : 0 ≠ 1
⊢ schnirelmannDensity {n | n % 0 = 1} = 0

tactic: refine schnirelmannDensity_finite ?_
state_before: case inl
hm : 0 ≠ 1
⊢ schnirelmannDensity {n | n % 0 = 1} = 0
state_after: case inl
hm : 0 ≠ 1
⊢ {n | n % 0 = 1}.Finite

tactic: simp
state_before: case inl
hm : 0 ≠ 1
⊢ {n | n % 0 = 1}.Finite
state_after: no goals

tactic: rw [← one_div, ← @Nat.cast_one ℝ]
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ ↑(filter (fun x => x ∈ {n | n % m = 1}) (Ioc 0 m)).card / ↑m ≤ (↑m)⁻¹
state_after: m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ ↑(filter (fun x => x ∈ {n | n % m = 1}) (Ioc 0 m)).card / ↑m ≤ ↑1 / ↑m

tactic: gcongr
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ ↑(filter (fun x => x ∈ {n | n % m = 1}) (Ioc 0 m)).card / ↑m ≤ ↑1 / ↑m
state_after: case hab.h
m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ (filter (fun x => x ∈ {n | n % m = 1}) (Ioc 0 m)).card ≤ 1

tactic: simp only [Set.mem_setOf_eq, card_le_one_iff_subset_singleton, subset_iff,
  mem_filter, mem_Ioc, mem_singleton, and_imp]
state_before: case hab.h
m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ (filter (fun x => x ∈ {n | n % m = 1}) (Ioc 0 m)).card ≤ 1
state_after: case hab.h
m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ ∃ x, ∀ ⦃x_1 : ℕ⦄, 0 < x_1 → x_1 ≤ m → x_1 % m = 1 → x_1 = x

tactic: use 1
state_before: case hab.h
m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ ∃ x, ∀ ⦃x_1 : ℕ⦄, 0 < x_1 → x_1 ≤ m → x_1 % m = 1 → x_1 = x
state_after: case h
m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ ∀ ⦃x : ℕ⦄, 0 < x → x ≤ m → x % m = 1 → x = 1

tactic: intro x _ hxm h
state_before: case h
m : ℕ
hm : m ≠ 1
hm' : m > 0
⊢ ∀ ⦃x : ℕ⦄, 0 < x → x ≤ m → x % m = 1 → x = 1
state_after: case h
m : ℕ
hm : m ≠ 1
hm' : m > 0
x : ℕ
a✝ : 0 < x
hxm : x ≤ m
h : x % m = 1
⊢ x = 1

tactic: rcases eq_or_lt_of_le hxm with rfl | hxm'
state_before: case h
m : ℕ
hm : m ≠ 1
hm' : m > 0
x : ℕ
a✝ : 0 < x
hxm : x ≤ m
h : x % m = 1
⊢ x = 1
state_after: case h.inl
x : ℕ
a✝ : 0 < x
hm : x ≠ 1
hm' : x > 0
hxm : x ≤ x
h : x % x = 1
⊢ x = 1

case h.inr
m : ℕ
hm : m ≠ 1
hm' : m > 0
x : ℕ
a✝ : 0 < x
hxm : x ≤ m
h : x % m = 1
hxm' : x < m
⊢ x = 1

tactic: rwa [Nat.mod_eq_of_lt hxm'] at h
state_before: case h.inr
m : ℕ
hm : m ≠ 1
hm' : m > 0
x : ℕ
a✝ : 0 < x
hxm : x ≤ m
h : x % m = 1
hxm' : x < m
⊢ x = 1
state_after: no goals

tactic: simp at h
state_before: case h.inl
x : ℕ
a✝ : 0 < x
hm : x ≠ 1
hm' : x > 0
hxm : x ≤ x
h : x % x = 1
⊢ x = 1
state_after: no goals

tactic: simp only [subset_iff, mem_image, forall_exists_index, mem_filter, mem_Ioc, mem_Icc, and_imp]
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
⊢ image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
state_after: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
⊢ ∀ ⦃x : ℕ⦄ (x_1 : ℕ), 0 ≤ x_1 → x_1 ≤ (n - 1) / m → x_1 * m + 1 = x → (0 < x ∧ x ≤ n) ∧ x % m = 1

tactic: rintro _ y _ hy' rfl
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
⊢ ∀ ⦃x : ℕ⦄ (x_1 : ℕ), 0 ≤ x_1 → x_1 ≤ (n - 1) / m → x_1 * m + 1 = x → (0 < x ∧ x ≤ n) ∧ x % m = 1
state_after: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
y : ℕ
a✝ : 0 ≤ y
hy' : y ≤ (n - 1) / m
⊢ (0 < y * m + 1 ∧ y * m + 1 ≤ n) ∧ (y * m + 1) % m = 1

tactic: have hm : 2 ≤ m := hm.lt_of_le' hm'
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
y : ℕ
a✝ : 0 ≤ y
hy' : y ≤ (n - 1) / m
⊢ (0 < y * m + 1 ∧ y * m + 1 ≤ n) ∧ (y * m + 1) % m = 1
state_after: m : ℕ
hm✝ : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
y : ℕ
a✝ : 0 ≤ y
hy' : y ≤ (n - 1) / m
hm : 2 ≤ m
⊢ (0 < y * m + 1 ∧ y * m + 1 ≤ n) ∧ (y * m + 1) % m = 1

tactic: 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]
state_before: m : ℕ
hm✝ : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
y : ℕ
a✝ : 0 ≤ y
hy' : y ≤ (n - 1) / m
hm : 2 ≤ m
⊢ (0 < y * m + 1 ∧ y * m + 1 ≤ n) ∧ (y * m + 1) % m = 1
state_after: m : ℕ
hm✝ : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
y : ℕ
a✝ : 0 ≤ y
hy' : y ≤ (n - 1) / m
hm : 2 ≤ m
⊢ y * m ≤ n - Nat.succ 0

tactic: exact Nat.mul_le_of_le_div _ _ _ hy'
state_before: m : ℕ
hm✝ : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
y : ℕ
a✝ : 0 ≤ y
hy' : y ≤ (n - 1) / m
hm : 2 ≤ m
⊢ y * m ≤ n - Nat.succ 0
state_after: no goals

tactic: have := @Nat.lt_div_mul_add n.pred m hm'
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
⊢ n ≤ (n - 1) / m * m + m
state_after: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this✝ : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
this : n.pred < n.pred / m * m + m
⊢ n ≤ (n - 1) / m * m + m

tactic: rwa [← Nat.succ_le, Nat.succ_pred hn.ne'] at this
state_before: m : ℕ
hm : m ≠ 1
hm' : m > 0
n : ℕ
hn : 0 < n
this✝ : image (fun x => x * m + 1) (Icc 0 ((n - 1) / m)) ⊆ filter (fun x => x % m = 1) (Ioc 0 n)
this : n.pred < n.pred / m * m + m
⊢ n ≤ (n - 1) / m * m + m
state_after: no goals