forked from vafeiadis/hahn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HahnEquational.v
1711 lines (1324 loc) · 49.3 KB
/
HahnEquational.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
(******************************************************************************)
(** * Equational properties of relations *)
(******************************************************************************)
Require Import Program.Basics Arith micromega.Lia Permutation List Setoid.
Require Import HahnBase HahnList HahnRelationsBasic HahnSets.
Set Implicit Arguments.
Local Open Scope program_scope.
(******************************************************************************)
(** Set up setoid rewriting *)
(******************************************************************************)
Global Hint Unfold Basics.impl : unfolderDb.
Local Ltac u := autounfold with unfolderDb in *; splits; ins; desf;
try solve [intuition; desf; eauto].
(** First, for inclusion. *)
Add Parametric Relation (A : Type) : (relation A) (@inclusion A)
reflexivity proved by (@inclusion_refl _)
transitivity proved by (@inclusion_trans _)
as inclusion_rel.
Add Parametric Morphism A : (@inclusion A) with signature
inclusion --> inclusion ++> Basics.impl as inclusion_mori.
Proof. u. Qed.
Add Parametric Morphism A : (@union A) with signature
inclusion ==> inclusion ==> inclusion as union_mori.
Proof. u. Qed.
Add Parametric Morphism A : (@inter_rel A) with signature
inclusion ==> inclusion ==> inclusion as inter_rel_mori.
Proof. u. Qed.
Add Parametric Morphism A : (@minus_rel A) with signature
inclusion ++> inclusion --> inclusion as minus_rel_mori.
Proof. u. Qed.
Add Parametric Morphism A : (@seq A) with signature
inclusion ==> inclusion ==> inclusion as seq_mori.
Proof. u. Qed.
Add Parametric Morphism A : (@irreflexive A) with signature
inclusion --> Basics.impl as irreflexive_mori.
Proof. u. Qed.
Add Parametric Morphism A : (@clos_refl A) with signature
inclusion ==> inclusion as clos_refl_mori.
Proof. u. Qed.
Add Parametric Morphism A : (@clos_trans A) with signature
inclusion ==> inclusion as clos_trans_mori.
Proof. u; eauto using clos_trans_mon. Qed.
Add Parametric Morphism A : (@clos_refl_trans A) with signature
inclusion ==> inclusion as clos_refl_trans_mori.
Proof. u; eauto using clos_refl_trans_mon. Qed.
Add Parametric Morphism A : (@clos_sym A) with signature
inclusion ==> inclusion as clos_sym_mori.
Proof. unfold clos_sym. u. Qed.
Add Parametric Morphism A : (@clos_refl_sym A) with signature
inclusion ==> inclusion as clos_refl_sym_mori.
Proof. unfold clos_refl_sym. u. Qed.
Add Parametric Morphism A : (@restr_rel A) with signature
set_subset ==> inclusion ==> inclusion as restr_rel_mori.
Proof. u. Qed.
Add Parametric Morphism A B : (@restr_eq_rel A B) with signature
eq ==> inclusion ==> inclusion as restr_eq_rel_mori.
Proof. u. Qed.
Add Parametric Morphism A B : (@map_rel A B) with signature
eq ==> inclusion ==> inclusion as map_rel_mori.
Proof. u. Qed.
Add Parametric Morphism A : (@acyclic A) with signature
inclusion --> Basics.impl as acyclic_mori.
Proof.
unfold acyclic; ins; rewrite H; reflexivity.
Qed.
Add Parametric Morphism A : (@is_total A) with signature
set_subset --> inclusion ++> Basics.impl as is_total_mori.
Proof. u; ins; desf; eapply H1 in NEQ; desf; eauto. Qed.
Add Parametric Morphism A : (@transp A) with signature
inclusion ==> inclusion as transp_mori.
Proof. u. Qed.
Add Parametric Morphism A : (@functional A) with signature
inclusion --> Basics.impl as functional_mori.
Proof. u. Qed.
Add Parametric Morphism A : (@eqv_rel A) with signature
set_subset ==> inclusion as eqv_rel_mori.
Proof. u. Qed.
Add Parametric Morphism X : (@pow_rel X) with signature
inclusion ==> eq ==> inclusion as pow_rel_mori.
Proof.
ins. induction y0 as [| y' IH].
by simpl; eauto with hahn.
by simpl; rewrite IH, H.
Qed.
Add Parametric Morphism A : (@well_founded A) with signature
inclusion --> Basics.impl as well_founded_mori.
Proof.
repeat red; ins; induction (H0 a); econs; eauto.
Qed.
Add Parametric Morphism A : (@cross_rel A) with signature
set_subset ==> set_subset ==> inclusion as cross_mori.
Proof. u. Qed.
Add Parametric Morphism A B : (@bunion A B) with signature
set_subset ==> eq ==> inclusion as bunion_mori.
Proof. u. Qed.
Add Parametric Morphism A B : (@collect_rel A B) with signature
eq ==> inclusion ==> inclusion as collect_rel_mori.
Proof. u; eauto 8. Qed.
(** Second, for equivalence. *)
Lemma same_relation_exp A (r r' : relation A) (EQ: r ≡ r') :
forall x y, r x y <-> r' x y.
Proof. split; apply EQ. Qed.
Lemma same_relation_refl A : reflexive (@same_relation A).
Proof. u. Qed.
Lemma same_relation_sym A : symmetric (@same_relation A).
Proof. u. Qed.
Lemma same_relation_trans A : transitive (@same_relation A).
Proof. u. Qed.
Add Parametric Relation (A : Type) : (relation A) (@same_relation A)
reflexivity proved by (@same_relation_refl A)
symmetry proved by (@same_relation_sym A)
transitivity proved by (@same_relation_trans A)
as same_rel.
Add Parametric Morphism A : (@inclusion A) with signature
same_relation ==> same_relation ==> iff as inclusion_more.
Proof. u. Qed.
Add Parametric Morphism A : (@union A) with signature
same_relation ==> same_relation ==> same_relation as union_more.
Proof. u. Qed.
Add Parametric Morphism A : (@inter_rel A) with signature
same_relation ==> same_relation ==> same_relation as inter_rel_more.
Proof. u. Qed.
Add Parametric Morphism A : (@minus_rel A) with signature
same_relation ==> same_relation ==> same_relation as minus_rel_more.
Proof. u. Qed.
Add Parametric Morphism A : (@seq A) with signature
same_relation ==> same_relation ==> same_relation as seq_more.
Proof. u. Qed.
Add Parametric Morphism A : (@immediate A) with signature
same_relation ==> same_relation as immediate_more.
Proof. u. Qed.
Add Parametric Morphism A : (@eqv_dom_rel A) with signature
(@Permutation _) ==> same_relation as eqv_dom_rel_more.
Proof. by u; rewrite H in *. Qed.
Add Parametric Morphism A : (@restr_rel A) with signature
set_equiv ==> same_relation ==> same_relation as restr_rel_more.
Proof. u. Qed.
Add Parametric Morphism A B : (@restr_eq_rel A B) with signature
eq ==> same_relation ==> same_relation as restr_eq_rel_more.
Proof. u. Qed.
Add Parametric Morphism A B : (@map_rel A B) with signature
eq ==> same_relation ==> same_relation as map_rel_more.
Proof. u. Qed.
Add Parametric Morphism A : (@clos_refl A) with signature
same_relation ==> same_relation as clos_relf_more.
Proof. u. Qed.
Add Parametric Morphism A : (@clos_trans A) with signature
same_relation ==> same_relation as clos_trans_more.
Proof. u; eauto using clos_trans_mon. Qed.
Add Parametric Morphism A : (@clos_refl_trans A) with signature
same_relation ==> same_relation as clos_refl_trans_more.
Proof. u; eauto using clos_refl_trans_mon. Qed.
Add Parametric Morphism A : (@clos_sym A) with signature
same_relation ==> same_relation as clos_sym_more.
Proof. unfold clos_sym. u. Qed.
Add Parametric Morphism A : (@clos_refl_sym A) with signature
same_relation ==> same_relation as clos_refl_sym_more.
Proof. unfold clos_refl_sym. u. Qed.
Add Parametric Morphism A : (@irreflexive A) with signature
same_relation ==> iff as irreflexive_more.
Proof. u. Qed.
Add Parametric Morphism A : (@acyclic A) with signature
same_relation ==> iff as acyclic_more.
Proof.
unfold acyclic; ins; rewrite H; reflexivity.
Qed.
Add Parametric Morphism A : (@symmetric A) with signature
same_relation ==> iff as symmetric_more.
Proof. u. Qed.
Add Parametric Morphism A : (@transitive A) with signature
same_relation ==> iff as transitive_more.
Proof. u. Qed.
Add Parametric Morphism A : (@is_total A) with signature
@set_equiv _ ==> same_relation ==> iff as is_total_more.
Proof.
u; split; ins; desf; apply H3 in NEQ; desf; eauto.
Qed.
Add Parametric Morphism A : (@transp A) with signature
same_relation ==> same_relation as transp_more.
Proof. u. Qed.
Add Parametric Morphism A : (@functional A) with signature
same_relation ==> Basics.impl as functional_more.
Proof. u. Qed.
Add Parametric Morphism A : (@eqv_rel A) with signature
@set_equiv _ ==> same_relation as eqv_rel_more.
Proof. u. Qed.
Add Parametric Morphism X : (@pow_rel X) with signature
same_relation ==> eq ==> same_relation as pow_rel_more.
Proof.
by ins; induction y0 as [| y' IH]; ins; rewrite IH, H.
Qed.
Add Parametric Morphism A : (@well_founded A) with signature
same_relation ==> iff as well_founded_more.
Proof.
unfold same_relation; split; eapply well_founded_mori; desf.
Qed.
Add Parametric Morphism A : (@cross_rel A) with signature
set_equiv ==> set_equiv ==> same_relation as cross_more.
Proof. u. Qed.
Add Parametric Morphism A B : (@bunion A B) with signature
set_equiv ==> eq ==> same_relation as bunion_more.
Proof. u. Qed.
Add Parametric Morphism A B : (@collect_rel A B) with signature
eq ==> same_relation ==> same_relation as collect_rel_more.
Proof. u; eauto 8. Qed.
Add Parametric Morphism A : (@dom_rel A) with signature
inclusion ==> set_subset as dom_rel_mori.
Proof. firstorder. Qed.
Add Parametric Morphism A : (@codom_rel A) with signature
inclusion ==> set_subset as codom_rel_mori.
Proof. firstorder. Qed.
Add Parametric Morphism A : (@dom_rel A) with signature
same_relation ==> set_equiv as dom_rel_more.
Proof. firstorder. Qed.
Add Parametric Morphism A : (@codom_rel A) with signature
same_relation ==> set_equiv as codom_rel_more.
Proof. firstorder. Qed.
(******************************************************************************)
(** Basic properties of sequential composition and relational union *)
(******************************************************************************)
Section PropertiesSeqUnion.
Variables B A : Type.
Implicit Type r : relation A.
Implicit Type rr : B -> relation A.
Local Ltac uu := autounfold with unfolderDb in *;
try solve [intuition; ins; desf; eauto; firstorder].
Lemma seqA r1 r2 r3 : (r1 ⨾ r2) ⨾ r3 ≡ r1 ⨾ (r2 ⨾ r3).
Proof. uu. Qed.
Lemma seq_false_l r : ∅₂ ⨾ r ≡ ∅₂.
Proof. uu. Qed.
Lemma seq_false_r r : r ⨾ ∅₂ ≡ ∅₂.
Proof. uu. Qed.
Lemma seq_id_l r : ⦗fun _ => True⦘ ⨾ r ≡ r.
Proof. uu. Qed.
Lemma seq_id_r r : r ⨾ ⦗fun _ => True⦘ ≡ r.
Proof. uu. Qed.
Lemma unionA r1 r2 r3 : (r1 ∪ r2) ∪ r3 ≡ r1 ∪ (r2 ∪ r3).
Proof. uu. Qed.
Lemma unionC r1 r2 : r1 ∪ r2 ≡ r2 ∪ r1.
Proof. uu. Qed.
Lemma unionAC r r' r'' : r ∪ (r' ∪ r'') ≡ r' ∪ (r ∪ r'').
Proof. uu. Qed.
Lemma unionK r : r ∪ r ≡ r.
Proof. uu. Qed.
Lemma union_false_r r : r ∪ ∅₂ ≡ r.
Proof. uu. Qed.
Lemma union_false_l r : ∅₂ ∪ r ≡ r.
Proof. uu. Qed.
Lemma seq_union_l r1 r2 r : (r1 ∪ r2) ⨾ r ≡ (r1 ⨾ r) ∪ (r2 ⨾ r).
Proof. uu. Qed.
Lemma seq_union_r r r1 r2 : r ⨾ (r1 ∪ r2) ≡ (r ⨾ r1) ∪ (r ⨾ r2).
Proof. uu. Qed.
Lemma seq_bunion_l P rr r : bunion P rr ⨾ r ≡ (⋃n ∈ P, rr n ⨾ r).
Proof. uu. Qed.
Lemma seq_bunion_r r P rr : r ⨾ bunion P rr ≡ (⋃n ∈ P, r ⨾ rr n).
Proof. uu. Qed.
Lemma minus_union_l r1 r2 r : (r1 ∪ r2) \ r ≡ (r1 \ r) ∪ (r2 \ r).
Proof. uu. Qed.
Lemma seq_eqvK (dom : A -> Prop) : ⦗dom⦘ ⨾ ⦗dom⦘ ≡ ⦗dom⦘.
Proof. uu. Qed.
Lemma seq_eqvK_l (dom1 dom2 : A -> Prop) (IMP: forall x, dom2 x -> dom1 x) :
⦗dom1⦘ ⨾ ⦗dom2⦘ ≡ ⦗dom2⦘.
Proof. uu. Qed.
Lemma seq_eqvK_r (dom1 dom2 : A -> Prop) (IMP: forall x, dom1 x -> dom2 x) :
⦗dom1⦘ ⨾ ⦗dom2⦘ ≡ ⦗dom1⦘.
Proof. uu. Qed.
Lemma seq_eqvC (doma domb : A -> Prop) :
⦗doma⦘ ⨾ ⦗domb⦘ ≡ ⦗domb⦘ ⨾ ⦗doma⦘.
Proof. uu. Qed.
Lemma seq_eqv (doma domb : A -> Prop) :
⦗doma⦘ ⨾ ⦗domb⦘ ≡ ⦗fun x => doma x /\ domb x⦘.
Proof. uu. Qed.
Lemma union_absorb_l r r' (SUB: r ⊆ r') : r ∪ r' ≡ r'.
Proof. uu. Qed.
Lemma union_absorb_r r r' (SUB: r ⊆ r') : r' ∪ r ≡ r'.
Proof. uu. Qed.
Lemma id_union (s s': A -> Prop) : ⦗s ∪₁ s'⦘ ≡ ⦗s⦘ ∪ ⦗s'⦘.
Proof. uu. Qed.
End PropertiesSeqUnion.
#[export]
Hint Rewrite seq_false_l seq_false_r union_false_l union_false_r unionK
seq_id_l seq_id_r seq_eqvK : hahn.
#[export]
Hint Rewrite seq_bunion_l seq_bunion_r seq_union_l seq_union_r : hahn_full.
(******************************************************************************)
(** Properties of big union *)
(******************************************************************************)
Section PropertiesBigUnion.
Variables B A : Type.
Implicit Type r : relation A.
Implicit Type rr : B -> relation A.
Local Ltac uu := autounfold with unfolderDb in *;
try solve [intuition; ins; desf; eauto; firstorder].
Lemma bunion_empty rr : bunion ∅ rr ≡ ∅₂.
Proof. uu. Qed.
Lemma bunion_eq a rr : bunion (eq a) rr ≡ rr a.
Proof. u; splits; ins; desf; eauto. Qed.
Lemma bunion_union_l s s' rr :
bunion (s ∪₁ s') rr ≡ bunion s rr ∪ bunion s' rr.
Proof. uu. Qed.
Lemma bunion_union_r s rr rr' :
bunion s (fun x => rr x ∪ rr' x) ≡ bunion s rr ∪ bunion s rr'.
Proof. uu. Qed.
Lemma bunion_inter_compat_l s r rr :
bunion s (fun x => r ∩ rr x) ≡ r ∩ bunion s rr.
Proof. uu; split; ins; desf; eauto 8. Qed.
Lemma bunion_inter_compat_r s r rr :
bunion s (fun x => rr x ∩ r) ≡ bunion s rr ∩ r.
Proof. uu; split; ins; desf; eauto 8. Qed.
Lemma bunion_minus_compat_r s r rr :
bunion s (fun x => rr x \ r) ≡ bunion s rr \ r.
Proof. uu; split; ins; desf; eauto 8. Qed.
End PropertiesBigUnion.
(******************************************************************************)
(** Basic properties of relational intersection *)
(******************************************************************************)
Section PropertiesInter.
Variable A : Type.
Implicit Type r : relation A.
Lemma interA r1 r2 r3 : (r1 ∩ r2) ∩ r3 ≡ r1 ∩ (r2 ∩ r3).
Proof. u. Qed.
Lemma interC r1 r2 : r1 ∩ r2 ≡ r2 ∩ r1.
Proof. u. Qed.
Lemma interAC r r' r'' : r ∩ (r' ∩ r'') ≡ r' ∩ (r ∩ r'').
Proof. u. Qed.
Lemma interK r : r ∩ r ≡ r.
Proof. u. Qed.
Lemma inter_false_r r : r ∩ ∅₂ ≡ ∅₂.
Proof. u. Qed.
Lemma inter_false_l r : ∅₂ ∩ r ≡ ∅₂.
Proof. u. Qed.
Lemma inter_union_r r r1 r2 : r ∩ (r1 ∪ r2) ≡ (r ∩ r1) ∪ (r ∩ r2).
Proof. u. Qed.
Lemma inter_union_l r r1 r2 : (r1 ∪ r2) ∩ r ≡ (r1 ∩ r) ∪ (r2 ∩ r).
Proof. u. Qed.
Lemma inter_absorb_l r r' (SUB: r ⊆ r') : r' ∩ r ≡ r.
Proof. u. Qed.
Lemma inter_absorb_r r r' (SUB: r ⊆ r') : r ∩ r' ≡ r.
Proof. u. Qed.
Lemma inter_trans (r r' i : relation A) (T: transitive i) :
(r ∩ i) ⨾ (r' ∩ i) ⊆ (r ⨾ r') ∩ i.
Proof. u. Qed.
Lemma inter_inclusion (r i : relation A) : r ∩ i ⊆ r.
Proof. u. Qed.
Lemma id_inter (s s' : A -> Prop) : ⦗s ∩₁ s'⦘ ≡ ⦗s⦘ ⨾ ⦗s'⦘.
Proof. u. Qed.
Lemma inter_restr_absorb_l (s : A -> Prop) r r' :
restr_rel s r ∩ restr_rel s r' ≡ r ∩ restr_rel s r'.
Proof. u. Qed.
Lemma inter_restr_absorb_r (s : A -> Prop) r r' :
restr_rel s r ∩ restr_rel s r' ≡ restr_rel s r ∩ r'.
Proof. u. Qed.
End PropertiesInter.
#[export]
Hint Rewrite inter_false_l inter_false_r interK : hahn.
(******************************************************************************)
(** Properties of relational difference *)
(******************************************************************************)
Section PropertiesMinus.
Variable A : Type.
Implicit Type r : relation A.
Lemma minus_false_r r : r \ ∅₂ ≡ r.
Proof. u. Qed.
Lemma minus_false_l r : ∅₂ \ r ≡ ∅₂.
Proof. u. Qed.
Lemma minusK r : r \ r ≡ ∅₂.
Proof. u. Qed.
Lemma minus_absorb r r' (SUB: r ⊆ r') : r \ r' ≡ ∅₂.
Proof. u. Qed.
End PropertiesMinus.
#[export]
Hint Rewrite minus_false_l minus_false_r minusK : hahn.
(******************************************************************************)
(** Basic properties of reflexive/symmetric/transitive closures *)
(******************************************************************************)
Section PropertiesClos.
Variable A : Type.
Implicit Types r : relation A.
Lemma crE r : r ^? ≡ ⦗fun _ => True⦘ ∪ r.
Proof. u. Qed.
Lemma rtE r : r * ≡ ⦗fun _ => True⦘ ∪ r⁺.
Proof.
u; rewrite clos_refl_transE in *; tauto.
Qed.
Lemma rtEE r : r* ≡ ⋃n, r ^^ n.
Proof.
split; ins; desc.
u.
induction H using clos_refl_trans_ind_left; desc.
by exists 0.
by exists (S a); vauto.
apply inclusion_bunion_l; ins.
induction x; ins; [|rewrite IHx];
unfold eqv_rel, seq; red; ins; desf; vauto.
Qed.
Lemma csE r : r^⋈ ≡ r ∪ r⁻¹.
Proof. u. Qed.
Lemma crsE r : r^⋈? ≡ ⦗fun _ => True⦘ ∪ r ∪ r⁻¹.
Proof. unfold clos_refl_sym. u. Qed.
Lemma crsEE r : r^⋈? ≡ ⦗fun _ => True⦘ ∪ r^⋈.
Proof. rewrite crsE, csE. u. Qed.
Lemma ct_begin r : r⁺ ≡ r ⨾ r *.
Proof.
unfold seq; split; red; ins; desf; rewrite t_step_rt in *; eauto.
Qed.
Lemma ct_end r : r⁺ ≡ r * ⨾ r.
Proof.
unfold seq; split; red; ins; desf; rewrite t_rt_step in *; eauto.
Qed.
Lemma ctEE r : r⁺ ≡ ⋃ n, r ^^ (S n).
Proof.
by rewrite ct_end, rtEE, seq_bunion_l.
Qed.
Lemma rt_begin r :
r * ≡ ⦗fun _ => True⦘ ∪ r ⨾ r *.
Proof.
rewrite <- ct_begin, <- rtE; vauto.
Qed.
Lemma rt_end r :
r * ≡ ⦗fun _ => True⦘ ∪ r * ⨾ r.
Proof.
rewrite <- ct_end, <- rtE; vauto.
Qed.
Lemma ct_of_trans r (T: transitive r) : r⁺ ≡ r.
Proof.
split; eauto with hahn.
Qed.
Lemma rt_of_trans r (T: transitive r) : r * ≡ r ^?.
Proof.
rewrite rtE, crE, ct_of_trans; vauto.
Qed.
Lemma cr_ct r : r ^? ⨾ r⁺ ≡ r⁺.
Proof.
unfold seq, clos_refl; split; red; ins; desf; eauto using t_trans, t_step.
Qed.
Lemma cr_rt r : r ^? ⨾ r * ≡ r *.
Proof.
unfold seq, clos_refl; split; red; ins; desf; eauto using rt_trans, rt_step.
Qed.
Lemma ct_rt r : r⁺ ⨾ r * ≡ r⁺.
Proof.
unfold seq; split; red; ins; desf; eauto using t_rt_trans, rt_refl.
Qed.
Lemma ct_ct r : r⁺ ⨾ r⁺ ⊆ r⁺.
Proof.
unfold seq; red; ins; desf; eauto using t_trans.
Qed.
Lemma ct_cr r : r⁺ ⨾ r ^? ≡ r⁺.
Proof.
unfold seq, clos_refl; split; red; ins; desf; eauto using t_trans, t_step.
Qed.
Lemma rt_rt r : r * ⨾ r * ≡ r *.
Proof.
unfold seq; split; red; ins; desf; eauto using rt_trans, rt_refl.
Qed.
Lemma rt_ct r : r * ⨾ r⁺ ≡ r⁺.
Proof.
unfold seq; split; red; ins; desf; eauto using rt_t_trans, rt_refl.
Qed.
Lemma rt_cr r : r * ⨾ r ^? ≡ r *.
Proof.
unfold seq, clos_refl; split; red; ins; desf; eauto using rt_trans, rt_step.
Qed.
Lemma cr_of_ct r : (r⁺) ^? ≡ r *.
Proof.
by rewrite rt_begin, ct_begin, crE.
Qed.
Lemma cr_of_cr r : (r ^?) ^? ≡ r ^?.
Proof.
by rewrite !crE, <- unionA, unionK.
Qed.
Lemma cr_of_rt r : (r *) ^? ≡ r *.
Proof.
by rewrite rtE, <- crE, cr_of_cr.
Qed.
Lemma ct_of_ct r: (r⁺)⁺ ≡ r⁺.
Proof.
split; eauto with hahn.
Qed.
Lemma ct_of_union_ct_l r r' : (r⁺ ∪ r')⁺ ≡ (r ∪ r')⁺.
Proof.
split; eauto 8 with hahn.
Qed.
Lemma ct_of_union_ct_r r r' : (r ∪ r'⁺)⁺ ≡ (r ∪ r')⁺.
Proof.
split; eauto 8 with hahn.
Qed.
Lemma ct_of_cr r: (r ^?)⁺ ≡ r *.
Proof.
split; eauto with hahn.
apply inclusion_rt_ind_left; vauto.
rewrite ct_begin at 2; eauto with hahn.
Qed.
Lemma ct_of_rt r: (r *)⁺ ≡ r *.
Proof.
split; eauto with hahn.
Qed.
Lemma rt_of_ct r : (r⁺) * ≡ r *.
Proof.
split; eauto using inclusion_rt_rt2 with hahn.
Qed.
Lemma rt_of_cr r : (r ^?) * ≡ r *.
Proof.
split; eauto using inclusion_rt_rt2 with hahn.
Qed.
Lemma rt_of_rt r : (r *) * ≡ r *.
Proof.
split; eauto using inclusion_rt_rt2 with hahn.
Qed.
Lemma cr_union_l r r' : (r ∪ r') ^? ≡ r ^? ∪ r'.
Proof.
by rewrite !crE, unionA.
Qed.
Lemma cr_union_r r r' : (r ∪ r') ^? ≡ r ∪ r' ^?.
Proof.
by rewrite unionC, cr_union_l, unionC.
Qed.
Lemma cs_union r r' : (r ∪ r')^⋈ ≡ r^⋈ ∪ r'^⋈.
Proof. rewrite !csE. u. Qed.
Lemma crs_union r r' : (r ∪ r')^⋈? ≡ r^⋈? ∪ r'^⋈?.
Proof. rewrite !crsE. u. Qed.
Lemma cs_inter r r' : (r ∩ r')^⋈ ⊆ r^⋈ ∩ r'^⋈.
Proof. rewrite !csE. u. Qed.
Lemma crs_inter r r' : (r ∩ r')^⋈? ⊆ r^⋈? ∩ r'^⋈?.
Proof. rewrite !crsE. u. Qed.
Lemma cs_cross (s s' : A -> Prop) : (s × s')^⋈ ≡ s × s' ∪ s' × s.
Proof. rewrite !csE. u. Qed.
Lemma crs_cross (s s' : A -> Prop) : (s × s')^⋈? ≡ ⦗fun _ => True⦘ ∪ s × s' ∪ s' × s.
Proof. rewrite !crsE. u. Qed.
Lemma cs_restr (s : A -> Prop) r : (restr_rel s r)^⋈ ≡ restr_rel s r^⋈.
Proof. rewrite !csE. u. Qed.
Lemma crs_restr (s : A -> Prop) r : (restr_rel s r)^⋈? ≡ ⦗fun _ => True⦘ ∪ restr_rel s r^⋈.
Proof. rewrite !csE, !crsE. u. Qed.
Lemma restr_of_crs (s : A -> Prop) r : restr_rel s r^⋈? ≡ ⦗s⦘ ∪ restr_rel s r^⋈.
Proof. rewrite !csE, !crsE. u. Qed.
Lemma seq_rtE_r r r' : r ⨾ r' * ≡ r ∪ (r ⨾ r') ⨾ r' *.
Proof.
by rewrite rt_begin at 1; rewrite ?seq_union_r, ?seq_id_r, ?seqA.
Qed.
Lemma seq_rtE_l r r' : r' * ⨾ r ≡ r ∪ (r' * ⨾ r' ⨾ r).
Proof.
by rewrite rt_end at 1; rewrite ?seq_union_l, ?seq_id_l, ?seqA.
Qed.
Lemma ct_step r : r ⊆ r⁺.
Proof.
vauto.
Qed.
Lemma rt_unit r : r* ⨾ r ⊆ r*.
Proof.
rewrite <- ct_end; apply inclusion_t_rt.
Qed.
Lemma ct_unit r : r⁺ ⨾ r ⊆ r⁺.
Proof.
unfold seq, inclusion; ins; desf; vauto.
Qed.
Lemma trailing_refl r r' e : r ⊆ r' -> r ⊆ r' ⨾ e^?.
Proof.
firstorder.
Qed.
Lemma cr_seq (r r' : relation A) : r^? ⨾ r' ≡ r' ∪ r ⨾ r'.
Proof. split; autounfold with unfolderDb; ins; desf; eauto. Qed.
Lemma cr_helper (r r' : relation A) d (H: r ⨾ ⦗d⦘ ⊆ ⦗d⦘ ⨾ r') : r^? ⨾ ⦗d⦘ ⊆ ⦗d⦘ ⨾ r'^? .
Proof.
rewrite crE.
autounfold with unfolderDb in *; ins; desf; eauto.
edestruct H; eauto. desf. eauto.
Qed.
End PropertiesClos.
#[export]
Hint Rewrite cr_of_ct cr_of_cr cr_of_rt
ct_of_ct ct_of_cr ct_of_rt
rt_of_ct rt_of_cr rt_of_rt : hahn.
Definition good_ctx A (P: relation A -> relation A) :=
<< MON: Morphisms.Proper (inclusion ==> inclusion) P >> /\
<< CUN: forall (rr : nat -> relation A), P (⋃ n, rr n) ⊆ ⋃ n, P (rr n) >>.
Section good_ctx_lemmas.
Variables A : Type.
Implicit Types P Q : relation A -> relation A.
Implicit Types r : relation A.
Lemma good_ctx_id : good_ctx (fun x : relation A => x).
Proof.
split; unnw; ins; vauto.
Qed.
Lemma good_ctx_const r : good_ctx (fun x : relation A => r).
Proof.
split; unnw; ins; repeat red; ins; vauto.
Qed.
Lemma good_ctx_seq_l P (GP : good_ctx P) r :
good_ctx (fun x => P x ⨾ r).
Proof.
cdes GP; split; unnw; ins; [by do 2 red; ins; rewrite H|].
by rewrite CUN, seq_bunion_l.
Qed.
Lemma good_ctx_seq_r P (GP : good_ctx P) r :
good_ctx (fun x => r ⨾ P x).
Proof.
cdes GP; split; unnw; ins; [by do 2 red; ins; rewrite H|].
by rewrite CUN, seq_bunion_r.
Qed.
Lemma good_ctx_union P (GP : good_ctx P) Q (GQ : good_ctx Q) :
good_ctx (fun x => P x ∪ Q x).
Proof.
cdes GP; cdes GQ; split; unnw; ins; [by do 2 red; ins; rewrite H|].
rewrite CUN, CUN0; firstorder.
Qed.
Lemma good_ctx_compose P (GP : good_ctx P) Q (GQ : good_ctx Q) :
good_ctx (fun x => P (Q x)).
Proof.
cdes GP; cdes GQ; split; unnw; ins; [by do 2 red; ins; rewrite H|].
rewrite CUN0, CUN; apply inclusion_bunion_l; vauto.
Qed.
Lemma seq_pow_l r n : r ^^ n ⨾ r ≡ r ⨾ r ^^ n.
Proof.
induction n; ins; autorewrite with hahn; try done.
by rewrite IHn at 1; rewrite seqA.
Qed.
Lemma rt_ind_left P (G: good_ctx P) r r' :
P ⦗fun _ => True⦘ ⊆ r' ->
(forall k, P k ⊆ r' -> P (r ⨾ k) ⊆ r') ->
P r* ⊆ r'.
Proof.
ins; cdes G; rewrite (proj1 (rtEE _)).
etransitivity; [eapply CUN|apply inclusion_bunion_l]; ins.
induction x; ins; rewrite (proj1 (seq_pow_l _ _)); eauto.
Qed.
Lemma rt_ind_right P (G: good_ctx P) r r' :
P ⦗fun _ => True⦘ ⊆ r' ->
(forall k, P k ⊆ r' -> P (k ⨾ r) ⊆ r') ->
P r* ⊆ r'.
Proof.
ins; cdes G; rewrite (proj1 (rtEE _)).
etransitivity; [eapply CUN|apply inclusion_bunion_l]; ins.
induction x; ins; eauto.
Qed.
Lemma ct_ind_left P (G: good_ctx P) r r' :
P r ⊆ r' -> (forall k, P k ⊆ r' -> P (r ⨾ k) ⊆ r') -> P ( r⁺ ) ⊆ r'.
Proof.
ins; cdes G; rewrite (proj1 (ct_end _)).
apply rt_ind_left with (P := fun x => P (x ⨾ r)); ins;
eauto using good_ctx_compose, good_ctx_seq_l, good_ctx_id.
by rewrite (proj1 (seq_id_l _)).
by rewrite (proj1 (seqA _ _ _)); eauto.
Qed.
Lemma ct_ind_right P (G: good_ctx P) r r' :
P r ⊆ r' -> (forall k, P k ⊆ r' -> P (k ⨾ r) ⊆ r') -> P ( r⁺ ) ⊆ r'.
Proof.
ins; cdes G; rewrite (proj1 (ctEE _)).
etransitivity; [eapply CUN|apply inclusion_bunion_l]; ins.
induction x; ins; eauto.
by rewrite (proj1 (seq_id_l _)).
Qed.
Lemma ct_ind_left_helper P (G: good_ctx P) x r (EQ: x = r⁺) r' :
P r ⊆ r' -> (forall k, P k ⊆ r' -> P (r ⨾ k) ⊆ r') -> P x ⊆ r'.
Proof.
by subst; apply ct_ind_left.
Qed.
End good_ctx_lemmas.
Global Hint Resolve good_ctx_id good_ctx_const good_ctx_seq_l
good_ctx_seq_r good_ctx_union good_ctx_compose : hahn.
Section ExtraPropertiesClos.
Variable A : Type.
Implicit Types r : relation A.
Lemma ct_seq_swap r r' :
(r ⨾ r')⁺ ⨾ r ≡ r ⨾ (r' ⨾ r)⁺.
Proof.
split.
{ apply ct_ind_left with (P := fun x => x ⨾ _); auto with hahn;
ins; rewrite seqA; eauto with hahn.
rewrite ct_begin, H, ?seqA; eauto with hahn. }
apply ct_ind_right with (P := fun x => _ ⨾ x); auto with hahn;
ins; rewrite <- seqA; eauto with hahn.
rewrite ct_end, H, <- ?seqA; eauto with hahn.
Qed.
Lemma rt_seq_swap r r' :
(r ⨾ r') * ⨾ r ≡ r ⨾ (r' ⨾ r) *.
Proof.
by rewrite !rtE; autorewrite with hahn hahn_full; rewrite ct_seq_swap.
Qed.
Lemma ct_rotl r r' :
(r ⨾ r')⁺ ≡ r ⨾ (r' ⨾ r) * ⨾ r'.
Proof.
by rewrite rt_seq_swap, ct_begin, seqA.
Qed.
Lemma crt_double r :
r * ≡ r ^? ⨾ (r ⨾ r) *.
Proof.
split; [|by eauto 7 using inclusion_seq_trans, inclusion_rt_rt2 with hahn].
apply inclusion_rt_ind_left; eauto with hahn.
rewrite !crE; autorewrite with hahn hahn_full.
rewrite <- seqA, <- ct_begin; eauto with hahn.
Qed.
End ExtraPropertiesClos.
(******************************************************************************)
(** Properties of [eqv_rel] *)
(******************************************************************************)
Lemma eqv_empty A : ⦗@set_empty A⦘ ≡ ∅₂.
Proof.
autounfold with unfolderDb; intuition; desf; eauto.
Qed.
Lemma seq_eqv_r A (r : relation A) dom :
r ⨾ ⦗dom⦘ ≡ (fun x y => r x y /\ dom y).
Proof.
autounfold with unfolderDb; intuition; desf; eauto.
Qed.
Lemma seq_eqv_l A (r : relation A) dom :
⦗dom⦘ ⨾ r ≡ (fun x y => dom x /\ r x y).
Proof.
autounfold with unfolderDb; intuition; desf; eauto.
Qed.
Lemma inclusion_seq_eqv_l A (r : relation A) dom :
⦗dom⦘ ⨾ r ⊆ r.
Proof.
autounfold with unfolderDb; intuition; desf; eauto.
Qed.
Lemma inclusion_seq_eqv_r A (r : relation A) dom :
r ⨾ ⦗dom⦘ ⊆ r.
Proof.
autounfold with unfolderDb; intuition; desf; eauto.
Qed.
Lemma seq_eqv_lr A (r : relation A) dom1 dom2 :
⦗dom1⦘ ⨾ r ⨾ ⦗dom2⦘ ≡ (fun x y : A => dom1 x /\ r x y /\ dom2 y).
Proof.
autounfold with unfolderDb; intuition; desf; eauto 10.
Qed.
Lemma seq_eqv_inter_ll A S (r r' : relation A) :
(⦗S⦘ ⨾ r) ∩ r' ≡ ⦗S⦘ ⨾ r ∩ r'.
Proof. autounfold with unfolderDb; intuition; desf; eauto. Qed.
Lemma seq_eqv_inter_lr A S (r r' : relation A) :
(r ⨾ ⦗S⦘) ∩ r' ≡ r ∩ r' ⨾ ⦗S⦘.
Proof. autounfold with unfolderDb; intuition; desf; eauto. Qed.
Lemma seq_eqv_minus_lr A (s : A -> Prop) (r r' : relation A) :
(r ⨾ ⦗s⦘) \ r' ≡ (r \ r') ⨾ ⦗s⦘.
Proof. autounfold with unfolderDb; intuition; desf; eauto. Qed.
Lemma seq_eqv_minus_ll A (s : A -> Prop) (r r' : relation A) :
(⦗s⦘ ⨾ r) \ r' ≡ ⦗s⦘ ⨾ (r \ r').
Proof. autounfold with unfolderDb; intuition; desf; eauto. Qed.
#[export]
Hint Rewrite eqv_empty : hahn.
(******************************************************************************)
(** Properties of restrictions *)
(******************************************************************************)
Lemma same_relation_restr A (f : A -> Prop) r r' :
(forall x (CONDx: f x) y (CONDy: f y), r x y <-> r' x y) ->
(restr_rel f r ≡ restr_rel f r').
Proof. u; firstorder. Qed.
Lemma restr_restr A (d d' : A -> Prop) r :
restr_rel d (restr_rel d' r) ≡ restr_rel (d' ∩₁ d) r.
Proof. u. Qed.
Lemma restrC A (d d': A -> Prop) r :
restr_rel d (restr_rel d' r) ≡ restr_rel d' (restr_rel d r).
Proof. u. Qed.
Lemma restr_relE A (d : A -> Prop) r :
restr_rel d r ≡ <| d |> ;; r ;; <| d |>.
Proof. rewrite seq_eqv_lr; u. Qed.
Lemma restr_relEE A (d : A -> Prop) r : restr_rel d r ≡ r ∩ d × d.
Proof. u. Qed.
Lemma restr_union A (f : A -> Prop) r r' :
restr_rel f (r ∪ r') ≡ restr_rel f r ∪ restr_rel f r'.
Proof. u. Qed.
Lemma restr_inter A (f : A -> Prop) r r' :
restr_rel f (r ∩ r') ≡ restr_rel f r ∩ restr_rel f r'.