-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmanger_sets.v
More file actions
4873 lines (4502 loc) · 126 KB
/
manger_sets.v
File metadata and controls
4873 lines (4502 loc) · 126 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Require Import Coq.Lists.List
Psatz.
Require Import CAS.coq.common.compute.
Require Import CAS.coq.theory.set. (* for in_set lemmas *)
Require Import CAS.coq.eqv.properties.
Require Import CAS.coq.eqv.set.
Require Import CAS.coq.eqv.minset.
Require Import CAS.coq.eqv.product.
Require Import CAS.coq.po.properties.
Require Import CAS.coq.po.trivial.
Require Import CAS.coq.sg.properties.
Require Import CAS.coq.sg.or.
Require Import CAS.coq.sg.and.
Require Import CAS.coq.sg.union.
Require Import CAS.coq.sg.lift.
Require Import CAS.coq.sg.product.
Require Import CAS.coq.algorithms.matrix_algorithms.
Require Import CAS.coq.uop.properties.
Require Import CAS.coq.po.theory.
Require Import CAS.coq.eqv.list.
Import ListNotations.
Section Computation.
(*
• Phase 1. All pairs from X with equal active components are merged
into a single pair whose active component is the one found in the
original pairs and passive component is the join of passive components
from the original pairs. For instance, if X contains altogether three
pairs with a given x ∈ P , i.e., (x, x1 ), (x, x2 ) and (x, x3 ), then they are
replaced with a single pair (x, x1 ∨ x2 ∨ x3 ). Note that after phase 1
all pairs in X have distinct active components.
• Phase 2. All pairs from X that are dominated in X with respect
to their active components are deleted from X. For instance, if X
contains two pairs (x, x') and (y, y') such that x ≺ y, then the pair
(x, x') is deleted. In other words, phase 2 leaves in X only those pairs
that are efficient according to their active component.
TGG22: Note that Manger's order is the dual of our left order.
*)
(*
A = type of active component
P = type of passive component
*)
Fixpoint manger_merge_sets
{A P : Type}
(eqA : brel A)
(addP : binary_op P)
(Y : finite_set (A * P))
(p1 : A * P) :=
match Y with
| nil => p1 :: nil
| p2 :: Y' =>
match p1, p2 with
| (s1, t1), (s2, t2) =>
if eqA s1 s2
then manger_merge_sets eqA addP Y' (s1, addP t1 t2)
else p2 :: (manger_merge_sets eqA addP Y' p1)
end
end.
(*
This makes the current proof that I am trying is bit easier.
The manger_merge_sets and manger_merge_sets_new are
equivalent.
*)
Definition manger_merge_sets_new_aux
{A P : Type}
(eqA : brel A)
(addP : binary_op P)
(Y : finite_set (A * P))
(p1 : A * P) : list (A * P) * list (A * P) :=
((filter (λ '(s2, t2), eqA (fst p1) s2) Y),
(filter (λ '(s2, t2), negb (eqA (fst p1) s2)) Y)).
Definition manger_merge_sets_new
{A P : Type}
(eqA : brel A)
(addP : binary_op P)
(Y : finite_set (A * P))
(p1 : A * P) : list (A * P) :=
match manger_merge_sets_new_aux eqA addP Y p1 with
| (Y1, Y2) =>
Y2 ++
[(fold_left
(λ '(s1, t1) '(s2, t2), (s1, addP t1 t2))
Y1 p1)]
end.
Definition manger_phase_1_auxiliary
{A P : Type}
(eqA : brel A)
(addP : binary_op P)
(Y : finite_set (A * P))
(X : finite_set (A * P)) : finite_set (A * P) :=
fold_left (manger_merge_sets eqA addP) X Y.
Definition uop_manger_phase_1
{A P : Type}
(eqA : brel A)
(addP : binary_op P)
(X : finite_set (A * P)) : finite_set (A * P) :=
manger_phase_1_auxiliary eqA addP nil X.
Definition equal_manger_phase_1
{A P : Type}
(eqA : brel A)
(eqP : brel P)
(addP : binary_op P) : brel (finite_set (A * P)) :=
λ X Z, brel_set (brel_product eqA eqP)
(uop_manger_phase_1 eqA addP X)
(uop_manger_phase_1 eqA addP Z).
Definition manger_pre_order
{A P : Type}
(lteA : brel A) : brel (A * P)
:= brel_product lteA (@brel_trivial P).
Definition uop_manger_phase_2
{A P : Type} (lteA : brel A) : unary_op (finite_set (A * P))
:= uop_minset (manger_pre_order lteA).
Definition equal_manger_phase_2
{A P : Type}
(eqA lteA : brel A)
(eqP : brel P) : brel (finite_set (A * P)) :=
λ X Z, brel_set (brel_product eqA eqP)
(uop_manger_phase_2 lteA X)
(uop_manger_phase_2 lteA Z).
Definition equal_manger
{A P : Type}
(eqA lteA : brel A)
(eqP : brel P)
(addP : binary_op P) : brel (finite_set (A * P)) :=
λ X Z, equal_manger_phase_1 eqA eqP addP
(@uop_manger_phase_2 A P lteA X)
(@uop_manger_phase_2 A P lteA Z).
Definition equal_manger_v2
{A P : Type}
(eqA lteA : brel A)
(eqP : brel P)
(addP : binary_op P) : brel (finite_set (A * P)) :=
λ X Z, @equal_manger_phase_2 A P eqA lteA eqP
(uop_manger_phase_1 eqA addP X)
(uop_manger_phase_1 eqA addP Z).
(* conjecture these two equalities are the same *)
End Computation.
Section Theory.
Variables (A P : Type)
(eqA lteA : brel A)
(eqP : brel P)
(addP : binary_op P)
(zeroP : P)
(* *)
(zeropLid : ∀ (p : P), eqP (addP zeroP p) p = true)
(zeropRid : ∀ (p : P), eqP (addP p zeroP) p = true)
(refA : brel_reflexive A eqA)
(symA : brel_symmetric A eqA)
(trnA : brel_transitive A eqA)
(refP : brel_reflexive P eqP)
(symP : brel_symmetric P eqP)
(trnP : brel_transitive P eqP)
(cong_addP : bop_congruence P eqP addP)
(cong_lteA : brel_congruence A eqA lteA)
(cong_eqP : brel_congruence P eqP eqP)
(cong_eqA : brel_congruence A eqA eqA)
(ref_lteA : brel_reflexive A lteA)
(trn_lteA: brel_transitive A lteA)
(* is idemP really needed, or is it
a consequence of using lists to represent sets?
*)
(idemP : bop_idempotent P eqP addP)
(* Extra assumptions needed to prove the lemmas fold_left congruence *)
(addP_assoc : bop_associative P eqP addP)
(addP_com : bop_commutative P eqP addP)
(* idempotence is baked in this addP_gen_idempotent but it can be proved *)
(addP_gen_idempotent : ∀ x y : P, eqP x y = true → eqP (addP x y) y = true).
Local Notation "a [in] X" := (in_set (brel_product eqA eqP) X a = true) (at level 70).
Local Notation "a == b" := (brel_product eqA eqP a b = true) (at level 70).
Local Notation "a <A> b" := (eqA a b = false) (at level 70).
Local Notation "[MMS]" := (manger_merge_sets eqA addP).
Local Notation "[P1AX]" := (manger_phase_1_auxiliary eqA addP).
Local Notation "[P1]" := (uop_manger_phase_1 eqA addP).
Local Notation "[P2]" := (uop_manger_phase_2 lteA).
Local Notation "[EQ]" := (brel_set (brel_product eqA eqP)).
Local Notation "a =S= b" := (brel_set (brel_product eqA eqP) a b = true) (at level 70).
Local Notation "[EQ1]" := (equal_manger_phase_1 eqA eqP addP).
Local Notation "[EQM]" := (equal_manger eqA lteA eqP addP).
(* equality on A * P *)
Lemma refAP : brel_reflexive (A * P) (brel_product eqA eqP).
Proof. apply brel_product_reflexive; auto. Qed.
Lemma symAP : brel_symmetric (A * P) (brel_product eqA eqP).
Proof. apply brel_product_symmetric; auto. Qed.
Lemma trnAP : brel_transitive (A * P) (brel_product eqA eqP).
Proof. apply brel_product_transitive; auto. Qed.
(* equality on set over A * P *)
Lemma refSetAP : brel_reflexive _ [EQ].
Proof. apply brel_set_reflexive.
- apply refAP.
- apply symAP.
Qed.
Lemma symSetAP : brel_symmetric _ [EQ].
Proof. apply brel_set_symmetric. Qed.
Lemma trnSetAP : brel_transitive _ [EQ].
Proof. apply brel_set_transitive.
- apply refAP.
- apply symAP.
- apply trnAP.
Qed.
Lemma set_equal_with_cons_left :
∀ X p1 p2, p1 == p2 -> (p1 :: X) =S= (p2 :: X) .
Proof. intros X p1 p2 H1.
apply brel_set_intro_prop.
- apply refAP.
- split; intros a H2.
+ apply in_set_cons_intro; auto.
* apply symAP.
* apply in_set_cons_elim in H2.
-- destruct H2 as [H2 | H2].
++ left. apply symAP in H1.
exact (trnAP _ _ _ H1 H2).
++ right. exact H2.
-- apply symAP.
+ apply in_set_cons_intro; auto.
* apply symAP.
* apply in_set_cons_elim in H2.
-- destruct H2 as [H2 | H2].
++ left.
exact (trnAP _ _ _ H1 H2).
++ right. exact H2.
-- apply symAP.
Qed.
Lemma set_equal_with_cons_right :
∀ X Y p, X =S= Y -> (p :: X) =S= (p :: Y) .
Proof. intros X Y p H1.
apply brel_set_intro_prop.
- apply refAP.
- split; intros a H2.
+ apply in_set_cons_intro; auto.
* apply symAP.
* apply in_set_cons_elim in H2.
-- destruct H2 as [H2 | H2].
++ left. exact H2.
++ right.
rewrite (in_set_left_congruence _ _ symAP trnAP a _ _ H1) in H2.
exact H2.
-- apply symAP.
+ apply in_set_cons_intro; auto.
* apply symAP.
* apply in_set_cons_elim in H2.
-- destruct H2 as [H2 | H2].
++ left. exact H2.
++ right.
rewrite (in_set_left_congruence _ _ symAP trnAP a _ _ H1).
exact H2.
-- apply symAP.
Qed.
Lemma remove_duplicate_from_set :
∀ Y p1 p2, p1 == p2 -> (p1 :: p2 :: Y) =S= (p1 :: Y).
Proof. intros Y p1 p2 H1.
apply brel_set_intro_prop.
- apply refAP.
- split; intros a H2.
+ apply in_set_cons_intro.
* apply symAP.
* apply in_set_cons_elim in H2.
-- destruct H2 as [H2 | H2].
++ left; auto.
++ apply in_set_cons_elim in H2.
** destruct H2 as [H2 | H2].
--- left. exact (trnAP _ _ _ H1 H2).
--- right; auto.
** apply symAP.
-- apply symAP.
+ apply in_set_cons_intro.
* apply symAP.
* apply in_set_cons_elim in H2.
-- destruct H2 as [H2 | H2].
++ left; auto.
++ right.
apply in_set_cons_intro; auto.
apply symAP.
-- apply symAP.
Qed.
Lemma set_rearrange_v1 :
∀ Y p1 p2, (p1 :: p2 :: Y) =S= (p2:: p1 :: Y).
Proof. intros Y p1 p2.
apply brel_set_intro_prop.
- apply refAP.
- split; intros p3 H1.
+ (*
H1 : p3 [in] p1 :: p2 :: Y
============================
p3 [in] p2 :: p1 :: Y
*)
apply in_set_cons_intro.
* apply symAP.
* apply in_set_cons_elim in H1.
-- destruct H1 as [H1 | H1].
++ right.
apply in_set_cons_intro.
** apply symAP.
** left. auto.
++ apply in_set_cons_elim in H1.
--- destruct H1 as [H1 | H1].
+++ left. auto.
+++ right.
apply in_set_cons_intro.
*** apply symAP.
*** right. auto.
--- apply symAP.
-- apply symAP.
+ (* same code!
H1 : p3 [in] p2 :: p1 :: Y
============================
p3 [in] p1 :: p2 :: Y
*)
apply in_set_cons_intro.
* apply symAP.
* apply in_set_cons_elim in H1.
-- destruct H1 as [H1 | H1].
++ right.
apply in_set_cons_intro.
** apply symAP.
** left. auto.
++ apply in_set_cons_elim in H1.
--- destruct H1 as [H1 | H1].
+++ left. auto.
+++ right.
apply in_set_cons_intro.
*** apply symAP.
*** right. auto.
--- apply symAP.
-- apply symAP.
Qed.
Lemma set_rearrange_v2 :
∀ X Y p, p :: X ++ Y =S= X ++ p :: Y.
Proof. induction X; intros Y p.
- rewrite app_nil_l. rewrite app_nil_l.
apply refSetAP.
- rewrite <- app_comm_cons. rewrite <- app_comm_cons.
assert (H1 := set_rearrange_v1 (X ++ Y) p a).
assert (H2 := IHX Y p).
assert (H3 := set_equal_with_cons_right (p :: X ++ Y) (X ++ p :: Y) a H2).
exact (trnSetAP _ _ _ H1 H3).
Qed.
(* properties of manger_pre_order *)
Lemma manger_pre_order_congruence : brel_congruence (A * P) (brel_product eqA eqP) (manger_pre_order lteA).
Proof. unfold manger_pre_order.
apply brel_product_congruence; auto.
apply brel_trivial_congruence.
Qed.
Lemma manger_pre_order_reflexive : brel_reflexive (A * P) (manger_pre_order lteA).
Proof. unfold manger_pre_order.
apply brel_product_reflexive; auto.
apply brel_trivial_reflexive.
Qed.
Lemma manger_pre_order_transitive :
brel_transitive (A * P) (manger_pre_order lteA).
Proof.
apply brel_product_transitive;
auto.
eapply brel_trivial_transitive.
Qed.
(* properties of equality [EQ1] *)
Lemma equal_manger_phase_1_congruence : brel_congruence _ [EQ1] [EQ1].
Proof. intros X Y Z W. unfold equal_manger_phase_1.
apply brel_set_congruence.
- apply refAP.
- apply symAP.
- apply trnAP.
Qed.
Lemma equal_manger_phase_1_reflexive : brel_reflexive _ [EQ1].
Proof. intro X. unfold equal_manger_phase_1.
apply brel_set_reflexive; auto.
+ apply refAP.
+ apply symAP.
Qed.
Lemma equal_manger_phase_1_symmetric : brel_symmetric _ [EQ1].
Proof. unfold equal_manger_phase_1. intros X Y.
apply brel_set_symmetric; auto.
Qed.
Lemma equal_manger_phase_1_transitive : brel_transitive _ [EQ1].
Proof. unfold equal_manger_phase_1. intros X Y Z.
apply brel_set_transitive; auto.
- apply refAP.
- apply symAP.
- apply trnAP.
Qed.
(* properties of equality [EQM] *)
Lemma equal_manger_congruence : brel_congruence _ [EQM] [EQM].
Proof. intros X Y Z W. unfold equal_manger.
apply equal_manger_phase_1_congruence.
Qed.
Lemma equal_manger_reflexive : brel_reflexive _ [EQM].
Proof. unfold equal_manger; intro X;
apply equal_manger_phase_1_reflexive.
Qed.
Lemma equal_manger_symmetric : brel_symmetric _ [EQM].
Proof. unfold equal_manger; intros X Y;
apply equal_manger_phase_1_symmetric.
Qed.
Lemma equal_manger_transitive : brel_transitive _ [EQM].
Proof. unfold equal_manger; intros X Y Z;
apply equal_manger_phase_1_transitive.
Qed.
(* Idempotence of reductions *)
Definition fst_unique_in_set X :=
∀ a a' p p', (a, p) [in] X -> (a', p') [in] X -> ((a, p) == (a', p')) + (a <A> a').
Lemma singleton_uniqueness : ∀ p, fst_unique_in_set (p :: nil).
Proof. destruct p as [a p].
intros a1 a2 p1 p2 H2 H3. left.
apply in_set_singleton_elim in H2, H3; try (apply symAP).
apply symAP in H3.
exact(trnAP _ _ _ H3 H2).
Qed.
Lemma fst_unique_in_set_congruence :
∀ X Y, X =S= Y -> fst_unique_in_set X -> fst_unique_in_set Y.
Proof. unfold fst_unique_in_set.
intros X Y H1 H2 a a' p p' H3 H4.
assert (H5 : (a, p) [in] X).
{
rewrite (in_set_left_congruence _ _ symAP trnAP (a,p) _ _ H1).
exact H3.
}
assert (H6 : (a', p') [in] X).
{
rewrite (in_set_left_congruence _ _ symAP trnAP (a',p') _ _ H1).
exact H4.
}
exact (H2 _ _ _ _ H5 H6).
Qed.
Lemma fst_unique_in_set_cons_intro :
∀ X a p, (∀ a' p', (a', p') [in] X -> ((a, p) == (a', p')) + (a <A> a'))
-> (fst_unique_in_set X)
-> fst_unique_in_set ((a,p) :: X).
Proof. intros X a p H1 H2. unfold fst_unique_in_set.
intros a' a'' p' p'' H3 H4.
apply in_set_cons_elim in H3.
- apply in_set_cons_elim in H4.
+ destruct H3 as [H3 | H3];
destruct H4 as [H4 | H4].
* left. apply symAP in H3.
exact (trnAP _ _ _ H3 H4).
* destruct (H1 _ _ H4) as [H5 | H5].
-- left. apply symAP in H3.
exact (trnAP _ _ _ H3 H5).
-- right.
apply brel_product_elim in H3.
destruct H3 as [H3 _].
case_eq(eqA a' a''); intro H6; auto.
rewrite (trnA _ _ _ H3 H6) in H5.
discriminate H5.
* destruct (H1 _ _ H3) as [H5 | H5].
-- left. apply symAP in H5.
exact (trnAP _ _ _ H5 H4).
-- right.
apply brel_product_elim in H4.
destruct H4 as [H4 _].
case_eq(eqA a' a''); intro H6; auto.
apply symA in H6. rewrite (trnA _ _ _ H4 H6) in H5.
discriminate H5.
* destruct (H1 _ _ H3) as [H5 | H5];
destruct (H1 _ _ H4) as [H6 | H6].
-- left. apply symAP in H5.
exact (trnAP _ _ _ H5 H6).
-- right.
apply brel_product_elim in H5.
destruct H5 as [H5 _].
case_eq(eqA a' a''); intro H7; auto.
rewrite (trnA _ _ _ H5 H7) in H6.
discriminate H6.
-- right.
apply brel_product_elim in H6.
destruct H6 as [H6 _].
case_eq(eqA a' a''); intro H7; auto.
apply symA in H7. rewrite (trnA _ _ _ H6 H7) in H5.
discriminate H5.
-- case_eq(eqA a' a''); intro H7.
++ left.
destruct (H2 _ _ _ _ H3 H4) as [H8 | H8].
** exact H8.
** rewrite H7 in H8. discriminate H8.
++ right. reflexivity.
+ apply symAP.
- apply symAP.
Qed.
Lemma fst_unique_in_set_cons_elim :
∀ X a p, fst_unique_in_set ((a,p) :: X) ->
(∀ a' p', (a', p') [in] X -> ((a, p) == (a', p')) + (a <A> a'))
*
(fst_unique_in_set X).
Proof. intros X a p H1. split.
- intros a' p' H2.
unfold fst_unique_in_set in H1.
assert (H3 : (a, p) [in] (a, p) :: X).
{
apply in_set_cons_intro; auto.
+ apply symAP.
+ left. apply refAP.
}
assert (H4 : (a', p') [in] (a, p) :: X).
{
apply in_set_cons_intro; auto.
+ apply symAP.
}
exact (H1 _ _ _ _ H3 H4).
- unfold fst_unique_in_set in *.
intros a' a'' p' p'' H2 H3.
assert (H4 : (a', p') [in] (a, p) :: X).
{
apply in_set_cons_intro; auto.
+ apply symAP.
}
assert (H5 : (a'', p'') [in] (a, p) :: X).
{
apply in_set_cons_intro; auto.
+ apply symAP.
}
exact (H1 _ _ _ _ H4 H5).
Qed.
Lemma fst_unique_in_set_concat_elim_right :
∀ X Y, fst_unique_in_set (X ++ Y) -> fst_unique_in_set Y.
Proof. induction X; intros Y H1.
- rewrite app_nil_l in H1. exact H1.
- rewrite <- app_comm_cons in H1.
destruct a as [a p].
apply fst_unique_in_set_cons_elim in H1.
destruct H1 as [_ H1].
apply IHX; auto.
Qed.
Lemma manger_merge_sets_unchanged :
∀ Y a b p p',
Y <> nil ->
a <A> b -> (b, p') [in] ([MMS] Y (a, p)) -> (b, p') [in] Y.
Proof. induction Y; intros s t p p' H0 H1 H2.
- congruence.
- simpl in H2.
destruct a as [a1 p1].
case_eq(eqA s a1); intro H3; rewrite H3 in H2.
+ apply in_set_cons_intro.
* apply symAP.
* right. destruct Y.
-- simpl in H2.
apply bop_or_elim in H2.
destruct H2 as [H2 | H2].
++ apply bop_and_elim in H2.
destruct H2 as [H2 H4].
apply symA in H2. rewrite H2 in H1.
discriminate H1.
++ discriminate H2.
-- assert (H4 : p0 :: Y ≠ nil). congruence.
exact(IHY _ _ _ _ H4 H1 H2).
+ apply in_set_cons_intro.
* apply symAP.
* destruct Y.
-- simpl in H2.
apply bop_or_elim in H2.
destruct H2 as [H2 | H2].
** left. apply bop_and_elim in H2.
destruct H2 as [H2 H4].
apply brel_product_intro; auto.
** apply bop_or_elim in H2.
destruct H2 as [H2 | H2].
--- apply bop_and_elim in H2.
destruct H2 as [H2 H4].
apply symA in H2. rewrite H2 in H1.
discriminate H1.
--- discriminate H2.
-- apply in_set_cons_elim in H2.
++ destruct H2 as [H2 | H2].
** left. exact H2.
** right.
assert (H4 : p0 :: Y ≠ nil). congruence.
exact (IHY _ _ _ _ H4 H1 H2).
++ apply symAP.
Qed.
Lemma manger_merge_sets_unchanged_v2 :
∀ Y a b p p',
Y <> nil ->
a <A> b -> (b, p') [in] Y -> (b, p') [in] ([MMS] Y (a, p)).
Proof. induction Y; intros a1 a2 p1 p2 H0 H1 H2.
- congruence.
- destruct a as [a3 p3].
simpl.
apply in_set_cons_elim in H2.
+ destruct H2 as [H2 | H2];
case_eq(eqA a1 a3); intro H3.
* apply brel_product_elim in H2.
destruct H2 as [H2 H4].
rewrite (trnA _ _ _ H3 H2) in H1.
discriminate H1.
* apply in_set_cons_intro.
-- apply symAP.
-- left. exact H2.
* destruct Y.
-- compute in H2. discriminate H2.
-- assert (H4 : p :: Y ≠ nil). congruence.
exact(IHY _ _ (addP p1 p3) _ H4 H1 H2).
* destruct Y.
-- compute in H2. discriminate H2.
-- assert (H4 : p :: Y ≠ nil). congruence.
assert (H5 := IHY _ _ p1 _ H4 H1 H2).
apply in_set_cons_intro.
++ apply symAP.
++ right. auto.
+ apply symAP.
Qed.
Lemma manger_merge_sets_preserves_uniqueness :
∀ Y p, fst_unique_in_set Y -> fst_unique_in_set ([MMS] Y p).
Proof. induction Y; intros p H1.
- simpl. apply singleton_uniqueness.
- destruct a as [a1 p1]. destruct p as [a2 p2].
apply fst_unique_in_set_cons_elim in H1.
destruct H1 as [H1 H2]. simpl.
case_eq(eqA a2 a1); intro H3.
+ apply IHY. exact H2.
+ apply fst_unique_in_set_cons_intro.
* intros a' p' H4.
case_eq(eqA a1 a'); intro H5.
-- left. apply brel_product_intro; auto.
assert (H6' : (a', p') == (a1, p')).
{
apply brel_product_intro; auto.
}
assert (H6 : (a1, p') [in] [MMS] Y (a2, p2)).
{
exact (in_set_right_congruence _ _ symAP trnAP _ _ _ H6' H4).
}
destruct Y.
++ simpl in H6. apply bop_or_elim in H6.
destruct H6 as [H6 | H6].
** apply bop_and_elim in H6.
destruct H6 as [H6 H7].
apply symA in H6. rewrite H6 in H3.
discriminate H3.
** discriminate H6.
++ assert (H99 : p :: Y <> nil). congruence.
assert (H6'' := manger_merge_sets_unchanged _ _ _ _ _ H99 H3 H6).
destruct (H1 _ _ H6'') as [H7 | H7].
** apply brel_product_elim in H7; auto.
destruct H7 as [_ H7]. exact H7.
** rewrite refA in H7. discriminate H7.
-- right. reflexivity.
* apply IHY; auto.
Qed.
Lemma uop_manger_phase_1_auxiliary_preserves_uniqueness :
∀ X Y, fst_unique_in_set Y -> fst_unique_in_set ([P1AX] Y X).
Proof. induction X; intros Y H1.
- simpl. exact H1.
- simpl. apply IHX.
apply manger_merge_sets_preserves_uniqueness; auto.
Qed.
Lemma manger_merge_set_congruence_right :
∀ Y p1 p2, p1 == p2 -> ([MMS] Y p1) =S= ([MMS] Y p2).
Proof. induction Y; intros [a1 p1] [a2 p2] H1.
- simpl.
apply set_equal_with_cons_left; auto.
- apply brel_product_elim in H1.
destruct H1 as [H1 H2].
destruct a as [a3 p3]. simpl.
case_eq(eqA a1 a3); intro H3; case_eq(eqA a2 a3); intro H4.
+ assert (H5 : (a1, addP p1 p3) == (a2, addP p2 p3)).
{
apply brel_product_intro; auto.
}
exact (IHY _ _ H5).
+ apply symA in H1.
rewrite (trnA _ _ _ H1 H3) in H4.
discriminate H4.
+ rewrite (trnA _ _ _ H1 H4) in H3.
discriminate H3.
+ assert (H5 : (a1, p1) == (a2, p2)).
{
apply brel_product_intro; auto.
}
assert (H6 := IHY _ _ H5).
exact (set_equal_with_cons_right _ _ (a3, p3) H6).
Qed.
Lemma filter_negb :
forall (X : list (A * P))
(f : A -> bool),
List.filter (λ '(s2, _), negb (f s2)) X ++
List.filter (λ '(s2, _), f s2) X =S= X.
Proof.
induction X as [|(ax, bx) X Ihx];
intros f; cbn.
+ reflexivity.
+ case_eq (f ax); intros Ha;
simpl.
++
remember (List.filter (λ '(s2, _),
negb (f s2)) X) as Xt.
remember (List.filter (λ '(s2, _),
f s2) X) as Yt.
apply symSetAP.
eapply trnSetAP.
instantiate (1 := (ax, bx) :: Xt ++ Yt).
+++
apply set_equal_with_cons_right,
symSetAP; subst; apply Ihx.
+++
apply set_rearrange_v2.
++
apply set_equal_with_cons_right,
Ihx.
Qed.
Lemma filter_congruence_gen :
forall X Y f,
(theory.bProp_congruence _
(brel_product eqA eqP) f) ->
X =S= Y ->
filter f X =S=
filter f Y.
Proof.
intros ? ? ? Fcong Ha.
apply brel_set_intro_prop.
+ apply refAP.
+ split.
++
intros (a, p) Hb.
eapply in_set_filter_elim in Hb.
destruct Hb as [Hbl Hbr].
eapply in_set_filter_intro;
[apply symAP | apply Fcong |
split; [exact Hbl | ]].
apply brel_set_elim_prop in Ha.
destruct Ha as [Hal Har].
apply Hal, Hbr.
apply symAP.
apply trnAP.
apply Fcong.
++
intros (a, p) Hb.
eapply in_set_filter_elim in Hb.
destruct Hb as [Hbl Hbr].
eapply in_set_filter_intro;
[apply symAP | apply Fcong |
split; [exact Hbl | ]].
apply brel_set_elim_prop in Ha.
destruct Ha as [Hal Har].
apply Har, Hbr.
apply symAP.
apply trnAP.
apply Fcong.
Qed.
Lemma negb_eqP_congruence :
forall a : P,
theory.bProp_congruence P
eqP (λ x : P, negb (eqP a x)).
Proof.
intros ? x y Hx.
f_equal.
case_eq (eqP a x);
case_eq (eqP a y);
intros Ha Hb;
try reflexivity.
rewrite (trnP _ _ _ Hb Hx) in Ha;
congruence.
apply symP in Hx.
rewrite (trnP _ _ _ Ha Hx) in Hb;
congruence.
Qed.
Lemma bop_neg_bProp_product_cong :
forall (ax : A) (bx : P),
theory.bProp_congruence (A * P) (brel_product eqA eqP)
(λ p : A * P, negb (brel_product eqA eqP p (ax, bx))).
Proof.
intros ax bx (ap, aq) (bp, bq) Ha.
apply f_equal.
apply brel_product_elim in Ha.
destruct Ha as [Hal Har].
eapply brel_product_congruence with
(rS := eqA) (rT := eqP).
eapply cong_eqA.
eapply cong_eqP.
apply brel_product_intro;
[exact Hal | exact Har].
apply brel_product_intro;
[apply refA | apply refP].
Qed.
Lemma bop_theory_bProp_congruence_negb :
forall (pa : A),
theory.bProp_congruence _
(brel_product eqA eqP)
(λ '(s2, _), negb (eqA pa s2)).
Proof.
intros ?.
unfold theory.bProp_congruence.
intros (aa, ap) (ba, bp) He.
f_equal.
apply brel_product_elim in He.
destruct He as [Hel Her].
case_eq (eqA pa aa); intro Hf.
rewrite (trnA pa aa ba Hf Hel);
reflexivity.
case_eq (eqA pa ba); intro Hg.
apply symA in Hel.
rewrite (trnA pa ba aa Hg Hel) in Hf;
congruence.
reflexivity.
Qed.
Lemma bop_congruence_bProp_eqA :
forall (pa : A),
theory.bProp_congruence _
(brel_product eqA eqP)
(λ '(s2, _), eqA pa s2).
Proof.
intros pa.
unfold theory.bProp_congruence.
intros (aa, ap) (ba, bp) He.
apply brel_product_elim in He.
destruct He as [Hel Her].
case_eq (eqA pa aa); intro Hf.
rewrite (trnA pa aa ba Hf Hel);
reflexivity.
case_eq (eqA pa ba); intro Hg.
apply symA in Hel.
rewrite (trnA pa ba aa Hg Hel) in Hf;
congruence.
reflexivity.
Qed.
Lemma manger_merge_set_new_aux_congruence_left :
∀ X Y pa,
X =S= Y ->
(filter (λ '(s2, _), negb (eqA pa s2)) X =S=
filter (λ '(s2, _), negb (eqA pa s2)) Y) ∧
(filter (λ '(s2, _), eqA pa s2) X =S=
filter (λ '(s2, _), eqA pa s2) Y).
Proof.
intros ? ? ? Ha.
pose proof (filter_negb X (fun x => negb (eqA pa x))) as Hb.
pose proof (filter_negb Y (eqA pa)) as Hc.
apply symSetAP in Hc.
pose proof (trnSetAP _ _ _ Ha Hc) as Hd.
split.
+ assert (He : theory.bProp_congruence _
(brel_product eqA eqP)
(λ '(s2, _), negb (eqA pa s2))).
eapply bop_theory_bProp_congruence_negb.
eapply filter_congruence_gen;
[exact He | exact Ha].
+ assert (He : theory.bProp_congruence _
(brel_product eqA eqP)
(λ '(s2, _), eqA pa s2)).
eapply bop_congruence_bProp_eqA.
eapply filter_congruence_gen;
[exact He | exact Ha].
Qed.
(*
If a ∈ X then by idempotence
a + (fold_right f p X) = (fold_right f p X).
*)
Lemma fold_right_idempotent_aux_one :
forall (X : list P) (a p : P)
(f : P -> P -> P),
(forall x y z : P,
eqP (f x (f y z)) (f (f x y) z) = true) ->
(forall x y : P, eqP (f x y) (f y x) = true) ->
(forall (x y w v : P),
eqP x y = true ->
eqP w v = true ->
eqP (f x w) (f y v) = true) ->
(forall x y : P, eqP x y = true ->
eqP (f x y) y = true) ->
in_set eqP X a = true ->
eqP (f a (fold_right f p X)) (fold_right f p X) = true.
Proof.
induction X as [|x X IHx].
+
intros ? ? ? fassoc fcom fcong Ha Hb.
simpl in Hb;
congruence.
+
intros ? ? ? fassoc fcom fcong Ha Hb.
simpl in * |- *.
case_eq ((in_set eqP X a));
case_eq (eqP a x);
intros Hc Hd.
++ (* a = x *)
remember ((fold_right f p X)) as w.
(* I need f to be associative *)
eapply trnP.
eapply fassoc.
eapply fcong.
eapply Ha.
exact Hc.
apply refP.
++
(* Induction case *)
pose proof IHx a p f fassoc fcom fcong Ha Hd as He.
remember ((fold_right f p X)) as w.
eapply trnP with (f a (f w x)).
eapply fcong.
eapply refP.
eapply fcom.
eapply trnP with (f (f a w) x).
eapply fassoc.
eapply trnP with (f w x).
eapply fcong.
exact He.
apply refP.
eapply fcom.
++
remember ((fold_right f p X)) as w.
(* I need f to be associative *)
eapply trnP.