Theorem: Nat.Ico_filter_coprime_le
File: Mathlib/Data/Nat/Totient.lean

tactic: conv_lhs => rw [← Nat.mod_add_div n a]
state_before: a k n : ℕ
a_pos : 0 < a
⊢ card (filter (coprime a) (Ico k (k + n))) ≤ φ a * (n / a + 1)

tactic: induction' n / a with i ih
state_before: a k n : ℕ
a_pos : 0 < a
⊢ card (filter (coprime a) (Ico k (k + (n % a + a * (n / a))))) ≤ φ a * (n / a + 1)

tactic: simp only [mul_succ]
state_before: case succ
a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + (n % a + a * i)))) ≤ φ a * (i + 1)
⊢ card (filter (coprime a) (Ico k (k + (n % a + a * succ i)))) ≤ φ a * (succ i + 1)

tactic: simp_rw [← add_assoc] at ih ⊢
state_before: case succ
a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + (n % a + a * i)))) ≤ φ a * (i + 1)
⊢ card (filter (coprime a) (Ico k (k + (n % a + (a * i + a))))) ≤ φ a * i + φ a + φ a

tactic: calc
  (filter a.coprime (Ico k (k + n % a + a * i + a))).card = (filter a.coprime
      (Ico k (k + n % a + a * i) ∪ Ico (k + n % a + a * i) (k + n % a + a * i + a))).card := by
    congr
    rw [Ico_union_Ico_eq_Ico]
    rw [add_assoc]
    exact le_self_add
    exact le_self_add
  _ ≤ (filter a.coprime (Ico k (k + n % a + a * i))).card + a.totient := by
    rw [filter_union, ← filter_coprime_Ico_eq_totient a (k + n % a + a * i)]
    apply card_union_le
  _ ≤ a.totient * i + a.totient + a.totient := add_le_add_right ih (totient a)
state_before: case succ
a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + n % a + a * i))) ≤ φ a * (i + 1)
⊢ card (filter (coprime a) (Ico k (k + n % a + a * i + a))) ≤ φ a * i + φ a + φ a

tactic: rw [← filter_coprime_Ico_eq_totient a k]
state_before: case zero
a k n : ℕ
a_pos : 0 < a
⊢ card (filter (coprime a) (Ico k (k + (n % a + a * zero)))) ≤ φ a * (zero + 1)

tactic: simp only [add_zero, mul_one, MulZeroClass.mul_zero, le_of_lt (mod_lt n a_pos),
  Nat.zero_eq, zero_add]
state_before: case zero
a k n : ℕ
a_pos : 0 < a
⊢ card (filter (coprime a) (Ico k (k + (n % a + a * zero)))) ≤ card (filter (coprime a) (Ico k (k + a))) * (zero + 1)

tactic: refine Finset.card_mono ?_
state_before: case zero
a k n : ℕ
a_pos : 0 < a
⊢ card (filter (coprime a) (Ico k (k + n % a))) ≤ card (filter (coprime a) (Ico k (k + a)))

tactic: refine' monotone_filter_left a.coprime _
state_before: case zero
a k n : ℕ
a_pos : 0 < a
⊢ filter (coprime a) (Ico k (k + n % a)) ≤ filter (coprime a) (Ico k (k + a))

tactic: simp only [Finset.le_eq_subset]
state_before: case zero
a k n : ℕ
a_pos : 0 < a
⊢ Ico k (k + n % a) ≤ Ico k (k + a)

tactic: exact Ico_subset_Ico rfl.le (add_le_add_left (le_of_lt (mod_lt n a_pos)) k)
state_before: case zero
a k n : ℕ
a_pos : 0 < a
⊢ Ico k (k + n % a) ⊆ Ico k (k + a)

tactic: congr
state_before: a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + n % a + a * i))) ≤ φ a * (i + 1)
⊢ card (filter (coprime a) (Ico k (k + n % a + a * i + a))) =
    card (filter (coprime a) (Ico k (k + n % a + a * i) ∪ Ico (k + n % a + a * i) (k + n % a + a * i + a)))

tactic: rw [Ico_union_Ico_eq_Ico]
state_before: case e_s.e_s
a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + n % a + a * i))) ≤ φ a * (i + 1)
⊢ Ico k (k + n % a + a * i + a) = Ico k (k + n % a + a * i) ∪ Ico (k + n % a + a * i) (k + n % a + a * i + a)

tactic: rw [add_assoc]
state_before: case e_s.e_s.hab
a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + n % a + a * i))) ≤ φ a * (i + 1)
⊢ k ≤ k + n % a + a * i

case e_s.e_s.hbc
a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + n % a + a * i))) ≤ φ a * (i + 1)
⊢ k + n % a + a * i ≤ k + n % a + a * i + a

tactic: exact le_self_add
state_before: case e_s.e_s.hab
a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + n % a + a * i))) ≤ φ a * (i + 1)
⊢ k ≤ k + (n % a + a * i)

case e_s.e_s.hbc
a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + n % a + a * i))) ≤ φ a * (i + 1)
⊢ k + n % a + a * i ≤ k + n % a + a * i + a

tactic: exact le_self_add
state_before: case e_s.e_s.hbc
a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + n % a + a * i))) ≤ φ a * (i + 1)
⊢ k + n % a + a * i ≤ k + n % a + a * i + a

tactic: rw [filter_union, ← filter_coprime_Ico_eq_totient a (k + n % a + a * i)]
state_before: a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + n % a + a * i))) ≤ φ a * (i + 1)
⊢ card (filter (coprime a) (Ico k (k + n % a + a * i) ∪ Ico (k + n % a + a * i) (k + n % a + a * i + a))) ≤
    card (filter (coprime a) (Ico k (k + n % a + a * i))) + φ a

tactic: apply card_union_le
state_before: a k n : ℕ
a_pos : 0 < a
i : ℕ
ih : card (filter (coprime a) (Ico k (k + n % a + a * i))) ≤ φ a * (i + 1)
⊢ card
      (filter (coprime a) (Ico k (k + n % a + a * i)) ∪
        filter (coprime a) (Ico (k + n % a + a * i) (k + n % a + a * i + a))) ≤
    card (filter (coprime a) (Ico k (k + n % a + a * i))) +
      card (filter (coprime a) (Ico (k + n % a + a * i) (k + n % a + a * i + a)))