-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIPPGrammarTheorems.v
1414 lines (1295 loc) · 61.2 KB
/
IPPGrammarTheorems.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 MyUtils.
Require Export IPPGrammar.
Section IPPGrammarTheorems.
Create HintDb IPPGrammar.
Hint Resolve CPrio_infix_infix_1 CPrio_infix_infix_2 CPrio_prefix_infix CPrio_infix_prefix CLeft_prefix_infix
CRight_infix_prefix CRight_postfix_infix CRight_postfix_infix CPrio_postfix_infix CPrio_postfix_prefix
CPrio_infix_postfix CLeft_infix_postfix CPrio_prefix_postfix CLeft_prefix_postfix CRight_postfix_prefix CLeft CRight
HMatch InfixMatch PrefixMatch PostfixMatch Atomic_wf Infix_wf Prefix_wf Postfix_wf Atomic_cf Infix_cf Prefix_cf
Postfix_cf Atomic_drmcf Infix_drmcf Prefix_drmcf Postfix_drmcf Match_rm InfixMatch_rm PrefixMatch_rm InfixMatch_drm
PrefixMatch_drm PostfixMatch_drm Atomic_dlmcf Infix_dlmcf Prefix_dlmcf Postfix_dlmcf Match_lm InfixMatch_lm
PostfixMatch_lm InfixMatch_dlm PrefixMatch_dlm PostfixMatch_dlm
: IPPGrammar.
(*
##############################################
##############################################
##############################################
*)
(* The following lemmas relate to the functions boolean functions that check for conflicts in trees,
such as [is_i_conflict_pattern]. *)
Lemma is_i_conflict_pattern_true {g} (pr : drules g) q :
i_conflict_pattern pr q <-> is_i_conflict_pattern pr q = true.
Proof.
split; intro.
- inv H; simpl; auto using decide_True, decide_False.
+ destruct (decide (prio pr (InfixProd o1) (InfixProd o2))); auto using decide_True, decide_False.
+ destruct (decide (prio pr (InfixProd o1) (InfixProd o2))); auto using decide_True, decide_False.
+ destruct (decide (prio pr (PrefixProd o1) (InfixProd o2))); auto using decide_True, decide_False.
+ destruct (decide (prio pr (PostfixProd o1) (InfixProd o2))); auto using decide_True, decide_False.
- destruct q; inv H.
+ destruct q1, q2; inv H1.
* destruct q2_1, q2_2; inv H0.
destruct (decide (prio pr (InfixProd o) (InfixProd o0))); eauto with IPPGrammar.
destruct (decide (left_a pr (InfixProd o) (InfixProd o0))); eauto with IPPGrammar.
inv H1.
* destruct q1_1, q1_2; inv H0.
destruct (decide (prio pr (InfixProd o) (InfixProd o0))); eauto with IPPGrammar.
destruct (decide (right_a pr (InfixProd o) (InfixProd o0))); eauto with IPPGrammar.
inv H1.
* destruct q1_1, q1_2; inv H0.
* destruct q1_1, q1_2; inv H0.
* destruct q1_1, q1_2; inv H0.
+ destruct q; inv H1.
destruct q1, q2; inv H0.
destruct (decide (prio pr (PrefixProd o) (InfixProd o0))); eauto with IPPGrammar.
destruct (decide (left_a pr (PrefixProd o) (InfixProd o0))); eauto with IPPGrammar.
inv H1.
+ destruct q; inv H1.
destruct q1, q2; inv H0.
destruct (decide (prio pr (PostfixProd o) (InfixProd o0))); eauto with IPPGrammar.
destruct (decide (right_a pr (PostfixProd o) (InfixProd o0))); eauto with IPPGrammar.
inv H1.
Qed.
Lemma is_i_conflict_pattern_false {g} (pr : drules g) q :
~ i_conflict_pattern pr q <-> is_i_conflict_pattern pr q = false.
Proof.
split; intro.
- destruct (is_i_conflict_pattern pr q) eqn:E; auto.
exfalso. destruct H. apply is_i_conflict_pattern_true. assumption.
- intro. apply is_i_conflict_pattern_true in H0. rewrite H in H0. inv H0.
Qed.
Lemma is_lm_conflict_pattern_true {g} (pr : drules g) q :
lm_conflict_pattern pr q <-> is_lm_conflict_pattern pr q = true.
Proof.
split; intro.
- inv H; simpl; auto using decide_True, decide_False.
+ destruct (decide (prio pr (InfixProd o1) (PostfixProd o2))); auto using decide_True, decide_False.
+ destruct (decide (prio pr (PrefixProd o1) (PostfixProd o2))); auto using decide_True, decide_False.
- destruct q; inv H.
+ destruct q1, q2; inv H1.
destruct q2; inv H0.
destruct (decide (prio pr (InfixProd o) (PostfixProd o0))); eauto with IPPGrammar.
destruct (decide (left_a pr (InfixProd o) (PostfixProd o0))); eauto with IPPGrammar.
inv H1.
+ destruct q; inv H1.
destruct q; inv H0.
destruct (decide (prio pr (PrefixProd o) (PostfixProd o0))); eauto with IPPGrammar.
destruct (decide (left_a pr (PrefixProd o) (PostfixProd o0))); eauto with IPPGrammar.
inv H1.
Qed.
Lemma is_lm_conflict_pattern_false {g} (pr : drules g) q :
~ lm_conflict_pattern pr q <-> is_lm_conflict_pattern pr q = false.
Proof.
split; intro.
- destruct (is_lm_conflict_pattern pr q) eqn:E; auto.
exfalso. destruct H. apply is_lm_conflict_pattern_true. assumption.
- intro. apply is_lm_conflict_pattern_true in H0. rewrite H in H0. inv H0.
Qed.
Lemma has_infix_lm_conflicts_true {g} (pr : drules g) o t2 :
has_infix_lm_conflicts pr o t2 = true <->
exists x, lm_conflict_pattern pr (CR_infix_postfix o x) /\ matches_lm t2 (PostfixPatt HPatt x).
Proof.
induction t2; split; intros.
- inv H.
- inv H. inv H0. inv H1. inv H0.
- apply IHt2_1 in H. inv H. inv H0. eauto with IPPGrammar.
- simpl. inv H. inv H0.
inv H1.
+ inv H0.
+ apply IHt2_1. eauto with IPPGrammar.
- inv H.
- inv H. inv H0. inv H1. inv H0.
- cbn [has_infix_lm_conflicts] in H.
destruct (is_lm_conflict_pattern pr (CR_infix_postfix o o0)) eqn:E.
+ apply is_lm_conflict_pattern_true in E. eauto with IPPGrammar.
+ apply IHt2 in H. inv H. inv H0. eauto with IPPGrammar.
- inv H. inv H0. cbn [has_infix_lm_conflicts].
destruct (is_lm_conflict_pattern pr (CR_infix_postfix o o0)) eqn:E; auto.
inv H1.
+ inv H0. apply is_lm_conflict_pattern_true in H. rewrite H in E. inv E.
+ rewrite IHt2. eauto with IPPGrammar.
Qed.
Lemma has_infix_lm_conflicts_false {g} (pr : drules g) o t2 :
has_infix_lm_conflicts pr o t2 = false <->
(forall x, matches_lm t2 (PostfixPatt HPatt x) -> ~ lm_conflict_pattern pr (CR_infix_postfix o x)).
Proof.
split; intros.
- intro. assert (has_infix_lm_conflicts pr o t2 = true). { apply has_infix_lm_conflicts_true. eauto. }
rewrite H in H2. inv H2.
- destruct (has_infix_lm_conflicts pr o t2) eqn:E; auto.
apply has_infix_lm_conflicts_true in E. inv E. inv H0. exfalso. eapply H; eauto.
Qed.
Lemma has_prefix_lm_conflicts_true {g} (pr : drules g) o t2 :
has_prefix_lm_conflicts pr o t2 = true <->
exists x, lm_conflict_pattern pr (CR_prefix_postfix o x) /\ matches_lm t2 (PostfixPatt HPatt x).
Proof.
induction t2; split; intros.
- inv H.
- inv H. inv H0. inv H1. inv H0.
- apply IHt2_1 in H. inv H. inv H0. eauto with IPPGrammar.
- simpl. inv H. inv H0.
inv H1.
+ inv H0.
+ apply IHt2_1. eauto with IPPGrammar.
- inv H.
- inv H. inv H0. inv H1. inv H0.
- cbn [has_prefix_lm_conflicts] in H.
destruct (is_lm_conflict_pattern pr (CR_prefix_postfix o o0)) eqn:E.
+ apply is_lm_conflict_pattern_true in E. eauto with IPPGrammar.
+ apply IHt2 in H. inv H. inv H0. eauto with IPPGrammar.
- inv H. inv H0. cbn [has_prefix_lm_conflicts].
destruct (is_lm_conflict_pattern pr (CR_prefix_postfix o o0)) eqn:E; auto.
inv H1.
+ inv H0. apply is_lm_conflict_pattern_true in H. rewrite H in E. inv E.
+ rewrite IHt2. eauto with IPPGrammar.
Qed.
Lemma has_prefix_lm_conflicts_false {g} (pr : drules g) o t2 :
has_prefix_lm_conflicts pr o t2 = false <->
(forall x, matches_lm t2 (PostfixPatt HPatt x) -> ~ lm_conflict_pattern pr (CR_prefix_postfix o x)).
Proof.
split; intros.
- intro. assert (has_prefix_lm_conflicts pr o t2 = true). { apply has_prefix_lm_conflicts_true. eauto. }
rewrite H in H2. inv H2.
- destruct (has_prefix_lm_conflicts pr o t2) eqn:E; auto.
apply has_prefix_lm_conflicts_true in E. inv E. inv H0. exfalso. eapply H; eauto.
Qed.
Lemma has_postfix_rm_conflicts_true {g} (pr : drules g) t1 o :
has_postfix_rm_conflicts pr t1 o = true <->
exists x, rm_conflict_pattern pr (CL_postfix_prefix o x) /\ matches_rm t1 (PrefixPatt x HPatt).
Proof.
induction t1; split; intros.
- inv H.
- inv H. inv H0. inv H1. inv H0.
- simpl in H. apply IHt1_2 in H. inv H. inv H0. eauto with IPPGrammar.
- simpl. inv H. inv H0.
inv H1.
+ inv H0.
+ apply IHt1_2. eauto with IPPGrammar.
- simpl in H. destruct (decide (prio pr (PostfixProd o) (PrefixProd o0))).
+ eexists. eauto with IPPGrammar.
+ destruct (decide (right_a pr (PostfixProd o) (PrefixProd o0))).
* eexists. eauto with IPPGrammar.
* apply IHt1 in H. inv H. inv H0. eexists. eauto with IPPGrammar.
- simpl. destruct (decide (prio pr (PostfixProd o) (PrefixProd o0))),
(decide (right_a pr (PostfixProd o) (PrefixProd o0))); auto.
inv H. inv H0.
inv H1.
+ inv H0. exfalso. inv H; auto.
+ apply IHt1. eexists. eauto.
- inv H.
- inv H. inv H0. inv H1. inv H0.
Qed.
Lemma has_postfix_rm_conflicts_false {g} (pr : drules g) t1 o :
has_postfix_rm_conflicts pr t1 o = false <->
(forall x, matches_rm t1 (PrefixPatt x HPatt) -> ~ rm_conflict_pattern pr (CL_postfix_prefix o x)).
Proof.
split; intros.
- intro. assert (has_postfix_rm_conflicts pr t1 o = true). { apply has_postfix_rm_conflicts_true. eauto. }
rewrite H in H2. inv H2.
- destruct (has_postfix_rm_conflicts pr t1 o) eqn:E; auto.
apply has_postfix_rm_conflicts_true in E. inv E. inv H0. edestruct H; eauto.
Qed.
(*
##############################################
##############################################
##############################################
*)
(* The following lemmas relate safety to relations between conflict patterns. *)
Lemma safe_infix_infix {g} (pr : drules g) o1 o2 :
safe_pr pr ->
i_conflict_pattern pr (CL_infix_infix o1 o2) ->
i_conflict_pattern pr (CR_infix_infix o2 o1) ->
False.
Proof.
intros H_safe H_CL H_CR. unfold safe_pr in H_safe. inv H_CL; inv H_CR; eauto.
Qed.
Lemma safe_infix_prefix {g} (pr : drules g) o1 o2 :
safe_pr pr ->
rm_conflict_pattern pr (CL_infix_prefix o1 o2) ->
i_conflict_pattern pr (CR_prefix_infix o2 o1) ->
False.
Proof.
intros. unfold safe_pr in H. inv H0; inv H1; eauto.
Qed.
Lemma safe_infix_postfix {g} (pr : drules g) o1 o2 :
safe_pr pr ->
lm_conflict_pattern pr (CR_infix_postfix o1 o2) ->
i_conflict_pattern pr (CL_postfix_infix o2 o1) ->
False.
Proof.
intros. unfold safe_pr in H. inv H0; inv H1; eauto.
Qed.
Lemma safe_prefix_postfix {g} (pr : drules g) o1 o2 :
safe_pr pr ->
lm_conflict_pattern pr (CR_prefix_postfix o1 o2) ->
rm_conflict_pattern pr (CL_postfix_prefix o2 o1) ->
False.
Proof.
intros. unfold safe_pr in H. inv H0; inv H1; eauto.
Qed.
(*
##############################################
##############################################
##############################################
*)
(* Helper tactics for simplifying specific repair terms. *)
(* Simplifies the term [insert_in pr t1 o (InfixNode t21 o2 t22)] *)
Ltac insert_in_inode_destruct pr o t21 o2 t22 :=
cbn [insert_in] in *;
destruct (is_i_conflict_pattern pr (CR_infix_infix o o2)) eqn:E;
[ apply is_i_conflict_pattern_true in E |
apply is_i_conflict_pattern_false in E;
destruct (has_infix_lm_conflicts pr o (InfixNode t21 o2 t22)) eqn:E2;
[ apply has_infix_lm_conflicts_true in E2 |
assert (forall x, matches_lm (InfixNode t21 o2 t22) (PostfixPatt HPatt x) ->
~ lm_conflict_pattern pr (CR_infix_postfix o x));
[apply has_infix_lm_conflicts_false; assumption|]
]
].
(* Simplifies the term [insert_in pr t1 o (PostfixNode t21 o2)] *)
Ltac insert_in_pnode_destruct pr o t21 o2 :=
cbn [insert_in] in *;
destruct (has_infix_lm_conflicts pr o (PostfixNode t21 o2)) eqn:E;
[apply has_infix_lm_conflicts_true in E |
assert (forall x, matches_lm (PostfixNode t21 o2) (PostfixPatt HPatt x) ->
~ lm_conflict_pattern pr (CR_infix_postfix o x));
[apply has_infix_lm_conflicts_false; assumption|]
].
(* Simplifies the term [insert_pre pr o (InfixNode t21 o2 t22)] *)
Ltac insert_pre_inode_destruct pr o t21 o2 t22 :=
cbn [insert_pre] in *;
destruct (is_i_conflict_pattern pr (CR_prefix_infix o o2)) eqn:E;
[ apply is_i_conflict_pattern_true in E |
apply is_i_conflict_pattern_false in E;
destruct (has_prefix_lm_conflicts pr o (InfixNode t21 o2 t22)) eqn:E2;
[ apply has_prefix_lm_conflicts_true in E2 |
assert (forall x, matches_lm (InfixNode t21 o2 t22) (PostfixPatt HPatt x) ->
~ lm_conflict_pattern pr (CR_prefix_postfix o x));
[apply has_prefix_lm_conflicts_false; assumption|]
]
].
(* Simplifies the term [insert_pre pr o (PostfixNode t21 o2)] *)
Ltac insert_pre_pnode_destruct pr o t21 o2 :=
cbn [insert_pre] in *;
destruct (has_prefix_lm_conflicts pr o (PostfixNode t21 o2)) eqn:E;
[apply has_prefix_lm_conflicts_true in E |
assert (forall x, matches_lm (PostfixNode t21 o2) (PostfixPatt HPatt x) ->
~ lm_conflict_pattern pr (CR_prefix_postfix o x));
[apply has_prefix_lm_conflicts_false; assumption|]
].
(* Simplifies the term [insert_post pr (InfixNode t11 o1 t12) o] *)
Ltac insert_post_inode_destruct pr t11 o1 t12 o :=
cbn [insert_post] in *;
destruct (is_i_conflict_pattern pr (CL_postfix_infix o o1)) eqn:E;
[ apply is_i_conflict_pattern_true in E |
apply is_i_conflict_pattern_false in E;
destruct (has_postfix_rm_conflicts pr (InfixNode t11 o1 t12) o) eqn:E2;
[ apply has_postfix_rm_conflicts_true in E2 |
assert (forall x, matches_rm (InfixNode t11 o1 t12) (PrefixPatt x HPatt) ->
~ rm_conflict_pattern pr (CL_postfix_prefix o x));
[apply has_postfix_rm_conflicts_false; assumption|]
]
].
(* Simplifies the term [insert_post pr (PrefixNode o1 t12) o] *)
Ltac insert_post_pnode_destruct pr o1 t12 o :=
cbn [insert_post] in *;
destruct (has_postfix_rm_conflicts pr (PrefixNode o1 t12) o) eqn:E;
[ apply has_postfix_rm_conflicts_true in E |
assert (forall x, matches_rm (PrefixNode o1 t12) (PrefixPatt x HPatt) ->
~ rm_conflict_pattern pr (CL_postfix_prefix o x));
[apply has_postfix_rm_conflicts_false; assumption|]
].
(*
##############################################
##############################################
##############################################
*)
(* Lemmas that show well-formedness of [repair] *)
Lemma insert_in_wf {g} (pr : drules g) t1 o t2 :
wf_parse_tree g t1 -> wf_parse_tree g t2 -> g.(prods) (InfixProd (inl o)) ->
wf_parse_tree g (insert_in pr t1 (inl o) t2).
Proof.
intros. induction t2.
- simpl. auto with IPPGrammar.
- inv H0.
insert_in_inode_destruct pr (@inl (OPinpre g) (OPpost g) o) t2_1 (@inl (OPinpre g) (OPpost g) o1) t2_2;
auto with IPPGrammar.
- simpl. inv H0. auto with IPPGrammar.
- inv H0.
insert_in_pnode_destruct pr (@inl (OPinpre g) (OPpost g) o) t2 (@inr (OPinpre g) (OPpost g) o1);
auto with IPPGrammar.
Qed.
Lemma insert_pre_wf {g} (pr : drules g) o t2 :
wf_parse_tree g t2 -> g.(prods) (PrefixProd (inl o)) ->
wf_parse_tree g (insert_pre pr (inl o) t2).
Proof.
intros. induction H; eauto with IPPGrammar.
- insert_pre_inode_destruct pr (@inl (OPinpre g) (OPpost g) o) t1 (@inl (OPinpre g) (OPpost g) o0) t2;
auto with IPPGrammar.
- insert_pre_pnode_destruct pr (@inl (OPinpre g) (OPpost g) o) t (@inr (OPinpre g) (OPpost g) o0);
auto with IPPGrammar.
Qed.
Lemma repair_in_wf {g} (pr : drules g) t1 o t2 :
wf_parse_tree g t1 -> wf_parse_tree g t2 -> g.(prods) (InfixProd (inl o)) ->
wf_parse_tree g (repair_in pr t1 (inl o) t2).
Proof.
intro. revert o t2. induction H; intros; simpl; auto using insert_in_wf, insert_pre_wf with IPPGrammar.
Qed.
Lemma insert_post_wf {g} (pr : drules g) t1 o :
wf_parse_tree g t1 -> g.(prods) (PostfixProd (inr o)) ->
wf_parse_tree g (insert_post pr t1 (inr o)).
Proof.
intros. induction H; eauto with IPPGrammar.
- insert_post_inode_destruct pr t1 (@inl (OPinpre g) (OPpost g) o0) t2 (@inr (OPinpre g) (OPpost g) o);
auto with IPPGrammar.
- insert_post_pnode_destruct pr (@inl (OPinpre g) (OPpost g) o0) t (@inr (OPinpre g) (OPpost g) o);
auto with IPPGrammar.
Qed.
Lemma repair_wf {g} (pr : drules g) t :
wf_parse_tree g t ->
wf_parse_tree g (repair pr t).
Proof.
intro. induction H; simpl; auto using repair_in_wf, insert_pre_wf, insert_post_wf with IPPGrammar.
Qed.
(*
##############################################
##############################################
##############################################
*)
(* Lemmas that show yield-preservation of [repair] *)
Lemma insert_pre_yield_preserve {g} (pr : drules g) o t2 :
yield (insert_pre pr o t2) = inr o :: yield t2.
Proof.
induction t2; try reflexivity.
- insert_pre_inode_destruct pr o t2_1 o0 t2_2; auto; simpl; rewrite IHt2_1; auto.
- insert_pre_pnode_destruct pr o t2 o0; simpl; auto. rewrite IHt2. reflexivity.
Qed.
Lemma insert_in_yield_preserve {g} (pr : drules g) t1 o t2 :
yield (insert_in pr t1 o t2) = yield t1 ++ inr o :: yield t2.
Proof.
induction t2; try reflexivity.
- insert_in_inode_destruct pr o t2_1 o0 t2_2; simpl; auto.
+ rewrite IHt2_1. simplify_list_eq. reflexivity.
+ rewrite IHt2_1. simplify_list_eq. reflexivity.
- insert_in_pnode_destruct pr o t2 o0; simpl; auto. rewrite IHt2. simplify_list_eq. reflexivity.
Qed.
Lemma repair_in_yield_preserve {g} (pr : drules g) t1 o t2 :
yield (repair_in pr t1 o t2) = yield t1 ++ inr o :: yield t2.
Proof.
revert o t2. induction t1; intros.
- simpl. rewrite insert_in_yield_preserve. reflexivity.
- simplify_list_eq. rewrite <- IHt1_2. rewrite <- IHt1_1. reflexivity.
- simpl. rewrite <- IHt1. rewrite insert_pre_yield_preserve. reflexivity.
- simpl. rewrite insert_in_yield_preserve. reflexivity.
Qed.
Lemma insert_post_yield_preserve {g} (pr : drules g) t1 o :
yield (insert_post pr t1 o) = yield t1 ++ [inr o].
Proof.
induction t1; try reflexivity.
- insert_post_inode_destruct pr t1_1 o0 t1_2 o; auto; simplify_list_eq; rewrite IHt1_2; auto.
- insert_post_pnode_destruct pr o0 t1 o; auto; simplify_list_eq; rewrite IHt1; auto.
Qed.
Lemma repair_yield_preserve {g} (pr : drules g) t :
yield (repair pr t) = yield t.
Proof.
induction t; auto; simpl.
- rewrite repair_in_yield_preserve. rewrite IHt1. rewrite IHt2. reflexivity.
- rewrite insert_pre_yield_preserve. rewrite IHt. reflexivity.
- rewrite insert_post_yield_preserve. rewrite IHt. reflexivity.
Qed.
(*
##############################################
##############################################
##############################################
*)
(* Auxiliary lemmas and tactics that help proving safety. *)
Lemma i_conflict_pattern_cases {g} (pr : drules g) q :
i_conflict_pattern pr q -> exists o1 o2,
q = CR_infix_infix o1 o2 \/ q = CL_infix_infix o1 o2 \/ q = CR_prefix_infix o1 o2 \/ q = CL_postfix_infix o1 o2.
Proof.
intros. inv H; eauto 7.
Qed.
Ltac icp_cases H :=
apply i_conflict_pattern_cases in H as T; destruct T as [? T1]; destruct T1 as [? T2]; destruct T2 as [T5|T3];
[|destruct T3 as [T5|T4]; [|destruct T4 as [T5|T5]]]; rewrite T5 in *; clear T5.
Lemma rm_conflict_pattern_cases {g} (pr : drules g) q :
rm_conflict_pattern pr q -> exists o1 o2,
q = CL_infix_prefix o1 o2 \/ q = CL_postfix_prefix o1 o2.
Proof.
intros. inv H; eauto.
Qed.
Ltac rcp_cases H :=
apply rm_conflict_pattern_cases in H as T; destruct T as [? T1]; destruct T1 as [? T2]; destruct T2; subst.
Lemma lm_conflict_pattern_cases {g} (pr : drules g) q :
lm_conflict_pattern pr q -> exists o1 o2,
q = CR_infix_postfix o1 o2 \/ q = CR_prefix_postfix o1 o2.
Proof.
intros. inv H; eauto.
Qed.
Ltac lcp_cases H :=
apply lm_conflict_pattern_cases in H as T; destruct T as [? T1]; destruct T1 as [? T2]; destruct T2; subst.
(*
##############################################
##############################################
##############################################
*)
(* Proving safety of shallow conflict patterns (i_conflict_patterns). *)
Lemma insert_in_top {g} (pr : drules g) t1 o t2 :
matches (insert_in pr t1 o t2) (InfixPatt HPatt o HPatt) \/
(exists o2, matches t2 (InfixPatt HPatt o2 HPatt) /\ matches (insert_in pr t1 o t2) (InfixPatt HPatt o2 HPatt)) \/
(exists o2, matches t2 (PostfixPatt HPatt o2) /\ matches (insert_in pr t1 o t2) (PostfixPatt HPatt o2)).
Proof.
destruct t2; eauto 6 with IPPGrammar.
- insert_in_inode_destruct pr o t2_1 o0 t2_2; eauto 7 with IPPGrammar.
- insert_in_pnode_destruct pr o t2 o0; eauto 7 with IPPGrammar.
Qed.
Lemma insert_in_top_unchanged {g} (pr : drules g) t1 o t2 x :
matches_lm t2 (PostfixPatt HPatt x) ->
lm_conflict_pattern pr (CR_infix_postfix o x) ->
(exists o2, matches t2 (InfixPatt HPatt o2 HPatt) /\ matches (insert_in pr t1 o t2) (InfixPatt HPatt o2 HPatt)) \/
(exists o2, matches t2 (PostfixPatt HPatt o2) /\ matches (insert_in pr t1 o t2) (PostfixPatt HPatt o2)).
Proof.
intros. destruct t2.
- inv H. inv H1.
- inv H. inv H1. left.
eexists. split; auto with IPPGrammar.
insert_in_inode_destruct pr o t2_1 o0 t2_2; auto with IPPGrammar. exfalso. apply H with x; auto with IPPGrammar.
- inv H. inv H1.
- right. eexists. split; auto with IPPGrammar.
insert_in_pnode_destruct pr o t2 o0; auto with IPPGrammar. exfalso. apply H1 with x; auto.
Qed.
Lemma insert_in_icfree {g} (pr : drules g) t1 o t2 :
safe_pr pr ->
i_conflict_free (i_conflict_pattern pr) t1 ->
i_conflict_free (i_conflict_pattern pr) t2 ->
(forall o1, i_conflict_pattern pr (CL_infix_infix o o1) -> ~ matches t1 (InfixPatt HPatt o1 HPatt)) ->
i_conflict_free (i_conflict_pattern pr) (insert_in pr t1 o t2).
Proof.
intros. induction t2 as [l2|t21 ? o2 t22|o2 t22|t21 ? o2].
- simpl. apply Infix_cf; auto. intro. inv H3. inv H4. icp_cases H3; inv H5. inv H12. eapply H2; eauto.
- insert_in_inode_destruct pr o t21 o2 t22.
+ inv H1. apply Infix_cf; auto. intro. inv H1. inv H3. icp_cases H1; inv H4.
* destruct H6. eexists. eauto with IPPGrammar.
* inv H9. decompose [or] (insert_in_top pr t1 o t21); rewrite <- H3 in *.
**inv H4. eauto using safe_infix_infix.
**inv H5. inv H4. inv H9. destruct H6. eexists. eauto with IPPGrammar.
**inv H5. inv H4. inv H9.
+ inv H1. apply Infix_cf; auto with IPPGrammar. intro. inv H1. inv H3. icp_cases H1; inv H4.
* destruct H6. eexists. eauto with IPPGrammar.
* inv E2. inv H3. inv H5. inv H3.
inv H9. apply insert_in_top_unchanged with pr t1 o t21 x2 in H13; auto. destruct H13; rewrite <- H3 in *.
**inv H5. inv H9. inv H10. destruct H6. eexists. eauto with IPPGrammar.
**inv H5. inv H9. inv H10.
+ apply Infix_cf; auto. intro. inv H4. inv H5. icp_cases H4; inv H6.
* inv H13. contradiction.
* inv H8. apply H2 with x1; auto with IPPGrammar.
- simpl. apply Infix_cf; auto with IPPGrammar. intro. inv H3. inv H4. icp_cases H3; inv H5. inv H12. inv H1.
eapply H2; eauto with IPPGrammar.
- insert_in_pnode_destruct pr o t21 o2.
+ inv H1. apply Postfix_cf; auto with IPPGrammar. intro. inv H1. inv H3. icp_cases H1; inv H4. inv H7. inv E.
inv H4. inv H8.
* inv H4. decompose [or] (insert_in_top pr t1 o t21); rewrite <- H3 in *.
**inv H4. eauto using safe_infix_postfix.
**inv H8. inv H4. inv H12. destruct H5. eexists. eauto with IPPGrammar.
**inv H8. inv H4. inv H12.
* apply insert_in_top_unchanged with pr t1 o t21 x2 in H13; auto. destruct H13; auto; rewrite <- H3 in *.
**inv H4. inv H8. inv H10. destruct H5. eexists. eauto with IPPGrammar.
**inv H4. inv H8. inv H10.
+ apply Infix_cf; auto with IPPGrammar. intro. inv H4. inv H5. icp_cases H4; inv H6. inv H13. inv H8.
eapply H2; eauto with IPPGrammar.
Qed.
Lemma insert_pre_top {g} (pr : drules g) o t2 :
matches (insert_pre pr o t2) (PrefixPatt o HPatt) \/
(exists o2, matches t2 (InfixPatt HPatt o2 HPatt) /\ matches (insert_pre pr o t2) (InfixPatt HPatt o2 HPatt)) \/
(exists o2, matches t2 (PostfixPatt HPatt o2) /\ matches (insert_pre pr o t2) (PostfixPatt HPatt o2)).
Proof.
destruct t2; eauto with IPPGrammar.
- insert_pre_inode_destruct pr o t2_1 o0 t2_2; eauto 7 with IPPGrammar.
- insert_pre_pnode_destruct pr o t2 o0; eauto 7 with IPPGrammar.
Qed.
Lemma insert_pre_top_unchanged {g} (pr : drules g) o t2 x :
matches_lm t2 (PostfixPatt HPatt x) ->
lm_conflict_pattern pr (CR_prefix_postfix o x) ->
(exists o2, matches t2 (InfixPatt HPatt o2 HPatt) /\ matches (insert_pre pr o t2) (InfixPatt HPatt o2 HPatt)) \/
(exists o2, matches t2 (PostfixPatt HPatt o2) /\ matches (insert_pre pr o t2) (PostfixPatt HPatt o2)).
Proof.
intros. destruct t2.
- inv H. inv H1.
- inv H. inv H1. left.
eexists. split; auto with IPPGrammar.
insert_pre_inode_destruct pr o t2_1 o0 t2_2; auto with IPPGrammar. exfalso. apply H with x; auto with IPPGrammar.
- inv H. inv H1.
- right. eexists. split; auto with IPPGrammar.
insert_pre_pnode_destruct pr o t2 o0; auto with IPPGrammar. exfalso. apply H1 with x; auto.
Qed.
Lemma insert_pre_icfree {g} (pr : drules g) o t2 :
safe_pr pr ->
i_conflict_free (i_conflict_pattern pr) t2 ->
i_conflict_free (i_conflict_pattern pr) (insert_pre pr o t2).
Proof.
intros. induction t2 as [l2|t21 ? o2 t22|o2 t22|t21 ? o2].
- simpl. apply Prefix_cf; auto. intro. inv H1. inv H2. icp_cases H1; inv H3. inv H4.
- insert_pre_inode_destruct pr o t21 o2 t22.
+ inv H0. apply Infix_cf; auto. intro. inv H0. inv H1. icp_cases H0; inv H2.
* inv H12. destruct H4. eexists. eauto with IPPGrammar.
* decompose [or] (insert_pre_top pr o t21).
**inv H7. rewrite <- H2 in *. inv H1.
**inv H2. inv H1. inv H7. rewrite <- H1 in *. inv H3. destruct H4. eexists. eauto with IPPGrammar.
**inv H2. inv H1. inv H7. rewrite <- H1 in *. inv H3.
+ inv H0. apply Infix_cf; auto. intro. inv H0. inv H1. inv E2. inv H1. inv H7. inv H1. icp_cases H0; inv H2.
* destruct H4. eexists. eauto with IPPGrammar.
* apply insert_pre_top_unchanged with pr o t21 x0 in H11; auto. destruct H11.
**inv H1. inv H2. inv H8. rewrite <- H2 in *. inv H7. destruct H4. eexists. eauto with IPPGrammar.
**inv H1. inv H2. inv H8. rewrite <- H2 in *. inv H7.
+ apply Prefix_cf; auto. intro. inv H2. inv H3. icp_cases H2; inv H4. inv H5. contradiction.
- simpl. apply Prefix_cf; auto. intro. inv H1. inv H2. icp_cases H1; inv H3. inv H4.
- insert_pre_pnode_destruct pr o t21 o2.
+ inv H0. apply Postfix_cf; auto. inv E. inv H0. intro. inv H0. inv H5. icp_cases H0; inv H6. inv H7. inv H2.
* inv H6. decompose [or] (insert_pre_top pr o t21); rewrite <- H5 in *.
** inv H2.
** inv H6. inv H2. inv H8. destruct H3. eexists. eauto with IPPGrammar.
** inv H6. inv H2. inv H8.
* apply insert_pre_top_unchanged with pr o t21 x in H10; auto.
destruct H10; rewrite <- H5 in *.
** inv H2. inv H6. inv H7. destruct H3. eexists. eauto with IPPGrammar.
** inv H2. inv H6. inv H7.
+ apply Prefix_cf; auto.
intro. inv H2. inv H3. icp_cases H2; inv H4. inv H5.
Qed.
Lemma repair_in_icfree {g} (pr : drules g) t1 o t2 :
safe_pr pr ->
i_conflict_free (i_conflict_pattern pr) t1 ->
i_conflict_free (i_conflict_pattern pr) t2 ->
i_conflict_free (i_conflict_pattern pr) (repair_in pr t1 o t2).
Proof.
intro. revert o t2. induction t1 as [l1|t11 ? o1 t12|o1 t12|t11 ? o1]; intros; simpl.
- apply insert_in_icfree; auto with IPPGrammar. intros. intro. inv H3.
- inv H0. auto.
- inv H0. apply insert_pre_icfree; auto.
- apply insert_in_icfree; auto with IPPGrammar. intros. intro. inv H3.
Qed.
Lemma insert_post_top {g} (pr : drules g) t1 o :
matches (insert_post pr t1 o) (PostfixPatt HPatt o) \/
(exists o1, matches t1 (InfixPatt HPatt o1 HPatt) /\ matches (insert_post pr t1 o) (InfixPatt HPatt o1 HPatt)) \/
(exists o1, matches t1 (PrefixPatt o1 HPatt) /\ matches (insert_post pr t1 o) (PrefixPatt o1 HPatt)).
Proof.
destruct t1; eauto with IPPGrammar.
- insert_post_inode_destruct pr t1_1 o0 t1_2 o; eauto 7 with IPPGrammar.
- insert_post_pnode_destruct pr o0 t1 o; eauto 7 with IPPGrammar.
Qed.
Lemma insert_post_top_unchanged {g} (pr : drules g) t1 o x :
matches_rm t1 (PrefixPatt x HPatt) ->
rm_conflict_pattern pr (CL_postfix_prefix o x) ->
(exists o1, matches t1 (InfixPatt HPatt o1 HPatt) /\ matches (insert_post pr t1 o) (InfixPatt HPatt o1 HPatt)) \/
(exists o1, matches t1 (PrefixPatt o1 HPatt) /\ matches (insert_post pr t1 o) (PrefixPatt o1 HPatt)).
Proof.
intros. destruct t1.
- inv H. inv H1.
- inv H. inv H1. left.
eexists. split; auto with IPPGrammar.
insert_post_inode_destruct pr t1_1 o0 t1_2 o; auto with IPPGrammar. exfalso. apply H with x; auto with IPPGrammar.
- right. eexists. split; auto with IPPGrammar.
insert_post_pnode_destruct pr o0 t1 o; auto with IPPGrammar. exfalso. apply H1 with x; auto.
- inv H. inv H1.
Qed.
Lemma insert_post_icfree {g} (pr : drules g) t1 o :
safe_pr pr ->
i_conflict_free (i_conflict_pattern pr) t1 ->
i_conflict_free (i_conflict_pattern pr) (insert_post pr t1 o).
Proof.
intros. induction t1 as [l1|t11 ? o1 t12|o1 t12|t11 ? o1].
- simpl. apply Postfix_cf; auto. intro. inv H1. inv H2. icp_cases H1; inv H3. inv H4.
- insert_post_inode_destruct pr t11 o1 t12 o.
+ inv H0. apply Infix_cf; auto. intro. inv H0. inv H1. icp_cases H0; inv H2.
* decompose [or] (insert_post_top pr t12 o).
**inv H12. rewrite <- H2 in *. inv H1.
**inv H2. inv H1. inv H12. rewrite <- H1 in *. inv H3. destruct H4. eexists. eauto with IPPGrammar.
**inv H2. inv H1. inv H12. rewrite <- H1 in *. inv H3.
* inv H12. destruct H4. eexists. eauto with IPPGrammar.
+ inv H0. apply Infix_cf; auto. intro. inv H0. inv H1. inv E2. inv H1. inv H7. inv H1. icp_cases H0; inv H2.
* apply insert_post_top_unchanged with pr t12 o x0 in H11; auto. destruct H11.
**inv H1. inv H2. inv H7. rewrite <- H2 in *. inv H14. destruct H4. eexists. eauto with IPPGrammar.
**inv H1. inv H2. inv H7. rewrite <- H2 in *. inv H14.
* destruct H4. eexists. eauto with IPPGrammar.
+ apply Postfix_cf; auto. intro. inv H2. inv H3. icp_cases H2; inv H4. inv H5. contradiction.
- insert_post_pnode_destruct pr o1 t12 o.
+ inv H0. apply Prefix_cf; auto. inv E. inv H0. intro. inv H0. inv H5. icp_cases H0; inv H6. inv H7. inv H2.
* inv H6. decompose [or] (insert_post_top pr t12 o); rewrite <- H5 in *.
**inv H2.
**inv H6. inv H2. inv H8. destruct H3. eexists. eauto with IPPGrammar.
**inv H6. inv H2. inv H8.
* apply insert_post_top_unchanged with pr t12 o x in H10; auto.
destruct H10; rewrite <- H5 in *.
**inv H2. inv H6. inv H7. destruct H3. eexists. eauto with IPPGrammar.
**inv H2. inv H6. inv H7.
+ apply Postfix_cf; auto. intro. inv H2. inv H3. icp_cases H2; inv H4. inv H5.
- simpl. apply Postfix_cf; auto. intro. inv H1. inv H2. icp_cases H1; inv H3. inv H4.
Qed.
Lemma repair_icfree {g} (pr : drules g) t :
safe_pr pr ->
i_conflict_free (i_conflict_pattern pr) (repair pr t).
Proof.
intro. induction t; simpl; auto using repair_in_icfree, insert_pre_icfree, insert_post_icfree with IPPGrammar.
Qed.
(*
##############################################
##############################################
##############################################
*)
(* Proving safety of deep rm conflict patterns. *)
Lemma insert_in_matches_rm {g} (pr : drules g) t1 o1 t2 o2 :
matches_rm (insert_in pr t1 o1 t2) (PrefixPatt o2 HPatt) ->
matches_rm t2 (PrefixPatt o2 HPatt).
Proof.
intros. destruct t2.
- simpl in H. inv H. inv H0. inv H4. inv H.
- insert_in_inode_destruct pr o1 t2_1 o t2_2.
+ inv H. inv H0. auto with IPPGrammar.
+ inv H. inv H0. auto with IPPGrammar.
+ inv H. inv H1. assumption.
- simpl in H. inv H. inv H0. assumption.
- insert_in_pnode_destruct pr o1 t2 o.
+ inv H. inv H0.
+ inv H. inv H1. inv H5. inv H.
Qed.
Lemma insert_in_drmcfree {g} (pr : drules g) t1 o t2 :
safe_pr pr ->
drm_conflict_free (rm_conflict_pattern pr) t1 ->
drm_conflict_free (rm_conflict_pattern pr) t2 ->
(forall x, rm_conflict_pattern pr (CL_infix_prefix o x) -> ~ matches_rm t1 (PrefixPatt x HPatt)) ->
drm_conflict_free (rm_conflict_pattern pr) (insert_in pr t1 o t2).
Proof.
intros. induction t2 as [l2|t21 ? o2 t22|o2 t22|t21 ? o2].
- simpl. apply Infix_drmcf; auto. intro. inv H3. inv H4. rcp_cases H3; inv H5. eapply H2; eauto.
- insert_in_inode_destruct pr o t21 o2 t22.
+ inv H1. apply Infix_drmcf; auto. intro. inv H1. inv H3. rcp_cases H1; inv H4.
destruct H6. eexists. eauto using insert_in_matches_rm with IPPGrammar.
+ inv H1. apply Infix_drmcf; auto. intro. inv H1. inv H3. rcp_cases H1; inv H4.
destruct H6. eexists. eauto using insert_in_matches_rm with IPPGrammar.
+ apply Infix_drmcf; auto with IPPGrammar. intro. inv H4. inv H5. rcp_cases H4; inv H6. eapply H2; eauto.
- simpl. apply Infix_drmcf; auto with IPPGrammar. intro. inv H3. inv H4. rcp_cases H3; inv H5. eapply H2; eauto.
- insert_in_pnode_destruct pr o t21 o2.
+ inv H1. apply Postfix_drmcf; auto. intro. inv H1. inv H3. rcp_cases H1; inv H4.
destruct H5. eexists. eauto using insert_in_matches_rm with IPPGrammar.
+ apply Infix_drmcf; auto with IPPGrammar. intro. inv H4. inv H5. rcp_cases H4; inv H6. eapply H2; eauto.
Qed.
Lemma prefixnode_single_drmcfree {g} (pr : drules g) o l2 :
drm_conflict_free (rm_conflict_pattern pr) (PrefixNode o (AtomicNode l2)).
Proof.
apply Prefix_drmcf; auto using Atomic_drmcf. intro. destruct H as [q]. inv H. rcp_cases H0; inv H1.
Qed.
Lemma insert_pre_matches_rm {g} (pr : drules g) o t2 o2 :
matches_rm (insert_pre pr o t2) (PrefixPatt o2 HPatt) ->
matches_rm t2 (PrefixPatt o2 HPatt) \/ o2 = o.
Proof.
intros. destruct t2.
- simpl in H. inv H.
+ inv H0. auto.
+ inv H3. inv H.
- insert_pre_inode_destruct pr o t2_1 o0 t2_2.
+ inv H. inv H0. left. auto with IPPGrammar.
+ inv H. inv H0. left. auto with IPPGrammar.
+ inv H; auto. inv H1. auto.
- inv H; auto. inv H0. auto.
- insert_pre_pnode_destruct pr o t2 o0.
+ inv H. inv H0.
+ inv H; auto. inv H1. auto.
Qed.
Lemma insert_pre_drmcfree {g} (pr : drules g) o t2 :
safe_pr pr ->
drm_conflict_free (rm_conflict_pattern pr) t2 ->
drm_conflict_free (rm_conflict_pattern pr) (insert_pre pr o t2).
Proof.
intros. induction t2 as [l2|t21 ? o2 t22|o2 t22|t21 ? o2].
- simpl. apply prefixnode_single_drmcfree.
- insert_pre_inode_destruct pr o t21 o2 t22.
+ inv H0. apply Infix_drmcf; auto. intro. inv H0. inv H1. rcp_cases H0; inv H2.
apply insert_pre_matches_rm in H7. inv H7.
* destruct H4. eexists. eauto with IPPGrammar.
* eapply safe_infix_prefix; eauto using CPrio_infix_prefix.
+ inv H0. apply Infix_drmcf; auto. intro. inv H0. inv H1. rcp_cases H0; inv H2. inv E2. inv H1. inv H3. inv H1.
destruct t21.
**inv H11. inv H1.
**inv H11. inv H1. rename E into E'. insert_pre_inode_destruct pr o t21_1 o0 t21_2.
***inv H7. inv H1. destruct H4. eexists. eauto with IPPGrammar.
***inv H7. inv H1. destruct H4. eexists. eauto with IPPGrammar.
***eapply H1; eauto with IPPGrammar.
**inv H11. inv H1.
**rename E into E'. insert_pre_pnode_destruct pr o t21 o0.
***inv H7. inv H1.
***eapply H1; eauto.
+ apply Prefix_drmcf; auto. intro. inv H2. inv H3. rcp_cases H2; inv H4.
- simpl. apply Prefix_drmcf; auto. intro. inv H1. inv H2. rcp_cases H1; inv H3.
- insert_pre_pnode_destruct pr o t21 o2.
+ inv H0. apply Postfix_drmcf; auto. intro. inv H0. inv H1. rcp_cases H0; inv H2. inv E. inv H1. inv H6.
* inv H1. destruct t21.
**simpl in H5. inv H5.
***inv H1. eauto using safe_prefix_postfix.
***inv H9. inv H1.
**insert_pre_inode_destruct pr o t21_1 o0 t21_2.
***inv H5. inv H1. destruct H3. eexists. eauto with IPPGrammar.
***inv H5. inv H1. destruct H3. eexists. eauto with IPPGrammar.
***inv H5.
****inv H6. eauto using safe_prefix_postfix.
****inv H10. inv H5. destruct H3. eexists. eauto with IPPGrammar.
**simpl in H5. inv H5.
***inv H1. eauto using safe_prefix_postfix.
***destruct H3. eexists. eauto with IPPGrammar.
**insert_pre_pnode_destruct pr o t21 o0.
***inv H5. inv H1.
***inv H5.
****inv H6. eauto using safe_prefix_postfix.
****inv H10. inv H5.
* destruct t21.
**inv H9. inv H1.
**inv H9. inv H1. insert_pre_inode_destruct pr o t21_1 o0 t21_2.
***inv H5. inv H1. destruct H3. eexists. eauto with IPPGrammar.
***inv H5. inv H1. destruct H3. eexists. eauto with IPPGrammar.
***inv H5.
****inv H6. eapply H1; eauto with IPPGrammar.
****inv H9. inv H5. destruct H3. eexists. eauto with IPPGrammar.
**inv H9. inv H1.
**insert_pre_pnode_destruct pr o t21 o0.
***inv H5. inv H1.
***eapply H1; eauto.
+ apply Prefix_drmcf; auto. intro. inv H2. inv H3. rcp_cases H2; inv H4.
Qed.
Lemma postfixnode_single_drmcfree {g} (pr : drules g) o l1 :
drm_conflict_free (rm_conflict_pattern pr) (PostfixNode (AtomicNode l1) o).
Proof.
apply Postfix_drmcf; auto using Atomic_drmcf. intro. destruct H as [q]. inv H. rcp_cases H0; inv H1. inv H2. inv H.
Qed.
Lemma insert_post_drmcfree {g} (pr : drules g) t1 o :
safe_pr pr ->
drm_conflict_free (rm_conflict_pattern pr) t1 ->
drm_conflict_free (rm_conflict_pattern pr) (insert_post pr t1 o).
Proof.
intros. induction t1 as [l1|t11 ? o1 t12|o1 t12|t11 ? o1].
- simpl. apply Postfix_drmcf; auto. intro. inv H1. inv H2. rcp_cases H1; inv H3. inv H4. inv H2.
- insert_post_inode_destruct pr t11 o1 t12 o.
+ inv H0. apply Infix_drmcf; auto. intro. inv H0. inv H1. rcp_cases H0; inv H2.
destruct H4. eexists. eauto with IPPGrammar.
+ inv H0. apply Infix_drmcf; auto. intro. inv H0. inv H1. rcp_cases H0; inv H2.
destruct H4. eexists. eauto with IPPGrammar.
+ apply Postfix_drmcf; auto. intro. inv H2. inv H3. rcp_cases H2; inv H4. inv H5. inv H3.
eapply H1; eauto with IPPGrammar.
- insert_post_pnode_destruct pr o1 t12 o.
+ inv H0. apply Prefix_drmcf; auto. intro. inv H0. inv H1. rcp_cases H0; inv H2.
+ apply Postfix_drmcf; auto. intro. inv H2. inv H3. rcp_cases H2; inv H4. eapply H1; eauto.
- simpl. apply Postfix_drmcf; auto. intro. inv H1. inv H2. rcp_cases H1; inv H3. inv H4. inv H2.
Qed.
Lemma repair_in_drmcfree {g} (pr : drules g) t1 o t2 :
safe_pr pr ->
drm_conflict_free (rm_conflict_pattern pr) t1 ->
drm_conflict_free (rm_conflict_pattern pr) t2 ->
drm_conflict_free (rm_conflict_pattern pr) (repair_in pr t1 o t2).
Proof.
intro. revert o t2. induction t1 as [l1|t11 ? o1 t12|o1 t12|t11 ? o1]; intros; simpl.
- apply insert_in_drmcfree; auto with IPPGrammar. intros. intro. inv H3. inv H4.
- inv H0. auto.
- inv H0. apply insert_pre_drmcfree; auto.
- apply insert_in_drmcfree; auto with IPPGrammar. intros. intro. inv H3. inv H4.
Qed.
Lemma repair_drmcfree {g} (pr : drules g) t :
safe_pr pr ->
drm_conflict_free (rm_conflict_pattern pr) (repair pr t).
Proof.
intro. induction t; simpl; auto using repair_in_drmcfree, insert_pre_drmcfree, insert_post_drmcfree with IPPGrammar.
Qed.
(*
##############################################
##############################################
##############################################
*)
(* Proving safety of deep lm conflict patterns. *)
Lemma insert_in_dlmcfree {g} (pr : drules g) t1 o t2 :
safe_pr pr ->
dlm_conflict_free (lm_conflict_pattern pr) t1 ->
dlm_conflict_free (lm_conflict_pattern pr) t2 ->
dlm_conflict_free (lm_conflict_pattern pr) (insert_in pr t1 o t2).
Proof.
intros. induction t2 as [l2|t21 ? o2 t22|o2 t22|t21 ? o2].
- simpl. apply Infix_dlmcf; auto. intro. inv H2. inv H3. lcp_cases H2; inv H4. inv H11. inv H3.
- insert_in_inode_destruct pr o t21 o2 t22.
+ inv H1. apply Infix_dlmcf; auto. intro. inv H1. inv H2. lcp_cases H1; inv H3.
destruct H5. eexists. eauto with IPPGrammar.
+ inv H1. apply Infix_dlmcf; auto. intro. inv H1. inv H2. lcp_cases H1; inv H3.
destruct H5. eexists. eauto with IPPGrammar.
+ apply Infix_dlmcf; auto. intro. inv H3. inv H4. lcp_cases H3; inv H5. inv H12. inv H4.
eapply H2; eauto with IPPGrammar.
- simpl. apply Infix_dlmcf; auto with IPPGrammar. intro. inv H2. inv H3. lcp_cases H2; inv H4. inv H11. inv H3.
- insert_in_pnode_destruct pr o t21 o2.
+ inv H1. apply Postfix_dlmcf; auto. intro. inv H1. inv H2. lcp_cases H1; inv H3.
+ apply Infix_dlmcf; auto with IPPGrammar. intro. inv H3. inv H4. lcp_cases H3; inv H5. eapply H2; eauto.
Qed.
Lemma insert_pre_dlmcfree {g} (pr : drules g) o t2 :
safe_pr pr ->
dlm_conflict_free (lm_conflict_pattern pr) t2 ->
dlm_conflict_free (lm_conflict_pattern pr) (insert_pre pr o t2).
Proof.
intros. induction t2 as [l2|t21 ? o2 t22|o2 t22|t21 ? o2].
- simpl. apply Prefix_dlmcf; auto. intro. inv H1. inv H2. lcp_cases H1; inv H3. inv H4. inv H2.
- insert_pre_inode_destruct pr o t21 o2 t22.
+ inv H0. apply Infix_dlmcf; auto. intro. inv H0. inv H1. lcp_cases H0; inv H2.
destruct H4. eexists. eauto with IPPGrammar.
+ inv H0. apply Infix_dlmcf; auto. intro. inv H0. inv H1. lcp_cases H0; inv H2.
destruct H4. eexists. eauto with IPPGrammar.
+ apply Prefix_dlmcf; auto. intro. inv H2. inv H3. lcp_cases H2; inv H4. inv H5. inv H3.
eapply H1; eauto with IPPGrammar.
- simpl. apply Prefix_dlmcf; auto. intro. inv H1. inv H2. lcp_cases H1; inv H3. inv H4. inv H2.
- insert_pre_pnode_destruct pr o t21 o2.
+ inv H0. apply Postfix_dlmcf; auto. intro. inv H0. inv H1. lcp_cases H0; inv H2.
+ apply Prefix_dlmcf; auto with IPPGrammar. intro. inv H2. inv H3. lcp_cases H2; inv H4. eapply H1; eauto.
Qed.
Lemma postfixnode_single_dlmcfree {g} (pr : drules g) o l1 :
dlm_conflict_free (lm_conflict_pattern pr) (PostfixNode (AtomicNode l1) o).
Proof.
apply Postfix_dlmcf; auto with IPPGrammar. intro. destruct H as [q]. inv H. lcp_cases H0; inv H1.
Qed.
Lemma insert_post_matches_lm {g} (pr : drules g) o t1 o1 :
matches_lm (insert_post pr t1 o) (PostfixPatt HPatt o1) ->
matches_lm t1 (PostfixPatt HPatt o1) \/ o1 = o.
Proof.
intros. destruct t1.
- simpl in H. inv H.
+ inv H0. auto.
+ inv H3. inv H.
- insert_post_inode_destruct pr t1_1 o0 t1_2 o.
+ inv H. inv H0. left. auto with IPPGrammar.
+ inv H. inv H0. left. auto with IPPGrammar.
+ inv H; auto. inv H1. auto.
- insert_post_pnode_destruct pr o0 t1 o.
+ inv H. inv H0.
+ inv H; auto. inv H1; auto.
- inv H; auto. inv H0. auto.
Qed.
Lemma insert_post_dlmcfree {g} (pr : drules g) t1 o :
safe_pr pr ->
dlm_conflict_free (lm_conflict_pattern pr) t1 ->
dlm_conflict_free (lm_conflict_pattern pr) (insert_post pr t1 o).
Proof.
intros. induction t1 as [l1|t11 ? o1 t12|o1 t12|t11 ? o1].
- simpl. apply postfixnode_single_dlmcfree.
- insert_post_inode_destruct pr t11 o1 t12 o.
+ inv H0. apply Infix_dlmcf; auto. intro. inv H0. inv H1. lcp_cases H0; inv H2.
apply insert_post_matches_lm in H12. inv H12.
* destruct H4. eexists. eauto with IPPGrammar.
* eauto using safe_infix_postfix.
+ inv H0. apply Infix_dlmcf; auto. intro. inv H0. inv H1. lcp_cases H0; inv H2. inv E2. inv H1. inv H3. inv H1.
destruct t12.
**inv H11. inv H1.
**inv H11. inv H1. rename E into E'. insert_post_inode_destruct pr t12_1 o0 t12_2 o.
***inv H12. inv H1. destruct H4. eexists. eauto with IPPGrammar.
***inv H12. inv H1. destruct H4. eexists. eauto with IPPGrammar.
***eapply H1; eauto with IPPGrammar.
**rename E into E'. insert_post_pnode_destruct pr o0 t12 o.
***inv H12. inv H1.
***eapply H1; eauto.
**inv H11. inv H1.
+ apply Postfix_dlmcf; auto. intro. inv H2. inv H3. lcp_cases H2; inv H4.
- insert_post_pnode_destruct pr o1 t12 o.
+ inv H0. apply Prefix_dlmcf; auto. intro. inv H0. inv H1. lcp_cases H0; inv H2. inv E. inv H1. inv H6.
* inv H1. destruct t12.
**simpl in H5. inv H5.
***inv H1. eauto using safe_prefix_postfix.
***inv H9. inv H1.
**insert_post_inode_destruct pr t12_1 o0 t12_2 o.
***inv H5. inv H1. destruct H3. eexists. eauto with IPPGrammar.
***inv H5. inv H1. destruct H3. eexists. eauto with IPPGrammar.
***inv H5.
****inv H6. eauto using safe_prefix_postfix.
****inv H10. inv H5. destruct H3. eexists. eauto with IPPGrammar.
**insert_post_pnode_destruct pr o0 t12 o.
***inv H5. inv H1.
***inv H5.
****inv H6. eauto using safe_prefix_postfix.
****inv H10. inv H5.
**simpl in H5. inv H5.
***inv H1. eauto using safe_prefix_postfix.
***destruct H3. eexists. eauto with IPPGrammar.
* destruct t12.
**inv H9. inv H1.
**inv H9. inv H1. insert_post_inode_destruct pr t12_1 o0 t12_2 o.
***inv H5. inv H1. destruct H3. eexists. eauto with IPPGrammar.
***inv H5. inv H1. destruct H3. eexists. eauto with IPPGrammar.
***inv H5.
****inv H6. eapply H1; eauto with IPPGrammar.
****inv H9. inv H5. destruct H3. eexists. eauto with IPPGrammar.