-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathword_to_stackProofScript.sml
11666 lines (11258 loc) · 405 KB
/
word_to_stackProofScript.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
(*
Correctness proof for word_to_stack
*)
open preamble semanticsPropsTheory stackSemTheory wordSemTheory
word_to_stackTheory wordPropsTheory wordConvsTheory stackPropsTheory
parmoveTheory helperLib;
val get_labels_def = stackSemTheory.get_labels_def;
val extract_labels_def = stackPropsTheory.extract_labels_def
val _ = new_theory "word_to_stackProof";
val _ = temp_delsimps ["NORMEQ_CONV"]
val _ = diminish_srw_ss ["ABBREV"]
val _ = temp_delsimps ["lift_disj_eq", "lift_imp_disj",
"fromAList_def", "domain_union", "domain_insert",
"domain_inter", "domain_map", "domain_difference",
"sptree.map_def", "sptree.lookup_rwts",
"sptree.insert_notEmpty"]
val _ = set_trace "BasicProvers.var_eq_old" 1
val _ = set_grammar_ancestry [
"semanticsProps", (* for extend_with_resource_limit *)
"stackProps", (* for extract_labels *)
"wordProps",
"stackSem", "wordSem", "word_to_stack"
]
Type state[pp] = “:(α,β,γ)wordSem$state”
Overload word_cmp[local] = “labSem$word_cmp”;
val _ = Parse.hide "B"
(* TODO: Move to stackProps*)
Theorem set_var_with_memory:
stackSem$set_var a b c with memory := m = set_var a b (c with memory := m)
Proof
EVAL_TAC
QED
Theorem set_var_memory[simp]:
(stackSem$set_var a b c).memory = c.memory
Proof
EVAL_TAC
QED
Theorem get_var_with_clock[simp]:
stackSem$get_var r (t with clock := clk) =
(stackSem$get_var r t)
Proof
rw[stackSemTheory.get_var_def]
QED
(* TODO: many things in this file need moving *)
val the_eqn = backendPropsTheory.the_eqn
Definition index_list_def:
(index_list [] n = []) /\
(index_list (x::xs) n = (n + LENGTH xs,x) :: index_list xs n)
End
val drule = old_drule
Theorem LENGTH_index_list:
!l n. LENGTH (index_list l n) = LENGTH l
Proof
Induct \\ fs [index_list_def]
QED
Theorem EL_index_list:
!xs i. i < LENGTH xs ==>
(EL i (index_list xs k) = (k + LENGTH xs - i - 1, EL i xs))
Proof
Induct \\ fs [index_list_def]
\\ rpt strip_tac \\ Cases_on `i` \\ fs [] \\ decide_tac
QED
Theorem EL_index_list2:
∀xs i. i < LENGTH xs ==>
(EL i (index_list xs k) = (k + LENGTH xs - (i+1), EL i xs))
Proof
Induct \\ fs [index_list_def]
\\ rpt strip_tac \\ Cases_on `i` \\ fs [] \\ decide_tac
QED
Theorem MAP_SND_index_list:
!xs k. MAP SND (index_list xs k) = xs
Proof
Induct \\ fs [index_list_def]
QED
Theorem MAP_FST_index_list:
∀xs k. MAP FST (index_list xs k) = REVERSE (MAP ($+ k) (COUNT_LIST (LENGTH xs)))
Proof
Induct \\ simp[index_list_def,COUNT_LIST_def,MAP_MAP_o]
\\ simp[LIST_EQ_REWRITE] \\ rw[]
\\ Cases_on`x < LENGTH xs`
>- (
simp[EL_APPEND1,LENGTH_COUNT_LIST]
\\ simp[EL_REVERSE,LENGTH_COUNT_LIST]
\\ simp[EL_MAP,LENGTH_COUNT_LIST]
\\ simp[EL_COUNT_LIST]
\\ Cases_on`x` \\ simp[]
\\ simp[EL_REVERSE,LENGTH_COUNT_LIST]
\\ simp[EL_MAP,LENGTH_COUNT_LIST]
\\ simp[EL_COUNT_LIST]
\\ simp[PRE_SUB1] )
\\ fs[LENGTH_COUNT_LIST]
\\ simp[EL_APPEND2,LENGTH_COUNT_LIST]
\\ `x = LENGTH xs` by decide_tac
\\ Cases_on`LENGTH xs`
\\ simp[]
\\ simp[EL_REVERSE,LENGTH_COUNT_LIST]
\\ simp[COUNT_LIST_def]
QED
Theorem index_list_eq_ZIP:
index_list xs k = ZIP(REVERSE(MAP($+ k)(COUNT_LIST (LENGTH xs))),xs)
Proof
metis_tac[MAP_FST_index_list,MAP_SND_index_list,ZIP_MAP_FST_SND_EQ]
QED
Theorem IMP_filter_bitmap_EQ_SOME_NIL:
!xs ys zs.
(LENGTH xs = LENGTH ys) /\
zs = MAP FST (FILTER SND (ZIP (ys, xs))) ==>
(filter_bitmap xs ys = SOME (zs,[]))
Proof
Induct \\ Cases_on `ys` \\ fs [filter_bitmap_def]
\\ Cases \\ fs [filter_bitmap_def]
QED
Theorem filter_bitmap_length:
∀bs ls xs ys.
filter_bitmap bs ls = SOME(xs,ys) ⇒
LENGTH xs ≤ LENGTH bs
Proof
ho_match_mp_tac filter_bitmap_ind>>fs[filter_bitmap_def]>>rw[]>>
EVERY_CASE_TAC>>rveq>>fs[]>>res_tac>>
rveq>>fs[]>>DECIDE_TAC
QED
Theorem filter_bitmap_length_input:
∀xs ys ls. filter_bitmap xs ys = SOME ls ⇒ LENGTH xs ≤ LENGTH ys
Proof
ho_match_mp_tac filter_bitmap_ind
\\ simp[filter_bitmap_def,LENGTH_NIL_SYM]
\\ rw[]
\\ every_case_tac \\ fs[]
QED
Theorem filter_bitmap_MAP_IMP:
∀ys xs l.
filter_bitmap ys (MAP SND xs) = SOME (MAP SND l,[]) ∧
filter_bitmap ys (MAP FST xs) = SOME (MAP FST l,[])
⇒
filter_bitmap ys xs = SOME (l,[])
Proof
Induct \\ Cases_on`xs` \\ fs[filter_bitmap_def]
\\ Cases \\ fs[filter_bitmap_def] \\ rpt strip_tac
\\ every_case_tac \\ fs[] \\ rw[]
\\ Cases_on`l` \\ fs[]
\\ rveq
\\ first_x_assum drule
\\ impl_tac >- metis_tac[]
\\ simp[]
\\ rw[]
\\ metis_tac[PAIR]
QED
Theorem filter_bitmap_IMP_MAP_SND:
!ys xs l.
filter_bitmap ys xs = SOME (l,[]) ==>
filter_bitmap ys (MAP SND xs) = SOME (MAP SND l,[])
Proof
Induct \\ Cases_on `xs` \\ fs [filter_bitmap_def]
\\ Cases \\ fs [filter_bitmap_def] \\ rpt strip_tac
\\ EVERY_CASE_TAC \\ fs [] \\ rw []
\\ res_tac \\ fs []
QED
Theorem filter_bitmap_IMP_MAP_FST:
!ys xs l.
filter_bitmap ys xs = SOME (l,[]) ==>
filter_bitmap ys (MAP FST xs) = SOME (MAP FST l,[])
Proof
Induct \\ Cases_on `xs` \\ fs [filter_bitmap_def]
\\ Cases \\ fs [filter_bitmap_def] \\ rpt strip_tac
\\ EVERY_CASE_TAC \\ fs [] \\ rw []
\\ res_tac \\ fs []
QED
Theorem filter_bitmap_TAKE_LENGTH_IMP:
!h5 x4 l.
filter_bitmap h5 (TAKE (LENGTH h5) x4) = SOME (MAP SND l,[]) ==>
filter_bitmap h5 x4 = SOME (MAP SND l,DROP (LENGTH h5) x4)
Proof
Induct \\ Cases_on `x4` \\ fs [filter_bitmap_def]
\\ Cases \\ fs [filter_bitmap_def] \\ rpt strip_tac
\\ EVERY_CASE_TAC \\ fs [] \\ rw []
\\ Cases_on `l` \\ fs [] \\ rw [] \\ res_tac \\ fs []
QED
Theorem filter_bitmap_lemma:
filter_bitmap h5 (index_list (TAKE (LENGTH h5) x4) k) = SOME (l,[]) ==>
filter_bitmap h5 x4 = SOME (MAP SND l, DROP (LENGTH h5) x4)
Proof
rpt strip_tac \\ imp_res_tac filter_bitmap_IMP_MAP_SND
\\ fs [MAP_SND_index_list] \\ imp_res_tac filter_bitmap_TAKE_LENGTH_IMP
QED
Theorem filter_bitmap_MEM:
∀b ls ls' x.
filter_bitmap b ls = SOME (ls',[]) ∧
MEM x ls' ⇒ MEM x ls
Proof
ho_match_mp_tac filter_bitmap_ind>>
rw[filter_bitmap_def]>>
EVERY_CASE_TAC>>fs[]>>rveq>>
fs[MEM]
QED
Theorem get_var_set_var[simp]:
stackSem$get_var k (set_var k v st) = SOME v
Proof
fs[stackSemTheory.get_var_def,stackSemTheory.set_var_def]>>
fs[FLOOKUP_UPDATE]
QED
Triviality MEM_TAKE:
!xs n x. MEM x (TAKE n xs) ==> MEM x xs
Proof
Induct \\ fs [TAKE_def] \\ rw [] \\ res_tac \\ fs []
QED
Triviality MEM_LASTN_ALT:
!xs n x. MEM x (LASTN n xs) ==> MEM x xs
Proof
fs [LASTN_def] \\ rw [] \\ imp_res_tac MEM_TAKE \\ fs []
QED
Theorem clock_add_0[simp]:
((t with clock := t.clock + 0) = t:('a,'c,'ffi) stackSem$state) /\
((t with clock := t.clock) = t:('a,'c,'ffi) stackSem$state)
Proof
fs [stackSemTheory.state_component_equality]
QED
Theorem DROP_DROP_EQ:
!n m xs. DROP m (DROP n xs) = DROP (m + n) xs
Proof
Induct \\ fs [] \\ Cases_on `xs` \\ fs []
\\ rpt strip_tac \\ rpt (AP_TERM_TAC ORELSE AP_THM_TAC) \\ decide_tac
QED
Triviality TAKE_TAKE_MIN:
!xs m n. TAKE n (TAKE m xs) = TAKE (MIN m n) xs
Proof
Induct \\ Cases_on `m` \\ Cases_on `n` \\ fs [MIN_DEF]
\\ rw [] \\ fs [] \\ Cases_on`n` \\ fs[]
QED
Triviality TAKE_DROP_EQ:
!xs n m. TAKE m (DROP n xs) = DROP n (TAKE (m + n) xs)
Proof
Induct \\ fs [] \\ rw [] \\ fs [] \\ Cases_on`n` \\ fs[]
\\ rpt (AP_TERM_TAC ORELSE AP_THM_TAC) \\ decide_tac
QED
Triviality DROP_TAKE_NIL:
DROP n (TAKE n xs) = []
Proof
rw[DROP_NIL,LENGTH_TAKE_EQ]
QED
Theorem TAKE_LUPDATE[simp]:
!xs n x i. TAKE n (LUPDATE x i xs) = LUPDATE x i (TAKE n xs)
Proof
Induct \\ fs [LUPDATE_def] \\ Cases_on `i` \\ fs [LUPDATE_def] \\ rw [LUPDATE_def]
>-
(Cases_on`n`>>fs[LUPDATE_def])
>>
Cases_on`n'`>>fs[LUPDATE_def]
QED
local
val DROP_LUPDATE_lemma1 = Q.prove(
`!xs n m h. n <= m ==>
DROP n (LUPDATE h m xs) = LUPDATE h (m - n) (DROP n xs)`,
Induct \\ fs [LUPDATE_def] \\ rw []
\\ Cases_on `m` \\ fs [LUPDATE_def]
\\ qmatch_assum_rename_tac `n <= SUC i`
\\ Cases_on`n`>>fs[LUPDATE_def])
val DROP_LUPDATE_lemma2 = Q.prove(
`!xs n m h. m < n ==> DROP n (LUPDATE h m xs) = DROP n xs`,
Induct \\ fs [LUPDATE_def] \\ rw []
\\ Cases_on `m` \\ fs [LUPDATE_def])
in
Theorem DROP_LUPDATE:
!n h m xs.
DROP n (LUPDATE h m xs) =
if m < n then DROP n xs else LUPDATE h (m - n) (DROP n xs)
Proof
rw [DROP_LUPDATE_lemma2]
\\ match_mp_tac DROP_LUPDATE_lemma1
\\ fs [NOT_LESS]
QED
end
Triviality MIN_ADD:
MIN m1 m2 + n = MIN (m1 + n) (m2 + n)
Proof
fs [MIN_DEF] \\ decide_tac
QED
Definition list_LUPDATE_def:
(list_LUPDATE [] n ys = ys) /\
(list_LUPDATE (x::xs) n ys = list_LUPDATE xs (n+1) (LUPDATE x n ys))
End
Theorem LENGTH_list_LUPDATE[simp]:
!xs n ys. LENGTH (list_LUPDATE xs n ys) = LENGTH ys
Proof
Induct \\ fs [list_LUPDATE_def]
QED
Theorem TAKE_list_LUPDATE[simp]:
!ys xs n i. TAKE n (list_LUPDATE ys i xs) = list_LUPDATE ys i (TAKE n xs)
Proof
Induct \\ fs [list_LUPDATE_def]
QED
Triviality LLOOKUP_list_LUPDATE_IGNORE:
!xs i n ys.
i + LENGTH xs <= n ==>
LLOOKUP (list_LUPDATE xs i ys) n = LLOOKUP ys n
Proof
Induct \\ fs [list_LUPDATE_def] \\ rpt strip_tac
\\ `(i+1) + LENGTH xs <= n` by decide_tac \\ res_tac
\\ `i <> n` by decide_tac \\ fs [LLOOKUP_LUPDATE]
QED
Triviality DROP_list_LUPDATE:
!ys n m xs.
n <= m ==>
DROP n (list_LUPDATE ys m xs) =
list_LUPDATE ys (m - n) (DROP n xs)
Proof
Induct
\\ fs [list_LUPDATE_def,LENGTH_NIL,PULL_FORALL]
\\ rpt strip_tac \\ `n <= m + 1` by decide_tac
\\ rw [] \\ `m + 1 - n = m - n + 1 /\ ~(m < n)` by decide_tac
\\ fs [DROP_LUPDATE]
QED
Triviality DROP_list_LUPDATE_IGNORE:
!xs i ys n.
LENGTH xs + i <= n ==>
DROP n (list_LUPDATE xs i ys) = DROP n ys
Proof
Induct \\ fs [list_LUPDATE_def] \\ rpt strip_tac
\\ `LENGTH xs + (i+1) <= n /\ i < n` by decide_tac
\\ fs [DROP_LUPDATE]
QED
Theorem list_LUPDATE_NIL[simp]:
!xs i. list_LUPDATE xs i [] = []
Proof
Induct \\ fs [list_LUPDATE_def,LUPDATE_def]
QED
Triviality LUPDATE_TAKE_LEMMA:
!xs n w. LUPDATE w n xs = TAKE n xs ++ LUPDATE w 0 (DROP n xs)
Proof
Induct \\ Cases_on `n` \\ fs [LUPDATE_def]
QED
Theorem list_LUPDATE_TAKE_DROP:
!xs (ys:'a list) n.
list_LUPDATE xs n ys = TAKE n ys ++ list_LUPDATE xs 0 (DROP n ys)
Proof
Induct \\ simp_tac std_ss [Once list_LUPDATE_def]
\\ once_rewrite_tac [list_LUPDATE_def] THEN1 fs []
\\ pop_assum (fn th => once_rewrite_tac [th])
\\ fs [DROP_LUPDATE,DROP_DROP_EQ,AC ADD_COMM ADD_ASSOC]
\\ simp_tac std_ss [Once LUPDATE_TAKE_LEMMA,TAKE_TAKE_MIN] \\ rpt strip_tac
\\ `MIN (n + 1) n = n` by (fs [MIN_DEF] \\ decide_tac) \\ fs []
\\ AP_TERM_TAC \\ fs [TAKE_DROP_EQ,AC ADD_COMM ADD_ASSOC]
QED
Theorem list_LUPDATE_0_CONS[simp]:
!xs x ys y. list_LUPDATE (x::xs) 0 (y::ys) = x :: list_LUPDATE xs 0 ys
Proof
fs [list_LUPDATE_def,LUPDATE_def]
\\ simp_tac std_ss [Once list_LUPDATE_TAKE_DROP] \\ fs []
QED
Theorem list_LUPDATE_APPEND:
!xs ys zs.
LENGTH xs = LENGTH ys ==> (list_LUPDATE xs 0 (ys ++ zs) = xs ++ zs)
Proof
Induct \\ Cases_on `ys` \\ fs [list_LUPDATE_def]
QED
(* move to stackProps? *)
Triviality DIV_ADD_1:
0 < d ==> (m DIV d + 1 = (m + d) DIV d)
Proof
rpt strip_tac
\\ ASSUME_TAC (ADD_DIV_ADD_DIV |> Q.SPECL [`d`] |> UNDISCH
|> Q.SPECL [`1`,`m`] |> ONCE_REWRITE_RULE [ADD_COMM]) \\ fs []
QED
Triviality LENGTH_word_list_lemma:
!xs d. 0 < d ==> (LENGTH (word_list xs d) = (LENGTH xs - 1) DIV d + 1)
Proof
recInduct word_list_ind
\\ rpt strip_tac \\ fsrw_tac[] []
\\ once_rewrite_tac [word_list_def] \\ fsrw_tac[] [] \\ rw []
\\ imp_res_tac ZERO_DIV \\ fsrw_tac[] [] \\ res_tac
\\ imp_res_tac LESS_DIV_EQ_ZERO \\ fsrw_tac[] []
\\ fsrw_tac[] [ADD1] \\ fsrw_tac[] [NOT_LESS]
\\ imp_res_tac (ONCE_REWRITE_RULE [ADD_COMM] LESS_EQ_EXISTS)
THEN1 (`LENGTH xs - 1 < d` by decide_tac
\\ imp_res_tac LESS_DIV_EQ_ZERO \\ fsrw_tac[] [])
\\ imp_res_tac DIV_ADD_1 \\ fsrw_tac[] []
\\ AP_THM_TAC \\ AP_TERM_TAC \\ decide_tac
QED
Theorem LENGTH_word_list:
!xs d. LENGTH (word_list xs d) =
if d = 0 then 1 else (LENGTH xs - 1) DIV d + 1
Proof
rw [] THEN1 (once_rewrite_tac [word_list_def] \\ fs [])
\\ match_mp_tac LENGTH_word_list_lemma \\ decide_tac
QED
(* move to wordProps? *)
Triviality list_rearrange_I:
(list_rearrange I = I)
Proof
fs [list_rearrange_def,FUN_EQ_THM]
\\ fs [BIJ_DEF,INJ_DEF,SURJ_DEF,GENLIST_ID]
QED
(* state relation *)
(*Abstracts a stackLang stack w.r.t. wordLang's
Note: requires assumption on dimindex(:'a) stated in state_rel
TODO: The length checks may be inconvenient for handler frames
*)
Definition abs_stack_def:
(abs_stack (bitmaps:'a word list) [] stack [] =
if stack = [Word (0w:'a word)] then SOME [] else NONE) ∧
(abs_stack bitmaps ((StackFrame n l NONE)::xs) (w::stack) (len::lens) =
(*Should cover the stack = [] case automatically*)
case full_read_bitmap bitmaps w of
| NONE => NONE
(*read_bitmap reads a bitmap and returns the liveness bits,
the words read and the rest of the stack*)
| SOME bits =>
if LENGTH bits ≠ len then NONE else
if LENGTH stack < len then NONE else
(* if the (len + 1) n ≠ len + 1 then NONE else*)
let frame = TAKE len stack in
let rest = DROP len stack in
case abs_stack bitmaps xs rest lens of
| NONE => NONE
| SOME ys => SOME ((NONE,bits,frame)::ys)) ∧
(abs_stack bitmaps ((StackFrame n l (SOME _))::xs) (w::stack) (len::lens) =
(*Index for bitmap for a handler frame*)
if w ≠ Word 1w then NONE
else
(case stack of
(*Read next 2 elements on the stack for the handler*)
| loc::hv::w::stack =>
(case full_read_bitmap bitmaps w of
| NONE => NONE
(*read_bitmap reads a bitmap and returns the liveness bits,
the words read and the rest of the stack*)
| SOME bits =>
if LENGTH bits ≠ len then NONE else
if LENGTH stack < len then NONE else
(* if the (len + 1) n ≠ len + 1 then NONE else*)
let frame = TAKE len stack in
let rest = DROP len stack in
case abs_stack bitmaps xs rest lens of
| NONE => NONE
| SOME ys => SOME ((SOME(loc,hv),bits,frame)::ys))
| _ => NONE)) ∧
(abs_stack bitmaps _ _ _ = NONE)
End
val abs_stack_ind = theorem"abs_stack_ind";
Theorem read_bitmap_append_extra:
∀l1 l2 bits.
read_bitmap l1 = SOME bits ⇒
read_bitmap (l1 ++ l2) = SOME bits
Proof
Induct >> simp[read_bitmap_def]
\\ rpt gen_tac
\\ IF_CASES_TAC \\ simp[]
\\ BasicProvers.CASE_TAC >> simp[]
\\ BasicProvers.CASE_TAC >> simp[]
\\ fs[] \\ rfs[]
QED
Theorem full_read_bitmap_append:
∀bitmaps w bits more_bitmaps.
full_read_bitmap bitmaps w = SOME bits ⇒
full_read_bitmap (bitmaps ++ more_bitmaps) w = SOME bits
Proof
recInduct full_read_bitmap_ind
\\ rw[full_read_bitmap_def]
\\ rw[DROP_APPEND]
\\ metis_tac[read_bitmap_append_extra]
QED
Theorem abs_stack_bitmaps_prefix:
∀bitmaps frames stack lens more_bitmaps result.
abs_stack bitmaps frames stack lens = SOME result ⇒
abs_stack (bitmaps ++ more_bitmaps) frames stack lens = SOME result
Proof
recInduct abs_stack_ind
\\ rw[abs_stack_def]
\\ fs[case_eq_thms]
\\ rveq
\\ imp_res_tac full_read_bitmap_append
\\ simp[]
QED
Definition MAP_FST_def:
MAP_FST f xs = MAP (\(x,y). (f x, y)) xs
End
Definition adjust_names_def:
adjust_names n = n DIV 2
End
(*handler_val counts the total number of words in the list of frames*)
Definition handler_val_def:
(handler_val [] = 1n) ∧
(handler_val ((NONE,_,frame)::stack) =
1+LENGTH frame+handler_val stack) ∧
(handler_val ((SOME _,_,frame)::stack) =
(* 1 for handler bitmaps pointer
+ 2 more for the pointer and locs
+ 1 for the next bitmap pointer
*)
4+LENGTH frame+handler_val stack)
End
(*TODO: Maybe switch to this alternative index_list that goes from
stackLang vars to wordLang vars more directly*)
(*
Definition index_list_def:
(index_list [] k = []) /\
(index_list (x::xs) k = (2*(k+LENGTH xs),x) :: index_list xs k)
End
*)
Definition is_handler_frame_def:
(is_handler_frame (StackFrame n l NONE) = F) ∧
(is_handler_frame _ = T)
End
(*Checks for consistency of the values*)
Definition stack_rel_aux_def:
(stack_rel_aux k len [] [] ⇔ T) ∧
(stack_rel_aux k len ((StackFrame n l NONE)::xs) ((NONE,bits,frame)::stack) ⇔
filter_bitmap bits (index_list frame k) = SOME (MAP_FST adjust_names l,[]) ∧
the (LENGTH frame + 1) n = LENGTH frame + 1 ∧
stack_rel_aux k len xs stack) ∧
(stack_rel_aux k len ((StackFrame n l (SOME (h1,l1,l2)))::xs) ((SOME(loc,hv),bits,frame)::stack) ⇔
(h1 < LENGTH stack ∧
is_handler_frame (EL (LENGTH stack - (h1+1)) xs) ⇒
hv = Word (n2w (len - handler_val (LASTN (h1+1) stack)))) ∧
loc = Loc l1 l2 ∧
filter_bitmap bits (index_list frame k) = SOME (MAP_FST adjust_names l,[]) ∧
the (LENGTH frame + 1) n = LENGTH frame + 1 ∧
stack_rel_aux k len xs stack) ∧
(stack_rel_aux k len _ _ = F)
End
Definition sorted_env_def:
sorted_env (StackFrame n l _) = SORTED (\x y. FST x > FST y) l
End
Definition stack_rel_def:
stack_rel k s_handler s_stack t_handler t_rest_of_stack t_stack_length t_bitmaps lens <=>
EVERY sorted_env s_stack /\
∃stack.
abs_stack t_bitmaps s_stack t_rest_of_stack lens = SOME stack ∧
(s_handler < LENGTH s_stack ∧
is_handler_frame (EL (LENGTH s_stack - (s_handler+1)) s_stack)
⇒
t_handler = SOME(Word (n2w (t_stack_length - handler_val (LASTN (s_handler+1) stack))))) ∧
stack_rel_aux k t_stack_length s_stack stack
End
(*f is the size of the current frame + 1 most of the time
(extra word for the bitmap pointer)
f' is the size of the current frame
lens tracks the size of each remaining stack frame on the stackLang stack
*)
Definition state_rel_def:
state_rel ac k f f' (s:('a,num # 'c,'ffi) wordSem$state) (t:('a,'c,'ffi) stackSem$state) lens ⇔
(s.clock = t.clock) /\ (s.gc_fun = t.gc_fun) /\ (s.permute = K I) /\
(t.ffi = s.ffi) /\ t.use_stack /\ t.use_store /\ t.use_alloc /\
(t.memory = s.memory) /\ (t.mdomain = s.mdomain) /\ 4 < k /\
(t.sh_mdomain = s.sh_mdomain) /\
(s.store = t.store \\ Handler) /\ gc_fun_ok t.gc_fun /\ s.termdep = 0 /\
t.be = s.be /\ t.ffi = s.ffi /\ Handler ∈ FDOM t.store ∧
t.fp_regs = s.fp_regs ∧
t.data_buffer = s.data_buffer ∧
t.code_buffer = s.code_buffer ∧
s.compile = (λ(bm0,cfg) progs.
let (progs,fs,bm) = word_to_stack$compile_word_to_stack ac k progs (Nil, bm0) in
OPTION_MAP (λ(bytes,cfg). (bytes,append (FST bm),(SND bm,cfg)))
(t.compile cfg progs)) ∧
t.compile_oracle = (λn.
let ((bm0,cfg),progs) = s.compile_oracle n in
let (progs,fs,bm) = word_to_stack$compile_word_to_stack ac k progs (Nil, bm0) in
(cfg,progs,append (FST bm))) ∧
(∀n. let ((bm0,cfg),progs) = s.compile_oracle n in
EVERY (post_alloc_conventions k o SND o SND) progs ∧
EVERY (flat_exp_conventions o SND o SND) progs ∧
EVERY ((<>) raise_stub_location o FST) progs ∧
EVERY ((<>) store_consts_stub_location o FST) progs ∧
(n = 0 ⇒ bm0 = LENGTH t.bitmaps)) ∧
domain t.code = raise_stub_location INSERT
store_consts_stub_location INSERT domain s.code ∧
(!n word_prog arg_count.
(lookup n s.code = SOME (arg_count,word_prog)) ==>
post_alloc_conventions k word_prog /\
flat_exp_conventions word_prog /\
?bs i bs2 i2 f stack_prog.
word_to_stack$compile_prog ac word_prog arg_count k (bs,i) = (stack_prog,f,(bs2,i2)) /\
LENGTH (append bs) ≤ i ∧ i - LENGTH (append bs) ≤ LENGTH t.bitmaps /\
isPREFIX (append bs2) (DROP (i - LENGTH (append bs)) t.bitmaps) /\
(lookup n t.code = SOME stack_prog) /\
the f (lookup n s.stack_size) = f
) /\
(lookup raise_stub_location t.code = SOME (raise_stub k)) /\
(lookup store_consts_stub_location t.code = SOME (store_consts_stub k)) /\
good_dimindex (:'a) /\ 8 <= dimindex (:'a) /\
LENGTH t.bitmaps + LENGTH s.data_buffer.buffer + s.data_buffer.space_left +1 < dimword (:α) /\
1 ≤ LENGTH t.bitmaps ∧ HD t.bitmaps = 4w ∧
t.stack_space + f <= LENGTH t.stack /\ LENGTH t.stack < dimword (:'a) /\
(if f' = 0 then f = 0 else (f = f' + 1)) /\
wf s.locals /\
(* Stack size as predicted by the wordLang state is a conservative estimate of the
actual stack usage. *)
(f <> 0 ==> the f s.locals_size = f) /\
s.stack_limit = LENGTH t.stack /\
LENGTH t.stack - t.stack_space - f <= the (LENGTH t.stack - t.stack_space - f) s.stack_max /\
(IS_SOME s.stack_max ==> IS_SOME (stack_size s.stack)) /\
(IS_SOME s.stack_max ==> IS_SOME s.locals_size) /\
(IS_SOME s.stack_max ==> the (LENGTH t.stack - t.stack_space - f) (stack_size s.stack) = LENGTH t.stack - t.stack_space - f) /\
let stack = DROP t.stack_space t.stack in
(*First f things on stack are the live stack vars*)
let current_frame = TAKE f stack in
let rest_of_stack = DROP f stack in
stack_rel k s.handler s.stack (FLOOKUP t.store Handler)
rest_of_stack (LENGTH t.stack) t.bitmaps lens /\
(!n v.
(lookup n s.locals = SOME v) ==>
EVEN n /\
if n DIV 2 < k then (FLOOKUP t.regs (n DIV 2) = SOME v)
else (LLOOKUP current_frame (f-1 -(n DIV 2 - k)) = SOME v) /\
n DIV 2 < k + f')
End
(* correctness proof *)
Triviality evaluate_SeqStackFree:
t.use_stack /\ t.stack_space <= LENGTH t.stack ==>
evaluate (SeqStackFree f p,t) =
evaluate (Seq (StackFree f) p,t)
Proof
fsrw_tac[] [SeqStackFree_def] \\ srw_tac[] [stackSemTheory.evaluate_def]
THEN1 (`F` by decide_tac) \\ AP_TERM_TAC
\\ fs [stackSemTheory.state_component_equality]
QED
val convs_def = LIST_CONJ
[wordConvsTheory.post_alloc_conventions_def,
wordConvsTheory.call_arg_convention_def,
wordConvsTheory.flat_exp_conventions_def,
wordLangTheory.every_var_def,
wordLangTheory.every_var_imm_def,
wordLangTheory.every_stack_var_def,
wordLangTheory.every_name_def]
val nn = ``(NONE:(num # 'a wordLang$prog # num # num) option)``
(*
Triviality LENGTH_write_bitmap:
state_rel ac k f f' (s:('a,'ffi) wordSem$state) t /\ 1 <= f ==>
(LENGTH ((write_bitmap (names:num_set) k f'):'a word list) + f' = f)
Proof
fs [state_rel_def,write_bitmap_def,LET_DEF]
\\ fs [LENGTH_word_list] \\ rpt strip_tac
\\ `~(dimindex (:'a) <= 1) /\ f <> 0` by decide_tac \\ fs []
\\ decide_tac
QED
*)
val DROP_list_LUPDATE_lemma =
MATCH_MP DROP_list_LUPDATE (SPEC_ALL LESS_EQ_REFL) |> SIMP_RULE std_ss []
Triviality bits_to_word_bit:
!bs i.
i < dimindex (:'a) /\ i < LENGTH bs ==>
((bits_to_word bs:'a word) ' i = EL i bs)
Proof
Induct \\ fs [] \\ Cases_on `i` \\ fs []
\\ Cases \\ fs [bits_to_word_def,word_or_def,fcpTheory.FCP_BETA,
word_index,word_lsl_def,ADD1] \\ rpt strip_tac
\\ first_x_assum match_mp_tac \\ fs [] \\ decide_tac
QED
Triviality bits_to_word_miss:
!bs i.
i < dimindex (:'a) /\ LENGTH bs <= i ==>
~((bits_to_word bs:'a word) ' i)
Proof
Induct \\ fs [] THEN1 (EVAL_TAC \\ fs [word_0])
\\ Cases_on `i` \\ fs [] \\ NTAC 2 strip_tac
\\ `n < dimindex (:'a)` by decide_tac \\ res_tac
\\ Cases_on `h` \\ fs [bits_to_word_def,word_or_def,fcpTheory.FCP_BETA,
word_index,word_lsl_def,ADD1]
QED
Triviality bits_to_word_NOT_0:
!bs. LENGTH bs <= dimindex (:'a) /\ EXISTS I bs ==>
(bits_to_word bs <> 0w:'a word)
Proof
fs [fcpTheory.CART_EQ] \\ rpt strip_tac
\\ fs [EXISTS_MEM,MEM_EL]
\\ Q.EXISTS_TAC `n` \\ fs []
\\ `n < dimindex (:'a)` by decide_tac \\ fs [word_0]
\\ fs [bits_to_word_bit]
QED
Triviality list_LUPDATE_write_bitmap_NOT_NIL:
8 <= dimindex (:'a) ==>
(list_LUPDATE (MAP Word (write_bitmap names k f')) 0 xs <>
[Word (0w:'a word)])
Proof
Cases_on `xs` \\ fs [list_LUPDATE_NIL]
\\ fs [write_bitmap_def,LET_DEF,Once word_list_def]
\\ strip_tac \\ `~(dimindex (:'a) <= 1)` by decide_tac \\ fs []
\\ rw [] \\ rpt disj1_tac
\\ match_mp_tac bits_to_word_NOT_0 \\ fs [LENGTH_TAKE_EQ]
\\ fs [MIN_LE,MIN_ADD] \\ decide_tac
QED
Triviality word_or_eq_0:
((w || v) = 0w) <=> (w = 0w) /\ (v = 0w)
Proof
srw_tac [wordsLib.WORD_BIT_EQ_ss] []
\\ metis_tac []
QED
Triviality shift_shift_lemma:
~(word_msb w) ==> (w ≪ 1 ⋙ 1 = w)
Proof
srw_tac [wordsLib.WORD_BIT_EQ_ss] []
\\ Cases_on `i + 1 < dimindex (:α)`
\\ full_simp_tac (srw_ss()++wordsLib.WORD_BIT_EQ_ss) [NOT_LESS]
\\ `i = dimindex (:'a) - 1` by decide_tac
\\ simp []
QED
Triviality bit_length_bits_to_word:
!qs.
LENGTH qs + 1 < dimindex (:'a) ==>
bit_length (bits_to_word (qs ++ [T]):'a word) = LENGTH qs + 1
Proof
Induct THEN1
(fs [] \\ fs [Once bit_length_def] \\ fs [Once bit_length_def]
\\ fs [bits_to_word_def] \\ EVAL_TAC)
\\ Cases \\ fs [bits_to_word_def]
\\ once_rewrite_tac [bit_length_def]
\\ fs [ADD_CLAUSES]
\\ rpt strip_tac \\ fs [EVAL ``1w >>> 1``]
\\ `(LENGTH qs + 1) < dimindex (:'a)` by decide_tac \\ fs []
\\ `bits_to_word (qs ++ [T]) << 1 <> 0w` by
(fs [fcpTheory.CART_EQ,word_or_def,fcpTheory.FCP_BETA,word_0,word_lsl_def]
\\ Q.EXISTS_TAC `LENGTH qs + 1`
\\ fs [fcpTheory.CART_EQ,word_or_def,fcpTheory.FCP_BETA]
\\ (bits_to_word_bit |> SPEC_ALL |> DISCH ``EL i (bs:bool list)``
|> SIMP_RULE std_ss [] |> MP_CANON |> match_mp_tac) \\ fs []
\\ fs [EL_LENGTH_APPEND] \\ decide_tac)
\\ `bits_to_word (qs ++ [T]) ≪ 1 ⋙ 1 =
bits_to_word (qs ++ [T]):'a word` by
(match_mp_tac shift_shift_lemma \\ fs [word_msb_def]
\\ match_mp_tac bits_to_word_miss \\ fs [] \\ decide_tac)
\\ fs [ADD1,word_or_eq_0]
QED
Triviality GENLIST_bits_to_word_alt:
LENGTH (xs ++ ys) <= dimindex (:'a) ==>
GENLIST (\i. (bits_to_word (xs ++ ys):'a word) ' i) (LENGTH xs) = xs
Proof
fs [LIST_EQ_REWRITE] \\ rpt strip_tac
\\ `EL x xs = EL x (xs ++ ys)` by fs [EL_APPEND1]
\\ pop_assum (fn th => once_rewrite_tac [th])
\\ match_mp_tac bits_to_word_bit
\\ fs [] \\ decide_tac
QED
Triviality GENLIST_bits_to_word:
LENGTH qs' + 1 < dimindex (:'a) ==>
GENLIST (\i. (bits_to_word (qs' ++ [T]):'a word) ' i) (LENGTH qs') = qs'
Proof
rpt strip_tac \\ match_mp_tac GENLIST_bits_to_word_alt
\\ fs [] \\ decide_tac
QED
Triviality read_bitmap_word_list:
8 <= dimindex (:'a) ==>
read_bitmap
((word_list (qs ++ [T]) (dimindex (:'a) - 1)) ++ (xs:'a word list)) =
SOME qs
Proof
completeInduct_on `LENGTH (qs:bool list)` \\ rpt strip_tac \\ fs [PULL_FORALL]
\\ rw [] \\ once_rewrite_tac [word_list_def]
\\ `dimindex (:'a) - 1 <> 0` by decide_tac \\ fs []
\\ Cases_on `LENGTH qs + 1 <= dimindex (:'a) - 1` \\ fs []
THEN1
(fs [read_bitmap_def]
\\ `~word_msb (bits_to_word (qs ++ [T]))` by
(fs [word_msb_def] \\ match_mp_tac bits_to_word_miss
\\ fs [] \\ decide_tac) \\ fs []
\\ `LENGTH qs + 1 < dimindex (:'a)` by decide_tac
\\ fs [bit_length_bits_to_word,GENLIST_bits_to_word])
\\ fs [read_bitmap_def]
\\ `dimindex (:'a) - 1 =
LENGTH (TAKE (dimindex (:'a) - 1) (qs ++ [T]))` by
(fs [LENGTH_TAKE_EQ,MIN_DEF] \\ decide_tac)
\\ `word_msb (bits_to_word (TAKE (dimindex (:'a) - 1)
(qs ++ [T]) ++ [T]) :'a word)` by
(fsrw_tac[] [word_msb_def]
\\ (bits_to_word_bit |> SPEC_ALL |> DISCH ``EL i (bs:bool list)``
|> SIMP_RULE std_ss [] |> MP_CANON |> match_mp_tac) \\ fsrw_tac[] []
\\ reverse (rpt strip_tac) THEN1 decide_tac THEN1 decide_tac
\\ pop_assum (fn th => simp_tac std_ss [Once th])
\\ fsrw_tac[] [EL_LENGTH_APPEND]) \\ fs []
\\ `DROP (dimindex (:'a) - 1) (qs ++ [T]) =
DROP (dimindex (:'a) - 1) qs ++ [T]` by
(match_mp_tac DROP_APPEND1 \\ fs [NOT_LESS] \\ decide_tac)
\\ `TAKE (dimindex (:'a) - 1) (qs ++ [T]) =
TAKE (dimindex (:'a) - 1) qs` by
(match_mp_tac TAKE_APPEND1 \\ fs [NOT_LESS] \\ decide_tac) \\ fs []
\\ first_x_assum (mp_tac o Q.SPEC `DROP (dimindex (:'a) - 1) qs`)
\\ match_mp_tac IMP_IMP \\ strip_tac
THEN1 (fs [LENGTH_DROP] \\ decide_tac)
\\ rpt strip_tac \\ fs []
\\ CONV_TAC (RAND_CONV (ONCE_REWRITE_CONV
[GSYM (Q.SPEC `dimindex (:'a) - 1`
(INST_TYPE [``:'a``|->``:bool``] TAKE_DROP))]))
\\ AP_THM_TAC \\ AP_TERM_TAC
\\ Q.ABBREV_TAC `ts = TAKE (dimindex (:'a) - 1) qs` \\ fs []
\\ match_mp_tac GENLIST_bits_to_word_alt \\ fs []
\\ decide_tac
QED
Triviality APPEND_LEMMA:
n1 + n2 + n3 <= LENGTH xs ==>
?xs2 xs3. (DROP n1 xs = xs2 ++ xs3) /\ n2 = LENGTH xs2
Proof
rpt strip_tac
\\ `n1 <= LENGTH xs` by decide_tac
\\ Q.PAT_X_ASSUM `n1 + n2 + n3 <= LENGTH xs` MP_TAC
\\ imp_res_tac LESS_EQ_LENGTH
\\ rw [DROP_LENGTH_APPEND] \\ fs []
\\ rename [‘n2 + (n3 + LENGTH xs1) ≤ LENGTH xs1 + LENGTH xs2’]
\\ `n2 <= LENGTH xs2` by decide_tac
\\ imp_res_tac LESS_EQ_LENGTH
\\ rw [] \\ metis_tac []
QED
Theorem read_bitmap_write_bitmap:
8 ≤ dimindex (:α) ⇒
read_bitmap ((write_bitmap names k f'):α word list) =
SOME (GENLIST (λx. MEM x (MAP (λ(r,y). f' - 1 - (r DIV 2 - k)) (toAList names))) f')
Proof
rw[write_bitmap_def]
\\ imp_res_tac read_bitmap_word_list
\\ first_x_assum(qspec_then`[]`mp_tac)
\\ simp[]
QED
Theorem read_bitmap_insert_bitmap:
∀bs n bs' n' i cur.
i < dimword (:α) ∧
IS_SOME (read_bitmap bm) ∧
n = LENGTH cur + LENGTH (append bs) ∧
insert_bitmap bm (bs, n) = ((bs',n'),i)
⇒ read_bitmap (DROP (i MOD dimword (:α)) (cur++append bs')) = read_bitmap bm
Proof
simp[insert_bitmap_def] \\ rw[] \\ simp[DROP_LENGTH_APPEND]>>
metis_tac[DROP_LENGTH_APPEND,LENGTH_APPEND]
QED
(*
TODO
Theorem insert_bitmap_length:
∀ls n ls' n' i.
insert_bitmap bm (ls,n) = ((ls',n'),i) ∧
n ≤ LENGTH (append ls) ⇒
i ≤ LENGTH (append ls) ∧ LENGTH (append ls) ≤ LENGTH (append ls')
Proof
simp[insert_bitmap_def]
QED
*)
(*
val read_bitmap_write_bitmap = Q.prove(
`t.stack_space + f <= LENGTH t.stack /\ 8 <= dimindex (:'a) /\
(LENGTH (write_bitmap names k f': 'a word list) + f' = f) /\
(if f' = 0 then f = 0 else f = f' + f' DIV (dimindex (:'a) - 1) + 1) /\
(1 <= f) ==>
read_bitmap
(list_LUPDATE (MAP Word (write_bitmap (names:num_set) k f')) 0
(DROP t.stack_space t.stack)) =
SOME (GENLIST (\x. MEM x (MAP (\(r,y). (f'-1) - (r DIV 2 - k)) (toAList names))) f',
MAP Word (write_bitmap names k f'): 'a word_loc list,
(DROP (f - f') (DROP t.stack_space t.stack)))`,
fs [write_bitmap_def,LET_DEF]
\\ Q.ABBREV_TAC `qs = GENLIST
(\x. MEM x (MAP (\(r,y). (f'-1) - (r DIV 2 -k) ) (toAList names))) f'`
\\ rpt strip_tac
\\ `t.stack_space + (f - f') + f' <= LENGTH t.stack` by
(`f <> 0` by decide_tac \\ fs [] \\ decide_tac)
\\ imp_res_tac APPEND_LEMMA
\\ fs [DROP_LENGTH_APPEND]
\\ `LENGTH (MAP Word (word_list (qs ++ [T]) (dimindex (:'a) - 1) :'a word list)) =
LENGTH xs2` by (fs [] \\ decide_tac)
\\ imp_res_tac list_LUPDATE_APPEND \\ fs [read_bitmap_word_list])
|> INST_TYPE [beta|->``:'ffi``];
*)
Triviality abs_stack_IMP_LENGTH:
∀bs wstack sstack lens stack.
abs_stack bs wstack sstack lens = SOME stack ⇒ LENGTH stack = LENGTH wstack ∧ LENGTH lens = LENGTH wstack
Proof
recInduct (theorem "abs_stack_ind")
\\ fs [abs_stack_def,LET_THM] \\ rpt strip_tac
\\ EVERY_CASE_TAC \\ fs [] \\ rw []
QED
Triviality SORTED_FST_LESS_IMP:
!xs x.
SORTED (\x y. FST x > FST y:num) (x::xs) ==>
SORTED (\x y. FST x > FST y) xs /\ ~(MEM x xs) /\
(!y. MEM y xs ==> FST x > FST y)
Proof
Induct \\ fs [SORTED_DEF]
\\ ntac 3 strip_tac \\ res_tac \\ rpt strip_tac
\\ rw [] \\ fs [] \\ res_tac \\ decide_tac
QED
Triviality SORTED_IMP_EQ_LISTS:
!xs ys.
SORTED (\x y. FST x > FST y:num) ys /\
SORTED (\x y. FST x > FST y) xs /\
(!x. MEM x ys <=> MEM x xs) ==>
(xs = ys)
Proof
Induct \\ fs [] \\ Cases_on `ys` \\ fs [] THEN1 metis_tac []
THEN1 (CCONTR_TAC THEN fs [] THEN metis_tac [])
\\ ntac 2 strip_tac
\\ Cases_on `h = h'` \\ fs [] THEN1
(first_x_assum match_mp_tac
\\ imp_res_tac SORTED_FST_LESS_IMP
\\ metis_tac [])
\\ Cases_on `FST h > FST h'`
THEN1
(first_assum (mp_tac o Q.SPEC `h`)
\\ imp_res_tac SORTED_FST_LESS_IMP
\\ rpt strip_tac \\ fs [] \\ fs []
\\ res_tac \\ decide_tac)
THEN1
(first_assum (mp_tac o Q.SPEC `h'`)
\\ imp_res_tac SORTED_FST_LESS_IMP
\\ rpt strip_tac \\ fs [] \\ fs [])
QED
Theorem transitive_key_val_compare:
transitive key_val_compare
Proof
fs[transitive_def,key_val_compare_def,FORALL_PROD,LET_DEF]