Skip to content

Commit 5d5ae53

Browse files
committed
feat(Order/GaloisConnection/Defs): use to_dual for GaloisInsertion/GaloisCoinsertion (leanprover-community#35649)
This PR uses `to_dual` to generate declarations about `GaloisCoinsertion` from those for `GaloisInsertion`. - An entry is added to the name translation dictionary for this particular name translation. - One lemma in another file had to be tagged. - Some uses of `to_dual` have been replaced with `to_dual none`, because I had written them before `to_dual none` existed.
1 parent 1da3efc commit 5d5ae53

5 files changed

Lines changed: 49 additions & 91 deletions

File tree

Mathlib/Algebra/Group/Submonoid/Units.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ lemma units_surjective : Function.Surjective (units (M := M)) :=
177177
@[to_additive]
178178
lemma units_left_inverse :
179179
Function.LeftInverse (units (M := M)) (Subgroup.ofUnits (M := M)) :=
180-
ofUnits_units_gci.u_l_leftInverse
180+
ofUnits_units_gci.leftInverse_u_l
181181

182182
/-- The equivalence between the subgroup of units of `S` and the submonoid of unit
183183
elements of `S`. -/
@@ -299,7 +299,7 @@ lemma ofUnits_inf_units (S T : Subgroup Mˣ) : (S.ofUnits ⊓ T.ofUnits).units =
299299
@[to_additive]
300300
lemma ofUnits_right_inverse :
301301
Function.RightInverse (ofUnits (M := M)) (Submonoid.units (M := M)) :=
302-
ofUnits_units_gci.u_l_leftInverse
302+
ofUnits_units_gci.leftInverse_u_l
303303

304304
@[to_additive]
305305
lemma ofUnits_strictMono : StrictMono (ofUnits (M := M)) := ofUnits_units_gci.strictMono_l

Mathlib/Order/GaloisConnection/Defs.lean

Lines changed: 42 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ section
4949

5050
variable [Preorder α] [Preorder β] {l : α → β} {u : β → α}
5151

52-
@[to_dual self (reorder := α β, 3 4, l u, hu hl, hul hlu)]
53-
theorem monotone_intro (hu : Monotone u) (hl : Monotone l) (hul : ∀ a, a ≤ u (l a))
54-
(hlu : ∀ a, l (u a) ≤ a) : GaloisConnection l u := fun _ _ =>
55-
⟨fun h => (hul _).trans (hu h), fun h => (hl h).trans (hlu _)⟩
52+
@[to_dual self (reorder := α β, 3 4, l u, hu hl, h_u_l h_l_u)]
53+
theorem monotone_intro (hu : Monotone u) (hl : Monotone l) (h_u_l : ∀ a, a ≤ u (l a))
54+
(h_l_u : ∀ a, l (u a) ≤ a) : GaloisConnection l u := fun _ _ =>
55+
⟨fun h => (h_u_l _).trans (hu h), fun h => (hl h).trans (h_l_u _)⟩
5656

5757
@[to_dual self]
5858
protected theorem dual {l : α → β} {u : β → α} (gc : GaloisConnection l u) :
@@ -63,7 +63,7 @@ protected theorem dual {l : α → β} {u : β → α} (gc : GaloisConnection l
6363
variable (gc : GaloisConnection l u)
6464
include gc
6565

66-
@[to_dual le_iff_le']
66+
@[to_dual none]
6767
theorem le_iff_le {a : α} {b : β} : l a ≤ b ↔ a ≤ u b :=
6868
gc _ _
6969

@@ -146,7 +146,7 @@ section LinearOrder
146146

147147
variable [LinearOrder α] [LinearOrder β] {l : α → β} {u : β → α}
148148

149-
@[to_dual lt_iff_lt']
149+
@[to_dual none]
150150
theorem lt_iff_lt (gc : GaloisConnection l u) {a : α} {b : β} : b < l a ↔ u b < a :=
151151
lt_iff_lt_of_le_iff_le (gc a b)
152152

@@ -209,16 +209,34 @@ structure GaloisInsertion {α β : Type*} [Preorder α] [Preorder β] (l : α
209209
/-- Property of the choice function. -/
210210
choice_eq : ∀ a h, choice a h = l a
211211

212+
/-- A Galois coinsertion is a Galois connection where `u ∘ l = id`. It also contains a constructive
213+
choice function, to give better definitional equalities when lifting order structures. Dual to
214+
`GaloisInsertion` -/
215+
@[to_dual (reorder := α β, 3 4, l u)]
216+
structure GaloisCoinsertion [Preorder α] [Preorder β] (l : α → β) (u : β → α) where
217+
/-- A constructive choice function for images of `u`. -/
218+
choice : ∀ x : β, x ≤ l (u x) → α
219+
/-- The Galois connection associated to a Galois coinsertion. -/
220+
gc : GaloisConnection l u
221+
/-- Main property of a Galois coinsertion. -/
222+
u_l_le : ∀ x, u (l x) ≤ x
223+
/-- Property of the choice function. -/
224+
choice_eq : ∀ a h, choice a h = u a
225+
212226
/-- A constructor for a Galois insertion with the trivial `choice` function. -/
227+
@[to_dual (reorder := hu hl)
228+
/-- A constructor for a Galois coinsertion with the trivial `choice` function. -/]
213229
def GaloisInsertion.monotoneIntro {α β : Type*} [Preorder α] [Preorder β] {l : α → β} {u : β → α}
214-
(hu : Monotone u) (hl : Monotone l) (hul : ∀ a, a ≤ u (l a)) (hlu : ∀ b, l (u b) = b) :
230+
(hu : Monotone u) (hl : Monotone l) (h_u_l : ∀ a, a ≤ u (l a)) (h_l_u : ∀ b, l (u b) = b) :
215231
GaloisInsertion l u where
216232
choice x _ := l x
217-
gc := GaloisConnection.monotone_intro hu hl hul fun b => le_of_eq (hlu b)
218-
le_l_u b := le_of_eq <| (hlu b).symm
233+
gc := GaloisConnection.monotone_intro hu hl h_u_l fun b => le_of_eq (h_l_u b)
234+
le_l_u b := le_of_eq <| (h_l_u b).symm
219235
choice_eq _ _ := rfl
220236

221237
/-- Make a `GaloisInsertion l u` from a `GaloisConnection l u` such that `∀ b, b ≤ l (u b)` -/
238+
@[to_dual /-- Make a `GaloisCoinsertion` between `αᵒᵈ` and `βᵒᵈ` from a `GaloisInsertion` between
239+
`α` and `β`. -/]
222240
def GaloisConnection.toGaloisInsertion {α β : Type*} [Preorder α] [Preorder β] {l : α → β}
223241
{u : β → α} (gc : GaloisConnection l u) (h : ∀ b, b ≤ l (u b)) : GaloisInsertion l u :=
224242
{ choice := fun x _ => l x
@@ -227,7 +245,7 @@ def GaloisConnection.toGaloisInsertion {α β : Type*} [Preorder α] [Preorder
227245
choice_eq := fun _ _ => rfl }
228246

229247
/-- Lift the bottom along a Galois connection -/
230-
@[implicit_reducible]
248+
@[to_dual (attr := implicit_reducible) /-- Lift the top along a Galois connection -/]
231249
def GaloisConnection.liftOrderBot {α β : Type*} [Preorder α] [OrderBot α] [PartialOrder β]
232250
{l : α → β} {u : β → α} (gc : GaloisConnection l u) :
233251
OrderBot β where
@@ -238,116 +256,53 @@ namespace GaloisInsertion
238256

239257
variable {l : α → β} {u : β → α}
240258

259+
@[to_dual]
241260
theorem l_u_eq [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) (b : β) : l (u b) = b :=
242261
(gi.gc.l_u_le _).antisymm (gi.le_l_u _)
243262

263+
@[to_dual]
244264
theorem leftInverse_l_u [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) :
245265
LeftInverse l u :=
246266
gi.l_u_eq
247267

268+
@[deprecated (since := "2026-03-06")]
269+
alias _root_.GaloisCoinsertion.u_l_leftInverse := GaloisCoinsertion.leftInverse_u_l
270+
271+
@[to_dual]
248272
theorem l_top [Preorder α] [PartialOrder β] [OrderTop α] [OrderTop β]
249273
(gi : GaloisInsertion l u) : l ⊤ = ⊤ :=
250274
top_unique <| (gi.le_l_u _).trans <| gi.gc.monotone_l le_top
251275

276+
@[to_dual]
252277
theorem l_surjective [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) : Surjective l :=
253278
gi.leftInverse_l_u.surjective
254279

280+
@[to_dual]
255281
theorem u_injective [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) : Injective u :=
256282
gi.leftInverse_l_u.injective
257283

284+
@[to_dual]
258285
theorem u_le_u_iff [Preorder α] [Preorder β] (gi : GaloisInsertion l u) {a b} : u a ≤ u b ↔ a ≤ b :=
259286
⟨fun h => (gi.le_l_u _).trans (gi.gc.l_le h), fun h => gi.gc.monotone_u h⟩
260287

288+
@[to_dual]
261289
theorem strictMono_u [Preorder α] [Preorder β] (gi : GaloisInsertion l u) : StrictMono u :=
262290
strictMono_of_le_iff_le fun _ _ => gi.u_le_u_iff.symm
263291

264292
end GaloisInsertion
265293

266-
/-- A Galois coinsertion is a Galois connection where `u ∘ l = id`. It also contains a constructive
267-
choice function, to give better definitional equalities when lifting order structures. Dual to
268-
`GaloisInsertion` -/
269-
structure GaloisCoinsertion [Preorder α] [Preorder β] (l : α → β) (u : β → α) where
270-
/-- A constructive choice function for images of `u`. -/
271-
choice : ∀ x : β, x ≤ l (u x) → α
272-
/-- The Galois connection associated to a Galois coinsertion. -/
273-
gc : GaloisConnection l u
274-
/-- Main property of a Galois coinsertion. -/
275-
u_l_le : ∀ x, u (l x) ≤ x
276-
/-- Property of the choice function. -/
277-
choice_eq : ∀ a h, choice a h = u a
278-
279294
/-- Make a `GaloisInsertion` between `αᵒᵈ` and `βᵒᵈ` from a `GaloisCoinsertion` between `α` and
280295
`β`. -/
296+
@[to_dual /-- Make a `GaloisCoinsertion` between `αᵒᵈ` and `βᵒᵈ` from a `GaloisInsertion` between
297+
`α` and `β`. -/]
281298
def GaloisCoinsertion.dual [Preorder α] [Preorder β] {l : α → β} {u : β → α} :
282299
GaloisCoinsertion l u → GaloisInsertion (toDual ∘ u ∘ ofDual) (toDual ∘ l ∘ ofDual) :=
283300
fun x => ⟨x.1, x.2.dual, x.3, x.4
284301

285-
/-- Make a `GaloisCoinsertion` between `αᵒᵈ` and `βᵒᵈ` from a `GaloisInsertion` between `α` and
286-
`β`. -/
287-
def GaloisInsertion.dual [Preorder α] [Preorder β] {l : α → β} {u : β → α} :
288-
GaloisInsertion l u → GaloisCoinsertion (toDual ∘ u ∘ ofDual) (toDual ∘ l ∘ ofDual) :=
289-
fun x => ⟨x.1, x.2.dual, x.3, x.4
290-
291302
/-- Make a `GaloisInsertion` between `α` and `β` from a `GaloisCoinsertion` between `αᵒᵈ` and
292303
`βᵒᵈ`. -/
304+
@[to_dual /-- Make a `GaloisCoinsertion` between `α` and `β` from a `GaloisInsertion` between `αᵒᵈ`
305+
and `βᵒᵈ`. -/]
293306
def GaloisCoinsertion.ofDual [Preorder α] [Preorder β] {l : αᵒᵈ → βᵒᵈ} {u : βᵒᵈ → αᵒᵈ} :
294307
GaloisCoinsertion l u → GaloisInsertion (ofDual ∘ u ∘ toDual) (ofDual ∘ l ∘ toDual) :=
295308
fun x => ⟨x.1, x.2.dual, x.3, x.4
296-
297-
/-- Make a `GaloisCoinsertion` between `α` and `β` from a `GaloisInsertion` between `αᵒᵈ` and
298-
`βᵒᵈ`. -/
299-
def GaloisInsertion.ofDual [Preorder α] [Preorder β] {l : αᵒᵈ → βᵒᵈ} {u : βᵒᵈ → αᵒᵈ} :
300-
GaloisInsertion l u → GaloisCoinsertion (ofDual ∘ u ∘ toDual) (ofDual ∘ l ∘ toDual) :=
301-
fun x => ⟨x.1, x.2.dual, x.3, x.4
302-
303-
/-- A constructor for a Galois coinsertion with the trivial `choice` function. -/
304-
def GaloisCoinsertion.monotoneIntro [Preorder α] [Preorder β] {l : α → β} {u : β → α}
305-
(hu : Monotone u) (hl : Monotone l) (hlu : ∀ b, l (u b) ≤ b) (hul : ∀ a, u (l a) = a) :
306-
GaloisCoinsertion l u :=
307-
(GaloisInsertion.monotoneIntro hl.dual hu.dual hlu hul).ofDual
308-
309-
/-- Make a `GaloisCoinsertion l u` from a `GaloisConnection l u` such that `∀ a, u (l a) ≤ a` -/
310-
def GaloisConnection.toGaloisCoinsertion {α β : Type*} [Preorder α] [Preorder β] {l : α → β}
311-
{u : β → α} (gc : GaloisConnection l u) (h : ∀ a, u (l a) ≤ a) : GaloisCoinsertion l u :=
312-
{ choice := fun x _ => u x
313-
gc
314-
u_l_le := h
315-
choice_eq := fun _ _ => rfl }
316-
317-
/-- Lift the top along a Galois connection -/
318-
@[implicit_reducible]
319-
def GaloisConnection.liftOrderTop {α β : Type*} [PartialOrder α] [Preorder β] [OrderTop β]
320-
{l : α → β} {u : β → α} (gc : GaloisConnection l u) :
321-
OrderTop α where
322-
top := u ⊤
323-
le_top _ := gc.le_u <| le_top
324-
325-
namespace GaloisCoinsertion
326-
327-
variable {l : α → β} {u : β → α}
328-
329-
theorem u_l_eq [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) (a : α) : u (l a) = a :=
330-
gi.dual.l_u_eq a
331-
332-
theorem u_l_leftInverse [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) :
333-
LeftInverse u l :=
334-
gi.u_l_eq
335-
336-
theorem u_bot [PartialOrder α] [Preorder β] [OrderBot α] [OrderBot β] (gi : GaloisCoinsertion l u) :
337-
u ⊥ = ⊥ :=
338-
gi.dual.l_top
339-
340-
theorem u_surjective [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) : Surjective u :=
341-
gi.dual.l_surjective
342-
343-
theorem l_injective [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) : Injective l :=
344-
gi.dual.u_injective
345-
346-
theorem l_le_l_iff [Preorder α] [Preorder β] (gi : GaloisCoinsertion l u) {a b} :
347-
l a ≤ l b ↔ a ≤ b :=
348-
gi.dual.u_le_u_iff
349-
350-
theorem strictMono_l [Preorder α] [Preorder β] (gi : GaloisCoinsertion l u) : StrictMono l :=
351-
fun _ _ h => gi.dual.strictMono_u h
352-
353-
end GaloisCoinsertion

Mathlib/Order/Monotone/Defs.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ theorem antitoneOn_const [Preorder α] [Preorder β] {c : β} {s : Set α} :
333333
AntitoneOn (fun _ : α ↦ c) s :=
334334
fun _ _ _ _ _ ↦ le_rfl
335335

336+
@[to_dual self]
336337
theorem strictMono_of_le_iff_le [Preorder α] [Preorder β] {f : α → β}
337338
(h : ∀ x y, x ≤ y ↔ f x ≤ f y) : StrictMono f :=
338339
fun _ _ ↦ (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1

Mathlib/Tactic/Translate/ToDual.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ def abbreviationDict : Std.HashMap String String := .ofList [
239239
("nhdsGT", "NhdsLT"),
240240
("nhdsLE", "NhdsGE"),
241241
("nhdsGE", "NhdsLE"),
242-
("neTop", "NeBot")
242+
("neTop", "NeBot"),
243+
("galoisInsertion", "GaloisCoinsertion"),
244+
("galoisCoinsertion", "GaloisInsertion"),
243245
]
244246

245247
/-- The bundle of environment extensions for `to_dual` -/

Mathlib/Topology/Order.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ theorem generateFrom_setOf_isOpen (t : TopologicalSpace α) :
203203

204204
theorem leftInverse_generateFrom :
205205
LeftInverse generateFrom fun t : TopologicalSpace α => { s | IsOpen[t] s } :=
206-
(gciGenerateFrom α).u_l_leftInverse
206+
(gciGenerateFrom α).leftInverse_u_l
207207

208208
theorem generateFrom_surjective : Surjective (generateFrom : Set (Set α) → TopologicalSpace α) :=
209209
(gciGenerateFrom α).u_surjective

0 commit comments

Comments
 (0)