-
Notifications
You must be signed in to change notification settings - Fork 1
/
manger_product.v
3632 lines (3316 loc) · 112 KB
/
manger_product.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
Require Import Coq.Lists.List.
Require Import Coq.Strings.String.
Require Import CAS.coq.common.compute.
Require Import CAS.coq.bs.properties.
Require Import CAS.coq.eqv.properties.
Require Import CAS.coq.eqv.product.
Require Import CAS.coq.eqv.set.
Require Import CAS.coq.eqv.manger_sets.
Require Import CAS.coq.eqv.reduce
CAS.coq.uop.commutative_composition
CAS.coq.uop.properties.
Require Import CAS.coq.sg.properties
CAS.coq.sg.product.
Require Import CAS.coq.sg.lift.
Require Import CAS.coq.sg.product.
Require Import CAS.coq.sg.reduce.
(* for testing *)
Require Import CAS.coq.sg.manger_llex.
Require Import CAS.coq.eqv.nat.
Require Import CAS.coq.sg.min.
Require Import CAS.coq.sg.plus.
Require Import CAS.coq.po.from_sg.
Import ListNotations.
Section Computation.
(*
A = type of active component
P = type of passive component
*)
(* replace bSAP with this one *)
Definition manger_product_phase_0
{A P : Type}
(eqA : brel A)
(eqP : brel P)
(mulA : binary_op A)
(mulP : binary_op P) : binary_op (finite_set (A * P)) :=
bop_lift (brel_product eqA eqP) (bop_product mulA mulP).
(*
Print bop_lift.
Print bop_list_product_left.
Print ltran_list_product.
Print uop_manger.
Print uop_manger_phase_1.
Print manger_phase_1_auxiliary.
*)
Definition bop_manger_product
{A P : Type}
(eqA lteA : brel A)
(eqP : brel P)
(addP : binary_op P)
(mulA : binary_op A)
(mulP : binary_op P) : binary_op (finite_set (A * P)) :=
bop_reduce (@uop_manger A P eqA lteA addP)
(manger_product_phase_0 eqA eqP mulA mulP).
End Computation.
(*
Section Testing.
(* A = nat * nat, P = nat *)
Local Definition eqA := brel_product brel_eq_nat brel_eq_nat.
Local Definition addA := bop_product bop_min bop_min.
Local Definition lteA := brel_lte_left eqA addA.
Local Definition mulA := bop_product bop_plus bop_plus.
Local Definition eqP := brel_eq_nat.
Local Definition addP := bop_min.
Local Definition mulP := bop_plus.
Local Definition manger_add := @bop_manger _ _ eqA lteA eqP addP.
Local Definition manger_mul := bop_manger_product eqA lteA eqP addP mulA mulP.
(*
Check manger_add.
: binary_op (finite_set (nat * nat * nat))
Check manger_mul.
: binary_op (finite_set (nat * nat * nat))
*)
Open Scope nat_scope.
Local Definition s1 := ((1, 2), 8) :: nil.
Local Definition s2 := ((3, 5), 9) :: nil.
Local Definition s3 := ((0, 5), 9) :: nil.
Local Definition s4 := ((1, 2), 10) :: nil.
Local Definition s5 := ((1, 2), 1):: ((1, 2), 2)::((1, 2), 3) :: nil.
Compute (manger_add s1 s2). (* = (1, 2, 8) :: nil *)
Compute (manger_add s1 s3). (* = (0, 5, 9) :: (1, 2, 8) :: nil *)
Compute (manger_add s1 s4). (* = (1, 2, 8) :: nil *)
Compute (manger_add s1 s1). (* = (1, 2, 8) :: nil *)
Compute (manger_add s5 nil). (* = (1, 2, 1) :: nil *)
Compute (manger_add nil s5). (* = (1, 2, 1) :: nil *)
Compute (manger_mul s1 s2). (* = (4, 7, 17) :: nil *)
Compute (manger_mul s2 s5). (* = (4, 7, 10) :: nil *)
Compute (manger_add (manger_mul s5 s1) (manger_mul s5 s3)).
(* (1, 7, 10) :: (2, 4, 9) :: nil *)
Compute (manger_mul s5 (manger_add s1 s3)).
(* (2, 4, 9) :: (1, 7, 10) :: nil *)
End Testing.
*)
Section Theory.
Variables
(A P : Type)
(zeroP : P) (* 0 *)
(eqA lteA : brel A)
(eqP : brel P)
(addP : binary_op P)
(wA : A)
(wP : P)
(fA : A -> A)
(ntA : brel_not_trivial A eqA fA)
(conA : brel_congruence A eqA eqA)
(mulA : binary_op A)
(mulP : binary_op P)
(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)
(ntot : properties.brel_not_total A lteA)
(conP : brel_congruence P eqP eqP)
(cong_addP : bop_congruence P eqP addP)
(conLte : brel_congruence A eqA lteA)
(refLte : brel_reflexive A lteA)
(trnLte : brel_transitive A lteA)
(addP_assoc : bop_associative P eqP addP)
(addP_com : bop_commutative P eqP addP)
(idemP : bop_idempotent P eqP addP)
(zeropLid : ∀ (p : P), eqP (addP zeroP p) p = true)
(zeropRid : ∀ (p : P), eqP (addP p zeroP) p = true).
(* Assumption about mulA and mulP *)
Variables
(mulA_assoc : bop_associative A eqA mulA)
(mulP_assoc : bop_associative P eqP mulP)
(cong_mulA : bop_congruence A eqA mulA)
(cong_mulP : bop_congruence P eqP mulP)
(mulP_addP_right_distributive :
(bop_right_distributive P eqP addP mulP)).
Local Notation "[EQP0]" := (brel_set (brel_product eqA eqP)) (only parsing).
Local Notation "[EQP1]" := (equal_manger_phase_1 eqA eqP addP) (only parsing).
Local Notation "[MP1]" := (uop_manger_phase_1 eqA addP) (only parsing).
Local Notation "[MPP0]" := (manger_product_phase_0 eqA eqP mulA mulP) (only parsing).
Local Notation "[MP]" := (bop_manger_product eqA lteA eqP addP mulA mulP) (only parsing).
Local Notation "[MR]" := (@uop_manger_phase_2 A P lteA) (only parsing).
Local Notation "[EQ]" := (equal_manger eqA lteA eqP addP) (only parsing).
(*
X := [(a, b); (c, d); (a, e)]
Y := [(u, v); (x, y); (x, t)]
1. (uop_manger_phase_1 eqA addP X) =
[(a, b + e); (c, d)]
2. (manger_product_phase_0 eqA eqP mulA mulP
(uop_manger_phase_1 eqA addP X) Y) =
[
(mulA a u, mulP (b + e) v);
(mulA a x, mulP (b + e) y;
(mulA a x, mulP (b + e) t);
(mulA c u, mulP d v);
(mulA c x, mulP d y);
(mulA c x, mulP d t);
]
3. (manger_product_phase_0 eqA eqP mulA mulP X Y) =
[
(mulA a u, mulP b v);
(mulA a x, mulP b y);
(mulA a x, mulP b t);
(mulA c u, mulP d v);
(mulA c x, mulP d y);
(mulA c x, mulP d t);
(mulA a u, mulP e v);
(mulA a x, mulP e y);
(mulA a x, mulP e t)
]
Now, let's say I want to filter (mulA a x) from
equation 3 and 2.
2 gives me:
[
(mulA a x, mulP (b + e) y;
(mulA a x, mulP (b + e) t);
]
and 3 gives me:
[
(mulA a x, mulP b y);
(mulA a x, mulP b t);
(mulA a x, mulP e y);
(mulA a x, mulP e t)
]
(* addP is + *)
mulP needs to distribute over addP
Prove that:
mulP (b + e) y + mulP (b + e) t =
mulP b y + mulP b t + mulP e y +
mulP e t
*)
Lemma addP_gen_idempotent :
∀ x y : P,
eqP x y = true → eqP (addP x y) y = true.
Proof.
intros * Ha.
assert (Hb := cong_addP _ _ _ _ Ha (refP y)).
assert (Hc := idemP y).
exact (trnP _ _ _ Hb Hc).
Qed.
Local Notation "x =S= y" := (manger_llex.eqSAP A P eqA eqP x y = true)
(at level 70, only parsing).
Local Notation "a == b" := (brel_product eqA eqP a b = true)
(at level 70).
Lemma bProp_cong :
forall au,
theory.bProp_congruence (A * P) (brel_product eqA eqP)
(λ '(x, _), eqA x au).
Proof.
intros * (ax, bx) (aw, bw) Ha;
cbn in Ha.
eapply Bool.andb_true_iff in Ha.
destruct Ha as (Hal & Har).
case_eq (eqA ax au);
case_eq (eqA aw au);
intros Hb Hc; try reflexivity.
rewrite (trnA _ _ _ (symA _ _ Hal) Hc) in
Hb; congruence.
rewrite (trnA _ _ _ Hal Hb) in Hc;
congruence.
Qed.
Lemma bop_cong :
bop_congruence (A * P) (brel_product eqA eqP) (bop_product mulA mulP).
Proof.
eapply bop_product_congruence; assumption.
Qed.
Lemma bop_assoc :
bop_associative (A * P) (manger_llex.eqAP A P eqA eqP)
(bop_product mulA mulP).
Proof.
eapply bop_product_associative; assumption.
Qed.
(* It's good idea to create a hint database and
writing some custom tactics using coq-elpi *)
Lemma brel_set_manger_product_phase_0_dist :
forall (X Y U : finite_set (A * P)),
brel_set (brel_product eqA eqP)
(manger_product_phase_0 eqA eqP mulA mulP (X ++ Y) U)
(manger_product_phase_0 eqA eqP mulA mulP X U ++
manger_product_phase_0 eqA eqP mulA mulP Y U) = true.
Proof.
intros *.
eapply brel_set_intro_prop;
[eapply refAP | split; intros (ax, ay) Ha]; try assumption.
+
eapply in_set_bop_lift_elim in Ha;
[| eapply refAP | eapply symAP]; try assumption;
destruct Ha as ((xa, xp) & (ya, yp) & (Ha & Hb) & Hc).
(* Now replace *)
eapply set.in_set_right_congruence with
(bop_product mulA mulP (xa, xp) (ya, yp));
[eapply symAP | eapply trnAP | eapply brel_product_symmetric |
]; try assumption.
(* case analysis on Ha *)
eapply set.in_set_concat_elim in Ha;
[| eapply symAP]; try assumption.
destruct Ha as [Ha | Ha].
++
(* go left *)
eapply set.in_set_concat_intro; left.
eapply in_set_bop_lift_intro;
[eapply refAP | eapply trnAP | eapply symAP | eapply
bop_cong | exact Ha | exact Hb];
try assumption.
++
(* go right *)
eapply set.in_set_concat_intro; right.
eapply in_set_bop_lift_intro;
[eapply refAP | eapply trnAP | eapply symAP | eapply
bop_cong | exact Ha | exact Hb];
try assumption.
+
(* I need find out (xa, xp) (ya, yp) such
that ax = mulA xa ya & ay = mulP xp yp from Ha *)
eapply set.in_set_concat_elim in Ha;
[| eapply symAP]; try assumption.
(* case analysis on Ha*)
destruct Ha as [Ha | Ha].
++
eapply in_set_bop_lift_elim in Ha;
[| eapply refAP | eapply symAP]; try assumption;
destruct Ha as ((xa, xp) & (ya, yp) & (Ha & Hb) & Hc).
eapply in_set_bop_lift_intro_v2;
[eapply refAP | eapply trnAP | eapply symAP |
eapply bop_cong | eapply set.in_set_concat_intro; left;
exact Ha | exact Hb | ]; try assumption.
++
eapply in_set_bop_lift_elim in Ha;
[| eapply refAP | eapply symAP]; try assumption;
destruct Ha as ((xa, xp) & (ya, yp) & (Ha & Hb) & Hc).
eapply in_set_bop_lift_intro_v2;
[eapply refAP | eapply trnAP | eapply symAP |
eapply bop_cong | eapply set.in_set_concat_intro; right;
exact Ha | exact Hb | ]; try assumption.
Qed.
Lemma brel_set_manger_product_phase_0_comm :
forall (X Y U : finite_set (A * P)),
brel_set (brel_product eqA eqP)
(manger_product_phase_0 eqA eqP mulA mulP (X ++ Y) U)
(manger_product_phase_0 eqA eqP mulA mulP (Y ++ X) U) = true.
Proof.
intros *.
eapply brel_set_transitive;
[eapply refAP | eapply symAP | eapply trnAP |
eapply brel_set_manger_product_phase_0_dist |
eapply brel_set_symmetric];
try assumption.
eapply brel_set_transitive;
[eapply refAP | eapply symAP | eapply trnAP |
eapply brel_set_manger_product_phase_0_dist |
eapply brel_set_symmetric];
try assumption.
eapply brel_set_intro_prop;
[eapply refAP|split; intros (ax, bx) Ha];
try assumption.
+
eapply set.in_set_concat_intro.
eapply set.in_set_concat_elim in Ha;
[| eapply symAP]; try assumption.
destruct Ha as [Ha | Ha];
[right | left]; assumption.
+
eapply set.in_set_concat_intro.
eapply set.in_set_concat_elim in Ha;
[| eapply symAP]; try assumption.
destruct Ha as [Ha | Ha];
[right | left]; assumption.
Qed.
Lemma brel_set_manger_product_phase_0_swap :
forall (X Y U : finite_set (A * P)) au bu,
brel_set (brel_product eqA eqP)
(manger_product_phase_0 eqA eqP mulA mulP (((au, bu) :: X) ++ Y) U)
(manger_product_phase_0 eqA eqP mulA mulP (X ++ (au, bu) :: Y) U) = true.
Proof.
intros *.
remember (((au, bu) :: X)) as Xa.
remember ((au, bu) :: Y) as Ya.
eapply brel_set_transitive;
[eapply refAP | eapply symAP | eapply trnAP |
eapply brel_set_manger_product_phase_0_dist |
eapply brel_set_symmetric];
try assumption.
eapply brel_set_transitive;
[eapply refAP | eapply symAP | eapply trnAP |
eapply brel_set_manger_product_phase_0_dist |
eapply brel_set_symmetric];
try assumption.
eapply brel_set_intro_prop;
[eapply refAP|split; intros (ax, bx) Ha];
try assumption.
+
subst; cbn in Ha |- *.
eapply set.in_set_concat_elim in Ha;
[| eapply symAP]; try assumption.
destruct Ha as [Ha | Ha].
eapply union.in_set_uop_duplicate_elim_elim,
set.in_set_concat_elim in Ha;
[| eapply symAP]; try assumption.
destruct Ha as [Ha | Ha].
++
(* go right; left *)
eapply set.in_set_concat_intro; right;
eapply union.in_set_dup_elim_intro;
[eapply symAP | eapply trnAP | eapply
set.in_set_concat_intro; left]; try assumption.
++
eapply set.in_set_concat_intro; left.
unfold manger_product_phase_0, bop_lift.
eapply union.in_set_dup_elim_intro;
[eapply symAP | eapply trnAP | exact Ha];
try assumption.
++
eapply set.in_set_concat_intro; right;
eapply union.in_set_dup_elim_intro;
[eapply symAP | eapply trnAP | eapply
set.in_set_concat_intro; right]; try assumption.
eapply union.in_set_uop_duplicate_elim_elim in Ha;
try assumption.
+
(* other direction *)
subst;
eapply set.in_set_concat_elim in Ha;
[|eapply symAP]; try assumption.
destruct Ha as [Ha | Ha].
++
eapply set.in_set_concat_intro; left;
cbn; eapply union.in_set_uop_duplicate_elim_intro;
[eapply symAP | eapply trnAP | ]; try assumption.
eapply set.in_set_concat_intro; right.
unfold manger_product_phase_0 in Ha.
eapply in_set_bop_lift_elim in Ha;
[| eapply refAP | eapply symAP]; try assumption;
destruct Ha as ((xa, xp) & (ya, yp) & (Ha & Hb) & Hc).
eapply set.in_set_right_congruence with
(bop_product mulA mulP (xa, xp) (ya, yp));
[eapply symAP | eapply trnAP | eapply brel_product_symmetric |
]; try assumption.
eapply in_set_list_product_intro;
[eapply refAP | eapply trnAP | eapply symAP |
eapply bop_cong | exact Ha | exact Hb];
try assumption.
++
cbn in Ha |- *;
eapply union.in_set_uop_duplicate_elim_elim,
set.in_set_concat_elim in Ha;
[| eapply symAP]; try assumption.
destruct Ha as [Ha | Ha].
+++
eapply set.in_set_concat_intro; left;
eapply union.in_set_uop_duplicate_elim_intro;
[eapply symAP | eapply trnAP | ];
try assumption.
eapply set.in_set_concat_intro; left;
assumption.
+++
eapply set.in_set_concat_intro; right;
eapply union.in_set_uop_duplicate_elim_intro;
[eapply symAP | eapply trnAP | ];
try assumption.
Qed.
(* requires commutativity *)
Lemma brel_set_manger_product_phase_0_swap_v1
(mulA_comm : bop_commutative A eqA mulA)
(mulP_comm : bop_commutative P eqP mulP) :
forall (X Y : finite_set (A * P)),
brel_set (brel_product eqA eqP)
(manger_product_phase_0 eqA eqP mulA mulP X Y)
(manger_product_phase_0 eqA eqP mulA mulP Y X) = true.
Proof.
intros *;
eapply brel_set_intro_prop;
[eapply refAP | split; intros (ax, bx) Ha];
try assumption.
+
eapply in_set_bop_lift_elim in Ha;
[| eapply refAP | eapply symAP]; try assumption;
destruct Ha as ((xa, xp) & (ya, yp) & (Ha & Hb) & Hc).
(* Now replace *)
eapply set.in_set_right_congruence with
(bop_product mulA mulP (xa, xp) (ya, yp));
[eapply symAP | eapply trnAP | eapply brel_product_symmetric |
]; try assumption.
eapply set.in_set_right_congruence with
(bop_product mulA mulP (ya, yp) (xa, xp));
[eapply symAP | eapply trnAP | eapply brel_product_symmetric | ];
try assumption;
[eapply brel_product_symmetric| ];
try assumption.
eapply brel_product_intro;
[eapply mulA_comm | eapply mulP_comm].
eapply in_set_bop_lift_intro;
[eapply refAP | eapply trnAP | eapply symAP |
eapply bop_cong | exact Hb | exact Ha];
try assumption.
+
eapply in_set_bop_lift_elim in Ha;
[| eapply refAP | eapply symAP]; try assumption;
destruct Ha as ((xa, xp) & (ya, yp) & (Ha & Hb) & Hc).
(* Now replace *)
eapply set.in_set_right_congruence with
(bop_product mulA mulP (xa, xp) (ya, yp));
[eapply symAP | eapply trnAP | eapply brel_product_symmetric |
]; try assumption.
eapply set.in_set_right_congruence with
(bop_product mulA mulP (ya, yp) (xa, xp));
[eapply symAP | eapply trnAP | eapply brel_product_symmetric | ];
try assumption;
[eapply brel_product_symmetric| ];
try assumption.
eapply brel_product_intro;
[eapply mulA_comm | eapply mulP_comm].
eapply in_set_bop_lift_intro;
[eapply refAP | eapply trnAP | eapply symAP |
eapply bop_cong | exact Hb | exact Ha];
try assumption.
Qed.
Lemma manger_product_phase_0_comm :
forall (X Y U : finite_set (A * P)) au ax bx,
eqP
((matrix_algorithms.sum_fn zeroP addP snd
(List.filter (λ '(x, _), eqA x au)
(manger_product_phase_0 eqA eqP mulA mulP
(((ax, bx) :: X) ++ Y) U))))
(matrix_algorithms.sum_fn zeroP addP snd
(List.filter (λ '(x, _), eqA x au)
(manger_product_phase_0 eqA eqP mulA mulP
(X ++ ((ax, bx) :: Y)) U))) = true.
Proof.
intros *.
eapply sum_fn_congruence_general_set with
(eqA := eqA) (lteA := lteA) (fA := fA);
try assumption.
+ eapply addP_gen_idempotent.
+
repeat rewrite list_filter_lib_filter_same;
eapply filter_congruence_gen;
try assumption; try (eapply bProp_cong).
eapply brel_set_manger_product_phase_0_swap.
Qed.
Lemma manger_product_phase_0_dist :
forall (X Y U : finite_set (A * P)) au,
eqP
(matrix_algorithms.sum_fn zeroP addP snd
(List.filter (λ '(x, _), eqA x au)
(manger_product_phase_0 eqA eqP mulA mulP (X ++ Y) U)))
(matrix_algorithms.sum_fn zeroP addP snd
(List.filter (λ '(x, _), eqA x au)
(manger_product_phase_0 eqA eqP mulA mulP X U ++
manger_product_phase_0 eqA eqP mulA mulP Y U))) = true.
Proof.
intros *.
eapply sum_fn_congruence_general_set with
(eqA := eqA) (lteA := lteA) (fA := fA);
try assumption.
+ eapply addP_gen_idempotent.
+
repeat rewrite list_filter_lib_filter_same;
eapply filter_congruence_gen;
try assumption; try (eapply bProp_cong).
eapply brel_set_manger_product_phase_0_dist.
Qed.
(* *)
Lemma set_in_set_non_empty_left :
forall (X Y : finite_set (A * P)) au q,
set.in_set (brel_product eqA eqP)
(manger_product_phase_0 eqA eqP mulA mulP X Y) (au, q) = true ->
brel_set (brel_product eqA eqP) [] X = false.
Proof.
intros * Ha.
eapply in_set_bop_lift_elim in Ha;
[| eapply refAP | eapply symAP];
try assumption;
destruct Ha as ((xa, xb) & (ya, yb) & (Ha, Hb) & Hc);
destruct Y; destruct X; cbn in Ha, Hb;
try congruence;
cbn; split; try reflexivity.
Qed.
Lemma set_in_set_non_empty_right :
forall (X Y : finite_set (A * P)) au q,
set.in_set (brel_product eqA eqP)
(manger_product_phase_0 eqA eqP mulA mulP X Y) (au, q) = true ->
brel_set (brel_product eqA eqP) [] Y = false.
Proof.
intros * Ha.
eapply in_set_bop_lift_elim in Ha;
[| eapply refAP | eapply symAP];
try assumption;
destruct Ha as ((xa, xb) & (ya, yb) & (Ha, Hb) & Hc);
destruct Y; destruct X; cbn in Ha, Hb;
try congruence;
cbn; split; try reflexivity.
Qed.
Lemma brel_set_manger_product_phase_0_non_empty_forward :
forall (s t : finite_set (A * P)),
brel_set (brel_product eqA eqP) []
(manger_product_phase_0 eqA eqP mulA mulP s t) = false ->
brel_set (brel_product eqA eqP) [] s = false ∧
brel_set (brel_product eqA eqP) [] t = false.
Proof.
intros * Ha.
eapply brel_set_false_elim_prop in Ha.
destruct Ha as [((a1, b1) & Ha & Hb) |
((a1, b1) & Ha & Hb)].
+
cbn in Ha; congruence.
+
refine (conj _ _ );
[eapply set_in_set_non_empty_left |
eapply set_in_set_non_empty_right]; exact Ha.
+ eapply refAP; try assumption.
+ eapply symAP; try assumption.
Qed.
Lemma non_empty_list :
forall (X Y : finite_set (A * P)),
(∀ a : A * P,
set.in_set (manger_llex.eqAP A P eqA eqP) X a = true ->
set.in_set (manger_llex.eqAP A P eqA eqP) Y a = true) ->
brel_set (brel_product eqA eqP) [] X = false ->
brel_set (brel_product eqA eqP) [] Y = false.
Proof.
intros * Ha Hb.
destruct X as [|(ax, bx) X];
cbn in Hb |- *;
[congruence |].
specialize (Ha (ax, bx));
cbn in Ha; rewrite refA, refP in Ha;
cbn in Ha.
specialize (Ha eq_refl).
destruct Y;
cbn in Ha |- *;
[congruence | reflexivity].
Qed.
Lemma manger_product_phase_0_cong :
bop_congruence _
(manger_llex.eqSAP A P eqA eqP)
(manger_product_phase_0 eqA eqP mulA mulP).
Proof.
intros ? ? ? ? Ha Hb.
eapply brel_set_elim_prop in Ha, Hb;
[| eapply symAP| eapply trnAP| eapply symAP|
eapply trnAP]; try assumption;
destruct Ha as (Hal & Har);
destruct Hb as (Hbl & Hbr).
eapply brel_set_intro_prop;
[eapply refAP| split; intros (au, av) Hc];
try assumption.
+
eapply in_set_bop_lift_elim in Hc;
[| eapply refAP | eapply symAP];
try assumption;
destruct Hc as ((xa, xb) & (ya, yb) & (Ha, Hb) & Hc).
eapply in_set_bop_lift_intro_v2;
[eapply refAP | eapply trnAP | eapply symAP |
eapply bop_cong | eapply Hal; exact Ha | eapply Hbl; exact Hb |
exact Hc]; try assumption.
+
eapply in_set_bop_lift_elim in Hc;
[| eapply refAP | eapply symAP];
try assumption;
destruct Hc as ((xa, xb) & (ya, yb) & (Ha, Hb) & Hc).
eapply in_set_bop_lift_intro_v2;
[eapply refAP | eapply trnAP | eapply symAP | eapply bop_cong |
eapply Har; exact Ha | eapply Hbr; exact Hb | exact Hc ];
try assumption.
Qed.
Lemma filter_not_in_set_no_dup :
forall (Y : finite_set (A * P)) (ah : A),
set.in_set eqA (map fst Y) ah = false ->
filter (λ '(s2, _), eqA ah s2) Y = [] ∧
filter (λ '(s2, _), negb (eqA ah s2)) Y = Y.
Proof.
induction Y as [|(ax, bx) Y IHy].
+
cbn; intros ? Ha.
auto.
+
cbn; intros ? Ha.
case_eq (eqA ah ax);
cbn; intros Hb.
rewrite Hb in Ha.
cbn in Ha; congruence.
rewrite Hb in Ha;
cbn in Ha.
destruct (IHy _ Ha) as (IHl & IHr).
split; auto.
f_equal. auto.
Qed.
Lemma uop_dup_elim_membership_cong :
forall (X : finite_set (A * P)),
set.uop_duplicate_elim (brel_product eqA eqP) X =S= X.
Proof.
intros *.
eapply brel_set_intro_prop;
[eapply refAP | split; intros (xa, xb) Ha];
try assumption.
+
eapply union.in_set_uop_duplicate_elim_elim; try assumption.
+
eapply union.in_set_uop_duplicate_elim_intro;
[eapply symAP | eapply trnAP | exact Ha];
try assumption.
Qed.
Lemma ltrans_list_app :
forall(X Y : list (A * P)) (ah : A) (bh : P),
ltran_list_product (bop_product mulA mulP) (ah, bh) (X ++ Y) =
ltran_list_product (bop_product mulA mulP) (ah, bh) X ++
ltran_list_product (bop_product mulA mulP) (ah, bh) Y.
Proof.
induction X as [|(ax, bx) X IHx].
+
simpl; intros; reflexivity.
+
simpl; intros *.
rewrite IHx; f_equal.
Qed.
Lemma manger_merge_set_no_dup :
forall (X Y : finite_set (A * P)),
no_dup eqA (map fst Y) = true ->
no_dup eqA (map fst
(fold_left (manger_merge_sets_new eqA addP) X Y)) = true.
Proof.
induction X as [|(ax, bx) X IHx].
+
simpl; intros * Ha.
exact Ha.
+
simpl; intros * Ha.
eapply IHx.
eapply no_dup_mmsn with (eqP := eqP);
try assumption.
Qed.
(* begin Admit *)
(* it is true! *)
Lemma mmsn_diff_swap_gen :
forall V au av ax bx,
((manger_merge_sets_new eqA addP)
((manger_merge_sets_new eqA addP) V (au, av)) (ax, bx)) =S=
((manger_merge_sets_new eqA addP)
((manger_merge_sets_new eqA addP) V (ax, bx)) (au, av)).
Proof.
intros ? ? ? ? ?.
eapply brel_set_intro_prop;
[eapply refAP | split; intros (ma, mb) Ha];
try assumption.
+
eapply set.in_set_concat_elim in Ha;
[| eapply symAP];
try assumption.
eapply set.in_set_concat_intro.
destruct Ha as [Ha | Ha].
++
left; simpl in Ha |- *.
cbn in Ha |- *.
repeat rewrite <-list_filter_lib_filter_same in Ha |- *.
repeat rewrite filter_app in Ha |- *.
eapply set.in_set_concat_elim in Ha;
[| eapply symAP]; try assumption.
eapply set.in_set_concat_intro.
destruct Ha as [Ha | Ha];
[left | right].
+++
rewrite filter_filter_curry in Ha |- *.
rewrite <-Ha.
f_equal. f_equal.
eapply FunctionalExtensionality.functional_extensionality;
intros (am, bm).
case_eq (eqA au am);
case_eq (eqA ax am);
intros Hb Hc; cbn;
try reflexivity.
+++
Admitted.
(* end *)
Lemma fold_left_cong_aux_aux_1 :
forall (X Y : finite_set (A * P)) au bu ax bx,
no_dup eqA (map fst Y) = true ->
eqA ax au = true ->
eqP bx bu = true ->
(fold_left (manger_merge_sets_new eqA addP) X
(manger_merge_sets_new eqA addP
(manger_merge_sets_new eqA addP Y (au, bu)) (ax, bx))) =S=
(fold_left (manger_merge_sets_new eqA addP) X
(manger_merge_sets_new eqA addP Y (au, bu))).
Proof.
Admitted.
(* use mmsn_diff_swap *)
Lemma fold_left_cong_aux_aux_2 :
forall (X Y : finite_set (A * P)) au bu ax bx,
no_dup eqA (map fst Y) = true ->
eqA ax au = false ->
(fold_left (manger_merge_sets_new eqA addP) X
(manger_merge_sets_new eqA addP
(manger_merge_sets_new eqA addP Y (ax, bx)) (au, bu))) =S=
(fold_left (manger_merge_sets_new eqA addP) X
(manger_merge_sets_new eqA addP
(manger_merge_sets_new eqA addP Y (au, bu)) (ax, bx))).
Proof.
Admitted.
Lemma fold_left_cong_aux_aux_3 :
forall (X Y : finite_set (A * P)) au bu ax bx,
no_dup eqA (map fst Y) = true ->
eqA ax au = true ->
(* eqP bx bu = false *) (* I don't need but keep it *)
(fold_left (manger_merge_sets_new eqA addP) X
(manger_merge_sets_new eqA addP
(manger_merge_sets_new eqA addP Y (au, bu)) (ax, bx))) =S=
(fold_left (manger_merge_sets_new eqA addP) X
(manger_merge_sets_new eqA addP Y (au, addP bu bx))).
Proof.
Admitted.
Lemma fold_left_cong_aux_1 :
forall (X Y : finite_set (A * P)) au bu,
no_dup eqA (map fst Y) = true ->
manger_llex.eqSAP A P eqA eqP
(fold_left (manger_merge_sets_new eqA addP) X
(manger_merge_sets_new eqA addP Y (au, bu)))
(fold_left (manger_merge_sets_new eqA addP)
(filter (λ p : A * P, negb (brel_product eqA eqP p (au, bu))) X)
(manger_merge_sets_new eqA addP Y (au, bu))) = true.
Proof.
induction X as [|(ax, bx) X IHx].
+
simpl;
intros * Ha.
eapply refSAP; try assumption.
+
(* induction case *)
(* case analysis *)
simpl; intros * Ha.
case_eq (eqP bx bu);
case_eq (eqA ax au);
intros Hb Hc; simpl.
++
specialize (IHx Y au bu Ha).
eapply trnSAP with
(t := (fold_left (manger_merge_sets_new eqA addP) X
(manger_merge_sets_new eqA addP Y (au, bu))));
try assumption.
(* Prove it separately *)
eapply fold_left_cong_aux_aux_1;
try assumption.
++
assert (Hd : no_dup eqA (map fst
(manger_merge_sets_new eqA addP Y (ax, bx))) = true).
eapply no_dup_mmsn with (eqP := eqP);
try assumption.
specialize (IHx (manger_merge_sets_new eqA addP Y (ax, bx))
au bu Hd).
(*
I can replace
(manger_merge_sets_new eqA addP
(manger_merge_sets_new eqA addP Y (au, bu)) (
ax, bx))
by
(manger_merge_sets_new eqA addP
(manger_merge_sets_new eqA addP Y [(au, bu); (ax, bx)]
Now My goal turns into
(fold_left (manger_merge_sets_new eqA addP) X
(manger_merge_sets_new eqA addP Y [(au, bu); (ax, bx)])) =S=
(fold_left (manger_merge_sets_new eqA addP)
(filter (λ p : A * P, negb (brel_product eqA eqP p (au, bu))) X)
(manger_merge_sets_new eqA addP Y [(au, bu); (ax, bx)]))
After simplification, the goal is same as IHx
*)
remember ((filter (λ p : A * P, negb
(brel_product eqA eqP p (au, bu))) X)) as Xa.
eapply trnSAP with
(t := (fold_left (manger_merge_sets_new eqA addP) X
(manger_merge_sets_new eqA addP
(manger_merge_sets_new eqA addP Y (ax, bx)) (au, bu))));
try assumption;
[eapply fold_left_cong_aux_aux_2; try assumption;
case_eq (eqA au ax); intro He; try reflexivity;
rewrite (symA _ _ He) in Hb; congruence| ];
try assumption.
eapply trnSAP with
(t := (fold_left (manger_merge_sets_new eqA addP) Xa
(manger_merge_sets_new eqA addP
(manger_merge_sets_new eqA addP Y (ax, bx)) (au, bu))));
try assumption.
eapply fold_left_cong_aux_aux_2;
try assumption.
++
(* easy *)
(*
In the goal,
(manger_merge_sets_new eqA addP
(manger_merge_sets_new eqA addP Y (au, bu)) (
ax, bx)) can be replace by
(manger_merge_sets_new eqA addP Y [(au, bu); (ax, bx)])
*)
assert (Hd : no_dup eqA (map fst
(manger_merge_sets_new eqA addP Y (ax, bx))) = true).
eapply no_dup_mmsn with (eqP := eqP);
try assumption.
specialize (IHx (manger_merge_sets_new eqA addP Y (ax, bx))
au bu Hd).
admit.
++
assert (Hd : no_dup eqA (map fst
(manger_merge_sets_new eqA addP Y (ax, bx))) = true).
eapply no_dup_mmsn with (eqP := eqP);
try assumption.
specialize (IHx (manger_merge_sets_new eqA addP Y (ax, bx))
au bu Hd).
(*
*)
Admitted.
Lemma fold_left_cong_aux_2:
forall (X Y : finite_set (A * P)) ax bx,
no_dup eqA (map fst Y) = true ->
set.in_set (brel_product eqA eqP) X (ax, bx) = true ->
manger_llex.eqSAP A P eqA eqP
(fold_left (manger_merge_sets_new eqA addP)
(filter (λ p : A * P, negb (brel_product eqA eqP p (ax, bx))) X)
(manger_merge_sets_new eqA addP Y (ax, bx)))
(fold_left (manger_merge_sets_new eqA addP) X Y) = true.
Proof.
Admitted.
(* end admit *)
(*