@@ -36,7 +36,7 @@ private theorem div.go.fuel_congr (x y fuel1 fuel2 : Nat) (hy : 0 < y) (h1 : x <
3636 next => rfl
3737termination_by structural fuel1
3838
39- theorem div_eq (x y : Nat) : x / y = if 0 < y ∧ y ≤ x then (x - y) / y + 1 else 0 := by
39+ theorem div_eq_ite (x y : Nat) : x / y = if 0 < y ∧ y ≤ x then (x - y) / y + 1 else 0 := by
4040 change Nat.div _ _ = ite _ (Nat.div _ _ + 1 ) _
4141 unfold Nat.div
4242 split
@@ -52,6 +52,10 @@ theorem div_eq (x y : Nat) : x / y = if 0 < y ∧ y ≤ x then (x - y) / y + 1 e
5252 next =>
5353 simp only [false_and, ↓reduceIte, *]
5454
55+ @ [deprecated div_eq_ite (since := "2026-07-20" )]
56+ theorem div_eq (x y : Nat) : x / y = if 0 < y ∧ y ≤ x then (x - y) / y + 1 else 0 :=
57+ Nat.div_eq_ite x y
58+
5559/--
5660An induction principle customized for reasoning about the recursion pattern of natural number
5761division by iterated subtraction.
@@ -71,7 +75,7 @@ decreasing_by apply div_rec_lemma; assumption
7175theorem div_le_self (n k : Nat) : n / k ≤ n := by
7276 induction n using Nat.strongRecOn with
7377 | ind n ih =>
74- rw [div_eq ]
78+ rw [div_eq_ite ]
7579 -- Note: manual split to avoid Classical.em which is not yet defined
7680 cases (inferInstance : Decidable (0 < k ∧ k ≤ n)) with
7781 | isFalse h => simp [h]
@@ -83,7 +87,7 @@ theorem div_le_self (n k : Nat) : n / k ≤ n := by
8387 exact succ_le_of_lt (Nat.lt_of_le_of_lt this hSub)
8488
8589theorem div_lt_self {n k : Nat} (hLtN : 0 < n) (hLtK : 1 < k) : n / k < n := by
86- rw [div_eq ]
90+ rw [div_eq_ite ]
8791 cases (inferInstance : Decidable (0 < k ∧ k ≤ n)) with
8892 | isFalse h => simp [hLtN, h]
8993 | isTrue h =>
@@ -155,9 +159,13 @@ protected theorem modCore_eq_mod (n m : Nat) : Nat.modCore n m = n % m := by
155159 rw [Nat.modCore_eq]
156160 exact if_neg fun ⟨_hlt, hle⟩ => h hle
157161
158- theorem mod_eq (x y : Nat) : x % y = if 0 < y ∧ y ≤ x then (x - y) % y else x := by
162+ theorem mod_eq_ite (x y : Nat) : x % y = if 0 < y ∧ y ≤ x then (x - y) % y else x := by
159163 rw [←Nat.modCore_eq_mod, ←Nat.modCore_eq_mod, Nat.modCore_eq]
160164
165+ @ [deprecated mod_eq_ite (since := "2026-07-20" )]
166+ theorem mod_eq (x y : Nat) : x % y = if 0 < y ∧ y ≤ x then (x - y) % y else x :=
167+ Nat.mod_eq_ite x y
168+
161169/--
162170An induction principle customized for reasoning about the recursion pattern of `Nat.mod`.
163171-/
@@ -173,13 +181,13 @@ def mod.inductionOn.{u}
173181 have : (if 0 < 0 ∧ 0 ≤ a then (a - 0 ) % 0 else a) = a :=
174182 have h : ¬ (0 < 0 ∧ 0 ≤ a) := fun ⟨h₁, _⟩ => absurd h₁ (Nat.lt_irrefl _)
175183 if_neg h
176- (mod_eq a 0 ).symm ▸ this
184+ (mod_eq_ite a 0 ).symm ▸ this
177185
178186theorem mod_eq_of_lt {a b : Nat} (h : a < b) : a % b = a :=
179187 have : (if 0 < b ∧ b ≤ a then (a - b) % b else a) = a :=
180188 have h' : ¬(0 < b ∧ b ≤ a) := fun ⟨_, h₁⟩ => absurd h₁ (Nat.not_le_of_gt h)
181189 if_neg h'
182- (mod_eq a b).symm ▸ this
190+ (mod_eq_ite a b).symm ▸ this
183191
184192@[simp] theorem one_mod_eq_zero_iff {n : Nat} : 1 % n = 0 ↔ n = 1 := by
185193 match n with
@@ -197,7 +205,7 @@ theorem mod_eq_of_lt {a b : Nat} (h : a < b) : a % b = a :=
197205theorem mod_eq_sub_mod {a b : Nat} (h : a ≥ b) : a % b = (a - b) % b :=
198206 match eq_zero_or_pos b with
199207 | Or.inl h₁ => h₁.symm ▸ (Nat.sub_zero a).symm ▸ rfl
200- | Or.inr h₁ => (mod_eq a b).symm ▸ if_pos ⟨h₁, h⟩
208+ | Or.inr h₁ => (mod_eq_ite a b).symm ▸ if_pos ⟨h₁, h⟩
201209
202210@[simp] protected theorem sub_mod_add_mod_cancel (a b : Nat) [NeZero a] : a - b % a + b % a = a := by
203211 rw [Nat.sub_add_cancel]
@@ -231,7 +239,7 @@ theorem mod_one (x : Nat) : x % 1 = 0 := by
231239 exact this _ h
232240
233241theorem div_add_mod (m n : Nat) : n * (m / n) + m % n = m := by
234- rw [div_eq, mod_eq ]
242+ rw [div_eq_ite, mod_eq_ite ]
235243 have h : Decidable (0 < n ∧ n ≤ m) := inferInstance
236244 cases h with
237245 | isFalse h => simp [h]
@@ -242,10 +250,10 @@ theorem div_add_mod (m n : Nat) : n * (m / n) + m % n = m := by
242250decreasing_by apply div_rec_lemma; assumption
243251
244252theorem div_eq_sub_div (h₁ : 0 < b) (h₂ : b ≤ a) : a / b = (a - b) / b + 1 := by
245- rw [div_eq a, if_pos]; constructor <;> assumption
253+ rw [div_eq_ite a, if_pos]; constructor <;> assumption
246254
247255theorem mod_add_div (m k : Nat) : m % k + k * (m / k) = m := by
248- induction m, k using mod.inductionOn with rw [div_eq, mod_eq ]
256+ induction m, k using mod.inductionOn with rw [div_eq_ite, mod_eq_ite ]
249257 | base x y h => simp [h]
250258 | ind x y h IH => simp [h]; rw [Nat.mul_succ, ← Nat.add_assoc, IH, Nat.sub_add_cancel h.2 ]
251259
@@ -263,14 +271,14 @@ theorem mod_eq_sub_div_mul {x k : Nat} : x % k = x - (x / k) * k := by
263271 rwa [mod_one, Nat.zero_add, Nat.one_mul] at this
264272
265273@[simp] protected theorem div_zero (n : Nat) : n / 0 = 0 := by
266- rw [div_eq ]; simp [Nat.lt_irrefl]
274+ rw [div_eq_ite ]; simp [Nat.lt_irrefl]
267275
268276@[simp] protected theorem zero_div (b : Nat) : 0 / b = 0 :=
269- (div_eq 0 b).trans <| if_neg <| And.rec Nat.not_le_of_gt
277+ (div_eq_ite 0 b).trans <| if_neg <| And.rec Nat.not_le_of_gt
270278
271279theorem le_div_iff_mul_le (k0 : 0 < k) : x ≤ y / k ↔ x * k ≤ y := by
272280 induction y, k using mod.inductionOn generalizing x with
273- (rw [div_eq ]; simp [h]; cases x with | zero => simp [zero_le] | succ x => ?_)
281+ (rw [div_eq_ite ]; simp [h]; cases x with | zero => simp [zero_le] | succ x => ?_)
274282 | base y k h =>
275283 simp only [add_one, succ_mul, false_iff, Nat.not_le, Nat.succ_ne_zero]
276284 refine Nat.lt_of_lt_of_le ?_ (Nat.le_add_left ..)
@@ -412,7 +420,7 @@ theorem mul_mod_mul_left (z x y : Nat) : (z * x) % (z * y) = z * (x % y) :=
412420 exact IH _ (sub_lt (Nat.lt_of_lt_of_le y0 yn) y0)
413421
414422theorem div_eq_of_lt (h₀ : a < b) : a / b = 0 := by
415- rw [div_eq a, if_neg]
423+ rw [div_eq_ite a, if_neg]
416424 intro h₁
417425 apply Nat.not_le_of_gt h₀ h₁.right
418426
0 commit comments