Skip to content

Commit bcf30a0

Browse files
vihdzpvihdzp
andcommitted
feat: the Dedekind–MacNeille completion (leanprover-community#26966)
We define the type of Dedekind cuts `DedekindCut α` as an abbreviation for `Concept α α (· ≤ ·)`. We prove that it's the smallest complete lattice containing a given partial order, in the sense that any embedding from `α` into a complete lattice factors through it. Co-authored-by: vihdzp <vi.hdz.p@mgmail.com>
1 parent 5d5ae53 commit bcf30a0

3 files changed

Lines changed: 249 additions & 5 deletions

File tree

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5746,6 +5746,7 @@ public import Mathlib.Order.CompleteLattice.SetLike
57465746
public import Mathlib.Order.CompleteLatticeIntervals
57475747
public import Mathlib.Order.CompletePartialOrder
57485748
public import Mathlib.Order.CompleteSublattice
5749+
public import Mathlib.Order.Completion
57495750
public import Mathlib.Order.Concept
57505751
public import Mathlib.Order.ConditionallyCompleteLattice.Basic
57515752
public import Mathlib.Order.ConditionallyCompleteLattice.Defs

Mathlib/Order/Completion.lean

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
/-
2+
Copyright (c) 2025 Violeta Hernández Palacios. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Violeta Hernández Palacios
5+
-/
6+
module
7+
8+
public import Mathlib.Order.Concept
9+
10+
import Mathlib.Order.UpperLower.CompleteLattice
11+
12+
/-!
13+
# Dedekind-MacNeille completion
14+
15+
The Dedekind-MacNeille completion of a partial order is the smallest complete lattice into which it
16+
embeds.
17+
18+
The theory of concept lattices allows for a simple construction. In fact, `DedekindCut α` is simply
19+
an abbreviation for `Concept α α (· ≤ ·)`. This means we don't need to reprove that this is a
20+
complete lattice; instead, the file simply proves that any order embedding into another complete
21+
lattice factors through it.
22+
23+
## Todo
24+
25+
- Build the order isomorphism `DedekindCut ℚ ≃o EReal`.
26+
27+
## Tags
28+
29+
Dedekind completion, Dedekind cut
30+
-/
31+
32+
@[expose] public section
33+
34+
open Concept Set
35+
36+
variable {α β : Type*}
37+
38+
variable (α) in
39+
/-- The **Dedekind-MacNeille completion** of a partial order is the smallest complete lattice that
40+
contains it. We define here the type of Dedekind cuts of `α` as the `Concept` lattice of the `≤`
41+
relation of `α`.
42+
43+
For `A : DedekindCut α`, the sets `A.left` and `A.right` are related by
44+
`upperBounds A.left = A.right` and `lowerBounds A.right = A.left`.
45+
46+
The theorem `DedekindCut.principalEmbedding_trans_factorEmbedding` proves that if `α` is a partial
47+
order and `β` is a complete lattice, any embedding `α ↪o β` factors through `DedekindCut α`. -/
48+
abbrev DedekindCut [Preorder α] := Concept α α (· ≤ ·)
49+
50+
namespace DedekindCut
51+
52+
section Preorder
53+
variable [Preorder α] [Preorder β]
54+
55+
/-- The left set of a Dedekind cut. This is an alias for `Concept.extent`. -/
56+
abbrev left (A : DedekindCut α) : Set α := A.extent
57+
58+
/-- The right set of a Dedekind cut. This is an alias for `Concept.intent`. -/
59+
abbrev right (A : DedekindCut α) : Set α := A.intent
60+
61+
/-- See `DedekindCut.ext'` for a version using the right set instead. -/
62+
@[ext] theorem ext {A B : DedekindCut α} (h : A.left = B.left) : A = B := Concept.ext h
63+
64+
/-- See `DedekindCut.ext` for a version using the left set instead. -/
65+
theorem ext' {A B : DedekindCut α} (h : A.right = B.right) : A = B := Concept.ext' h
66+
67+
@[simp]
68+
theorem upperBounds_left (A : DedekindCut α) : upperBounds A.left = A.right :=
69+
A.upperPolar_extent
70+
71+
@[simp]
72+
theorem lowerBounds_right (A : DedekindCut α) : lowerBounds A.right = A.left :=
73+
A.lowerPolar_intent
74+
75+
theorem image_left_subset_lowerBounds {f : α → β} (hf : Monotone f)
76+
(A : DedekindCut α) : f '' A.left ⊆ lowerBounds (f '' A.right) := by
77+
rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩
78+
exact hf <| rel_extent_intent hx hy
79+
80+
theorem image_right_subset_upperBounds {f : α → β} (hf : Monotone f)
81+
(A : DedekindCut α) : f '' A.right ⊆ upperBounds (f '' A.left) := by
82+
rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩
83+
exact hf <| rel_extent_intent hy hx
84+
85+
/-- Convert an element into its Dedekind cut (`Iic a`, `Ici a`). This map is order-preserving,
86+
though it is injective only on partial orders. -/
87+
def principal (a : α) : DedekindCut α :=
88+
(Concept.ofObject _ a).copy (Iic a) (Ici a)
89+
(by ext; simpa [mem_lowerPolar_iff] using forall_ge_iff_le.symm)
90+
(by ext; simp)
91+
92+
@[simp] theorem left_principal (a : α) : (principal a).left = Iic a := rfl
93+
@[simp] theorem right_principal (a : α) : (principal a).right = Ici a := rfl
94+
95+
@[simp] theorem ofObject_eq_principal (a : α) : ofObject (· ≤ ·) a = principal a :=
96+
(copy_eq ..).symm
97+
@[simp] theorem ofAttribute_eq_principal (a : α) : ofAttribute (· ≤ ·) a = principal a := by
98+
ext; simp
99+
100+
@[simp]
101+
theorem principal_le_principal {a b : α} : principal a ≤ principal b ↔ a ≤ b := by
102+
simpa using ofObject_le_ofAttribute_iff (r := (· ≤ ·)) (a := a)
103+
104+
@[simp]
105+
theorem principal_lt_principal {a b : α} : principal a < principal b ↔ a < b := by
106+
simp [lt_iff_le_not_ge]
107+
108+
/-- We can never have a computable decidable instance, for the same reason we can't on `Set α`. -/
109+
noncomputable instance : DecidableLE (DedekindCut α) :=
110+
Classical.decRel _
111+
112+
end Preorder
113+
114+
section PartialOrder
115+
variable [PartialOrder α]
116+
117+
@[simp]
118+
theorem principal_inj {a b : α} : principal a = principal b ↔ a = b := by
119+
simp [le_antisymm_iff]
120+
121+
/-- `DedekindCut.principal` as an `OrderEmbedding`. -/
122+
@[simps! apply]
123+
def principalEmbedding : α ↪o DedekindCut α where
124+
toFun := principal
125+
inj' _ _ := principal_inj.1
126+
map_rel_iff' := principal_le_principal
127+
128+
@[simp] theorem coe_principalEmbedding : ⇑(@principalEmbedding α _) = principal := rfl
129+
130+
end PartialOrder
131+
132+
section CompleteLattice
133+
variable [CompleteLattice α] [PartialOrder β]
134+
135+
@[simp]
136+
theorem principal_sSup_left (A : DedekindCut α) : principal (sSup A.left) = A := by
137+
apply ext'
138+
ext
139+
rw [right_principal, mem_Ici, sSup_le_iff, ← upperBounds_left, mem_upperBounds]
140+
141+
@[simp]
142+
theorem principal_sInf_right (A : DedekindCut α) : principal (sInf A.right) = A := by
143+
ext
144+
rw [left_principal, mem_Iic, le_sInf_iff, ← lowerBounds_right, mem_lowerBounds]
145+
146+
/-- Any order embedding `β ↪o α` into a complete lattice `α` factors through `DedekindCut β`.
147+
148+
This map is defined so that `factorEmbedding f A = sSup (f '' A.left)`. Although the construction
149+
`factorEmbedding f A = sInf (f '' A.right)` would also work, these do **not** in general give equal
150+
embeddings. -/
151+
def factorEmbedding (f : β ↪o α) : DedekindCut β ↪o α :=
152+
.ofMapLEIff (fun A ↦ sSup (f '' A.left)) <| by
153+
refine fun A B ↦ ⟨fun h x hx ↦ ?_, fun h ↦ sSup_le_sSup (image_mono h)⟩
154+
simp_rw [← lowerBounds_right]
155+
simp_rw [le_sSup_iff, sSup_le_iff, forall_mem_image] at h
156+
intro y hy
157+
rw [← f.le_iff_le]
158+
exact h _ (image_right_subset_upperBounds f.monotone _ (mem_image_of_mem _ hy)) hx
159+
160+
theorem factorEmbedding_apply (f : β ↪o α) (A : DedekindCut β) :
161+
factorEmbedding f A = sSup (f '' A.left) :=
162+
rfl
163+
164+
@[simp]
165+
theorem factorEmbedding_principal (f : β ↪o α) (x : β) : factorEmbedding f (principal x) = f x := by
166+
rw [factorEmbedding_apply]
167+
apply le_antisymm (by simp)
168+
rw [le_sSup_iff]
169+
refine fun y hy ↦ hy ?_
170+
simp
171+
172+
/-- The Dedekind-MacNeille completion of a partial order is the smallest complete lattice containing
173+
it, in the sense that any embedding into any complete lattice factors through it. -/
174+
theorem principalEmbedding_trans_factorEmbedding (f : β ↪o α) :
175+
principalEmbedding.trans (factorEmbedding f) = f := by
176+
ext; simp
177+
178+
/-- `DedekindCut.principal` as an `OrderIso`.
179+
180+
This provides the second half of the **fundamental theorem of concept lattices**: every complete
181+
lattice is isomorphic to a concept lattice (its own Dedekind completion).
182+
183+
See `Concept.instCompleteLattice` for the first half. -/
184+
@[simps! apply]
185+
def principalIso : α ≃o DedekindCut α where
186+
invFun := factorEmbedding (OrderIso.refl α)
187+
left_inv x := factorEmbedding_principal _ x
188+
right_inv x := by simp [factorEmbedding]
189+
__ := principalEmbedding
190+
191+
theorem principalIso_symm_apply (A : DedekindCut α) : principalIso.symm A = sSup A.left :=
192+
(factorEmbedding_apply ..).trans <| by simp
193+
194+
end CompleteLattice
195+
196+
section LinearOrder
197+
variable [LinearOrder α]
198+
199+
instance : @Std.Total (DedekindCut α) (· ≤ ·) where
200+
total x y := le_total (α := LowerSet α) ⟨_, isLowerSet_extent_le x⟩ ⟨_, isLowerSet_extent_le y⟩
201+
202+
noncomputable instance : LinearOrder (DedekindCut α) where
203+
min_def x y := congrFun₂ inf_eq_minDefault x y
204+
max_def x y := congrFun₂ sup_eq_maxDefault x y
205+
le_total := total_of _
206+
toDecidableLE := inferInstance
207+
208+
noncomputable instance : CompleteLinearOrder (DedekindCut α) where
209+
__ := inferInstanceAs (LinearOrder _)
210+
__ := inferInstanceAs (CompleteLattice _)
211+
__ := LinearOrder.toBiheytingAlgebra _
212+
213+
end LinearOrder
214+
end DedekindCut

Mathlib/Order/Concept.lean

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@ the concept lattice of its `≤`.
2424
Concept lattices are usually defined from a *context*, that is the triple `(α, β, r)`, but the type
2525
of `r` determines `α` and `β` already, so we do not define contexts as a separate object.
2626
27-
## TODO
28-
29-
Prove the fundamental theorem of concept lattices.
30-
3127
## References
3228
3329
* [Davey, Priestley *Introduction to Lattices and Order*][davey_priestley]
3430
* [Birkhoff, Garrett *Lattice Theory*][birkhoff1940]
3531
3632
## Tags
3733
38-
concept, formal concept analysis, intent, extend, attribute
34+
concept, formal concept analysis, intent, extent, object, attribute
3935
-/
4036

4137
@[expose] public section
@@ -57,6 +53,9 @@ which `r` relates to all elements of `t`. -/
5753
def lowerPolar (t : Set β) : Set α :=
5854
{ a | ∀ ⦃b⦄, b ∈ t → r a b }
5955

56+
@[simp] theorem upperPolar_le [LE α] : upperPolar (· ≤ ·) s = upperBounds s := rfl
57+
@[simp] theorem lowerPolar_le [LE β] : lowerPolar (· ≤ ·) t = lowerBounds t := rfl
58+
6059
variable {r} {a : α} {b : β}
6160

6261
theorem mem_upperPolar_iff : b ∈ upperPolar r s ↔ ∀ ⦃a⦄, a ∈ s → r a b := .rfl
@@ -460,6 +459,32 @@ theorem strictMono_extent : StrictMono (@extent α β r) := fun _ _ =>
460459
theorem strictAnti_intent : StrictAnti (@intent α β r) := fun _ _ =>
461460
intent_ssubset_intent_iff.2
462461

462+
@[simp]
463+
theorem isLowerSet_extent_le {α : Type*} [Preorder α] (c : Concept α α (· ≤ ·)) :
464+
IsLowerSet c.extent :=
465+
@mem_extent_of_rel_extent _ _ _ _
466+
467+
@[simp]
468+
theorem isUpperSet_intent_le {α : Type*} [Preorder α] (c : Concept α α (· ≤ ·)) :
469+
IsUpperSet c.intent :=
470+
@mem_intent_of_intent_rel _ _ _ _
471+
472+
@[simp]
473+
theorem isLowerSet_extent_lt {α : Type*} [PartialOrder α] (c : Concept α α (· < ·)) :
474+
IsLowerSet c.extent := by
475+
intro a b hb ha
476+
obtain rfl | hb := hb.eq_or_lt
477+
· assumption
478+
· exact mem_extent_of_rel_extent hb ha
479+
480+
@[simp]
481+
theorem isUpperSet_intent_lt {α : Type*} [PartialOrder α] (c : Concept α α (· < ·)) :
482+
IsUpperSet c.intent := by
483+
intro a b hb ha
484+
obtain rfl | hb := hb.eq_or_lt
485+
· assumption
486+
· exact mem_intent_of_intent_rel hb ha
487+
463488
@[simps!]
464489
instance : Max (Concept α β r) where
465490
max c d := ofIsIntent _ _ (c.isIntent_intent.inter d.isIntent_intent)
@@ -519,6 +544,10 @@ instance : InfSet (Concept α β r) where
519544
instance : SupSet (Concept α β r) where
520545
sSup S := ofIsIntent _ _ (.iInter₂ _ fun c (_ : c ∈ S) ↦ c.isIntent_intent)
521546

547+
/-- One half of the **fundamental theorem of concept lattices**: every concept lattice is a complete
548+
lattice.
549+
550+
See `DedekindCut.principalIso` for the second half. -/
522551
instance : CompleteLattice (Concept α β r) where
523552
isLUB_sSup s := by
524553
refine ⟨fun _ hc ↦ ?_, fun _ hc ↦ ?_⟩

0 commit comments

Comments
 (0)