Skip to content

Commit ba1e3bb

Browse files
chore: extract API from #38807 and golf (#39230)
I wanted to understand why these two proofs in #38807 were long (and also play around more with the API in this corner of the library) so I walked through them with Claude Opus. prepared with Claude code
1 parent a592298 commit ba1e3bb

2 files changed

Lines changed: 23 additions & 37 deletions

File tree

Mathlib/Order/Bounds/Basic.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ lemma DirectedOn.isCofinalFor_fst_image_prod_snd_image {β : Type*} [Preorder β
132132
obtain ⟨z, hz, hxz, hyz⟩ := hs _ hx _ hy
133133
exact ⟨z, hz, hxz.1, hyz.2
134134

135+
@[to_dual]
136+
lemma IsCofinalFor.nonempty (h : IsCofinalFor s t) (hs : s.Nonempty) : t.Nonempty :=
137+
let ⟨_, ha⟩ := hs; let ⟨b, hb, _⟩ := h ha; ⟨b, hb⟩
138+
135139
theorem IsCofinalFor.union_left (hc : IsCofinalFor s t) : IsCofinalFor (s ∪ t) t := by
136140
rintro a (has | hat)
137141
· exact hc has
@@ -226,6 +230,13 @@ theorem IsLUB.of_subset_of_superset {s t p : Set α} (hs : IsLUB s a) (hp : IsLU
226230
(htp : t ⊆ p) : IsLUB t a :=
227231
⟨upperBounds_mono_set htp hp.1, lowerBounds_mono_set (upperBounds_mono_set hst) hs.2
228232

233+
/-- The least upper bound of a set is also the least upper bound of any cofinal subset. -/
234+
@[to_dual /-- The greatest lower bound of a set is also the greatest lower bound of any
235+
coinitial subset. -/]
236+
theorem IsLUB.of_isCofinalFor {s t : Set α} (hs : IsLUB s a) (hts : t ⊆ s)
237+
(hst : IsCofinalFor s t) : IsLUB t a :=
238+
⟨upperBounds_mono_set hts hs.1, fun _b hb ↦ hs.2 (upperBounds_mono_of_isCofinalFor hst hb)⟩
239+
229240
@[to_dual]
230241
theorem IsLeast.mono (ha : IsLeast s a) (hb : IsLeast t b) (hst : s ⊆ t) : b ≤ a :=
231242
hb.2 (hst ha.1)

Mathlib/Order/DirSupClosed.lean

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -171,32 +171,14 @@ theorem DirSupClosedOn.union (hDL : IsLowerSet D)
171171
(hs : DirSupClosedOn D s) (ht : DirSupClosedOn D t) : DirSupClosedOn D (s ∪ t) := by
172172
intro d hD hdu hd₀ hd₁ a ha
173173
have hdst : d ∩ s ∪ d ∩ t = d := by grind
174-
rw [← hdst] at hd₀ hd₁
175-
wlog h : DirectedOn (· ≤ ·) (d ∩ s) ∧ (d ∩ s).Nonempty
176-
· rw [union_comm] at hdu hd₀ hd₁ hdst ⊢
174+
wlog h : DirectedOn (· ≤ ·) (d ∩ s) ∧ IsCofinalFor (d ∩ t) (d ∩ s)
175+
· rw [union_comm] at hdu hdst ⊢
177176
exact this hDL ht hs hD hdu hd₀ hd₁ ha hdst <|
178-
(directedOn_or_directedOn_of_union' hd₀ hd₁).resolve_right h
179-
obtain ⟨hds, hn⟩ := h
180-
by_cases had : a ∈ lowerBounds (upperBounds (d ∩ s))
181-
· exact .inl <| hs (hDL inter_subset_left hD) inter_subset_right hn hds
182-
fun b hb ↦ ha.1 hb.1, had⟩
183-
· simp only [lowerBounds, mem_setOf_eq, not_forall] at had
184-
obtain ⟨b, hb, hb'⟩ := had
185-
have key : {x ∈ d | ¬ x ≤ b} ⊆ d ∩ t := fun a ⟨had, hab⟩ ↦
186-
⟨had, (hdu had).resolve_left fun has ↦ hab <| hb ⟨had, has⟩⟩
187-
obtain ⟨w, hw⟩ : {x ∈ d | ¬ x ≤ b}.Nonempty := by
188-
contrapose! hb'
189-
apply ha.2
190-
aesop
191-
refine Or.inr <| ht (hDL inter_subset_left hD) (key.trans inter_subset_right)
192-
⟨w, hw⟩ (fun x hx y hy ↦ ?_) ?_
193-
· obtain ⟨z, hz, hz'⟩ := hd₁ _ (.inr (key hx)) _ (.inr (key hy))
194-
exact ⟨z, ⟨⟨hdst ▸ hz, mt hz'.1.trans hx.2⟩, hz'⟩⟩
195-
· refine ⟨fun x hx ↦ ha.1 hx.1, fun x hx ↦ ha.2 fun y hy ↦ ?_⟩
196-
by_cases hyb : y ≤ b
197-
· obtain ⟨z, hz, hxz, hyz⟩ := hd₁ _ (hdst ▸ hy) _ (.inr (key hw))
198-
exact hxz.trans (hx ⟨hdst ▸ hz, fun hzb ↦ hw.2 (hyz.trans hzb)⟩)
199-
exact hx ⟨hy, hyb⟩
177+
(directedOn_union_iff.mp (by rwa [hdst])).resolve_right h
178+
obtain ⟨hds, hcof⟩ := h
179+
have hcof' : IsCofinalFor d (d ∩ s) := hcof.union_right.mono_left hdst.ge
180+
exact .inl <| hs (hDL inter_subset_left hD) inter_subset_right
181+
(hcof'.nonempty hd₀) hds (ha.of_isCofinalFor inter_subset_left hcof')
200182

201183
theorem DirSupInaccOn.inter (hDL : IsLowerSet D)
202184
(hs : DirSupInaccOn D s) (ht : DirSupInaccOn D t) : DirSupInaccOn D (s ∩ t) := by
@@ -228,18 +210,11 @@ theorem dirSupInaccOn_iff_inter_subset (hDL : IsLowerSet D) :
228210
mpr := .of_inter_subset
229211
mp h t hD ht₀ ht₁ a ha has := by
230212
by_contra! H
231-
have H : ∀ b : t, ∃ c, b.1 ≤ c ∧ c ∈ t ∧ c ∉ s := by simpa [not_subset, and_assoc] using H
232-
choose f hf using H
233-
have := ht₀.to_subtype
234-
have hft : range f ⊆ t := by grind
235-
apply (h (hDL hft hD) (range_nonempty f) _ _ has).ne_empty
236-
· aesop
237-
· intro a ha b hb
238-
obtain ⟨c, hc, _, _⟩ := ht₁ _ (hft ha) _ (hft hb)
239-
have := hf ⟨c, hc⟩
240-
grind
241-
· exact ⟨upperBounds_mono_set hft ha.1,
242-
fun b hb ↦ ha.2 fun c hc ↦ (hf ⟨c, hc⟩).1.trans (hb <| by simp)⟩
213+
have hcof : IsCofinalFor t (t \ s) := by grind [IsCofinalFor, not_subset]
214+
obtain ⟨x, hx, hxs⟩ := h (hDL sdiff_subset hD) (hcof.nonempty ht₀)
215+
(ht₁.of_isCofinalFor sdiff_subset hcof)
216+
(ha.of_isCofinalFor sdiff_subset hcof) has
217+
exact hx.2 hxs
243218

244219
/-- The condition `(d ∩ s).Nonempty` in `DirSupInacc` can be replaced with the stronger
245220
`∃ b ∈ d, Ici b ∩ d ⊆ s`. -/

0 commit comments

Comments
 (0)