-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathdata_to_word_bignumProofScript.sml
2492 lines (2429 loc) · 107 KB
/
data_to_word_bignumProofScript.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
(*
Part of the correctness proof for data_to_word
*)
open preamble dataSemTheory dataPropsTheory
copying_gcTheory int_bitwiseTheory finite_mapTheory
data_to_word_memoryProofTheory data_to_word_gcProofTheory
data_to_wordTheory wordPropsTheory
set_sepTheory semanticsPropsTheory
helperLib alignmentTheory blastLib word_bignumTheory
wordLangTheory word_bignumProofTheory gen_gc_partialTheory
gc_sharedTheory word_gcFunctionsTheory word_depthProofTheory;
local open gen_gcTheory in end
val _ = new_theory "data_to_word_bignumProof";
val _ = temp_delsimps ["NORMEQ_CONV", "fromAList_def", "domain_union",
"domain_inter", "domain_difference",
"domain_map", "sptree.map_def", "sptree.lookup_rwts",
"sptree.insert_notEmpty", "sptree.isEmpty_union"]
val _ = diminish_srw_ss ["ABBREV"]
val _ = set_trace "BasicProvers.var_eq_old" 1
val _ = set_grammar_ancestry
["dataSem", "wordSem", "data_to_word",
"data_to_word_memoryProof", "data_to_word_gcProof", "word_bignumProof"
];
val _ = temp_bring_to_front_overload"cut_env"{Name="cut_env",Thy="wordSem"};
val _ = hide "next";
val clean_tac = rpt var_eq_tac \\ rpt (qpat_x_assum `T` kall_tac)
fun rpt_drule th = drule (th |> GEN_ALL) \\ rpt (disch_then drule \\ fs [])
val state_rel_def = data_to_word_gcProofTheory.state_rel_def
val code_rel_def = data_to_word_gcProofTheory.code_rel_def
val eval_tac = fs [wordSemTheory.evaluate_def,
wordSemTheory.word_exp_def, wordSemTheory.set_var_def,
set_var_def, wordSemTheory.the_words_def,
wordSemTheory.mem_load_def,wordLangTheory.word_op_def,
wordLangTheory.word_sh_def]
Theorem eq_eval =
LIST_CONJ [wordSemTheory.evaluate_def,wordSemTheory.get_var_def,
lookup_insert,wordSemTheory.get_var_imm_def,asmTheory.word_cmp_def,
wordSemTheory.word_exp_def,wordSemTheory.set_var_def,
wordSemTheory.call_env_def,fromList2_def,wordSemTheory.mem_load_def,
wordSemTheory.bad_dest_args_def,wordSemTheory.get_vars_def,
wordSemTheory.find_code_def,wordSemTheory.add_ret_loc_def,
list_insert_def,wordSemTheory.dec_clock_def,wordSemTheory.the_words_def,
wordLangTheory.word_op_def]
Theorem word_list_IMP_store_list:
!xs a frame m dm.
(word_list a xs * frame) (fun2set (m,dm)) ==>
store_list a xs m dm = SOME m
Proof
Induct \\ fs [store_list_def,word_list_def]
\\ rw [] \\ SEP_R_TAC
\\ `(a =+ h) m = m` by
(fs [FUN_EQ_THM,APPLY_UPDATE_THM] \\ rw [] \\ SEP_R_TAC \\ fs [])
\\ simp [] \\ first_x_assum match_mp_tac
\\ qexists_tac `frame * one (a,h)` \\ fs [AC STAR_COMM STAR_ASSOC]
QED
Theorem word_exp_set_var_ShiftVar_lemma:
word_exp t (ShiftVar sow v n) =
case lookup v t.locals of
| SOME (Word w) =>
OPTION_MAP Word
(case sow of Lsl => SOME (w << n)
| Lsr => SOME (w >>> n)
| Asr => SOME (w >> n)
| Ror => SOME (word_ror w n))
| _ => FAIL (word_exp t (ShiftVar sow v n)) "lookup failed"
Proof
Cases_on `lookup v t.locals` \\ fs [] \\ rw [FAIL_DEF]
\\ fs [ShiftVar_def]
\\ IF_CASES_TAC \\ fs []
THEN1
(Cases_on `n < dimindex (:'a)` \\ fs []
THEN1
(Cases_on `n = 0` \\ fs []
\\ eval_tac \\ every_case_tac \\ fs [])
\\ eval_tac \\ every_case_tac \\ fs [] \\ eval_tac
\\ qspec_then `n` assume_tac (MATCH_MP MOD_LESS DIMINDEX_GT_0)
\\ simp [])
\\ IF_CASES_TAC \\ fs []
THEN1 (eval_tac \\ every_case_tac \\ fs [])
\\ IF_CASES_TAC \\ fs []
THEN1
(drule word_asr_dimindex
\\ IF_CASES_TAC \\ eval_tac
\\ every_case_tac \\ eval_tac)
\\ eval_tac \\ every_case_tac \\ fs [] \\ eval_tac
QED
Theorem i2mw_small_int_IMP_0:
(∀v1. i2mw v ≠ (F,[v1:'a word])) /\ (∀v1. i2mw v ≠ (T,[v1:'a word])) /\
small_int (:α) v /\ good_dimindex (:'a) ==> v = 0
Proof
CCONTR_TAC \\ fs [] \\ Cases_on `v` \\ fs []
\\ fs [multiwordTheory.i2mw_def,small_int_def]
\\ qpat_x_assum `!x._` mp_tac \\ fs []
\\ once_rewrite_tac [multiwordTheory.n2mw_def]
\\ once_rewrite_tac [multiwordTheory.n2mw_def]
\\ rw []
\\ fs [good_dimindex_def,dimword_def]
\\ fs [good_dimindex_def,dimword_def] \\ rfs [DIV_EQ_X]
\\ intLib.COOPER_TAC
QED
Theorem state_rel_Number_small_int:
state_rel c r1 r2 s t [x] locs /\ small_int (:'a) i ==>
state_rel c r1 r2 s t [(Number i,Word (Smallnum i:'a word))] locs
Proof
fs [state_rel_thm] \\ rw[]
\\ match_mp_tac IMP_memory_rel_Number \\ fs []
\\ first_x_assum (fn th => mp_tac th THEN match_mp_tac memory_rel_rearrange)
\\ fs []
QED
Theorem heap_lookup_Unused_Bignum:
heap_lookup a (Unused k::hb) = SOME (Bignum j) <=>
k+1 <= a /\
heap_lookup (a - (k+1)) hb = SOME (Bignum j)
Proof
fs [heap_lookup_def,el_length_def]
\\ rw [] \\ fs [Bignum_def]
\\ pairarg_tac \\ fs []
QED
Theorem push_env_insert_0:
push_env (insert 0 x LN) NONE t =
t with <| stack := StackFrame t.locals_size [(0,x)] NONE :: t.stack ;
stack_max :=
OPTION_MAP2 MAX t.stack_max
(stack_size (StackFrame t.locals_size [(0,x)] NONE:: t.stack));
permute := \n. t.permute (n+1) |>
Proof
fs [wordSemTheory.push_env_def]
\\ fs [wordSemTheory.env_to_list_def]
\\ EVAL_TAC \\ rw [] \\ fs []
\\ fs [BIJ_DEF,INJ_DEF]
QED
Theorem mc_header_i2mw_eq_0w:
2 * LENGTH (SND (i2mw i):'a word list) + 1 < dimword (:'a) ==>
(mc_header (i2mw i:bool # 'a word list) = 0w:'a word <=> i = 0)
Proof
Cases_on `i = 0`
\\ fs [multiwordTheory.i2mw_def,mc_multiwordTheory.mc_header_def]
\\ rw [] \\ fs [word_add_n2w] THEN1 EVAL_TAC
\\ fs [LENGTH_NIL]
\\ once_rewrite_tac [multiwordTheory.n2mw_def]
\\ rw [] \\ intLib.COOPER_TAC
QED
Theorem MustTerminate_limit_eq:
good_dimindex (:'a) ==>
?k. MustTerminate_limit (:α) =
10 * dimword (:'a) * dimword (:'a) +
10 * dimword (:'a) + 100 + k
Proof
rewrite_tac [GSYM LESS_EQ_EXISTS]
\\ fs [wordSemTheory.MustTerminate_limit_def] \\ rw []
\\ match_mp_tac LESS_EQ_TRANS
\\ qexists_tac `dimword (:α) ** dimword (:α)`
\\ fs []
\\ match_mp_tac LESS_EQ_TRANS
\\ qexists_tac `12 * (dimword (:α))²`
\\ `10 * dimword (:'a) <= (dimword (:α))² /\
100 <= (dimword (:α))²` by
(fs [dimword_def,good_dimindex_def] \\ NO_TAC)
\\ fs []
\\ match_mp_tac LESS_EQ_TRANS
\\ qexists_tac `(dimword (:α)) * (dimword (:α))²` \\ fs []
\\ fs [dimword_def,good_dimindex_def]
QED
Theorem SND_i2mw_NIL:
SND (i2mw i) = [] <=> i = 0
Proof
Cases_on `i` \\ fs []
\\ fs [multiwordTheory.i2mw_def]
\\ once_rewrite_tac [multiwordTheory.n2mw_def]
\\ rw [] \\ intLib.COOPER_TAC
QED
Theorem word_cmp_Test_1:
word_cmp Test w 1w <=> ~(word_bit 0 w)
Proof
EVAL_TAC \\ fs [word_and_one_eq_0_iff,word_bit_def]
QED
Theorem word_bit_if_1_0:
word_bit 0 (if b then 1w else 0w) <=> b
Proof
Cases_on `b` \\ EVAL_TAC
QED
Definition get_iop_def:
get_iop (n:num) =
if n = 0 then multiword$Add else
if n = 1 then multiword$Sub else
if n = 4 then multiword$Mul else
if n = 5 then multiword$Div else
multiword$Mod
End
Definition int_op_def:
int_op op_index i j =
if op_index = 0n then SOME (i + j) else
if op_index = 1 then SOME (i - j) else
if op_index = 4 then SOME (i * j) else
if op_index = 5 /\ j <> 0 then SOME (i / j) else
if op_index = 6 /\ j <> 0 then SOME (i % j) else NONE
End
Theorem get_sign_word_lemma:
good_dimindex (:α) ⇒ (1w && x ⋙ 4) = if word_bit 4 x then 1w else 0w:'a word
Proof
rw [] \\ fs [fcpTheory.CART_EQ,word_and_def,word_lsr_def,fcpTheory.FCP_BETA,
good_dimindex_def,word_index]
\\ rw [] \\ Cases_on `i = 0` \\ fs [word_bit_def]
QED
val if_eq_b2w = prove(
``(if b then 1w else 0w) = b2w b``,
Cases_on `b` \\ EVAL_TAC);
Theorem option_le_max_dest:
option_le a b ==> OPTION_MAP2 MAX a b = b
Proof
rw []
\\ Cases_on `a` \\ Cases_on `b` \\ fs [backendPropsTheory.option_le_def, OPTION_MAP2_DEF, MAX_DEF]
\\ every_case_tac \\ fs []
QED
Theorem option_map_max_comm:
OPTION_MAP2 MAX a b = OPTION_MAP2 MAX b a
Proof
rw []
\\ Cases_on `a` \\ Cases_on `b` \\ fs [OPTION_MAP2_DEF, MAX_DEF]
\\ every_case_tac \\ fs []
QED
Triviality b2n_not:
(if c then 0 else 1) = b2n (~c)
Proof
Cases_on ‘c’ \\ EVAL_TAC
QED
Theorem LongDiv1_thm':
!k n1 n2 m i1 i2 (t2:('a,'c,'ffi) wordSem$state)
r1 r2 m1 is1 c:data_to_word$config.
single_div_loop (n2w k,[n1;n2],m,[i1;i2]) = (m1,is1) /\
lookup LongDiv1_location t2.code = SOME (7,LongDiv1_code c) /\
lookup 0 t2.locals = SOME (Loc r1 r2) /\
lookup 2 t2.locals = SOME (Word (n2w k)) /\
lookup 4 t2.locals = SOME (Word n2) /\
lookup 6 t2.locals = SOME (Word n1) /\
lookup 8 t2.locals = SOME (Word m) /\
lookup 10 t2.locals = SOME (Word i1) /\
lookup 12 t2.locals = SOME (Word i2) /\
k < dimword (:'a) /\ k < t2.clock /\ good_dimindex (:'a) /\ ~c.has_longdiv ==>
?j1 j2 max.
is1 = [j1;j2] /\
evaluate (LongDiv1_code c,t2) = (SOME (Result (Loc r1 r2) (Word m1)),
t2 with <| clock := t2.clock - k;
locals := LN;
locals_size := SOME 0;
stack_max := max;
store := t2.store |+ (Temp 28w,Word (HD is1)) |>) /\
(max = t2.stack_max \/ max = OPTION_MAP2 MAX t2.stack_max
(OPTION_MAP2 $+ (stack_size t2.stack)
(lookup LongDiv1_location t2.stack_size)))
Proof
Induct THEN1
(fs [Once multiwordTheory.single_div_loop_def] \\ rw []
\\ rewrite_tac [LongDiv1_code_def]
\\ fs [eq_eval,wordSemTheory.set_store_def,wordSemTheory.flush_state_def]
\\ fs [wordSemTheory.state_component_equality])
\\ once_rewrite_tac [multiwordTheory.single_div_loop_def]
\\ rpt strip_tac \\ fs []
\\ fs [multiwordTheory.mw_shift_def]
\\ fs [ADD1,GSYM word_add_n2w]
\\ qpat_x_assum `_ = (m1,is1)` mp_tac
\\ once_rewrite_tac [multiwordTheory.mw_cmp_def] \\ fs []
\\ once_rewrite_tac [multiwordTheory.mw_cmp_def] \\ fs []
\\ once_rewrite_tac [multiwordTheory.mw_cmp_def] \\ fs []
\\ qabbrev_tac `n2' = n2 ⋙ 1`
\\ qabbrev_tac `n1' = (n2 ≪ (dimindex (:α) − 1) || n1 ⋙ 1)`
\\ rewrite_tac [LongDiv1_code_def]
\\ fs [eq_eval,word_add_n2w]
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ once_rewrite_tac [word_exp_set_var_ShiftVar_lemma] \\ fs []
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ once_rewrite_tac [word_exp_set_var_ShiftVar_lemma] \\ fs [lookup_insert]
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ once_rewrite_tac [word_exp_set_var_ShiftVar_lemma] \\ fs [lookup_insert]
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ fs [GSYM word_add_n2w]
\\ Cases_on `i2 <+ n2'` \\ fs [WORD_LOWER_NOT_EQ] THEN1
(strip_tac
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ qmatch_goalsub_abbrev_tac `evaluate (LongDiv1_code c,t3)`
\\ first_x_assum drule
\\ disch_then (qspecl_then [`t3`,`r1`,`r2`,`c`] mp_tac)
\\ impl_tac THEN1 (unabbrev_all_tac \\ fs [lookup_insert])
\\ strip_tac \\ fs []
\\ unabbrev_all_tac
\\ fs [wordSemTheory.state_component_equality])
\\ Cases_on `i2 = n2' /\ i1 <+ n1'` \\ asm_rewrite_tac [] THEN1
(fs [WORD_LOWER_NOT_EQ] \\ rveq \\ strip_tac
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ qmatch_goalsub_abbrev_tac `evaluate (LongDiv1_code c,t3)`
\\ first_x_assum drule
\\ disch_then (qspecl_then [`t3`,`r1`,`r2`,`c`] mp_tac)
\\ impl_tac THEN1 (unabbrev_all_tac \\ fs [lookup_insert])
\\ strip_tac \\ fs []
\\ unabbrev_all_tac
\\ fs [wordSemTheory.state_component_equality])
\\ IF_CASES_TAC
THEN1 (sg `F` \\ fs [] \\ pop_assum mp_tac \\ rfs [] \\ rfs [] \\ rw [])
\\ pop_assum kall_tac
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ `i2 = n2' ==> ~(i1 <₊ n1')` by metis_tac []
\\ simp [] \\ ntac 2 (pop_assum kall_tac)
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ fs [multiwordTheory.mw_sub_def,multiwordTheory.single_sub_def]
\\ pairarg_tac \\ fs []
\\ rename1 `_ = (is2,r)`
\\ rpt (pairarg_tac \\ fs []) \\ rveq
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval,wordSemTheory.inst_def]
\\ fs [if_eq_b2w,GSYM word_add_n2w]
\\ `i1 + ¬n1' + 1w = z /\ (dimword (:α) ≤ w2n i1 + (w2n (¬n1') + 1)) = c1` by
(fs [multiwordTheory.single_add_def] \\ rveq
\\ fs [multiwordTheory.b2w_def,multiwordTheory.b2n_def])
\\ fs [] \\ ntac 2 (pop_assum kall_tac)
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval,wordSemTheory.inst_def]
\\ fs [if_eq_b2w,GSYM word_add_n2w]
\\ qmatch_goalsub_abbrev_tac `b2w new_c`
\\ qmatch_goalsub_abbrev_tac `insert 12 (Word new_z)`
\\ `z' = new_z /\ c1' = new_c` by
(unabbrev_all_tac \\ pop_assum mp_tac
\\ simp [b2n_not]
\\ simp [multiwordTheory.single_add_def] \\ strip_tac \\ rveq
\\ fs [multiwordTheory.b2w_def])
\\ fs [list_Seq_def,eq_eval]
\\ qmatch_goalsub_abbrev_tac `evaluate (LongDiv1_code c,t3)`
\\ strip_tac \\ first_x_assum drule
\\ disch_then (qspecl_then [`t3`,`r1`,`r2`,`c`] mp_tac)
\\ impl_tac THEN1 (unabbrev_all_tac \\ fs [lookup_insert])
\\ strip_tac \\ fs []
\\ unabbrev_all_tac
\\ fs [wordSemTheory.state_component_equality]
QED
Theorem LongDiv1_thm:
!k n1 n2 m i1 i2 (t2:('a,'c,'ffi) wordSem$state)
r1 r2 m1 is1 c:data_to_word$config.
single_div_loop (n2w k,[n1;n2],m,[i1;i2]) = (m1,is1) /\
lookup LongDiv1_location t2.code = SOME (7,LongDiv1_code c) /\
lookup 0 t2.locals = SOME (Loc r1 r2) /\
lookup 2 t2.locals = SOME (Word (n2w k)) /\
lookup 4 t2.locals = SOME (Word n2) /\
lookup 6 t2.locals = SOME (Word n1) /\
lookup 8 t2.locals = SOME (Word m) /\
lookup 10 t2.locals = SOME (Word i1) /\
lookup 12 t2.locals = SOME (Word i2) /\
k < dimword (:'a) /\ k < t2.clock /\ good_dimindex (:'a) /\ ~c.has_longdiv ==>
?j1 j2 max.
is1 = [j1;j2] /\
evaluate (LongDiv1_code c,t2) = (SOME (Result (Loc r1 r2) (Word m1)),
t2 with <| clock := t2.clock - k;
locals := LN;
locals_size := SOME 0;
stack_max := max;
store := t2.store |+ (Temp 28w,Word (HD is1)) |>) /\
(option_le (OPTION_MAP2 $+ (stack_size t2.stack) t2.locals_size) t2.stack_max /\
t2.locals_size = lookup LongDiv1_location t2.stack_size ==> max = t2.stack_max)
Proof
Induct THEN1
(fs [Once multiwordTheory.single_div_loop_def] \\ rw []
\\ rewrite_tac [LongDiv1_code_def]
\\ fs [eq_eval,wordSemTheory.set_store_def,wordSemTheory.flush_state_def]
\\ fs [wordSemTheory.state_component_equality])
\\ once_rewrite_tac [multiwordTheory.single_div_loop_def]
\\ rpt strip_tac \\ fs []
\\ fs [multiwordTheory.mw_shift_def]
\\ fs [ADD1,GSYM word_add_n2w]
\\ qpat_x_assum `_ = (m1,is1)` mp_tac
\\ once_rewrite_tac [multiwordTheory.mw_cmp_def] \\ fs []
\\ once_rewrite_tac [multiwordTheory.mw_cmp_def] \\ fs []
\\ once_rewrite_tac [multiwordTheory.mw_cmp_def] \\ fs []
\\ qabbrev_tac `n2' = n2 ⋙ 1`
\\ qabbrev_tac `n1' = (n2 ≪ (dimindex (:α) − 1) || n1 ⋙ 1)`
\\ rewrite_tac [LongDiv1_code_def]
\\ fs [eq_eval,word_add_n2w]
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ once_rewrite_tac [word_exp_set_var_ShiftVar_lemma] \\ fs []
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ once_rewrite_tac [word_exp_set_var_ShiftVar_lemma] \\ fs [lookup_insert]
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ once_rewrite_tac [word_exp_set_var_ShiftVar_lemma] \\ fs [lookup_insert]
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ fs [GSYM word_add_n2w]
\\ Cases_on `i2 <+ n2'` \\ fs [WORD_LOWER_NOT_EQ] THEN1
(strip_tac
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ qmatch_goalsub_abbrev_tac `evaluate (LongDiv1_code c,t3)`
\\ first_x_assum drule
\\ disch_then (qspecl_then [`t3`,`r1`,`r2`,`c`] mp_tac)
\\ impl_tac THEN1 (unabbrev_all_tac \\ fs [lookup_insert])
\\ strip_tac \\ fs []
\\ unabbrev_all_tac
\\ fs [wordSemTheory.state_component_equality]
\\ strip_tac \\ fs [] \\ rveq \\ fs [backendPropsTheory.option_le_max_right]
\\ drule option_le_max_dest \\ fs [option_map_max_comm])
\\ Cases_on `i2 = n2' /\ i1 <+ n1'` \\ asm_rewrite_tac [] THEN1
(fs [WORD_LOWER_NOT_EQ] \\ rveq \\ strip_tac
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ once_rewrite_tac [list_Seq_def] \\ fs [eq_eval]
\\ qmatch_goalsub_abbrev_tac `evaluate (LongDiv1_code c,t3)`
\\ first_x_assum drule
\\ disch_then (qspecl_then [`t3`,`r1`,`r2`,`c`] mp_tac)
\\ impl_tac THEN1 (unabbrev_all_tac \\ fs [lookup_insert])
\\ strip_tac \\ fs []
\\ unabbrev_all_tac
\\ fs [wordSemTheory.state_component_equality]
\\ strip_tac \\ fs [] \\ rveq \\ fs [backendPropsTheory.option_le_max_right]
\\ drule option_le_max_dest \\ fs [option_map_max_comm])
\\ IF_CASES_TAC
THEN1 (sg `F` \\ fs [] \\ pop_assum mp_tac \\ rfs [] \\ rfs [] \\ rw [])
\\ pop_assum kall_tac
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ `i2 = n2' ==> ~(i1 <₊ n1')` by metis_tac []
\\ simp [] \\ ntac 2 (pop_assum kall_tac)
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ fs [multiwordTheory.mw_sub_def,multiwordTheory.single_sub_def]
\\ pairarg_tac \\ fs []
\\ rename1 `_ = (is2,r)`
\\ rpt (pairarg_tac \\ fs []) \\ rveq
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval]
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval,wordSemTheory.inst_def]
\\ fs [if_eq_b2w,GSYM word_add_n2w]
\\ `i1 + ¬n1' + 1w = z /\ (dimword (:α) ≤ w2n i1 + (w2n (¬n1') + 1)) = c1` by
(fs [multiwordTheory.single_add_def] \\ rveq
\\ fs [multiwordTheory.b2w_def,multiwordTheory.b2n_def])
\\ fs [] \\ ntac 2 (pop_assum kall_tac)
\\ once_rewrite_tac [list_Seq_def] \\ simp [eq_eval,wordSemTheory.inst_def]
\\ fs [if_eq_b2w,GSYM word_add_n2w]
\\ qmatch_goalsub_abbrev_tac `b2w new_c`
\\ qmatch_goalsub_abbrev_tac `insert 12 (Word new_z)`
\\ `z' = new_z /\ c1' = new_c` by
(unabbrev_all_tac \\ pop_assum mp_tac
\\ simp [multiwordTheory.single_add_def] \\ strip_tac \\ rveq
\\ simp [b2n_not] \\ fs [multiwordTheory.b2w_def])
\\ fs [list_Seq_def,eq_eval]
\\ qmatch_goalsub_abbrev_tac `evaluate (LongDiv1_code c,t3)`
\\ strip_tac \\ first_x_assum drule
\\ disch_then (qspecl_then [`t3`,`r1`,`r2`,`c`] mp_tac)
\\ impl_tac THEN1 (unabbrev_all_tac \\ fs [lookup_insert])
\\ strip_tac \\ fs []
\\ unabbrev_all_tac
\\ fs [wordSemTheory.state_component_equality]
\\ strip_tac \\ fs [] \\ rveq \\ fs [backendPropsTheory.option_le_max_right]
\\ drule option_le_max_dest \\ fs [option_map_max_comm]
QED
Theorem get_real_addr_lemma:
shift_length c < dimindex (:'a) /\
good_dimindex (:'a) /\
get_var v (t:('a,'c,'ffi) wordSem$state) = SOME (Word ptr_w) /\
get_real_addr c t.store ptr_w = SOME x ==>
word_exp t (real_addr c v) = SOME (Word (x:'a word))
Proof
fs [get_real_addr_def] \\ every_case_tac \\ fs []
\\ fs [wordSemTheory.get_var_def,real_addr_def]
\\ eval_tac \\ fs [] \\ rw []
\\ eval_tac \\ fs [] \\ rw [] \\ fs []
\\ fs [good_dimindex_def,dimword_def] \\ rw []
\\ rfs [backend_commonTheory.word_shift_def] \\ fs []
QED
Theorem memory_rel_lookup:
memory_rel c be ts refs s st m dm
(join_env l1 (toAList (inter l2 (adjust_set l1))) ++ xs) ∧
lookup n l1 = SOME x ∧ lookup (adjust_var n) l2 = SOME w ⇒
memory_rel c be ts refs s st m dm
((x,w)::(join_env l1 (toAList (inter l2 (adjust_set l1))) ++ xs))
Proof
fs [memory_rel_def] \\ rw [] \\ asm_exists_tac \\ fs []
\\ rpt_drule (Q.INST [`ys`|->`[]`] word_ml_inv_lookup
|> SIMP_RULE std_ss [APPEND])
QED
Theorem evaluate_AddNumSize:
!src c l1 l2 s t locs i w.
state_rel c l1 l2 s (t:('a,'c,'ffi) wordSem$state) [] locs /\
get_var src s.locals = SOME (Number i) ==>
evaluate (AddNumSize c src,set_var 1 (Word w) t) =
(NONE,set_var 1 (Word (w +
n2w (4 * LENGTH ((SND (i2mw i):'a word list))))) t)
Proof
fs [AddNumSize_def] \\ rpt strip_tac
\\ imp_res_tac state_rel_get_var_IMP
\\ fs [state_rel_thm,get_var_def,wordSemTheory.get_var_def]
\\ full_simp_tac std_ss [GSYM APPEND_ASSOC]
\\ drule (GEN_ALL memory_rel_lookup)
\\ rpt (disch_then drule) \\ fs [] \\ strip_tac
\\ imp_res_tac memory_rel_any_Number_IMP
\\ rveq \\ fs [] \\ rveq \\ fs []
\\ rename1 `_ = SOME (Word w4)`
\\ Cases_on `w4 = 0w` THEN1
(fs [eq_eval,EVAL ``0w ' 0``]
\\ imp_res_tac memory_rel_Number_const_test
\\ pop_assum (qspec_then `i` assume_tac) \\ rfs []
\\ sg `i = 0` \\ fs [EVAL ``i2mw 0``]
\\ fs [Smallnum_def,small_int_def,good_dimindex_def] \\ rfs [dimword_def]
\\ Cases_on `i` \\ fs [] \\ rfs [dimword_def])
\\ Cases_on `(w4 && 1w) = 0w` THEN1
(fs [eq_eval]
\\ imp_res_tac memory_rel_Number_const_test
\\ pop_assum (qspec_then `i` assume_tac) \\ rfs []
\\ fs [Smallnum_def]
\\ sg `LENGTH (SND (i2mw i)) = 1` \\ fs []
\\ fs [word_index_test]
\\ fs [multiwordTheory.i2mw_def,Once multiwordTheory.n2mw_def] \\ rfs []
\\ rveq \\ fs [] \\ fs [small_int_def]
\\ fs [good_dimindex_def] \\ rfs [dimword_def]
\\ Cases_on `i` \\ fs [dimword_def] \\ rfs []
\\ once_rewrite_tac [multiwordTheory.n2mw_def]
\\ fs [DIV_EQ_X]
\\ rw [] \\ fs []
\\ `F` by intLib.COOPER_TAC)
\\ fs [eq_eval]
\\ fs [word_index_test]
\\ full_simp_tac std_ss [GSYM APPEND_ASSOC]
\\ drule (GEN_ALL memory_rel_Number_bignum_IMP_ALT) \\ fs []
\\ strip_tac
\\ `word_exp (t with locals := insert 1 (Word w) t.locals)
(real_addr c (adjust_var src)) = SOME (Word a)` by
(match_mp_tac (GEN_ALL get_real_addr_lemma)
\\ fs [wordSemTheory.get_var_def,lookup_insert] \\ NO_TAC) \\ fs []
\\ fs [word_sh_def,decode_length_def]
\\ IF_CASES_TAC THEN1
(rfs [memory_rel_def,heap_in_memory_store_def]
\\ fs [good_dimindex_def] \\ rfs [] \\ fs[])
\\ pop_assum kall_tac \\ fs []
\\ IF_CASES_TAC THEN1
(fs [good_dimindex_def] \\ rfs [])
\\ pop_assum kall_tac \\ fs []
\\ fs [WORD_MUL_LSL,GSYM word_mul_n2w,multiwordTheory.i2mw_def]
QED
Theorem AnyHeader_thm:
!t1 t2 t3 r.
state_rel c l1 l2 s (t:('a,'c,'ffi) wordSem$state) [] locs /\
get_var r s.locals = SOME (Number i) /\
ALL_DISTINCT [t1;t2;t3] ==>
?a2 a3 temp.
evaluate (AnyHeader c (adjust_var r) a t1 t2 t3,t) =
(NONE, (set_store (Temp t1) (Word (mc_header (i2mw i)))
(set_store (Temp t2) (Word a2)
(set_store (Temp t3) (Word a3) (set_var 7 temp t))))) /\
(i = 0i ==>
small_int (:'a) 0i /\ i2mw i = (F,[]) /\
a2 = 0w /\ a3 = 0w) /\
(small_int (:'a) i /\ i <> 0 ==>
i2mw i = (i < 0,[a3]) /\
FLOOKUP t.store (if a then OtherHeap else NextFree) = SOME (Word a2)) /\
(~small_int (:'a) i ==>
?w x. get_var (adjust_var r) t = SOME (Word w) /\
get_real_addr c t.store w = SOME x /\
a2 = x + bytes_in_word)
Proof
rpt strip_tac
\\ imp_res_tac state_rel_get_var_IMP
\\ fs [state_rel_thm]
\\ full_simp_tac std_ss [GSYM APPEND_ASSOC]
\\ rpt_drule memory_rel_get_var_IMP
\\ fs [APPEND] \\ strip_tac
\\ imp_res_tac memory_rel_any_Number_IMP
\\ fs [] \\ fs [] \\ rveq \\ fs []
\\ rename1 `w ' 0 ⇔ ¬small_int (:α) i`
\\ `(w = 0w) <=> (i = 0)` by
(rpt_drule memory_rel_Number_const_test
\\ disch_then (qspec_then `i` mp_tac)
\\ fs [] \\ Cases_on `w = 0w` \\ fs [EVAL ``0w ' 0``]
\\ rw [] \\ fs [] \\ rpt strip_tac
\\ fs [EVAL ``Smallnum 0``,EVAL ``small_int (:'a) 0``]
\\ fs [small_int_def,Smallnum_def]
\\ Cases_on `i` \\ fs []
\\ rfs [good_dimindex_def,dimword_def]
\\ rfs [good_dimindex_def,dimword_def])
\\ Cases_on `i = 0` \\ fs []
THEN1
(fs [EVAL ``i2mw 0``] \\ fs [EVAL ``small_int (:α) 0``]
\\ fs [EVAL ``mc_header (F,[])``,dimword_def]
\\ `0n < 2 ** dimindex (:α) DIV 8` by fs [good_dimindex_def] \\ fs []
\\ fs [AnyHeader_def]
\\ fs [eq_eval,list_Seq_def,wordSemTheory.set_store_def,wordSemTheory.set_var_def]
\\ fs [wordSemTheory.state_component_equality]
\\ fs [GSYM fmap_EQ,FUN_EQ_THM,FAPPLY_FUPDATE_THM]
\\ qexists_tac `Word 0w`
\\ rw [] \\ fs [] \\ eq_tac \\ rw [] \\ fs [])
\\ fs [word_bit,word_bit_test]
\\ reverse (Cases_on `small_int (:'a) i`) \\ fs []
THEN1
(fs [AnyHeader_def,eq_eval]
\\ fs [eq_eval,list_Seq_def,wordSemTheory.set_store_def]
\\ rpt_drule memory_rel_Number_bignum_IMP_ALT
\\ strip_tac
\\ `word_exp t (real_addr c (adjust_var r)) = SOME (Word a)` by
(match_mp_tac (GEN_ALL get_real_addr_lemma)
\\ fs [wordSemTheory.get_var_def]) \\ fs []
\\ fs [word_sh_def]
\\ IF_CASES_TAC
THEN1 (rfs [memory_rel_def,heap_in_memory_store_def]
\\ rfs [good_dimindex_def])
\\ pop_assum kall_tac
\\ `~(1 ≥ dimindex (:α)) /\ ~(4 ≥ dimindex (:α))` by
(fs [good_dimindex_def] \\ fs [good_dimindex_def])
\\ fs []
\\ qexists_tac `0w` \\ fs []
\\ qexists_tac `Word a` \\ fs []
\\ fs [wordSemTheory.state_component_equality]
\\ fs [GSYM fmap_EQ,FUN_EQ_THM,FAPPLY_FUPDATE_THM]
\\ rw [] \\ fs [] \\ TRY (eq_tac \\ rw [] \\ fs [])
\\ fs [decode_length_def,mc_multiwordTheory.mc_header_def,
multiwordTheory.i2mw_def,WORD_MUL_LSL,word_mul_n2w]
\\ qpat_assum `_ <=> i < 0i` (fn th => rewrite_tac [GSYM th])
\\ qpat_assum `good_dimindex (:α)` mp_tac
\\ fs [get_sign_word_lemma])
\\ fs [AnyHeader_def,eq_eval]
\\ Q.MATCH_ASMSUB_RENAME_TAC `(Number i,Word w)::vars` \\ rveq
\\ `memory_rel c t.be (THE s.tstamps) s.refs s.space t.store t.memory t.mdomain
((Number 0,Word (Smallnum 0))::(Number i,Word w)::vars)` by
(match_mp_tac IMP_memory_rel_Number
\\ fs [] \\ EVAL_TAC \\ fs [good_dimindex_def,dimword_def])
\\ imp_res_tac memory_rel_swap
\\ drule memory_rel_Number_cmp \\ fs [EVAL ``word_bit 0 (Smallnum 0)``]
\\ fs [word_bit_test,EVAL ``Smallnum 0``]
\\ strip_tac \\ fs []
\\ IF_CASES_TAC \\ fs []
THEN1
(`i2mw i = (F,[w >>> 2])` by
(fs [multiwordTheory.i2mw_def]
\\ Cases_on `i` \\ fs [intLib.COOPER_PROVE ``Num (ABS (&n)) = n``]
\\ once_rewrite_tac [multiwordTheory.n2mw_def] \\ fs []
\\ `n < dimword (:α)` by
(ntac 2 (rfs [good_dimindex_def,small_int_def,dimword_def]))
\\ once_rewrite_tac [multiwordTheory.n2mw_def] \\ fs []
\\ fs [DIV_EQ_X]
\\ imp_res_tac memory_rel_Number_IMP \\ fs []
\\ fs [Smallnum_def]
\\ rewrite_tac [GSYM w2n_11,w2n_lsr]
\\ fs [] \\ rfs [good_dimindex_def,small_int_def,dimword_def] \\ rfs[]
\\ fs [ONCE_REWRITE_RULE [MULT_COMM] MULT_DIV])
\\ fs [] \\ fs [eq_eval,list_Seq_def,wordSemTheory.set_store_def]
\\ Cases_on `a` \\ fs [FLOOKUP_UPDATE,heap_in_memory_store_def,memory_rel_def]
\\ fs [word_sh_def]
\\ qexists_tac `Word 0w` \\ fs []
\\ fs [wordSemTheory.state_component_equality]
\\ fs [GSYM fmap_EQ,FUN_EQ_THM,FAPPLY_FUPDATE_THM]
\\ rw [] \\ fs [] \\ TRY (eq_tac \\ rw [] \\ fs [])
\\ EVAL_TAC \\ fs [n2w_mod])
THEN1
(`i2mw i = (T,[0w - (w >> 2)])` by
(fs [multiwordTheory.i2mw_def]
\\ Cases_on `i` \\ fs [intLib.COOPER_PROVE ``Num (ABS (-&n)) = n``]
\\ once_rewrite_tac [multiwordTheory.n2mw_def] \\ fs []
\\ `n < dimword (:α)` by
(ntac 2 (rfs [good_dimindex_def,small_int_def,dimword_def]))
\\ once_rewrite_tac [multiwordTheory.n2mw_def] \\ fs []
\\ fs [DIV_EQ_X]
\\ imp_res_tac memory_rel_Number_IMP \\ fs []
\\ fs [small_int_def,Smallnum_def]
\\ `-n2w (4 * n) = i2w (- & (4 * n))` by
(fs [integer_wordTheory.i2w_def] \\ NO_TAC) \\ fs []
\\ qspecl_then [`2`,`-&(4 * n)`] mp_tac (GSYM integer_wordTheory.i2w_DIV)
\\ impl_tac THEN1
(fs [wordsTheory.INT_MIN_def]
\\ fs [EXP_SUB,X_LE_DIV,dimword_def]
\\ rfs [good_dimindex_def])
\\ fs [] \\ strip_tac
\\ `-&(4 * n) / 4:int = - & n` by
(rewrite_tac [MATCH_MP (GSYM integerTheory.INT_DIV_NEG)
(intLib.COOPER_PROVE ``0 <> 4i``)]
\\ fs [integerTheory.INT_DIV_CALCULATE]
\\ fs [integerTheory.INT_EQ_NEG]
\\ match_mp_tac integerTheory.INT_DIV_UNIQUE
\\ fs [] \\ qexists_tac `0` \\ fs []
\\ fs [integerTheory.INT_MUL_CALCULATE])
\\ fs [] \\ fs [integer_wordTheory.i2w_def]
\\ rewrite_tac [GSYM WORD_NEG_MUL] \\ fs [])
\\ fs [] \\ fs [eq_eval,list_Seq_def,wordSemTheory.set_store_def]
\\ Cases_on `a` \\ fs [FLOOKUP_UPDATE,heap_in_memory_store_def,memory_rel_def]
\\ fs [word_sh_def]
\\ qexists_tac `Word 0w` \\ fs []
\\ fs [wordSemTheory.state_component_equality]
\\ fs [GSYM fmap_EQ,FUN_EQ_THM,FAPPLY_FUPDATE_THM]
\\ rw [] \\ fs [] \\ TRY (eq_tac \\ rw [] \\ fs [])
\\ EVAL_TAC \\ fs [n2w_mod])
QED
Theorem state_rel_set_store_Temp:
state_rel c l1 l2 s (set_store (Temp tmp) w t) vs locs =
state_rel c l1 l2 s t vs locs
Proof
fs [state_rel_def,wordSemTheory.set_store_def]
\\ rw [] \\ eq_tac \\ rw []
\\ fs [heap_in_memory_store_def,PULL_EXISTS,FLOOKUP_UPDATE,
FAPPLY_FUPDATE_THM,code_oracle_rel_def]
\\ rpt (asm_exists_tac \\ fs []) \\ metis_tac []
QED
Theorem state_rel_IMP_num_size_limit:
state_rel c l1 l2 s (t:('a,'c,'ffi) wordSem$state) [] locs /\
get_var k s.locals = SOME (Number i) ==>
LENGTH (SND (i2mw i):'a word list) < dimword (:'a) DIV 16
Proof
rpt strip_tac
\\ imp_res_tac state_rel_get_var_IMP
\\ fs [state_rel_thm,get_var_def,wordSemTheory.get_var_def]
\\ full_simp_tac std_ss [GSYM APPEND_ASSOC]
\\ rpt_drule (GEN_ALL memory_rel_lookup)
\\ Cases_on `small_int (:'a) i`
THEN1
(rw [] \\ simp [multiwordTheory.i2mw_def]
\\ once_rewrite_tac [multiwordTheory.n2mw_def]
\\ once_rewrite_tac [multiwordTheory.n2mw_def]
\\ fs [good_dimindex_def,dimword_def] \\ rfs [DIV_EQ_X]
\\ rw [] \\ fs [] \\ rfs [small_int_def,dimword_def]
\\ `F` by intLib.COOPER_TAC)
\\ strip_tac
\\ rpt_drule memory_rel_Number_bignum_IMP_ALT
\\ fs [multiwordTheory.i2mw_def] \\ rw [] \\ fs []
\\ fs [good_dimindex_def,dimword_def] \\ rfs [EXP_SUB]
QED
Theorem word_list_store_list:
!xs a frame m dm.
(word_list a xs * frame) (fun2set (m,dm)) ==>
?m2. (store_list a (REPLICATE (LENGTH xs) (Word 0w)) m dm = SOME m2) /\
(word_list a (REPLICATE (LENGTH xs) (Word 0w)) * frame)
(fun2set (m2,dm))
Proof
Induct \\ fs [store_list_def,REPLICATE,word_list_def] \\ rw []
\\ SEP_R_TAC \\ fs [] \\ SEP_W_TAC \\ SEP_F_TAC
\\ strip_tac \\ fs [AC STAR_COMM STAR_ASSOC]
QED
Theorem MustTerminate_limit_SUB_2:
good_dimindex (:'a) ==> dimword (:'a) <= MustTerminate_limit (:α) − 2
Proof
fs [wordSemTheory.MustTerminate_limit_def]
\\ qpat_abbrev_tac `m = (_:num) ** _`
\\ qpat_abbrev_tac `n = (_:num) ** _`
\\ rpt (pop_assum kall_tac)
\\ fs [good_dimindex_def] \\ rw [] \\ fs [dimword_def]
QED
Theorem cut_env_fromList_sing:
cut_env (fromList [()]) (insert 0 (Loc l1 l2) LN) =
SOME (insert 0 (Loc l1 l2) LN)
Proof
EVAL_TAC
QED
Theorem single_div_pre_IMP_single_div_full:
single_div_pre x1 x2 y ==>
single_div x1 x2 y = single_div_full x1 x2 y
Proof
strip_tac
\\ match_mp_tac (GSYM multiwordTheory.single_div_full_thm)
\\ fs [mc_multiwordTheory.single_div_pre_def,multiwordTheory.mw2n_def]
\\ Cases_on `y` \\ fs [] \\ rfs [DIV_LT_X]
QED
Theorem IMP_LESS_MustTerminate_limit[simp]:
i < dimword (:α) ==>
i < MustTerminate_limit (:α) − 1
Proof
rewrite_tac [wordSemTheory.MustTerminate_limit_def] \\ decide_tac
QED
Theorem evaluate_LongDiv_code':
!(t:('a,'c,'ffi) wordSem$state) l1 l2 c w x1 x2 y d1 m1.
single_div_pre x1 x2 y /\
single_div x1 x2 y = (d1,m1:'a word) /\
lookup LongDiv1_location t.code = SOME (7,LongDiv1_code c) /\
lookup 0 t.locals = SOME (Loc l1 l2) /\
lookup 2 t.locals = SOME (Word x1) /\
lookup 4 t.locals = SOME (Word x2) /\
lookup 6 t.locals = SOME (Word y) /\
dimword (:'a) < t.clock /\ good_dimindex (:'a) ==>
?ck max.
evaluate (LongDiv_code c,t) =
(SOME (Result (Loc l1 l2) (Word d1)),
t with <| clock := ck; locals := LN; locals_size := SOME 0;
store := t.store |+ (Temp 28w,Word m1);
stack_max := max|>) /\
(max = t.stack_max \/ max = OPTION_MAP2 MAX t.stack_max
(OPTION_MAP2 $+ (stack_size t.stack)
(lookup LongDiv1_location t.stack_size)))
Proof
rpt strip_tac
\\ Cases_on `c.has_longdiv` \\ simp []
\\ fs [LongDiv_code_def,eq_eval,wordSemTheory.push_env_def]
THEN1 (* has_longdiv case *)
(once_rewrite_tac [list_Seq_def] \\ fs [eq_eval,wordSemTheory.inst_def]
\\ reverse IF_CASES_TAC THEN1
(sg `F` \\ pop_assum mp_tac \\ simp []
\\ fs [mc_multiwordTheory.single_div_pre_def])
\\ fs [list_Seq_def,eq_eval,wordSemTheory.set_store_def,lookup_insert]
\\ fs [fromAList_def,wordSemTheory.state_component_equality,wordSemTheory.flush_state_def]
\\ fs [multiwordTheory.single_div_def]
\\ fs [OPTION_MAP2_ADD_SOME_0, backendPropsTheory.option_le_refl])
\\ `dimindex (:'a) + 5 < dimword (:'a)` by
(fs [dimword_def,good_dimindex_def] \\ NO_TAC)
\\ imp_res_tac IMP_LESS_MustTerminate_limit
\\ qmatch_goalsub_abbrev_tac `evaluate (LongDiv1_code c,t2)`
\\ rfs [single_div_pre_IMP_single_div_full]
\\ fs [multiwordTheory.single_div_full_def]
\\ Cases_on `(single_div_loop (n2w (dimindex (:α)),[0w; y],0w,[x2; x1]))`
\\ fs [] \\ rveq
\\ `lookup LongDiv1_location t2.code = SOME (7,LongDiv1_code c) /\
lookup 0 t2.locals = SOME (Loc l1 l2)` by
(qunabbrev_tac `t2` \\ fs [lookup_insert])
\\ rpt_drule LongDiv1_thm'
\\ impl_tac THEN1 (qunabbrev_tac `t2` \\ EVAL_TAC \\ fs [])
\\ strip_tac \\ fs []
\\ qunabbrev_tac `t2` \\ fs []
\\ fs [FLOOKUP_UPDATE,wordSemTheory.set_store_def,
wordSemTheory.state_component_equality,fromAList_def]
QED
Theorem evaluate_LongDiv_code:
!(t:('a,'c,'ffi) wordSem$state) l1 l2 c w x1 x2 y d1 m1.
single_div_pre x1 x2 y /\
single_div x1 x2 y = (d1,m1:'a word) /\
lookup LongDiv1_location t.code = SOME (7,LongDiv1_code c) /\
lookup 0 t.locals = SOME (Loc l1 l2) /\
lookup 2 t.locals = SOME (Word x1) /\
lookup 4 t.locals = SOME (Word x2) /\
lookup 6 t.locals = SOME (Word y) /\
dimword (:'a) < t.clock /\ good_dimindex (:'a) ==>
?ck max.
evaluate (LongDiv_code c,t) =
(SOME (Result (Loc l1 l2) (Word d1)),
t with <| clock := ck; locals := LN; locals_size := SOME 0;
store := t.store |+ (Temp 28w,Word m1);
stack_max := max|>) /\
(option_le (OPTION_MAP2 $+ (stack_size t.stack) t.locals_size) t.stack_max /\
t.locals_size = lookup LongDiv1_location t.stack_size ==> max = t.stack_max)
Proof
rpt strip_tac
\\ Cases_on `c.has_longdiv` \\ simp []
\\ fs [LongDiv_code_def,eq_eval,wordSemTheory.push_env_def]
THEN1 (* has_longdiv case *)
(once_rewrite_tac [list_Seq_def] \\ fs [eq_eval,wordSemTheory.inst_def]
\\ reverse IF_CASES_TAC THEN1
(sg `F` \\ pop_assum mp_tac \\ simp []
\\ fs [mc_multiwordTheory.single_div_pre_def])
\\ fs [list_Seq_def,eq_eval,wordSemTheory.set_store_def,lookup_insert]
\\ fs [fromAList_def,wordSemTheory.state_component_equality,wordSemTheory.flush_state_def]
\\ fs [multiwordTheory.single_div_def]
\\ fs [OPTION_MAP2_ADD_SOME_0, backendPropsTheory.option_le_refl])
\\ `dimindex (:'a) + 5 < dimword (:'a)` by
(fs [dimword_def,good_dimindex_def] \\ NO_TAC)
\\ imp_res_tac IMP_LESS_MustTerminate_limit
\\ qmatch_goalsub_abbrev_tac `evaluate (LongDiv1_code c,t2)`
\\ rfs [single_div_pre_IMP_single_div_full]
\\ fs [multiwordTheory.single_div_full_def]
\\ Cases_on `(single_div_loop (n2w (dimindex (:α)),[0w; y],0w,[x2; x1]))`
\\ fs [] \\ rveq
\\ `lookup LongDiv1_location t2.code = SOME (7,LongDiv1_code c) /\
lookup 0 t2.locals = SOME (Loc l1 l2)` by
(qunabbrev_tac `t2` \\ fs [lookup_insert])
\\ rpt_drule LongDiv1_thm
\\ impl_tac THEN1 (qunabbrev_tac `t2` \\ EVAL_TAC \\ fs [])
\\ strip_tac \\ fs []
\\ qunabbrev_tac `t2` \\ fs []
\\ fs [FLOOKUP_UPDATE,wordSemTheory.set_store_def,
wordSemTheory.state_component_equality,fromAList_def]
\\ strip_tac \\ fs [] \\ rveq \\ fs [backendPropsTheory.option_le_max_right]
\\ drule option_le_max_dest \\ fs [option_map_max_comm]
QED
Theorem div_code_assum_thm:
state_rel c l1 l2 s (t:('a,'c,'ffi) wordSem$state) [] locs ==>
div_code_assum (:'ffi) (:'c) t.code
Proof
fs [DivCode_def,div_code_assum_def,eq_eval] \\ rpt strip_tac
\\ fs [state_rel_thm,code_rel_def,stubs_def]
\\ fs [EVAL ``LongDiv_location``,div_location_def]
\\ qpat_abbrev_tac `x = cut_env (LS ()) _`
\\ `x = SOME (insert 0 ret_val LN)` by
(unabbrev_all_tac \\ fs [wordSemTheory.cut_env_def,domain_lookup]
\\ match_mp_tac (spt_eq_thm |> REWRITE_RULE [EQ_IMP_THM]
|> SPEC_ALL |> UNDISCH_ALL |> CONJUNCT2
|> DISCH_ALL |> MP_CANON |> GEN_ALL)
\\ conj_tac THEN1 (rewrite_tac [wf_inter] \\ EVAL_TAC)
\\ simp_tac std_ss [lookup_inter_alt,lookup_def,domain_lookup]
\\ fs [lookup_insert,lookup_def] \\ NO_TAC)
\\ fs [eq_eval,wordSemTheory.push_env_def]
\\ `env_to_list (insert 0 ret_val LN) t1.permute =
([(0,ret_val)],\n. t1.permute (n+1))` by
(fs [wordSemTheory.env_to_list_def,wordSemTheory.list_rearrange_def]
\\ fs [EVAL ``(QSORT key_val_compare (toAList (insert 0 x LN)))``]
\\ fs [EVAL ``count 1``] \\ rw []
\\ EVAL_TAC
\\ fs [BIJ_DEF,SURJ_DEF]
\\ first_x_assum (qspec_then`0` kall_tac)
\\ first_x_assum (qspec_then`0` mp_tac)
\\ EVAL_TAC \\ simp[])
\\ fs []
\\ `dimindex (:'a) + 5 < dimword (:'a)` by
(fs [dimword_def,good_dimindex_def] \\ NO_TAC)
\\ qmatch_goalsub_abbrev_tac `evaluate (LongDiv_code c,t2)`
\\ qspecl_then [`t2`,`n`,`l`,`c`] mp_tac evaluate_LongDiv_code
\\ fs [Abbr `t2`,lookup_insert,multiwordTheory.single_div_def]
\\ impl_tac THEN1 fs [wordSemTheory.MustTerminate_limit_def]
\\ strip_tac \\ fs [] \\ pop_assum kall_tac
\\ fs [wordSemTheory.pop_env_def,EVAL ``domain (fromAList [(0,ret_val)])``,
FLOOKUP_UPDATE,wordSemTheory.set_store_def]
\\ fs [fromAList_def,wordSemTheory.state_component_equality]
\\ match_mp_tac (spt_eq_thm |> REWRITE_RULE [EQ_IMP_THM]
|> SPEC_ALL |> UNDISCH_ALL |> CONJUNCT2
|> DISCH_ALL |> MP_CANON |> GEN_ALL)
\\ conj_tac THEN1 metis_tac [wf_def,wf_insert]
\\ simp_tac std_ss [lookup_insert,lookup_def]
\\ rpt strip_tac
\\ rpt (IF_CASES_TAC \\ asm_rewrite_tac [])
\\ rveq \\ qpat_x_assum `0 < 0n` mp_tac
\\ simp_tac (srw_ss()) []
QED
Theorem IMP_bignum_code_rel:
compile Bignum_location 2 1 (Bignum_location + 1,[])
mc_iop_code = (xx1,xx2,xx3,xx4,xx5) /\
state_rel c l1 l2 s t [] locs ==>
code_rel (xx4,xx5) t.code
Proof
fs [word_bignumProofTheory.code_rel_def,state_rel_def,code_rel_def,stubs_def]
\\ rpt strip_tac
\\ fs [generated_bignum_stubs_def] \\ rfs [] \\ fs [EVERY_MAP]
\\ drule alistTheory.ALOOKUP_MEM \\ strip_tac
\\ first_x_assum (drule o REWRITE_RULE [EVERY_MEM])
\\ fs [] \\ strip_tac
\\ imp_res_tac compile_NIL_IMP \\ fs []
\\ asm_exists_tac \\ fs []
QED
Theorem TWO_LESS_MustTerminate_limit[simp]:
2 < MustTerminate_limit (:α) /\
~(MustTerminate_limit (:α) <= 1)
Proof
fs [wordSemTheory.MustTerminate_limit_def,dimword_def]
\\ Cases_on `dimindex (:'a)` \\ fs [dimword_def,MULT_CLAUSES,EXP]
\\ Cases_on `n` \\ fs [EXP] \\ Cases_on `2 ** n'` \\ fs []
QED
Definition Arith_location_def:
Arith_location index =
if index = 0n then Add_location else
if index = 1n then Sub_location else
if index = 4n then Mul_location else
if index = 5n then Div_location else
if index = 6n then Mod_location else ARB
End
Theorem push_env_code:
(push_env y NONE t).code = t.code
Proof
fs [wordSemTheory.push_env_def] \\ pairarg_tac \\ fs []
QED
Definition Arith_code_def:
Arith_code index =
Seq (Assign 6 (Const (n2w (4 * index))))
(Call NONE (SOME AnyArith_location) [0; 2; 4; 6] NONE)
End
Theorem lookup_Arith_location:
state_rel c l1 l2 x t [] locs /\ int_op index i1 i2 = SOME r ==>