-
Notifications
You must be signed in to change notification settings - Fork 86
/
divScript.sml
1431 lines (1323 loc) · 43.9 KB
/
divScript.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
(*
Examples of non-termination.
*)
open preamble basis
open integerTheory cfDivTheory cfDivLib
val _ = temp_delsimps ["NORMEQ_CONV"]
val _ = new_theory "div";
val _ = translation_extends "basisProg";
(* A simple pure non-terminating loop *)
val _ = process_topdecs `
fun pureLoop x = pureLoop x;
` |> append_prog;
val st = ml_translatorLib.get_ml_prog_state();
Theorem pureLoop_spec:
!xv s u ns.
limited_parts ns p ==>
app (p:'ffi ffi_proj) ^(fetch_v "pureLoop" st) [xv]
(one (FFI_part s u ns [])) (POSTd io. io = [||])
Proof
xcf_div "pureLoop" st
\\ MAP_EVERY qexists_tac [`K emp`, `K []`, `K(K T)`, `K s`, `u`]
\\ xsimpl \\ rw [lprefix_lub_def]
\\ xvar \\ xsimpl
QED
(* Lemma needed for examples with integers *)
Triviality eq_v_INT_thm:
(INT --> INT --> BOOL) $= eq_v
Proof
metis_tac[DISCH_ALL mlbasicsProgTheory.eq_v_thm,EqualityType_NUM_BOOL]
QED
(* A conditionally terminating loop *)
val _ = process_topdecs `
fun condLoop x = if x = 0 then 0 else condLoop (x - 1);
` |> append_prog;
val st = ml_translatorLib.get_ml_prog_state();
Theorem condLoop_spec:
!x xv s u ns.
limited_parts ns p /\ INT x xv ==>
app (p:'ffi ffi_proj) ^(fetch_v "condLoop" st) [xv]
(one (FFI_part s u ns []))
(POSTvd
(\v. &(0 <= x /\ INT 0 v) * one (FFI_part s u ns []))
(\io. x < 0 /\ io = [||]))
Proof
strip_tac \\ Cases_on `x`
THEN1 (
pop_assum (K ALL_TAC) \\ qid_spec_tac `n`
\\ Induct_on `n` \\ rpt strip_tac
THEN1 (
xcf "condLoop" st
\\ xlet_auto THEN1 xsimpl
\\ xif \\ instantiate
\\ xlit \\ xsimpl)
\\ xcf "condLoop" st
\\ xlet_auto THEN1 xsimpl
\\ xif \\ instantiate
\\ xlet_auto THEN1 xsimpl
\\ xapp
\\ MAP_EVERY qexists_tac [`emp`, `u`, `s`, `ns`]
\\ xsimpl \\ fs [INT_def, NUM_def])
THEN1 (
fs [SEP_CLAUSES] \\ fs [SEP_F_to_cond, POSTvd_def, GSYM POSTd_def]
\\ xcf_div "condLoop" st
\\ MAP_EVERY qexists_tac
[`K emp`, `K []`, `\n v. ?i. INT i v /\ i < 0`, `K s`, `u`]
\\ xsimpl \\ qexists_tac `-&n` \\ simp[lprefix_lub_def]
\\ rw[]
\\ xlet_auto >- xsimpl
\\ xif \\ fs[]
\\ xlet_auto >- xsimpl
\\ xvar \\ xsimpl \\ fs[INT_def] \\ intLib.COOPER_TAC)
\\ rpt strip_tac
\\ xcf "condLoop" st
\\ xlet_auto THEN1 xsimpl
\\ xif \\ instantiate
\\ xlit \\ xsimpl
QED
(* Another conditionally terminating loop, using FFI_full *)
val _ = process_topdecs `
fun oddLoop x = if x = 0 then () else oddLoop(x-2);
` |> append_prog;
val st = ml_translatorLib.get_ml_prog_state();
Theorem oddLoop_spec:
!i iv.
INT i iv /\ ¬(2 int_divides i) ==>
app (p:'ffi ffi_proj) ^(fetch_v "oddLoop" st) [iv]
(one (FFI_full [])) (POSTd io. io = [||])
Proof
xcf_div_FFI_full "oddLoop" st
\\ MAP_EVERY qexists_tac [`K emp`,`K []`,`(\n. Litv(IntLit(i - 2 * &n)))`]
\\ simp[lprefix_lub_def]
\\ conj_tac >- (fs[ml_translatorTheory.INT_def])
\\ conj_tac >- xsimpl
\\ fs[SEP_CLAUSES]
\\ strip_tac
\\ rename1 `2 * SUC j`
\\ xlet `POSTv bv. &BOOL F bv * one(FFI_full [])`
>- (xapp_spec eq_v_INT_thm \\ xsimpl
\\ fs[ml_translatorTheory.BOOL_def,semanticPrimitivesTheory.Boolv_def]
\\ rw[] \\ intLib.COOPER_TAC)
\\ xif
\\ asm_exists_tac \\ simp[]
\\ xlet `POSTv iv2. &INT (i − &(2 * SUC j)) iv2 * one(FFI_full [])`
>- (xapp \\ xsimpl \\ fs[ml_translatorTheory.INT_def]
\\ intLib.COOPER_TAC)
\\ xvar \\ xsimpl \\ fs[ml_translatorTheory.INT_def]
QED
(* A loop containing a divergent function *)
val _ = process_topdecs `
fun outerLoop x = if x = 5000 then pureLoop () else outerLoop (x + 1);
` |> append_prog;
val st = ml_translatorLib.get_ml_prog_state();
Theorem outerLoop_spec:
!n nv s u ns.
limited_parts ns p /\ NUM n nv ==>
app (p:'ffi ffi_proj) ^(fetch_v "outerLoop" st) [nv]
(one (FFI_part s u ns [])) (POSTd io. io = [||])
Proof
strip_tac \\ Cases_on `n <= 5000`
THEN1 (
Induct_on `5000 - n` \\ rw []
THEN1 (
xcf "outerLoop" st
\\ xlet_auto THEN1 xsimpl
\\ xif \\ instantiate
\\ xlet_auto THEN1 (xcon \\ xsimpl)
\\ xapp \\ fs [])
\\ xcf "outerLoop" st
\\ xlet_auto THEN1 xsimpl
\\ xif \\ instantiate
\\ xlet_auto THEN1 xsimpl
\\ xapp \\ fs []
\\ qexists_tac `n + 1` \\ fs [])
\\ xcf_div "outerLoop" st
\\ MAP_EVERY qexists_tac
[`K emp`, `K []`, `\i. NUM (n + i)`, `K s`, `u`]
\\ xsimpl \\ rw [lprefix_lub_def]
\\ xlet_auto THEN1 xsimpl
\\ xif \\ instantiate
\\ xlet_auto THEN1 xsimpl
\\ xvar \\ xsimpl \\ fs [ADD_CLAUSES, GSYM ADD1]
QED
(* A small IO model needed for IO examples *)
Definition names_def:
names = ["put_char"; "get_char"]
End
Definition put_char_event_def:
put_char_event c = IO_event (ExtCall "put_char") [n2w (ORD c)] []
End
Definition put_str_event_def:
put_str_event cs = IO_event (ExtCall "put_char") (MAP (n2w o ORD) cs) []
End
Definition get_char_event_def:
get_char_event c = IO_event (ExtCall "get_char") [] [0w, 1w; 0w, n2w (ORD c)]
End
Definition get_char_eof_event_def:
get_char_eof_event = IO_event (ExtCall "get_char") [] [0w, 0w; 0w, 0w]
End
val update_def = PmatchHeuristics.with_classic_heuristic Define `
(update "put_char" cs [] s = SOME (FFIreturn [] s)) /\
(update "get_char" [] [0w; 0w] s = case destStream s of
| NONE => NONE
| SOME ll => if ll = [||] then
SOME (FFIreturn [0w; 0w] s)
else
SOME (FFIreturn [1w; n2w (THE (LHD ll))]
(Stream (THE (LTL ll)))))`
Definition State_def:
State input = Stream (LMAP ORD input)
End
Definition SIO_def:
SIO input events =
one (FFI_part (State input) update names events)
End
val _ = process_topdecs `
fun put_char c = let
val s = String.implode [c]
val a = Word8Array.array 0 (Word8.fromInt 0)
val _ = #(put_char) s a
in () end
` |> append_prog;
val _ = process_topdecs `
fun put_line l = let
val s = l ^ "\n"
val a = Word8Array.array 0 (Word8.fromInt 0)
val _ = #(put_char) s a
in () end
` |> append_prog;
val _ = process_topdecs `
fun get_char (u:unit) = let
val a = Word8Array.array 2 (Word8.fromInt 0)
val _ = #(get_char) "" a
in if Word8Array.sub a 0 = Word8.fromInt 1 then
Some (Char.chr (Word8.toInt (Word8Array.sub a 1)))
else
None
end
` |> append_prog;
val st = ml_translatorLib.get_ml_prog_state();
Theorem put_char_spec:
!c cv input events.
limited_parts names p /\ CHAR c cv ==>
app (p:'ffi ffi_proj) ^(fetch_v "put_char" st) [cv]
(SIO input events)
(POSTv v. &UNIT_TYPE () v *
SIO input (SNOC (put_char_event c) events))
Proof
rpt strip_tac
\\ xcf "put_char" st
\\ xlet_auto THEN1 (xcon \\ xsimpl)
\\ xlet_auto THEN1 (xcon \\ xsimpl)
\\ xlet
`POSTv v. &STRING_TYPE (implode [c]) v * SIO input events`
THEN1 (xapp \\ xsimpl \\ qexists_tac `[c]` \\ fs [LIST_TYPE_def])
\\ xlet_auto THEN1 xsimpl
\\ xlet_auto THEN1 xsimpl
\\ rename1 `W8ARRAY av`
\\ xlet
`POSTv v. &UNIT_TYPE () v * W8ARRAY av [] *
SIO input (SNOC (put_char_event c) events)`
THEN1 (
xffi \\ xsimpl \\ fs [SIO_def]
\\ MAP_EVERY qexists_tac
[`[n2w (ORD c)]`, `emp`, `State input`, `update`, `names`, `events`]
\\ fs [update_def, put_char_event_def, names_def, SNOC_APPEND,
implode_def, STRING_TYPE_def, State_def]
\\ xsimpl)
\\ xcon \\ xsimpl
QED
Theorem put_line_spec:
!l lv input events.
limited_parts names p /\ STRING_TYPE (strlit l) lv ==>
app (p:'ffi ffi_proj) ^(fetch_v "put_line" st) [lv]
(SIO input events)
(POSTv v. &UNIT_TYPE () v *
SIO input (SNOC (put_str_event (l ++ "\n")) events))
Proof
rpt strip_tac
\\ xcf "put_line" st
\\ xlet_auto THEN1 xsimpl
\\ xlet_auto THEN1 xsimpl
\\ xlet_auto THEN1 xsimpl
\\ rename1 `W8ARRAY av`
\\ xlet
`POSTv v. &UNIT_TYPE () v * W8ARRAY av [] *
SIO input (SNOC (put_str_event (l ++ "\n")) events)`
THEN1 (
xffi \\ xsimpl \\ fs [SIO_def]
\\ MAP_EVERY qexists_tac
[`MAP (n2w o ORD) (l ++ "\n")`, `emp`, `State input`, `update`,
`names`, `events`]
\\ fs [update_def, put_str_event_def, names_def, SNOC_APPEND,
STRING_TYPE_def, State_def, strlit_STRCAT, MAP_MAP_o, o_DEF,
CHR_ORD, ORD_BOUND]
\\ xsimpl)
\\ xcon \\ xsimpl
QED
Theorem get_char_spec:
!uv c input events.
limited_parts names p /\ UNIT_TYPE () uv ==>
app (p:'ffi ffi_proj) ^(fetch_v "get_char" st) [uv]
(SIO input events)
(POSTv v. &OPTION_TYPE CHAR (LHD input) v *
if input = [||] then
SIO input (SNOC (get_char_eof_event) events)
else
SIO (THE (LTL input))
(SNOC (get_char_event (THE (LHD input))) events))
Proof
rpt strip_tac
\\ xcf "get_char" st
\\ qmatch_goalsub_abbrev_tac `_ * sio`
\\ qabbrev_tac `a:word8 list = if input = [||] then
[0w; 0w]
else
[1w; n2w (ORD (THE (LHD input)))]`
\\ xmatch \\ rpt (xlet_auto THEN1 xsimpl)
\\ Cases_on `input` \\ (
fs [] \\ rename1 `W8ARRAY av`
\\ xlet `POSTv v. &UNIT_TYPE () v * W8ARRAY av a * sio`
THEN1 (
xffi \\ xsimpl \\ fs [SIO_def]
\\ qpat_abbrev_tac `s = State _`
\\ MAP_EVERY qexists_tac [`emp`, `s`, `update`, `names`, `events`]
\\ unabbrev_all_tac
\\ fs [update_def, get_char_event_def, get_char_eof_event_def,
names_def, SNOC_APPEND, EVAL ``REPLICATE 2 0w``, State_def]
\\ xsimpl)
\\ rpt (xlet_auto THEN1 xsimpl)
\\ xlet_auto THEN1 (xsimpl \\ fs [WORD_def])
\\ xif \\ instantiate
\\ rpt (xlet_auto THEN1 xsimpl)
\\ xcon \\ xsimpl \\ fs [OPTION_TYPE_def, CHR_ORD, ORD_BOUND])
QED
(* TODO: Move REPLICATE_LIST and lemmas to an appropriate theory *)
Definition REPLICATE_LIST_def:
(REPLICATE_LIST l 0 = []) /\
(REPLICATE_LIST l (SUC n) = REPLICATE_LIST l n ++ l)
End
Theorem REPLICATE_LIST_SNOC:
!x n. SNOC x (REPLICATE_LIST [x] n) = REPLICATE_LIST [x] (SUC n)
Proof
rw [REPLICATE_LIST_def]
QED
Theorem REPLICATE_LIST_APPEND:
!l n. REPLICATE_LIST l n ++ l = REPLICATE_LIST l (SUC n)
Proof
rw [REPLICATE_LIST_def]
QED
Theorem REPLICATE_LIST_APPEND_SYM:
!l n. REPLICATE_LIST l n ++ l = l ++ REPLICATE_LIST l n
Proof
strip_tac \\ Induct_on `n` \\ fs [REPLICATE_LIST_def]
QED
Theorem REPLICATE_LIST_LENGTH:
!l n. LENGTH (REPLICATE_LIST l n) = LENGTH l * n
Proof
Induct_on `n` THEN1 (EVAL_TAC \\ fs [])
\\ rw [REPLICATE_LIST_def, MULT_CLAUSES]
QED
Theorem LPREFIX_REPLICATE_LIST_LREPEAT:
!l n. LPREFIX (fromList (REPLICATE_LIST l n)) (LREPEAT l)
Proof
strip_tac \\ Induct_on `n`
\\ fs [REPLICATE_LIST_def, REPLICATE_LIST_APPEND_SYM, GSYM LAPPEND_fromList]
\\ rw [Once LREPEAT_thm] \\ fs [LPREFIX_APPEND]
\\ qexists_tac `ll` \\ fs [LAPPEND_ASSOC]
QED
Theorem LTAKE_EQ_MULT:
!ll1 ll2 m.
0 < m /\ ~LFINITE ll1 /\
(!n. LTAKE (m * n) ll1 = LTAKE (m * n) ll2) ==>
(!n. LTAKE n ll1 = LTAKE n ll2)
Proof
rw []
\\ first_x_assum (qspec_then `n` mp_tac) \\ strip_tac
\\ drule NOT_LFINITE_TAKE
\\ disch_then (qspec_then `m * n` mp_tac) \\ strip_tac \\ fs []
\\ rename1 `SOME l`
\\ `n <= m * n` by fs []
\\ `LTAKE n ll1 = SOME (TAKE n l)` by (
irule LTAKE_TAKE_LESS \\ qexists_tac `m * n` \\ fs [])
\\ `LTAKE n ll2 = SOME (TAKE n l)` by (
irule LTAKE_TAKE_LESS \\ qexists_tac `m * n` \\ fs [])
\\ fs []
QED
Theorem LTAKE_LAPPEND_fromList:
!ll l n.
LTAKE (n + LENGTH l) (LAPPEND (fromList l) ll) =
OPTION_MAP (APPEND l) (LTAKE n ll)
Proof
rw [] \\ Cases_on `LTAKE n ll` \\ fs []
THEN1 (
`LFINITE ll` by (fs [LFINITE] \\ instantiate)
\\ drule LFINITE_HAS_LENGTH \\ strip_tac \\ rename1 `SOME m`
\\ irule LTAKE_LLENGTH_NONE
\\ qexists_tac `m + LENGTH l` \\ rw []
THEN1 (
drule LTAKE_LLENGTH_SOME \\ strip_tac
\\ Cases_on `n ≤ m` \\ fs []
\\ drule (GEN_ALL LTAKE_TAKE_LESS)
\\ disch_then drule \\ fs [])
\\ fs [LLENGTH_APPEND, LFINITE_fromList])
\\ Induct_on `l` \\ rw []
\\ fs [LTAKE_CONS_EQ_SOME]
\\ instantiate
QED
Theorem REPLICATE_LIST_LREPEAT:
!l ll.
l <> [] /\ (!n. LPREFIX (fromList (REPLICATE_LIST l n)) ll) ==>
ll = LREPEAT l
Proof
rw [LTAKE_EQ]
\\ Cases_on `toList ll`
THEN1 (
irule LTAKE_EQ_MULT
\\ `~LFINITE ll` by fs [LFINITE_toList_SOME] \\ fs []
\\ qexists_tac `LENGTH l`
\\ `0 < LENGTH l` by (Cases_on `l` \\ fs []) \\ rw []
\\ rpt (pop_assum mp_tac) \\ qid_spec_tac `ll`
\\ Induct_on `n` \\ rw []
\\ `?ll1. ll = LAPPEND (fromList l) ll1` by (
first_x_assum (qspec_then `1` mp_tac) \\ strip_tac
\\ fs [LPREFIX_APPEND, EVAL ``REPLICATE_LIST l 1``]
\\ rename1 `LAPPEND _ ll1`
\\ qexists_tac `ll1` \\ fs [])
\\ `~LFINITE ll1` by fs [LFINITE_APPEND, LFINITE_fromList]
\\ `toList ll1 = NONE` by fs [LFINITE_toList_SOME]
\\ `!n. LPREFIX (fromList (REPLICATE_LIST l n)) ll1` by (
strip_tac \\ rename1 `REPLICATE_LIST _ n1`
\\ first_x_assum (qspec_then `SUC n1` mp_tac) \\ strip_tac
\\ fs [LPREFIX_fromList] \\ rfs []
\\ fs [REPLICATE_LIST_LENGTH, MULT_CLAUSES]
\\ qspecl_then [`ll1`, `l`, `n1 * LENGTH l`] mp_tac
LTAKE_LAPPEND_fromList \\ strip_tac
\\ fs [REPLICATE_LIST_def, REPLICATE_LIST_APPEND_SYM])
\\ first_x_assum (qspec_then `ll1` drule)
\\ rpt (disch_then drule) \\ strip_tac \\ rveq
\\ `LENGTH l * SUC n = LENGTH l * n + LENGTH l` by fs [MULT_CLAUSES]
\\ qspecl_then [`ll1`, `l`, `LENGTH l * n`] mp_tac
LTAKE_LAPPEND_fromList \\ strip_tac
\\ rw [Once LREPEAT_thm]
\\ qspecl_then [`LREPEAT l`, `l`, `LENGTH l * n`] mp_tac
LTAKE_LAPPEND_fromList \\ strip_tac
\\ fs [])
\\ first_x_assum (qspec_then `SUC (LENGTH x)` mp_tac) \\ strip_tac
\\ fs [LPREFIX_fromList] \\ rfs []
\\ drule IS_PREFIX_LENGTH \\ strip_tac
\\ fs [REPLICATE_LIST_LENGTH]
\\ Cases_on `l` \\ Cases_on `LENGTH x` \\ fs [MULT_CLAUSES]
QED
(* A non-terminating loop with side effects *)
val _ = process_topdecs `
fun printLoop c = (put_char c; printLoop c);
` |> append_prog;
val st = ml_translatorLib.get_ml_prog_state();
Theorem printLoop_spec:
!c cv.
limited_parts names p /\ CHAR c cv ==>
app (p:'ffi ffi_proj) ^(fetch_v "printLoop" st) [cv]
(SIO [||] []) (POSTd io. io = LREPEAT [put_char_event c])
Proof
xcf_div_rule IMP_app_POSTd_one_FFI_part_FLATTEN "printLoop" st
\\ MAP_EVERY qexists_tac
[`K emp`, `\i. if i = 0 then [] else [put_char_event c]`, `K ($= cv)`,
`K (State [||])`, `update`]
\\ SIMP_TAC std_ss [LFLATTEN_LGENLIST_REPEAT,o_DEF,K_DEF,Once LGENLIST_NONE_UNFOLD,
LFLATTEN_THM, CONJUNCT1 llistTheory.fromList_def]
\\ fs [GSYM SIO_def, REPLICATE_LIST_def]
\\ xsimpl
\\ xlet `POSTv v. &UNIT_TYPE () v *
SIO [||] [put_char_event c]`
THEN1 (
xapp
\\ MAP_EVERY qexists_tac [`emp`, `[||]`, `[]`, `c`]
\\ xsimpl)
\\ xvar \\ xsimpl
QED
(* The Unix yes program *)
val _ = process_topdecs `
fun yes u = (put_line "y"; yes u);
` |> append_prog;
val st = ml_translatorLib.get_ml_prog_state();
Definition io_events_def:
io_events = SIO [||]
End
Overload yes = ``yes_v``
Theorem yes_spec_lemma:
!uv.
limited_parts names p ==>
app (p:'ffi ffi_proj) ^(fetch_v "yes" st) [arg]
(io_events []) (POSTd io. io = LREPEAT [put_str_event "y\n"])
Proof
xcf_div "yes" st
\\ MAP_EVERY qexists_tac
[`K emp`, `\i. REPLICATE_LIST [put_str_event "y\n"] i`, `K ($= arg)`,
`K (State [||])`, `update`]
\\ fs [GSYM SIO_def, REPLICATE_LIST_def, io_events_def]
\\ xsimpl \\ rw [lprefix_lub_def]
THEN1 (
xlet `POSTv v. &UNIT_TYPE () v *
SIO [||]
(REPLICATE_LIST [put_str_event "y\n"] (SUC i))`
THEN1 (
xapp
\\ MAP_EVERY qexists_tac
[`emp`, `"y"`, `[||]`, `REPLICATE_LIST [put_str_event "y\n"] i`]
\\ fs [REPLICATE_LIST_SNOC] \\ xsimpl)
\\ xvar \\ fs [REPLICATE_LIST_APPEND] \\ xsimpl)
THEN1 fs [LPREFIX_REPLICATE_LIST_LREPEAT]
\\ fs [PULL_EXISTS]
\\ qmatch_goalsub_abbrev_tac `LPREFIX ll`
\\ `ub = ll` suffices_by simp []
\\ unabbrev_all_tac
\\ irule REPLICATE_LIST_LREPEAT \\ fs []
QED
Theorem yes_spec =
yes_spec_lemma |> SPEC_ALL |> UNDISCH_ALL
(* An IO-conditional loop with side effects *)
val _ = process_topdecs `
fun catLoop u = case get_char () of
None => ()
| Some c => (put_char c; catLoop u);
` |> append_prog;
val st = ml_translatorLib.get_ml_prog_state();
Definition cat_def:
cat ll = LFLATTEN (LMAP (\c. fromList [get_char_event c;
put_char_event c]) ll)
End
Theorem cat_LCONS:
!h t. cat (h ::: t) = LAPPEND (fromList [get_char_event h;
put_char_event h]) (cat t)
Proof
rw [cat_def]
QED
Theorem LMAP_EQ_LGENLIST:
¬LFINITE ll
==>
LMAP f ll =
LGENLIST (\x. f(THE(LNTH x ll))) NONE
Proof
rw[LNTH_EQ,LNTH_LMAP,LNTH_LGENLIST,LFINITE_LNTH_NONE,
GSYM quantHeuristicsTheory.IS_SOME_EQ_NOT_NONE,IS_SOME_EXISTS] >>
metis_tac[THE_DEF]
QED
(* TODO: move LFINITE_LFLATTEN and every_LNTH to llistTheory or similar *)
Theorem LFINITE_LFLATTEN:
!lll:'a llist llist.
every (\ll. LFINITE ll /\ ll <> LNIL) lll ==>
LFINITE (LFLATTEN lll) = LFINITE lll
Proof
`!lll.
LFINITE lll ==> llist$every (\ll. LFINITE ll /\ ll <> LNIL) lll ==>
LFINITE (LFLATTEN lll)` by (ho_match_mp_tac LFINITE_ind \\ fs [LFINITE_APPEND])
\\ qsuff_tac `!x.
LFINITE x ==>
!lll. x = LFLATTEN lll /\ llist$every (\ll. LFINITE ll /\ ll <> LNIL) lll ==>
LFINITE lll` THEN1 (metis_tac [])
\\ ho_match_mp_tac LFINITE_ind
\\ fs [PULL_FORALL] \\ rw []
THEN1 (Cases_on `lll` \\ fs [])
\\ rename [`_ = LFLATTEN lll2`]
\\ Cases_on `lll2` \\ fs []
\\ rename [`h2 <> _`]
\\ Cases_on `h2` \\ fs [] \\ rw []
\\ rename [`LAPPEND t2`]
\\ Cases_on `t2` \\ fs []
\\ rename [`LAPPEND t1`]
\\ first_x_assum (qspec_then `(h:::t1) ::: t` mp_tac) \\ fs []
QED
Theorem every_LNTH:
!P ll. every P ll <=> !n e. LNTH n ll = SOME e ==> P e
Proof
fs [every_def,exists_LNTH] \\ metis_tac []
QED
Theorem cat_LFINITE:
!ll. LFINITE ll <=> LFINITE (cat ll)
Proof
rw [cat_def] \\ qmatch_goalsub_abbrev_tac `LFLATTEN ll'`
\\ `LFINITE (LFLATTEN ll') <=> LFINITE ll'`
suffices_by (unabbrev_all_tac \\ fs [LFINITE_MAP])
\\ irule LFINITE_LFLATTEN
\\ rw [every_LNTH] \\ unabbrev_all_tac \\ fs []
QED
Theorem cat_LTAKE_SUC:
!ll c n.
~LFINITE ll /\ LNTH n ll = SOME c ==>
THE (LTAKE (2 * SUC n) (cat ll)) =
THE (LTAKE (2 * n) (cat ll)) ++
[get_char_event c; put_char_event c]
Proof
Induct_on `n` \\ rw []
\\ qmatch_goalsub_abbrev_tac `[g; p]`
THEN1 (
Cases_on `ll` \\ fs [cat_LCONS] \\ rveq
\\ `2 = LENGTH [g; p]` by EVAL_TAC
\\ `IS_SOME (LTAKE (LENGTH [g; p]) (fromList [g; p]))`
by fs [LTAKE_fromList]
\\ drule LTAKE_LAPPEND1
\\ disch_then (qspec_then `cat t` mp_tac) \\ strip_tac
\\ fs [LTAKE_fromList])
\\ Cases_on `ll` \\ fs [cat_LCONS]
\\ qmatch_goalsub_abbrev_tac `g' ::: p' ::: _`
\\ `2 * SUC n = SUC (SUC (2 * n))` by fs [MULT_CLAUSES]
\\ `2 * SUC (SUC n) = SUC (SUC (2 * SUC n))` by fs [MULT_CLAUSES]
\\ rw [] \\ fs []
\\ `SUC (SUC (2 * n)) = 2 * SUC n` by fs [MULT_CLAUSES]
\\ rw [] \\ fs [cat_LFINITE]
\\ drule NOT_LFINITE_TAKE \\ strip_tac
\\ first_assum (qspec_then `2 * SUC n` mp_tac)
\\ first_x_assum (qspec_then `2 * n` mp_tac)
\\ rpt strip_tac \\ rw []
\\ first_x_assum (qspecl_then [`t`, `c`] drule)
\\ disch_then drule \\ fs []
QED
Theorem LPREFIX_LTAKE:
!ll1 ll2.
~LFINITE ll1 /\ (!n. LPREFIX (fromList (THE (LTAKE n ll1))) ll2) ==>
ll1 = ll2
Proof
rw [LTAKE_EQ]
\\ Cases_on `toList ll2`
THEN1 (
drule NOT_LFINITE_TAKE
\\ disch_then (qspec_then `n` mp_tac) \\ strip_tac
\\ drule LTAKE_LENGTH \\ strip_tac
\\ first_x_assum (qspec_then `n` mp_tac) \\ strip_tac
\\ fs [LPREFIX_fromList] \\ rfs [])
\\ rename1 `SOME l`
\\ first_x_assum (qspec_then `SUC (LENGTH l)` mp_tac) \\ strip_tac
\\ fs [LPREFIX_fromList] \\ rfs []
\\ drule NOT_LFINITE_TAKE
\\ disch_then (qspec_then `SUC (LENGTH l)` mp_tac) \\ strip_tac
\\ drule LTAKE_LENGTH \\ strip_tac \\ fs []
\\ drule IS_PREFIX_LENGTH \\ strip_tac \\ fs []
QED
Theorem IS_PREFIX_TAKE:
!l n. TAKE n l ≼ l
Proof
Induct_on `l` \\ Cases_on `n` \\ rw []
QED
Theorem LPREFIX_LTAKE_MULT:
!ll1 ll2 m.
0 < m /\ ~LFINITE ll1 /\
(!n. LPREFIX (fromList (THE (LTAKE (m * n) ll1))) ll2) ==>
(!n. LPREFIX (fromList (THE (LTAKE n ll1))) ll2)
Proof
rw []
\\ first_x_assum (qspec_then `n` mp_tac) \\ strip_tac
\\ irule LPREFIX_TRANS \\ instantiate
\\ fs [LPREFIX_fromList_fromList]
\\ drule NOT_LFINITE_TAKE
\\ disch_then (qspec_then `m * n` mp_tac) \\ strip_tac
\\ `n <= m * n` by simp []
\\ drule (GEN_ALL LTAKE_TAKE_LESS)
\\ disch_then drule \\ rw [IS_PREFIX_TAKE]
QED
Theorem catLoop_spec:
!uv input.
limited_parts names p ==>
app (p:'ffi ffi_proj) ^(fetch_v "catLoop" st) [uv]
(SIO input []) (POSTvd
(\v. &(LFINITE input /\ UNIT_TYPE () v) *
SIO [||]
(SNOC get_char_eof_event (THE(toList(cat input)))))
(\io. ~LFINITE input /\ io = cat input))
Proof
rw [] \\ Cases_on `LFINITE input` \\ fs [POSTvd_def, SEP_CLAUSES]
\\ fs [SEP_F_to_cond, GSYM POSTv_def, GSYM POSTd_def]
THEN1 (
qmatch_goalsub_abbrev_tac `app _ f`
\\ qsuff_tac `
(\input.
!uv events.
app p f [uv] (SIO input events)
(POSTv v. &UNIT_TYPE () v *
SIO [||]
(events ++ SNOC get_char_eof_event
(THE (toList (cat input))))))
input`
THEN1 (
rw [] \\ pop_assum (qspecl_then [`uv`, `[]`] mp_tac) \\ fs [])
\\ irule LFINITE_STRONG_INDUCTION \\ rw []
\\ unabbrev_all_tac
THEN1 (
xcf "catLoop" st
\\ xlet_auto THEN1 (xcon \\ xsimpl)
\\ xlet `POSTv v. &OPTION_TYPE CHAR NONE v *
SIO [||] (SNOC (get_char_eof_event) events)`
THEN1 (
xapp
\\ MAP_EVERY qexists_tac [`emp`, `[||]`, `events`]
\\ xsimpl)
\\ xmatch \\ fs [OPTION_TYPE_def]
\\ reverse (rw []) THEN1 EVAL_TAC
THEN1 (xcon \\ fs [toList, cat_def, SNOC_APPEND] \\ xsimpl)
\\ EVAL_TAC \\ simp [] \\ EVAL_TAC)
\\ xcf "catLoop" st
\\ xlet_auto THEN1 (xcon \\ xsimpl)
\\ xlet `POSTv v. &OPTION_TYPE CHAR (SOME h) v *
SIO t (SNOC (get_char_event h) events)`
THEN1 (
xapp
\\ MAP_EVERY qexists_tac [`emp`, `h ::: t`, `events`]
\\ xsimpl)
\\ xmatch \\ fs [OPTION_TYPE_def] \\ reverse (rpt strip_tac)
THEN1 EVAL_TAC THEN1 EVAL_TAC
\\ xlet `POSTv v. &UNIT_TYPE () v *
SIO t
(SNOC (put_char_event h)
(SNOC (get_char_event h) events))`
THEN1 (xapp \\ fs [])
\\ qmatch_goalsub_abbrev_tac `SIO _ events1`
\\ qmatch_goalsub_abbrev_tac `_ * SIO _ events2`
\\ `events2 = events1 ++ SNOC get_char_eof_event
(THE (toList (cat t)))` by (
unabbrev_all_tac \\ fs [cat_LFINITE, cat_LCONS, toList_THM]
\\ drule LFINITE_toList \\ strip_tac \\ fs [])
\\ xapp
\\ MAP_EVERY qexists_tac [`emp`, `events1`]
\\ xsimpl)
\\ xcf_div_rule IMP_app_POSTd_one_FFI_part_FLATTEN "catLoop" st
\\ MAP_EVERY qexists_tac
[`K emp`, `\i. if i = 0 then [] else
[get_char_event(THE(LNTH (i-1) input));put_char_event(THE(LNTH (i-1) input))]`, `K ($= uv)`,
`\i. State (THE (LDROP i input))`, `update`]
\\ fs [GSYM SIO_def] \\ xsimpl \\ rw [lprefix_lub_def]
THEN1 (
qmatch_goalsub_abbrev_tac `SIO input1 events1`
\\ qmatch_goalsub_abbrev_tac `&_ * _ * SIO input2 events2`
\\ Cases_on `LNTH i input` THEN1 metis_tac [LFINITE_LNTH_NONE]
\\ rename1 `LNTH _ _ = SOME c`
\\ `input1 = c ::: input2` by (
unabbrev_all_tac \\
simp[LDROP_SUC]
\\ Cases_on `LDROP i input`
\\ TRY (metis_tac [LDROP_NONE_LFINITE])
\\ drule LNTH_LDROP
\\ fs[] \\ rw[] \\ rename1 `ll = _`
\\ Cases_on `ll` \\ fs[])
\\ xlet_auto THEN1 (xcon \\ xsimpl)
\\ xlet `POSTv v. &OPTION_TYPE CHAR (SOME c) v *
SIO input2 (SNOC (get_char_event c) events1)`
THEN1 (
xapp
\\ MAP_EVERY qexists_tac [`emp`, `input1`, `events1`]
\\ xsimpl)
\\ xmatch \\ fs [OPTION_TYPE_def] \\ reverse (rpt strip_tac)
THEN1 EVAL_TAC THEN1 EVAL_TAC
\\ xlet `POSTv v. &UNIT_TYPE () v * SIO input2 events2`
THEN1 (
xapp
\\ MAP_EVERY qexists_tac
[`emp`, `input2`, `SNOC (get_char_event c) events1`, `c`]
\\ qmatch_goalsub_abbrev_tac `&_ * SIO _ events'`
\\ `events' = events2` by (
unabbrev_all_tac \\ fs [SNOC_APPEND])
\\ fs [SNOC_APPEND] \\ xsimpl)
\\ xvar \\ xsimpl)
\\ simp[Once LGENLIST_NONE_UNFOLD,o_DEF,cat_def,LMAP_EQ_LGENLIST]
QED
(* Infinite lists encoded as cyclic pointer structures in the heap *)
Definition REF_LIST_def:
(REF_LIST rv [] A [] = SEP_EXISTS loc. cond(rv=Loc T loc))
/\
(REF_LIST rv (rv2::rvs) A (x::l) =
(SEP_EXISTS loc v1.
cond(rv = Loc T loc)
* cell loc (Refv(Conv NONE [v1;rv2]))
* cond(A x v1)
* REF_LIST rv2 rvs A l
) /\
(REF_LIST _ _ _ _ = &F)
)
End
Theorem REF_LIST_extend:
!rv rvs A l x v1.
(REF_LIST rv rvs A l *
SEP_EXISTS v1 loc loc'.
cond(LAST(rv::rvs) = Loc T loc)
* cell loc (Refv(Conv NONE [v1;rv2]))
* cond(rv2 = Loc T loc')
* cond(A x v1))
= (REF_LIST rv (SNOC rv2 rvs) A (SNOC x l))
Proof
PURE_ONCE_REWRITE_TAC[FUN_EQ_THM] >>
ho_match_mp_tac (fetch "-" "REF_LIST_ind") >>
rpt strip_tac >-
(simp[REF_LIST_def] >>
simp[SEP_CLAUSES] >>
simp[AC STAR_COMM STAR_ASSOC] >>
simp[SEP_EXISTS,cond_STAR] >>
metis_tac[]) >-
(pop_assum(assume_tac o REWRITE_RULE[GSYM FUN_EQ_THM] o GSYM) >>
simp[REF_LIST_def] >>
simp[SEP_CLAUSES] >>
simp[AC STAR_COMM STAR_ASSOC] >>
simp[SEP_EXISTS,cond_STAR]) >-
(simp[REF_LIST_def,SNOC_APPEND] >>
rename1 `REF_LIST _ (a1 ++ _)` >>
Cases_on `a1` >> simp[REF_LIST_def,SEP_CLAUSES]) >-
(simp[REF_LIST_def,SNOC_APPEND] >>
rename1 `REF_LIST _ _ _ (a1 ++ _)` >>
Cases_on `a1` >> simp[REF_LIST_def,SEP_CLAUSES])
QED
(* TODO: lots of these lemmas should probably live in characteristic/ or llistTheory *)
Inductive llist_upto:
(llist_upto R x x) /\
(R x y ==> llist_upto R x y) /\
(llist_upto R x y /\ llist_upto R y z ==> llist_upto R x z) /\
(llist_upto R x y ==> llist_upto R (LAPPEND z x) (LAPPEND z y))
End
val [llist_upto_eq,llist_upto_rel,llist_upto_trans,llist_upto_context] =
llist_upto_rules |> SPEC_ALL |> CONJUNCTS |> map GEN_ALL
|> curry (ListPair.map save_thm)
["llist_upto_eq","llist_upto_rel",
"llist_upto_trans","llist_upto_context"]
Theorem LLIST_BISIM_UPTO:
∀ll1 ll2 R.
R ll1 ll2 ∧
(∀ll3 ll4.
R ll3 ll4 ⇒
ll3 = [||] ∧ ll4 = [||] ∨
LHD ll3 = LHD ll4 ∧
llist_upto R (THE (LTL ll3)) (THE (LTL ll4)))
==> ll1 = ll2
Proof
rpt strip_tac
>> PURE_ONCE_REWRITE_TAC[LLIST_BISIMULATION]
>> qexists_tac `llist_upto R`
>> conj_tac >- rw[llist_upto_rules]
>> ho_match_mp_tac llist_upto_ind
>> rpt conj_tac
>- rw[llist_upto_rules]
>- first_x_assum ACCEPT_TAC
>- (rw[]
>> match_mp_tac OR_INTRO_THM2
>> conj_tac >- simp[]
>> metis_tac[llist_upto_rules])
>- (rw[llist_upto_rules]
>> Cases_on `ll3 = [||]`
>- (Cases_on `ll4` >> fs[llist_upto_rules])
>> match_mp_tac OR_INTRO_THM2
>> conj_tac
>- (Cases_on `z` >> simp[])
>> Cases_on `z` >- simp[]
>> simp[]
>> Cases_on `ll3` >> Cases_on `ll4`
>> fs[] >> rveq
>> CONV_TAC(RAND_CONV(RAND_CONV(RAND_CONV(PURE_ONCE_REWRITE_CONV [GSYM(CONJUNCT1 LAPPEND)]))))
>> CONV_TAC(RATOR_CONV(RAND_CONV(RAND_CONV(RAND_CONV(PURE_ONCE_REWRITE_CONV [GSYM(CONJUNCT1 LAPPEND)])))))
>> PURE_ONCE_REWRITE_TAC[GSYM(CONJUNCT2 LAPPEND)]
>> simp[GSYM LAPPEND_ASSOC]
>> metis_tac[llist_upto_rules])
QED
Theorem REF_cell_eq:
loc ~~>> Refv v = Loc T loc ~~> v
Proof
rw[FUN_EQ_THM,cell_def,REF_def,SEP_EXISTS,cond_STAR]
QED
Triviality LTAKE_LNTH_EQ:
!x ll y. LTAKE (LENGTH x) ll = SOME x
/\ y < LENGTH x
==> LNTH y ll = SOME(EL y x)
Proof
Induct_on `x` >> rw[LTAKE] >>
Cases_on `ll` >> fs[] >>
PURE_FULL_CASE_TAC >> fs[] >> rveq >>
Cases_on `y` >> fs[]
QED
Theorem LTAKE_LPREFIX:
!x ll.
~LFINITE ll ==> ?l. LTAKE x ll = SOME l /\
LPREFIX (fromList l) ll
Proof
Induct >> rw[] >>
Cases_on `ll` >> fs[] >>
first_x_assum(drule_then strip_assume_tac) >>
fs[LPREFIX_LCONS]
QED
Theorem LMAP_fromList:
LMAP f (fromList l) = fromList(MAP f l)
Proof
Induct_on `l` >> fs[]
QED
Theorem LTAKE_LMAP:
!n f ll. LTAKE n (LMAP f ll) =
OPTION_MAP (MAP f) (LTAKE n ll)
Proof
Induct_on `n` >> rw[] >>
Cases_on `ll` >> fs[OPTION_MAP_COMPOSE,o_DEF]
QED
Theorem LNTH_LREPEAT:
!i x l.
LNTH i (LREPEAT l) = SOME x
==> x = EL (i MOD LENGTH l) l
Proof
Induct_on `i DIV LENGTH l` >> rw[]
>- (Cases_on `l = []`
>> fs[Once LREPEAT_thm]
>> fs[LNTH_LAPPEND]
>> `0 < LENGTH l` by(Cases_on `l` >> fs[])
>> qpat_x_assum `0 = _` (assume_tac o GSYM)
>> rfs[RatProgTheory.DIV_EQ_0]
>> fs[LNTH_fromList])
>> fs[ADD1]
>> `LENGTH l <= i`
by(CCONTR_TAC >> fs[LESS_DIV_EQ_ZERO])
>> `0 < LENGTH l` by(Cases_on `l` >> fs[])
>> `v = (i - LENGTH l) DIV LENGTH l`
by(fs[Q.INST[`q`|->`1`] DIV_SUB |> REWRITE_RULE [MULT_CLAUSES]])
>> first_x_assum drule
>> drule lnth_some_down_closed
>> disch_then(qspec_then `i - LENGTH l` mp_tac)
>> impl_tac >- simp[]
>> strip_tac
>> disch_then drule
>> strip_tac
>> rveq
>> qpat_x_assum `LNTH (_ - _) _ = _`
(fn thm => qpat_x_assum `LNTH _ _ = _` mp_tac >> assume_tac thm)
>> simp[Once LREPEAT_thm]
>> fs[LNTH_LAPPEND]
>> fs[SUB_MOD]
QED
Theorem REF_LIST_is_loc:
!rv rvs A l h. REF_LIST rv rvs A l h ==> ?loc. rv = Loc T loc
Proof
ho_match_mp_tac (fetch "-" "REF_LIST_ind") >>
rw[REF_LIST_def,SEP_CLAUSES,SEP_F_def,STAR_def,SEP_EXISTS,cond_def]
QED
Theorem REF_LIST_LENGTH:
!rv rvs A l h. REF_LIST rv rvs A l h ==> LENGTH rvs = LENGTH l
Proof
ho_match_mp_tac (fetch "-" "REF_LIST_ind") >>
rw[REF_LIST_def,SEP_CLAUSES,SEP_F_def,STAR_def,SEP_EXISTS,cond_def] >>
metis_tac[]
QED
Theorem REF_LIST_rotate_1:
REF_LIST rv (SNOC rv (rv2::rvs)) A (x::l) =
REF_LIST rv2 (SNOC rv2 (SNOC rv rvs)) A (SNOC x l)
Proof
rw[FUN_EQ_THM] >>
simp[REF_LIST_def,GSYM REF_LIST_extend,Once LAST_DEF] >>
simp[SEP_CLAUSES,AC STAR_COMM STAR_ASSOC] >>
simp[SEP_EXISTS,cond_STAR] >>
rw[EQ_IMP_THM] >-
(asm_exists_tac >> simp[] >>
fs[STAR_def] >> Cases_on `l` >>
fs[REF_LIST_def] >> metis_tac[REF_LIST_is_loc]) >>
metis_tac[]