Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 033a131

Browse files
committed
chore(order/zorn): add module docstring (#7767)
add module docstring, tidy up notation a bit
1 parent d0ebc8e commit 033a131

File tree

1 file changed

+85
-75
lines changed

1 file changed

+85
-75
lines changed

src/order/zorn.lean

Lines changed: 85 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,28 @@
22
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Johannes Hölzl
5+
-/
6+
import data.set.lattice
7+
8+
/-!
9+
# Chains and Zorn's lemmas
10+
11+
This file defines chains for an arbitrary relation and proves several formulations of Zorn's Lemma,
12+
along with Hausdorff's Maximality Principle.
13+
14+
## Main declarations
15+
16+
* `chain c`: A chain `c` is a set of comparable elements.
17+
* `max_chain_spec`: Hausdorff's Maximality Principle.
18+
* `exists_maximal_of_chains_bounded`: Zorn's Lemma. Many variants are offered.
519
6-
Zorn's lemmas.
20+
## Notes
721
8-
Ported from Isabelle/HOL (written by Jacques D. Fleuriot, Tobias Nipkow, and Christian Sternagel).
22+
Ported from Isabelle/HOL. The
23+
[original file](https://isabelle.in.tum.de/dist/library/HOL/HOL/Zorn.html) was written by Jacques D.
24+
Fleuriot, Tobias Nipkow, Christian Sternagel.
925
-/
10-
import data.set.lattice
26+
1127
noncomputable theory
1228

1329
universes u
@@ -20,36 +36,35 @@ section chain
2036
parameters {α : Type u} (r : α → α → Prop)
2137
local infix ` ≺ `:50 := r
2238

23-
/-- A chain is a subset `c` satisfying
24-
`x ≺ y ∨ x = y ∨ y ≺ x` for all `x y ∈ c`. -/
39+
/-- A chain is a subset `c` satisfying `x ≺ y ∨ x = y ∨ y ≺ x` for all `x y ∈ c`. -/
2540
def chain (c : set α) := pairwise_on c (λ x y, x ≺ y ∨ y ≺ x)
2641
parameters {r}
2742

28-
theorem chain.total_of_refl [is_refl α r]
43+
lemma chain.total_of_refl [is_refl α r]
2944
{c} (H : chain c) {x y} (hx : x ∈ c) (hy : y ∈ c) :
3045
x ≺ y ∨ y ≺ x :=
3146
if e : x = y then or.inl (e ▸ refl _) else H _ hx _ hy e
3247

33-
theorem chain.mono {c c'} :
48+
lemma chain.mono {c c'} :
3449
c' ⊆ c → chain c → chain c' :=
3550
pairwise_on.mono
3651

37-
theorem chain.directed_on [is_refl α r] {c} (H : chain c) :
52+
lemma chain.directed_on [is_refl α r] {c} (H : chain c) :
3853
directed_on (≺) c :=
39-
assume x hx y hy,
54+
λ x hx y hy,
4055
match H.total_of_refl hx hy with
4156
| or.inl h := ⟨y, hy, h, refl _⟩
4257
| or.inr h := ⟨x, hx, refl _, h⟩
4358
end
4459

45-
theorem chain_insert {c : set α} {a : α} (hc : chain c) (ha : ∀ b ∈ c, b ≠ a → a ≺ b ∨ b ≺ a) :
60+
lemma chain_insert {c : set α} {a : α} (hc : chain c) (ha : ∀ b ∈ c, b ≠ a → a ≺ b ∨ b ≺ a) :
4661
chain (insert a c) :=
4762
forall_insert_of_forall
48-
(assume x hx, forall_insert_of_forall (hc x hx) (assume hneq, (ha x hx hneq).symm))
63+
(λ x hx, forall_insert_of_forall (hc x hx) (λ hneq, (ha x hx hneq).symm))
4964
(forall_insert_of_forall
50-
(assume x hx hneq, ha x hx $ assume h', hneq h'.symm) (assume h, (h rfl).rec _))
65+
(λ x hx hneq, ha x hx $ λ h', hneq h'.symm) (λ h, (h rfl).rec _))
5166

52-
/-- `super_chain c₁ c₂` means that `c₂ is a chain that strictly includes `c₁`. -/
67+
/-- `super_chain c₁ c₂` means that `c₂` is a chain that strictly includes `c₁`. -/
5368
def super_chain (c₁ c₂ : set α) : Prop := chain c₂ ∧ c₁ ⊂ c₂
5469

5570
/-- A chain `c` is a maximal chain if there does not exists a chain strictly including `c`. -/
@@ -60,54 +75,54 @@ is one of these chains. Otherwise it is `c`. -/
6075
def succ_chain (c : set α) : set α :=
6176
if h : ∃ c', chain c ∧ super_chain c c' then some h else c
6277

63-
theorem succ_spec {c : set α} (h : ∃ c', chain c ∧ super_chain c c') :
78+
lemma succ_spec {c : set α} (h : ∃ c', chain c ∧ super_chain c c') :
6479
super_chain c (succ_chain c) :=
6580
let ⟨c', hc'⟩ := h in
6681
have chain c ∧ super_chain c (some h),
6782
from @some_spec _ (λc', chain c ∧ super_chain c c') _,
6883
by simp [succ_chain, dif_pos, h, this.right]
6984

70-
theorem chain_succ {c : set α} (hc : chain c) :
85+
lemma chain_succ {c : set α} (hc : chain c) :
7186
chain (succ_chain c) :=
7287
if h : ∃ c', chain c ∧ super_chain c c' then
7388
(succ_spec h).left
7489
else
7590
by simp [succ_chain, dif_neg, h]; exact hc
7691

77-
theorem super_of_not_max {c : set α} (hc₁ : chain c) (hc₂ : ¬ is_max_chain c) :
92+
lemma super_of_not_max {c : set α} (hc₁ : chain c) (hc₂ : ¬ is_max_chain c) :
7893
super_chain c (succ_chain c) :=
7994
begin
8095
simp [is_max_chain, not_and_distrib, not_forall_not] at hc₂,
8196
cases hc₂.neg_resolve_left hc₁ with c' hc',
8297
exact succ_spec ⟨c', hc₁, hc'⟩
8398
end
8499

85-
theorem succ_increasing {c : set α} :
100+
lemma succ_increasing {c : set α} :
86101
c ⊆ succ_chain c :=
87102
if h : ∃ c', chain c ∧ super_chain c c' then
88103
have super_chain c (succ_chain c), from succ_spec h,
89104
this.right.left
90105
else by simp [succ_chain, dif_neg, h, subset.refl]
91106

92107
/-- Set of sets reachable from `∅` using `succ_chain` and `⋃₀`. -/
93-
inductive chain_closure : set α → Prop
108+
inductive chain_closure : set (set α)
94109
| succ : ∀ {s}, chain_closure s → chain_closure (succ_chain s)
95110
| union : ∀ {s}, (∀ a ∈ s, chain_closure a) → chain_closure (⋃₀ s)
96111

97-
theorem chain_closure_empty :
98-
chain_closure ∅ :=
112+
lemma chain_closure_empty :
113+
∅ ∈ chain_closure :=
99114
have chain_closure (⋃₀ ∅),
100-
from chain_closure.union $ assume a h, h.rec _,
115+
from chain_closure.union $ λ a h, h.rec _,
101116
by simp at this; assumption
102117

103-
theorem chain_closure_closure :
104-
chain_closure (⋃₀ chain_closure) :=
105-
chain_closure.union $ assume s hs, hs
118+
lemma chain_closure_closure :
119+
⋃₀ chain_closure ∈ chain_closure :=
120+
chain_closure.union $ λ s hs, hs
106121

107122
variables {c c₁ c₂ c₃ : set α}
108123

109-
private lemma chain_closure_succ_total_aux (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂)
110-
(h : ∀ {c₃}, chain_closure c₃ → c₃ ⊆ c₂ → c₂ = c₃ ∨ succ_chain c₃ ⊆ c₂) :
124+
private lemma chain_closure_succ_total_aux (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure)
125+
(h : ∀ {c₃}, c₃ ∈ chain_closure → c₃ ⊆ c₂ → c₂ = c₃ ∨ succ_chain c₃ ⊆ c₂) :
111126
c₁ ⊆ c₂ ∨ succ_chain c₂ ⊆ c₁ :=
112127
begin
113128
induction hc₁,
@@ -125,26 +140,26 @@ begin
125140
exact subset.trans h (subset_sUnion_of_mem ha) }
126141
end
127142

128-
private lemma chain_closure_succ_total (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂)
143+
private lemma chain_closure_succ_total (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure)
129144
(h : c₁ ⊆ c₂) :
130145
c₂ = c₁ ∨ succ_chain c₁ ⊆ c₂ :=
131146
begin
132147
induction hc₂ generalizing c₁ hc₁ h,
133148
case succ : c₂ hc₂ ih {
134149
have h₁ : c₁ ⊆ c₂ ∨ @succ_chain α r c₂ ⊆ c₁ :=
135-
(chain_closure_succ_total_aux hc₁ hc₂ $ assume c₁, ih),
150+
(chain_closure_succ_total_aux hc₁ hc₂ $ λ c₁, ih),
136151
cases h₁ with h₁ h₁,
137152
{ have h₂ := ih hc₁ h₁,
138153
cases h₂ with h₂ h₂,
139154
{ exact (or.inr $ h₂ ▸ subset.refl _) },
140155
{ exact (or.inr $ subset.trans h₂ succ_increasing) } },
141156
{ exact (or.inl $ subset.antisymm h₁ h) } },
142157
case union : s hs ih {
143-
apply or.imp_left (assume h', subset.antisymm h' h),
158+
apply or.imp_left (λ h', subset.antisymm h' h),
144159
apply classical.by_contradiction,
145160
simp [not_or_distrib, sUnion_subset_iff, not_forall],
146161
intros c₃ hc₃ h₁ h₂,
147-
have h := chain_closure_succ_total_aux hc₁ (hs c₃ hc₃) (assume c₄, ih _ hc₃),
162+
have h := chain_closure_succ_total_aux hc₁ (hs c₃ hc₃) (λ c₄, ih _ hc₃),
148163
cases h with h h,
149164
{ have h' := ih c₃ hc₃ hc₁ h,
150165
cases h' with h' h',
@@ -153,52 +168,51 @@ begin
153168
{ exact (h₁ $ subset.trans succ_increasing h) } }
154169
end
155170

156-
theorem chain_closure_total (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂) :
171+
lemma chain_closure_total (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure) :
157172
c₁ ⊆ c₂ ∨ c₂ ⊆ c₁ :=
158-
have c₁ ⊆ c₂ ∨ succ_chain c₂ ⊆ c₁,
159-
from chain_closure_succ_total_aux hc₁ hc₂ $ assume c₃ hc₃, chain_closure_succ_total hc₃ hc₂,
160-
or.imp_right (assume : succ_chain c₂ ⊆ c₁, subset.trans succ_increasing this) this
173+
or.imp_right succ_increasing.trans $ chain_closure_succ_total_aux hc₁ hc₂ $ λ c₃ hc₃,
174+
chain_closure_succ_total hc₃ hc₂
161175

162-
theorem chain_closure_succ_fixpoint (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂)
176+
lemma chain_closure_succ_fixpoint (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure)
163177
(h_eq : succ_chain c₂ = c₂) :
164178
c₁ ⊆ c₂ :=
165179
begin
166180
induction hc₁,
167181
case succ : c₁ hc₁ h {
168182
exact or.elim (chain_closure_succ_total hc₁ hc₂ h)
169-
(assume h, h ▸ h_eq.symm ▸ subset.refl c₂) id },
183+
(λ h, h ▸ h_eq.symm ▸ subset.refl c₂) id },
170184
case union : s hs ih {
171-
exact (sUnion_subset $ assume c₁ hc₁, ih c₁ hc₁) }
185+
exact (sUnion_subset $ λ c₁ hc₁, ih c₁ hc₁) }
172186
end
173187

174-
theorem chain_closure_succ_fixpoint_iff (hc : chain_closure c) :
188+
lemma chain_closure_succ_fixpoint_iff (hc : c ∈ chain_closure) :
175189
succ_chain c = c ↔ c = ⋃₀ chain_closure :=
176-
⟨assume h, subset.antisymm
177-
(subset_sUnion_of_mem hc)
190+
⟨λ h, (subset_sUnion_of_mem hc).antisymm
178191
(chain_closure_succ_fixpoint chain_closure_closure hc h),
179-
assume : c = ⋃₀{c : set α | chain_closure c},
192+
λ h,
180193
subset.antisymm
181-
(calc succ_chain c ⊆ ⋃₀{c : set α | chain_closure c} :
194+
(calc succ_chain c ⊆ ⋃₀{c : set α | c ∈ chain_closure} :
182195
subset_sUnion_of_mem $ chain_closure.succ hc
183-
... = c : this.symm)
196+
... = c : h.symm)
184197
succ_increasing⟩
185198

186-
theorem chain_chain_closure (hc : chain_closure c) :
199+
lemma chain_chain_closure (hc : c ∈ chain_closure) :
187200
chain c :=
188201
begin
189202
induction hc,
190203
case succ : c hc h {
191204
exact chain_succ h },
192205
case union : s hs h {
193206
have h : ∀ c ∈ s, zorn.chain c := h,
194-
exact assume c₁ ⟨t₁, ht₁, (hc₁ : c₁ ∈ t₁)⟩ c₂ ⟨t₂, ht₂, (hc₂ : c₂ ∈ t₂)⟩ hneq,
207+
exact λ c₁ ⟨t₁, ht₁, (hc₁ : c₁ ∈ t₁)⟩ c₂ ⟨t₂, ht₂, (hc₂ : c₂ ∈ t₂)⟩ hneq,
195208
have t₁ ⊆ t₂ ∨ t₂ ⊆ t₁, from chain_closure_total (hs _ ht₁) (hs _ ht₂),
196209
or.elim this
197-
(assume : t₁ ⊆ t₂, h t₂ ht₂ c₁ (this hc₁) c₂ hc₂ hneq)
198-
(assume : t₂ ⊆ t₁, h t₁ ht₁ c₁ hc₁ c₂ (this hc₂) hneq) }
210+
(λ ht, h t₂ ht₂ c₁ (ht hc₁) c₂ hc₂ hneq)
211+
(λ ht, h t₁ ht₁ c₁ hc₁ c₂ (ht hc₂) hneq) }
199212
end
200213

201-
/-- `max_chain` is the union of all sets in the chain closure. -/
214+
/-- An explicit maximal chain. `max_chain` is taken to be the union of all sets in `chain_closure`.
215+
-/
202216
def max_chain := ⋃₀ chain_closure
203217

204218
/-- Hausdorff's maximality principle
@@ -207,36 +221,32 @@ There exists a maximal totally ordered subset of `α`.
207221
Note that we do not require `α` to be partially ordered by `r`. -/
208222
theorem max_chain_spec :
209223
is_max_chain max_chain :=
210-
classical.by_contradiction $
211-
assume : ¬ is_max_chain (⋃₀ chain_closure),
212-
have super_chain (⋃₀ chain_closure) (succ_chain (⋃₀ chain_closure)),
213-
from super_of_not_max (chain_chain_closure chain_closure_closure) this,
214-
let ⟨h₁, H⟩ := this,
215-
⟨h₂, (h₃ : (⋃₀ chain_closure) ≠ succ_chain (⋃₀ chain_closure))⟩ := ssubset_iff_subset_ne.1 H in
216-
have succ_chain (⋃₀ chain_closure) = (⋃₀ chain_closure),
217-
from (chain_closure_succ_fixpoint_iff chain_closure_closure).mpr rfl,
218-
h₃ this.symm
224+
classical.by_contradiction $ λ h,
225+
begin
226+
obtain ⟨h₁, H⟩ := super_of_not_max (chain_chain_closure chain_closure_closure) h,
227+
obtain ⟨h₂, h₃⟩ := ssubset_iff_subset_ne.1 H,
228+
exact h₃ ((chain_closure_succ_fixpoint_iff chain_closure_closure).mpr rfl).symm,
229+
end
219230

220231
/-- Zorn's lemma
221232
222-
If every chain has an upper bound, then there is a maximal element -/
233+
If every chain has an upper bound, then there exists a maximal element. -/
223234
theorem exists_maximal_of_chains_bounded (h : ∀ c, chain c → ∃ ub, ∀ a ∈ c, a ≺ ub)
224235
(trans : ∀ {a b c}, a ≺ b → b ≺ c → a ≺ c) :
225236
∃ m, ∀ a, m ≺ a → a ≺ m :=
226237
have ∃ ub, ∀ a ∈ max_chain, a ≺ ub,
227238
from h _ $ max_chain_spec.left,
228239
let ⟨ub, (hub : ∀ a ∈ max_chain, a ≺ ub)⟩ := this in
229-
⟨ub, assume a ha,
240+
⟨ub, λ a ha,
230241
have chain (insert a max_chain),
231-
from chain_insert max_chain_spec.left $ assume b hb _, or.inr $ trans (hub b hb) ha,
242+
from chain_insert max_chain_spec.left $ λ b hb _, or.inr $ trans (hub b hb) ha,
232243
have a ∈ max_chain, from
233-
classical.by_contradiction $ assume h : a ∉ max_chain,
244+
classical.by_contradiction $ λ h : a ∉ max_chain,
234245
max_chain_spec.right $ ⟨insert a max_chain, this, ssubset_insert h⟩,
235246
hub a this
236247

237-
/--
238-
If every nonempty chain of a nonempty type has an upper bound, then there is a maximal element.
239-
(A variant of Zorn's lemma.)
248+
/-- A variant of Zorn's lemma. If every nonempty chain of a nonempty type has an upper bound, then
249+
there is a maximal element.
240250
-/
241251
theorem exists_maximal_of_nonempty_chains_bounded [nonempty α]
242252
(h : ∀ c, chain c → c.nonempty → ∃ ub, ∀ a ∈ c, a ≺ ub)
@@ -253,15 +263,15 @@ end chain
253263

254264
--This lemma isn't under section `chain` because `parameters` messes up with it. Feel free to fix it
255265
/-- This can be used to turn `zorn.chain (≥)` into `zorn.chain (≤)` and vice-versa. -/
256-
theorem chain.symm {α : Type u} {s : set α} {q : α → α → Prop} (h : chain q s) :
266+
lemma chain.symm {α : Type u} {s : set α} {q : α → α → Prop} (h : chain q s) :
257267
chain (flip q) s :=
258268
h.mono' (λ _ _, or.symm)
259269

260270
theorem zorn_partial_order {α : Type u} [partial_order α]
261271
(h : ∀ c : set α, chain (≤) c → ∃ ub, ∀ a ∈ c, a ≤ ub) :
262272
∃ m : α, ∀ a, m ≤ a → a = m :=
263-
let ⟨m, hm⟩ := @exists_maximal_of_chains_bounded α (≤) h (assume a b c, le_trans) in
264-
⟨m, assume a ha, le_antisymm (hm a ha) ha⟩
273+
let ⟨m, hm⟩ := @exists_maximal_of_chains_bounded α (≤) h (λ a b c, le_trans) in
274+
⟨m, λ a ha, le_antisymm (hm a ha) ha⟩
265275

266276
theorem zorn_nonempty_partial_order {α : Type u} [partial_order α] [nonempty α]
267277
(h : ∀ (c : set α), chain (≤) c → c.nonempty → ∃ ub, ∀ a ∈ c, a ≤ ub) :
@@ -285,8 +295,8 @@ theorem zorn_nonempty_partial_order₀ {α : Type u} [partial_order α] (s : set
285295
∃ m ∈ s, x ≤ m ∧ ∀ z ∈ s, m ≤ z → z = m :=
286296
let ⟨⟨m, hms, hxm⟩, h⟩ := @zorn_partial_order {m // m ∈ s ∧ x ≤ m} _
287297
(λ c hc, c.eq_empty_or_nonempty.elim
288-
(assume hce, hce.symm ▸ ⟨⟨x, hxs, le_refl _⟩, λ _, false.elim⟩)
289-
(assume ⟨m, hmc⟩,
298+
(λ hce, hce.symm ▸ ⟨⟨x, hxs, le_refl _⟩, λ _, false.elim⟩)
299+
(λ ⟨m, hmc⟩,
290300
let ⟨ub, hubs, hub⟩ := ih (subtype.val '' c) (image_subset_iff.2 $ λ z hzc, z.2.1)
291301
(by rintro _ ⟨p, hpc, rfl⟩ _ ⟨q, hqc, rfl⟩ hpq;
292302
exact hc p hpc q hqc (mt (by rintro rfl; refl) hpq)) m.1 (mem_image_of_mem _ hmc) in
@@ -315,11 +325,11 @@ theorem zorn_superset_nonempty {α : Type u} (S : set (set α))
315325
@zorn_nonempty_partial_order₀ (order_dual (set α)) _ S (λ c cS hc y yc, H _ cS
316326
hc.symm ⟨y, yc⟩) _ hx
317327

318-
theorem chain.total {α : Type u} [preorder α] {c : set α} (H : chain (≤) c) :
328+
lemma chain.total {α : Type u} [preorder α] {c : set α} (H : chain (≤) c) :
319329
∀ {x y}, x ∈ c → y ∈ c → x ≤ y ∨ y ≤ x :=
320330
λ x y, H.total_of_refl
321331

322-
theorem chain.image {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) (f : α → β)
332+
lemma chain.image {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) (f : α → β)
323333
(h : ∀ x y, r x y → s (f x) (f y)) {c : set α} (hrc : chain r c) :
324334
chain s (f '' c) :=
325335
λ x ⟨a, ha₁, ha₂⟩ y ⟨b, hb₁, hb₂⟩, ha₂ ▸ hb₂ ▸ λ hxy,
@@ -328,12 +338,12 @@ theorem chain.image {α β : Type*} (r : α → α → Prop) (s : β → β →
328338

329339
end zorn
330340

331-
theorem directed_of_chain {α β r} [is_refl β r] {f : α → β} {c : set α}
341+
lemma directed_of_chain {α β r} [is_refl β r] {f : α → β} {c : set α}
332342
(h : zorn.chain (f ⁻¹'o r) c) :
333343
directed r (λ x : {a : α // a ∈ c}, f x) :=
334-
assume ⟨a, ha⟩ ⟨b, hb⟩, classical.by_cases
335-
(assume : a = b, by simp only [this, exists_prop, and_self, subtype.exists];
344+
λ ⟨a, ha⟩ ⟨b, hb⟩, classical.by_cases
345+
(λ hab : a = b, by simp only [hab, exists_prop, and_self, subtype.exists];
336346
exact ⟨b, hb, refl _⟩)
337-
(assume : a ≠ b, (h a ha b hb this).elim
347+
(λ hab, (h a ha b hb hab).elim
338348
(λ h : r (f a) (f b), ⟨⟨b, hb⟩, h, refl _⟩)
339349
(λ h : r (f b) (f a), ⟨⟨a, ha⟩, refl _, h⟩))

0 commit comments

Comments
 (0)