Skip to content

Commit f5362da

Browse files
committed
chore: replace single-subgoal cases' (leanprover-community#21976)
Replace uses of `cases'` that generate only one subgoal with `obtain` (or `rcases` if it is of the form `cases' h : f x`). ```python #!/usr/bin/env python3 import re keys = {} with open("cases-uses", 'r') as f: for l in f: filename, line_n, col_n, rest = l.split(':', maxsplit=3) i = int(line_n)-1 col_n = int(col_n) head, sep, n_subgoals = rest.strip().rpartition(' ') n_subgoals = int(n_subgoals) assert head.endswith(']') head, sep, newvars = head[:-1].rpartition(' [') assert sep newvars = newvars.split(', ') if filename not in keys: keys[filename] = {} if i not in keys[filename]: keys[filename][i] = {} keys[filename][i].update({col_n: (head, newvars, n_subgoals)}) for (filename, d) in keys.items(): with open(filename, 'r') as f: lines = f.readlines() for (i, t) in d.items(): line = lines[i] for (col_n, (head, newvars, n_subgoals)) in t.items(): cases_re = re.compile(rf"cases' (.*?) with " + " ".join(newvars)) def rf(m): if n_subgoals == 1: if ':' not in m[1]: return f"obtain ⟨{', '.join(newvars)}⟩ := {m[1]}" return f"rcases {m[1]} with ⟨{', '.join(newvars)}⟩" return m[0] line = cases_re.sub(rf, line, 1) lines[i] = line with open(filename, 'w') as f: f.write("".join(lines)) ``` The version of `cases-uses` used for this replacement was extracted from [this run](https://github.com/leanprover-community/mathlib4/actions/runs/13362153558/job/37313542212) and is available [here](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/The.20plan.20to.20remove.20cases'/near/500097792).
1 parent ad8e0f1 commit f5362da

File tree

104 files changed

+225
-248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+225
-248
lines changed

Archive/Imo/Imo2008Q3.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ theorem p_lemma (p : ℕ) (hpp : Nat.Prime p) (hp_mod_4_eq_1 : p ≡ 1 [MOD 4])
4848
have hnat₃ : p ≥ 2 * n := by omega
4949
set k : ℕ := p - 2 * n with hnat₄
5050
have hnat₅ : p ∣ k ^ 2 + 4 := by
51-
cases' hnat₁ with x hx
51+
obtain ⟨x, hx⟩ := hnat₁
5252
have : (p : ℤ) ∣ (k : ℤ) ^ 2 + 4 := by
5353
use (p : ℤ) - 4 * n + 4 * x
5454
have hcast₁ : (k : ℤ) = p - 2 * n := by assumption_mod_cast

Archive/MiuLanguage/DecisionNec.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ We'll show, for each `i` from 1 to 4, that if `en` follows by Rule `i` from `st`
122122

123123
theorem goodm_of_rule1 (xs : Miustr) (h₁ : Derivable (xs ++ [I])) (h₂ : Goodm (xs ++ [I])) :
124124
Goodm (xs ++ [I, U]) := by
125-
cases' h₂ with mhead nmtail
125+
obtain ⟨mhead, nmtail⟩ := h₂
126126
constructor
127127
· cases xs <;> simp_all
128128
· change ¬M ∈ tail (xs ++ ([I] ++ [U]))
@@ -134,14 +134,14 @@ theorem goodm_of_rule2 (xs : Miustr) (_ : Derivable (M :: xs)) (h₂ : Goodm (M
134134
Goodm ((M :: xs) ++ xs) := by
135135
constructor
136136
· rfl
137-
· cases' h₂ with mhead mtail
137+
· obtain ⟨mhead, mtail⟩ := h₂
138138
contrapose! mtail
139139
rw [cons_append] at mtail
140140
exact or_self_iff.mp (mem_append.mp mtail)
141141

142142
theorem goodm_of_rule3 (as bs : Miustr) (h₁ : Derivable (as ++ [I, I, I] ++ bs))
143143
(h₂ : Goodm (as ++ [I, I, I] ++ bs)) : Goodm (as ++ (U :: bs)) := by
144-
cases' h₂ with mhead nmtail
144+
obtain ⟨mhead, nmtail⟩ := h₂
145145
have k : as ≠ nil := by rintro rfl; contradiction
146146
constructor
147147
· cases as
@@ -159,7 +159,7 @@ The proof of the next lemma is identical, on the tactic level, to the previous p
159159

160160
theorem goodm_of_rule4 (as bs : Miustr) (h₁ : Derivable (as ++ [U, U] ++ bs))
161161
(h₂ : Goodm (as ++ [U, U] ++ bs)) : Goodm (as ++ bs) := by
162-
cases' h₂ with mhead nmtail
162+
obtain ⟨mhead, nmtail⟩ := h₂
163163
have k : as ≠ nil := by rintro rfl; contradiction
164164
constructor
165165
· cases as

Archive/Sensitivity.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ theorem duality (p q : Q n) : ε p (e q) = if p = q then 1 else 0 := by
210210
theorem epsilon_total {v : V n} (h : ∀ p : Q n, (ε p) v = 0) : v = 0 := by
211211
induction' n with n ih
212212
· dsimp [ε] at h; exact h fun _ => true
213-
· cases' v with v₁ v₂
213+
· obtain ⟨v₁, v₂⟩ := v
214214
ext <;> change _ = (0 : V n) <;> simp only <;> apply ih <;> intro p <;>
215215
[let q : Q n.succ := fun i => if h : i = 0 then true else p (i.pred h);
216216
let q : Q n.succ := fun i => if h : i = 0 then false else p (i.pred h)]

Archive/Wiedijk100Theorems/PerfectNumbers.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ theorem even_two_pow_mul_mersenne_of_prime (k : ℕ) (pr : (mersenne (k + 1)).Pr
5656

5757
theorem eq_two_pow_mul_odd {n : ℕ} (hpos : 0 < n) : ∃ k m : ℕ, n = 2 ^ k * m ∧ ¬Even m := by
5858
have h := Nat.finiteMultiplicity_iff.2 ⟨Nat.prime_two.ne_one, hpos⟩
59-
cases' pow_multiplicity_dvd 2 n with m hm
59+
obtain ⟨m, hm⟩ := pow_multiplicity_dvd 2 n
6060
use multiplicity 2 n, m
6161
refine ⟨hm, ?_⟩
6262
rw [even_iff_two_dvd]

Mathlib/Algebra/Lie/Weights/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ lemma genWeightSpace_ne_bot (χ : Weight R L M) : genWeightSpace M χ ≠ ⊥ :=
226226
variable {M}
227227

228228
@[ext] lemma ext {χ₁ χ₂ : Weight R L M} (h : ∀ x, χ₁ x = χ₂ x) : χ₁ = χ₂ := by
229-
cases' χ₁ with f₁ _; cases' χ₂ with f₂ _; aesop
229+
obtain ⟨f₁, _⟩ := χ₁; obtain ⟨f₂, _⟩ := χ₂; aesop
230230

231231
lemma ext_iff' {χ₁ χ₂ : Weight R L M} : (χ₁ : L → R) = χ₂ ↔ χ₁ = χ₂ := by simp
232232

Mathlib/Algebra/Polynomial/BigOperators.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ theorem coeff_multiset_prod_of_natDegree_le (n : ℕ) (hl : ∀ p ∈ t, natDegr
217217

218218
theorem coeff_prod_of_natDegree_le (f : ι → R[X]) (n : ℕ) (h : ∀ p ∈ s, natDegree (f p) ≤ n) :
219219
coeff (∏ i ∈ s, f i) (#s * n) = ∏ i ∈ s, coeff (f i) n := by
220-
cases' s with l hl
220+
obtain ⟨l, hl⟩ := s
221221
convert coeff_multiset_prod_of_natDegree_le (l.map f) n ?_
222222
· simp
223223
· simp

Mathlib/Algebra/Polynomial/FieldDivision.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,12 @@ theorem eval_gcd_eq_zero [DecidableEq R] {f g : R[X]} {α : R}
446446

447447
theorem root_left_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k}
448448
(hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : f.eval₂ ϕ α = 0 := by
449-
cases' EuclideanDomain.gcd_dvd_left f g with p hp
449+
obtain ⟨p, hp⟩ := EuclideanDomain.gcd_dvd_left f g
450450
rw [hp, Polynomial.eval₂_mul, hα, zero_mul]
451451

452452
theorem root_right_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k}
453453
(hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : g.eval₂ ϕ α = 0 := by
454-
cases' EuclideanDomain.gcd_dvd_right f g with p hp
454+
obtain ⟨p, hp⟩ := EuclideanDomain.gcd_dvd_right f g
455455
rw [hp, Polynomial.eval₂_mul, hα, zero_mul]
456456

457457
theorem root_gcd_iff_root_left_right [CommSemiring k] [DecidableEq R]

Mathlib/Analysis/Analytic/Composition.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ theorem applyComposition_single (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ}
117117
dsimp
118118
congr 1
119119
convert Composition.single_embedding hn ⟨i, hi2⟩ using 1
120-
cases' j with j_val j_property
120+
obtain ⟨j_val, j_property⟩ := j
121121
have : j_val = 0 := le_bot_iff.1 (Nat.lt_succ_iff.1 j_property)
122122
congr!
123123
simp

Mathlib/Analysis/BoxIntegral/Box/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ theorem mk'_eq_bot {l u : ι → ℝ} : mk' l u = ⊥ ↔ ∃ i, u i ≤ l i :=
288288

289289
@[simp]
290290
theorem mk'_eq_coe {l u : ι → ℝ} : mk' l u = I ↔ l = I.lower ∧ u = I.upper := by
291-
cases' I with lI uI hI; rw [mk']; split_ifs with h
291+
obtain ⟨lI, uI, hI⟩ := I; rw [mk']; split_ifs with h
292292
· simp [WithBot.coe_eq_coe]
293293
· suffices l = lI → u ≠ uI by simpa
294294
rintro rfl rfl

Mathlib/Analysis/Calculus/Taylor.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,8 @@ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : S
120120
refine continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => ?_
121121
refine (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul ?_
122122
rw [contDiffOn_nat_iff_continuousOn_differentiableOn_deriv hs] at hf
123-
cases' hf with hf_left
124-
specialize hf_left i
125123
simp only [Finset.mem_range] at hi
126-
refine hf_left ?_
124+
refine hf.1 i ?_
127125
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
128126

129127
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor

0 commit comments

Comments
 (0)