Skip to content

Commit fdfd405

Browse files
committed
refactor(Order/OmegaCompletePartialOrder): make Chain a structure (#37258)
It has a different `LE` to `OrderHom`, hence should not be an `abbrev`.
1 parent 4586e6a commit fdfd405

File tree

4 files changed

+43
-38
lines changed

4 files changed

+43
-38
lines changed

Mathlib/LinearAlgebra/Span/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Scott continuous for the ω-complete partial order induced by the complete latti
160160
theorem coe_scott_continuous :
161161
OmegaCompletePartialOrder.ωScottContinuous ((↑) : Submodule R M → Set M) :=
162162
OmegaCompletePartialOrder.ωScottContinuous.of_monotone_map_ωSup
163-
⟨SetLike.coe_mono, coe_iSup_of_chain⟩
163+
⟨SetLike.coe_mono, fun _ ↦ coe_iSup_of_chain _
164164

165165
section IsScalarTower
166166

Mathlib/Order/Hom/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ instance : Inhabited (α →o α) :=
287287

288288
/-- The preorder structure of `α →o β` is pointwise inequality: `f ≤ g ↔ ∀ a, f a ≤ g a`. -/
289289
instance : Preorder (α →o β) :=
290-
@Preorder.lift (α →o β) (α → β) _ toFun
290+
@Preorder.lift (α →o β) (α → β) _ DFunLike.coe
291291

292292
instance {β : Type*} [PartialOrder β] : PartialOrder (α →o β) :=
293293
@PartialOrder.lift (α →o β) (α → β) _ toFun ext

Mathlib/Order/OmegaCompletePartialOrder.lean

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,42 +67,52 @@ namespace OmegaCompletePartialOrder
6767

6868
/-- A chain is a monotone sequence.
6969
70+
This is made a one-field structure around order homomorphisms `ℕ →o α` because we want to endow
71+
chains with the domination order rather than the pointwise order. See `Chain.instLE`.
72+
7073
See the definition on page 114 of [gunter1992]. -/
71-
def Chain (α : Type u) [Preorder α] :=
72-
ℕ →o α
74+
structure Chain (α : Type u) [Preorder α] extends ℕ →o α
7375

7476
namespace Chain
7577
variable [Preorder α] [Preorder β] [Preorder γ]
7678

77-
instance : FunLike (Chain α) ℕ α := inferInstanceAs <| FunLike (ℕ →o α) ℕ α
78-
instance : OrderHomClass (Chain α) ℕ α := inferInstanceAs <| OrderHomClass (ℕ →o α) ℕ α
79+
instance : FunLike (Chain α) ℕ α where
80+
coe c := c.toOrderHom
81+
coe_injective' := by rintro ⟨f, hf⟩; congr!
82+
83+
initialize_simps_projections Chain (toFun → apply)
84+
85+
instance : OrderHomClass (Chain α) ℕ α where
86+
map_rel c _m _n hmn := c.monotone hmn
7987

8088
/-- See note [partially-applied ext lemmas]. -/
8189
@[ext] lemma ext ⦃f g : Chain α⦄ (h : ⇑f = ⇑g) : f = g := DFunLike.ext' h
8290

91+
@[simp] lemma coe_toOrderHom (c : Chain α) : ⇑c.toOrderHom = c := rfl
92+
8393
instance [Inhabited α] : Inhabited (Chain α) :=
8494
⟨⟨default, fun _ _ _ => le_rfl⟩⟩
8595

86-
instance : Membership α (Chain α) :=
87-
fun (c : ℕ →o α) a => ∃ i, a = c i
96+
instance : Membership α (Chain α) where
97+
mem c a := ∃ i, a = c i
8898

8999
variable (c c' : Chain α)
90100
variable (f : α →o β)
91101
variable (g : β →o γ)
92102

93-
instance : LE (Chain α) where le x y := ∀ i, ∃ j, x i ≤ y j
103+
instance instLE : LE (Chain α) where le x y := ∀ i, ∃ j, x i ≤ y j
94104

95105
lemma isChain_range : IsChain (· ≤ ·) (Set.range c) := Monotone.isChain_range (OrderHomClass.mono c)
96106

97107
lemma directed : Directed (· ≤ ·) c := directedOn_range.2 c.isChain_range.directedOn
98108

99109
/-- `map` function for `Chain` -/
100-
-- Not `@[simps]`: we need `@[simps!]` to see through the type synonym `Chain β = ℕ →o β`,
101-
-- but then we'd get the `FunLike` instance for `OrderHom` instead.
102-
def map : Chain β :=
103-
f.comp c
110+
@[simps toOrderHom]
111+
def map : Chain β where toOrderHom := f.comp c.toOrderHom
104112

105-
@[simp] theorem map_coe : ⇑(map c f) = f ∘ c := rfl
113+
@[simp] lemma coe_map : ⇑(c.map f) = f ∘ c := rfl
114+
115+
@[deprecated (since := "2026-03-27")] alias map_coe := coe_map
106116

107117
variable {f}
108118

@@ -119,25 +129,23 @@ theorem mem_map_iff {b : β} : b ∈ c.map f ↔ ∃ a, a ∈ c ∧ f a = b :=
119129
subst b
120130
apply mem_map c _ h⟩
121131

122-
@[simp]
123-
theorem map_id : c.map OrderHom.id = c :=
124-
OrderHom.comp_id _
132+
@[simp] lemma map_id : c.map OrderHom.id = c := by ext; simp
125133

126134
theorem map_comp : (c.map f).map g = c.map (g.comp f) :=
127135
rfl
128136

129137
@[mono]
130-
theorem map_le_map {g : α →o β} (h : f ≤ g) : c.map f ≤ c.map g :=
131-
fun i => by simp only [map_coe, Function.comp_apply]; exists i; apply h
138+
theorem map_le_map {g : α →o β} (h : f ≤ g) : c.map f ≤ c.map g := fun _ ↦ ⟨_, h _⟩
132139

133140
/-- `OmegaCompletePartialOrder.Chain.zip` pairs up the elements of two chains
134141
that have the same index. -/
135-
-- Not `@[simps]`: we need `@[simps!]` to see through the type synonym `Chain β = ℕ →o β`,
136-
-- but then we'd get the `FunLike` instance for `OrderHom` instead.
137-
def zip (c₀ : Chain α) (c₁ : Chain β) : Chain (α × β) :=
138-
OrderHom.prod c₀ c₁
142+
@[simps toOrderHom]
143+
def zip (c₀ : Chain α) (c₁ : Chain β) : Chain (α × β) where
144+
toOrderHom := c₀.toOrderHom.prod c₁.toOrderHom
145+
146+
@[simp] lemma zip_apply (c₀ : Chain α) (c₁ : Chain β) (n : ℕ) : c₀.zip c₁ n = (c₀ n, c₁ n) := rfl
139147

140-
@[simp] theorem zip_coe (c₀ : Chain α) (c₁ : Chain β) (n : ℕ) : c₀.zip c₁ n = (c₀ n, c₁ n) := rfl
148+
@[deprecated (since := "2026-03-27")] alias zip_coe := zip_apply
141149

142150
/-- An example of a `Chain` constructed from an ordered pair. -/
143151
def pair (a b : α) (hab : a ≤ b) : Chain α where
@@ -154,7 +162,7 @@ def pair (a b : α) (hab : a ≤ b) : Chain α where
154162

155163
@[simp] lemma pair_zip_pair (a₁ a₂ : α) (b₁ b₂ : β) (ha hb) :
156164
(pair a₁ a₂ ha).zip (pair b₁ b₂ hb) = pair (a₁, b₁) (a₂, b₂) (Prod.le_def.2 ⟨ha, hb⟩) := by
157-
unfold Chain; ext n : 2; cases n <;> rfl
165+
ext n : 2; cases n <;> rfl
158166

159167
end Chain
160168

@@ -263,7 +271,7 @@ lemma ωScottContinuous.monotone (h : ωScottContinuous f) : Monotone f :=
263271

264272
lemma ωScottContinuous.isLUB {c : Chain α} (hf : ωScottContinuous f) :
265273
IsLUB (Set.range (c.map ⟨f, hf.monotone⟩)) (f (ωSup c)) := by
266-
simpa [map_coe, OrderHom.coe_mk, Set.range_comp]
274+
simpa [Set.range_comp]
267275
using hf (by simp) (Set.range_nonempty _) (isChain_range c).directedOn (isLUB_range_ωSup c)
268276

269277
@[fun_prop, to_fun (attr := simp)]
@@ -278,7 +286,7 @@ lemma ωScottContinuous_iff_monotone_map_ωSup :
278286
refine ⟨fun hf ↦ ⟨hf.monotone, hf.map_ωSup⟩, ?_⟩
279287
intro hf _ ⟨c, hc⟩ _ _ _ hda
280288
convert isLUB_range_ωSup (c.map { toFun := f, monotone' := hf.1 })
281-
· rw [map_coe, OrderHom.coe_mk, ← hc, ← (Set.range_comp f ⇑c)]
289+
· simp [← hc, ← (Set.range_comp f ⇑c)]
282290
· rw [← hc] at hda
283291
rw [← hf.2 c, ωSup_eq_of_isLUB hda]
284292

@@ -504,7 +512,7 @@ lemma ωScottContinuous.inf (hf : ωScottContinuous f) (hg : ωScottContinuous g
504512
ωScottContinuous (f ⊓ g) := by
505513
refine ωScottContinuous.of_monotone_map_ωSup
506514
⟨hf.monotone.inf hg.monotone, fun c ↦ eq_of_forall_ge_iff fun a ↦ ?_⟩
507-
simp only [Pi.inf_apply, hf.map_ωSup c, hg.map_ωSup c, inf_le_iff, ωSup_le_iff, Chain.map_coe,
515+
simp only [Pi.inf_apply, hf.map_ωSup c, hg.map_ωSup c, inf_le_iff, ωSup_le_iff, Chain.coe_map,
508516
Function.comp, OrderHom.coe_mk, ← forall_or_left, ← forall_or_right]
509517
exact ⟨fun h _ ↦ h _ _, fun h i j ↦
510518
(h (max j i)).imp (le_trans <| hf.monotone <| c.mono <| le_max_left _ _)
@@ -606,15 +614,15 @@ theorem ωSup_bind {β γ : Type v} (c : Chain α) (f : α →o Part β) (g : α
606614
simp only [Part.mem_ωSup] at hb
607615
rcases hb with ⟨j, hb⟩
608616
replace hb := hb.symm
609-
simp only [Part.eq_some_iff, Chain.map_coe, Function.comp_apply] at hy hb
617+
simp only [Part.eq_some_iff, Chain.coe_map, Function.comp_apply] at hy hb
610618
replace hb : b ∈ f (c (max i j)) := f.mono (c.mono (le_max_right i j)) _ hb
611619
replace hy : y ∈ g (c (max i j)) b := g.mono (c.mono (le_max_left i j)) _ _ hy
612620
apply h''' (max i j)
613-
simp only [Part.mem_bind_iff, Chain.map_coe,
621+
simp only [Part.mem_bind_iff, Chain.coe_map,
614622
Function.comp_apply, OrderHom.partBind_coe]
615623
exact ⟨_, hb, hy⟩
616624
· intro i y hy
617-
simp only [Part.mem_bind_iff, Chain.map_coe,
625+
simp only [Part.mem_bind_iff, Chain.coe_map,
618626
Function.comp_apply, OrderHom.partBind_coe] at hy
619627
rcases hy with ⟨b, hb₀, hb₁⟩
620628
apply h''' b _
@@ -808,7 +816,7 @@ theorem ωSup_iterate_mem_fixedPoint (h : x ≤ f x) :
808816
apply le_antisymm
809817
· apply ωSup_le
810818
intro n
811-
simp only [Chain.map_coe, OrderHomClass.coe_coe, comp_apply]
819+
simp only [Chain.coe_map, OrderHomClass.coe_coe, comp_apply]
812820
have : iterateChain f x h (n.succ) = f (iterateChain f x h n) :=
813821
Function.iterate_succ_apply' ..
814822
rw [← this]

Mathlib/SetTheory/Ordinal/FixedPointApproximants.lean

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,9 @@ theorem lfpApprox_mono_left : Monotone (lfpApprox : (α →o α) → _) := by
121121
forall_eq_or_imp, le_sup_left, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂,
122122
true_and]
123123
intro i' h_lt
124-
apply le_sup_of_le_right
125-
apply le_sSup_of_le
126-
· use i'
127-
· apply le_trans (h _)
128-
simp only [OrderHom.toFun_eq_coe]
129-
exact g.monotone (ih i' h_lt)
124+
grw [← le_sup_right]
125+
refine le_sSup_of_le ⟨i', h_lt, rfl⟩ ?_
126+
grw [h _, ih i' h_lt]
130127

131128
theorem lfpApprox_mono_mid : Monotone (lfpApprox f) := by
132129
intro x₁ x₂ h a

0 commit comments

Comments
 (0)