forked from leanprover-community/mathlib4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLattice.lean
More file actions
484 lines (382 loc) · 21.4 KB
/
Copy pathLattice.lean
File metadata and controls
484 lines (382 loc) · 21.4 KB
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kyle Miller
-/
module
public import Mathlib.Data.Set.Finite.Powerset
public import Mathlib.Data.Set.Finite.Range
public import Mathlib.Data.Set.Lattice.Image
import Mathlib.Data.Fintype.Option
/-!
# Finiteness of unions and intersections
## Implementation notes
Each result in this file should come in three forms: a `Fintype` instance, a `Finite` instance
and a `Set.Finite` constructor.
## Tags
finite sets
-/
@[expose] public section
assert_not_exists IsOrderedRing MonoidWithZero
open Set Function
universe u v w x
variable {α : Type u} {β : Type v} {ι : Sort w} {γ : Type x}
namespace Set
/-! ### Fintype instances
Every instance here should have a corresponding `Set.Finite` constructor in the next section.
-/
section FintypeInstances
instance fintypeiUnion [DecidableEq α] [Fintype (PLift ι)] (f : ι → Set α) [∀ i, Fintype (f i)] :
Fintype (⋃ i, f i) :=
Fintype.ofFinset (Finset.univ.biUnion fun i : PLift ι => (f i.down).toFinset) <| by simp
instance fintypesUnion [DecidableEq α] {s : Set (Set α)} [Fintype s]
[H : ∀ t : s, Fintype (t : Set α)] : Fintype (⋃₀ s) := by
rw [sUnion_eq_iUnion]
exact @Set.fintypeiUnion _ _ _ _ _ H
lemma toFinset_iUnion [Fintype β] [DecidableEq α] (f : β → Set α)
[∀ w, Fintype (f w)] :
Set.toFinset (⋃ (x : β), f x) =
Finset.biUnion (Finset.univ : Finset β) (fun x => (f x).toFinset) := by
ext v
simp only [mem_toFinset, mem_iUnion, Finset.mem_biUnion, Finset.mem_univ, true_and]
/-- A union of sets with `Fintype` structure over a set with `Fintype` structure has a `Fintype`
structure. -/
@[implicit_reducible]
def fintypeBiUnion [DecidableEq α] {ι : Type*} (s : Set ι) [Fintype s] (t : ι → Set α)
(H : ∀ i ∈ s, Fintype (t i)) : Fintype (⋃ x ∈ s, t x) :=
haveI : ∀ i : toFinset s, Fintype (t i) := fun i => H i (mem_toFinset.1 i.2)
Fintype.ofFinset (s.toFinset.attach.biUnion fun x => (t x).toFinset) fun x => by simp
instance fintypeBiUnion' [DecidableEq α] {ι : Type*} (s : Set ι) [Fintype s] (t : ι → Set α)
[∀ i, Fintype (t i)] : Fintype (⋃ x ∈ s, t x) :=
Fintype.ofFinset (s.toFinset.biUnion fun x => (t x).toFinset) <| by simp
end FintypeInstances
end Set
/-! ### Finite instances
There is seemingly some overlap between the following instances and the `Fintype` instances
in `Data.Set.Finite`. While every `Fintype` instance gives a `Finite` instance, those
instances that depend on `Fintype` or `Decidable` instances need an additional `Finite` instance
to be able to generally apply.
Some set instances do not appear here since they are consequences of others, for example
`Subtype.Finite` for subsets of a finite type.
-/
namespace Finite.Set
instance finite_iUnion [Finite ι] (f : ι → Set α) [∀ i, Finite (f i)] : Finite (⋃ i, f i) := by
have : Fintype (PLift ι) := Fintype.ofFinite _
have : ∀ i, Fintype (f i) := fun i => Fintype.ofFinite _
classical apply (fintypeiUnion _).finite
instance finite_sUnion {s : Set (Set α)} [Finite s] [H : ∀ t : s, Finite (t : Set α)] :
Finite (⋃₀ s) := by
rw [sUnion_eq_iUnion]
exact @Finite.Set.finite_iUnion _ _ _ _ H
theorem finite_biUnion {ι : Type*} (s : Set ι) [Finite s] (t : ι → Set α)
(H : ∀ i ∈ s, Finite (t i)) : Finite (⋃ x ∈ s, t x) := by
rw [biUnion_eq_iUnion]
haveI : ∀ i : s, Finite (t i) := fun i => H i i.property
infer_instance
instance finite_biUnion' {ι : Type*} (s : Set ι) [Finite s] (t : ι → Set α) [∀ i, Finite (t i)] :
Finite (⋃ x ∈ s, t x) :=
finite_biUnion s t fun _ _ => inferInstance
/-- Example: `Finite (⋃ (i < n), f i)` where `f : ℕ → Set α` and `[∀ i, Finite (f i)]`
(when given instances from `Order.Interval.Finset.Nat`).
-/
instance finite_biUnion'' {ι : Type*} (p : ι → Prop) [h : Finite { x | p x }] (t : ι → Set α)
[∀ i, Finite (t i)] : Finite (⋃ (x) (_ : p x), t x) :=
@Finite.Set.finite_biUnion' _ _ (setOf p) h t _
instance finite_iInter {ι : Sort*} [Nonempty ι] (t : ι → Set α) [∀ i, Finite (t i)] :
Finite (⋂ i, t i) :=
Finite.Set.subset (t <| Classical.arbitrary ι) (iInter_subset _ _)
end Finite.Set
namespace Set
/-! ### Constructors for `Set.Finite`
Every constructor here should have a corresponding `Fintype` instance in the previous section
(or in the `Fintype` module).
The implementation of these constructors ideally should be no more than `Set.toFinite`,
after possibly setting up some `Fintype` and classical `Decidable` instances.
-/
section SetFiniteConstructors
theorem finite_iUnion [Finite ι] {f : ι → Set α} (H : ∀ i, (f i).Finite) : (⋃ i, f i).Finite :=
haveI := fun i => (H i).to_subtype
toFinite _
/-- Dependent version of `Finite.biUnion`. -/
theorem Finite.biUnion' {ι} {s : Set ι} (hs : s.Finite) {t : ∀ i ∈ s, Set α}
(ht : ∀ i (hi : i ∈ s), (t i hi).Finite) : (⋃ i ∈ s, t i ‹_›).Finite := by
have := hs.to_subtype
rw [biUnion_eq_iUnion]
apply finite_iUnion fun i : s => ht i.1 i.2
theorem Finite.biUnion {ι} {s : Set ι} (hs : s.Finite) {t : ι → Set α}
(ht : ∀ i ∈ s, (t i).Finite) : (⋃ i ∈ s, t i).Finite :=
hs.biUnion' ht
theorem Finite.sUnion {s : Set (Set α)} (hs : s.Finite) (H : ∀ t ∈ s, Set.Finite t) :
(⋃₀ s).Finite := by
simpa only [sUnion_eq_biUnion] using hs.biUnion H
theorem Finite.sInter {α : Type*} {s : Set (Set α)} {t : Set α} (ht : t ∈ s) (hf : t.Finite) :
(⋂₀ s).Finite :=
hf.subset (sInter_subset_of_mem ht)
/-- If sets `s i` are finite for all `i` from a finite set `t` and are empty for `i ∉ t`, then the
union `⋃ i, s i` is a finite set. -/
theorem Finite.iUnion {ι : Type*} {s : ι → Set α} {t : Set ι} (ht : t.Finite)
(hs : ∀ i ∈ t, (s i).Finite) (he : ∀ i, i ∉ t → s i = ∅) : (⋃ i, s i).Finite := by
suffices ⋃ i, s i ⊆ ⋃ i ∈ t, s i by exact (ht.biUnion hs).subset this
refine iUnion_subset fun i x hx => ?_
by_cases hi : i ∈ t
· exact mem_biUnion hi hx
· rw [he i hi, mem_empty_iff_false] at hx
contradiction
/-- An indexed union of pairwise disjoint sets is finite iff all sets are finite, and all but
finitely many are empty. -/
lemma finite_iUnion_iff {ι : Type*} {s : ι → Set α} (hs : Pairwise fun i j ↦ Disjoint (s i) (s j)) :
(⋃ i, s i).Finite ↔ (∀ i, (s i).Finite) ∧ {i | (s i).Nonempty}.Finite where
mp h := by
refine ⟨fun i ↦ h.subset <| subset_iUnion _ _, ?_⟩
let u (i : {i | (s i).Nonempty}) : ⋃ i, s i := ⟨i.2.choose, mem_iUnion.2 ⟨i.1, i.2.choose_spec⟩⟩
have u_inj : Function.Injective u := by
rintro ⟨i, hi⟩ ⟨j, hj⟩ hij
ext
refine hs.eq <| not_disjoint_iff.2 ⟨u ⟨i, hi⟩, hi.choose_spec, ?_⟩
rw [hij]
exact hj.choose_spec
have : Finite (⋃ i, s i) := h
exact .of_injective u u_inj
mpr h := h.2.iUnion (fun _ _ ↦ h.1 _) (by simp [not_nonempty_iff_eq_empty])
protected lemma Infinite.iUnion {ι : Sort*} {s : ι → Set α} (i : ι) (hi : (s i).Infinite) :
(⋃ i, s i).Infinite :=
fun h ↦ hi (h.subset (Set.subset_iUnion s i))
lemma Infinite.iUnion₂ {ι : Sort*} {κ : ι → Sort*} {s : ∀ i, κ i → Set α} (i : ι) (j : κ i)
(hij : (s i j).Infinite) : (⋃ (i) (j), s i j).Infinite :=
fun hc ↦ hij (hc.subset <| subset_iUnion₂ _ _)
@[simp] lemma finite_iUnion_of_subsingleton {ι : Sort*} [Subsingleton ι] {s : ι → Set α} :
(⋃ i, s i).Finite ↔ ∀ i, (s i).Finite := by
rw [← iUnion_plift_down, finite_iUnion_iff _root_.Subsingleton.pairwise]
simp [PLift.forall, Finite.of_subsingleton]
/-- An indexed union of pairwise disjoint sets is finite iff all sets are finite, and all but
finitely many are empty. -/
lemma PairwiseDisjoint.finite_biUnion_iff {f : β → Set α} {s : Set β} (hs : s.PairwiseDisjoint f) :
(⋃ i ∈ s, f i).Finite ↔ (∀ i ∈ s, (f i).Finite) ∧ {i ∈ s | (f i).Nonempty}.Finite := by
rw [finite_iUnion_iff (by aesop (add unfold safe [Pairwise, PairwiseDisjoint, Set.Pairwise]))]
simp
section preimage
variable {f : α → β} {s : Set β}
theorem Finite.preimage' (h : s.Finite) (hf : ∀ b ∈ s, (f ⁻¹' {b}).Finite) :
(f ⁻¹' s).Finite := by
rw [← Set.biUnion_preimage_singleton]
exact Set.Finite.biUnion h hf
end preimage
/-- A finite union of finsets is finite. -/
theorem union_finset_finite_of_range_finite (f : α → Finset β) (h : (range f).Finite) :
(⋃ a, (f a : Set β)).Finite := by
rw [← biUnion_range]
exact h.biUnion fun y _ => y.finite_toSet
end SetFiniteConstructors
/--
If the image of `s` under `f` is finite, and each fiber of `f` has a finite intersection
with `s`, then `s` is itself finite.
It is useful to give `f` explicitly here so this can be used with `apply`.
-/
lemma Finite.of_finite_fibers (f : α → β) {s : Set α} (himage : (f '' s).Finite)
(hfibers : ∀ x ∈ f '' s, (s ∩ f ⁻¹' {x}).Finite) : s.Finite :=
(himage.biUnion hfibers).subset fun x ↦ by aesop
/-! ### Properties -/
theorem finite_subset_iUnion {s : Set α} (hs : s.Finite) {ι} {t : ι → Set α} (h : s ⊆ ⋃ i, t i) :
∃ I : Set ι, I.Finite ∧ s ⊆ ⋃ i ∈ I, t i := by
have := hs.to_subtype
choose f hf using show ∀ x : s, ∃ i, x.1 ∈ t i by simpa [subset_def] using h
refine ⟨range f, finite_range f, fun x hx => ?_⟩
rw [biUnion_range, mem_iUnion]
exact ⟨⟨x, hx⟩, hf _⟩
theorem eq_finite_iUnion_of_finite_subset_iUnion {ι} {s : ι → Set α} {t : Set α} (tfin : t.Finite)
(h : t ⊆ ⋃ i, s i) :
∃ I : Set ι,
I.Finite ∧
∃ σ : { i | i ∈ I } → Set α, (∀ i, (σ i).Finite) ∧ (∀ i, σ i ⊆ s i) ∧ t = ⋃ i, σ i :=
let ⟨I, Ifin, hI⟩ := finite_subset_iUnion tfin h
⟨I, Ifin, fun x => s x ∩ t, fun _ => tfin.subset inter_subset_right, fun _ =>
inter_subset_left, by
ext x
rw [mem_iUnion]
constructor
· intro x_in
rcases mem_iUnion.mp (hI x_in) with ⟨i, _, ⟨hi, rfl⟩, H⟩
exact ⟨⟨i, hi⟩, ⟨H, x_in⟩⟩
· rintro ⟨i, -, H⟩
exact H⟩
/-! ### Infinite sets -/
variable {s t : Set α}
theorem infinite_iUnion {ι : Type*} [Infinite ι] {s : ι → Set α} (hs : Function.Injective s) :
(⋃ i, s i).Infinite :=
fun hfin ↦ @not_injective_infinite_finite ι _ _ hfin.finite_subsets.to_subtype
(fun i ↦ ⟨s i, subset_iUnion _ _⟩) fun _ _ h_eq ↦ hs (Subtype.ext_iff.1 h_eq)
theorem Infinite.biUnion {ι : Type*} {s : ι → Set α} {a : Set ι} (ha : a.Infinite)
(hs : a.InjOn s) : (⋃ i ∈ a, s i).Infinite := by
rw [biUnion_eq_iUnion]
have _ := ha.to_subtype
exact infinite_iUnion fun ⟨i,hi⟩ ⟨j,hj⟩ hij ↦ by simp [hs hi hj hij]
theorem Infinite.sUnion {s : Set (Set α)} (hs : s.Infinite) : (⋃₀ s).Infinite := by
rw [sUnion_eq_iUnion]
have _ := hs.to_subtype
exact infinite_iUnion Subtype.coe_injective
/-! ### Order properties -/
@[to_dual]
lemma map_finite_biSup {F ι : Type*} [CompleteLattice α] [CompleteLattice β] [FunLike F α β]
[SupBotHomClass F α β] {s : Set ι} (hs : s.Finite) (f : F) (g : ι → α) :
f (⨆ x ∈ s, g x) = ⨆ x ∈ s, f (g x) := by
have := map_finset_sup f hs.toFinset g
simp only [Finset.sup_eq_iSup, hs.mem_toFinset, comp_apply] at this
exact this
@[to_dual]
lemma map_finite_iSup {F ι : Type*} [CompleteLattice α] [CompleteLattice β] [FunLike F α β]
[SupBotHomClass F α β] [Finite ι] (f : F) (g : ι → α) :
f (⨆ i, g i) = ⨆ i, f (g i) := by
rw [← iSup_univ (f := g), ← iSup_univ (f := fun i ↦ f (g i))]
exact map_finite_biSup finite_univ f g
@[to_dual]
theorem Finite.iSup_biInf_of_monotone {ι ι' α : Type*} [Preorder ι'] [Nonempty ι']
[IsDirectedOrder ι'] [Order.Frame α] {s : Set ι} (hs : s.Finite) {f : ι → ι' → α}
(hf : ∀ i ∈ s, Monotone (f i)) : ⨆ j, ⨅ i ∈ s, f i j = ⨅ i ∈ s, ⨆ j, f i j := by
induction s, hs using Set.Finite.induction_on with
| empty => simp [iSup_const]
| insert _ _ ihs =>
rw [forall_mem_insert] at hf
simp only [iInf_insert, ← ihs hf.2]
exact iSup_inf_of_monotone hf.1 fun j₁ j₂ hj => iInf₂_mono fun i hi => hf.2 i hi hj
@[to_dual]
theorem Finite.iSup_biInf_of_antitone {ι ι' α : Type*} [Preorder ι'] [Nonempty ι']
[IsCodirectedOrder ι'] [Order.Frame α] {s : Set ι} (hs : s.Finite) {f : ι → ι' → α}
(hf : ∀ i ∈ s, Antitone (f i)) : ⨆ j, ⨅ i ∈ s, f i j = ⨅ i ∈ s, ⨆ j, f i j :=
@Finite.iSup_biInf_of_monotone ι ι'ᵒᵈ α _ _ _ _ _ hs _ fun i hi => (hf i hi).dual_left
@[to_dual]
theorem _root_.iSup_iInf_of_monotone {ι ι' α : Type*} [Finite ι] [Preorder ι'] [Nonempty ι']
[IsDirectedOrder ι'] [Order.Frame α] {f : ι → ι' → α} (hf : ∀ i, Monotone (f i)) :
⨆ j, ⨅ i, f i j = ⨅ i, ⨆ j, f i j := by
simpa only [iInf_univ] using finite_univ.iSup_biInf_of_monotone fun i _ => hf i
@[to_dual]
theorem _root_.iSup_iInf_of_antitone {ι ι' α : Type*} [Finite ι] [Preorder ι'] [Nonempty ι']
[IsCodirectedOrder ι'] [Order.Frame α] {f : ι → ι' → α} (hf : ∀ i, Antitone (f i)) :
⨆ j, ⨅ i, f i j = ⨅ i, ⨆ j, f i j :=
@iSup_iInf_of_monotone ι ι'ᵒᵈ α _ _ _ _ _ _ fun i => (hf i).dual_left
@[deprecated (since := "2026-02-03")] protected alias iSup_iInf_of_monotone := iSup_iInf_of_monotone
@[deprecated (since := "2026-02-03")] protected alias iSup_iInf_of_antitone := iSup_iInf_of_antitone
@[deprecated (since := "2026-02-03")] protected alias iInf_iSup_of_monotone := iInf_iSup_of_monotone
@[deprecated (since := "2026-02-03")] protected alias iInf_iSup_of_antitone := iInf_iSup_of_antitone
/-- An increasing union distributes over finite intersection. -/
theorem iUnion_iInter_of_monotone {ι ι' α : Type*} [Finite ι] [Preorder ι'] [IsDirectedOrder ι']
[Nonempty ι'] {s : ι → ι' → Set α} (hs : ∀ i, Monotone (s i)) :
⋃ j : ι', ⋂ i : ι, s i j = ⋂ i : ι, ⋃ j : ι', s i j :=
iSup_iInf_of_monotone hs
/-- A decreasing union distributes over finite intersection. -/
theorem iUnion_iInter_of_antitone {ι ι' α : Type*} [Finite ι] [Preorder ι']
[IsCodirectedOrder ι'] [Nonempty ι'] {s : ι → ι' → Set α} (hs : ∀ i, Antitone (s i)) :
⋃ j : ι', ⋂ i : ι, s i j = ⋂ i : ι, ⋃ j : ι', s i j :=
iSup_iInf_of_antitone hs
/-- An increasing intersection distributes over finite union. -/
theorem iInter_iUnion_of_monotone {ι ι' α : Type*} [Finite ι] [Preorder ι']
[IsCodirectedOrder ι'] [Nonempty ι'] {s : ι → ι' → Set α} (hs : ∀ i, Monotone (s i)) :
⋂ j : ι', ⋃ i : ι, s i j = ⋃ i : ι, ⋂ j : ι', s i j :=
iInf_iSup_of_monotone hs
/-- A decreasing intersection distributes over finite union. -/
theorem iInter_iUnion_of_antitone {ι ι' α : Type*} [Finite ι] [Preorder ι'] [IsDirectedOrder ι']
[Nonempty ι'] {s : ι → ι' → Set α} (hs : ∀ i, Antitone (s i)) :
⋂ j : ι', ⋃ i : ι, s i j = ⋃ i : ι, ⋂ j : ι', s i j :=
iInf_iSup_of_antitone hs
theorem iUnion_pi_of_monotone {ι ι' : Type*} [LinearOrder ι'] [Nonempty ι'] {α : ι → Type*}
{I : Set ι} {s : ∀ i, ι' → Set (α i)} (hI : I.Finite) (hs : ∀ i ∈ I, Monotone (s i)) :
⋃ j : ι', I.pi (fun i => s i j) = I.pi fun i => ⋃ j, s i j := by
simp only [pi_def, biInter_eq_iInter, preimage_iUnion]
haveI := hI.fintype.finite
refine iUnion_iInter_of_monotone (ι' := ι') (fun (i : I) j₁ j₂ h => ?_)
exact preimage_mono <| hs i i.2 h
theorem iUnion_univ_pi_of_monotone {ι ι' : Type*} [LinearOrder ι'] [Nonempty ι'] [Finite ι]
{α : ι → Type*} {s : ∀ i, ι' → Set (α i)} (hs : ∀ i, Monotone (s i)) :
⋃ j : ι', pi univ (fun i => s i j) = pi univ fun i => ⋃ j, s i j :=
iUnion_pi_of_monotone finite_univ fun i _ => hs i
theorem _root_.iInf_iSup_eq_of_finite {ι : Sort v} {κ : ι → Sort w} [Order.Frame α] [Finite ι]
{f : Π a, κ a → α} : ⨅ a, ⨆ b, f a b = ⨆ g : (Π a, κ a), ⨅ a, f a (g a) := by
suffices ∀ {ι : Type v} {κ : ι → Type w} [Finite ι] (f : Π a, κ a → α),
⨅ a, ⨆ b, f a b = ⨆ g : (Π a, κ a), ⨅ a, f a (g a) by
simpa [← Equiv.plift.symm.iInf_comp, ← Equiv.plift.symm.iSup_comp,
← (Equiv.plift.piCongr fun a => @Equiv.plift (κ a.down)).symm.iSup_comp] using!
this (κ := fun a => PLift (κ a.down)) fun (a : PLift ι) b => f a.down b.down
intro ι κ _ f
induction ι using Finite.induction_empty_option with
| of_equiv e h => simp [← e.iInf_comp, ← e.piCongrLeft κ |>.iSup_comp, h]
| h_empty => simp [iInf_of_empty, iSup_const]
| h_option h =>
simp only [iInf_option, h, ← (Equiv.piOptionEquivProd (β := κ)).symm.iSup_comp,
Equiv.piOptionEquivProd_symm_apply, iSup_prod, ← inf_iSup_eq, ← iSup_inf_eq]
theorem _root_.iSup_iInf_eq_of_finite {ι : Sort v} {κ : ι → Sort w} [Order.Coframe α] [Finite ι]
{f : ∀ a, κ a → α} : ⨆ a, ⨅ b, f a b = ⨅ g : ∀ a, κ a, ⨆ a, f a (g a) :=
iInf_iSup_eq_of_finite (α := αᵒᵈ)
theorem Finite.biInf_iSup_eq {ι : Type v} {κ : ι → Sort w} [Nonempty (Π a, κ a)] [Order.Frame α]
{s : Set ι} (hs : s.Finite) {f : Π a, κ a → α} :
⨅ a ∈ s, ⨆ b, f a b = ⨆ g : (Π a, κ a), ⨅ a ∈ s, f a (g a) := by
classical
suffices h : ∀ {κ : ι → Type w} [Nonempty (Π a, κ a)] (f : Π a, κ a → α),
⨅ a ∈ s, ⨆ b, f a b = ⨆ g : (Π a, κ a), ⨅ a ∈ s, f a (g a) by
haveI : Nonempty (Π a, PLift (κ a)) := (Equiv.piCongrRight fun _ => Equiv.plift).nonempty
simpa [← Equiv.plift.symm.iSup_comp, ← (Equiv.piCongrRight fun _ => Equiv.plift).symm.iSup_comp]
using h (κ := fun a => PLift (κ a)) fun a b => f a b.down
intro κ _ f
haveI := hs.to_subtype
haveI : Nonempty (Π a : { a // a ∉ s }, κ ↑a) := ‹Nonempty (Π a, κ a)›.map fun f a ↦ f a
simp [← iInf_subtype'', iInf_iSup_eq_of_finite (ι := s),
← Equiv.piEquivPiSubtypeProd (· ∈ s) _ |>.symm.iSup_comp, iSup_prod, iSup_const]
theorem Finite.biSup_iInf_eq {ι : Type v} {κ : ι → Sort w} [Nonempty (∀ a, κ a)] [Order.Coframe α]
{s : Set ι} (hs : s.Finite) {f : ∀ a, κ a → α} :
⨆ a ∈ s, ⨅ b, f a b = ⨅ g : ∀ a, κ a, ⨆ a ∈ s, f a (g a) :=
hs.biInf_iSup_eq (α := αᵒᵈ)
section
variable [Preorder α] [IsDirectedOrder α] [Nonempty α] {s : Set α}
/-- A finite set is bounded above. -/
@[to_dual /-- A finite set is bounded below. -/]
protected theorem Finite.bddAbove (hs : s.Finite) : BddAbove s :=
Finite.induction_on _ hs bddAbove_empty fun _ _ h => h.insert _
/-- A finite union of sets which are all bounded above is still bounded above. -/
@[to_dual /-- A finite union of sets which are all bounded below is still bounded below. -/]
theorem Finite.bddAbove_biUnion {I : Set β} {S : β → Set α} (H : I.Finite) :
BddAbove (⋃ i ∈ I, S i) ↔ ∀ i ∈ I, BddAbove (S i) := by
induction I, H using Set.Finite.induction_on with
| empty => simp only [biUnion_empty, bddAbove_empty, forall_mem_empty]
| insert _ _ hs => simp only [biUnion_insert, forall_mem_insert, bddAbove_union, hs]
@[to_dual]
theorem infinite_of_not_bddAbove : ¬BddAbove s → s.Infinite :=
mt Finite.bddAbove
end
end Set
/-- A finset is bounded above. -/
@[to_dual /-- A finset is bounded below. -/]
protected theorem Finset.bddAbove [SemilatticeSup α] [Nonempty α] (s : Finset α) :
BddAbove (↑s : Set α) :=
s.finite_toSet.bddAbove
section LinearOrder
variable [LinearOrder α] {s : Set α}
lemma Set.finite_sdiff_iUnion_Ioo (s : Set α) : (s \ ⋃ (x ∈ s) (y ∈ s), Ioo x y).Finite :=
Set.finite_of_forall_not_lt_lt fun _x hx _y hy _z hz hxy hyz => hy.2 <| mem_iUnion₂_of_mem hx.1 <|
mem_iUnion₂_of_mem hz.1 ⟨hxy, hyz⟩
@[deprecated (since := "2026-06-03")]
alias Set.finite_diff_iUnion_Ioo := Set.finite_sdiff_iUnion_Ioo
lemma Set.finite_sdiff_iUnion_Ioo' (s : Set α) : (s \ ⋃ x : s × s, Ioo x.1 x.2).Finite := by
simpa only [iUnion, iSup_prod, iSup_subtype] using s.finite_sdiff_iUnion_Ioo
@[deprecated (since := "2026-06-03")]
alias Set.finite_diff_iUnion_Ioo' := Set.finite_sdiff_iUnion_Ioo'
lemma Directed.exists_mem_subset_of_finset_subset_biUnion {α ι : Type*} [Nonempty ι]
{f : ι → Set α} (h : Directed (· ⊆ ·) f) {s : Finset α} (hs : (s : Set α) ⊆ ⋃ i, f i) :
∃ i, (s : Set α) ⊆ f i := by
induction s using Finset.cons_induction with
| empty => simp
| cons b t hbt iht =>
simp only [Finset.coe_cons, Set.insert_subset_iff, Set.mem_iUnion] at hs ⊢
rcases hs.imp_right iht with ⟨⟨i, hi⟩, j, hj⟩
rcases h i j with ⟨k, hik, hjk⟩
exact ⟨k, hik hi, hj.trans hjk⟩
theorem DirectedOn.exists_mem_subset_of_finset_subset_biUnion {α ι : Type*} {f : ι → Set α}
{c : Set ι} (hn : c.Nonempty) (hc : DirectedOn (fun i j => f i ⊆ f j) c) {s : Finset α}
(hs : (s : Set α) ⊆ ⋃ i ∈ c, f i) : ∃ i ∈ c, (s : Set α) ⊆ f i := by
rw [Set.biUnion_eq_iUnion] at hs
haveI := hn.coe_sort
simpa using (directed_comp.2 hc.directed_val).exists_mem_subset_of_finset_subset_biUnion hs
theorem DirectedOn.exists_mem_subset_of_finite_of_subset_sUnion {α : Type*} {c : Set (Set α)}
(hn : c.Nonempty) (hc : DirectedOn (· ⊆ ·) c) {s : Set α} (hs : s.Finite)
(hsc : s ⊆ sUnion c) : ∃ t ∈ c, s ⊆ t := by
rw [← hs.coe_toFinset, sUnion_eq_biUnion] at hsc
have := DirectedOn.exists_mem_subset_of_finset_subset_biUnion hn hc hsc
exact hs.coe_toFinset ▸ this
end LinearOrder