-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnsembles_util.v
1898 lines (1582 loc) · 53.1 KB
/
Ensembles_util.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
(* Ensemble library utilities. Part of the CertiCoq project.
* Author: Zoe Paraskevopoulou, 2016
*)
From Coq Require Import Classes.Morphisms Arith NArith.BinNat Lists.List Sets.Ensembles Sorting.Permutation.
From SFS Require Import Coqlib.
Import ListNotations.
Close Scope Z_scope.
Ltac inv H := inversion H; clear H; subst.
Hint Constructors Singleton.
Hint Constructors Union.
Hint Constructors Intersection.
Hint Unfold In.
Create HintDb Ensembles_DB.
(** * Usefull notations. Inspired from https://github.com/QuickChick/QuickChick/blob/master/src/Sets.v *)
Notation "x \in A" := (Ensembles.In _ A x) (at level 70, only parsing) : Ensembles_scope.
Infix "<-->" := (Ensembles.Same_set _) (at level 70, no associativity) : Ensembles_scope.
Infix "\subset" := (Ensembles.Included _) (at level 70, no associativity) : Ensembles_scope.
Open Scope Ensembles_scope.
Notation "[ 'set' x : T | P ]" := (fun x : T => P)
(at level 0, x at level 99, only parsing) : Ensembles_scope.
Notation "[ 'set' x | P ]" := [set x : _ | P]
(at level 0, x, P at level 99, format "[ 'set' x | P ]", only parsing) : Ensembles_scope.
Notation "[ 'set' a ]" := (Ensembles.Singleton _ a)
(at level 0, a at level 99, format "[ 'set' a ]") : Ensembles_scope.
Notation "[ 'set' a : T ]" := [set (a : T)]
(at level 0, a at level 99, format "[ 'set' a : T ]") : Ensembles_scope.
Notation "A :|: B" := (Union _ A B) (at level 52, left associativity)
: Ensembles_scope.
Notation "a |: A" := ([set a] :|: A) (at level 52, left associativity)
: Ensembles_scope.
Notation "A :&: B" := (Intersection _ A B) (at level 48, left associativity)
: Ensembles_scope.
Notation "a &: B" := (Intersection _ [set a] B) (at level 48, left associativity)
: Ensembles_scope.
Notation "A \\ B" := (Setminus _ A B) (at level 52, left associativity)
: Ensembles_scope.
(** * Equivalence and preorder properties *)
Lemma Included_refl {A} (s1 : Ensemble A) :
s1 \subset s1.
Proof.
intros x Hin; eauto.
Qed.
Lemma Included_trans {A} (s1 s2 s3 : Ensemble A) :
s1 \subset s2 ->
s2 \subset s3 ->
s1 \subset s3.
Proof.
intros H1 H2 x HIn.
eapply H2. eapply H1; eauto.
Qed.
Instance PreOrder_Included {A} : PreOrder (@Included A).
Proof.
constructor.
now apply Included_refl.
intros ? ? ? ? ?. now eapply Included_trans; eauto.
Qed.
Lemma Same_set_refl A (s : Ensemble A) :
s <--> s.
Proof.
split; apply Included_refl.
Qed.
Lemma Same_set_sym A (s1 s2 : Ensemble A) :
s1 <--> s2 ->
s2 <--> s1.
Proof.
intros [H1 H2]; split; eauto.
Qed.
Lemma Same_set_trans {A} (s1 s2 s3 : Ensemble A) :
s1 <--> s2 ->
s2 <--> s3 ->
s1 <--> s3.
Proof.
intros [H1 H2] [H3 H4]. split; eapply Included_trans; eauto.
Qed.
Instance Equivalence_Same_set {A} : Equivalence (@Same_set A).
Proof.
constructor.
now apply Same_set_refl.
intros ? ? ?. now eapply Same_set_sym.
intros ? ? ? ? ?. now eapply Same_set_trans; eauto.
Qed.
Hint Immediate Same_set_refl Included_refl : Ensembles_DB.
Ltac edb := eauto with Ensembles_DB.
(** * Decidability instances *)
Class Decidable {A} (S : Ensemble A) : Type :=
{ Dec : forall x, { S x } + {~ S x} }.
Instance Decidable_Union {A} (S1 S2 : Ensemble A)
{H1 : Decidable S1} {H2 : Decidable S2} : Decidable (Union A S1 S2).
Proof.
constructor. intros x.
edestruct (@Dec _ _ H1 x); try now left; constructor.
edestruct (@Dec _ _ H2 x); try now left; constructor.
right. intros Hun. inv Hun; eauto.
Qed.
Instance Decidable_Intersection {A} (S1 S2 : Ensemble A)
{H1 : Decidable S1} {H2 : Decidable S2} : Decidable (Intersection A S1 S2).
Proof.
constructor. intros x.
edestruct (@Dec _ _ H1 x); edestruct (@Dec _ _ H2 x);
try (now left; constructor); right; intros Hc; inv Hc; eauto.
Qed.
Instance Decidable_Setminus {A} s1 s2 { H1 : Decidable s1 }
{ H2 : Decidable s2 } : Decidable (Setminus A s1 s2).
Proof.
constructor. intros x. destruct H1, H2. destruct (Dec1 x).
- right. intros Hc. inv Hc; eauto.
- destruct (Dec0 x). left. constructor; eauto.
right. intros Hc. inv Hc. eauto.
Qed.
(** $\{x\}$ is decidable. TODO : generalize the type *)
Instance DecidableSingleton_positive x : Decidable (Singleton positive x).
Proof.
constructor. intros x'.
destruct (peq x x'); subst. left; constructor.
right. intros Hc. inv Hc; eauto.
Qed.
(** TODO make it proper? *)
Lemma Decidable_Same_set A (S1 S2 : Ensemble A) :
S1 <--> S2 ->
Decidable S1 ->
Decidable S2.
Proof.
intros Heq Hdec. constructor. intros x.
destruct Hdec as [Dec]. destruct (Dec x) as [Hin | Hnin].
left; eapply Heq; eauto.
right; intros Hc; eapply Hnin; eapply Heq; eauto.
Qed.
(** * Proper instances *)
Instance Proper_Union_l A :
Proper (Same_set A ==> Logic.eq ==> Same_set A)
(Union A).
Proof.
constructor; subst; intros x' H'; destruct H'; destruct H as [H1 H2]; eauto.
Qed.
Instance Proper_Union_r A :
Proper (Logic.eq ==> Same_set A ==> Same_set A)
(Union A).
Proof.
constructor; subst; intros x' H'; destruct H'; destruct H0 as [H1 H2]; eauto.
Qed.
Instance Proper_Setminus_l A :
Proper (Same_set A ==> Logic.eq ==> Same_set A)
(Setminus A).
Proof.
constructor; intros x' H'; destruct H as [H1 H2];
inv H'; constructor; eauto.
Qed.
Instance Proper_Setminus_r A :
Proper (Logic.eq ==> Same_set A ==> Same_set A)
(Setminus A).
Proof.
constructor; intros x' H'; destruct H0 as [H1 H2];
inv H'; constructor; eauto.
Qed.
Instance Proper_Intersection_l A :
Proper (Same_set A ==> Logic.eq ==> Same_set A)
(Intersection A).
Proof.
constructor; subst; intros x' H'; destruct H'; constructor; firstorder.
Qed.
Instance Proper_Intersection_r A :
Proper (Logic.eq ==> Same_set A ==> Same_set A)
(Intersection A).
Proof.
constructor; subst; intros x' H'; destruct H'; constructor; firstorder.
Qed.
Instance Proper_Disjoint_l A :
Proper (Same_set A ==> Logic.eq ==> iff)
(Disjoint A).
Proof.
constructor; subst; intros H'; destruct H as [H1 H2]; inv H';
constructor; intros x' HIn; inv HIn; eapply H; constructor; eauto.
Qed.
Instance Proper_Disjoint_r A :
Proper (Logic.eq ==> Same_set A ==> iff)
(Disjoint A).
Proof.
constructor; subst; intros H'; destruct H0 as [H1 H2]; inv H';
constructor; intros x' HIn; inv HIn; eapply H; constructor; eauto.
Qed.
Instance Proper_In {A} :
Proper (Same_set A ==> Logic.eq ==> iff) (In A).
Proof.
constructor; intros H'; subst; destruct H as [H1 H2]; eauto.
Qed.
Instance Proper_Included_l A :
Proper (Same_set A ==> Logic.eq ==> iff)
(Included A).
Proof.
constructor; subst; intros H'; destruct H as [H1 H2];
intros x' HIn; eauto.
Qed.
Instance Proper_Included_r A :
Proper (Logic.eq ==> Same_set A ==> iff)
(Included A).
Proof.
constructor; subst; intros H'; destruct H0 as [H1 H2];
intros x' HIn; eauto.
Qed.
Instance Proper_Same_set_l A :
Proper (Same_set A ==> Logic.eq ==> iff)
(Same_set A).
Proof.
constructor; subst; intros H'; destruct H as [H1 H2]; destruct H' as [H3 H4];
constructor; eauto; eapply Included_trans; eauto.
Qed.
Instance Proper_Same_set_r A :
Proper (Logic.eq ==> Same_set A ==> iff)
(Same_set A).
Proof.
constructor; subst; intros H'; destruct H0 as [H1 H2]; destruct H' as [H3 H4];
constructor; eauto; eapply Included_trans; eauto.
Qed.
Instance Complement_Proper {A : Type} : Proper (Same_set A ==> Same_set A) (Complement A).
Proof.
intros s1 s2 [Hin1 Hin2]; split; intros x Hc Hc'; eapply Hc; eauto.
Qed.
(** * Useful definitions and lemmas *)
(** ** Commutativity properties *)
Lemma Union_commut {A} (s1 s2 : Ensemble A) :
(s1 :|: s2) <--> (s2 :|: s1).
Proof.
split; intros x H; inv H; eauto.
Qed.
Lemma Intersection_commut {A} (s1 s2 : Ensemble A) :
Same_set A (Intersection A s2 s1) (Intersection A s1 s2).
Proof.
split; intros x H; inv H; constructor; eauto.
Qed.
Lemma Disjoint_sym {A} s1 s2 :
Disjoint A s2 s1 -> Disjoint A s1 s2.
Proof.
intros H. inv H.
constructor. intros x HIn. inv HIn.
eapply H0; eauto.
Qed.
Hint Immediate Union_commut Intersection_commut : Ensembles_DB.
(** ** Associativity properties *)
Lemma Union_assoc {A} s1 s2 s3 :
Same_set A (Union A s1 (Union A s2 s3))
(Union A (Union A s1 s2) s3).
Proof.
split; intros x HIn; inv HIn; eauto; inv H; eauto.
Qed.
Lemma Intersection_assoc {A} s1 s2 s3 :
Same_set A (Intersection A s1 (Intersection A s2 s3))
(Intersection A (Intersection A s1 s2) s3).
Proof.
split; intros x HIn; inv HIn.
inv H0. now eauto.
inv H. now eauto.
Qed.
Hint Immediate Union_assoc Intersection_assoc : Ensembles_DB.
(** ** Distributitvity properties *)
Lemma Setminus_Union_distr {A} s1 s2 s3 :
Same_set A (Setminus A (Union A s1 s2) s3)
(Union A (Setminus A s1 s3) (Setminus A s2 s3)).
Proof.
split; intros x H; inv H; inv H0;
try (now try left; constructor; eauto);
now right; constructor; eauto.
Qed.
Lemma Union_Intersection_distr {A} s1 s2 s3:
Same_set A (Union A (Intersection A s1 s2) s3)
(Intersection A (Union A s1 s3) (Union A s2 s3)).
Proof.
split; intros x H; inv H; eauto.
inv H0. now eauto.
now inv H0; inv H1; eauto.
Qed.
Lemma Intersection_Union_distr :
forall (A : Type) (s1 s2 s3 : Ensemble A),
(s1 :|: s2) :&: s3 <--> (s1 :&: s3) :|: (s2 :&: s3).
Proof.
intros A s1 s2 s3.
split; intros x.
- intros [H1 H2]. inv H2; eauto.
- intros Hin. inv Hin; eauto; inv H; eauto.
Qed.
Lemma Intersection_Disjoint :
forall (A : Type) (s1 s2 : Ensemble A),
Disjoint _ s1 s2 ->
s1 :&: s2 <--> Empty_set _.
Proof.
intros A s1 s2 Hd.
split; intros x.
- intros H1; inv H1. exfalso; eapply Hd; eauto.
- intros Hc; inv Hc.
Qed.
Lemma Intersection_Setmius_Disjoint {A} (S1 S2 S3 : Ensemble A) :
Disjoint _ S2 S3 ->
(S1 \\ S2) :&: S3 <--> S1 :&: S3.
Proof.
intros Hd. split.
- intros x Hin. inv Hin. inv H. constructor; eauto.
- intros x Hin. inv Hin. constructor; eauto.
constructor. eassumption. intros Hc. eapply Hd; constructor; eauto.
Qed.
Lemma Intersection_Setmius_Setminus_Disjoint {A} (S1 S2 S3 S4 : Ensemble A) :
Disjoint _ S3 S4 ->
(S1 \\ (S2 \\ S4)) :&: S3 <--> (S1 \\ S2) :&: S3.
Proof.
intros Hd. split.
- intros x Hin. inv Hin. inv H. constructor; eauto. constructor; eauto.
intros Hc. eapply H2; eauto. constructor. eassumption.
intros Hc'. eapply Hd; constructor; eauto.
- intros x Hin. inv Hin. constructor; eauto. inv H.
constructor. eassumption. intros Hc. eapply Hd; constructor; eauto.
inv Hc. exfalso; eauto.
Qed.
Hint Immediate Setminus_Union_distr Union_Intersection_distr : Ensembles_DB.
(** ** Compatibility properties *)
Lemma Included_Union_compat {A} s1 s1' s2 s2' :
Included A s1 s2 ->
Included A s1' s2' ->
Included A (Union A s1 s1') (Union A s2 s2').
Proof.
intros H1 H2 x Hin. inv Hin; eauto.
Qed.
Lemma Same_set_Union_compat {A} s1 s1' s2 s2' :
Same_set A s1 s2 ->
Same_set A s1' s2' ->
Same_set A (Union A s1 s1') (Union A s2 s2').
Proof.
intros [H1 H2] [H3 H4].
split; apply Included_Union_compat; eauto.
Qed.
Lemma Included_Setminus_compat {A} s1 s1' s2 s2' :
Included A s1 s2 ->
Included A s2' s1' ->
Included A (Setminus A s1 s1') (Setminus A s2 s2').
Proof.
intros H1 H2 x H; inv H; constructor; eauto.
Qed.
Lemma Same_set_Setminus_compat {A} s1 s1' s2 s2' :
Same_set A s1 s2 ->
Same_set A s1' s2' ->
Same_set A (Setminus A s1 s1') (Setminus A s2 s2').
Proof.
intros [H1 H2] [H3 H4].
split; apply Included_Setminus_compat; eauto.
Qed.
Lemma Setminus_Intersection_distr {A} (S1 S2 S3 : Ensemble A) :
(S1 :&: S2) \\ S3 <--> (S1 \\ S3) :&: (S2 \\ S3).
Proof.
split; intros x H1.
inv H1. inv H. constructor; constructor; eauto.
inv H1. inv H; inv H0. constructor; eauto.
Qed.
Hint Resolve Included_Union_compat Same_set_Union_compat
Included_Setminus_compat Same_set_Setminus_compat : Ensembles_DB.
(** ** [Empty_set] is neutral *)
Lemma Union_Empty_set_neut_r {A} s:
Same_set A (Union A s (Empty_set A)) s.
Proof.
split; intros x H; eauto. inv H; eauto. inv H0.
Qed.
Lemma Union_Empty_set_neut_l (A : Type) (s : Ensemble A):
Same_set A (Union A (Empty_set A) s) s.
Proof.
split; intros x H; try inv H; eauto. inv H0.
Qed.
Lemma Setminus_Empty_set_neut_r {A} s :
Same_set A (Setminus A s (Empty_set A)) s.
Proof.
split; intros x H; try inv H; eauto.
constructor; eauto. intros H'; inv H'.
Qed.
Hint Immediate Union_Empty_set_neut_r Union_Empty_set_neut_l
Setminus_Empty_set_neut_r : Ensembles_DB.
(** ** [Empty_set] is absorbing *)
Lemma Intersection_Empty_set_abs_r {A} s:
Same_set A (Intersection A s (Empty_set A)) (Empty_set A).
Proof.
split; intros x H; eauto; inv H; eauto.
Qed.
Lemma Intersection_Empty_set_abs_l {A} s:
Same_set A (Intersection A (Empty_set A) s) (Empty_set A).
Proof.
split; intros x H; eauto; inv H; eauto.
Qed.
Lemma Setminus_Empty_set_abs_r {A} s :
Same_set A (Setminus A (Empty_set A) s) (Empty_set _).
Proof.
split; intros x H; inv H; eauto.
Qed.
Hint Immediate Intersection_Empty_set_abs_r Intersection_Empty_set_abs_l
Setminus_Empty_set_abs_r : Ensembles_DB.
(** ** Idemptotency properties *)
Lemma Union_idempotent {A} s :
Same_set A (Union _ s s) s.
Proof.
split; intros x H; eauto.
inv H; eauto.
Qed.
Lemma Intersection_idempotent {A} s :
Same_set A (Intersection _ s s) s.
Proof.
split; intros x H; eauto.
inv H; eauto.
Qed.
Hint Immediate Union_idempotent Intersection_idempotent : Ensembles_DB.
(** ** De Morgan's laws *)
Lemma Union_DeMorgan {A} s1 s2 :
Same_set A (Complement _ (Union _ s1 s2))
(Intersection _ (Complement _ s1) (Complement _ s2)).
Proof.
split; intros x H.
now constructor; intros Hc; eauto.
inv H. intros Hc; inv Hc; eauto.
Qed.
Lemma Intersection_DeMorgan {A} s1 s2 :
Decidable s1 ->
Same_set A (Complement _ (Intersection _ s1 s2))
(Union _ (Complement _ s1) (Complement _ s2)).
Proof.
intros Hdec. split; intros x H.
destruct Hdec. destruct (Dec0 x); eauto.
right. intros Hc. eapply H. constructor; eauto.
inv H; intros Hc; inv Hc; eauto.
Qed.
Lemma Intersection_DeMorgan' {A} s1 s2 :
Decidable s2 ->
Same_set A (Complement _ (Intersection _ s1 s2))
(Union _ (Complement _ s1) (Complement _ s2)).
Proof.
intros Hdec. split; intros x H.
destruct Hdec. destruct (Dec0 x); eauto.
left. intros Hc. eapply H. constructor; eauto.
inv H; intros Hc; inv Hc; eauto.
Qed.
Hint Immediate Union_DeMorgan : Ensembles_DB.
(** ** Complement is involutive *)
Lemma Complement_involutive_l {A} s :
Included A s (Complement _ (Complement _ s)).
Proof.
intros x H Hc. eauto.
Qed.
Lemma Complement_involutive_r {A} s :
Decidable s ->
Included A (Complement _ (Complement _ s)) s.
Proof.
intros Hdec x H. destruct Hdec. destruct (Dec0 x); eauto.
exfalso; eauto.
Qed.
Hint Immediate Complement_involutive_l : Ensembles_DB.
(** ** Inclusion properties *)
Lemma Included_Empty_set {A} s :
Included A (Empty_set A) s.
Proof.
intros x H. inv H.
Qed.
Lemma Included_Union_l {A} s1 s2 :
Included A s1 (Union A s1 s2).
Proof.
intros x HIn. constructor. eauto.
Qed.
Lemma Included_Union_r {A} s1 s2 :
Included A s2 (Union A s1 s2).
Proof.
intros x HIn. constructor 2. eauto.
Qed.
Lemma Union_Included_l {A} S1 S2 S3 :
Union A S1 S2 \subset S3 ->
S1 \subset S3.
Proof.
firstorder.
Qed.
Lemma Union_Included_r {A} S1 S2 S3 :
Union A S1 S2 \subset S3 ->
S2 \subset S3.
Proof.
firstorder.
Qed.
Lemma Included_Union_preserv_l {A} s1 s2 s3 :
Included A s1 s2 ->
Included A s1 (Union A s2 s3).
Proof.
intros H x H'. left; eauto.
Qed.
Lemma Included_Union_preserv_r {A} s1 s2 s3 :
Included A s1 s3 ->
Included A s1 (Union A s2 s3).
Proof.
intros H x H'. right; eauto.
Qed.
Lemma Setminus_Included_Included_Union {A} s1 s2 s3 :
Included A s1 (Union _ s2 s3) ->
Included A (Setminus _ s1 s3) s2.
Proof.
intros H x Hm; inv Hm.
eapply H in H0. inv H0; try contradiction.
eassumption.
Qed.
Lemma Setminus_Included {A} s1 s2 :
Included A (Setminus A s1 s2) s1.
Proof.
intros x HIn. inv HIn. eauto.
Qed.
Lemma Setminus_Included_preserv {A} s1 s2 s3 :
Included A s1 s3 ->
Included A (Setminus A s1 s2) s3.
Proof.
intros Hin1 x Hin2. inv Hin2. eauto.
Qed.
Lemma Union_Included {A} S1 S2 S :
Included A S1 S ->
Included A S2 S ->
Included A (Union A S1 S2) S.
Proof.
intros H1 H2 x Hin; inv Hin; eauto.
Qed.
Lemma Singleton_Included {A} x S :
In A S x ->
Included A (Singleton A x) S.
Proof.
intros H x' Hin; inv Hin; eauto.
Qed.
Lemma Singleton_Included_r {A : Type} (x : A) (S : Ensemble A) :
[set x] \subset S -> In A S x.
Proof.
firstorder.
Qed.
Lemma Included_Setminus {A} s1 s2 s3:
Disjoint A s1 s3 ->
Included A s1 s2 ->
Included A s1 (Setminus A s2 s3).
Proof.
intros Hd Hin x H. constructor; eauto.
intros Hc. eapply Hd; eauto.
Qed.
Lemma Included_Union_Setminus_Included_Union {A} s1 s2 s3 s4 :
Decidable s3 ->
Included A s3 s4 ->
Included A s1 (Union _ s2 s4) ->
Included A s1 (Union _ (Setminus A s2 s3) s4).
Proof.
intros Hd Hin Hin' x H. eapply Hin' in H. inv H; eauto.
destruct Hd as [D]. destruct (D x); eauto.
left; constructor; eauto.
Qed.
Hint Immediate Included_Empty_set Included_Union_l Included_Union_r
Setminus_Included : Ensembles_DB.
Hint Resolve Included_Union_preserv_l Included_Union_preserv_r Setminus_Included_preserv
Setminus_Included_Included_Union Union_Included Singleton_Included
Included_Setminus Included_Union_Setminus_Included_Union : Ensembles_DB.
(** ** Disjoint properties *)
Lemma Disjoint_Setminus_l {A} s1 s2 s3 :
Included A s3 s2 ->
Disjoint A (Setminus A s1 s2) s3.
Proof.
intros Hincl.
constructor. intros x HIn. inv HIn. inv H.
apply H2. apply Hincl in H0; eauto.
Qed.
Lemma Disjoint_Setminus_r {A} s1 s2 s3 :
Included A s1 s3 ->
Disjoint A s1 (Setminus A s2 s3).
Proof.
intros Hincl.
constructor. intros x HIn. inv HIn. inv H0.
apply H2. eauto.
Qed.
Lemma Disjoint_Empty_set_l {A} s :
Disjoint A (Empty_set A) s.
Proof.
constructor. intros x Hin. inv Hin. inv H.
Qed.
Lemma Disjoint_Empty_set_r {A} s :
Disjoint A s (Empty_set A).
Proof.
constructor. intros x Hin. inv Hin. inv H0.
Qed.
Lemma Disjoint_Union_l {A} s1 s2 s3 :
Disjoint A (Union A s1 s2) s3 ->
Disjoint A s1 s3.
Proof.
intros H. inv H.
constructor. intros x Hin. inv Hin. eapply H0; eauto.
Qed.
Lemma Disjoint_Union_r {A} s1 s2 s3 :
Disjoint A (Union A s1 s2) s3 ->
Disjoint A s2 s3.
Proof.
intros H. inv H.
constructor. intros x Hin. inv Hin. eapply H0; eauto.
Qed.
Lemma Disjoint_Included_l {A} s1 s2 s3 :
Included A s1 s3 ->
Disjoint A s3 s2 ->
Disjoint A s1 s2.
Proof.
intros H1 H2. inv H2. constructor. intros x Hin.
inv Hin. eapply H; eauto.
Qed.
Lemma Disjoint_Included_l_sym {A} s1 s2 s3 :
Included A s1 s3 ->
Disjoint A s2 s3 ->
Disjoint A s1 s2.
Proof.
intros H1 H2. inv H2. constructor. intros x Hin.
inv Hin. eapply H; eauto.
Qed.
Lemma Disjoint_Included_r_sym {A} s1 s2 s3 :
Included A s3 s2 ->
Disjoint A s2 s1 ->
Disjoint A s1 s3.
Proof.
intros H1 H2. inv H2. constructor. intros x Hin.
inv Hin. eapply H; eauto.
Qed.
Lemma Disjoint_Included_r {A} s1 s2 s3 :
Included A s3 s2 ->
Disjoint A s1 s2 ->
Disjoint A s1 s3.
Proof.
intros H1 H2. inv H2. constructor. intros x Hin.
inv Hin. eapply H; eauto.
Qed.
Lemma Disjoint_Included A s1 s2 s3 s4 :
Included A s4 s2 ->
Included A s3 s1 ->
Disjoint A s1 s2 ->
Disjoint A s3 s4.
Proof.
intros H1 H2 HD. inv HD. constructor. intros x H'.
inv H'. eapply H; constructor; eauto.
Qed.
Lemma Disjoint_Singleton_r {A} s x :
~ In _ s x ->
Disjoint A s (Singleton A x).
Proof.
intros H. constructor. intros x' Hin. inv Hin. inv H1. contradiction.
Qed.
Lemma Disjoint_Singleton_l {A} s x :
~ Ensembles.In _ s x ->
Disjoint A (Singleton A x) s.
Proof.
intros H. constructor. intros x' Hin. inv Hin. inv H0. contradiction.
Qed.
Lemma Union_Disjoint_l A s1 s2 s3 :
Disjoint A s1 s3 ->
Disjoint A s2 s3 ->
Disjoint A (Union A s1 s2) s3.
Proof.
intros H1 H2. constructor. intros x H. inv H.
inv H0. eapply H1; eauto.
eapply H2; eauto.
Qed.
Lemma Union_Disjoint_r A s1 s2 s3 :
Disjoint A s1 s2 ->
Disjoint A s1 s3 ->
Disjoint A s1 (Union A s2 s3).
Proof.
intros H1 H2. constructor. intros x H. inv H.
inv H3. eapply H1; eauto.
eapply H2; eauto.
Qed.
Lemma Setminus_Disjoint_preserv_l {A} s1 s2 s3:
Disjoint A s1 s3 ->
Disjoint A (Setminus A s1 s2) s3.
Proof.
intros Hd. constructor; intros x H. inv H.
inv H0. eapply Hd; eauto.
Qed.
Lemma Setminus_Disjoint_preserv_r {A} s1 s2 s3:
Disjoint A s1 s2 ->
Disjoint A s1 (Setminus A s2 s3).
Proof.
intros Hd. constructor; intros x H. inv H.
inv H1. eapply Hd; eauto.
Qed.
Lemma Union_Same_set_Disjoint {A} (S1 S2 S3 : Ensemble A) :
S1 :|: S2 <--> S1 :|: S3 ->
Disjoint _ S1 S2 ->
Disjoint _ S1 S3 ->
S2 <--> S3.
Proof.
intros Heq HD HD'. split; intros x Hin.
- assert (Hin' : (S1 :|: S3) x).
{ eapply Heq. now right. }
inv Hin'; eauto.
exfalso. eapply HD; eauto.
- assert (Hin' : (S1 :|: S2) x).
{ eapply Heq. now right. }
inv Hin'; eauto.
exfalso. eapply HD'; eauto.
Qed.
Hint Resolve Disjoint_Setminus_l Disjoint_Setminus_r Union_Disjoint_l
Union_Disjoint_r Disjoint_Singleton_l Disjoint_Singleton_r
Setminus_Disjoint_preserv_l Setminus_Disjoint_preserv_r : Ensembles_DB.
Hint Immediate Disjoint_Empty_set_l Disjoint_Empty_set_r : Ensembles_DB.
(** ** Set difference properties *)
Lemma Union_Setminus {A} S1 S2 {Hdec: Decidable S2 } :
Same_set A (Union A S1 S2) (Union A (Setminus A S1 S2) S2).
Proof.
split; intros x H; inv H; try (now constructor).
edestruct (Dec x); try (now constructor).
inv H0. constructor; eauto.
Qed.
Lemma Setminus_Same_set_Empty_set {A} s:
Same_set A (Setminus A s s) (Empty_set A).
Proof.
split; intros x H; inv H; contradiction.
Qed.
Lemma Setminus_Union {A} s1 s2 s3:
Same_set A (Setminus A (Setminus A s1 s2) s3)
(Setminus A s1 (Union A s2 s3)).
Proof.
split; intros x H'; inv H'. inv H.
constructor; eauto. intros Hc; inv Hc; eauto.
constructor; eauto. constructor; eauto.
Qed.
Lemma Union_Setminus_Same_set {A} (S1 S2 : Ensemble A) {HD : Decidable S2} :
S2 \subset S1 ->
S1 <--> S2 :|: (S1 \\ S2).
Proof.
intros Heq. split; intros x Hin.
- destruct HD. destruct (Dec0 x).
+ now left.
+ right. constructor; eauto.
- inv Hin; eauto. inv H; eauto.
Qed.
Lemma Union_Setminus_Included {A} s1 s2 s3:
Decidable s3 ->
Included A s3 s1 ->
Same_set A (Union A s1 (Setminus A s2 s3))
(Union A s1 s2).
Proof.
intros Hdec H.
split; intros x H'; inv H'; eauto.
inv H0; eauto.
destruct Hdec. destruct (Dec0 x); eauto.
right. constructor; eauto.
Qed.
Lemma Setminus_Included_Empty_set_r {A} s1 s2 :
Included A s1 s2 ->
Included A (Setminus A s1 s2) (Empty_set A).
Proof.
intros H1 x H; inv H. apply H1 in H0. contradiction.
Qed.
Lemma Setminus_Disjoint {A} s1 s2 :
Disjoint A s1 s2 ->
Same_set A (Setminus A s1 s2) s1.
Proof.
intros D; split; inv D; intros x H'; try inv H'; eauto.
constructor; eauto. intros Hc. eapply H; eauto.
Qed.
Lemma Union_Setminus_Setminus_Union {A} s1 s2 s3 :
Decidable s3 ->
Same_set A (Union A (Setminus A s1 s2) s3)
(Setminus A (Union A s1 s3) (Setminus A s2 s3)).
Proof.
intros Hdec.
rewrite Setminus_Union_distr.
rewrite (Setminus_Disjoint s3);
eauto using Disjoint_sym, Disjoint_Setminus_l, Included_refl.
split; intros x H; inv H; eauto; inv H0. constructor. constructor; eauto.
intros Hc. inv Hc; eauto.
destruct (@Dec _ _ Hdec x); eauto.
left. constructor; eauto. intros Hc. apply H1; constructor; eauto.
Qed.
Lemma Included_Union_Setminus {A} s1 s2:
Decidable s2 ->
Included A s1 (Union A (Setminus A s1 s2) s2).
Proof.
intros Hdec x H. destruct (@Dec _ _ Hdec x); eauto.
left; eauto. constructor; eauto.
Qed.
Lemma Union_Included_Union_Setminus {A} s1 s2 s3 :
Decidable s3 ->
Included _ s3 s2 ->
Same_set A (Union _ s1 s2) (Union A (Setminus A s1 s3) s2).
Proof.
intros Hdec HIn. split; intros x H.
- destruct (@Dec _ _ Hdec x); eauto. inv H; eauto.
left; eauto. constructor; eauto.
- inv H; eauto. inv H0; eauto.
Qed.
Lemma Setminus_Included_Empty_set {A} s1 s2 :
Included A s1 s2 ->
Same_set A (Setminus A s1 s2) (Empty_set A).
Proof.
intros H; split; intros x H'; inv H'. exfalso; eauto.
Qed.
Lemma Setminus_Union_Included {A} s1 s2 s3 :
Included A s2 s3 ->
Same_set A (Setminus _ (Union _ s1 s2) s3) (Setminus _ s1 s3).
Proof.
intros H.
rewrite Setminus_Union_distr.
rewrite (Setminus_Included_Empty_set s2 s3); eauto.
now rewrite (Union_Empty_set_neut_r).
Qed.
Lemma Setminus_Included_mon {A} s1 s2 s2' s3 :
Included A (Setminus A s1 s2) s3 ->
Included A s2 s2' ->
Included A (Setminus A s1 s2') s3.
Proof.
intros H1 H2 x Hin. inv Hin. eapply H1. constructor; eauto.
Qed.
Lemma Included_Setminus_antimon {A} (s1 s1' s2 s3 : Ensemble A) :
Included A (Setminus A s1 s2) s3 ->
Included A s1' s1 ->
Included A (Setminus A s1' s2) s3.
Proof.
intros H H1 x H2.
eapply H. inv H2. constructor; eauto.
Qed.
Lemma Included_Setminus_Disjoint {A} s1 s2 :
Disjoint _ s1 s2 ->
Same_set A s1 (Setminus _ s1 s2).
Proof.
intros Hd.
split; intros x H. constructor; eauto. intros Hc; eapply Hd; eauto.
inv H; eauto.
Qed.
Lemma Setminus_Included_Empty_set_l {A} s1 s2 :
Decidable s2 ->
Included A (Setminus A s1 s2) (Empty_set A) ->
Included A s1 s2.
Proof.
intros Hdec H1 x H.
destruct (@Dec _ _ Hdec x); eauto.
exfalso.
assert (Hsuff : Empty_set _ x) by (eapply H1; constructor; eauto).
inv Hsuff.
Qed.
Hint Immediate Setminus_Same_set_Empty_set Setminus_Union : Ensembles_DB.
Hint Resolve Setminus_Disjoint Setminus_Included_Empty_set
Setminus_Union_Included Included_Setminus_Disjoint : Ensembles_DB.
(** ** Other properties *)
Lemma Union_Same_set {A} s1 s2 :
Included A s1 s2 ->