File size: 15,007 Bytes
ae00908
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import OAI.Algebra.Universal.Congruence
import Mathlib.Data.Finset.Lattice.Fold
import Mathlib.Data.Fintype.EquivFin
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.Fintype.Prod

namespace OAI

/-!
# Graph characterization of finite congruence lattices

A finite lattice is the full congruence lattice of a nonempty finite algebra if and only if
it admits a finite nonempty lattice-colored graph satisfying `IsGraphWitness`. Principal
congruences supply the colors in one direction; all label-decreasing self-maps supply the
unary operations in the other.
-/

namespace FiniteCongruence

/-- A label-decreasing self-map; collapsed edges are permitted. -/
def Admissible {Lat Carrier : Type} [LE Lat] (color : Carrier → Carrier → Lat)
    (placement : Carrier → Carrier) : Prop :=
  ∀ left right, color (placement left) (placement right) ≤ color left right

/-- An oriented image of a seed edge under an admissible map. -/
def Marked {Lat Carrier : Type} [LE Lat] (color : Carrier → Carrier → Lat)
    (seeds : Finset (Carrier × Carrier)) (left right : Carrier) : Prop :=
  ∃ placement : Carrier → Carrier, Admissible color placement ∧
    ∃ edge ∈ seeds, placement edge.1 = left ∧ placement edge.2 = right

/-- Finite paths in the undirected marked graph, including paths of length zero. -/
def Connected {Lat Carrier : Type} [LE Lat] (color : Carrier → Carrier → Lat)
    (seeds : Finset (Carrier × Carrier)) (left right : Carrier) : Prop :=
  Relation.EqvGen (Marked color seeds) left right

/-- Symmetric colors separate vertices, satisfy the join triangle inequality, detect order,
and connect every pair below the join of any nonempty finite set of seed colors. -/
def IsGraphWitness {Lat Carrier : Type} [Lattice Lat] [OrderBot Lat]
    (color : Carrier → Carrier → Lat) : Prop :=
  (∀ left right, color left right = color right left) ∧
  (∀ left right, color left right = ⊥ ↔ left = right) ∧
  (∀ left right middle, color left right ≤ color left middle ⊔ color middle right) ∧
  (∀ lower upper : Lat, ¬ lower ≤ upper →
    ∃ left right, color left right ≤ lower ∧ ¬ color left right ≤ upper) ∧
  (∀ seeds : Finset (Carrier × Carrier), seeds.Nonempty → ∀ left right,
    color left right ≤ seeds.sup (fun edge => color edge.1 edge.2) →
      Connected color seeds left right)

/-- The graph size is unbounded, but each individual witness is finite and nonempty. -/
def HasGraphWitness (Lat : Type) [Lattice Lat] [OrderBot Lat] : Prop :=
  ∃ size : ℕ, 0 < size ∧ ∃ color : Fin size → Fin size → Lat, IsGraphWitness color

section PrincipalColors

variable {Lat Carrier : Type} [Lattice Lat] [OrderBot Lat] {alg : Algebra Carrier}

/-- Color a pair by its principal congruence, transported to the lattice. -/
noncomputable def principalColor (equiv : Lat ≃o Congruence alg) (left right : Carrier) : Lat :=
  equiv.symm (Congruence.principal alg left right)

omit [OrderBot Lat] in
theorem principalColor_le (equiv : Lat ≃o Congruence alg) {left right : Carrier} {bound : Lat} :
    principalColor equiv left right ≤ bound ↔ equiv bound left right := by
  change equiv.symm (Congruence.principal alg left right) ≤ bound ↔ _
  rw [equiv.symm_apply_le]
  exact Congruence.principal_le

theorem map_bot_equality (equiv : Lat ≃o Congruence alg) :
    equiv ⊥ = Congruence.equality alg := by
  apply le_antisymm
  · have : (⊥ : Lat) ≤ equiv.symm (Congruence.equality alg) := bot_le
    simpa using equiv.monotone this
  · exact Congruence.equality_le _

theorem principalColor_eq_bot (equiv : Lat ≃o Congruence alg) (left right : Carrier) :
    principalColor equiv left right = ⊥ ↔ left = right := by
  rw [← le_bot_iff, principalColor_le, map_bot_equality, Congruence.equality_apply]

omit [OrderBot Lat] in
theorem principalColor_triangle (equiv : Lat ≃o Congruence alg) (left right middle : Carrier) :
    principalColor equiv left right ≤
      principalColor equiv left middle ⊔ principalColor equiv middle right := by
  apply (principalColor_le equiv).mpr
  apply (equiv _).trans
  · exact (principalColor_le equiv).mp le_sup_left
  · exact (principalColor_le equiv).mp le_sup_right

omit [OrderBot Lat] in
theorem principalColor_reflect (equiv : Lat ≃o Congruence alg) (lower upper : Lat)
    (notBelow : ¬ lower ≤ upper) :
    ∃ left right, principalColor equiv left right ≤ lower ∧
      ¬ principalColor equiv left right ≤ upper := by
  classical
  by_contra noPair
  apply notBelow
  apply equiv.le_iff_le.mp
  intro left right related
  by_contra notRelated
  exact noPair ⟨left, right, (principalColor_le equiv).mpr related,
    by simpa [principalColor_le] using notRelated⟩

end PrincipalColors

theorem admissible_id {Lat Carrier : Type} [Preorder Lat] (color : Carrier → Carrier → Lat) :
    Admissible color id := fun _ _ => le_rfl

theorem Admissible.comp {Lat Carrier : Type} [Preorder Lat]
    {color : Carrier → Carrier → Lat} {outer inner : Carrier → Carrier}
    (outerAdmissible : Admissible color outer) (innerAdmissible : Admissible color inner) :
    Admissible color (outer ∘ inner) :=
  fun left right => le_trans (outerAdmissible _ _) (innerAdmissible left right)

theorem marked_map {Lat Carrier : Type} [Preorder Lat] {color : Carrier → Carrier → Lat}
    {seeds : Finset (Carrier × Carrier)} {placement : Carrier → Carrier}
    (admissible : Admissible color placement) {left right : Carrier}
    (marked : Marked color seeds left right) :
    Marked color seeds (placement left) (placement right) := by
  rcases marked with ⟨inner, innerAdmissible, edge, member, rfl, rfl⟩
  exact ⟨placement ∘ inner, admissible.comp innerAdmissible, edge, member, rfl, rfl⟩

theorem connected_map {Lat Carrier : Type} [Preorder Lat] {color : Carrier → Carrier → Lat}
    {seeds : Finset (Carrier × Carrier)} {placement : Carrier → Carrier}
    (admissible : Admissible color placement) {left right : Carrier}
    (connected : Connected color seeds left right) :
    Connected color seeds (placement left) (placement right) := by
  induction connected with
  | rel left right marked => exact Relation.EqvGen.rel _ _ (marked_map admissible marked)
  | refl point => exact Relation.EqvGen.refl _
  | symm left right _ inductionHyp => exact Relation.EqvGen.symm _ _ inductionHyp
  | trans left middle right _ _ first second => exact Relation.EqvGen.trans _ _ _ first second

section Forward

variable {Lat Carrier : Type} [Lattice Lat] [OrderBot Lat] {alg : Algebra Carrier}

omit [OrderBot Lat] in
theorem translation_admissible (equiv : Lat ≃o Congruence alg) (index : Fin alg.numOps)
    (coord : Fin (alg.arity index)) (inputs : Fin (alg.arity index) → Carrier) :
    Admissible (principalColor equiv) (translation alg index coord inputs) := by
  intro left right
  apply (principalColor_le equiv).mpr
  exact translation_preserves (equiv (principalColor equiv left right)) index coord inputs
    ((principalColor_le equiv).mp le_rfl)

/-- Connectivity in the marked graph is a congruence of the original algebra, not just
of its admissible unary maps. -/
noncomputable def pathCongruence (equiv : Lat ≃o Congruence alg)
    (seeds : Finset (Carrier × Carrier)) : Congruence alg :=
  ⟨Relation.EqvGen.setoid (Marked (principalColor equiv) seeds), by
    apply (compatible_iff_translations alg _).mpr
    intro index coord inputs left right related
    exact connected_map (translation_admissible equiv index coord inputs) related⟩

theorem principalColor_connected (equiv : Lat ≃o Congruence alg)
    (seeds : Finset (Carrier × Carrier)) (left right : Carrier)
    (below : principalColor equiv left right ≤
      seeds.sup (fun edge => principalColor equiv edge.1 edge.2)) :
    Connected (principalColor equiv) seeds left right := by
  have supBelow : seeds.sup (fun edge => principalColor equiv edge.1 edge.2) ≤
      equiv.symm (pathCongruence equiv seeds) := by
    apply Finset.sup_le
    intro edge member
    change equiv.symm (Congruence.principal alg edge.1 edge.2) ≤
      equiv.symm (pathCongruence equiv seeds)
    apply equiv.symm.monotone
    apply Congruence.principal_le.mpr
    exact Relation.EqvGen.rel _ _ ⟨id, admissible_id _, edge, member, rfl, rfl⟩
  have principalBelow : Congruence.principal alg left right ≤ pathCongruence equiv seeds :=
    equiv.symm.le_iff_le.mp (below.trans supBelow)
  exact Congruence.principal_le.mp principalBelow

theorem principalColor_isGraphWitness (equiv : Lat ≃o Congruence alg) :
    IsGraphWitness (principalColor equiv) := by
  refine ⟨?_, principalColor_eq_bot equiv, principalColor_triangle equiv,
    principalColor_reflect equiv, ?_⟩
  · intro left right
    simp only [principalColor, Congruence.principal_comm left right]
  · intro seeds _ left right below
    exact principalColor_connected equiv seeds left right below

end Forward

section Backward

variable {Lat Carrier : Type} [Lattice Lat] [OrderBot Lat] [Fintype Carrier]

/-- All label-decreasing maps, made into a finite list of unary total operations. -/
noncomputable def graphAlgebra (color : Carrier → Carrier → Lat) : Algebra Carrier := by
  classical
  let Maps := {placement : Carrier → Carrier // Admissible color placement}
  exact {
    numOps := Fintype.card Maps
    arity := fun _ => 1
    op := fun index inputs => ((Fintype.equivFin Maps).symm index).1 (inputs 0)
  }

omit [OrderBot Lat] in
/-- Every admissible map is one of the basic unary operations. -/
theorem graphAlgebra_preserves (color : Carrier → Carrier → Lat)
    (rel : Congruence (graphAlgebra color)) {placement : Carrier → Carrier}
    (admissible : Admissible color placement) {left right : Carrier} (related : rel left right) :
    rel (placement left) (placement right) := by
  classical
  let Maps := {placement : Carrier → Carrier // Admissible color placement}
  have preserved := rel.compatible ((Fintype.equivFin Maps) ⟨placement, admissible⟩)
    (fun _ => left) (fun _ => right) (fun _ => related)
  simpa only [graphAlgebra, Maps, Equiv.symm_apply_apply] using preserved

/-- Each lattice element defines the equivalence relation of edges below its color. -/
noncomputable def labelCongruence (color : Carrier → Carrier → Lat)
    (witness : IsGraphWitness color) (bound : Lat) : Congruence (graphAlgebra color) := by
  classical
  refine ⟨⟨fun left right => color left right ≤ bound, ⟨?_, ?_, ?_⟩⟩, ?_⟩
  · intro point
    rw [(witness.2.1 point point).mpr rfl]
    exact bot_le
  · intro left right below
    rwa [witness.1 right left]
  · intro left middle right first second
    exact (witness.2.2.1 left right middle).trans (sup_le first second)
  · intro index left right below
    exact ((((Fintype.equivFin
      {placement : Carrier → Carrier // Admissible color placement}).symm index).2) _ _).trans
        (below ⟨0, by change 0 < 1; decide⟩)

@[simp] theorem labelCongruence_apply (color : Carrier → Carrier → Lat)
    (witness : IsGraphWitness color) (bound : Lat) (left right : Carrier) :
    labelCongruence color witness bound left right ↔ color left right ≤ bound := Iff.rfl

theorem labelCongruence_le_iff (color : Carrier → Carrier → Lat)
    (witness : IsGraphWitness color) (lower upper : Lat) :
    labelCongruence color witness lower ≤ labelCongruence color witness upper ↔ lower ≤ upper := by
  constructor
  · intro below
    by_contra notBelow
    obtain ⟨left, right, belowLower, notBelowUpper⟩ := witness.2.2.2.1 lower upper notBelow
    exact notBelowUpper (below belowLower)
  · intro below left right belowLower
    exact belowLower.trans below

omit [OrderBot Lat] in
/-- Equivalence closure of marked edges lies in every congruence containing the seed edges. -/
theorem connected_below_congruence (color : Carrier → Carrier → Lat)
    (rel : Congruence (graphAlgebra color)) (seeds : Finset (Carrier × Carrier))
    (contains : ∀ edge ∈ seeds, rel edge.1 edge.2) {left right : Carrier}
    (connected : Connected color seeds left right) : rel left right := by
  induction connected with
  | rel left right marked =>
    obtain ⟨placement, admissible, edge, member, rfl, rfl⟩ := marked
    exact graphAlgebra_preserves color rel admissible (contains edge member)
  | refl point => exact rel.refl point
  | symm left right _ inductionHyp => exact rel.symm inductionHyp
  | trans left middle right _ _ first second => exact rel.trans first second

/-- Every congruence is recovered using all its related pairs. -/
theorem labelCongruence_surjective [Nonempty Carrier] (color : Carrier → Carrier → Lat)
    (witness : IsGraphWitness color) : Function.Surjective (labelCongruence color witness) := by
  classical
  intro rel
  let seeds : Finset (Carrier × Carrier) := Finset.univ.filter (fun edge => rel edge.1 edge.2)
  have membership : ∀ edge, edge ∈ seeds ↔ rel edge.1 edge.2 := by simp [seeds]
  have nonempty : seeds.Nonempty := by
    obtain ⟨point⟩ := ‹Nonempty Carrier›
    exact ⟨(point, point), (membership _).mpr (rel.refl point)⟩
  refine ⟨seeds.sup (fun edge => color edge.1 edge.2), ?_⟩
  apply Congruence.ext
  intro left right
  constructor
  · intro below
    exact connected_below_congruence color rel seeds (fun edge member => (membership edge).mp member)
      (witness.2.2.2.2 seeds nonempty left right below)
  · intro related
    change color left right ≤ seeds.sup (fun edge => color edge.1 edge.2)
    exact Finset.le_sup (f := fun edge : Carrier × Carrier => color edge.1 edge.2)
      ((membership (left, right)).mpr related)

/-- The lattice is isomorphic to the full congruence lattice of the graph algebra. -/
noncomputable def graphOrderIso [Nonempty Carrier] (color : Carrier → Carrier → Lat)
    (witness : IsGraphWitness color) : Lat ≃o Congruence (graphAlgebra color) :=
  { Equiv.ofBijective (labelCongruence color witness)
      ⟨fun lower upper equal => le_antisymm
        ((labelCongruence_le_iff color witness lower upper).mp equal.le)
        ((labelCongruence_le_iff color witness upper lower).mp equal.ge),
        labelCongruence_surjective color witness⟩ with
    map_rel_iff' := fun {lower upper} => labelCongruence_le_iff color witness lower upper }

end Backward

/-- A finite lattice is representable as the full congruence lattice of a nonempty finite
algebra exactly when it has a finite nonempty colored-graph witness. -/
theorem graph_criterion (Lat : Type) [Fintype Lat] [Lattice Lat] [OrderBot Lat] :
    Representable Lat ↔ HasGraphWitness Lat := by
  constructor
  · rintro ⟨size, positive, alg, ⟨equiv⟩⟩
    exact ⟨size, positive, principalColor equiv, principalColor_isGraphWitness equiv⟩
  · rintro ⟨size, positive, color, witness⟩
    have : Nonempty (Fin size) := ⟨⟨0, positive⟩⟩
    exact ⟨size, positive, graphAlgebra color, ⟨graphOrderIso color witness⟩⟩

end FiniteCongruence

end OAI