-
Notifications
You must be signed in to change notification settings - Fork 85
/
TypeValidatorScript.sml
1018 lines (992 loc) · 41.6 KB
/
TypeValidatorScript.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
(**
Simple Type Inference algorithm with correctness proof to infer machine type
assignments for FloVer's input expressions
**)
open realTheory realLib sptreeTheory;
open ExpressionsTheory MachineTypeTheory FloverTactics ExpressionAbbrevsTheory
ExpressionSemanticsTheory CommandsTheory FloverMapTheory ResultsTheory;
open ResultsLib;
open preambleFloVer;
val _ = new_theory "TypeValidator";
Definition validTypes_def:
validTypes e Gamma =
∃ mG. FloverMapTree_find e Gamma = SOME mG ∧
(case e of
| Var x => T
| Const m v => m = mG
| Unop u e1 =>
validTypes e1 Gamma ∧
(? me. FloverMapTree_find e1 Gamma = SOME me ∧ isCompat me mG)
| Binop b e1 e2 =>
validTypes e1 Gamma ∧
validTypes e2 Gamma ∧
(?m1 m2. FloverMapTree_find e1 Gamma = SOME m1 ∧
FloverMapTree_find e2 Gamma = SOME m2 ∧
isJoin m1 m2 mG)
| Fma e1 e2 e3 =>
validTypes e1 Gamma ∧
validTypes e2 Gamma ∧
validTypes e3 Gamma ∧
(?m1 m2 m3. FloverMapTree_find e1 Gamma = SOME m1 ∧
FloverMapTree_find e2 Gamma = SOME m2 ∧
FloverMapTree_find e3 Gamma = SOME m3 ∧
isJoin3 m1 m2 m3 mG)
| Downcast m e1 =>
validTypes e1 Gamma ∧
m = mG ∧
(? m1. FloverMapTree_find e1 Gamma = SOME m1 ∧
isMorePrecise m1 mG)) ∧
(! E Gamma2 v m.
(! e m. FloverMapTree_find e Gamma = SOME m ==>
FloverMapTree_find e Gamma2 = SOME m) ∧
eval_expr E (toRExpMap Gamma2) e v m ==>
m = mG)
End
Theorem validTypes_single:
∀ e Gamma.
validTypes e Gamma ==>
∃ mG.
FloverMapTree_find e Gamma = SOME mG /\
(!E v m Gamma2.
(! e m. FloverMapTree_find e Gamma = SOME m ==>
FloverMapTree_find e Gamma2 = SOME m) /\
eval_expr E (toRExpMap Gamma2) e v m ==>
m = mG)
Proof
Cases_on `e` \\ rpt strip_tac \\ fs[Once validTypes_def] \\ rpt strip_tac
\\ first_x_assum irule \\ fs[]
\\ rpt (asm_exists_tac \\ fs[])
QED
Theorem validTypes_exec:
! e Gamma m.
validTypes e Gamma /\
FloverMapTree_find e Gamma = SOME m ==>
! E v mG.
eval_expr E (toRExpMap Gamma) e v mG ==>
mG = m
Proof
rpt strip_tac \\ IMP_RES_TAC validTypes_single
\\ rename1 `FloverMapTree_find e Gamma = SOME mG2`
\\ `m = mG2` by (fs[])
\\ rveq
\\ first_x_assum irule
\\ qexistsl_tac [`E`, `Gamma`, `v`] \\ fs[]
QED
Definition isMonotone_def:
isMonotone NONE mNew = T /\
isMonotone (SOME mOld) mNew = (mOld = mNew)
End
Definition addMono_def:
addMono e m map =
case FloverMapTree_find e map of
| SOME mOld => Fail "Nonmonotonic map update"
| NONE => Succes (FloverMapTree_insert e m map)
End
Overload insert[local] = “FloverMapTree_insert”
Definition getValidMap_def:
getValidMap Gamma e akk =
if (FloverMapTree_mem e akk)
then Succes akk
else
let mOldO = FloverMapTree_find e Gamma in
case e of
| Var x =>
(case mOldO of
| SOME m => Succes (insert e m akk)
| NONE => Fail "Undefined variable")
| Const m n =>
if (isMonotone mOldO m)
then Succes (insert e m akk)
else Fail "Wrong type annotation for Constant"
| Unop u e1 =>
do
akk_new <- getValidMap Gamma e1 akk;
case FloverMapTree_find e1 akk_new of
| NONE => Fail "Cannot typecheck unary op"
| SOME m_e1 =>
if (isFixedPoint m_e1)
then
case mOldO of
| NONE => Fail "Undefined fixed-point type"
| SOME mFix =>
if (isCompat m_e1 mFix)
then addMono e mFix akk_new
else Fail "Incompatible type assignment"
else
if (isMonotone mOldO m_e1)
then addMono e m_e1 akk_new
else Fail "Wront type annotation for unary constant"
od
| Binop b e1 e2 =>
do
akk1_map <- getValidMap Gamma e1 akk;
akk2_map <- getValidMap Gamma e2 akk1_map;
let m1 = FloverMapTree_find e1 akk2_map;
m2 = FloverMapTree_find e2 akk2_map in
case m1, m2 of
| SOME t1, SOME t2 =>
if (isFixedPoint t1 /\ isFixedPoint t2)
then
case mOldO of
| NONE => Fail "Undefined fixed-point type"
| SOME mj =>
if (morePrecise t1 mj /\ morePrecise t2 mj)
then addMono e mj akk2_map
else Fail "Incorrect fixed-point type"
else
if (t1 = REAL ∨ t2 = REAL)
then if (t1 = REAL ∧ t2 = REAL)
then if (isMonotone mOldO REAL)
then addMono e REAL akk2_map
else Fail "Wrong type annotation for binary operator"
else Fail "Both arguments must be REAL if one is REAL"
else
(case join_fl t1 t2 of
| NONE => Fail "Could not compute join for arguments"
| SOME m =>
if (isMonotone mOldO m)
then addMono e m akk2_map
else Fail "Wrong type annotation for binary operator")
| _, _ => Fail "Could not compute type for arguments"
od
| Fma e1 e2 e3 =>
do
akk1_map <- getValidMap Gamma e1 akk;
akk2_map <- getValidMap Gamma e2 akk1_map;
akk3_map <- getValidMap Gamma e3 akk2_map;
let m1 = FloverMapTree_find e1 akk3_map;
m2 = FloverMapTree_find e2 akk3_map;
m3 = FloverMapTree_find e3 akk3_map in
case m1, m2, m3 of
| SOME t1, SOME t2, SOME t3=>
if (isFixedPoint t1 /\ isFixedPoint t2 /\ isFixedPoint t3)
then
case mOldO of
| NONE => Fail "Undefined fixed-point type"
| SOME mj =>
if (morePrecise t1 mj /\ morePrecise t2 mj /\ morePrecise t3 mj)
then addMono e mj akk3_map
else Fail "Incorrect fixed-point type"
else if (t1 = REAL ∨ t2 = REAL ∨ t3 = REAL)
then if (t1 = REAL ∧ t2 = REAL ∧ t3 = REAL)
then if (isMonotone mOldO REAL)
then addMono e REAL akk3_map
else Fail "Wrong type annotation for binary operator"
else Fail "Both arguments must be REAL if one is REAL"
else
(case join_fl3 t1 t2 t3 of
| NONE => Fail "Could not compute join for arguments"
| SOME m =>
if (isMonotone mOldO m)
then addMono e m akk3_map
else Fail "Wrong type annotation for FMA")
| _, _ => Fail "Could not compute type for arguments"
od
| Downcast m e1 =>
do
akk_new <- getValidMap Gamma e1 akk;
case FloverMapTree_find e1 akk_new of
| NONE => Fail "Could not find cast argument type"
| SOME t1 =>
if (isFixedPoint t1)
then
case mOldO of
| NONE => Fail "Could not find fixed_point type for cast"
| SOME mFix =>
if (m = mFix /\ morePrecise t1 mFix)
then addMono e mFix akk_new
else Fail "Incorrect fixed-point type"
else
if (morePrecise t1 m /\ isMonotone mOldO m)
then addMono e m akk_new
else Fail "Cannot cast down to lower precision"
od
End
val tMap_def = FloverMapTree_correct;
Theorem toRExpMap_char:
!e m akk. toRExpMap (FloverMapTree_insert e m akk) e = SOME m
Proof
fs[toRExpMap_def, tMap_def]
QED
val by_monotonicity =
once_rewrite_tac [map_find_add]
\\ COND_CASES_TAC \\ fs[]
\\ rveq
\\ fs[FloverMapTree_mem_def]
\\ EVERY_CASE_TAC \\ fs[];
val _ = temp_delsimps ["lift_disj_eq", "lift_imp_disj"]
Theorem getValidMap_mono:
∀ e Gamma akk res.
getValidMap Gamma e akk = Succes res ⇒
∀ e m. FloverMapTree_find e akk = SOME m ⇒
FloverMapTree_find e res = SOME m
Proof
Induct_on `e`
\\ once_rewrite_tac [getValidMap_def] \\ fs[]
\\ rpt strip_tac
>- (Cases_on `FloverMapTree_mem (Var n) akk`
\\ fs[option_case_eq] \\ rveq \\ fs[]
\\ by_monotonicity)
>- (Cases_on `FloverMapTree_mem (Const m v) akk`
\\ fs[option_case_eq] \\ rveq \\ fs[]
\\ Cases_on `isMonotone (FloverMapTree_find (Const m v) Gamma) m`
\\ fs[]
\\ rveq \\ by_monotonicity)
>- (Cases_on `FloverMapTree_mem (Unop u e) akk`
\\ fs[] \\ rveq \\ fs[]
\\ Cases_on `getValidMap Gamma e akk` \\ fs[option_case_eq]
\\ Cases_on `isFixedPoint m_e1` \\ fs[option_case_eq]
>- (Cases_on `isCompat m_e1 mFix` \\ fs[addMono_def, option_case_eq]
\\ rveq \\ res_tac
\\ by_monotonicity)
\\ Cases_on `isMonotone (FloverMapTree_find (Unop u e) Gamma) m_e1`
\\ fs[addMono_def, option_case_eq] \\ rveq
\\ res_tac
\\ by_monotonicity)
>- (rename1 `Binop b e1 e2` \\ Cases_on `FloverMapTree_mem (Binop b e1 e2) akk`
\\ fs[] \\ rveq \\ fs[]
\\ Cases_on `getValidMap Gamma e1 akk` \\ fs[result_bind_def]
\\ Cases_on `getValidMap Gamma e2 a` \\ fs[option_case_eq]
\\ Cases_on `isFixedPoint t1` \\ Cases_on `isFixedPoint t2` \\ fs[option_case_eq]
>- (Cases_on `morePrecise t1 mj` \\ Cases_on `morePrecise t2 mj`
\\ fs[addMono_def, option_case_eq]
\\ rveq \\ res_tac
\\ by_monotonicity)
\\ Cases_on ‘t1 = REAL ∨ t2 = REAL’ \\ fs[]
\\ TRY (rename1 ‘t1 = REAL ∧ t2 = REAL’ \\ Cases_on ‘t1 = REAL ∧ t2 = REAL’ \\ fs[] \\ fs[])
\\ TRY (fs[option_case_eq] \\ rename1 `join_fl t1 t2 = SOME mj`
\\ Cases_on `isMonotone (FloverMapTree_find (Binop b e1 e2) Gamma) mj`
\\ fs[addMono_def, option_case_eq] \\ rveq \\ res_tac
\\ by_monotonicity)
\\ rveq \\ fs[]
\\ Cases_on `isMonotone (FloverMapTree_find (Binop b e1 e2) Gamma) REAL`
\\ fs[addMono_def, option_case_eq] \\ rveq \\ res_tac
\\ by_monotonicity)
>- (rename1 `Fma e1 e2 e3` \\ Cases_on `FloverMapTree_mem (Fma e1 e2 e3) akk`
\\ fs[] \\ rveq \\ fs[]
\\ Cases_on `getValidMap Gamma e1 akk` \\ fs[result_bind_def]
\\ Cases_on `getValidMap Gamma e2 a` \\ fs[result_bind_def]
\\ Cases_on `getValidMap Gamma e3 a'` \\ fs[option_case_eq]
\\ Cases_on `isFixedPoint t1`
\\ Cases_on `isFixedPoint t2`
\\ Cases_on `isFixedPoint t3`
\\ fs[option_case_eq]
>- (Cases_on `morePrecise t1 mj`
\\ Cases_on `morePrecise t2 mj`
\\ Cases_on `morePrecise t3 mj`
\\ fs[addMono_def, option_case_eq]
\\ rveq \\ res_tac
\\ by_monotonicity)
\\ Cases_on ‘t1 = REAL ∨ t2 = REAL ∨ t3 = REAL’ \\ fs[]
\\ TRY (rename1 ‘t1 = REAL ∧ t2 = REAL ∧ t3 = REAL’
\\ Cases_on ‘t1 = REAL ∧ t2 = REAL ∧ t3 = REAL’ \\ fs[] \\ fs[])
\\ TRY (fs[option_case_eq]
\\ rename1 `join_fl3 t1 t2 t3 = SOME mj`
\\ Cases_on `isMonotone (FloverMapTree_find (Fma e1 e2 e3) Gamma) mj`
\\ fs[addMono_def, option_case_eq] \\ rveq \\ res_tac
\\ by_monotonicity)
\\ rveq \\ fs[]
\\ Cases_on `isMonotone (FloverMapTree_find (Fma e1 e2 e3) Gamma) REAL`
\\ fs[addMono_def, option_case_eq] \\ rveq \\ res_tac
\\ by_monotonicity)
\\ Cases_on `FloverMapTree_mem (Downcast m e) akk`
\\ fs[] \\ rveq \\ fs[]
\\ Cases_on `getValidMap Gamma e akk` \\ fs[option_case_eq]
\\ Cases_on `isFixedPoint t1` \\ fs[option_case_eq]
>- (Cases_on `m = mFix` \\ Cases_on `morePrecise t1 mFix`
\\ fs[addMono_def, option_case_eq]
\\ rveq \\ res_tac
\\ by_monotonicity)
\\ Cases_on `morePrecise t1 m`
\\ Cases_on `isMonotone (FloverMapTree_find (Downcast m e) Gamma) m`
\\ fs[addMono_def, option_case_eq] \\ rveq
\\ res_tac
\\ by_monotonicity
QED
Theorem validTypes_mono:
! e map1 map2.
(! e m. FloverMapTree_find e map1 = SOME m ==>
FloverMapTree_find e map2 = SOME m) /\
validTypes e map1 ==>
validTypes e map2
Proof
Induct_on `e` \\ fs[Once validTypes_def]
\\ rpt strip_tac
\\ simp [Once validTypes_def]
>- (qexists_tac `mG` \\ fs[]
\\ rpt strip_tac \\ first_x_assum irule
\\ qexistsl_tac [`E`, `Gamma2`, `v`]
\\ fs[])
>- (rpt strip_tac \\ first_x_assum irule
\\ qexistsl_tac [`E`, `Gamma2`, `v'`] \\ fs[])
>- (qexists_tac `mG` \\ fs[]
\\ rpt conj_tac
>- (first_x_assum irule
\\ qexists_tac `map1` \\ simp[GSYM validTypes_def])
>- (qexists_tac `me` \\ fs[])
\\ rpt strip_tac \\ first_x_assum irule
\\ qexistsl_tac [`E`, `Gamma2`, `v`] \\ fs[])
>- (qexists_tac `mG` \\ fs[]
\\ rpt conj_tac
>- (first_x_assum irule
\\ qexists_tac `map1` \\ simp[GSYM validTypes_def])
>- (first_x_assum irule
\\ qexists_tac `map1` \\ simp[GSYM validTypes_def])
>- (qexistsl_tac [`m1`, `m2`] \\ fs[])
\\ rpt strip_tac \\ first_x_assum irule
\\ qexistsl_tac [`E`, `Gamma2`, `v`] \\ fs[])
>- (qexists_tac `mG` \\ fs[]
\\ rpt conj_tac
>- (first_x_assum irule
\\ qexists_tac `map1` \\ simp[GSYM validTypes_def])
>- (first_x_assum irule
\\ qexists_tac `map1` \\ simp[GSYM validTypes_def])
>- (first_x_assum irule
\\ qexists_tac `map1` \\ simp[GSYM validTypes_def])
>- (qexistsl_tac [`m1`, `m2`, `m3`] \\ fs[])
\\ rpt strip_tac \\ first_x_assum irule
\\ qexistsl_tac [`E`, `Gamma2`, `v`] \\ fs[])
\\ rpt conj_tac
>- (first_x_assum irule
\\ qexists_tac `map1` \\ simp[GSYM validTypes_def])
>- (qexists_tac `m1` \\ fs[])
\\ rpt strip_tac \\ first_x_assum irule
\\ qexistsl_tac [`E`, `Gamma2`, `v`] \\ fs[]
QED
Theorem map_find_mono:
! e1 e2 m1 m2 Gamma.
FloverMapTree_mem e2 Gamma = F /\
FloverMapTree_find e1 Gamma = SOME m1 ==>
FloverMapTree_find e1 (FloverMapTree_insert e2 m2 Gamma) = SOME m1
Proof
rpt strip_tac \\ fs[map_find_add]
\\ Cases_on `e1 = e2` \\ fs[FloverMapTree_mem_def]
QED
Theorem getValidMap_correct:
∀ e Gamma akk res.
(∀ e.
FloverMapTree_mem e akk ⇒
validTypes e akk) ∧
getValidMap Gamma e akk = Succes res ⇒
∀ e.
FloverMapTree_mem e res ⇒
validTypes e res
Proof
Induct_on `e` \\ simp[Once getValidMap_def] \\ rpt strip_tac
>- (Cases_on `FloverMapTree_mem (Var n) akk`
\\ fs[] \\ rveq \\ fs[option_case_eq]
\\ rveq
\\ fs[FloverMapTree_mem_def]
\\ Cases_on `FloverMapTree_find e (insert (Var n) m akk)`
\\ fs[map_find_add]
\\ Cases_on `e = Var n` \\ fs[]
>- (rveq \\ simp[Once validTypes_def]
\\ qexists_tac `m` \\ fs[map_find_add]
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Var n`, `m`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def])
\\ `validTypes e akk`
by (first_x_assum irule \\ fs[])
\\ irule validTypes_mono \\ find_exists_tac \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (Cases_on `FloverMapTree_mem (Const m v) akk`
\\ fs[] \\ rveq \\ fs[]
\\ Cases_on `isMonotone (FloverMapTree_find (Const m v) Gamma) m`
\\ fs[] \\ rveq \\ fs[FloverMapTree_mem_def, map_find_add]
\\ reverse (Cases_on `e = Const m v`) \\ fs[]
>- (irule validTypes_mono
\\ qexists_tac `akk` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
\\ simp[Once validTypes_def]
\\ fs[map_find_add]
\\ rpt strip_tac \\ rveq
\\ first_x_assum (qspecl_then [`Const m v`, `m`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def])
>- (qpat_x_assum `getValidMap _ _ _ = _`
(fn thm => assume_tac (ONCE_REWRITE_RULE [getValidMap_def] thm))
\\ Cases_on `FloverMapTree_mem (Unop u e) akk` \\ fs[]
\\ Cases_on `getValidMap Gamma e akk` \\ fs[]
\\ Cases_on `FloverMapTree_find e a` \\ fs[]
\\ `! e. FloverMapTree_mem e a ==> validTypes e a`
by (rpt strip_tac \\ first_x_assum irule \\ fs[]
\\ qexistsl_tac [`Gamma`, `akk`] \\ fs[])
\\ Cases_on `isFixedPoint x` \\ fs[option_case_eq]
>- (Cases_on `isCompat x mFix` \\ fs[addMono_def, option_case_eq]
\\ rveq \\ fs[FloverMapTree_mem_def, map_find_add]
\\ reverse (Cases_on `e' = Unop u e`) \\ fs[]
>- (irule validTypes_mono
\\ qexists_tac `a` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
>- (COND_CASES_TAC \\ fs[])
\\ first_x_assum irule \\ fs[])
\\ rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `mFix` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `a` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (fs[no_cycle_unop])
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Unop u e`, `mFix`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def] \\ rveq \\ fs[])
\\ Cases_on `isMonotone (FloverMapTree_find (Unop u e) Gamma) x`
\\ fs[addMono_def, option_case_eq]
\\ rveq \\ fs[FloverMapTree_mem_def, map_find_add]
\\ reverse (Cases_on `e' = Unop u e`) \\ fs[]
>- (irule validTypes_mono
\\ qexists_tac `a` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
>- (COND_CASES_TAC \\ fs[])
\\ first_x_assum irule \\ fs[])
\\ rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `x` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `a` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (Cases_on `x` \\ fs[isCompat_def, morePrecise_def])
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Unop u e`, `x`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def] \\ rveq \\ fs[])
>- (qpat_x_assum `getValidMap _ _ _ = _`
(fn thm => assume_tac (ONCE_REWRITE_RULE [getValidMap_def] thm))
\\ rename1 `Binop b e1 e2`
\\ Cases_on `FloverMapTree_mem (Binop b e1 e2) akk` \\ fs[]
\\ Cases_on `getValidMap Gamma e1 akk` \\ fs[]
\\ Cases_on `getValidMap Gamma e2 a` \\ fs[]
\\ rename1 `getValidMap Gamma e2 a = Succes map2`
\\ Cases_on `FloverMapTree_find e1 map2` \\ fs[]
\\ Cases_on `FloverMapTree_find e2 map2` \\ fs[]
\\ ‘∀ e. FloverMapTree_mem e a ⇒ validTypes e a’
by (rpt strip_tac \\ last_x_assum irule \\ fs[]
\\ qexistsl_tac [`Gamma`, `akk`] \\ fs[])
\\ ‘∀ e. FloverMapTree_mem e map2 ⇒ validTypes e map2’
by (rpt strip_tac \\ first_x_assum irule \\ fs[]
\\ qexistsl_tac [`Gamma`, `a`] \\ fs[])
\\ Cases_on ‘isFixedPoint x ∧ isFixedPoint x'’
>- (fs[option_case_eq] \\ Cases_on `morePrecise x mj` \\ Cases_on `morePrecise x' mj`
\\ fs[addMono_def, option_case_eq]
\\ rveq \\ fs[FloverMapTree_mem_def, map_find_add]
\\ reverse (Cases_on `e'' = Binop b e1 e2`) \\ fs[]
>- (irule validTypes_mono
\\ qexists_tac `map2` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
>- (COND_CASES_TAC \\ fs[]))
\\ rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `mj` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `map2` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map2` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (fs[no_cycle_binop_left, no_cycle_binop_right, isJoin_def]
\\ Cases_on ‘x’ \\ Cases_on ‘x'’ \\ fs[isFixedPoint_def]
\\ fs[join_fl_def]
\\ Cases_on ‘mj’ \\ fs[morePrecise_def])
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Binop b e1 e2`, `mj`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def] \\ rveq \\ fs[])
\\ pop_assum (fn thm => fs[thm, option_case_eq])
\\ rename1 ‘m1 = REAL ∨ m2 = REAL’
\\ Cases_on ‘m1 = REAL ∨ m2 = REAL’ \\ fs[] \\ fs[]
\\ TRY (rename1 ‘(if m2 = REAL then _ else _) = _’ \\ Cases_on ‘m2 = REAL’ \\ fs[]
\\ Cases_on `isMonotone (FloverMapTree_find (Binop b e1 e2) Gamma) REAL`)
ORELSE (TRY (rename1 ‘(if m1 = REAL then _ else _) = _’ \\ Cases_on ‘m1 = REAL’ \\ fs[]
\\ Cases_on `isMonotone (FloverMapTree_find (Binop b e1 e2) Gamma) REAL`))
ORELSE (Cases_on `isMonotone (FloverMapTree_find (Binop b e1 e2) Gamma) m`)
\\ fs[addMono_def, option_case_eq]
\\ rveq \\ fs[FloverMapTree_mem_def, map_find_add]
\\ reverse (Cases_on `e'' = Binop b e1 e2`) \\ fs[]
\\ TRY (irule validTypes_mono
\\ qexists_tac `map2` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[] \\ FAIL_TAC "NOT FINISHED")
>- (rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `REAL` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `map2` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map2` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- fs[isJoin_def, isFixedPoint_def, join_fl_def]
\\ rpt strip_tac \\ fs[eval_expr_cases, toRExpMap_def]
\\ first_x_assum (qspecl_then [‘Binop b e1 e2’, ‘REAL’] assume_tac) \\ fs[])
>- (Cases_on ‘FloverMapTree_find (Binop b e1 e2) akk’ \\ fs[]
\\ Cases_on ‘m1 = REAL’ \\ fs[]
\\ Cases_on ‘isMonotone (FloverMapTree_find (Binop b e1 e2) Gamma) REAL’
\\ fs[option_case_eq] \\ rveq
\\ irule validTypes_mono \\ qexists_tac ‘map2’ \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ TOP_CASE_TAC \\ fs[])
>- (rveq
\\ Cases_on ‘FloverMapTree_find (Binop b e1 e2) akk’ \\ fs[]
\\ Cases_on ‘m1 = REAL’ \\ fs[]
\\ Cases_on ‘isMonotone (FloverMapTree_find (Binop b e1 e2) Gamma) REAL’
\\ fs[option_case_eq] \\ rveq
\\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `REAL` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `map2` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map2` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- fs[isJoin_def, isFixedPoint_def, join_fl_def]
\\ rpt strip_tac \\ fs[eval_expr_cases, toRExpMap_def]
\\ first_x_assum (qspecl_then [‘Binop b e1 e2’, ‘REAL’] assume_tac) \\ fs[])
>- (Cases_on ‘isMonotone (FloverMapTree_find (Binop b e1 e2) Gamma) m’
\\ fs[option_case_eq] \\ rveq
\\ irule validTypes_mono \\ qexists_tac ‘map2’ \\ fs[map_find_add]
\\ rpt strip_tac \\ TOP_CASE_TAC \\ fs[])
\\ rveq \\ fs[]
\\ Cases_on ‘isMonotone (FloverMapTree_find (Binop b e1 e2) Gamma) m’
\\ fs[option_case_eq] \\ rveq
\\ rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac ‘m’ \\ fs[] \\ rpt conj_tac \\ fs[map_find_add]
>- (irule validTypes_mono
\\ qexists_tac `map2` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map2` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (fs[no_cycle_binop_left, no_cycle_binop_right, isJoin_def]
\\ Cases_on ‘m1’ \\ Cases_on ‘m2’ \\ fs[join_fl_def, morePrecise_def]
\\ rveq \\ EVAL_TAC)
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Binop b e1 e2`, `m`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def] \\ rveq \\ fs[])
>- (qpat_x_assum `getValidMap _ _ _ = _`
(fn thm => assume_tac (ONCE_REWRITE_RULE [getValidMap_def] thm))
\\ rename1 `Fma e1 e2 e3` \\ fs[]
\\ Cases_on `FloverMapTree_mem (Fma e1 e2 e3) akk` \\ fs[]
\\ Cases_on `getValidMap Gamma e1 akk` \\ fs[]
\\ Cases_on `getValidMap Gamma e2 a` \\ fs[]
\\ rename1 `getValidMap Gamma e2 a = Succes map2`
\\ Cases_on `getValidMap Gamma e3 map2` \\ fs[]
\\ rename1 `getValidMap Gamma e3 map2 = Succes map3`
\\ Cases_on `FloverMapTree_find e1 map3` \\ fs[]
\\ Cases_on `FloverMapTree_find e2 map3` \\ fs[]
\\ Cases_on `FloverMapTree_find e3 map3` \\ fs[]
\\ `! e. FloverMapTree_mem e a ==> validTypes e a`
by (rpt strip_tac \\ last_x_assum irule \\ fs[]
\\ qexistsl_tac [`Gamma`, `akk`] \\ fs[])
\\ `! e. FloverMapTree_mem e map2 ==> validTypes e map2`
by (rpt strip_tac
\\ qpat_x_assum `!Gamma akk res. _ /\ getValidMap _ e3 _ = _ ==> _` kall_tac
\\ first_x_assum irule \\ fs[]
\\ qexistsl_tac [`Gamma`, `a`] \\ fs[])
\\ `! e. FloverMapTree_mem e map3 ==> validTypes e map3`
by (rpt strip_tac \\ first_x_assum irule \\ fs[]
\\ qexistsl_tac [`Gamma`, `map2`] \\ fs[])
\\ Cases_on `isFixedPoint x /\ isFixedPoint x' /\ isFixedPoint x''`
>- (fs[option_case_eq]
\\ Cases_on `morePrecise x mj` \\ Cases_on `morePrecise x' mj`
\\ Cases_on `morePrecise x'' mj`
\\ fs[addMono_def, option_case_eq]
\\ rveq \\ fs[FloverMapTree_mem_def, map_find_add]
\\ rename1 `if eNew = Fma e1 e2 e3 then SOME mj else _`
\\ reverse (Cases_on `eNew = Fma e1 e2 e3`) \\ fs[]
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
\\ rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `mj` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (fs[no_cycle_fma_left, no_cycle_fma_center, no_cycle_fma_right,
isJoin3_def]
\\ Cases_on ‘x’ \\ Cases_on ‘x'’ \\ Cases_on ‘x''’ \\ fs[isFixedPoint_def]
\\ Cases_on ‘mj’ \\ fs[morePrecise_def])
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Fma e1 e2 e3`, `mj`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def] \\ rveq \\ fs[])
\\ pop_assum (fn thm => fs[thm, option_case_eq])
\\ rename1 ‘m1 = REAL ∨ m2 = REAL ∨ m3 = REAL’
\\ Cases_on ‘m1 = REAL ∨ m2 = REAL ∨ m3 = REAL’ \\ fs[] \\ fs[]
\\ ((rename1 ‘(if m2 = REAL ∧ m3 = REAL then _ else _) = _’
\\ Cases_on ‘m2 = REAL ∧ m3 = REAL’ \\ fs[]
\\ Cases_on `isMonotone (FloverMapTree_find (Fma e1 e2 e3) Gamma) REAL`)
ORELSE (rename1 ‘(if m1 = REAL ∧ m3 = REAL then _ else _) = _’
\\ Cases_on ‘m1 = REAL ∧ m3 = REAL’ \\ fs[]
\\ Cases_on `isMonotone (FloverMapTree_find (Fma e1 e2 e3) Gamma) REAL`)
ORELSE (rename1 ‘(if m1 = REAL ∧ m2 = REAL then _ else _) = _’
\\ Cases_on ‘m1 = REAL ∧ m2 = REAL’ \\ fs[]
\\ Cases_on `isMonotone (FloverMapTree_find (Fma e1 e2 e3) Gamma) REAL`)
ORELSE (fs[option_case_eq] \\ Cases_on `isMonotone (FloverMapTree_find (Fma e1 e2 e3) Gamma) m`))
\\ fs[addMono_def, option_case_eq]
\\ rveq \\ fs[FloverMapTree_mem_def, map_find_add]
\\ rename1 `eNew = Fma e1 e2 e3`
\\ reverse (Cases_on `eNew = Fma e1 e2 e3`) \\ fs[]
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `REAL` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- EVAL_TAC
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Fma e1 e2 e3`, `REAL`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def] \\ rveq \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `REAL` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- EVAL_TAC
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Fma e1 e2 e3`, `REAL`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def] \\ rveq \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `REAL` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- EVAL_TAC
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Fma e1 e2 e3`, `REAL`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def] \\ rveq \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `m` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (irule validTypes_mono
\\ qexists_tac `map3` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (fs[no_cycle_fma_left, no_cycle_fma_center, no_cycle_fma_right,
isJoin3_def]
\\ Cases_on ‘m1’ \\ Cases_on ‘m2’ \\ Cases_on ‘m3’
\\ fs[join_fl3_def, join_fl_def, morePrecise_def, isFixedPoint_def]
\\ rveq \\ fs[])
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Fma e1 e2 e3`, `m`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def] \\ rveq \\ fs[]))
\\ qpat_x_assum `getValidMap _ _ _ = _`
(fn thm => assume_tac (ONCE_REWRITE_RULE [getValidMap_def] thm))
\\ Cases_on `FloverMapTree_mem (Downcast m e) akk` \\ fs[]
\\ Cases_on `getValidMap Gamma e akk` \\ fs[]
\\ Cases_on `FloverMapTree_find e a` \\ fs[]
\\ `! e. FloverMapTree_mem e a ==> validTypes e a`
by (rpt strip_tac \\ first_x_assum irule \\ fs[]
\\ qexistsl_tac [`Gamma`, `akk`] \\ fs[])
\\ Cases_on `isFixedPoint x` \\ fs[option_case_eq]
>- (Cases_on `m = mFix` \\ Cases_on `morePrecise x mFix`
\\ fs[addMono_def, option_case_eq]
\\ rveq \\ fs[FloverMapTree_mem_def, map_find_add]
\\ reverse (Cases_on `e' = Downcast m e`) \\ fs[]
>- (irule validTypes_mono
\\ qexists_tac `a` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
\\ rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `m` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `a` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (fs[no_cycle_cast, isMorePrecise_morePrecise])
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Downcast m e`, `mFix`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def] \\ rveq \\ fs[])
\\ Cases_on `morePrecise x m`
\\ Cases_on `isMonotone (FloverMapTree_find (Downcast m e) Gamma) m`
\\ fs[addMono_def, option_case_eq]
\\ rveq \\ fs[FloverMapTree_mem_def, map_find_add]
\\ reverse (Cases_on `e' = Downcast m e`) \\ fs[]
>- (irule validTypes_mono
\\ qexists_tac `a` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
\\ rveq \\ once_rewrite_tac[validTypes_def]
\\ qexists_tac `m` \\ fs[map_find_add]
\\ rpt conj_tac
>- (irule validTypes_mono
\\ qexists_tac `a` \\ fs[]
\\ rpt strip_tac \\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[])
>- (fs[no_cycle_cast, isMorePrecise_morePrecise])
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Downcast m e`, `m`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def] \\ rveq \\ fs[]
QED
Theorem getValidMap_top_contained:
! e akk Gamma res.
getValidMap Gamma e akk = Succes res ==>
FloverMapTree_mem e res
Proof
Induct_on `e` \\ simp[Once getValidMap_def] \\ rpt strip_tac
>- (EVERY_CASE_TAC \\ rveq \\ fs[FloverMapTree_mem_def, map_find_add])
>- (EVERY_CASE_TAC \\ rveq \\ fs[FloverMapTree_mem_def, map_find_add])
>- (Cases_on `getValidMap Gamma e akk` \\ fs[]
\\ res_tac
\\ fs[addMono_def]
\\ EVERY_CASE_TAC \\ rveq \\ fs[FloverMapTree_mem_def, map_find_add])
>- (Cases_on `FloverMapTree_mem (Binop b e e') akk` \\ fs[] \\ rveq \\ fs[]
\\ Cases_on `getValidMap Gamma e akk` \\ fs[]
\\ Cases_on `getValidMap Gamma e' a` \\ fs[]
\\ res_tac \\ fs[addMono_def]
\\ EVERY_CASE_TAC \\ rveq \\ fs[FloverMapTree_mem_def, map_find_add])
>- (rename1 `Fma e1 e2 e3`
\\ Cases_on `FloverMapTree_mem (Fma e1 e2 e3) akk` \\ fs[] \\ rveq \\ fs[]
\\ Cases_on `getValidMap Gamma e1 akk` \\ fs[]
\\ Cases_on `getValidMap Gamma e2 a` \\ fs[]
\\ Cases_on `getValidMap Gamma e3 a'` \\ fs[]
\\ res_tac \\ fs[addMono_def]
\\ EVERY_CASE_TAC \\ rveq \\ fs[FloverMapTree_mem_def, map_find_add])
\\ Cases_on `getValidMap Gamma e akk` \\ fs[]
\\ res_tac
\\ fs[addMono_def]
\\ EVERY_CASE_TAC \\ rveq \\ fs[FloverMapTree_mem_def, map_find_add]
QED
Theorem getValidMap_top_correct:
! e akk Gamma res.
(! e. FloverMapTree_mem e akk ==> validTypes e akk) /\
getValidMap Gamma e akk = Succes res ==>
validTypes e res
Proof
metis_tac[getValidMap_correct, getValidMap_top_contained]
QED
Definition validTypesCmd_def:
validTypesCmd f Gamma =
((case f of
| Let m x e g =>
? mG.
FloverMapTree_find e Gamma = SOME mG /\
FloverMapTree_find (Var x) Gamma = SOME m /\
m = mG /\
validTypes e Gamma /\
validTypesCmd g Gamma
| Ret e => validTypes e Gamma) /\
? mT.
FloverMapTree_find (getRetExp f) Gamma = SOME mT /\
(! E Gamma2 v m.
(! e m. FloverMapTree_find e Gamma = SOME m ==>
FloverMapTree_find e Gamma2 = SOME m) /\
bstep f E (toRExpMap Gamma2) v m ==>
m = mT))
End
Theorem validTypesCmd_single:
! f Gamma.
validTypesCmd f Gamma ==>
? mT.
FloverMapTree_find (getRetExp f) Gamma = SOME mT /\
! E Gamma2 v m.
(! e m. FloverMapTree_find e Gamma = SOME m ==>
FloverMapTree_find e Gamma2 = SOME m) /\
bstep f E (toRExpMap Gamma2) v m ==>
m = mT
Proof
Cases_on `f` \\ simp[Once validTypesCmd_def] \\ rpt strip_tac \\ metis_tac[]
QED
Definition getValidMapCmd_def:
getValidMapCmd Gamma (Let m x e g) akk =
do
res_e <- getValidMap Gamma e akk;
case FloverMapTree_find e res_e of
| NONE => Fail "No type computed for argument"
| SOME m_e =>
if (m = m_e)
then
do
newMap <- addMono (Var x) m res_e;
getValidMapCmd Gamma g newMap;
od
else Fail "Incorrect type for let-bound variable"
od /\
getValidMapCmd Gamma (Ret e) akk = getValidMap Gamma e akk
End
Theorem getValidMapCmd_mono:
! f Gamma akk res.
getValidMapCmd Gamma f akk = Succes res ==>
! e m. FloverMapTree_find e akk = SOME m ==>
FloverMapTree_find e res = SOME m
Proof
Induct_on `f` \\ simp[Once getValidMapCmd_def]
THENL [ ALL_TAC , MATCH_ACCEPT_TAC getValidMap_mono]
\\ rpt strip_tac
\\ Cases_on `getValidMap Gamma e akk` \\ fs[option_case_eq]
\\ Cases_on `m = m_e` \\ fs[] \\ rveq
\\ Cases_on `addMono (Var n) m a` \\ fs[addMono_def, option_case_eq]
\\ rveq
\\ res_tac
\\ first_x_assum irule
\\ fs[map_find_add]
\\ COND_CASES_TAC \\ fs[]
>- (rveq
\\ `FloverMapTree_find (Var n) a = SOME m'`
by (irule getValidMap_mono \\ qexistsl_tac [`Gamma`, `akk`, `e`]
\\ fs[])
\\ fs[])
\\ irule getValidMap_mono \\ ntac 2 (find_exists_tac \\ fs[])
QED
Theorem getValidMapCmd_correct:
! f Gamma akk res.
(! e. FloverMapTree_mem e akk ==>
validTypes e akk) /\
getValidMapCmd Gamma f akk = Succes res ==>
validTypesCmd f res /\
(! e. FloverMapTree_mem e res ==>
validTypes e res)
Proof
Induct_on `f` \\ simp[getValidMapCmd_def]
\\ rpt gen_tac \\ rpt (disch_then assume_tac) \\ fs[]
>- (Cases_on `getValidMap Gamma e akk` \\ fs[option_case_eq]
\\ Cases_on `m = m_e` \\ fs[] \\ rveq
\\ Cases_on `addMono (Var n) m a` \\ fs[addMono_def, option_case_eq]
\\ rveq
\\ `validTypesCmd f res /\
! e. FloverMapTree_mem e res ==> validTypes e res`
by (first_x_assum irule \\ qexistsl_tac [`Gamma`, `insert (Var n) m a`]
\\ fs[] \\ rpt strip_tac \\ fs[FloverMapTree_mem_def, map_find_add]
\\ Cases_on `e' = Var n`
>- (rveq \\ simp[validTypes_def]
\\ qexists_tac `m` \\ fs[map_find_add]
\\ rpt strip_tac
\\ first_x_assum (qspecl_then [`Var n`, `m`] assume_tac)
\\ fs[eval_expr_cases, toRExpMap_def])
\\ fs[] \\ irule validTypes_mono
\\ qexists_tac `a` \\ conj_tac
>- (rpt strip_tac \\ irule map_find_mono
\\ fs[FloverMapTree_mem_def])
\\ irule getValidMap_correct
\\ conj_tac \\ fs[FloverMapTree_mem_def]
\\ qexistsl_tac [`Gamma`, `akk`, `e`] \\ fs[])
\\ simp[Once validTypesCmd_def, getRetExp_def]
\\ IMP_RES_TAC validTypesCmd_single
\\ rpt conj_tac
>- (irule getValidMapCmd_mono
\\ qexistsl_tac [`Gamma`, `insert (Var n) m a`, `f`] \\ fs[]
\\ fs[map_find_add] \\ Cases_on `e = Var n` \\ fs[])
>- (irule getValidMapCmd_mono
\\ qexistsl_tac [`Gamma`, `insert (Var n) m a`, `f`] \\ fs[]
\\ fs[map_find_add])
>- (`? m. FloverMapTree_find e res = SOME m`
by (qexists_tac `m` \\ irule getValidMapCmd_mono
\\ qexistsl_tac [`Gamma`, `insert (Var n) m a`, `f`] \\ fs[]
\\ fs[map_find_add] \\ COND_CASES_TAC \\ fs[])
\\ first_x_assum irule \\ fs[FloverMapTree_mem_def])
\\ qexists_tac `mT` \\ fs[]
\\ rpt strip_tac \\ fs[bstep_cases]
\\ first_x_assum irule
\\ ntac 2 (find_exists_tac \\ fs[]))
\\ simp[Once validTypesCmd_def]
\\ IMP_RES_TAC getValidMap_correct
\\ IMP_RES_TAC getValidMap_top_correct
\\ rpt conj_tac \\ fs[]
\\ IMP_RES_TAC validTypes_single
\\ qexists_tac `mG` \\ fs[getRetExp_def]
\\ rpt strip_tac \\ fs[bstep_cases]
\\ first_x_assum irule \\ ntac 2 (find_exists_tac \\ fs[])
QED
Theorem validTypes_defined_usedVars:
∀ e Gamma.
validTypes e Gamma ⇒
∀ x. x IN domain (usedVars e) ⇒
∃ m. FloverMapTree_find (Var x) Gamma = SOME m
Proof
ho_match_mp_tac (fetch "-" "validTypes_ind")
\\ rpt strip_tac
\\ qpat_x_assum ‘validTypes _ _’ mp_tac \\ simp[Once validTypes_def]
\\ every_case_tac
\\ qpat_x_assum ‘_ IN domain (usedVars _)’ mp_tac
\\ simp[Once usedVars_def]
\\ rpt strip_tac \\ rveq \\ fs[domain_union]
QED