Skip to content

Commit 2ebbdbb

Browse files
refactor: tighten proof style from Mathlib PR review feedback
Apply lessons from three rounds of review on PR #36443: - .rfl over Iff.rfl, ext;simp for set equality, sub_pos.mpr for cast positivity - Unsqueeze terminal simp, squeeze non-terminal simp, omega over verbose lemmas - Drop deprecated `from` keyword, remove unused intermediates - Update CLAUDE.md with Mathlib reviewer conventions -35 lines of Lean, build + lint clean, zero sorry.
1 parent 0daec0e commit 2ebbdbb

7 files changed

Lines changed: 50 additions & 67 deletions

File tree

CLAUDE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ copyright headers on all `.lean` files.
5555
- **Terminal `simp`**: do NOT squeeze (maintenance burden from lemma renames)
5656
- **Non-terminal `simp`**: MUST be `simp only [...]`
5757
- **One tactic per line** (semicolons only for short single-idea sequences)
58+
- **Set equality**: `ext v; simp [...]` is canonical — don't build manual
59+
`constructor`/`rcases`/`absurd` chains when `simp` with the right lemma set closes it
60+
- **Skip `ext`** when `simp` alone closes a set equality (e.g., `ball_zero`)
61+
- **`simp` before `tauto`**: `simp` + commutativity lemmas (`adj_comm`, `or_comm`)
62+
often closes goals that look like they need `tauto`
63+
- **`.rfl`** not `Iff.rfl` — dot notation for constructor terms
64+
- **Named lemmas over `show ... from rfl`**: e.g., `one_add_one_eq_two.symm`
65+
not `show (2 : ℕ∞) = 1 + 1 from rfl`
5866

5967
### Attributes
6068

@@ -72,6 +80,9 @@ copyright headers on all `.lean` files.
7280
- **Hypotheses left of colon**`(h : 1 < n) : 0 < n` not `: 1 < n → 0 < n`
7381
- **`abbrev`** (reducible) requires justification; `@[irreducible]` requires justification
7482
- **Classical by default** — don't thread `Decidable` instances unless the type requires them
83+
- **Definition argument order**: choose to minimize downstream `symm`/`comm` calls —
84+
e.g., `{v | G.edist v c < r}` not `{v | G.edist c v < r}` when most API lemmas
85+
state the varying argument first
7586

7687
### Documentation
7788

@@ -182,3 +193,10 @@ copyright headers on all `.lean` files.
182193
- **Commit messages**: substantive, not ceremonial
183194
- Feature branches merge to main via fast-forward; delete after merge
184195
- **Mathlib PR process**: post to Zulip first, small PRs preferred, AI disclosure required
196+
- **PR description format**: one-line summary → blank line → AI disclosure (1-2 sentences)
197+
→ Zulip link → `---` → template buttons. No design-decision sections, no tables.
198+
- **Review responses**: one sentence per comment, inline on the diff where possible.
199+
No tables, headers, diff summaries, or structured documents. Let the code speak.
200+
- **AI disclosure**: in PR body only, not in commit `Co-Authored-By` tags
201+
- **Reviewer disagreements**: defer to the later or more authoritative reviewer
202+
- **File-author naming preferences**: defer (e.g., `ball_mono` over `ball_subset_ball`)

FdFormal/FlowerConstruction.lean

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ theorem flowerEdge_card (u v g : ℕ) :
118118
induction g with
119119
| zero => simp [FlowerEdge]
120120
| succ g ih =>
121-
simp only [FlowerEdge, Fintype.card_prod, Fintype.card_sum, Fintype.card_fin, ih, pow_succ,
121+
simp [FlowerEdge, Fintype.card_prod, Fintype.card_sum, Fintype.card_fin, ih, pow_succ,
122122
mul_comm]
123123

124124
/-- Vertex type for the (u,v)-flower at generation `g`.
@@ -158,8 +158,7 @@ theorem FlowerVert.embed_injective {u v g : ℕ} :
158158
| inl a =>
159159
cases y with
160160
| inl _ =>
161-
have := Sum.inl_injective hxy
162-
exact congrArg Sum.inl this
161+
exact congrArg Sum.inl (Sum.inl_injective hxy)
163162
| inr _ => simp [embed] at hxy
164163
| inr a =>
165164
cases y with
@@ -412,10 +411,7 @@ noncomputable def flowerGraph' (u v g : ℕ) :
412411
/-- The adjacency relation of `flowerGraph'` is `flowerAdj'`. -/
413412
theorem flowerGraph'_adj_iff (u v g : ℕ)
414413
(a b : FlowerVert u v g) :
415-
(flowerGraph' u v g).Adj a b ↔ flowerAdj' u v g a b := by
416-
constructor
417-
· exact id
418-
· exact id
414+
(flowerGraph' u v g).Adj a b ↔ flowerAdj' u v g a b := .rfl
419415

420416
/-! ## Layer 4: Walk construction and distance -/
421417

@@ -757,13 +753,13 @@ theorem rank_edge_bounds (u v g : ℕ) (hu : 1 < u) (huv : u ≤ v)
757753
| (have h := htgt_eq ‹_›; rw [h, mul_add, mul_one]
758754
constructor
759755
· exact Nat.add_le_add_left (Nat.div_le_of_le_mul (by
760-
nlinarith [Nat.mul_le_mul_left u (show n + 1 ≤ v from by omega),
756+
nlinarith [Nat.mul_le_mul_left u (show n + 1 ≤ v by omega),
761757
mul_comm (n + 1) u])) _
762758
· suffices u - 1 ≤ (n + 1) * u / v by omega
763759
calc u - 1 = (u - 1) * v / v :=
764-
(Nat.mul_div_cancel (u - 1) (show 0 < v from by omega)).symm
760+
(Nat.mul_div_cancel (u - 1) (show 0 < v by omega)).symm
765761
_ ≤ (n + 1) * u / v := Nat.div_le_div_right (by
766-
zify [show 1 ≤ u from by omega, show 1 ≤ v from by omega] at *
762+
zify [show 1 ≤ u by omega, show 1 ≤ v by omega] at *
767763
nlinarith))
768764

769765
/-- Rank is non-decreasing along edges: rank(edgeSrc) ≤ rank(edgeTgt). -/
@@ -941,8 +937,7 @@ theorem FlowerVert.project_embed (u v g : ℕ) (x : FlowerVert u v g) :
941937
| inl _ => rfl
942938
| inr val =>
943939
obtain ⟨k, e, pos⟩ := val
944-
simp only [FlowerVert.embed, FlowerVert.project, Fin.val_castSucc, dif_pos k.isLt,
945-
Fin.eta]
940+
simp [FlowerVert.embed, FlowerVert.project, Fin.val_castSucc, Fin.eta]
946941

947942
/-- Hub 0 projects to hub 0. -/
948943
theorem FlowerVert.project_hub0 (u v g : ℕ) :

FdFormal/FlowerCounts.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ theorem flowerVertCount_eq (u v g : ℕ) (hu : 1 < u) (huv : u ≤ v) :
103103
(u + v - 2) * (u + v) ^ g + (u + v) := by
104104
induction g with
105105
| zero =>
106-
simp
106+
simp only [flowerVertCount, pow_zero, mul_one]
107107
omega
108108
| succ g ih =>
109109
simp only [flowerVertCount_succ, flowerEdgeCount_eq_pow, pow_succ]
@@ -128,7 +128,7 @@ theorem flowerVertCount_lower (u v g : ℕ) (hu : 1 < u) (huv : u ≤ v) :
128128
(u + v - 2) * (u + v) ^ g ≤
129129
(u + v - 1) * flowerVertCount u v g := by
130130
rw [flowerVertCount_eq u v g hu huv]
131-
exact le_add_of_nonneg_right (Nat.zero_le _)
131+
omega
132132

133133
/-- Upper bound: `(w - 1) * N_g ≤ 2 * (w - 1) * w^g`. -/
134134
theorem flowerVertCount_upper (u v g : ℕ) (hu : 1 < u) (huv : u ≤ v) :

FdFormal/FlowerDimension.lean

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ theorem flowerVertCount_ge_real (u v g : ℕ) (hu : 1 < u)
7474
(huv : u ≤ v) :
7575
(↑(u + v) - 2) / (↑(u + v) - 1) * (↑(u + v) : ℝ) ^ g ≤
7676
↑(flowerVertCount u v g) := by
77-
have hw1 : (0 : ℝ) < ↑(u + v) - 1 := by
78-
have : (1 : ℝ) < ↑(u + v) := by
79-
exact_mod_cast (show 1 < u + v from by omega)
80-
linarith
77+
have hw1 : (0 : ℝ) < ↑(u + v) - 1 :=
78+
sub_pos.mpr (by exact_mod_cast (show 1 < u + v by omega))
8179
rw [div_mul_eq_mul_div, div_le_iff₀ hw1]
8280
have h := flowerVertCount_lower_real u v g hu huv
8381
linarith [mul_comm (↑(u + v) - 1 : ℝ) (↑(flowerVertCount u v g) : ℝ)]
@@ -86,13 +84,11 @@ theorem flowerVertCount_ge_real (u v g : ℕ) (hu : 1 < u)
8684
theorem flowerVertCount_le_real (u v g : ℕ) (hu : 1 < u)
8785
(huv : u ≤ v) :
8886
(↑(flowerVertCount u v g) : ℝ) ≤ 2 * (↑(u + v) : ℝ) ^ g := by
89-
have hw1 : (0 : ℝ) < ↑(u + v) - 1 := by
90-
have : (1 : ℝ) < ↑(u + v) := by
91-
exact_mod_cast (show 1 < u + v from by omega)
92-
linarith
87+
have hw1 : (0 : ℝ) < ↑(u + v) - 1 :=
88+
sub_pos.mpr (by exact_mod_cast (show 1 < u + v by omega))
9389
have h := flowerVertCount_upper_real u v g hu huv
9490
rw [show (2 : ℝ) * (↑(u + v) - 1) * (↑(u + v) : ℝ) ^ g =
95-
(↑(u + v) - 1) * (2 * (↑(u + v) : ℝ) ^ g) from by ring] at h
91+
(↑(u + v) - 1) * (2 * (↑(u + v) : ℝ) ^ g) by ring] at h
9692
exact (mul_le_mul_iff_right₀ hw1).mp h
9793

9894
/-! ### The headline theorem -/
@@ -113,7 +109,7 @@ theorem flowerDimension (u v : ℕ) (hu : 1 < u) (huv : u ≤ v) :
113109
have hlogu : 0 < log (↑u : ℝ) :=
114110
log_pos (by exact_mod_cast hu)
115111
have hlogw : 0 < log (↑(u + v) : ℝ) :=
116-
log_pos (by exact_mod_cast (show 1 < u + v from by omega))
112+
log_pos (by exact_mod_cast (show 1 < u + v by omega))
117113
have hw_pos : (0 : ℝ) < ↑(u + v) :=
118114
Nat.cast_pos.mpr (by omega)
119115
have hN_pos : ∀ g, (0 : ℝ) < ↑(flowerVertCount u v g) :=
@@ -122,8 +118,8 @@ theorem flowerDimension (u v : ℕ) (hu : 1 < u) (huv : u ≤ v) :
122118
have h_log_hub : ∀ g : ℕ,
123119
log (↑(flowerHubDist u v g) : ℝ) = ↑g * log (↑u : ℝ) := by
124120
intro g
125-
rw [show (↑(flowerHubDist u v g) : ℝ) = (↑u : ℝ) ^ g from by
126-
simp [flowerHubDist_eq_pow, Nat.cast_pow]]
121+
rw [show (↑(flowerHubDist u v g) : ℝ) = (↑u : ℝ) ^ g by
122+
simp only [flowerHubDist_eq_pow, Nat.cast_pow]]
127123
exact log_pow (↑u) g
128124
-- Step 2: Suffices with g * log(u) in denominator
129125
suffices h : Tendsto
@@ -148,14 +144,9 @@ theorem flowerDimension (u v : ℕ) (hu : 1 < u) (huv : u ≤ v) :
148144
-- The residual is bounded between log(c₁)/(g*log u) and log(2)/(g*log u)
149145
-- where c₁ = (w-2)/(w-1) > 0
150146
set c₁ := (↑(u + v) - 2 : ℝ) / (↑(u + v) - 1) with hc₁_def
151-
have hc₁_pos : 0 < c₁ := by
152-
apply div_pos
153-
· have : (2 : ℝ) < ↑(u + v) := by
154-
exact_mod_cast (show 2 < u + v from by omega)
155-
linarith
156-
· have : (1 : ℝ) < ↑(u + v) := by
157-
exact_mod_cast (show 1 < u + v from by omega)
158-
linarith
147+
have hc₁_pos : 0 < c₁ :=
148+
div_pos (sub_pos.mpr (by exact_mod_cast (show 2 < u + v by omega)))
149+
(sub_pos.mpr (by exact_mod_cast (show 1 < u + v by omega)))
159150
-- g * log(u) → ∞
160151
have h_denom : Tendsto (fun g : ℕ ↦ (↑g : ℝ) * log (↑u : ℝ))
161152
atTop atTop :=

FdFormal/FlowerLog.lean

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,10 @@ theorem log_flowerVertCount_residual_lower :
6666
log ((↑(u + v) - 2 : ℝ) / (↑(u + v) - 1)) ≤
6767
log ↑(flowerVertCount u v g) - ↑g * log (↑(u + v) : ℝ) := by
6868
have hw_pos : (0 : ℝ) < ↑(u + v) := Nat.cast_pos.mpr (by omega)
69-
have hw1 : (0 : ℝ) < ↑(u + v) - 1 := by
70-
have : (1 : ℝ) < ↑(u + v) := by exact_mod_cast (show 1 < u + v by omega)
71-
linarith
72-
have hc : (0 : ℝ) < (↑(u + v) - 2) / (↑(u + v) - 1) := by
73-
apply div_pos _ hw1
74-
have : (2 : ℝ) < ↑(u + v) := by exact_mod_cast (show 2 < u + v by omega)
75-
linarith
69+
have hw1 : (0 : ℝ) < ↑(u + v) - 1 :=
70+
sub_pos.mpr (by exact_mod_cast (show 1 < u + v by omega))
71+
have hc : (0 : ℝ) < (↑(u + v) - 2) / (↑(u + v) - 1) :=
72+
div_pos (sub_pos.mpr (by exact_mod_cast (show 2 < u + v by omega))) hw1
7673
-- From ℕ bound: (w-2)·w^g ≤ (w-1)·N_g → (w-2)/(w-1)·w^g ≤ N_g
7774
have h_ge : (↑(u + v) - 2) / (↑(u + v) - 1) * (↑(u + v) : ℝ) ^ g ≤
7875
↑(flowerVertCount u v g) := by

FdFormal/GraphBall.lean

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ variable {G}
6060

6161
@[simp]
6262
theorem mem_ball {c v : V} {r : ℕ∞} :
63-
v ∈ G.ball c r ↔ G.edist c v < r :=
64-
Iff.rfl
63+
v ∈ G.ball c r ↔ G.edist c v < r := .rfl
6564

6665
@[simp]
6766
theorem ball_zero {c : V} : G.ball c 0 = ∅ := by
@@ -70,29 +69,13 @@ theorem ball_zero {c : V} : G.ball c 0 = ∅ := by
7069
@[simp]
7170
theorem ball_one {c : V} : G.ball c 1 = {c} := by
7271
ext v
73-
simp only [mem_ball, Set.mem_singleton_iff]
74-
constructor
75-
· intro h
76-
have h0 : G.edist c v = 0 := by
77-
have hne : G.edist c v ≠ ⊤ := ne_top_of_lt h
78-
lift G.edist c v to ℕ using hne with d
79-
have : d < 1 := by exact_mod_cast h
80-
exact_mod_cast (show d = 0 from by omega)
81-
exact (edist_eq_zero_iff.mp h0).symm
82-
· rintro rfl; simp
72+
simp [ball, ENat.lt_one_iff_eq_zero]
8373

8474
@[simp]
8575
theorem ball_top {c : V} :
8676
G.ball c ⊤ = (G.connectedComponentMk c).supp := by
8777
ext v
88-
simp only [mem_ball, ConnectedComponent.mem_supp_iff]
89-
constructor
90-
· intro h
91-
exact (ConnectedComponent.eq.mpr
92-
(reachable_of_edist_ne_top (ne_top_of_lt h))).symm
93-
· intro h
94-
exact lt_top_iff_ne_top.mpr
95-
(edist_ne_top_iff_reachable.mpr (ConnectedComponent.eq.mp h.symm))
78+
simp [lt_top_iff_ne_top, edist_ne_top_iff_reachable, reachable_comm]
9679

9780
/-- Balls are monotone in the radius. -/
9881
theorem ball_mono {c : V} {r₁ r₂ : ℕ∞} (h : r₁ ≤ r₂) :
@@ -128,7 +111,7 @@ theorem ball_anti {G' : SimpleGraph V} {c : V} {r : ℕ∞} (h : G ≤ G') :
128111
theorem mem_ball_of_adj {c v : V} (h : G.Adj c v) :
129112
v ∈ G.ball c 2 := by
130113
simp only [mem_ball]
131-
have h1 : (1 : ℕ∞) < 2 := by exact_mod_cast (show (1 : ℕ) < 2 from by omega)
114+
have h1 : (1 : ℕ∞) < 2 := by exact_mod_cast (by omega : (1 : ℕ) < 2)
132115
exact lt_of_le_of_lt (edist_le_one_iff_adj_or_eq.mpr (Or.inl h)) h1
133116

134117
theorem adj_of_mem_ball_two {c v : V} (h : v ∈ G.ball c 2) (hne : c ≠ v) :
@@ -138,7 +121,7 @@ theorem adj_of_mem_ball_two {c v : V} (h : v ∈ G.ball c 2) (hne : c ≠ v) :
138121
have hne_top : G.edist c v ≠ ⊤ := ne_top_of_lt h
139122
lift G.edist c v to ℕ using hne_top with d
140123
have : d < 2 := by exact_mod_cast h
141-
exact_mod_cast (show d ≤ 1 from by omega)
124+
exact_mod_cast (by omega : d ≤ 1)
142125
exact (edist_le_one_iff_adj_or_eq.mp hle).resolve_right hne
143126

144127
/-- If `v ∈ ball c r₁` and `w ∈ ball v r₂`, then `w ∈ ball c (r₁ + r₂)`. -/

FdFormal/PathGraphDist.lean

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,15 @@ private theorem pathGraph_walk_le {n : ℕ} {i j : Fin (n + 1)} (hij : i.val ≤
7474
∃ w : (pathGraph (n + 1)).Walk i j, w.length = j.val - i.val := by
7575
induction j using Fin.inductionOn with
7676
| zero =>
77-
have hi : i = 0 := by ext; exact Nat.le_zero.mp hij
77+
have hi : i = 0 := by ext; omega
7878
exact hi ▸ ⟨.nil, by simp⟩
7979
| succ j ih =>
8080
by_cases h : i.val ≤ j.val
8181
· obtain ⟨w, hw⟩ := ih h
8282
have hadj : (pathGraph (n + 1)).Adj j.castSucc j.succ := by
8383
rw [pathGraph_adj]; left; simp [Fin.val_succ, Fin.val_castSucc]
8484
exact ⟨w.append (.cons hadj .nil), by simp [hw]; omega⟩
85-
· have hval : j.succ.val = j.val + 1 := Fin.val_succ j
86-
have hi : i = j.succ := Fin.ext (by omega)
85+
· have hi : i = j.succ := Fin.ext (by omega)
8786
subst hi; exact ⟨.nil, by simp⟩
8887

8988
/-- Any walk in `pathGraph` has length ≥ the index difference between endpoints.
@@ -127,7 +126,7 @@ theorem pathGraph_edist {n : ℕ} (i j : Fin (n + 1)) :
127126
theorem pathGraph_dist {n : ℕ} (i j : Fin (n + 1)) :
128127
(pathGraph (n + 1)).dist i j =
129128
if i.val ≤ j.val then j.val - i.val else i.val - j.val := by
130-
simp only [SimpleGraph.dist, pathGraph_edist, ENat.toNat_coe]
129+
simp [SimpleGraph.dist, pathGraph_edist, ENat.toNat_coe]
131130

132131
/-- Distance from `0` to `Fin.last n` in `pathGraph (n + 1)` is `n`. -/
133132
theorem pathGraph_dist_zero_last (n : ℕ) :

0 commit comments

Comments
 (0)