-
Notifications
You must be signed in to change notification settings - Fork 48
/
topology.v
2119 lines (1773 loc) · 85.2 KB
/
topology.v
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
(* mathcomp analysis (c) 2017 Inria and AIST. License: CeCILL-C. *)
From mathcomp Require Import ssreflect ssrfun ssrbool ssrnat eqtype choice.
From mathcomp Require Import seq fintype ssralg finmap matrix.
Require Import boolp.
Require Import classical_sets posnum.
(******************************************************************************)
(* This file develops tools for the manipulation of filters and basic *)
(* topological notions. *)
(* *)
(* * Filters : *)
(* filteredType U == interface type for types whoses *)
(* elements represent sets of sets on U. *)
(* These sets are intended to be filters *)
(* on U but this is not enforced yet. *)
(* FilteredType U T m == packs the function m: T -> set (set U) *)
(* to build a filtered type of type *)
(* filteredType U; T must have a *)
(* pointedType structure. *)
(* [filteredType U of T for cT] == T-clone of the filteredType U *)
(* structure cT. *)
(* [filteredType U of T] == clone of a canonical filteredType U *)
(* structure on T. *)
(* filter_on_term X Y == structure that records terms x : X *)
(* with a set of sets (filter) in Y. *)
(* Allows to infer the canonical filter *)
(* associated to a term by looking at its *)
(* type. *)
(* filter_term F == if F : filter_on_term X Y, outputs the *)
(* term in X contained in F. *)
(* term_filter F == if F : filter_on_term X Y, outputs the *)
(* filter on Y contained in F. *)
(* Filtered.source Y Z == structure that records types X such *)
(* that there is a function mapping *)
(* functions of type X -> Y to filters on *)
(* Z. Allows to infer the canonical *)
(* filter associated to a function by *)
(* looking at its source type. *)
(* Filtered.Source F == if F : (X -> Y) -> set (set Z), packs *)
(* X with F in a Filtered.source Y Z *)
(* structure. *)
(* [filter of x] == canonical filter associated to x. *)
(* locally p == set of sets associated to p (in a *)
(* filtered type). *)
(* filter_from D B == set of the supersets of the elements *)
(* of the family of sets B whose indices *)
(* are in the domain D. *)
(* This is a filter if (B_i)_(i in D) *)
(* forms a filter base. *)
(* filter_prod F G == product of the filters F and G. *)
(* F `=>` G <-> G is included in F; F and G are sets *)
(* of sets. *)
(* F --> G <-> the canonical filter associated to G *)
(* is included in the canonical filter *)
(* associated to F. *)
(* [lim F in T] == limit in T of the canonical filter *)
(* associated to F; T must have a *)
(* filteredType structure. *)
(* lim F == same as [lim F in T] where T is *)
(* inferred from the type of the *)
(* canonical filter associated to F. *)
(* [cvg F in T] <-> the canonical filter associated to F *)
(* converges in T. *)
(* cvg F <-> same as [cvg F in T] where T is *)
(* inferred from the type of the *)
(* canonical filter associated to F. *)
(* Filter F == type class proving that the set of *)
(* sets F is a filter. *)
(* ProperFilter F == type class proving that the set of *)
(* sets F is a proper filter. *)
(* UltraFilter F == type class proving that the set of *)
(* sets F is an ultrafilter *)
(* filtermap f F == image of the filter F by the function *)
(* f. *)
(* E @[x --> F] == image of the canonical filter *)
(* associated to F by the function *)
(* (fun x => E). *)
(* f @ F == image of the canonical filter *)
(* associated to F by the function f. *)
(* filtermapi f F == image of the filter F by the relation *)
(* f. *)
(* E `@[x --> F] == image of the canonical filter *)
(* associated to F by the relation *)
(* (fun x => E). *)
(* f `@ F == image of the canonical filter *)
(* associated to F by the relation f. *)
(* at_point a == filter of the sets containing a. *)
(* within D F == restriction of the filter F to the *)
(* domain D. *)
(* subset_filter F D == similar to within D F, but with *)
(* dependent types. *)
(* *)
(* * Near notations and tactics: *)
(* --> The purpose of the near notations and tactics is to make the *)
(* manipulation of filters easier. Instead of proving F G, one can *)
(* prove G x for x "near F", i.e. for x such that H x for H arbitrarily *)
(* precise as long as F H. The near tactics allow for a delayed *)
(* introduction of H: H is introduced as an existential variable and *)
(* progressively instantiated during the proof process. *)
(* --> Notations: *)
(* {near F, P} == the property P holds near the *)
(* canonical filter associated to F; P *)
(* must have the form forall x, Q x. *)
(* Equivalent to F Q. *)
(* \forall x \near F, P x <-> F (fun x => P x). *)
(* \near x, P x := \forall y \near x, P x. *)
(* {near F & G, P} == same as {near H, P}, where H is the *)
(* product of the filters F and G. *)
(* \forall x \near F & y \near G, P x y := {near F & G, forall x y, P x y}. *)
(* \forall x & y \near F, P x y == same as before, with G = F. *)
(* \near x & y, P x y := \forall z \near x & t \near y, P x y. *)
(* --> Tactics: *)
(* - near=> x introduces x: *)
(* On the goal \forall x \near F, G x, introduces the variable x and an *)
(* "existential", and unaccessible hypothesis ?H x and asks the user to *)
(* prove (G x) in this context. *)
(* Under the hood delays the proof of F ?H and waits for near: x *)
(* Also exists under the form near=> x y. *)
(* - near: x discharges x: *)
(* On the goal H_i x, and where x \is_near F, it asks the user to prove *)
(* that (\forall x \near F, H_i x), provided that H_i x does not depend *)
(* on variables introduced after x. *)
(* Under the hood, it refines by intersection the existential variable *)
(* ?H attached to x, commutes the intersection with F, and asks the *)
(* user to prove F H_i, right now *)
(* - end_near should be used to close remaining existentials trivially *)
(* - near F => x poses a variable near F, where F is a proper filter *)
(* adds to the context a variable x that \is_near F, i.e. one may *)
(* assume H x for any H in F. This new variable xcan be dealt with *)
(* using near: x, as for variables introduced by near=>. *)
(* *)
(* * Topology : *)
(* topologicalType == interface type for topological space *)
(* structure. *)
(* TopologicalMixin loc_filt locE == builds the mixin for a topological *)
(* space from the proofs that locally *)
(* outputs proper filters and defines the *)
(* same notion of neighbourhood as the *)
(* open sets. *)
(* topologyOfFilterMixin loc_filt loc_sing loc_loc == builds the mixin for *)
(* a topological space from the *)
(* properties of locally. *)
(* topologyOfOpenMixin opT opI op_bigU == builds the mixin for a *)
(* topological space from the properties *)
(* of open sets. *)
(* topologyOfBaseMixin b_cover b_join == builds the mixin for a topological *)
(* space from the properties of a base of *)
(* open sets; the type of indices must be *)
(* a pointedType. *)
(* topologyOfSubbaseMixin D b == builds the mixin for a topological *)
(* space from a subbase of open sets b *)
(* indexed on domain D; the type of *)
(* indices must be a pointedType. *)
(* TopologicalType T m == packs the mixin m to build a *)
(* topologicalType; T must have a *)
(* canonical filteredType T structure. *)
(* weak_topologicalType f == weak topology by f : S -> T on S; S *)
(* must be a pointedType and T a *)
(* topologicalType. *)
(* sup_topologicalType Tc == supremum topology of the family of *)
(* topologicalType structures Tc on T; T *)
(* must be a pointedType. *)
(* product_topologicalType T == product topology of the family of *)
(* topologicalTypes T. *)
(* [topologicalType of T for cT] == T-clone of the topologicalType *)
(* structure cT. *)
(* [topologicalType of T] == clone of a canonical topologicalType *)
(* structure on T. *)
(* open == set of open sets. *)
(* neigh p == set of open neighbourhoods of p. *)
(* continuous f <-> f is continuous w.r.t the topology. *)
(* locally' x == set of neighbourhoods of x where x is *)
(* excluded. *)
(* closure A == closure of the set A. *)
(* closed == set of closed sets. *)
(* cluster F == set of cluster points of F. *)
(* compact == set of compact sets w.r.t. the filter- *)
(* based definition of compactness. *)
(* hausdorff T <-> T is a Hausdorff space (T_2). *)
(* cover_compact == set of compact sets w.r.t. the open *)
(* cover-based definition of compactness. *)
(* connected A <-> the only non empty subset of A which *)
(* is both open and closed in A is A. *)
(* *)
(* --> We used these topological notions to prove Tychonoff's Theorem, which *)
(* states that any product of compact sets is compact according to the *)
(* product topology. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope classical_set_scope.
Module Filtered.
(* Index a family of filters on a type, one for each element of the type *)
Definition locally_of U T := T -> set (set U).
Record class_of U T := Class {
base : Pointed.class_of T;
locally_op : locally_of U T
}.
Section ClassDef.
Variable U : Type.
Structure type := Pack { sort; _ : class_of U sort ; _ : Type }.
Local Coercion sort : type >-> Sortclass.
Variables (T : Type) (cT : type).
Definition class := let: Pack _ c _ := cT return class_of U cT in c.
Definition clone c of phant_id class c := @Pack T c T.
Let xT := let: Pack T _ _ := cT in T.
Notation xclass := (class : class_of U xT).
Local Coercion base : class_of >-> Pointed.class_of.
Definition pack m :=
fun bT b of phant_id (Pointed.class bT) b => @Pack T (Class b m) T.
Definition eqType := @Equality.Pack cT xclass xT.
Definition choiceType := @Choice.Pack cT xclass xT.
Definition fpointedType := @Pointed.Pack cT xclass xT.
End ClassDef.
(* filter on arrow sources *)
Structure source Z Y := Source {
source_type :> Type;
_ : (source_type -> Z) -> set (set Y)
}.
Definition source_filter Z Y (F : source Z Y) : (F -> Z) -> set (set Y) :=
let: Source X f := F in f.
Module Exports.
Coercion sort : type >-> Sortclass.
Coercion base : class_of >-> Pointed.class_of.
Coercion locally_op : class_of >-> locally_of.
Coercion eqType : type >-> Equality.type.
Canonical eqType.
Coercion choiceType : type >-> Choice.type.
Canonical choiceType.
Coercion fpointedType : type >-> Pointed.type.
Canonical fpointedType.
Notation filteredType := type.
Notation FilteredType U T m := (@pack U T m _ _ idfun).
Notation "[ 'filteredType' U 'of' T 'for' cT ]" := (@clone U T cT _ idfun)
(at level 0, format "[ 'filteredType' U 'of' T 'for' cT ]") : form_scope.
Notation "[ 'filteredType' U 'of' T ]" := (@clone U T _ _ id)
(at level 0, format "[ 'filteredType' U 'of' T ]") : form_scope.
(* The default filter for an arbitrary element is the one obtained *)
(* from its type *)
Canonical default_arrow_filter Y (Z : pointedType) (X : source Z Y) :=
FilteredType Y (X -> Z) (@source_filter _ _ X).
Canonical source_filter_filter Y :=
@Source Prop _ (_ -> Prop) (fun x : (set (set Y)) => x).
Canonical source_filter_filter' Y :=
@Source Prop _ (set _) (fun x : (set (set Y)) => x).
End Exports.
End Filtered.
Export Filtered.Exports.
Definition locally {U} {T : filteredType U} : T -> set (set U) :=
Filtered.locally_op (Filtered.class T).
Arguments locally {U T} _ _ : simpl never.
Definition filter_from {I T : Type} (D : set I) (B : I -> set T) : set (set T) :=
[set P | exists2 i, D i & B i `<=` P].
(* the canonical filter on matrices on X is the product of the canonical filter
on X *)
Canonical matrix_filtered m n X (Z : filteredType X) : filteredType 'M[X]_(m, n) :=
FilteredType 'M[X]_(m, n) 'M[Z]_(m, n) (fun mx => filter_from
[set P | forall i j, locally (mx i j) (P i j)]
(fun P => [set my : 'M[X]_(m, n) | forall i j, P i j (my i j)])).
Definition filter_prod {T U : Type}
(F : set (set T)) (G : set (set U)) : set (set (T * U)) :=
filter_from (fun P => F P.1 /\ G P.2) (fun P => P.1 `*` P.2).
Section Near.
Local Notation "{ 'all1' P }" := (forall x, P x : Prop) (at level 0).
Local Notation "{ 'all2' P }" := (forall x y, P x y : Prop) (at level 0).
Local Notation "{ 'all3' P }" := (forall x y z, P x y z: Prop) (at level 0).
Local Notation ph := (phantom _).
Definition prop_near1 {X} {fX : filteredType X} (x : fX)
P (phP : ph {all1 P}) := locally x P.
Definition prop_near2 {X X'} {fX : filteredType X} {fX' : filteredType X'}
(x : fX) (x' : fX') := fun P of ph {all2 P} =>
filter_prod (locally x) (locally x') (fun x => P x.1 x.2).
End Near.
Notation "{ 'near' x , P }" := (@prop_near1 _ _ x _ (inPhantom P))
(at level 0, format "{ 'near' x , P }") : type_scope.
Notation "'\forall' x '\near' x_0 , P" := {near x_0, forall x, P}
(at level 200, x ident, P at level 200, format "'\forall' x '\near' x_0 , P") : type_scope.
Notation "'\near' x , P" := (\forall x \near x, P)
(at level 200, x at level 99, P at level 200, format "'\near' x , P", only parsing) : type_scope.
Notation "{ 'near' x & y , P }" := (@prop_near2 _ _ _ _ x y _ (inPhantom P))
(at level 0, format "{ 'near' x & y , P }") : type_scope.
Notation "'\forall' x '\near' x_0 & y '\near' y_0 , P" :=
{near x_0 & y_0, forall x y, P}
(at level 200, x ident, y ident, P at level 200,
format "'\forall' x '\near' x_0 & y '\near' y_0 , P") : type_scope.
Notation "'\forall' x & y '\near' z , P" :=
{near z & z, forall x y, P}
(at level 200, x ident, y ident, P at level 200,
format "'\forall' x & y '\near' z , P") : type_scope.
Notation "'\near' x & y , P" := (\forall x \near x & y \near y, P)
(at level 200, x, y at level 99, P at level 200, format "'\near' x & y , P", only parsing) : type_scope.
Arguments prop_near1 : simpl never.
Arguments prop_near2 : simpl never.
Lemma nearE {T} {F : set (set T)} (P : set T) : (\forall x \near F, P x) = F P.
Proof. by []. Qed.
Definition filter_of X (fX : filteredType X) (x : fX) of phantom fX x :=
locally x.
Notation "[ 'filter' 'of' x ]" := (@filter_of _ _ _ (Phantom _ x))
(format "[ 'filter' 'of' x ]") : classical_set_scope.
Arguments filter_of _ _ _ _ _ /.
Lemma filter_of_filterE {T : Type} (F : set (set T)) : [filter of F] = F.
Proof. by []. Qed.
Lemma locally_filterE {T : Type} (F : set (set T)) : locally F = F.
Proof. by []. Qed.
Module Export LocallyFilter.
Definition locally_simpl := (@filter_of_filterE, @locally_filterE).
End LocallyFilter.
Definition flim {T : Type} (F G : set (set T)) := G `<=` F.
Notation "F `=>` G" := (flim F G)
(at level 70, format "F `=>` G") : classical_set_scope.
Lemma flim_refl T (F : set (set T)) : F `=>` F.
Proof. exact. Qed.
Lemma flim_trans T (G F H : set (set T)) :
(F `=>` G) -> (G `=>` H) -> (F `=>` H).
Proof. by move=> FG GH P /GH /FG. Qed.
Notation "F --> G" := (flim [filter of F] [filter of G])
(at level 70, format "F --> G") : classical_set_scope.
Definition type_of_filter {T} (F : set (set T)) := T.
Definition lim_in {U : Type} (T : filteredType U) :=
fun F : set (set U) => get (fun l : T => F --> l).
Notation "[ 'lim' F 'in' T ]" := (@lim_in _ T [filter of F])
(format "[ 'lim' F 'in' T ]") : classical_set_scope.
Notation lim F := [lim F in [filteredType _ of @type_of_filter _ [filter of F]]].
Notation "[ 'cvg' F 'in' T ]" := (F --> [lim F in T])
(format "[ 'cvg' F 'in' T ]") : classical_set_scope.
Notation cvg F := [cvg F in [filteredType _ of @type_of_filter _ [filter of F]]].
Section FilteredTheory.
Canonical filtered_prod X1 X2 (Z1 : filteredType X1)
(Z2 : filteredType X2) : filteredType (X1 * X2) :=
FilteredType (X1 * X2) (Z1 * Z2)
(fun x => filter_prod (locally x.1) (locally x.2)).
Lemma flim_prod T {U U' V V' : filteredType T} (x : U) (l : U') (y : V) (k : V') :
x --> l -> y --> k -> (x, y) --> (l, k).
Proof.
move=> xl yk X [[X1 X2] /= [HX1 HX2] H]; exists (X1, X2) => //=.
split; [exact: xl | exact: yk].
Qed.
Lemma cvg_ex {U : Type} (T : filteredType U) (F : set (set U)) :
[cvg F in T] <-> (exists l : T, F --> l).
Proof. by split=> [cvg|/getPex//]; exists [lim F in T]. Qed.
Lemma cvgP {U : Type} (T : filteredType U) (F : set (set U)) (l : T) :
F --> l -> [cvg F in T].
Proof. by move=> Fl; apply/cvg_ex; exists l. Qed.
Lemma dvgP {U : Type} (T : filteredType U) (F : set (set U)) :
~ [cvg F in T] -> [lim F in T] = point.
Proof. by rewrite /lim_in /=; case xgetP. Qed.
(* CoInductive cvg_spec {U : Type} (T : filteredType U) (F : set (set U)) : *)
(* U -> Prop -> Type := *)
(* | HasLim of F --> [lim F in T] : cvg_spec T F [lim F in T] True *)
(* | HasNoLim of ~ [cvg F in U] : cvg_spec F point False. *)
(* Lemma cvgP (F : set (set U)) : cvg_spec F (lim F) [cvg F in U]. *)
(* Proof. *)
(* have [cvg|dvg] := pselect [cvg F in U]. *)
(* by rewrite (propT cvg); apply: HasLim; rewrite -cvgE. *)
(* by rewrite (propF dvg) (dvgP _) //; apply: HasNoLim. *)
(* Qed. *)
End FilteredTheory.
Lemma locally_nearE {U} {T : filteredType U} (x : T) (P : set U) :
locally x P = \near x, P x.
Proof. by []. Qed.
Lemma near_locally {U} {T : filteredType U} (x : T) (P : set U) :
(\forall x \near locally x, P x) = \near x, P x.
Proof. by []. Qed.
Lemma near2_curry {U V} (F : set (set U)) (G : set (set V)) (P : U -> set V) :
{near F & G, forall x y, P x y} = {near (F, G), forall x, P x.1 x.2}.
Proof. by []. Qed.
Lemma near2_pair {U V} (F : set (set U)) (G : set (set V)) (P : set (U * V)) :
{near F & G, forall x y, P (x, y)} = {near (F, G), forall x, P x}.
Proof. by symmetry; congr (locally _); rewrite predeqE => -[]. Qed.
Definition near2E := (@near2_curry, @near2_pair).
Lemma filter_of_nearI (X : Type) (fX : filteredType X)
(x : fX) (ph : phantom fX x) : forall P,
@filter_of X fX x ph P = @prop_near1 X fX x P (inPhantom (forall x, P x)).
Proof. by []. Qed.
Module Export NearLocally.
Definition near_simpl := (@near_locally, @locally_nearE, filter_of_nearI).
Ltac near_simpl := rewrite ?near_simpl.
End NearLocally.
Lemma near_swap {U V} (F : set (set U)) (G : set (set V)) (P : U -> set V) :
(\forall x \near F & y \near G, P x y) = (\forall y \near G & x \near F, P x y).
Proof.
rewrite propeqE; split => -[[/=A B] [FA FB] ABP];
by exists (B, A) => // -[x y] [/=Bx Ay]; apply: (ABP (y, x)).
Qed.
(** * Filters *)
(** ** Definitions *)
Class Filter {T : Type} (F : set (set T)) := {
filterT : F setT ;
filterI : forall P Q : set T, F P -> F Q -> F (P `&` Q) ;
filterS : forall P Q : set T, P `<=` Q -> F P -> F Q
}.
Global Hint Mode Filter - ! : typeclass_instances.
Class ProperFilter' {T : Type} (F : set (set T)) := {
filter_not_empty : not (F (fun _ => False)) ;
filter_filter' :> Filter F
}.
Global Hint Mode ProperFilter' - ! : typeclass_instances.
Arguments filter_not_empty {T} F {_}.
Notation ProperFilter := ProperFilter'.
Lemma filter_setT (T' : Type) : Filter (@setT (set T')).
Proof. by constructor. Qed.
Lemma filter_bigI T (I : choiceType) (D : {fset I}) (f : I -> set T)
(F : set (set T)) :
Filter F -> (forall i, i \in D -> F (f i)) ->
F (\bigcap_(i in [set i | i \in D]) f i).
Proof.
move=> FF FfD.
suff: F [set p | forall i, i \in enum_fset D -> f i p] by [].
have {FfD} : forall i, i \in enum_fset D -> F (f i) by move=> ? /FfD.
elim: (enum_fset D) => [|i s ihs] FfD; first exact: filterS filterT.
apply: (@filterS _ _ _ (f i `&` [set p | forall i, i \in s -> f i p])).
by move=> p [fip fsp] j; rewrite inE => /orP [/eqP->|] //; apply: fsp.
apply: filterI; first by apply: FfD; rewrite inE eq_refl.
by apply: ihs => j sj; apply: FfD; rewrite inE sj orbC.
Qed.
Structure filter_on T := FilterType {
filter :> (T -> Prop) -> Prop;
filter_class : Filter filter
}.
Arguments FilterType {T} _ _.
Existing Instance filter_class.
(* Typeclasses Opaque filter. *)
Coercion filter_filter' : ProperFilter >-> Filter.
Structure pfilter_on T := PFilterPack {
pfilter :> (T -> Prop) -> Prop;
pfilter_class : ProperFilter pfilter
}.
Arguments PFilterPack {T} _ _.
Existing Instance pfilter_class.
(* Typeclasses Opaque pfilter. *)
Canonical pfilter_filter_on T (F : pfilter_on T) :=
FilterType F (pfilter_class F).
Coercion pfilter_filter_on : pfilter_on >-> filter_on.
Definition PFilterType {T} (F : (T -> Prop) -> Prop)
{fF : Filter F} (fN0 : not (F set0)) :=
PFilterPack F (Build_ProperFilter' fN0 fF).
Arguments PFilterType {T} F {fF} fN0.
Canonical filter_on_eqType T := EqType (filter_on T) gen_eqMixin.
Canonical filter_on_choiceType T :=
ChoiceType (filter_on T) gen_choiceMixin.
Canonical filter_on_PointedType T :=
PointedType (filter_on T) (FilterType _ (filter_setT T)).
Canonical filter_on_FilteredType T :=
FilteredType T (filter_on T) (@filter T).
Global Instance filter_on_Filter T (F : filter_on T) : Filter F.
Proof. by case: F. Qed.
Global Instance pfilter_on_ProperFilter T (F : pfilter_on T) : ProperFilter F.
Proof. by case: F. Qed.
Lemma filter_locallyT {T : Type} (F : set (set T)) :
Filter F -> locally F setT.
Proof. by move=> FF; apply: filterT. Qed.
Hint Resolve filter_locallyT.
Lemma nearT {T : Type} (F : set (set T)) : Filter F -> \near F, True.
Proof. by move=> FF; apply: filterT. Qed.
Hint Resolve nearT.
Lemma filter_not_empty_ex {T : Type} (F : set (set T)) :
(forall P, F P -> exists x, P x) -> ~ F set0.
Proof. by move=> /(_ set0) ex /ex []. Qed.
Definition Build_ProperFilter {T : Type} (F : set (set T))
(filter_ex : forall P, F P -> exists x, P x)
(filter_filter : Filter F) :=
Build_ProperFilter' (filter_not_empty_ex filter_ex) (filter_filter).
Lemma filter_ex_subproof {T : Type} (F : set (set T)) :
~ F set0 -> (forall P, F P -> exists x, P x).
Proof.
move=> NFset0 P FP; apply: contrapNT NFset0 => nex; suff <- : P = set0 by [].
by rewrite funeqE => x; rewrite propeqE; split=> // Px; apply: nex; exists x.
Qed.
Definition filter_ex {T : Type} (F : set (set T)) {FF : ProperFilter F} :=
filter_ex_subproof (filter_not_empty F).
Arguments filter_ex {T F FF _}.
Lemma filter_getP {T : pointedType} (F : set (set T)) {FF : ProperFilter F}
(P : set T) : F P -> P (get P).
Proof. by move=> /filter_ex /getPex. Qed.
(* Near Tactic *)
Record in_filter T (F : set (set T)) := InFilter {
prop_in_filter_proj : T -> Prop;
prop_in_filterP_proj : F prop_in_filter_proj
}.
(* add ball x e as a canonical instance of locally x *)
Module Type PropInFilterSig.
Axiom t : forall (T : Type) (F : set (set T)), in_filter F -> T -> Prop.
Axiom tE : t = prop_in_filter_proj.
End PropInFilterSig.
Module PropInFilter : PropInFilterSig.
Definition t := prop_in_filter_proj.
Lemma tE : t = prop_in_filter_proj. Proof. by []. Qed.
End PropInFilter.
(* Coercion PropInFilter.t : in_filter >-> Funclass. *)
Notation prop_of := PropInFilter.t.
Definition prop_ofE := PropInFilter.tE.
Notation "x \is_near F" :=
(@PropInFilter.t _ F _ x) (at level 10, format "x \is_near F").
Definition is_nearE := prop_ofE.
Lemma prop_ofP T F (iF : @in_filter T F) : F (prop_of iF).
Proof. by rewrite prop_ofE; apply: prop_in_filterP_proj. Qed.
Definition in_filterT T F (FF : Filter F) : @in_filter T F :=
InFilter (filterT).
Canonical in_filterI T F (FF : Filter F) (P Q : @in_filter T F) :=
InFilter (filterI (prop_in_filterP_proj P) (prop_in_filterP_proj Q)).
Lemma filter_near_of T F (P : @in_filter T F) (Q : set T) : Filter F ->
(forall x, prop_of P x -> Q x) -> F Q.
Proof.
by move: P => [P FP] FF /=; rewrite prop_ofE /= => /filterS; apply.
Qed.
Lemma near_acc T F (P : @in_filter T F) (Q : set T) (FF : Filter F)
(FQ : \forall x \near F, Q x) :
(forall x, prop_of (in_filterI FF P (InFilter FQ)) x -> Q x).
Proof. by move=> x /=; rewrite !prop_ofE /= => -[Px]. Qed.
Lemma nearW T F (P Q : @in_filter T F) (G : set T) (FF : Filter F) :
(forall x, prop_of P x -> G x) ->
(forall x, prop_of (in_filterI FF P Q) x -> G x).
Proof.
move=> FG x /=; rewrite !prop_ofE /= => -[Px Qx].
by have /= := FG x; apply; rewrite prop_ofE.
Qed.
Tactic Notation "near=>" ident(x) := apply: filter_near_of => x ?.
Ltac just_discharge_near x :=
tryif match goal with Hx : x \is_near _ |- _ => move: (x) Hx end
then idtac else fail "the variable" x "is not a ""near"" variable".
Tactic Notation "near:" ident(x) :=
just_discharge_near x;
tryif do ![apply: near_acc; first shelve
|apply: nearW; [move] (* ensures only one goal is created *)]
then idtac
else fail "the goal depends on variables introduced after" x.
Ltac end_near := do ?exact: in_filterT.
Ltac done :=
trivial; hnf; intros; solve
[ do ![solve [trivial | apply: sym_equal; trivial]
| discriminate | contradiction | split]
| case not_locked_false_eq_true; assumption
| match goal with H : ~ _ |- _ => solve [case H; trivial] end
| match goal with |- ?x \is_near _ => near: x; apply: prop_ofP end ].
Lemma have_near (U : Type) (fT : filteredType U) (x : fT) (P : Prop) :
ProperFilter (locally x) -> (\forall x \near x, P) -> P.
Proof. by move=> FF nP; have [] := @filter_ex _ _ FF (fun=> P). Qed.
Arguments have_near {U fT} x.
Tactic Notation "near" constr(F) "=>" ident(x) :=
apply: (have_near F); near=> x.
Lemma near T (F : set (set T)) P (FP : F P) (x : T)
(Px : prop_of (InFilter FP) x) : P x.
Proof. by move: Px; rewrite prop_ofE. Qed.
Arguments near {T F P} FP x Px.
Lemma filterE {T : Type} {F : set (set T)} :
Filter F -> forall P : set T, (forall x, P x) -> F P.
Proof. by move=> ???; near=> x => //. Unshelve. end_near. Qed.
Lemma filter_app (T : Type) (F : set (set T)) :
Filter F -> forall P Q : set T, F (fun x => P x -> Q x) -> F P -> F Q.
Proof.
by move=> FF P Q subPQ FP; near=> x; suff: P x; near: x.
Grab Existential Variables. by end_near. Qed.
Lemma filter_app2 (T : Type) (F : set (set T)) :
Filter F -> forall P Q R : set T, F (fun x => P x -> Q x -> R x) ->
F P -> F Q -> F R.
Proof. by move=> ???? PQR FP; apply: filter_app; apply: filter_app FP. Qed.
Lemma filter_app3 (T : Type) (F : set (set T)) :
Filter F -> forall P Q R S : set T, F (fun x => P x -> Q x -> R x -> S x) ->
F P -> F Q -> F R -> F S.
Proof. by move=> ????? PQR FP; apply: filter_app2; apply: filter_app FP. Qed.
Lemma filterS2 (T : Type) (F : set (set T)) :
Filter F -> forall P Q R : set T, (forall x, P x -> Q x -> R x) ->
F P -> F Q -> F R.
Proof. by move=> ???? /filterE; apply: filter_app2. Qed.
Lemma filterS3 (T : Type) (F : set (set T)) :
Filter F -> forall P Q R S : set T, (forall x, P x -> Q x -> R x -> S x) ->
F P -> F Q -> F R -> F S.
Proof. by move=> ????? /filterE; apply: filter_app3. Qed.
Lemma filter_const {T : Type} {F} {FF: @ProperFilter T F} (P : Prop) :
F (fun=> P) -> P.
Proof. by move=> FP; case: (filter_ex FP). Qed.
Lemma in_filter_from {I T : Type} (D : set I) (B : I -> set T) (i : I) :
D i -> filter_from D B (B i).
Proof. by exists i. Qed.
Lemma near_andP {T : Type} F (b1 b2 : T -> Prop) : Filter F ->
(\forall x \near F, b1 x /\ b2 x) <->
(\forall x \near F, b1 x) /\ (\forall x \near F, b2 x).
Proof.
move=> FF; split=> [H|[H1 H2]]; first by split; apply: filterS H => ? [].
by apply: filterS2 H1 H2.
Qed.
Lemma nearP_dep {T U} {F : set (set T)} {G : set (set U)}
{FF : Filter F} {FG : Filter G} (P : T -> U -> Prop) :
(\forall x \near F & y \near G, P x y) ->
\forall x \near F, \forall y \near G, P x y.
Proof.
move=> [[Q R] [/=FQ GR]] QRP.
by apply: filterS FQ => x Q1x; apply: filterS GR => y Q2y; apply: (QRP (_, _)).
Qed.
Lemma filter2P T U (F : set (set T)) (G : set (set U))
{FF : Filter F} {FG : Filter G} (P : set (T * U)) :
(exists2 Q : set T * set U, F Q.1 /\ G Q.2
& forall (x : T) (y : U), Q.1 x -> Q.2 y -> P (x, y))
<-> \forall x \near (F, G), P x.
Proof.
split=> [][[A B] /=[FA GB] ABP]; exists (A, B) => //=.
by move=> [a b] [/=Aa Bb]; apply: ABP.
by move=> a b Aa Bb; apply: (ABP (_, _)).
Qed.
Lemma filter_ex2 {T U : Type} (F : set (set T)) (G : set (set U))
{FF : ProperFilter F} {FG : ProperFilter G} (P : set T) (Q : set U) :
F P -> G Q -> exists x : T, exists2 y : U, P x & Q y.
Proof. by move=> /filter_ex [x Px] /filter_ex [y Qy]; exists x, y. Qed.
Arguments filter_ex2 {T U F G FF FG _ _}.
Lemma filter_fromP {I T : Type} (D : set I) (B : I -> set T) (F : set (set T)) :
Filter F -> F `=>` filter_from D B <-> forall i, D i -> F (B i).
Proof.
split; first by move=> FB i ?; apply/FB/in_filter_from.
by move=> FB P [i Di BjP]; apply: (filterS BjP); apply: FB.
Qed.
Lemma filter_fromTP {I T : Type} (B : I -> set T) (F : set (set T)) :
Filter F -> F `=>` filter_from setT B <-> forall i, F (B i).
Proof. by move=> FF; rewrite filter_fromP; split=> [P i|P i _]; apply: P. Qed.
Lemma filter_from_filter {I T : Type} (D : set I) (B : I -> set T) :
(exists i : I, D i) ->
(forall i j, D i -> D j -> exists2 k, D k & B k `<=` B i `&` B j) ->
Filter (filter_from D B).
Proof.
move=> [i0 Di0] Binter; constructor; first by exists i0.
- move=> P Q [i Di BiP] [j Dj BjQ]; have [k Dk BkPQ]:= Binter _ _ Di Dj.
by exists k => // x /BkPQ [/BiP ? /BjQ].
- by move=> P Q subPQ [i Di BiP]; exists i; apply: subset_trans subPQ.
Qed.
Lemma filter_fromT_filter {I T : Type} (B : I -> set T) :
(exists _ : I, True) ->
(forall i j, exists k, B k `<=` B i `&` B j) ->
Filter (filter_from setT B).
Proof.
move=> [i0 _] BI; apply: filter_from_filter; first by exists i0.
by move=> i j _ _; have [k] := BI i j; exists k.
Qed.
Lemma filter_from_proper {I T : Type} (D : set I) (B : I -> set T) :
Filter (filter_from D B) ->
(forall i, D i -> B i !=set0) ->
ProperFilter (filter_from D B).
Proof.
move=> FF BN0; apply: Build_ProperFilter=> P [i Di BiP].
by have [x Bix] := BN0 _ Di; exists x; apply: BiP.
Qed.
(** ** Limits expressed with filters *)
Definition filtermap {T U : Type} (f : T -> U) (F : set (set T)) :=
[set P | F (f @^-1` P)].
Arguments filtermap _ _ _ _ _ /.
Lemma filtermapE {U V : Type} (f : U -> V)
(F : set (set U)) (P : set V) : filtermap f F P = F (f @^-1` P).
Proof. by []. Qed.
Notation "E @[ x --> F ]" := (filtermap (fun x => E) [filter of F])
(at level 60, x ident, format "E @[ x --> F ]") : classical_set_scope.
Notation "f @ F" := (filtermap f [filter of F])
(at level 60, format "f @ F") : classical_set_scope.
Global Instance filtermap_filter T U (f : T -> U) (F : set (set T)) :
Filter F -> Filter (f @ F).
Proof.
move=> FF; constructor => [|P Q|P Q PQ]; rewrite ?filtermapE ?filter_ofE //=.
- exact: filterT.
- exact: filterI.
- by apply: filterS=> ?/PQ.
Qed.
Typeclasses Opaque filtermap.
Global Instance filtermap_proper_filter T U (f : T -> U) (F : set (set T)) :
ProperFilter F -> ProperFilter (f @ F).
Proof.
move=> FF; apply: Build_ProperFilter';
by rewrite filtermapE; apply: filter_not_empty.
Qed.
Definition filtermap_proper_filter' := filtermap_proper_filter.
Definition filtermapi {T U : Type} (f : T -> set U) (F : set (set T)) :=
[set P | \forall x \near F, exists y, f x y /\ P y].
Notation "E `@[ x --> F ]" := (filtermapi (fun x => E) [filter of F])
(at level 60, x ident, format "E `@[ x --> F ]") : classical_set_scope.
Notation "f `@ F" := (filtermapi f [filter of F])
(at level 60, format "f `@ F") : classical_set_scope.
Lemma filtermapiE {U V : Type} (f : U -> set V)
(F : set (set U)) (P : set V) :
filtermapi f F P = \forall x \near F, exists y, f x y /\ P y.
Proof. by []. Qed.
Global Instance filtermapi_filter T U (f : T -> set U) (F : set (set T)) :
infer {near F, is_totalfun f} -> Filter F -> Filter (f `@ F).
Proof.
move=> f_totalfun FF; rewrite /filtermapi; apply: Build_Filter. (* bug *)
- by apply: filterS f_totalfun => x [[y Hy] H]; exists y.
- move=> P Q FP FQ; near=> x.
have [//|y [fxy Py]] := near FP x.
have [//|z [fxz Qz]] := near FQ x.
have [//|_ fx_prop] := near f_totalfun x.
by exists y; split => //; split => //; rewrite [y](fx_prop _ z).
- move=> P Q subPQ FP; near=> x.
by have [//|y [fxy /subPQ Qy]] := near FP x; exists y.
Grab Existential Variables. all: end_near. Qed.
Typeclasses Opaque filtermapi.
Global Instance filtermapi_proper_filter
T U (f : T -> U -> Prop) (F : set (set T)) :
infer {near F, is_totalfun f} ->
ProperFilter F -> ProperFilter (f `@ F).
Proof.
move=> f_totalfun FF; apply: Build_ProperFilter.
by move=> P; rewrite /filtermapi => /filter_ex [x [y [??]]]; exists y.
Qed.
Definition filter_map_proper_filter' := filtermapi_proper_filter.
Lemma flim_id T (F : set (set T)) : x @[x --> F] --> F.
Proof. exact. Qed.
Arguments flim_id {T F}.
Lemma appfilter U V (f : U -> V) (F : set (set U)) :
f @ F = [set P : set _ | \forall x \near F, P (f x)].
Proof. by []. Qed.
Lemma flim_app U V (F G : set (set U)) (f : U -> V) :
F --> G -> f @ F --> f @ G.
Proof. by move=> FG P /=; exact: FG. Qed.
Lemma flimi_app U V (F G : set (set U)) (f : U -> set V) :
F --> G -> f `@ F --> f `@ G.
Proof. by move=> FG P /=; exact: FG. Qed.
Lemma flim_comp T U V (f : T -> U) (g : U -> V)
(F : set (set T)) (G : set (set U)) (H : set (set V)) :
f @ F `=>` G -> g @ G `=>` H -> g \o f @ F `=>` H.
Proof. by move=> fFG gGH; apply: flim_trans gGH => P /fFG. Qed.
Lemma flimi_comp T U V (f : T -> U) (g : U -> set V)
(F : set (set T)) (G : set (set U)) (H : set (set V)) :
f @ F `=>` G -> g `@ G `=>` H -> g \o f `@ F `=>` H.
Proof. by move=> fFG gGH; apply: flim_trans gGH => P /fFG. Qed.
Lemma flim_eq_loc {T U} {F : set (set T)} {FF : Filter F} (f g : T -> U) :
{near F, f =1 g} -> g @ F `=>` f @ F.
Proof. by move=> eq_fg P /=; apply: filterS2 eq_fg => x <-. Qed.
Lemma flimi_eq_loc {T U} {F : set (set T)} {FF : Filter F} (f g : T -> set U) :
{near F, f =2 g} -> g `@ F `=>` f `@ F.
Proof.
move=> eq_fg P /=; apply: filterS2 eq_fg => x eq_fg [y [fxy Py]].
by exists y; rewrite -eq_fg.
Qed.
(** ** Specific filters *)
Section at_point.
Context {T : Type}.
Definition at_point (a : T) (P : set T) : Prop := P a.
Global Instance at_point_filter (a : T) : ProperFilter (at_point a).
Proof. by constructor=> //; constructor=> // P Q subPQ /subPQ. Qed.
Typeclasses Opaque at_point.
End at_point.
(** Filters for pairs *)
Global Instance filter_prod_filter T U (F : set (set T)) (G : set (set U)) :
Filter F -> Filter G -> Filter (filter_prod F G).
Proof.
move=> FF FG; apply: filter_from_filter.
by exists (setT, setT); split; apply: filterT.
move=> [P Q] [P' Q'] /= [FP GQ] [FP' GQ'].
exists (P `&` P', Q `&` Q') => /=; first by split; apply: filterI.
by move=> [x y] [/= [??] []].
Qed.
Global Instance filter_prod_proper {T1 T2 : Type}
{F : (T1 -> Prop) -> Prop} {G : (T2 -> Prop) -> Prop}
{FF : ProperFilter F} {FG : ProperFilter G} :
ProperFilter (filter_prod F G).
Proof.
apply: filter_from_proper => -[A B] [/=FA GB].
by have [[x ?] [y ?]] := (filter_ex FA, filter_ex GB); exists (x, y).
Qed.
Definition filter_prod_proper' := @filter_prod_proper.
Lemma filter_prod1 {T U} {F : set (set T)} {G : set (set U)}
{FG : Filter G} (P : set T) :
(\forall x \near F, P x) -> \forall x \near F & _ \near G, P x.
Proof.
move=> FP; exists (P, setT)=> //= [|[?? []//]].
by split=> //; apply: filterT.
Qed.
Lemma filter_prod2 {T U} {F : set (set T)} {G : set (set U)}
{FF : Filter F} (P : set U) :
(\forall y \near G, P y) -> \forall _ \near F & y \near G, P y.
Proof.
move=> FP; exists (setT, P)=> //= [|[?? []//]].
by split=> //; apply: filterT.
Qed.
Program Definition in_filter_prod {T U} {F : set (set T)} {G : set (set U)}
(P : in_filter F) (Q : in_filter G) : in_filter (filter_prod F G) :=
@InFilter _ _ (fun x => prop_of P x.1 /\ prop_of Q x.2) _.
Next Obligation.
by exists (prop_of P, prop_of Q) => //=; split; apply: prop_ofP.
Qed.
Lemma near_pair {T U} {F : set (set T)} {G : set (set U)}
{FF : Filter F} {FG : Filter G}
(P : in_filter F) (Q : in_filter G) x :
prop_of P x.1 -> prop_of Q x.2 -> prop_of (in_filter_prod P Q) x.
Proof. by case: x=> x y; do ?rewrite prop_ofE /=; split. Qed.
Lemma flim_fst {T U F G} {FG : Filter G} :
(@fst T U) @ filter_prod F G --> F.
Proof. by move=> P; apply: filter_prod1. Qed.
Lemma flim_snd {T U F G} {FF : Filter F} :
(@snd T U) @ filter_prod F G --> G.
Proof. by move=> P; apply: filter_prod2. Qed.
Lemma near_map {T U} (f : T -> U) (F : set (set T)) (P : set U) :
(\forall y \near f @ F, P y) = (\forall x \near F, P (f x)).
Proof. by []. Qed.
Lemma near_map2 {T T' U U'} (f : T -> U) (g : T' -> U')
(F : set (set T)) (G : set (set T')) (P : U -> set U') :
Filter F -> Filter G ->
(\forall y \near f @ F & y' \near g @ G, P y y') =
(\forall x \near F & x' \near G , P (f x) (g x')).
Proof.
move=> FF FG; rewrite propeqE; split=> -[[A B] /= [fFA fGB] ABP].
exists (f @^-1` A, g @^-1` B) => //= -[x y /=] xyAB.
by apply: (ABP (_, _)); apply: xyAB.
exists (f @` A, g @` B) => //=; last first.
by move=> -_ [/= [x Ax <-] [x' Bx' <-]]; apply: (ABP (_, _)).
rewrite !locally_simpl /filtermap /=; split.
by apply: filterS fFA=> x Ax; exists x.
by apply: filterS fGB => x Bx; exists x.
Qed.
Lemma near_mapi {T U} (f : T -> set U) (F : set (set T)) (P : set U) :
(\forall y \near f `@ F, P y) = (\forall x \near F, exists y, f x y /\ P y).
Proof. by []. Qed.
(* Lemma filterSpair (T T' : Type) (F : set (set T)) (F' : set (set T')) : *)
(* Filter F -> Filter F' -> *)
(* forall (P : set T) (P' : set T') (Q : set (T * T')), *)
(* (forall x x', P x -> P' x' -> Q (x, x')) -> F P /\ F' P' -> *)
(* filter_prod F F' Q. *)
(* Proof. *)
(* move=> FF FF' P P' Q PQ [FP FP']; near=> x. *)
(* have := PQ x.1 x.2; rewrite -surjective_pairing; apply; near: x; *)
(* by [apply: flim_fst|apply: flim_snd]. *)
(* Grab Existential Variables. all: end_near. Qed. *)
Lemma filter_pair_near_of (T T' : Type) (F : set (set T)) (F' : set (set T')) :
Filter F -> Filter F' ->
forall (P : @in_filter T F) (P' : @in_filter T' F') (Q : set (T * T')),
(forall x x', prop_of P x -> prop_of P' x' -> Q (x, x')) ->
filter_prod F F' Q.
Proof.
move=> FF FF' [P FP] [P' FP'] Q PQ; rewrite prop_ofE in FP FP' PQ.
near=> x; have := PQ x.1 x.2; rewrite -surjective_pairing; apply; near: x;
by [apply: flim_fst|apply: flim_snd].
Grab Existential Variables. all: end_near. Qed.
Tactic Notation "near=>" ident(x) ident(y) :=
(apply: filter_pair_near_of => x y ? ?).
Tactic Notation "near" constr(F) "=>" ident(x) ident(y) :=
apply: (have_near F); near=> x y.
Module Export NearMap.
Definition near_simpl := (@near_simpl, @near_map, @near_mapi, @near_map2).
Ltac near_simpl := rewrite ?near_simpl.
End NearMap.
Lemma flim_pair {T U V F} {G : set (set U)} {H : set (set V)}
{FF : Filter F} {FG : Filter G} {FH : Filter H} (f : T -> U) (g : T -> V) :
f @ F --> G -> g @ F --> H ->
(f x, g x) @[x --> F] --> (G, H).
Proof.
move=> fFG gFH P; rewrite !near_simpl => -[[A B] /=[GA HB] ABP]; near=> x.
by apply: (ABP (_, _)); split=> //=; near: x; [apply: fFG|apply: gFH].
Grab Existential Variables. all: end_near. Qed.
Lemma flim_comp2 {T U V W}
{F : set (set T)} {G : set (set U)} {H : set (set V)} {I : set (set W)}
{FF : Filter F} {FG : Filter G} {FH : Filter H}
(f : T -> U) (g : T -> V) (h : U -> V -> W) :
f @ F --> G -> g @ F --> H ->
h (fst x) (snd x) @[x --> (G, H)] --> I ->
h (f x) (g x) @[x --> F] --> I.
Proof. by move=> fFG gFH hGHI P /= IP; apply: flim_pair (hGHI _ IP). Qed.
Arguments flim_comp2 {T U V W F G H I FF FG FH f g h} _ _ _.
Definition flim_comp_2 := @flim_comp2.