-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreAdministrativeCommutation.v
More file actions
2794 lines (2669 loc) · 102 KB
/
Copy pathCoreAdministrativeCommutation.v
File metadata and controls
2794 lines (2669 loc) · 102 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
From Stdlib Require Import FunctionalExtensionality Lia PeanoNat
Relations.Relation_Operators.
Require Import AdministrativeReduction.
Require Import AdministrativeAlgebra.
Require Import AdministrativeResiduals.
Require Import FrameCompatibility.
Require Import SharedPrompts.CoreParallel.
Require Import SharedPrompts.CoreParallelCompatibility.
Require Import SharedPrompts.ScopedAlgebra.
Require Import SharedPrompts.SubstitutionMaps.
Require Import SharedPrompts.CoreAlgebra.
Require Import SharedPrompts.ScopedFusion.
Require Import SharedPrompts.MapComposition.
Import SharedPrompts.
Import SharedPrompts.ContinuationMaps.
(** TODO after commutation: eliminate functional extensionality, add the
sequential/parallel core bridges, define the final union [estep], and
finish cosmetic API consolidation. *)
Lemma admin_ksubst_star_sequence e e' :
star admin_step e e' -> forall cut k,
star admin_step
(ksubst_e cut (ICont k CHole) e)
(ksubst_e cut (ICont k CHole) e').
Proof.
intro H. induction H as [x|x y z Hxy Hyz IH]; intros cut k.
- apply star_refl.
- eapply star_trans.
+ exact (proj2 admin_ksubst_star x y Hxy cut k).
+ exact (IH cut k).
Qed.
Lemma admin_olift_value_star v v' :
star admin_vstep v v' -> forall cut,
star admin_vstep (olift_v cut 1 v) (olift_v cut 1 v').
Proof.
intro H. induction H as [x | x y z Hxy Hyz IH]; intro cut.
- apply star_refl.
- eapply star_step.
+ exact (proj1 admin_olift_step x y Hxy cut).
+ exact (IH cut).
Qed.
Lemma admin_klift_value_star v v' :
star admin_vstep v v' -> forall cut,
star admin_vstep (klift_v cut 1 v) (klift_v cut 1 v').
Proof.
intro H. induction H as [x | x y z Hxy Hyz IH]; intro cut.
- apply star_refl.
- eapply star_step.
+ exact (proj1 admin_klift_step x y Hxy cut).
+ exact (IH cut).
Qed.
(** Changing the value installed for one ordinary variable transports an
administrative sequence. Multiple occurrences account for the star. *)
Lemma admin_substitution_value_star :
(forall x cut v v', star admin_vstep v v' ->
star admin_vstep
(osubst_v cut v x) (osubst_v cut v' x)) /\
(forall e cut v v', star admin_vstep v v' ->
star admin_step
(osubst_e cut v e) (osubst_e cut v' e)).
Proof.
apply (syntax_ind
(fun x => forall cut v v', star admin_vstep v v' ->
star admin_vstep (osubst_v cut v x) (osubst_v cut v' x))
(fun e => forall cut v v', star admin_vstep v v' ->
star admin_step (osubst_e cut v e) (osubst_e cut v' e))).
- intros n cut v v' Hv. simpl. destruct (remove_index cut n).
+ apply star_refl.
+ exact Hv.
- intros e IH cut v v' Hv. simpl.
apply (admin_star_map admin_step admin_vstep VLam).
+ intros x y Hxy. apply AVS_Lam. exact Hxy.
+ apply IH. exact (admin_olift_value_star v v' Hv 0).
- intros v0 IH cut v v' Hv. simpl.
apply (admin_star_map admin_vstep admin_step EVal).
+ intros x y Hxy. apply AS_Val. exact Hxy.
+ apply IH. exact Hv.
- intros v0 IHv u IHu cut v v' Hv. simpl.
eapply star_trans.
+ apply (admin_star_map admin_vstep admin_step
(fun x => EApp x (osubst_v cut v u))).
* intros x y Hxy. apply AS_AppL. exact Hxy.
* apply IHv. exact Hv.
+ apply (admin_star_map admin_vstep admin_step
(fun x => EApp (osubst_v cut v' v0) x)).
* intros x y Hxy. apply AS_AppR. exact Hxy.
* apply IHu. exact Hv.
- intros a IHa t IHt cut v v' Hv. simpl.
eapply star_trans.
+ apply (admin_star_map admin_step admin_step
(fun x => ELet x (osubst_e (S cut) (olift_v 0 1 v) t))).
* intros x y Hxy. apply AS_LetBinding. exact Hxy.
* apply IHa. exact Hv.
+ apply (admin_star_map admin_step admin_step
(fun x => ELet (osubst_e cut v' a) x)).
* intros x y Hxy. apply AS_LetBody. exact Hxy.
* apply IHt. exact (admin_olift_value_star v v' Hv 0).
- intros e IH cut v v' Hv. simpl.
apply (admin_star_map admin_step admin_step EShift).
+ intros x y Hxy. apply AS_ShiftBody. exact Hxy.
+ apply IH. exact (admin_klift_value_star v v' Hv 0).
- intros k e IH cut v v' Hv. simpl.
apply (admin_star_map admin_step admin_step (ECont k)).
+ intros x y Hxy. apply AS_ContBody. exact Hxy.
+ apply IH. exact Hv.
- intros k cut v v' Hv. apply star_refl.
Qed.
Corollary admin_subst0_value_star v v' e :
star admin_vstep v v' ->
star admin_step
(subst_e (subst0 v) e) (subst_e (subst0 v') e).
Proof.
intro H. unfold subst0. rewrite !subst_single_e.
exact (proj2 admin_substitution_value_star e 0 v v' H).
Qed.
Lemma cocc_osubst_preserved :
(forall x k cut v, cocc_v k x = true ->
cocc_v k (osubst_v cut v x) = true) /\
(forall e k cut v, cocc_e k e = true ->
cocc_e k (osubst_e cut v e) = true).
Proof.
apply (syntax_ind
(fun x => forall k cut v, cocc_v k x = true ->
cocc_v k (osubst_v cut v x) = true)
(fun e => forall k cut v, cocc_e k e = true ->
cocc_e k (osubst_e cut v e) = true)).
- intros n k cut v H. discriminate.
- intros e IH k cut v H. simpl in *. apply IH. exact H.
- intros x IH k cut v H. simpl in *. apply IH. exact H.
- intros x IHx y IHy k cut v H. simpl in *.
apply Bool.orb_true_iff in H. apply Bool.orb_true_iff.
destruct H as [H | H]; [left; apply IHx | right; apply IHy]; exact H.
- intros a IHa t IHt k cut v H. simpl in *.
apply Bool.orb_true_iff in H. apply Bool.orb_true_iff.
destruct H as [H | H].
+ left. apply IHa. exact H.
+ right. apply IHt. exact H.
- intros e IH k cut v H. simpl in *. apply IH. exact H.
- intros j e IH k cut v H. simpl in *.
apply Bool.orb_true_iff in H. apply Bool.orb_true_iff.
destruct H as [H | H]; [left | right; apply IH]; exact H.
- intros j k cut v H. exact H.
Qed.
Lemma osubst_abort cut v e :
osubst_e cut v (abort e) = abort (osubst_e cut v e).
Proof.
unfold abort. simpl. f_equal.
symmetry. apply klift_osubst_e.
Qed.
Lemma tail_step_osubst k e e' :
tail_step k e e' -> forall cut v,
tail_step k (osubst_e cut v e) (osubst_e cut v e').
Proof.
intro H. induction H as [k a t t' Htail IH | k e Hocc | k e];
intros cut v.
- simpl. apply TS_LetBody. apply IH.
- rewrite osubst_abort, fs_osubst_ksubst_hole_e_upk.
simpl.
apply TS_Shift. apply (proj2 cocc_osubst_preserved).
exact Hocc.
- rewrite osubst_abort. simpl. apply TS_Abort.
Qed.
Lemma admin_osubst_step_from_roots
(Hlet_shift : forall e t cut v,
admin_step
(osubst_e cut v (ELet (EShift e) t))
(osubst_e cut v (EShift (krepl_e 0 (frame t) e))))
(Hlet_assoc : forall a u t cut v,
admin_step
(osubst_e cut v (ELet (ELet a u) t))
(osubst_e cut v
(ELet a (ELet u (olift_e 1 1 t))))) :
(forall x x', admin_vstep x x' -> forall cut v,
admin_vstep (osubst_v cut v x) (osubst_v cut v x')) /\
(forall e e', admin_step e e' -> forall cut v,
admin_step (osubst_e cut v e) (osubst_e cut v e')).
Proof.
apply admin_mutind.
- intros e e' H IH cut v. simpl. apply AVS_Lam. apply IH.
- intros x x' H IH cut v. simpl. apply AS_Val. apply IH.
- intros x x' y H IH cut v. simpl. apply AS_AppL. apply IH.
- intros x y y' H IH cut v. simpl. apply AS_AppR. apply IH.
- intros a a' t H IH cut v. simpl. apply AS_LetBinding. apply IH.
- intros a t t' H IH cut v. simpl. apply AS_LetBody. apply IH.
- intros e e' H IH cut v. simpl. apply AS_ShiftBody. apply IH.
- intros k e e' H IH cut v. simpl. apply AS_ContBody. apply IH.
- intros k e e' Htail cut v. simpl. apply AS_ContTail.
apply tail_step_osubst. exact Htail.
- exact Hlet_shift.
- exact Hlet_assoc.
Qed.
Lemma admin_osubst_star_from_roots
(Hlet_shift : forall e t cut v,
admin_step
(osubst_e cut v (ELet (EShift e) t))
(osubst_e cut v (EShift (krepl_e 0 (frame t) e))))
(Hlet_assoc : forall a u t cut v,
admin_step
(osubst_e cut v (ELet (ELet a u) t))
(osubst_e cut v
(ELet a (ELet u (olift_e 1 1 t)))))
e e' :
star admin_step e e' -> forall cut v,
star admin_step (osubst_e cut v e) (osubst_e cut v e').
Proof.
intro H. induction H as [x | x y z Hxy Hyz IH]; intros cut v.
- apply star_refl.
- eapply star_step.
+ exact (proj2
(admin_osubst_step_from_roots Hlet_shift Hlet_assoc)
x y Hxy cut v).
+ exact (IH cut v).
Qed.
Lemma osubst_olift_one_below cut v e :
osubst_e (S (S cut)) (olift_v 0 1 (olift_v 0 1 v))
(olift_e 1 1 e) =
olift_e 1 1 (osubst_e (S cut) (olift_v 0 1 v) e).
Proof.
pose proof (omap_olift_depth_e 1 (osub_map cut v) e) as H.
cbn [omap_up_n] in H.
rewrite (osub_map_lam_eq cut v) in H.
rewrite (osub_map_lam_eq (S cut) (olift_v 0 1 v)) in H.
rewrite !omap_single_e in H. exact H.
Qed.
Fixpoint osubst_ectx (cut : nat) (v : value) (c : ectx) : ectx :=
match c with
| CHole => CHole
| CLet c t =>
CLet (osubst_ectx cut v c)
(osubst_e (S cut) (olift_v 0 1 v) t)
end.
Definition osubst_installed (cut : nat) (v : value)
(d : installed) : installed :=
match d with
| ICont k c => ICont k (osubst_ectx cut v c)
end.
Lemma osubst_plug_ectx cut v c q :
osubst_e cut v (plug c q) =
plug (osubst_ectx cut v c) (osubst_e cut v q).
Proof.
induction c as [|c IH t]; simpl; [reflexivity |].
rewrite IH. reflexivity.
Qed.
Lemma osubst_plug_installed cut v d q :
osubst_e cut v (plug_d d q) =
plug_d (osubst_installed cut v d) (osubst_e cut v q).
Proof.
destruct d as [k c]. simpl. f_equal. apply osubst_plug_ectx.
Qed.
Lemma osubst_ectx_olift cut v c :
osubst_ectx (S cut) (olift_v 0 1 v) (olift_c 0 1 c) =
olift_c 0 1 (osubst_ectx cut v c).
Proof.
induction c as [|c IH t]; simpl.
- reflexivity.
- f_equal.
+ exact IH.
+ apply osubst_olift_one_below.
Qed.
Lemma osubst_installed_olift cut v d :
osubst_installed (S cut) (olift_v 0 1 v) (olift_d 0 1 d) =
olift_d 0 1 (osubst_installed cut v d).
Proof.
destruct d as [k c]. simpl. f_equal. apply osubst_ectx_olift.
Qed.
Lemma osubst_ectx_klift cut v c :
osubst_ectx cut (klift_v 0 1 v) (klift_c 0 1 c) =
klift_c 0 1 (osubst_ectx cut v c).
Proof.
induction c as [|c IH t]; simpl.
- reflexivity.
- f_equal; [exact IH |].
rewrite <- klift_olift_v_comm.
symmetry. apply klift_osubst_e.
Qed.
Lemma osubst_installed_klift cut v d :
osubst_installed cut (klift_v 0 1 v) (klift_d 0 1 d) =
klift_d 0 1 (osubst_installed cut v d).
Proof.
destruct d as [k c]. simpl. f_equal. apply osubst_ectx_klift.
Qed.
Lemma osubst_krepl :
(forall x kc d cut v,
cocc_v kc v = false ->
osubst_v cut v (krepl_v kc d x) =
krepl_v kc (osubst_installed cut v d) (osubst_v cut v x)) /\
(forall e kc d cut v,
cocc_v kc v = false ->
osubst_e cut v (krepl_e kc d e) =
krepl_e kc (osubst_installed cut v d) (osubst_e cut v e)).
Proof.
apply (syntax_ind
(fun x => forall kc d cut v,
cocc_v kc v = false ->
osubst_v cut v (krepl_v kc d x) =
krepl_v kc (osubst_installed cut v d) (osubst_v cut v x))
(fun e => forall kc d cut v,
cocc_v kc v = false ->
osubst_e cut v (krepl_e kc d e) =
krepl_e kc (osubst_installed cut v d) (osubst_e cut v e))).
- intros n kc d cut v Hfresh. simpl.
destruct (remove_index cut n) as [n' |] eqn:Hremove; simpl.
+ reflexivity.
+ symmetry. apply (proj1 admin_krepl_no_cocc). exact Hfresh.
- intros e IH kc d cut v Hfresh. simpl. f_equal.
rewrite IH, osubst_installed_olift; [reflexivity |].
rewrite (proj1 admin_cocc_olift). exact Hfresh.
- intros x IH kc d cut v Hfresh. simpl. f_equal. apply IH. exact Hfresh.
- intros x IHx y IHy kc d cut v Hfresh. simpl. f_equal.
+ apply IHx. exact Hfresh.
+ apply IHy. exact Hfresh.
- intros a IHa t IHt kc d cut v Hfresh. simpl. f_equal.
+ apply IHa. exact Hfresh.
+ rewrite IHt, osubst_installed_olift; [reflexivity |].
rewrite (proj1 admin_cocc_olift). exact Hfresh.
- intros e IH kc d cut v Hfresh. simpl. f_equal.
rewrite IH, osubst_installed_klift; [reflexivity |].
rewrite cocc_klift_zero_succ_v. exact Hfresh.
- intros k e IH kc d cut v Hfresh. simpl.
destruct (Nat.eqb k kc); simpl.
+ rewrite osubst_plug_installed, IH; [reflexivity | exact Hfresh].
+ f_equal. apply IH. exact Hfresh.
- intros k kc d cut v Hfresh. simpl. destruct (Nat.eqb k kc).
+ destruct d. reflexivity.
+ reflexivity.
Qed.
Lemma osubst_installed_frame cut v t :
osubst_installed cut (klift_v 0 1 v) (frame t) =
frame (osubst_e (S cut) (olift_v 0 1 v) t).
Proof.
unfold frame, osubst_installed. simpl. f_equal. f_equal.
symmetry. rewrite <- klift_olift_v_comm. apply klift_osubst_e.
Qed.
Lemma admin_osubst_let_assoc_root a u t cut v :
admin_step
(osubst_e cut v (ELet (ELet a u) t))
(osubst_e cut v (ELet a (ELet u (olift_e 1 1 t)))).
Proof.
simpl.
rewrite osubst_olift_one_below.
apply AS_LetAssoc.
Qed.
Lemma admin_osubst_let_shift_root e t cut v :
admin_step
(osubst_e cut v (ELet (EShift e) t))
(osubst_e cut v (EShift (krepl_e 0 (frame t) e))).
Proof.
simpl.
rewrite (proj2 osubst_krepl e 0 (frame t) cut
(klift_v 0 1 v) (cocc_klift_fresh_v 0 v)).
rewrite osubst_installed_frame.
apply AS_LetShift.
Qed.
Corollary admin_osubst_star e e' :
star admin_step e e' -> forall cut v,
star admin_step (osubst_e cut v e) (osubst_e cut v e').
Proof.
apply admin_osubst_star_from_roots.
- exact admin_osubst_let_shift_root.
- exact admin_osubst_let_assoc_root.
Qed.
Corollary admin_subst0_expr_star v e e' :
star admin_step e e' ->
star admin_step
(subst_e (subst0 v) e) (subst_e (subst0 v) e').
Proof.
intro H. unfold subst0. rewrite !subst_single_e.
exact (admin_osubst_star e e' H 0 v).
Qed.
Lemma subst0_let_lift_cancel (v : value) (u t : expr) :
subst_e (subst0 v) (ELet u (olift_e 1 1 t)) =
ELet (subst_e (subst0 v) u) t.
Proof.
unfold subst0.
rewrite !subst_single_e.
simpl. rewrite osubst_olift_cancel_e. reflexivity.
Qed.
Lemma core_parallel_let_assoc_residual
(delta : payload_env) (a u b t t' : expr) :
core_parallel delta (ELet a u) b ->
core_parallel (payload_env_olift delta) t t' ->
exists z,
star admin_step (ELet b t') z /\
core_parallel delta
(ELet a (ELet u (olift_e 1 1 t))) z.
Proof.
intros Hbinding Htail. inversion Hbinding; subst.
- exists (ELet a' (ELet t'0 (olift_e 1 1 t'))); split.
+ apply star_one. apply AS_LetAssoc.
+ apply CP_Let; [assumption |].
apply CP_Let; [assumption |].
pose proof (core_parallel_olift_expr_at Htail 1) as Hlift.
change (core_parallel
(payload_env_olift_at (S 0) (payload_env_olift delta))
(olift_e 1 1 t) (olift_e 1 1 t')) in Hlift.
rewrite (payload_env_olift_at_payload_env_olift 0 delta) in Hlift.
exact Hlift.
- exists (ELet (subst_e (subst0 v') t'0) t'); split.
+ apply star_refl.
+ replace (ELet (subst_e (subst0 v') t'0) t') with
(subst_e (subst0 v') (ELet t'0 (olift_e 1 1 t'))).
* apply CP_LetValue; [assumption |].
apply CP_Let; [assumption |].
pose proof (core_parallel_olift_expr_at Htail 1) as Hlift.
change (core_parallel
(payload_env_olift_at (S 0) (payload_env_olift delta))
(olift_e 1 1 t) (olift_e 1 1 t')) in Hlift.
rewrite (payload_env_olift_at_payload_env_olift 0 delta) in Hlift.
exact Hlift.
* apply subst0_let_lift_cancel.
Qed.
(** The outer-constructor induction. This deliberately exposes only the
substitution and root/tail residuals; no datatype of reduction positions
is introduced. *)
Lemma core_admin_commute_from_residuals
(Hsubst_expr : forall v e e',
star admin_step e e' ->
star admin_step
(subst_e (subst0 v) e) (subst_e (subst0 v) e'))
(Hsubst_value : forall v v' e,
star admin_vstep v v' ->
star admin_step
(subst_e (subst0 v) e) (subst_e (subst0 v') e))
(Hlet_shift : forall delta e e' t t',
core_parallel delta (EShift e) (EShift e') ->
core_parallel (payload_env_olift delta) t t' ->
exists u,
star admin_step (ELet (EShift e') t') u /\
core_parallel delta
(EShift (krepl_e 0 (frame t) e)) u)
(Hlet_assoc : forall delta a u b t t',
core_parallel delta (ELet a u) b ->
core_parallel (payload_env_olift delta) t t' ->
exists z,
star admin_step (ELet b t') z /\
core_parallel delta
(ELet a (ELet u (olift_e 1 1 t))) z)
(Hcont_tail : forall delta k e e' a,
core_parallel delta e e' ->
tail_step k e a ->
exists u,
star admin_step (ECont k e') u /\
core_parallel delta (ECont k a) u)
(Hcont_shift_tail : forall delta k e e' a,
core_parallel (payload_env_klift delta) e e' ->
tail_step k (EShift e) a ->
exists u,
star admin_step (ksubst_e 0 (ICont k CHole) e') u /\
core_parallel delta (ECont k a) u) :
forall delta,
(forall v c,
core_value_parallel delta v c ->
forall a, admin_vstep v a ->
exists u, star admin_vstep c u /\ core_value_parallel delta a u) /\
(forall e c,
core_parallel delta e c ->
forall a, admin_step e a ->
exists u, star admin_step c u /\ core_parallel delta a u).
Proof.
apply (core_parallel_mutind
(fun delta v c _ => forall a, admin_vstep v a ->
exists u, star admin_vstep c u /\ core_value_parallel delta a u)
(fun delta e c _ => forall a, admin_step e a ->
exists u, star admin_step c u /\ core_parallel delta a u)).
- intros delta n a Ha. inversion Ha.
- intros delta e e' Hp IH a Ha. inversion Ha; subst.
match goal with
| H : admin_step e _ |- _ =>
destruct (IH _ H) as [u [Heu Hcore]]
end.
exists (VLam u); split.
+ apply (admin_star_map admin_step admin_vstep VLam); [|exact Heu].
intros x y Hxy. apply AVS_Lam. exact Hxy.
+ apply CP_VLam. exact Hcore.
- intros delta v v' Hp IH a Ha. inversion Ha; subst.
match goal with
| H : admin_vstep v _ |- _ =>
destruct (IH _ H) as [u [Hvu Hcore]]
end.
exists (EVal u); split.
+ apply (admin_star_map admin_vstep admin_step EVal); [|exact Hvu].
intros x y Hxy. apply AS_Val. exact Hxy.
+ apply CP_Val. exact Hcore.
- intros delta v v' u u' Hv IHv Hu IHu a Ha.
inversion Ha; subst.
+ match goal with
| H : admin_vstep v _ |- _ =>
destruct (IHv _ H) as [w [Hvw Hcore]]
end.
exists (EApp w u'); split.
* apply (admin_star_map admin_vstep admin_step
(fun x => EApp x u')); [|exact Hvw].
intros x y Hxy. apply AS_AppL. exact Hxy.
* apply CP_App; [exact Hcore | exact Hu].
+ match goal with
| H : admin_vstep u _ |- _ =>
destruct (IHu _ H) as [w [Huw Hcore]]
end.
exists (EApp v' w); split.
* apply (admin_star_map admin_vstep admin_step
(fun x => EApp v' x)); [|exact Huw].
intros x y Hxy. apply AS_AppR. exact Hxy.
* apply CP_App; [exact Hv | exact Hcore].
- intros delta a a' t t' Ha IHa Ht IHt z Hz.
inversion Hz; subst.
+ match goal with
| H : admin_step a _ |- _ =>
destruct (IHa _ H) as [b [Hab Hcore]]
end.
exists (ELet b t'); split.
* apply (admin_star_map admin_step admin_step
(fun x => ELet x t')); [|exact Hab].
intros x y Hxy. apply AS_LetBinding. exact Hxy.
* apply CP_Let; [exact Hcore | exact Ht].
+ match goal with
| H : admin_step t _ |- _ =>
destruct (IHt _ H) as [q [Htq Hcore]]
end.
exists (ELet a' q); split.
* apply (admin_star_map admin_step admin_step
(fun x => ELet a' x)); [|exact Htq].
intros x y Hxy. apply AS_LetBody. exact Hxy.
* apply CP_Let; [exact Ha | exact Hcore].
+ inversion Ha; subst. eapply Hlet_shift; eassumption.
+ eapply Hlet_assoc; eassumption.
- intros delta e e' Hp IH a Ha. inversion Ha; subst.
match goal with
| H : admin_step e _ |- _ =>
destruct (IH _ H) as [u [Heu Hcore]]
end.
exists (EShift u); split.
+ apply (admin_star_map admin_step admin_step EShift); [|exact Heu].
intros x y Hxy. apply AS_ShiftBody. exact Hxy.
+ apply CP_Shift. exact Hcore.
- intros delta k e e' Hp IH a Ha. inversion Ha; subst.
+ match goal with
| H : admin_step e _ |- _ =>
destruct (IH _ H) as [u [Heu Hcore]]
end.
exists (ECont k u); split.
* apply (admin_star_map admin_step admin_step (ECont k)); [|exact Heu].
intros x y Hxy. apply AS_ContBody. exact Hxy.
* apply CP_Cont. exact Hcore.
+ eapply Hcont_tail; eassumption.
- intros delta k a Ha. inversion Ha.
- intros delta k v Hlookup a Ha. inversion Ha.
- intros delta e e' v v' He IHe Hv IHv a Ha.
inversion Ha; subst.
+ match goal with
| Hlam : admin_vstep (VLam e) _ |- _ => inversion Hlam; subst
end.
match goal with
| H : admin_step e _ |- _ =>
destruct (IHe _ H) as [b [Heb Hcore]]
end.
exists (subst_e (subst0 v') b); split.
* apply Hsubst_expr. exact Heb.
* apply CP_Beta; [exact Hcore | exact Hv].
+ match goal with
| H : admin_vstep v _ |- _ =>
destruct (IHv _ H) as [w [Hvw Hcore]]
end.
exists (subst_e (subst0 w) e'); split.
* apply Hsubst_value. exact Hvw.
* apply CP_Beta; [exact He | exact Hcore].
- intros delta v v' t t' Hv IHv Ht IHt a Ha.
inversion Ha; subst.
+ match goal with
| Hval : admin_step (EVal v) _ |- _ => inversion Hval; subst
end.
match goal with
| H : admin_vstep v _ |- _ =>
destruct (IHv _ H) as [w [Hvw Hcore]]
end.
exists (subst_e (subst0 w) t'); split.
* apply Hsubst_value. exact Hvw.
* apply CP_LetValue; [exact Hcore | exact Ht].
+ match goal with
| H : admin_step t _ |- _ =>
destruct (IHt _ H) as [q [Htq Hcore]]
end.
exists (subst_e (subst0 v') q); split.
* apply Hsubst_expr. exact Htq.
* apply CP_LetValue; [exact Hv | exact Hcore].
- intros delta k e e' Hp IH a Ha.
inversion Ha; subst.
+ match goal with
| Hshift : admin_step (EShift e) _ |- _ =>
inversion Hshift; subst
end.
match goal with
| H : admin_step e _ |- _ =>
destruct (IH _ H) as [u [Heu Hcore]]
end.
exists (ksubst_e 0 (ICont k CHole) u); split.
* exact (admin_ksubst_star_sequence e' u Heu 0 k).
* apply CP_ContShift. exact Hcore.
+ eapply Hcont_shift_tail; eassumption.
Qed.
(** --------------------------------------------------------------------
Decreasing mixed pentagons, with [let.S] kept out of core parallelism.
Compared with strong commutation, the administrative reduct is allowed
to perform an administrative prefix before the residual parallel step:
x
P / \ A
p a
| |
A* A*
| |
b <-P- r
This is the mixed diagram required by the source-labelled decreasing-
diagrams argument. *)
Lemma core_admin_decreasing_from_residuals
(Hlet_shift : forall delta e p t t',
core_parallel delta (EShift e) p ->
core_parallel (payload_env_olift delta) t t' ->
exists r b,
star admin_step (ELet p t') b /\
star admin_step
(EShift (krepl_e 0 (frame t) e)) r /\
core_parallel delta r b)
(Hlet_assoc : forall delta a u p t t',
core_parallel delta (ELet a u) p ->
core_parallel (payload_env_olift delta) t t' ->
exists r b,
star admin_step (ELet p t') b /\
star admin_step
(ELet a (ELet u (olift_e 1 1 t))) r /\
core_parallel delta r b)
(Hcont_tail : forall delta k e p a,
core_parallel delta e p ->
tail_step k e a ->
exists r b,
star admin_step (ECont k p) b /\
star admin_step (ECont k a) r /\
core_parallel delta r b)
(Hcont_shift_tail : forall delta k e p a,
core_parallel (payload_env_klift delta) e p ->
tail_step k (EShift e) a ->
exists r b,
star admin_step
(ksubst_e 0 (ICont k CHole) p) b /\
star admin_step (ECont k a) r /\
core_parallel delta r b) :
forall delta,
(forall v p,
core_value_parallel delta v p ->
forall a, admin_vstep v a ->
exists r b,
star admin_vstep p b /\
star admin_vstep a r /\
core_value_parallel delta r b) /\
(forall e p,
core_parallel delta e p ->
forall a, admin_step e a ->
exists r b,
star admin_step p b /\
star admin_step a r /\
core_parallel delta r b).
Proof.
apply (core_parallel_mutind
(fun delta v p _ => forall a, admin_vstep v a ->
exists r b,
star admin_vstep p b /\
star admin_vstep a r /\
core_value_parallel delta r b)
(fun delta e p _ => forall a, admin_step e a ->
exists r b,
star admin_step p b /\
star admin_step a r /\
core_parallel delta r b)).
- intros delta n a Ha. inversion Ha.
- intros delta e e' Hp IH a Ha. inversion Ha; subst.
match goal with
| H : admin_step e _ |- _ =>
destruct (IH _ H) as [r [b [Heb [Har Hcore]]]]
end.
exists (VLam r), (VLam b); split; [|split].
+ apply (admin_star_map admin_step admin_vstep VLam); [|exact Heb].
intros x y Hxy. apply AVS_Lam. exact Hxy.
+ apply (admin_star_map admin_step admin_vstep VLam); [|exact Har].
intros x y Hxy. apply AVS_Lam. exact Hxy.
+ apply CP_VLam. exact Hcore.
- intros delta v v' Hp IH a Ha. inversion Ha; subst.
match goal with
| H : admin_vstep v _ |- _ =>
destruct (IH _ H) as [r [b [Hvb [Har Hcore]]]]
end.
exists (EVal r), (EVal b); split; [|split].
+ apply (admin_star_map admin_vstep admin_step EVal); [|exact Hvb].
intros x y Hxy. apply AS_Val. exact Hxy.
+ apply (admin_star_map admin_vstep admin_step EVal); [|exact Har].
intros x y Hxy. apply AS_Val. exact Hxy.
+ apply CP_Val. exact Hcore.
- intros delta v v' u u' Hv IHv Hu IHu a Ha.
inversion Ha; subst.
+ match goal with
| H : admin_vstep v _ |- _ =>
destruct (IHv _ H) as [r [b [Hvb [Har Hcore]]]]
end.
exists (EApp r u), (EApp b u'); split; [|split].
* apply (admin_star_map admin_vstep admin_step
(fun x => EApp x u')); [|exact Hvb].
intros x y Hxy. apply AS_AppL. exact Hxy.
* apply (admin_star_map admin_vstep admin_step
(fun x => EApp x u)); [|exact Har].
intros x y Hxy. apply AS_AppL. exact Hxy.
* apply CP_App; [exact Hcore | exact Hu].
+ match goal with
| H : admin_vstep u _ |- _ =>
destruct (IHu _ H) as [r [b [Hub [Har Hcore]]]]
end.
exists (EApp v r), (EApp v' b); split; [|split].
* apply (admin_star_map admin_vstep admin_step
(fun x => EApp v' x)); [|exact Hub].
intros x y Hxy. apply AS_AppR. exact Hxy.
* apply (admin_star_map admin_vstep admin_step
(fun x => EApp v x)); [|exact Har].
intros x y Hxy. apply AS_AppR. exact Hxy.
* apply CP_App; [exact Hv | exact Hcore].
- intros delta e e' t t' He IHe Ht IHt z Hz.
inversion Hz; subst.
+ match goal with
| H : admin_step e _ |- _ =>
destruct (IHe _ H) as [r [b [Heb [Har Hcore]]]]
end.
exists (ELet r t), (ELet b t'); split; [|split].
* apply (admin_star_map admin_step admin_step
(fun x => ELet x t')); [|exact Heb].
intros x y Hxy. apply AS_LetBinding. exact Hxy.
* apply (admin_star_map admin_step admin_step
(fun x => ELet x t)); [|exact Har].
intros x y Hxy. apply AS_LetBinding. exact Hxy.
* apply CP_Let; [exact Hcore | exact Ht].
+ match goal with
| H : admin_step t _ |- _ =>
destruct (IHt _ H) as [r [b [Htb [Har Hcore]]]]
end.
exists (ELet e r), (ELet e' b); split; [|split].
* apply (admin_star_map admin_step admin_step
(fun x => ELet e' x)); [|exact Htb].
intros x y Hxy. apply AS_LetBody. exact Hxy.
* apply (admin_star_map admin_step admin_step
(fun x => ELet e x)); [|exact Har].
intros x y Hxy. apply AS_LetBody. exact Hxy.
* apply CP_Let; [exact He | exact Hcore].
+ eapply Hlet_shift; eassumption.
+ eapply Hlet_assoc; eassumption.
- intros delta e e' Hp IH a Ha. inversion Ha; subst.
match goal with
| H : admin_step e _ |- _ =>
destruct (IH _ H) as [r [b [Heb [Har Hcore]]]]
end.
exists (EShift r), (EShift b); split; [|split].
+ apply (admin_star_map admin_step admin_step EShift); [|exact Heb].
intros x y Hxy. apply AS_ShiftBody. exact Hxy.
+ apply (admin_star_map admin_step admin_step EShift); [|exact Har].
intros x y Hxy. apply AS_ShiftBody. exact Hxy.
+ apply CP_Shift. exact Hcore.
- intros delta k e e' Hp IH a Ha. inversion Ha; subst.
+ match goal with
| H : admin_step e _ |- _ =>
destruct (IH _ H) as [r [b [Heb [Har Hcore]]]]
end.
exists (ECont k r), (ECont k b); split; [|split].
* apply (admin_star_map admin_step admin_step (ECont k)); [|exact Heb].
intros x y Hxy. apply AS_ContBody. exact Hxy.
* apply (admin_star_map admin_step admin_step (ECont k)); [|exact Har].
intros x y Hxy. apply AS_ContBody. exact Hxy.
* apply CP_Cont. exact Hcore.
+ eapply Hcont_tail; eassumption.
- intros delta k a Ha. inversion Ha.
- intros delta k v Hlookup a Ha. inversion Ha.
- intros delta e e' v v' He IHe Hv IHv a Ha.
inversion Ha; subst.
+ match goal with
| Hlam : admin_vstep (VLam e) _ |- _ => inversion Hlam; subst
end.
match goal with
| H : admin_step e _ |- _ =>
destruct (IHe _ H) as [r [b [Heb [Har Hcore]]]]
end.
exists (EApp (VLam r) v), (subst_e (subst0 v') b); split; [|split].
* apply admin_subst0_expr_star. exact Heb.
* apply (admin_star_map admin_step admin_step
(fun x => EApp (VLam x) v)); [|exact Har].
intros x y Hxy. apply AS_AppL. apply AVS_Lam. exact Hxy.
* apply CP_Beta; [exact Hcore | exact Hv].
+ match goal with
| H : admin_vstep v _ |- _ =>
destruct (IHv _ H) as [r [b [Hvb [Har Hcore]]]]
end.
exists (EApp (VLam e) r), (subst_e (subst0 b) e'); split; [|split].
* apply admin_subst0_value_star. exact Hvb.
* apply (admin_star_map admin_vstep admin_step
(fun x => EApp (VLam e) x)); [|exact Har].
intros x y Hxy. apply AS_AppR. exact Hxy.
* apply CP_Beta; [exact He | exact Hcore].
- intros delta v v' t t' Hv IHv Ht IHt a Ha.
inversion Ha; subst.
+ match goal with
| Hval : admin_step (EVal v) _ |- _ => inversion Hval; subst
end.
match goal with
| H : admin_vstep v _ |- _ =>
destruct (IHv _ H) as [r [b [Hvb [Har Hcore]]]]
end.
exists (ELet (EVal r) t), (subst_e (subst0 b) t'); split; [|split].
* apply admin_subst0_value_star. exact Hvb.
* apply (admin_star_map admin_vstep admin_step
(fun x => ELet (EVal x) t)); [|exact Har].
intros x y Hxy. apply AS_LetBinding. apply AS_Val. exact Hxy.
* apply CP_LetValue; [exact Hcore | exact Ht].
+ match goal with
| H : admin_step t _ |- _ =>
destruct (IHt _ H) as [r [b [Htb [Har Hcore]]]]
end.
exists (ELet (EVal v) r), (subst_e (subst0 v') b); split; [|split].
* apply admin_subst0_expr_star. exact Htb.
* apply (admin_star_map admin_step admin_step
(fun x => ELet (EVal v) x)); [|exact Har].
intros x y Hxy. apply AS_LetBody. exact Hxy.
* apply CP_LetValue; [exact Hv | exact Hcore].
- intros delta k e e' Hp IH a Ha.
inversion Ha; subst.
+ match goal with
| Hshift : admin_step (EShift e) _ |- _ =>
inversion Hshift; subst
end.
match goal with
| H : admin_step e _ |- _ =>
destruct (IH _ H) as [r [b [Heb [Har Hcore]]]]
end.
exists (ECont k (EShift r)),
(ksubst_e 0 (ICont k CHole) b); split; [|split].
* exact (admin_ksubst_star_sequence e' b Heb 0 k).
* apply (admin_star_map admin_step admin_step
(fun x => ECont k (EShift x))); [|exact Har].
intros x y Hxy. apply AS_ContBody. apply AS_ShiftBody. exact Hxy.
* apply CP_ContShift. exact Hcore.
+ eapply Hcont_shift_tail; eassumption.
Qed.
(** Let-association already satisfies the stronger square proved above, so
its decreasing residual needs no new algebra. *)
Lemma core_parallel_let_assoc_decreasing_residual
(delta : payload_env) (a u p t t' : expr) :
core_parallel delta (ELet a u) p ->
core_parallel (payload_env_olift delta) t t' ->
exists r b,
star admin_step (ELet p t') b /\
star admin_step
(ELet a (ELet u (olift_e 1 1 t))) r /\
core_parallel delta r b.
Proof.
intros Hp Ht.
destruct (core_parallel_let_assoc_residual delta a u p t t' Hp Ht)
as [b [Hpb Hcore]].
exists (ELet a (ELet u (olift_e 1 1 t))), b.
repeat split; try assumption. apply star_refl.
Qed.
(** Frame postponement is the one genuinely new algebraic lemma exposed by
the decreasing presentation. Administrative preprocessing may bubble
core [k.S] redexes back out of installed let frames; the final parallel
step also updates every duplicated copy of the frame payload. *)
Lemma osubst_olift_cancel_ectx (cut : nat) (v : value) (c : ectx) :
osubst_ectx cut v (olift_c cut 1 c) = c.
Proof.
induction c as [|c IH t]; simpl.
- reflexivity.
- rewrite IH, osubst_olift_cancel_e. reflexivity.
Qed.
Lemma osubst_olift_cancel_installed (cut : nat) (v : value)
(d : installed) :
osubst_installed cut v (olift_d cut 1 d) = d.
Proof.
destruct d as [k c]. simpl. f_equal.
apply osubst_olift_cancel_ectx.
Qed.
Lemma krepl_osubst_fusion :
(forall x kc d cut v,
krepl_v kc d (osubst_v cut v x) =
osubst_v cut (krepl_v kc d v)
(krepl_v kc (olift_d cut 1 d) x)) /\
(forall e kc d cut v,
krepl_e kc d (osubst_e cut v e) =
osubst_e cut (krepl_v kc d v)
(krepl_e kc (olift_d cut 1 d) e)).
Proof.
apply (syntax_ind
(fun x => forall kc d cut v,
krepl_v kc d (osubst_v cut v x) =
osubst_v cut (krepl_v kc d v)
(krepl_v kc (olift_d cut 1 d) x))
(fun e => forall kc d cut v,
krepl_e kc d (osubst_e cut v e) =
osubst_e cut (krepl_v kc d v)
(krepl_e kc (olift_d cut 1 d) e))).
- intros n kc d cut v. simpl.
destruct (remove_index cut n); reflexivity.
- intros e IH kc d cut v. simpl. f_equal.
rewrite (IH kc (olift_d 0 1 d) (S cut) (olift_v 0 1 v)).
rewrite (proj1 admin_olift_krepl v 0 1 kc d).
rewrite admin_olift_d_comp. reflexivity.
- intros v0 IH kc d cut v. simpl. f_equal. apply IH.
- intros v0 IHv u IHu kc d cut v. simpl. f_equal;
[apply IHv | apply IHu].
- intros a IHa t IHt kc d cut v. simpl. f_equal.
+ apply IHa.
+ rewrite (IHt kc (olift_d 0 1 d) (S cut) (olift_v 0 1 v)).
rewrite (proj1 admin_olift_krepl v 0 1 kc d).
rewrite admin_olift_d_comp. reflexivity.
- intros e IH kc d cut v. simpl. f_equal.
rewrite (IH (S kc) (klift_d 0 1 d) cut (klift_v 0 1 v)).
rewrite (admin_klift_krepl_v 0 kc d v).
rewrite admin_klift_olift_d_general. reflexivity.
- intros k e IH kc d cut v. simpl.
destruct (Nat.eqb k kc); simpl.
+ rewrite osubst_plug_installed, IH.
rewrite osubst_olift_cancel_installed. reflexivity.
+ rewrite IH. reflexivity.
- intros k kc d cut v. simpl.
destruct (Nat.eqb k kc); [destruct d |]; reflexivity.
Qed.
(** Pointwise ordinary lifting of every installed continuation in a map.
Unlike continuation lifting, ordinary lifting does not reindex the map's
domain, so its naturality law is genuinely pointwise. *)
Definition cmap_olift_at_action (cut amount : nat) (rho : cmap) : cmap :=
fun k => olift_d cut amount (rho k).
Lemma cmap_olift_at_action_binder cut amount rho :
cmap_olift_at_action (S cut) amount (cmap_olift rho) =
cmap_olift (cmap_olift_at_action cut amount rho).
Proof.
apply functional_extensionality. intro k.
unfold cmap_olift_at_action, cmap_olift.
apply admin_olift_d_comp.
Qed.
Lemma cmap_olift_at_action_shift cut amount rho :
cmap_olift_at_action cut amount (cmap_up rho) =
cmap_up (cmap_olift_at_action cut amount rho).
Proof.
apply functional_extensionality. intros [|k].
- reflexivity.
- unfold cmap_olift_at_action, cmap_up.
symmetry. apply admin_klift_olift_d_general.
Qed.
Lemma cmap_action_olift_v :
(forall v rho cut amount,
olift_v cut amount (cmap_v rho v) =
cmap_v (cmap_olift_at_action cut amount rho)
(olift_v cut amount v)) /\
(forall e rho cut amount,
olift_e cut amount (cmap_e rho e) =
cmap_e (cmap_olift_at_action cut amount rho)
(olift_e cut amount e)).
Proof.
apply (syntax_ind
(fun v => forall rho cut amount,
olift_v cut amount (cmap_v rho v) =