-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp4_stmt_subject_reductionScript.sml
4371 lines (3199 loc) · 126 KB
/
p4_stmt_subject_reductionScript.sml
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
open HolKernel boolLib liteLib simpLib Parse bossLib;
open arithmeticTheory stringTheory containerTheory pred_setTheory
listTheory finite_mapTheory;
open p4Lib;
open blastLib bitstringLib;
open p4Theory;
open p4_auxTheory;
open p4_deterTheory;
open p4_e_subject_reductionTheory;
open p4_e_progressTheory;
open bitstringTheory;
open wordsTheory;
open optionTheory;
open sumTheory;
open stringTheory;
open ottTheory;
open pairTheory;
open rich_listTheory;
open arithmeticTheory;
open alistTheory;
open numeralTheory;
(*tactics*)
fun OPEN_V_TYP_TAC v_term =
(Q.PAT_X_ASSUM `v_typ v_term t bll` (fn thm => ASSUME_TAC (SIMP_RULE (srw_ss()) [Once v_typ_cases] thm)))
fun OPEN_EXP_RED_TAC exp_term =
(Q.PAT_X_ASSUM `e_red j scope scopest ^exp_term exp2 fr` (fn thm => ASSUME_TAC (SIMP_RULE (srw_ss()) [Once e_sem_cases] thm)))
fun OPEN_ANY_EXP_RED_TAC exp_term =
(Q.PAT_X_ASSUM `e_red c scope scopest exp_term exp2 fr` (fn thm => ASSUME_TAC (SIMP_RULE (srw_ss()) [Once e_sem_cases] thm)))
fun OPEN_EXP_TYP_TAC exp_term =
(Q.PAT_X_ASSUM ` e_typ (t1,t2) t ^exp_term ta bll` (fn thm => ASSUME_TAC (SIMP_RULE (srw_ss()) [Once e_typ_cases] thm)))
fun OPEN_ANY_EXP_TYP_TAC exp_term =
(Q.PAT_X_ASSUM ` e_typ (t1,t2) t exp_term ta bll` (fn thm => ASSUME_TAC (SIMP_RULE (srw_ss()) [Once e_typ_cases] thm)))
fun OPEN_STMT_TYP_TAC stmt_term =
(Q.PAT_X_ASSUM ` stmt_typ (t1,t2) q g ^stmt_term` (fn thm => ASSUME_TAC (SIMP_RULE (srw_ss()) [Once stmt_typ_cases] thm)))
fun OPEN_STMT_RED_TAC stm_term =
(Q.PAT_X_ASSUM `stmt_red ct (ab, gsl,[(fun,[^stm_term],gam)],st) stat`
(fn thm => ASSUME_TAC (SIMP_RULE (srw_ss()) [Once stmt_sem_cases] thm)))
val OPEN_ANY_STMT_RED_TAC =
(Q.PAT_X_ASSUM `stmt_red ct (ab, gsl,[(fun,[stm_term],gam)],st) stat`
(fn thm => ASSUME_TAC (SIMP_RULE (srw_ss()) [Once stmt_sem_cases] thm)))
fun OPEN_FRAME_TYP_TAC frame_term =
(Q.PAT_X_ASSUM ` frame_typ (t1,t2) a b h d ^frame_term` (fn thm => ASSUME_TAC (SIMP_RULE (srw_ss()) [Once frame_typ_cases] thm)))
fun OPEN_LVAL_TYP_TAC lval_term =
(Q.PAT_X_ASSUM `lval_typ (g1,q1) t (^lval_term) (tp)` (fn thm => ASSUME_TAC (SIMP_RULE (srw_ss()) [Once lval_typ_cases] thm)))
val _ = new_theory "p4_stmt_subject_reduction";
(* represent the definition of:
ψlist_G ψlist_local ⊢ Φ
is the programmable blocks names so it is the main *)
(* here in t_scopes_consistent we need the same T_e as the caller, in the state's typing it should be the passed version *)
val res_frame_typ_def = Define ‘
res_frame_typ (order, f, (delta_g, delta_b, delta_x, delta_t)) Prs_n t_scope_list_g t_scope_list gscope framel func_map b_func_map t_scope_list_pre =
∀i. 0 <= i ∧ i < LENGTH framel ⇒
∃stmt_stack f_name local_scope_list passed_gscope passed_delta_b passed_delta_t passed_tslg.
EL i framel = (f_name,stmt_stack,local_scope_list) ∧
order (order_elem_f f_name) (order_elem_f f) ∧
t_passed_elem f_name delta_g delta_b delta_t t_scope_list_g = (SOME passed_delta_b, SOME passed_delta_t , SOME passed_tslg) ∧
scopes_to_pass f_name func_map b_func_map gscope = SOME passed_gscope ∧
t_scopes_consistent (order, f, (delta_g, delta_b, delta_x, delta_t)) (t_scope_list_pre) (t_scope_list_g) (t_scope_list) ∧
frame_typ (passed_tslg,t_scope_list) (order, f_name, (delta_g, passed_delta_b, delta_x, passed_delta_t))
Prs_n passed_gscope local_scope_list stmt_stack
’;
val sr_stmt_def = Define `
sr_stmt (stmt) (ty:'a itself) =
∀ stmtl ascope ascope' gscope gscope' (scopest:scope list) scopest' framel status status' t_scope_list t_scope_list_g T_e (c:'a ctx) order delta_g delta_b delta_t delta_x f Prs_n
apply_table_f ext_map func_map b_func_map pars_map tbl_map.
(c = ( apply_table_f , ext_map , func_map , b_func_map , pars_map , tbl_map ) ) ∧
(WT_c c order t_scope_list_g delta_g delta_b delta_x delta_t Prs_n) ∧
(T_e = (order, f, (delta_g, delta_b, delta_x, delta_t))) ∧
(frame_typ ( t_scope_list_g , t_scope_list ) T_e Prs_n gscope scopest [stmt] ) ∧
(stmt_red c ( ascope , gscope , [ (f, [stmt], scopest )] , status)
( ascope', gscope' , framel ++ [ (f, stmtl , scopest')] , status')) ⇒
(∃ t_scope_list'.
res_frame_typ T_e Prs_n t_scope_list_g t_scope_list' gscope framel func_map b_func_map t_scope_list) ∧
(∃ t_scope_list'' .
LENGTH t_scope_list'' = (LENGTH stmtl - LENGTH [stmt]) ∧
frame_typ ( t_scope_list_g , t_scope_list''++t_scope_list ) T_e Prs_n gscope' scopest' stmtl)
`;
val fr_len_exp_def = Define `
fr_len_exp (e) (ty:'a itself) =
∀ e' gscope (scopest:scope list) framel (c:'a ctx).
e_red c gscope scopest e e' framel ⇒
((LENGTH framel = 1 ∧ ∃f_called stmt_called copied_in_scope. framel = [(f_called,[stmt_called],copied_in_scope)]) ∨
(LENGTH framel = 0))
`;
val fr_len_exp_list_def = Define `
fr_len_exp_list (l : e list) (ty:'a itself) =
∀(e : e). MEM e l ==> fr_len_exp (e) (ty:'a itself)
`;
val fr_len_strexp_list_def = Define `
fr_len_strexp_list (l : (string#e) list) (ty:'a itself) =
∀ (e:e) . MEM e (SND (UNZIP l)) ==> fr_len_exp(e) (ty:'a itself)
`;
val fr_len_strexp_tup_def = Define `
fr_len_strexp_tup (tup : (string#e)) (ty:'a itself) =
fr_len_exp ((SND tup)) (ty:'a itself)
`;
fun FR_LEN_IND_CASE exp = OPEN_EXP_RED_TAC (exp) >>
gvs[] >>
METIS_TAC[]
(* The expression reduction can create a frame of length 1 or nothing [] *)
Theorem fr_len_from_e_theorem:
! (ty:'a itself) .
(!e. fr_len_exp e ty) /\
(! (l1: e list). fr_len_exp_list l1 ty) /\
(! (l2: (string#e) list) . fr_len_strexp_list l2 ty) /\
(! tup. fr_len_strexp_tup tup ty)
Proof
STRIP_TAC >>
Induct >>
fs[fr_len_exp_def] >>
REPEAT STRIP_TAC >| [
fs[Once e_sem_cases]
,
fs[Once e_sem_cases]
,
fs[Once e_sem_cases]
,
FR_LEN_IND_CASE “e_acc e s”
,
FR_LEN_IND_CASE “e_unop u e”
,
FR_LEN_IND_CASE “e_cast c e”
,
FR_LEN_IND_CASE “e_binop e b e'”
,
FR_LEN_IND_CASE “e_concat e e'”
,
FR_LEN_IND_CASE “e_slice e e' e''”
,
OPEN_EXP_RED_TAC “e_call f l” >>
gvs[fr_len_exp_list_def] >>
IMP_RES_TAC unred_arg_index_in_range >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL
[`EL i (MAP (λ(e_,e'_,x_,d_). e_) (e_e'_x_d_list : (e # e # string # d) list)) `])) >>
gvs[EL_MEM] >>
fs[fr_len_exp_def] >>
RES_TAC >>
gvs[]
,
FR_LEN_IND_CASE “(e_select e l s)”
,
OPEN_EXP_RED_TAC “(e_struct l2)” >>
gvs[] >>
gvs[fr_len_strexp_list_def] >>
IMP_RES_TAC unred_mem_index_in_range >>
subgoal `fr_len_exp (EL i (MAP (λ(f_,e_,e'_). e_) f_e_e'_list)) ty ` >-
(FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL
[`EL i (MAP (λ(f_,e_,e'_). e_) (f_e_e'_list : (string # e # e) list)) `])) >>
IMP_RES_TAC EL_MEM >>
IMP_RES_TAC mem_el_map2 >>
gvs[] ) >>
fs[fr_len_exp_def] >>
RES_TAC >>
gvs[]
,
OPEN_EXP_RED_TAC “(e_header b l2)” >>
gvs[fr_len_strexp_list_def] >>
IMP_RES_TAC unred_mem_index_in_range >>
subgoal `fr_len_exp (EL i (MAP (λ(f_,e_,e'_). e_) f_e_e'_list)) ty ` >-
(FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL
[`EL i (MAP (λ(f_,e_,e'_). e_) (f_e_e'_list : (string # e # e) list)) `])) >>
IMP_RES_TAC EL_MEM >>
IMP_RES_TAC mem_el_map2 >>
gvs[] ) >>
fs[fr_len_exp_def] >>
RES_TAC >>
gvs[]
,
fs[fr_len_strexp_list_def]
,
fs[fr_len_strexp_list_def, fr_len_strexp_tup_def] >>
REPEAT STRIP_TAC >>
PairCases_on ‘tup’ >> gvs[] >> gvs[]
,
fs[fr_len_strexp_tup_def, fr_len_exp_def] >>
gvs[]
,
fs[fr_len_exp_list_def]
,
fs[fr_len_exp_list_def] >>
REPEAT STRIP_TAC >>
gvs[] >>
gvs[fr_len_exp_def] >>
rfs[]
]
QED
fun FR_LEN_STMT_IND_CASE stm = OPEN_STMT_RED_TAC stm >>
gvs[] >>
ASSUME_TAC fr_len_from_e_theorem >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`ty`])) >>
LAST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`e`])) >>
fs[fr_len_exp_def] >> gvs[] >>
RES_TAC >> gvs[]
(* the statement reduction can create a framel of length 1 or 0 *)
Theorem fr_len_from_a_frame_theorem:
∀ stmt stmtl ascope ascope' gscope gscope' scopest scopest' f c status status' framel.
(stmt_red c ( ascope , gscope , [ (f, [stmt], scopest )] , status)
( ascope', gscope' , framel ++ [ (f, stmtl , scopest')] , status')) ⇒
((LENGTH framel = 1 ∧ ∃f_called stmt_called copied_in_scope. framel = [(f_called,[stmt_called],copied_in_scope)]) ∨ (LENGTH framel = 0))
Proof
Induct >>
REPEAT GEN_TAC >>
STRIP_TAC >| [
fs[Once stmt_sem_cases]
,
FR_LEN_STMT_IND_CASE “stmt_ass l e”
,
FR_LEN_STMT_IND_CASE “stmt_cond e stmt stmt'”
,
FR_LEN_STMT_IND_CASE “stmt_block l stmt”
,
FR_LEN_STMT_IND_CASE “stmt_ret e”
,
OPEN_STMT_RED_TAC “stmt_seq stmt stmt'” >>
gvs[] >>
RES_TAC >>
gvs[]
,
(*FR_LEN_STMT_IND_CASE “stmt_verify e e0” >>
gvs[] >>
ASSUME_TAC fr_len_from_e_theorem >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`ty`])) >>
fs[fr_len_exp_def] >> gvs[] >>
RES_TAC >> gvs[]
,*)
FR_LEN_STMT_IND_CASE “stmt_trans e”
,
OPEN_STMT_RED_TAC “stmt_app s l” >>
gvs[] >>
ASSUME_TAC fr_len_from_e_theorem >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`ty`])) >>
fs[fr_len_exp_def] >> gvs[] >>
RES_TAC >> gvs[]
,
fs[Once stmt_sem_cases]
]
QED
(* NOTE that in the res_frame, we take the previous T_e to calculate the new T_e *)
val frame_typ_imp_res_frame_single = prove (
“ ∀ Prs_n gscope t_scope_list_g t_scope_list_fr f_called copied_in_scope
stmt_called func_map b_func_map passed_gscope passed_delta_b
passed_delta_t passed_tslg order delta_g delta_b delta_x delta_t f t_scope_list.
order (order_elem_f f_called) (order_elem_f f) ∧
scopes_to_pass f_called func_map b_func_map gscope =
SOME passed_gscope ∧
t_passed_elem f_called delta_g delta_b delta_t t_scope_list_g =
(SOME passed_delta_b,SOME passed_delta_t,SOME passed_tslg) ∧
frame_typ (passed_tslg,t_scope_list_fr)
(order,f_called,delta_g,passed_delta_b,delta_x,passed_delta_t)
Prs_n passed_gscope copied_in_scope [stmt_called] ∧
t_scopes_consistent (order,f,delta_g,delta_b,delta_x,delta_t)
t_scope_list t_scope_list_g t_scope_list_fr
⇒
res_frame_typ (order,f,delta_g,delta_b,delta_x,delta_t) Prs_n t_scope_list_g t_scope_list_fr gscope
[(f_called,[stmt_called],copied_in_scope)] func_map b_func_map t_scope_list”,
fs[res_frame_typ_def] >>
REPEAT STRIP_TAC >>
‘i=0’ by fs[] >>
fs[Once EL] >>
Q.EXISTS_TAC ‘Prs_n’ >>
gvs[]
);
Theorem fr_len_from_a_stmtl_theorem:
∀ stmtl stmtl' ascope ascope' gscope gscope' scopest scopest' f c status status' framel.
(stmt_red c ( ascope , gscope , [ (f, stmtl, scopest )] , status)
( ascope', gscope' , framel ++ [ (f, stmtl' , scopest')] , status')) ⇒
((LENGTH framel = 1 ∧ ∃f_called stmt_called copied_in_scope. framel = [(f_called,[stmt_called],copied_in_scope)]) ∨ (LENGTH framel = 0))
Proof
Cases >>
REPEAT GEN_TAC >-
gvs[Once stmt_sem_cases] >>
REPEAT STRIP_TAC >>
gvs[Once stmt_sem_cases] >>
IMP_RES_TAC fr_len_from_a_frame_theorem >> gvs[]>>
ASSUME_TAC fr_len_from_e_theorem >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`ty`])) >>
LAST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`e`])) >>
fs[fr_len_exp_def] >> gvs[] >>
RES_TAC >> gvs[] >>
(*case stmt apply e*)
ASSUME_TAC fr_len_from_e_theorem >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`ty`])) >>
LAST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`(EL i (MAP (λ(e_,e'_). e_) (e_e'_list: (e # e) list)))`])) >>
fs[fr_len_exp_def] >> gvs[] >>
RES_TAC >> gvs[]
QED
fun OPEN_FRAME_TYP_TAC frame_term =
(Q.PAT_X_ASSUM ` frame_typ (t1,t2) a b h d ^frame_term` (fn thm => ASSUME_TAC (SIMP_RULE (srw_ss()) [Once frame_typ_cases] thm)))
fun EXP_IS_WT_IN_FRAME_TAC frm = OPEN_FRAME_TYP_TAC frm >>
fs[stmtl_typ_cases, type_ith_stmt_def] >>
gvs[] >>
rfs[Once stmt_typ_cases]
fun ASSUME_SR_EXP_FOR e = ASSUME_TAC SR_e >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`ty`])) >>
PAT_ASSUM ``∀e. sr_exp e ty`` ( STRIP_ASSUME_TAC o (Q.SPECL [e])) >>
fs[sr_exp_def]
fun INST_SR_EXP_FOR (e', tau, b) = FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [e', ‘gscope’, ‘scopest’,
‘[(f_called,[stmt_called],copied_in_scope)]’, ‘t_scope_list’, ‘t_scope_list_g’,
tau,b, ‘order’,‘delta_g’,‘delta_b’, ‘delta_t’,‘delta_x’,‘f’,‘f_called’,
‘stmt_called’,‘copied_in_scope’, ‘Prs_n’ ,‘apply_table_f’, ‘ext_map’, ‘func_map’, ‘b_func_map’,
‘pars_map’, ‘tbl_map’])) >>
gvs[]
(* here we know that also the frame we create and trying to type is empty*)
val SR_stmt_newframe = prove (“
∀ stmt stmtl ascope ascope' gscope gscope' (scopest:scope list) scopest' framel status status' t_scope_list t_scope_list_g T_e
(c:'a ctx) order delta_g delta_b delta_t delta_x f Prs_n apply_table_f ext_map func_map b_func_map pars_map tbl_map.
(c = ( apply_table_f , ext_map , func_map , b_func_map , pars_map , tbl_map ) ) ∧
(WT_c c order t_scope_list_g delta_g delta_b delta_x delta_t Prs_n) ∧
(T_e = (order, f, (delta_g, delta_b, delta_x, delta_t))) ∧
(frame_typ ( t_scope_list_g , t_scope_list ) T_e Prs_n gscope scopest [stmt] ) ∧
(stmt_red c ( ascope , gscope , [ (f, [stmt], scopest )] , status)
( ascope', gscope' , framel ++ [ (f, stmtl , scopest')] , status')) ⇒
(∃ t_scope_list'. res_frame_typ (order,f,(delta_g, delta_b, delta_x, delta_t)) Prs_n t_scope_list_g t_scope_list' gscope framel func_map b_func_map t_scope_list) ”,
Induct >>
REPEAT STRIP_TAC >| [
fs[Once stmt_sem_cases]
,
(** assignment case **)
(* we know that the length of the frame framel is either 0 or one from :*)
IMP_RES_TAC fr_len_from_a_frame_theorem >|[
(* if 1, then we also know that e made a reduction*)
OPEN_ANY_STMT_RED_TAC >>
gvs[] >>
(* we also know that e is well typed from frame typ *)
EXP_IS_WT_IN_FRAME_TAC “[stmt_ass l e]” >>
(* from sr we know that this frame is well typed, we need to know the
typing scope for the body *)
ASSUME_SR_EXP_FOR ‘e’ >>
INST_SR_EXP_FOR (‘e''’,‘(t_tau tau')’,‘b’) >>
gvs[type_frame_tsl_def] >>
qexistsl_tac [‘t_scope_list_fr’] >>
drule frame_typ_imp_res_frame_single >> gvs[]
,
fs[res_frame_typ_def]
]
,
(* condition case *)
schneiderUtils.POP_NO_TAC 5 >>
schneiderUtils.POP_NO_TAC 5 >>
IMP_RES_TAC fr_len_from_a_frame_theorem >|[
OPEN_ANY_STMT_RED_TAC >>
gvs[] >>
EXP_IS_WT_IN_FRAME_TAC “[stmt_cond e stmt stmt']” >>
ASSUME_SR_EXP_FOR ‘e’ >>
INST_SR_EXP_FOR (‘e''’,‘(t_tau tau_bool)’,‘b’) >>
gvs[type_frame_tsl_def] >>
qexistsl_tac [‘t_scope_list_fr’] >>
drule frame_typ_imp_res_frame_single >> gvs[]
,
fs[res_frame_typ_def]
]
,
(* stmt_block can never create a frame *)
OPEN_ANY_STMT_RED_TAC >>
gvs[] >>
fs[res_frame_typ_def]
,
(* return *)
IMP_RES_TAC fr_len_from_a_frame_theorem >|[
OPEN_ANY_STMT_RED_TAC >>
gvs[] >>
EXP_IS_WT_IN_FRAME_TAC “[stmt_ret e]” >>
ASSUME_SR_EXP_FOR ‘e’ >>
INST_SR_EXP_FOR (‘e''’,‘(t_tau tau')’,‘b’) >>
gvs[type_frame_tsl_def] >>
qexistsl_tac [‘t_scope_list_fr’] >>
drule frame_typ_imp_res_frame_single >> gvs[]
,
fs[res_frame_typ_def]
]
,
(* only seq 1 create a frame *)
schneiderUtils.POP_NO_TAC 5 >>
IMP_RES_TAC fr_len_from_a_frame_theorem >| [
OPEN_ANY_STMT_RED_TAC >>
gvs[] >>
(* use IH *)
LAST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [‘stmt_stack' ⧺ [stmt1']’, ‘ascope’, ‘ascope'’, ‘gscope’, ‘gscope'’,
‘scopest’, ‘scopest'’,‘[(f_called,[stmt_called],copied_in_scope)]’,‘status_running’,
‘status_running’,‘t_scope_list’,‘t_scope_list_g’, ‘order’,‘delta_g’,‘delta_b’,
‘delta_t’,‘delta_x’,‘f’,‘Prs_n’])) >> gvs[] >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [‘apply_table_f’, ‘ext_map’, ‘func_map’, ‘b_func_map’, ‘pars_map’, ‘tbl_map’])) >> gvs[] >>
(* we know that [stmt] is well typed from frame_typ*)
subgoal ‘frame_typ (t_scope_list_g,t_scope_list)
(order,f,delta_g,delta_b,delta_x,delta_t) Prs_n gscope scopest [stmt]’ >-
( OPEN_FRAME_TYP_TAC “[stmt_seq stmt stmt']” >>
SIMP_TAC list_ss [Once frame_typ_cases] >>
fs[stmtl_typ_cases, type_ith_stmt_def] >>
gvs[] >>
OPEN_STMT_TYP_TAC “stmt_seq stmt stmt'” >>
gvs[] >>
qexistsl_tac [‘tau_x_d_list’,‘tau’] >> gvs[] >>
REPEAT STRIP_TAC >> gvs[] >>
REPEAT STRIP_TAC >>
‘i=0’ by fs[] >>
fs[Once EL] ) >>
gvs[] >>
srw_tac [SatisfySimps.SATISFY_ss][]
,
fs[res_frame_typ_def]
]
,
(** statement trans **)
IMP_RES_TAC fr_len_from_a_frame_theorem >| [
OPEN_ANY_STMT_RED_TAC >> gvs[] >>
EXP_IS_WT_IN_FRAME_TAC “[stmt_trans e]” >>
ASSUME_SR_EXP_FOR ‘e’ >>
INST_SR_EXP_FOR (‘e''’,‘t_string_names_a x_list’,‘b’) >>
gvs[type_frame_tsl_def] >>
qexistsl_tac [‘t_scope_list_fr’] >>
drule frame_typ_imp_res_frame_single >> gvs[]
,
fs[res_frame_typ_def]
]
,
(* statement apply s l *)
IMP_RES_TAC fr_len_from_a_frame_theorem >| [
OPEN_ANY_STMT_RED_TAC >>
gvs[] >>
EXP_IS_WT_IN_FRAME_TAC “[stmt_app s l]” >>
(* we know that i is indeed less than the list *)
subgoal ‘i < LENGTH e_tau_b_list’ >- (
IMP_RES_TAC index_not_const_in_range >>
gvs[LIST_EQ_REWRITE] )>>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`i`])) >>
gvs[] >>
ASSUME_SR_EXP_FOR ‘(EL i (MAP (λ(e_,e'_). e_) (e_e'_list : (e # e) list)))’ >>
INST_SR_EXP_FOR (‘e'’,‘(t_tau (EL i (MAP (λ(e_,tau_,b_). tau_) (e_tau_b_list: (e # tau # bool) list))))’,
‘(EL i (MAP (λ(e_,tau_,b_). b_) (e_tau_b_list : (e # tau # bool) list)))’) >>
gvs[type_frame_tsl_def] >>
qexistsl_tac [‘t_scope_list_fr’] >>
drule frame_typ_imp_res_frame_single >> gvs[]
,
fs[res_frame_typ_def]
]
,
(* statement extern would never create a frame *)
OPEN_ANY_STMT_RED_TAC >>
gvs[] >>
fs[res_frame_typ_def]
]
);
(*
EVAL “declare_list_in_fresh_scope [(varn_name "x",tau_bot)]”
EVAL “ type_scopes_list [[(varn_name "x",v_bot,NONE)]] [[(varn_name "x",tau_bot)]] ”
*)
val tsl_singletone_exsists = prove (“
∀ scopest ts .
type_scopes_list scopest [ts] ⇒
(LENGTH scopest = 1 ∧ ∃ sc . scopest = [sc] ∧
type_scopes_list [sc] [ts] )
”,
REPEAT GEN_TAC >>
STRIP_TAC >>
IMP_RES_TAC type_scopes_list_LENGTH >>
‘LENGTH [ts] = 1’ by fs[] >>
gvs[] >>
fs[type_scopes_list_def] >>
gvs[similarl_def]
);
val similar_normalize2 = prove ( ``
∀ R l l' h h'.
similar R (h::l) (h'::l') ⇔
similar R [h] [h'] ∧
similar R l l'``,
REPEAT STRIP_TAC >>
fs[similar_def]
);
val similar_ext_out_scope_lemma = prove (“
∀ sc sc' varnl varnl' tl.
similar (λsi so. SND si = SND so) sc sc' ∧
similar (λ(v,lop1) (t,lop2). v_typ v (t_tau t) F ∧ lop1 = lop2) sc' (ZIP (varnl,tl)) ∧
similar (λ(v,lop1) (t,lop2). v_typ v (t_tau t) F ∧ lop1 = lop2) sc (ZIP (varnl',tl)) ⇒
similar (λ(v,lop1) (t,lop2). v_typ v (t_tau t) F ∧ lop1 = lop2) sc' (ZIP (varnl',tl))
”,
reverse (
Induct_on ‘sc’ >>
Induct_on ‘sc'’ >>
Induct_on ‘tl’ >>
Induct_on ‘varnl’ >>
Induct_on ‘varnl'’ >>
REPEAT STRIP_TAC) >-
(
SIMP_TAC list_ss [Once similar_normalize2] >> gvs[] >> CONJ_TAC >| [
(*head case*)
gvs[Once similar_normalize2] >>
PairCases_on ‘h'’ >>
PairCases_on ‘h''''’ >>
gvs[similar_def]
,
(*IH case*)
rfs[Once similar_normalize2] >>
RES_TAC
]
) >>
srw_tac [][ZIP, ZIP_def] >>
gvs[similar_def] >>
TRY (PairCases_on ‘h’) >>
TRY (PairCases_on ‘h'’) >>
TRY(PairCases_on ‘y’) >>
fsrw_tac [][LENGTH_ZIP_MIN] >>
rfs[ZIP_def]
);
val similar_ext_out_scope_lemma2 = prove (“
∀ sc sc' varnl varnl' tl.
similar (λsi so. SND si = SND so ∧ SND si = NONE) sc sc' ∧
similar (λ(v,lop1) (t,lop2). v_typ v (t_tau t) F ∧ lop1 = lop2) sc' (ZIP (varnl,tl)) ∧
similar (λ(v,lop1) (t,lop2). v_typ v (t_tau t) F ∧ lop1 = lop2) sc (ZIP (varnl',tl)) ⇒
similar (λ(v,lop1) (t,lop2). v_typ v (t_tau t) F ∧ lop1 = lop2) sc' (ZIP (varnl',tl))
”,
reverse (
Induct_on ‘sc’ >>
Induct_on ‘sc'’ >>
Induct_on ‘tl’ >>
Induct_on ‘varnl’ >>
Induct_on ‘varnl'’ >>
REPEAT STRIP_TAC) >-
(
SIMP_TAC list_ss [Once similar_normalize2] >> gvs[] >> CONJ_TAC >| [
(*head case*)
gvs[Once similar_normalize2] >>
PairCases_on ‘h'’ >>
PairCases_on ‘h''''’ >>
gvs[similar_def]
,
(*IH case*)
rfs[Once similar_normalize2] >>
RES_TAC
]
) >>
srw_tac [][ZIP, ZIP_def] >>
gvs[similar_def] >>
TRY (PairCases_on ‘h’) >>
TRY (PairCases_on ‘h'’) >>
TRY(PairCases_on ‘y’) >>
fsrw_tac [][LENGTH_ZIP_MIN] >>
rfs[ZIP_def]
);
val typ_ext_out_scope_lemma = prove (“
∀ sc sc' tl varnl varnl'.
ext_sc_same_as_input [sc] [sc'] ∧
type_scopes_list [sc'] [ZIP (varnl, tl)] ∧
type_scopes_list [sc] [ZIP(varnl', tl)] ⇒
type_scopes_list [sc'] [ZIP(varnl', tl)] ”,
REPEAT STRIP_TAC >>
gvs[ext_sc_same_as_input_def] >>
gvs[type_scopes_list_def] >>
gvs[similarl_def] >>
IMP_RES_TAC similar_ext_out_scope_lemma
);
val ext_sc_same_as_input_LENGTH = prove (“
∀ scopest tsl .
ext_sc_same_as_input scopest tsl ⇒
LENGTH scopest = LENGTH tsl”,
gvs[ext_sc_same_as_input_def] >>
fs[type_scopes_list_def, similarl_def, similar_def] >>
REPEAT STRIP_TAC >>
IMP_RES_TAC LIST_REL_LENGTH
);
val LOL_ext_sc_same_as_input = prove (“
∀ sc outsc tsc' tsc lol.
ext_sc_same_as_input [outsc] [sc] ∧
MAP (λx. SND (SND x)) tsc' = lol ∧
type_scopes_list [sc] [tsc'] ∧
type_scopes_list [outsc] [tsc] ⇒
MAP (λx. SND (SND x)) tsc = lol ”,
gvs[type_scopes_list_def]>>
gvs[ext_sc_same_as_input_def] >>
gvs[similarl_def] >>
reverse (
Induct_on ‘sc’ >>
Induct_on ‘outsc’ >>
Induct_on ‘tsc'’ >>
Induct_on ‘tsc’) >- (
REPEAT STRIP_TAC >>
PairCases_on ‘h’ >>
PairCases_on ‘h'’ >>
PairCases_on ‘h''’ >>
PairCases_on ‘h'''’ >>
gvs[] >>
gvs[similar_def] >>
METIS_TAC []) >>
gvs[similar_def]
);
val map_lemma_local_tmp = prove (“
∀ txdl lol .
MAP (λx. SND (SND x))
(ZIP
(mk_varn (MAP (λx. FST (SND x)) txdl),
ZIP (MAP FST txdl,MAP (λtxd. lol) txdl))) =
MAP (λtxd. lol) txdl ”,
Induct >>
REPEAT STRIP_TAC >>
gvs[mk_varn_def]
);
val typ_scope_list_ext_out_scope_lemma = prove (
“ ∀ f apply_table_f ext_map func_map b_func_map pars_map tbl_map
order tslg delta_g delta_b delta_x ascope ascope'
gscope scopest scopest' v ext_fun tsl tau txdl delta_t Prs_n.
WT_c (apply_table_f,ext_map,func_map,b_func_map,pars_map,tbl_map)
order tslg delta_g delta_b delta_x delta_t Prs_n ∧
SOME (txdl,tau) = t_lookup_funn f delta_g delta_b delta_x ∧
args_t_same (MAP FST txdl) tsl ∧
type_scopes_list scopest tsl ∧
type_scopes_list gscope tslg ∧
star_not_in_sl scopest ∧
SOME ext_fun = lookup_ext_fun f ext_map ∧
SOME (ascope',scopest',v) = ext_fun (ascope,gscope,scopest) ⇒
(type_scopes_list scopest' tsl ∧ star_not_in_sl scopest')”,
Cases_on ‘f’ >>
fs[lookup_ext_fun_def] >>
REPEAT GEN_TAC >>
STRIP_TAC >| [
(* we know that the length of scopest is one,*)
(* and if the length is one, we know that there exists only one element there via *)
(*inst*)
Cases_on ‘ALOOKUP ext_map s’ >> gvs[] >>
PairCases_on ‘x’ >> gvs[] >>
Cases_on ‘x0’ >> gvs[] >>
PairCases_on ‘x’ >> gvs[] >>
fs[WT_c_cases] >>
fs[WTX_cases] >>
fs[extern_map_IoE_typed_def] >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`x0`, `s`, ‘ext_fun’,‘x1’])) >>
gvs[] >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`ascope`, `gscope`, ‘scopest’])) >>
gvs[] >>
Cases_on ‘ext_fun (ascope,gscope,scopest)’ >> gvs[] >>
(* the output scope sc is only of length 1*)
IMP_RES_TAC tsl_singletone_exsists >>
gvs[]
(*
(* show that txdl and txdl ' are the same *)
IMP_RES_TAC t_lookup_funn_ext_lemma >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`delta_g`, `delta_b`])) >>
gvs[] >>
Cases_on ‘t_lookup_funn (funn_inst s) delta_g delta_b delta_x’ >> gvs[] >>
(* we know that the scopest (initial one) must be of size 1 *)
IMP_RES_TAC ext_sc_same_as_input_LENGTH >>
(*‘LENGTH scopest = 1’ by gvs[] >>
‘∃ outsc. scopest = [outsc]’ by fs[quantHeuristicsTheory.LIST_LENGTH_1] >>
(* same for the typing scope*)
‘LENGTH tsl = 1’ by (IMP_RES_TAC type_scopes_list_LENGTH >> gvs[]) >>
‘∃ tsc. tsl = [tsc]’ by fs[quantHeuristicsTheory.LIST_LENGTH_1] >>
gvs[] >>
*)
fs[args_t_same_def, same_dir_x_def] >>
gvs[mk_tscope_def] >>
srw_tac [] [] >>
(* we know that ts contains the same types as the input*)
subgoal ‘ [tsc] = [ZIP (MAP FST tsc ,ZIP(MAP (λ(t,x,d). t) txdl, MAP (λtxd. lol) txdl ))]’ >-
( gvs[ELIM_UNCURRY, map_fst_EQ ] >>
ASSUME_TAC LOL_ext_sc_same_as_input >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [‘sc’, ‘outsc’,
‘ZIP (mk_varn (MAP (λx. FST (SND x)) (txdl : (tau # string # d) list)),
ZIP (MAP FST (txdl : (tau # string # d) list),
MAP (λtxd. lol) txdl ))’,
‘tsc’, ‘MAP (λtxd. lol) (txdl : (tau # string # d) list)’])) >>
gvs[] >>
METIS_TAC [ZIP_tri_id1, map_lemma_local_tmp ]
) >>
IMP_RES_TAC typ_ext_out_scope_lemma >>
rfs[] >>
LAST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`MAP FST (tsc : (varn # tau) list)`])) >>
srw_tac [][] >>
METIS_TAC [] *)
,
(*ext methods *)
Cases_on ‘ALOOKUP ext_map s’ >> gvs[] >>
PairCases_on ‘x’ >> gvs[] >>
Cases_on ‘ALOOKUP x1 s0’ >> gvs[] >>
PairCases_on ‘x’ >> gvs[] >>
fs[WT_c_cases] >>
fs[WTX_cases] >>
fs[extern_MoE_typed_def] >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`x0'`, `s`, ‘s0’,‘x0’,‘x1’,‘ext_fun’])) >>
gvs[] >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`ascope`, `gscope`, ‘scopest’])) >>
gvs[] >>
Cases_on ‘ext_fun (ascope,gscope,scopest)’ >> gvs[]
(*
IMP_RES_TAC tsl_singletone_exsists >>
gvs[] >>
IMP_RES_TAC t_lookup_funn_ext_lemma >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`delta_g`, `delta_b`])) >>
gvs[] >>
Cases_on ‘t_lookup_funn (funn_ext s s0) delta_g delta_b delta_x’ >> gvs[] >>
(* we know that the scopest (initial one) must be of size 1 *)
IMP_RES_TAC ext_sc_same_as_input_LENGTH >>
‘LENGTH scopest = 1’ by gvs[] >>
‘∃ outsc. scopest = [outsc]’ by fs[quantHeuristicsTheory.LIST_LENGTH_1] >>
(* same for the typing scope*)
‘LENGTH tsl = 1’ by (IMP_RES_TAC type_scopes_list_LENGTH >> gvs[]) >>
‘∃ tsc. tsl = [tsc]’ by fs[quantHeuristicsTheory.LIST_LENGTH_1] >>
gvs[] >>
fs[args_t_same_def, same_dir_x_def] >>
gvs[mk_tscope_def] >>
srw_tac [] [] >>
(* we know that ts contains the same types as the input*)
subgoal ‘ [tsc] = [ZIP (MAP FST tsc ,ZIP(MAP (λ(t,x,d). t) txdl, MAP (λtxd. lol) txdl ))]’ >-
( gvs[ELIM_UNCURRY, map_fst_EQ ] >>
ASSUME_TAC LOL_ext_sc_same_as_input >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [‘sc’, ‘outsc’,
‘ZIP (mk_varn (MAP (λx. FST (SND x)) (txdl : (tau # string # d) list)),
ZIP (MAP FST (txdl : (tau # string # d) list),
MAP (λtxd. lol) txdl))’,
‘tsc’, ‘MAP (λtxd. lol) (txdl : (tau # string # d) list)’])) >>
gvs[] >>
METIS_TAC [ZIP_tri_id1, map_lemma_local_tmp ]
) >>
IMP_RES_TAC typ_ext_out_scope_lemma >>
rfs[] >>
LAST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [`MAP FST (tsc : (varn # tau) list)`])) >>
srw_tac [][] >>
METIS_TAC [] *)
]
);
val directionless_lval_f = prove (“∀ dl.
is_directionless (dl) ⇒ out_is_lval (dl) (MAP (λd. F) dl)”,
Induct >>
gvs[is_d_out_def, out_is_lval_def] >>
REPEAT STRIP_TAC >>
fs[Once EL_compute] >> Cases_on ‘i=0’ >> gvs[EL_CONS] >| [
Cases_on ‘h’ >> gvs[is_d_out_def, is_directionless_def]
,
‘is_directionless dl’ by fs[is_directionless_def] >>
gvs[] >>
FIRST_X_ASSUM (STRIP_ASSUME_TAC o (Q.SPECL [‘i - 1’])) >>
gvs[numeralTheory.numeral_pre, PRE_SUB1, PRE_SUC_EQ] >>
Cases_on `i = 1` >>
fs[] >>
`~ (i ≤ 1)` by fs[] >>
gvs[] >>
fs[GSYM EL] >> fs[ADD1] (* TODO add this everywherre i needed to show something about the tail*) ]
);
Theorem ALOOKUP_not_empty:
∀ l s t . ALOOKUP l s = SOME t ⇒
l ≠ []
Proof
Induct >>
fs[]
QED
Theorem assign_to_null_same_lemma:
∀ scl scl' v .
SOME scl' = assign (scl) v lval_null ⇔
scl' = scl
Proof
gvs[assign_def]
QED
(*EVAL “oDROP 3 [a;b;c]”*)
(*EVAL “oTAKE 3 [a;b;c;d]”*)
Theorem oDROP_empty:
∀l . oDROP (LENGTH l) l = SOME []
Proof
Induct >>
gvs[oDROP_def]
QED