Theorem: Int.image_Ico_emod
File: Mathlib/Data/Int/Interval.lean

tactic: obtain rfl | ha := eq_or_lt_of_le h
state_before: a✝ b n a : ℤ
h : 0 ≤ a
⊢ image (fun x => x % a) (Ico n (n + a)) = Ico 0 a

tactic: ext i
state_before: case inr
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
⊢ image (fun x => x % a) (Ico n (n + a)) = Ico 0 a

tactic: simp only [mem_image, mem_range, mem_Ico]
state_before: case inr.a
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
⊢ i ∈ image (fun x => x % a) (Ico n (n + a)) ↔ i ∈ Ico 0 a

tactic: constructor
state_before: case inr.a
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
⊢ (∃ a_1, (n ≤ a_1 ∧ a_1 < n + a) ∧ a_1 % a = i) ↔ 0 ≤ i ∧ i < a

tactic: intro hia
state_before: case inr.a.mpr
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
⊢ 0 ≤ i ∧ i < a → ∃ a_2, (n ≤ a_2 ∧ a_2 < n + a) ∧ a_2 % a = i

tactic: have hn := Int.emod_add_ediv n a
state_before: case inr.a.mpr
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
⊢ ∃ a_1, (n ≤ a_1 ∧ a_1 < n + a) ∧ a_1 % a = i

tactic: obtain hi | hi := lt_or_le i (n % a)
state_before: case inr.a.mpr
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
⊢ ∃ a_1, (n ≤ a_1 ∧ a_1 < n + a) ∧ a_1 % a = i

tactic: simp
state_before: case inl
a b n : ℤ
h : 0 ≤ 0
⊢ image (fun x => x % 0) (Ico n (n + 0)) = Ico 0 0

tactic: rintro ⟨i, _, rfl⟩
state_before: case inr.a.mp
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
⊢ (∃ a_1, (n ≤ a_1 ∧ a_1 < n + a) ∧ a_1 % a = i) → 0 ≤ i ∧ i < a

tactic: exact ⟨emod_nonneg i ha.ne', emod_lt_of_pos i ha⟩
state_before: case inr.a.mp.intro.intro
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
left✝ : n ≤ i ∧ i < n + a
⊢ 0 ≤ i % a ∧ i % a < a

tactic: refine' ⟨i + a * (n / a + 1), ⟨_, _⟩, _⟩
state_before: case inr.a.mpr.inl
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : i < n % a
⊢ ∃ a_1, (n ≤ a_1 ∧ a_1 < n + a) ∧ a_1 % a = i

tactic: rw [add_comm (n / a), mul_add, mul_one, ← add_assoc]
state_before: case inr.a.mpr.inl.refine'_1
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : i < n % a
⊢ n ≤ i + a * (n / a + 1)

tactic: refine' hn.symm.le.trans (add_le_add_right _ _)
state_before: case inr.a.mpr.inl.refine'_1
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : i < n % a
⊢ n ≤ i + a + a * (n / a)

tactic: simpa only [zero_add] using add_le_add hia.left (Int.emod_lt_of_pos n ha).le
state_before: case inr.a.mpr.inl.refine'_1
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : i < n % a
⊢ n % a ≤ i + a

tactic: refine' lt_of_lt_of_le (add_lt_add_right hi (a * (n / a + 1))) _
state_before: case inr.a.mpr.inl.refine'_2
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : i < n % a
⊢ i + a * (n / a + 1) < n + a

tactic: rw [mul_add, mul_one, ← add_assoc, hn]
state_before: case inr.a.mpr.inl.refine'_2
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : i < n % a
⊢ n % a + a * (n / a + 1) ≤ n + a

tactic: rw [Int.add_mul_emod_self_left, Int.emod_eq_of_lt hia.left hia.right]
state_before: case inr.a.mpr.inl.refine'_3
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : i < n % a
⊢ (i + a * (n / a + 1)) % a = i

tactic: refine' ⟨i + a * (n / a), ⟨_, _⟩, _⟩
state_before: case inr.a.mpr.inr
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : n % a ≤ i
⊢ ∃ a_1, (n ≤ a_1 ∧ a_1 < n + a) ∧ a_1 % a = i

tactic: exact hn.symm.le.trans (add_le_add_right hi _)
state_before: case inr.a.mpr.inr.refine'_1
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : n % a ≤ i
⊢ n ≤ i + a * (n / a)

tactic: rw [add_comm n a]
state_before: case inr.a.mpr.inr.refine'_2
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : n % a ≤ i
⊢ i + a * (n / a) < n + a

tactic: refine' add_lt_add_of_lt_of_le hia.right (le_trans _ hn.le)
state_before: case inr.a.mpr.inr.refine'_2
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : n % a ≤ i
⊢ i + a * (n / a) < a + n

tactic: simp only [zero_le, le_add_iff_nonneg_left]
state_before: case inr.a.mpr.inr.refine'_2
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : n % a ≤ i
⊢ a * (n / a) ≤ n % a + a * (n / a)

tactic: exact Int.emod_nonneg n (ne_of_gt ha)
state_before: case inr.a.mpr.inr.refine'_2
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : n % a ≤ i
⊢ 0 ≤ n % a

tactic: rw [Int.add_mul_emod_self_left, Int.emod_eq_of_lt hia.left hia.right]
state_before: case inr.a.mpr.inr.refine'_3
a✝ b n a : ℤ
h : 0 ≤ a
ha : 0 < a
i : ℤ
hia : 0 ≤ i ∧ i < a
hn : n % a + a * (n / a) = n
hi : n % a ≤ i
⊢ (i + a * (n / a)) % a = i