-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathG0.lean
More file actions
1524 lines (1454 loc) · 53.3 KB
/
G0.lean
File metadata and controls
1524 lines (1454 loc) · 53.3 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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import Mathlib
open MeasureTheory (AnalyticSet)
theorem Nat.log2_add_one_le_self {n} : log2 (n + 1) ≤ n :=
by simp [Nat.le_iff_lt_add_one, Nat.log2_lt, Nat.lt_two_pow_self]
theorem string_eq_iff {s t : Σ n, Fin n → Bool} : s = t ↔ ∃ h, ∀ i, s.snd i = t.snd (i.cast h) := by
constructor
. intro (.refl _)
simp
. intro h
ext
exact h.fst
apply heq_of_eq_cast (h.fst ▸ rfl)
funext i
rewrite [h.snd]
cases s
cases h.fst
simp
instance : Denumerable (Σ n, Fin n → Bool) where
encode | ⟨n, s⟩ => 2 ^ n - 1 + .ofBits s
decode m := let n := (m + 1).log2; some ⟨n, fun i => (m - (2 ^ n - 1)).testBit i⟩
encodek := by
intro ⟨n, s⟩
simp only [Option.some.injEq, string_eq_iff]
suffices _ by
use this
intro ⟨i, h⟩
simp [this] at h
simp [this, Nat.testBit_ofBits, h]
simp [Nat.log2_eq_log_two, Nat.log_eq_iff]
constructor
. omega
apply Nat.lt_of_le_of_lt
. apply Nat.add_le_add_right
apply Nat.add_le_add_left
apply Nat.le_pred_of_lt
apply Nat.ofBits_lt_two_pow
simp [Nat.pow_succ']
rewrite [Nat.add_assoc, Nat.sub_add_cancel Nat.one_le_two_pow, ← Nat.sub_add_comm Nat.one_le_two_pow]
simp +arith
decode_inv m := by
simp
symm
rewrite [← Nat.sub_eq_iff_eq_add']
. apply Nat.eq_of_testBit_eq
intro i
simp [Nat.testBit_ofBits]
intro h
apply Nat.lt_of_succ_le
simp [Nat.le_log2, Nat.pow_succ']
apply Nat.le_trans (Nat.mul_le_mul_left 2 (Nat.ge_two_pow_of_testBit h))
clear i h
simp [Nat.mul_sub]
simp [← Nat.pow_succ']
trans
swap
. apply Nat.add_le_add_left
apply Nat.sub_le_sub_right
exact Nat.le_of_lt Nat.lt_log2_self
. omega
. simp [Nat.log2_self_le]
def s n : Fin n → Bool :=
let ⟨m, x⟩ := Denumerable.ofNat (Σ n, Fin n → Bool) n
fun i => if h : i < m then x ⟨i, h⟩ else false
theorem s_dense {m} (t : Fin m → Bool) : ∃ n, ∃ (h : m ≤ n), ∀ i : Fin m, t i = s n (i.castLE h) := by
use Denumerable.toEncodable.encode (⟨m, t⟩ : Σ n, Fin n → Bool)
simp [Encodable.encode]
have : (2 ^ m - 1 + Nat.ofBits t + 1).log2 = m := by
apply Nat.le_antisymm
. apply Nat.le_of_lt_succ
rewrite [Nat.log2_lt (by simp)]
apply Nat.lt_of_le_of_lt
. apply Nat.add_le_add_right
apply Nat.add_le_add_left
apply Nat.le_pred_of_lt
apply Nat.ofBits_lt_two_pow
simp [Nat.pow_succ']
rewrite [Nat.add_assoc, Nat.sub_add_cancel Nat.one_le_two_pow, ← Nat.sub_add_comm Nat.one_le_two_pow]
simp +arith
. simp [Nat.le_log2]
omega
use Nat.le_trans (Nat.le_of_eq this.symm) Nat.log2_add_one_le_self
intro i
simp [s]
simp only [Denumerable.ofNat, Encodable.decode]
simp [this]
section
variable {α} [TopologicalSpace α] [DiscreteTopology α]
instance {n} : HAppend (Fin n → α) (Nat → α) (Nat → α) where
hAppend s t i := if h : i < n then s ⟨i, h⟩ else t (i - n)
def N {n} (t : Fin n → α) : Set (Nat → α) :=
{x | ∀ i, t i = x i}
instance [Inhabited α] {n} {t : Fin n → α} : Nonempty (N t) :=
⟨fun i => if h : i < n then t ⟨i, h⟩ else default, fun i => by simp⟩
theorem mem_N {α : Type*} {n} {t : Fin n → α} {x} : (x ∈ N t) = ∀ i, t i = x i := rfl
theorem N_agree {α : Type*} {n₁ n₂} {t₁ : Fin n₁ → α} {t₂ : Fin n₂ → α} (hn : n₁ ≤ n₂) (ht : ∀ i, t₁ i = t₂ (i.castLE hn)) : N t₂ ⊆ N t₁
| _, hx, i => (ht i).trans (hx (i.castLE hn))
theorem N_open {n} {t : Fin n → α} : IsOpen (N t) := by
simp [isOpen_pi_iff]
intro x h
use .range n, fun i b => if h : i < n then t ⟨i, h⟩ = b else True
simp [mem_N] at h
simp [Membership.mem, Set.Mem, h]
intro y
simp [mem_N]
intro hy i
rewrite [h i]
apply hy <;> exact i.isLt
theorem N_closed {x : α} : IsClosed (N ![x]) := by
constructor
have : (N ![x])ᶜ = ⋃ y ∈ ({x}ᶜ : Set α), N ![y] := by
ext z
simp [mem_N]
exact ⟨Ne.symm, Ne.symm⟩
rewrite [this]
apply isOpen_iUnion
intro y
apply isOpen_iUnion
intro
apply N_open
theorem contains_basic {U : Set (Nat → α)} (h : IsOpen U) {y} (h' : y ∈ U) : ∃ m, ∃ t : Fin m → α, y ∈ N t ∧ N t ⊆ U := by
simp [isOpen_pi_iff] at h
specialize h y h'
rcases h with ⟨I, u, h₁, h₂⟩
use I.max.elim 0 (· + 1), fun i => y i
simp [mem_N]
intro x h''
apply h₂
intro i hi
refine h'' ⟨i, ?_⟩ ▸ h₁ i hi
rcases I.le_max hi i rfl with ⟨m, h₁, h₂⟩
rw [h₁]
simp!
exact Nat.lt_succ_of_le h₂
theorem contains_s {U : Set (Nat → Bool)} (h : IsOpen U) (h' : U.Nonempty) : ∃ n, N (s n) ⊆ U := by
rcases h' with ⟨_, h'⟩
let ⟨m, t, _, ht⟩ := contains_basic h h'
let ⟨n, hn, hsn⟩ := s_dense t
use n
intro x hx
apply ht
intro i
rw [hsn i]
apply hx
theorem N_basis : TopologicalSpace.IsTopologicalBasis {A | ∃ m, ∃ t : Fin m → α, A = N t} := by
apply TopologicalSpace.isTopologicalBasis_of_isOpen_of_nhds
. intro A ⟨m, t, h⟩
exact h ▸ N_open
. intro x U mem U_open
let ⟨m, t, h⟩ := contains_basic U_open mem
exists _, ⟨m, t, rfl⟩
def treelim {β} (f : ∀ n, (Fin n → α) → (Fin n → β)) (x : Nat → α) (n : Nat) : β :=
f (n + 1) (fun i => x i) (Fin.last n)
theorem treelim_cont {β} [TopologicalSpace β] [DiscreteTopology β] (f : ∀ n, (Fin n → α) → (Fin n → β)) : Continuous (treelim f) := by
constructor
intro A hA
replace hA := N_basis.open_eq_iUnion hA
rcases hA with ⟨β, g, h, h'⟩
cases h
simp at h' ⊢
apply isOpen_iUnion
intro i
specialize h' i
rcases h' with ⟨m, t, h⟩
rewrite [h]
clear g h i β
simp [Set.preimage, mem_N, treelim]
simp [isOpen_pi_iff]
intro g hg
replace hg := funext hg
cases hg
use .range m, fun n => {g n}
simp
intro x
simp
intro hx i
congr
funext j
simp [hx j (by omega)]
end
def 𝔾₀ (x y : Nat → Bool) : Prop :=
∃ n b, ∃ z : Nat → Bool, x = s n ++ (![b] ++ z) ∧ y = s n ++ (![!b] ++ z)
instance : IsSymm _ 𝔾₀ where
symm _ _ | ⟨n, b, z, h₁, h₂⟩ => ⟨n, !b, z, h₂, b.not_not.symm ▸ h₁⟩
instance : IsIrrefl _ 𝔾₀ where
irrefl x := by
intro ⟨n, b, z, h₁, h₂⟩
replace h₁ := congrFun h₁ n
replace h₂ := congrFun h₂ n
simp [s, HAppend.hAppend] at h₁ h₂
have := h₁.symm.trans h₂
simp at this
variable {X} [TopologicalSpace X]
theorem IsMeagre.union {s t : Set X} (hs : IsMeagre s) (ht : IsMeagre t) : IsMeagre (s ∪ t) := by
have := isMeagre_iUnion (s := fun n => if n = 0 then s else t) fun n => by dsimp; split; exact hs; exact ht
refine cast ?_ this
congr
simp
ext x
constructor
. simp
intro i
split <;> simp +contextual
. intro h
cases h with simp
| inl h => use 0; simp [h]
| inr h => use 1; simp [h]
theorem localize (A : Set X) (bp : BaireMeasurableSet A) (h : ¬IsMeagre A) : ∃ U, IsOpen U ∧ U.Nonempty ∧ IsMeagre (U \ A) := by
simp [BaireMeasurableSet.iff_residualEq_isOpen] at bp
rcases bp with ⟨U, hU, h'⟩
use U, hU
constructor
. by_contra hU
simp [Set.not_nonempty_iff_eq_empty] at hU
cases hU
simp [IsMeagre] at h
simp [Filter.EventuallyEq, EmptyCollection.emptyCollection] at h'
exact h h'
. apply Filter.mem_of_superset h'
intro x hx
simp at hx ⊢
intro h
exact hx.mpr h
theorem dense_iff {A : Set X} : closure A = .univ ↔ ∀ (U : Set X), IsOpen U → U.Nonempty → (A ∩ U).Nonempty := by
constructor
. intro h U U_open U_nonempty
by_contra h'
have : A ⊆ Uᶜ := fun x hx hu => h' ⟨x, hx, hu⟩
have := h ▸ closure_minimal this (by simp [U_open])
simp at this
simp [this] at U_nonempty
. intro h
ext x
simp
by_contra hx
specialize h (closure A)ᶜ
simp at h
specialize h ⟨x, hx⟩
have := Set.inter_subset_inter_right A (Set.compl_subset_compl_of_subset (subset_closure (s := A)))
simp at this
rewrite [this] at h
simp at h
lemma preimage_val_empty_iff {X : Type*} {A B : Set X} : (Subtype.val ⁻¹' A : Set B) = ∅ ↔ A ∩ B = ∅ := by
constructor
. intro h
ext x
simp
intro hA hB
have := congrArg (⟨x, hB⟩ ∈ ·) h
simp at this
exact this hA
. intro h
ext ⟨x, hB⟩
simp
intro hA
have : x ∈ A ∩ B := ⟨hA, hB⟩
rewrite [h] at this
simp at this
theorem somewhere_dense_iff {A : Set X} : (interior (closure A)).Nonempty ↔ ∃ (U : Set X), IsOpen U ∧ U.Nonempty ∧ closure (X := U) (Subtype.val ⁻¹' A) = .univ := by
constructor
. intro h
exists _, by simp, h
simp [dense_iff]
intro U U_open
rcases U_open with ⟨V, V_open, hu⟩
cases hu
contrapose
simp [Set.nonempty_iff_ne_empty, ← Set.preimage_inter, preimage_val_empty_iff]
intro h'
have : A ⊆ (V ∩ interior (closure A))ᶜ :=
fun x hA hV => have : x ∈ A ∩ V ∩ interior (closure A) := ⟨⟨hA, hV.left⟩, hV.right⟩; nomatch h' ▸ this
have := closure_minimal this (by simp; exact IsOpen.inter V_open isOpen_interior)
have : ¬(closure A ∩ V ∩ interior (closure A)).Nonempty := fun ⟨x, ⟨hA, hV⟩, hA'⟩ => this hA ⟨hV, hA'⟩
rewrite [Set.inter_comm, ← Set.inter_assoc, Set.inter_eq_self_of_subset_left interior_subset] at this
simp [Set.nonempty_iff_ne_empty, Set.inter_comm] at this
exact this
. intro ⟨U, U_open, U_nonempty, h⟩
replace h := fun x => congrArg (x ∈ ·) h
simp [closure_subtype] at h
exact U_nonempty.mono <| .trans (interior_maximal h U_open) (interior_mono (closure_mono Set.inter_subset_right))
theorem nowhere_dense_iff {A : Set X} : IsNowhereDense A ↔ ∀ (U : Set X), IsOpen U → U.Nonempty → ∃ V : Set U, IsOpen V ∧ V.Nonempty ∧ Subtype.val ⁻¹' A ∩ V = ∅ := by
rewrite [← not_iff_not]
simp [IsNowhereDense, ← Set.nonempty_iff_ne_empty, somewhere_dense_iff, dense_iff]
theorem BaireSpace.iff_open_nonempty_nonmeager : BaireSpace X ↔ ∀ (U : Set X), IsOpen U → U.Nonempty → ¬IsMeagre U := by
constructor
. intro _ U U_open U_nonempty U_meager
simp [IsMeagre, mem_residual] at U_meager
rcases U_meager with ⟨A, hA, A_Gδ, A_dense⟩
simp [isGδ_iff_eq_iInter_nat] at A_Gδ
rcases A_Gδ with ⟨S, S_open, h⟩
cases h
have := A_dense.closure.mono (IsClosed.closure_subset_iff (by simp [U_open]) |>.mpr hA) |>.interior_compl
simp [interior_eq_iff_isOpen.mpr U_open] at this
cases this
nomatch U_nonempty
. intro h
constructor
intro S S_open S_dense
by_contra h'
simp [Dense] at h'
simp [← Set.mem_compl_iff, ← interior_compl] at h'
apply h (interior <| ⋃ n, (S n)ᶜ)
. simp
. exact h'
. simp [isMeagre_iff_countable_union_isNowhereDense]
use Set.range fun n => (S n)ᶜ
simp
constructor
. intro n
ext x
simp [interior_eq_iff_isOpen.mpr (S_open n)]
exact S_dense n x
. constructor
. apply Set.countable_range
. exact interior_subset
theorem BaireSpace.comeager_nonempty [BaireSpace X] [Nonempty X] {A : Set X} (hA : IsMeagre Aᶜ) : A.Nonempty := by
have := fun h => BaireSpace.iff_open_nonempty_nonmeager.mp inferInstance (interior Aᶜ) (by simp) h (hA.mono interior_subset)
simp [Set.nonempty_compl] at this
by_contra h
simp [Set.nonempty_iff_ne_empty] at h
cases h
replace := fun x => congrArg (x ∈ ·) this
simp at this
theorem isMeager_subspace {Y : Set X} {A : Set Y} (h : IsMeagre A) : IsMeagre (Subtype.val '' A) := by
simp [isMeagre_iff_countable_union_isNowhereDense] at h ⊢
rcases h with ⟨S, S_nowhereDense, S_countable, h⟩
use (Subtype.val '' ·) '' S
simp
refine ⟨?_, S_countable.image _, ?_⟩
. intro B hB
specialize S_nowhereDense B hB
simp [IsNowhereDense] at S_nowhereDense ⊢
change interior {x | x ∈ closure B} = _ at S_nowhereDense
simp [closure_subtype] at S_nowhereDense
rewrite [← compl_compl (interior {x : Y | ↑x ∈ closure (Subtype.val '' B)}), ← closure_compl] at S_nowhereDense
change {x | x ∈ closure _}ᶜ = _ at S_nowhereDense
simp only [closure_subtype] at S_nowhereDense
replace S_nowhereDense := fun x => congrArg (x ∈ ·) S_nowhereDense
simp at S_nowhereDense
change Y ⊆ _ at S_nowhereDense
rewrite [Set.image] at S_nowhereDense
simp at S_nowhereDense
have : interior (closure (Subtype.val '' B)) ⊆ (interior (closure (Subtype.val '' B)))ᶜ := by
trans
. exact interior_subset
apply closure_minimal
. trans
swap
. trans
. exact S_nowhereDense
simp [← closure_compl]
apply closure_mono
intro
simp
. simp
. simp
simp [Set.subset_compl_iff_disjoint_right] at this
exact this
. intro _ hx
simp
exact h hx
theorem isMeager_subspace_open {U : Set X} {A : Set U} (hU : IsOpen U) : IsMeagre A ↔ IsMeagre (Subtype.val '' A) := by
constructor
. exact isMeager_subspace
. simp [isMeagre_iff_countable_union_isNowhereDense]
intro S nowhereDense countable cover
use (Subtype.val ⁻¹' ·) '' S
refine ⟨?_, countable.image _, ?_⟩
. intro B ⟨C, hC, hC'⟩
cases hC'
specialize nowhereDense C hC
simp [nowhere_dense_iff] at nowhereDense ⊢
intro V V_open V_nonempty
specialize nowhereDense (Subtype.val '' V) (IsOpen.isOpenMap_subtype_val hU _ V_open) (V_nonempty.image _)
rcases nowhereDense with ⟨W, W_open, W_nonempty, hW⟩
use ((fun x => ⟨x, x, x.property, rfl⟩) ⁻¹' W)
refine ⟨?_, ?_, ?_⟩
. simp [IsOpen, instTopologicalSpaceSubtype, TopologicalSpace.induced] at W_open ⊢
rcases W_open with ⟨W', W_open, h⟩
cases h
exists W', W_open
. rcases W_nonempty with ⟨⟨x', ⟨x, hU⟩, hV, h⟩, hW⟩
cases h
refine ⟨⟨⟨x, hU⟩, hV⟩, hW⟩
. ext ⟨⟨x, hU⟩, hV⟩
simp
intro hC hW'
replace hW := congrArg (⟨x, ⟨x, hU⟩, hV, rfl⟩ ∈ ·) hW
simp at hW
exact hW hC hW'
. simp [cover]
theorem BaireSpace.open_subspace [BaireSpace X] {U : Set X} (U_open : IsOpen U) : BaireSpace U := by
rewrite [iff_open_nonempty_nonmeager]
intro V V_open V_nonempty V_meager
apply iff_open_nonempty_nonmeager.mp (U := U ∩ Subtype.val '' V)
. infer_instance
. simp
exact IsOpen.isOpenMap_subtype_val U_open _ V_open
. simp [V_nonempty]
. simp
rewrite [← isMeager_subspace_open U_open]
exact V_meager
theorem MeasureTheory.AnalyticSet.inter [T2Space X] {A B : Set X} (hA : AnalyticSet A) (hB : AnalyticSet B) : AnalyticSet (A ∩ B) := by
refine cast ?_ <| iInter (s := fun n => Nat.casesOn n A fun _ => B) fun n => n.casesOn hA fun _ => hB
congr
ext
simp
constructor
. intro h
exact ⟨h 0, h 1⟩
. intro ⟨hA, hB⟩
intro n
cases n with simp [*]
def BorelSet (Y : Set X) : Prop :=
@MeasurableSet X (borel X) Y
def Independent (G : X → X → Prop) (A : Set X) : Prop :=
∀ x ∈ A, ∀ y ∈ A, ¬G x y
omit [TopologicalSpace X] in
theorem Independent.anti {G} {A₁ A₂ : Set X} (hA : A₁ ⊆ A₂) (indep : Independent G A₂) : Independent G A₁ := by
intro x hx y hy
exact indep x (hA hx) y (hA hy)
theorem 𝔾₀_independent_meager {A} (bp : BaireMeasurableSet A) : Independent 𝔾₀ A → IsMeagre A := by
contrapose
intro nonmeager
simp [Independent]
let ⟨U, U_open, U_nonempty, A_comeager'⟩ := localize A bp nonmeager
let ⟨n, h⟩ := contains_s U_open U_nonempty
have A_comeager : IsMeagre (N (s n) \ A) := by
apply Filter.mem_of_superset A_comeager'
simp
intro x
specialize @h x
simp +contextual [h]
clear U U_open U_nonempty A_comeager' h
let γ (x : Nat → Bool) i : Bool := if i = n then !x i else x i
have γ_cont : Continuous γ := by
simp [continuous_pi_iff, continuous_discrete_rng]
intro i
constructor
all_goals
simp [isOpen_pi_iff]
intro x hx
use {i}, fun _ => {x i}
simp [γ] at hx ⊢
by_cases h : i = n
. simp [h] at hx ⊢
simp [Set.preimage, hx]
. simp [h] at hx ⊢
exact hx
have γ_invol : γ.Involutive := by
intro x
funext i
dsimp [γ]
split <;> simp
let γ' : Homeomorph (Nat → Bool) (Nat → Bool) := {
toFun := γ
invFun := γ
left_inv := γ_invol
right_inv := γ_invol
continuous_toFun := γ_cont
continuous_invFun := γ_cont
}
have γA_comeager : IsMeagre (γ' '' (N (s n) \ A)) := by
dsimp [IsMeagre]
rewrite [← Set.image_compl_eq γ'.bijective, ← γ'.residual_map_eq]
simp
exact A_comeager
rewrite [Set.image_diff γ'.injective] at γA_comeager
have γ_stable : γ' '' N (s n) = N (s n) := by
ext x
simp [γ']
constructor
. simp
intro y hy (.refl _) i
simp [γ, Nat.ne_of_lt i.isLt]
exact hy i
. intro hx
use γ x
refine ⟨?_, γ_invol x⟩
intro i
simp [γ, Nat.ne_of_lt i.isLt]
exact hx i
rw [γ_stable] at γA_comeager
have := A_comeager.union γA_comeager
have := isMeager_subspace_open (N_open (t := s n)) (A := Subtype.val ⁻¹' (N (s n) \ (A ∩ γ' '' A)))
simp [Set.diff_inter] at this
have := this.mpr ‹_›
simp [← Set.compl_eq_univ_diff, ← Set.compl_inter, ← Set.preimage_inter] at this
let ⟨⟨_, hγN⟩, hγA, x, hA, h⟩ := (BaireSpace.open_subspace N_open).comeager_nonempty this
cases h
simp at hγA
change γ x ∈ N (s n) at hγN
rewrite [← γ_stable] at hγN
simp at hγN
rcases hγN with ⟨x', hN, h⟩
replace h := congrArg γ h
simp [γ', γ_invol x, γ_invol x'] at h
cases h
refine ⟨x, hA, γ x, hγA, n, x n, fun i => x (i + n + 1), ?_, ?_⟩
. funext i
simp [HAppend.hAppend]
split
. exact (hN ⟨i, ‹_›⟩).symm
. split <;> congr <;> omega
. funext i
simp [HAppend.hAppend]
split
. simp [γ, Nat.ne_of_lt ‹_›]; exact (hN ⟨i, ‹_›⟩).symm
next h =>
have := Nat.le_of_not_gt h
split
next h =>
simp [Nat.sub_eq_zero_iff_le] at h
cases Nat.le_antisymm this h
simp [γ]
next h =>
simp [Nat.sub_eq_zero_iff_le] at h
simp [Nat.ne_of_gt h, γ]
congr
omega
structure Approximation (n : Nat) where
f : (Fin n → Bool) → (Fin n → Nat)
g : ∀ k : Fin n, (Fin (n - (k + 1)) → Bool) → (Fin n → Nat)
deriving Countable
def append {n k} (a : Fin k → Bool) (b : Bool) (c : Fin (n - (k + 1)) → Bool) (i : Fin n) : Bool :=
if h : i < k then a ⟨i, h⟩ else if h' : i = k then b else c (.subNat (k + 1) (i.cast (by omega)) (by simp; omega))
structure Realization (n : Nat) (a : Approximation n) (Θ : (Nat → Nat) → X × X) (Φ : (Nat → Nat) → X) where
φ : (Fin n → Bool) → (Nat → Nat)
γ : ∀ k : Fin n, (Fin (n - (k + 1)) → Bool) → (Nat → Nat)
φ_f : ∀ s, φ s ∈ N (a.f s)
γ_g : ∀ k t, γ k t ∈ N (a.g k t)
edge : ∀ k t, Θ (γ k t) = (Φ (φ (append (s k) false t)), Φ (φ (append (s k) true t)))
structure Extension (n : Nat) (a : Approximation n) (b : Approximation (n + 1)) where
f : ∀ s c i, a.f s i = b.f (Fin.lastCases c s) i.castSucc
g : ∀ k t c i, a.g k t i = b.g k.castSucc (fun i => (i.cast (by simp; omega)).lastCases c t) i.castSucc
structure SetRealization (Y : Set X) {n a Θ Φ} (α : Realization n a Θ Φ) where
image : Set.range (fun x => Φ (α.φ x)) ⊆ Y
def A {n} (a : Approximation n) (s : Fin n → Bool) (Y : Set X) (Θ : (Nat → Nat) → X × X) (Φ : (Nat → Nat) → X) : Set X :=
{x | ∃ α : Realization n a Θ Φ, SetRealization Y α ∧ x = Φ (α.φ s)}
omit [TopologicalSpace X] in
theorem A_monotone {n} {a : Approximation n} {s Θ Φ} {Y₁ Y₂ : Set X} (hY : Y₁ ⊆ Y₂) : A a s Y₁ Θ Φ ⊆ A a s Y₂ Θ Φ := by
intro _ ⟨α, hα, h⟩
exact ⟨α, ⟨hα.image.trans hY⟩, h⟩
theorem A_analytic [T2Space X] {n a s' Y Θ Φ} (Y_borel : BorelSet Y) (Θ_cont : Continuous Θ) (Φ_cont : Continuous Φ) : AnalyticSet (@A X n a s' Y Θ Φ) := by
suffices AnalyticSet (Φ '' {x | ∃ α : Realization n a Θ Φ, SetRealization Y α ∧ x = α.φ s'}) by
refine cast ?_ this
congr
simp [A]
ext
simp
constructor
. intro ⟨_, ⟨α, hα, h'⟩, h⟩
cases h
cases h'
use α
. intro ⟨α, hα, h⟩
cases h
use α.φ s'
simp
use α
apply AnalyticSet.image_of_continuous _ Φ_cont
suffices AnalyticSet ({(φ, γ) : ((Fin n → Bool) → ℕ → ℕ) × (∀ k : Fin n, (Fin (n - (k + 1)) → Bool) → ℕ → ℕ) | ∀ s, φ s ∈ N (a.f s)} ∩ {(φ, γ) | ∀ k t, γ k t ∈ N (a.g k t)} ∩ {(φ, γ) | ∀ k t, Θ (γ k t) = (Φ (φ (append (s k) false t)), Φ (φ (append (s k) true t)))} ∩ {(φ, γ) | Set.range (fun x => Φ (φ x)) ⊆ Y}) by
replace := this.image_of_continuous (f := fun (φ, γ) => φ s') ?_
. refine cast ?_ this
congr
ext x
simp
constructor
. simp
intro φ γ φ_f γ_g edge image h
cases h
exact ⟨⟨φ, γ, φ_f, γ_g, edge⟩, ⟨image⟩, rfl⟩
. simp
intro α hα h
cases h
use α.φ
simp
exact ⟨⟨α.γ, ⟨α.φ_f, α.γ_g⟩, α.edge⟩, hα.image⟩
. simp
apply Continuous.fst' (f := fun φ : _ → _ => φ s')
apply continuous_apply
apply AnalyticSet.inter
apply AnalyticSet.inter
apply AnalyticSet.inter
. apply MeasurableSet.analyticSet
apply IsOpen.measurableSet
suffices IsOpen ({φ : (Fin n → Bool) → ℕ → ℕ | ∀ s, φ s ∈ N (a.f s)} ×ˢ @Set.univ (∀ k : Fin n, (Fin (n - (k + 1)) → Bool) → ℕ → ℕ)) by
simp [SProd.sprod, Set.prod] at this
exact this
simp [isOpen_prod_iff']
left
suffices IsOpen (⋂ s, {φ : (Fin n → Bool) → ℕ → ℕ | φ s ∈ N (a.f s)}) by
refine cast ?_ this
congr
ext
simp
apply isOpen_iInter_of_finite
intro s
apply N_open.preimage
apply continuous_apply
. apply MeasurableSet.analyticSet
apply IsOpen.measurableSet
suffices IsOpen (@Set.univ ((Fin n → Bool) → ℕ → ℕ) ×ˢ {γ : ∀ k : Fin n, (Fin (n - (k + 1)) → Bool) → ℕ → ℕ | ∀ k t, γ k t ∈ N (a.g k t)}) by
simp [SProd.sprod, Set.prod] at this
exact this
simp [isOpen_prod_iff']
left
suffices IsOpen (⋂ k, ⋂ t, {γ : ∀ k : Fin n, (Fin (n - (k + 1)) → Bool) → ℕ → ℕ | γ k t ∈ N (a.g k t)}) by
refine cast ?_ this
congr
ext
simp
apply isOpen_iInter_of_finite
intro k
apply isOpen_iInter_of_finite
intro t
apply N_open.preimage
revert t
rewrite [← continuous_pi_iff]
apply continuous_apply
. apply IsClosed.analyticSet
simp [← isOpen_compl_iff, HasCompl.compl]
suffices IsOpen (⋃ k : Fin n, ⋃ t : Fin (n - (k + 1)) → Bool, {(φ, γ) : ((Fin n → Bool) → ℕ → ℕ) × (∀ k : Fin n, (Fin (n - (k + 1)) → Bool) → ℕ → ℕ) | Θ (γ k t) ≠ (Φ (φ (append (s k) false t)), Φ (φ (append (s k) true t)))}) by
refine cast ?_ this
congr
ext
simp
apply isOpen_iUnion
intro k
apply isOpen_iUnion
intro t
simp [← isClosed_compl_iff, HasCompl.compl]
apply isClosed_eq
. apply Θ_cont.comp
apply Continuous.snd' (f := fun γ : ∀ k : Fin n, (Fin (n - (k + 1)) → Bool) → ℕ → ℕ => γ k t)
revert t
rewrite [← continuous_pi_iff]
apply continuous_apply
. simp
constructor
. apply Φ_cont.comp
apply Continuous.fst' (f := fun φ : _ → _ => φ (append (s k) false t))
apply continuous_apply
. apply Φ_cont.comp
apply Continuous.fst' (f := fun φ : _ → _ => φ (append (s k) true t))
apply continuous_apply
. apply MeasurableSet.analyticSet
suffices MeasurableSet ({φ : (Fin n → Bool) → ℕ → ℕ | Set.range (fun x => Φ (φ x)) ⊆ Y} ×ˢ @Set.univ (∀ k : Fin n, (Fin (n - (k + 1)) → Bool) → ℕ → ℕ)) by
simp [SProd.sprod, Set.prod, -measurableSet_setOf] at this
exact this
simp [measurableSet_prod, -measurableSet_setOf]
left
suffices MeasurableSet (⋂ x : Fin n → Bool, {φ : (Fin n → Bool) → ℕ → ℕ | Φ (φ x) ∈ Y}) by
refine cast ?_ this
congr
ext φ
simp
constructor
. intro h _ ⟨x, h⟩
cases h
exact h x
. intro h x
exact h ⟨x, rfl⟩
apply MeasurableSet.iInter
intro x
apply Y_borel.preimage
borelize X
apply Continuous.measurable
apply Φ_cont.comp
apply continuous_apply
structure GKernel (Y : Set X) (Θ Φ) where
prop : ∀ n : Nat, ∀ a : Approximation n, ∀ s : Fin n → Bool, Independent (fun x y => ∃ z, Θ z = (x, y)) (A a s Y Θ Φ) → A a s Y Θ Φ = ∅
noncomputable def amalgamation {n} Θ Φ {a : Approximation n} (α₀ α₁ : @Realization X n a Θ Φ) (h : ∃ z, Θ z = (Φ (α₀.φ (s n)), Φ (α₁.φ (s n)))) : Realization (n + 1) ⟨fun s => Fin.lastCases (if s (Fin.last n) then α₁.φ (fun i => s i.castSucc) n else α₀.φ (fun i => s i.castSucc) n) (a.f fun i => s i.castSucc), Fin.lastCases (fun _ i => Classical.choose h i) fun k t => Fin.lastCases (if t (Fin.last (n - k - 1) |>.cast (by simp; omega)) then α₁.γ k (fun i => t (i.castSucc.cast (by simp; omega))) n else α₀.γ k (fun i => t (i.castSucc.cast (by simp; omega))) n) (a.g k fun i => t (i.castSucc.cast (by simp; omega)))⟩ Θ Φ where
φ s := if s (Fin.last n) then α₁.φ fun i => s i.castSucc else α₀.φ fun i => s i.castSucc
γ := Fin.lastCases (fun _ => Classical.choose h) fun k t => if t (Fin.last (n - k - 1) |>.cast (by simp; omega)) then α₁.γ k fun i => t (i.castSucc.cast (by simp; omega)) else α₀.γ k fun i => t (i.castSucc.cast (by simp; omega))
φ_f s := by
split
. intro i
cases i using Fin.lastCases with
| last => simp [*]
| cast i => simp; exact α₁.φ_f (fun i => s i.castSucc) i
. intro i
cases i using Fin.lastCases with
| last => simp [*]
| cast i => simp; exact α₀.φ_f (fun i => s i.castSucc) i
γ_g k t := by
cases k using Fin.lastCases with
| last => intro; simp
| cast k =>
simp
split
. intro i
cases i using Fin.lastCases with
| last => simp
| cast i => simp; exact α₁.γ_g k (fun i => t (i.castSucc.cast (by simp; omega))) i
. intro i
cases i using Fin.lastCases with
| last => simp
| cast i => simp; exact α₀.γ_g k (fun i => t (i.castSucc.cast (by simp; omega))) i
edge k t := by
cases k using Fin.lastCases with
| last =>
simp [append]
exact Classical.choose_spec h
| cast k =>
have (b) : append (s ↑k) b t (Fin.last n) = t (Fin.last (n - k - 1) |>.cast (by simp; omega)) := by
have : ¬n < k := by simp
have : n ≠ k := by omega
simp [append, *]
congr
ext
simp
omega
simp [this]
split
. rewrite [α₁.edge k (fun i => t (i.castSucc.cast (by simp; omega)))]
rfl
. rewrite [α₀.edge k (fun i => t (i.castSucc.cast (by simp; omega)))]
rfl
def Realized {n} (a : Approximation n) (Y : Set X) (Θ : (Nat → Nat) → X × X) (Φ : (Nat → Nat) → X) : Prop :=
∃ α : Realization n a Θ Φ, SetRealization Y α
example {n a Y Θ Φ} : @Realized X n a Y Θ Φ ↔ ∀ s, (A a s Y Θ Φ).Nonempty := by
simp [Realized, A]
constructor
. intro ⟨α, h⟩ s
exact ⟨Φ (α.φ s), α, h, rfl⟩
. intro h
specialize h default
rcases h with ⟨_, α, h, _⟩
exact ⟨α, h⟩
omit [TopologicalSpace X] in
lemma splitting {n a Y Θ Φ} (hY : GKernel Y Θ Φ) (h : @Realized X n a Y Θ Φ) : ∃ b : Approximation (n + 1), Extension n a b ∧ Realized b Y Θ Φ := by
have : (A a (s n) Y Θ Φ).Nonempty := by
rcases h with ⟨α, h⟩
exact ⟨Φ (α.φ (s n)), α, h, rfl⟩
replace hY := fun h => have := hY.prop n a (s n) h ▸ this; (by simp at this : False)
simp [Independent] at hY
rcases hY with ⟨_, ⟨α₀, hα₀, h₀⟩, _, ⟨α₁, hα₁, h₁⟩, hY⟩
cases h₀
cases h₁
refine ⟨_, ?_, amalgamation Θ Φ α₀ α₁ hY, ?_⟩
. constructor <;> simp
. constructor
simp [amalgamation]
intro x hx
simp at hx
rcases hx with ⟨y, hy⟩
cases hy
split
. exact hα₁.image ⟨fun i => y i.castSucc, rfl⟩
. exact hα₀.image ⟨fun i => y i.castSucc, rfl⟩
def CountableBorelChromatic (Y : Set X) (G : X → X → Prop) : Prop :=
∃ A : Nat → Set X, (∀ n, BorelSet (A n) ∧ Independent G (A n)) ∧ Y = ⋃ n, A n
def CountableBorelChromatic.sing {G} {Y : Set X} (indep : Independent G Y) (borel : BorelSet Y) : CountableBorelChromatic Y G := by
use fun _ => Y
simp [*]
ext
simp
theorem CountableBorelChromatic.iUnion {G ι} [Countable ι] {Y : ι → Set X} (h : ∀ i, CountableBorelChromatic (Y i) G) : CountableBorelChromatic (⋃ i, Y i) G := by
by_cases Nonempty ι
case neg h =>
simp at h
simp
use fun _ => ∅
simp [BorelSet, Independent]
case pos =>
have ⟨f, hf⟩ := exists_surjective_nat ι
generalize hh : (fun i => Classical.choose (h i)) = h₁
have h₂ := fun i => Classical.choose_spec (h i)
simp [congrFun hh] at h₂
clear hh h
use fun n => h₁ (f n.unpair.1) n.unpair.2
simp
constructor
. intro n
exact (h₂ (f n.unpair.1)).left n.unpair.2
. ext x
simp
constructor
. intro ⟨i, hx⟩
specialize hf i
rcases hf with ⟨a, hf⟩
cases hf
rewrite [(h₂ (f a)).right] at hx
simp at hx
rcases hx with ⟨b, hx⟩
use a.pair b
simp
exact hx
. intro ⟨n, hn⟩
use f n.unpair.1
rewrite [(h₂ (f n.unpair.1)).right]
simp
use n.unpair.2
theorem CountableBorelChromatic.union {G} {Y₁ Y₂ : Set X} (h₁ : CountableBorelChromatic Y₁ G) (h₂ : CountableBorelChromatic Y₂ G) : CountableBorelChromatic (Y₁ ∪ Y₂) G := by
have := iUnion (Y := fun n => if n = 0 then Y₁ else Y₂) fun n => by dsimp; split; exact h₁; exact h₂
refine cast ?_ this
congr
simp
ext x
constructor
. simp
intro i
split <;> simp +contextual
. intro h
cases h with simp
| inl h => use 0; simp [h]
| inr h => use 1; simp [h]
variable [T2Space X]
lemma grow (G : X → X → Prop) (G_analytic : AnalyticSet {(x, y) | G x y}) {A} (A_analytic : AnalyticSet A) (indep : Independent G A) : ∃ B, BorelSet B ∧ A ⊆ B ∧ Independent G B := by
borelize X
let A' := {x | ∃ y ∈ A, G x y}
have : AnalyticSet A' := by
simp [AnalyticSet] at G_analytic A_analytic
cases G_analytic with
| inl h =>
replace h := fun x => congrArg (x ∈ ·) h
simp at h
simp [A', h]
exact MeasureTheory.analyticSet_empty
| inr G_analytic =>
cases A_analytic with
| inl h =>
replace h := fun x => congrArg (x ∈ ·) h
simp [A', h]
exact MeasureTheory.analyticSet_empty
| inr A_analytic =>
rcases G_analytic with ⟨G_f, hG⟩
rcases A_analytic with ⟨A_f, hA⟩
let P := (fun (x, y) => (G_f x |>.snd, A_f y)) ⁻¹' Set.diagonal X
have : IsClosed P := by
apply isClosed_diagonal.preimage
simp
exact ⟨hG.left.fst'.snd, hA.left.snd'⟩
have : A' = Prod.fst ∘ G_f ∘ Prod.fst '' P := by
ext x
simp [A', P]
constructor
. intro ⟨y, hy, h⟩
have := congrArg ((x, y) ∈ ·) hG.right
simp [h] at this
rcases this with ⟨z, hz⟩
use z
simp [hz]
have := congrArg (y ∈ ·) hA.right
simp [hy] at this
rcases this with ⟨w, hw⟩
exact ⟨w, hw.symm⟩
. simp
intro x y h h
cases h
use A_f y
constructor
. have : A_f y ∈ Set.range A_f := ⟨y, rfl⟩
rewrite [hA.right] at this
exact this
. rewrite [← h]
have : G_f x ∈ Set.range G_f := ⟨x, rfl⟩
rewrite [hG.right] at this
exact this
rw [this]
clear this
apply this.analyticSet.image_of_continuous
exact hG.left.fst.fst'
replace := A_analytic.measurablySeparable this
have disjoint : Disjoint A A' := by
simp [Set.disjoint_iff_inter_eq_empty]
ext x
simp [A']
exact indep x
specialize this disjoint
rcases this with ⟨B, hB, hB₁, B_borel⟩
let A'' := {y | ∃ x ∈ B, G x y}
have : AnalyticSet A'' := by
have : A'' = Prod.snd '' ({(x, y) | G x y} ∩ B ×ˢ .univ) := by
ext x
simp [A'']
constructor
. intro ⟨y, hy, h⟩
exact ⟨y, h, hy⟩
. intro ⟨y, h, hy⟩
exact ⟨y, hy, h⟩
rewrite [this]
apply AnalyticSet.image_of_continuous _ continuous_snd
simp [AnalyticSet] at G_analytic
cases G_analytic with
| inl h =>
replace h := fun x => congrArg (x ∈ ·) h
simp at h
simp [A', h]
exact MeasureTheory.analyticSet_empty
| inr G_analytic =>
rcases G_analytic with ⟨G_f, hG⟩
simp [← hG.right]
have : MeasurableSet (G_f ⁻¹' B ×ˢ .univ) := by
borelize (X × X)
apply hG.left.measurable
have : B ×ˢ @Set.univ X = Prod.fst ⁻¹' B := by
ext
simp
rewrite [this]
exact continuous_fst.measurable B_borel
replace := this.analyticSet.image_of_continuous hG.left
refine cast ?_ this
congr
ext ⟨x, y⟩
simp
constructor
. intro ⟨z, h₁, h₂⟩
exact ⟨⟨z, h₂⟩, (h₂ ▸ h₁ :)⟩
. intro ⟨⟨z, h₁⟩, h₂⟩
exact ⟨z, h₁ ▸ h₂, h₁⟩
replace := A_analytic.measurablySeparable this
have disjoint : Disjoint A A'' := by
simp [Set.disjoint_iff_inter_eq_empty]
ext y
simp [A'']
intro hy x hx h
exact hB₁.notMem_of_mem_left ⟨y, hy, h⟩ hx
specialize this disjoint
rcases this with ⟨B', hB', hB'₁, B'_borel⟩
use B ∩ B', B_borel.inter B'_borel, Set.subset_inter hB hB'
intro x hx y hy h
exact hB'₁.notMem_of_mem_left ⟨x, Set.mem_of_mem_inter_left hx, h⟩ (Set.mem_of_mem_inter_right hy)
open Ordinal Cardinal in
lemma HW Θ Φ (Θ_cont : Continuous Θ) (Φ_cont : Continuous Φ) : ∃ Y, @GKernel X Y Θ Φ ∧ CountableBorelChromatic Yᶜ fun x y => ∃ z, Θ z = (x, y) := by
borelize X
let G x y := (x, y) ∈ Set.range Θ
have G_analytic : AnalyticSet {(x, y) | G x y} := by
simp [AnalyticSet]
exact .inr ⟨Θ, Θ_cont, rfl⟩
let prime (Y : Set X) (Y_borel : BorelSet Y) : Set X :=
letI growth (n : Nat) (s : Fin n → Bool) (a : Approximation n) (indep : Independent G (A a s Y Θ Φ)) : Set X :=
haveI : AnalyticSet (A a s Y Θ Φ) := A_analytic Y_borel Θ_cont Φ_cont
Classical.choose (grow G G_analytic this indep)
Y \ ⋃ n, ⋃ s, ⋃ a, ⋃ indep, growth n s a indep
have prime_borel Y Y_borel : BorelSet (prime Y Y_borel) := by
apply Y_borel.diff