forked from pirapira/eth-isabelle
/
LLLL.thy
6909 lines (5914 loc) · 266 KB
/
LLLL.thy
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
theory LLLL
imports Main Nat "../ContractSem" "../RelationalSem" "../ProgramInAvl" "../Hoare/Hoare" "../lem/Evm"
begin
value "CHR''0'' :: char"
(* convenience routines for reading/printing hex as string *)
value "List.hd (''abcd'' :: char list)"
definition hexread1_dom :: "char \<Rightarrow> bool" where
"hexread1_dom c = (c = CHR ''0'' \<or> c = CHR ''1'' \<or> c = CHR ''2'' \<or>
c = CHR ''3'' \<or> c = CHR ''4'' \<or> c = CHR ''5'' \<or>
c = CHR ''6'' \<or> c = CHR ''7'' \<or> c = CHR ''8'' \<or>
c = CHR ''9'' \<or> c = CHR ''A'' \<or> c = CHR ''B'' \<or>
c = CHR ''D'' \<or> c = CHR ''E'' \<or> c = CHR ''F'')"
definition hexread1 :: "char \<Rightarrow> nat" where
"hexread1 c = (if c = (CHR ''0'') then 0 else
if c = (CHR ''1'') then 1 else
if c = (CHR ''2'') then 2 else
if c = (CHR ''3'') then 3 else
if c = (CHR ''4'') then 4 else
if c = (CHR ''5'') then 5 else
if c = (CHR ''6'') then 6 else
if c = (CHR ''7'') then 7 else
if c = (CHR ''8'') then 8 else
if c = (CHR ''9'') then 9 else
if c = (CHR ''A'') then 10 else
if c = (CHR ''B'') then 11 else
if c = (CHR ''C'') then 12 else
if c = (CHR ''D'') then 13 else
if c = (CHR ''E'') then 14 else
if c = (CHR ''F'') then 15 else
undefined)"
definition hexwrite1_dom :: "nat \<Rightarrow> bool" where
"hexwrite1_dom n = (n < 16)"
definition hexwrite1 :: "nat \<Rightarrow> char" where
"hexwrite1 c = (if c = 0 then CHR ''0'' else
if c = 1 then CHR ''1'' else
if c = 2 then CHR ''2'' else
if c = 3 then CHR ''3'' else
if c = 4 then CHR ''4'' else
if c = 5 then CHR ''5'' else
if c = 6 then CHR ''6'' else
if c = 7 then CHR ''7'' else
if c = 8 then CHR ''8'' else
if c = 9 then CHR ''9'' else
if c = 10 then CHR ''A'' else
if c = 11 then CHR ''B'' else
if c = 12 then CHR ''C'' else
if c = 13 then CHR ''D'' else
if c = 14 then CHR ''E'' else
if c = 15 then CHR ''F'' else undefined)"
value "(1 < (0::nat))"
lemma hexread1_hexwrite1 : "hexread1_dom c \<Longrightarrow> hexwrite1 (hexread1 c) = c"
apply (auto simp add:hexread1_dom_def hexread1_def hexwrite1_def)
done
lemma hexwrite1_help :
"n < 16 \<Longrightarrow>
n \<noteq> 15 \<Longrightarrow>
n \<noteq> 14 \<Longrightarrow>
n \<noteq> 13 \<Longrightarrow>
n \<noteq> 12 \<Longrightarrow>
n \<noteq> 11 \<Longrightarrow>
n \<noteq> 10 \<Longrightarrow>
n \<noteq> 9 \<Longrightarrow>
n \<noteq> 8 \<Longrightarrow>
n \<noteq> 7 \<Longrightarrow>
n \<noteq> 6 \<Longrightarrow>
n \<noteq> 5 \<Longrightarrow>
n \<noteq> 4 \<Longrightarrow>
n \<noteq> 3 \<Longrightarrow>
n \<noteq> 2 \<Longrightarrow>
n \<noteq> Suc 0 \<Longrightarrow>
0 < n \<Longrightarrow> False"
proof(induction n, auto)
qed
lemma hexwrite1_hexread1 : "hexwrite1_dom n \<Longrightarrow> hexread1 (hexwrite1 n) = n"
apply(auto simp add:hexwrite1_dom_def hexwrite1_def)
apply(auto simp add:hexread1_def)
apply(insert hexwrite1_help, auto)
done
definition hexread2 :: "char \<Rightarrow> char \<Rightarrow> nat" where
"hexread2 c1 c2 = (16 * (hexread1 c1) + hexread1 c2)"
(* we need to reverse the input list? *)
(* TODO: later handle zero padding for odd numbers of bytes *)
fun hexread' :: "char list \<Rightarrow> nat \<Rightarrow> nat" where
"hexread' [] n = n"
| "hexread' [_] _ = undefined"
| "hexread' (n1#n2#t) a = hexread' t (hexread2 n1 n2 + 256 * a)"
definition hexread :: "char list \<Rightarrow> nat" where
"hexread ls = hexread' ls 0"
fun hexwrite2 :: "8 word \<Rightarrow> (char * char)" where
"hexwrite2 w =
(case Divides.divmod_nat (Word.unat w) 16 of
(d,m) \<Rightarrow> (hexwrite1 d, hexwrite1 m))"
(* TODO: make sure we aren't supposed to do the reverse of this *)
fun hexwrite :: "8 word list \<Rightarrow> char list" where
"hexwrite [] = []"
| "hexwrite (h#t) = (case hexwrite2 h of
(c1, c2) \<Rightarrow> c1#c2#(hexwrite t))"
value "(hexwrite [1,2])"
(* *)
(* we need to rule out invalid, PC, and misc instrs *)
(* stack manipulation should be OK *)
fun inst_valid :: "inst => bool" where
"inst_valid (Unknown _) = False"
| "inst_valid (Pc _) = False"
| "inst_valid (Misc _) = False"
| "inst_valid _ = True"
(* don't mix up de Bruijn indices with sizes *)
type_synonym idx = nat
datatype ll1 =
L "inst"
(* de-Bruijn style approach to local binders *)
| LLab "idx"
| LJmp "idx"
| LJmpI "idx"
(* sequencing nodes also serve as local binders *)
| LSeq "ll1 list"
lemma my_ll1_induct:
assumes Ln: "(\<And> i. P1 (L i))"
and La: "(\<And> idx . P1 (LLab idx))"
and Lj: "(\<And>idx . P1 (LJmp idx))"
and Lji : "(\<And>idx . P1 (LJmpI idx))"
and Lls : "(\<And>l . P2 l \<Longrightarrow> P1 (LSeq l))"
and Lln : "P2 []"
and Llc : "\<And>t l . P1 t \<Longrightarrow> P2 l \<Longrightarrow> P2 (t # l)"
shows "P1 t \<and> P2 l"
proof-
{fix t
have "P1 t \<and> (\<forall> l . t = LSeq l \<longrightarrow> P2 l)"
proof (induction)
case (L) thus ?case using Ln by auto next
case (LLab) thus ?case using La by auto next
case (LJmp) thus ?case using Lj by auto next
case (LJmpI) thus ?case using Lji by auto next
case (LSeq l) thus ?case
apply (induct l) using Lls Lln Llc by auto blast+
qed}
thus ?thesis by auto
qed
fun ll1_valid :: "ll1 \<Rightarrow> bool" where
"ll1_valid (L i) = inst_valid i"
| "ll1_valid (LSeq is) = list_all ll1_valid is"
| "ll1_valid _ = True"
(* "quantitative annotations" *)
type_synonym qan = "nat * nat"
datatype ('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) punit =
PU
(* let's try the uniform version with pairs first *)
(* Q: can we fix the cases for valid_q by adding a 'dummy' optional argument of each data type? - doesn't seem to work *)
datatype ('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) llt =
L "'lix" "inst"
(* de-Bruijn style approach to local binders *)
| LLab "'llx" "idx"
(* idx stores which label it is
nat stores how many bytes *)
| LJmp "'ljx" "idx" "nat"
| LJmpI "'ljix" "idx" "nat"
(* sequencing nodes also serve as local binders *)
(* do we put an "'ix" in here? *)
| LSeq "'lsx" "(qan * ('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx )llt )list"
type_synonym ('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll =
"(qan * ('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) llt)"
(* Q: should P2 also take a qan expressing entire list? *)
lemma my_ll_induct:
assumes Ln: "(\<And> q e i. P1 (q, L e i))"
and La: "(\<And> q e idx . P1 (q, LLab e idx))"
and Lj: "(\<And> q e idx n . P1 (q, LJmp e idx n))"
and Lji : "(\<And> q e idx n . P1 (q, LJmpI e idx n))"
and Lls : "(\<And> q e l . P2 l \<Longrightarrow> P1 (q, LSeq e l))"
and Lln : "P2 []" (* should this only be identical q? *)
and Llc : "\<And> h l. P1 h \<Longrightarrow> P2 l \<Longrightarrow> P2 (h # l)"
shows "P1 t \<and> P2 l"
proof-
{fix t
have "(\<forall> q . P1 (q, t)) \<and> (\<forall> l e . t = LSeq e l \<longrightarrow> P2 l)"
proof (induction)
case (L) thus ?case using Ln by auto next
case (LLab) thus ?case using La by auto next
case (LJmp) thus ?case using Lj by auto next
case (LJmpI) thus ?case using Lji by auto next
case (LSeq e l) thus ?case
proof(induct l)
case Nil thus ?case using Lln Lls by auto next
case (Cons a l)
thus ?case using Llc Lls
apply(clarsimp)
apply(case_tac a)
apply(subgoal_tac "P1 a") apply(clarsimp)
apply(subgoal_tac "P2 l") apply(clarsimp)
apply(auto, blast)
apply(metis)
done
qed
qed}
thus ?thesis
apply(case_tac t)
apply(auto, blast )
done qed
(*Q: do we need more qan's in the path *)
datatype ('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) llpath =
Top "'ptx"
| Node "'pnx" "'lsx" "('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll list"
"('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) llpath"
"('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll list"
(* undecorated syntax with qan *)
(* TODO: change these from units to any type *)
type_synonym ll2t =
"(unit, unit, unit, unit, unit, unit, unit) llt"
type_synonym ll2 =
"(unit, unit, unit, unit, unit, unit, unit) ll"
type_synonym ll2p =
"(unit, unit, unit, unit, unit, unit, unit) llpath"
(* location = path + node *)
type_synonym ll2l = "(ll2 * ll2p)"
(* decorate Seq nodes with label resolution *)
(* Q: just store which number child? list of nats representing path?*)
type_synonym ll3t =
"(unit, bool, unit, unit, nat list, unit, unit) llt"
type_synonym ('lix, 'ljx, 'ljix, 'ptx, 'pnx) ll3t' =
"('lix, bool, 'ljx, 'ljix, nat list, 'ptx, 'pnx) llt"
type_synonym ll3 =
"(unit, bool, unit, unit, nat list, unit, unit) ll"
type_synonym ('lix, 'ljx, 'ljix, 'ptx, 'pnx) ll3' =
"('lix, bool, 'ljx, 'ljix, nat list, 'ptx, 'pnx) ll"
type_synonym ll3p =
"(unit, bool, unit, unit, nat list, unit, unit) llpath"
type_synonym ll3l = "ll3 * ll3p"
type_synonym ll4t =
"(unit, bool, nat, nat, nat list, unit, unit) llt"
type_synonym ll4 =
"(unit, bool, nat, nat, nat list, unit, unit) ll"
type_synonym ll4p =
"(unit, bool, nat, nat, nat list, unit, unit) llpath"
type_synonym ll4l = "ll4 * ll4p"
definition jump_size :: "nat" where
"jump_size = nat (inst_size (Pc JUMP))"
declare jump_size_def [simp]
definition jumpi_size :: "nat" where
"jumpi_size = nat (inst_size (Pc JUMPI))"
declare jumpi_size_def [simp]
(* validity of ll2 terms that have just been translated from ll1 *)
(* TODO: we need to break this up into separate pieces for each constructor,
this way we can reuse them later without type variable ambiguities *)
definition ll_valid_qi :: "(qan * inst) set" where
"ll_valid_qi = {((n,n'),i) . inst_valid i \<and> n' = n + nat (inst_size i)}"
declare ll_valid_qi_def [simp]
definition ll_valid_ql :: "(qan * idx) set" where
"ll_valid_ql = {((n,n'),i) . n' = n+1}"
declare ll_valid_ql_def [simp]
(* +2 to account for the push instruction and the jump instruction *)
definition ll_valid_qj :: "(qan * idx * nat) set" where
"ll_valid_qj = {((n,n'),d,s) . n' = n + 2 + s}"
declare ll_valid_qj_def [simp]
definition ll_valid_qji :: "(qan * idx * nat) set" where
"ll_valid_qji = {((n,n'),d,s) . n' = n + 2 + s}"
declare ll_valid_qji_def [simp]
inductive_set
ll_valid_q :: "('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll set" and
ll_validl_q :: "(qan * (('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll list)) set "
where
"\<And> i x e . (x, i) \<in> ll_valid_qi \<Longrightarrow> (x, L e i) \<in> ll_valid_q"
| "\<And> x d e . (x, d) \<in> ll_valid_ql \<Longrightarrow> (x, LLab e d) \<in> ll_valid_q"
| "\<And> x d e s . (x, d, s) \<in> ll_valid_qj \<Longrightarrow> (x, LJmp e d s) \<in> ll_valid_q"
| "\<And> x d e s . (x, d, s) \<in> ll_valid_qji \<Longrightarrow> (x, LJmpI e d s) \<in> ll_valid_q"
| "\<And> n l n' e . ((n, n'), l) \<in> ll_validl_q \<Longrightarrow> ((n, n'), (LSeq e l)) \<in> ll_valid_q"
| "\<And> n . ((n,n), []) \<in> ll_validl_q"
| "\<And> n h n' t n'' .
((n,n'), h) \<in> ll_valid_q \<Longrightarrow>
((n',n''), t) \<in> ll_validl_q \<Longrightarrow>
((n,n''), ((n,n'), h) # t) \<in> ll_validl_q"
(* TODO: define "bump" to move the given ll to the "right" in the buffer by X bytes
in order for this to be useful, we will need to make our annotations
parametric in the size (? - maybe we don't use this until the
very end so it will work out)
*)
(* this should operate on a (qan * (ll list))?
otherwise there is and repacking we have to do... *)
fun ll_bump :: "nat \<Rightarrow> ('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll \<Rightarrow>
('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll" where
"ll_bump b ((n,n'), l) = ((n+b,n'+b), (case l of
LSeq e ls \<Rightarrow> LSeq e (map (ll_bump b) ls)
| _ \<Rightarrow> l))"
(* this is also suffering from the same problem as the validity predicate itself had.
we need a case for each constructor. *)
(* to fix this we should have a better induction rule for validity that breaks out cases,
maybe defining all of them as a mutually inductive set will work... *)
(* I am unsure if this is actually necessary though as both rules work individually *)
lemma ll_bump_valid [rule_format]:
"((x, (t :: ('lix, 'llx, 'ljx, 'ljix, 'llx, 'ptx, 'pnx) llt)) \<in> ll_valid_q \<longrightarrow> (! b . ((ll_bump b (x,t))) \<in> ll_valid_q)) \<and>
(((m,m'), (l :: ('lix, 'llx, 'ljx, 'ljix, 'llx, 'ptx, 'pnx) ll list)) \<in> ll_validl_q \<longrightarrow> (! b' .((m+b', m'+b'), map (ll_bump b') l) \<in> ll_validl_q))"
proof(induction rule: ll_valid_q_ll_validl_q.induct)
case 1 thus ?case by (auto simp add: ll_valid_q_ll_validl_q.intros) next
case 2 thus ?case by (auto simp add: ll_valid_q_ll_validl_q.intros) next
case 3 thus ?case by (auto simp add: ll_valid_q_ll_validl_q.intros) next
case 4 thus ?case by (auto simp add: ll_valid_q_ll_validl_q.intros) next
case (5 n l n' e) thus ?case by (auto simp add:ll_valid_q_ll_validl_q.intros) next
case 6 thus ?case by (auto simp add:ll_valid_q_ll_validl_q.intros) next
case (7 n h n' t n'') thus ?case
apply(clarsimp)
apply(drule_tac x = "b'" in spec)
apply(drule_tac x = "b'" in spec)
apply(rule ll_valid_q_ll_validl_q.intros(7), auto)
done qed
fun ll1_size :: "ll1 \<Rightarrow> nat" and
ll1_size_seq :: "ll1 list \<Rightarrow> nat" where
"ll1_size (ll1.L inst) = nat (inst_size inst)"
| "ll1_size (ll1.LLab idx) = 1"
| "ll1_size (ll1.LJmp idx) = 2"
| "ll1_size (ll1.LJmpI idx) = 2"
| "ll1_size (ll1.LSeq ls) = ll1_size_seq ls"
| "ll1_size_seq [] = 0"
| "ll1_size_seq (h # t) = ll1_size h + ll1_size_seq t"
(* first pass, storing sizes *)
fun ll_phase1 :: "ll1 \<Rightarrow> nat \<Rightarrow> (ll2 * nat)" and
ll_phase1_seq :: "ll1 list \<Rightarrow> nat \<Rightarrow> (ll2 list * nat)"
where
"ll_phase1 (ll1.L inst) i = (((i, i + nat (inst_size inst)), L () inst ), i + nat (inst_size inst))"
| "ll_phase1 (ll1.LLab idx) i = (((i, i+1), LLab () idx ), 1+i)" (* labels take 1 byte *)
| "ll_phase1 (ll1.LJmp idx) i = (((i, 2 + i), LJmp () idx 0), 2 + i)" (* jumps take at least 2 bytes (jump plus push) *)
| "ll_phase1 (ll1.LJmpI idx) i = (((i, 2 + i), LJmpI () idx 0), 2 + i)"
| "ll_phase1 (ll1.LSeq ls) i =
(let (ls', i') = ll_phase1_seq ls i in
(((i, i'), LSeq () ls'), i'))"
| "ll_phase1_seq [] i = ([], i)"
| "ll_phase1_seq (h # t) i =
(let (h', i') = ll_phase1 h i in
(let (t', i'') = ll_phase1_seq t i' in
(h' # t', i'')))"
definition ll_pass1 :: "ll1 \<Rightarrow> ll2" where
"ll_pass1 l = fst (ll_phase1 l 0)"
lemma ll_phase1_correct :
"(ll1_valid x \<longrightarrow> (! i . ? x2 . ? i' . ll_phase1 x i = (((i, i'), x2), i') \<and> ((i, i'), x2) \<in> ll_valid_q)) \<and>
(list_all ll1_valid xs \<longrightarrow>
(! j . ? xs2 . ? j' . ll_phase1_seq xs j = (xs2, j') \<and> ((j,j'),xs2) \<in> ll_validl_q))"
proof(induction rule:my_ll1_induct)
case (1 i) thus ?case by (auto simp add:ll_valid_q.simps) next
case (2 idx) thus ?case by (auto simp add:ll_valid_q.simps) next
case (3 idx) thus ?case
by (auto simp add:ll_valid_q.simps) next
case (4 idx) thus ?case by (auto simp add:ll_valid_q.simps) next
case (5 l) thus ?case
apply(clarsimp)
apply(case_tac "ll_phase1_seq l i", clarsimp)
apply(drule_tac x = "i" in spec)
apply (auto simp add:ll_valid_q.simps)
done next
case (6) thus ?case using ll_valid_q_ll_validl_q.intros(6) by auto next
case(7 t l) thus ?case
apply(clarsimp)
apply(case_tac "ll_phase1 t j", clarsimp)
apply(rename_tac "b'")
apply(case_tac "ll_phase1_seq l b'", clarsimp)
apply(drule_tac x = "j" in spec)
apply(clarsimp)
apply(drule_tac x = "b" in spec)
apply(clarsimp)
apply(rule ll_valid_q_ll_validl_q.intros(7), auto)
done
qed
value "ll_pass1 (ll1.LSeq [ll1.LLab 0, ll1.L (Arith ADD)])"
value "(inst_size (Arith ADD))"
(* get the label at the provided childpath, if it exists *)
type_synonym childpath = "nat list"
(* Q: better to return None or Some in nil case?
(i.e., return None and then make the base case part of get list) *)
fun ll_get_node :: "('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll \<Rightarrow> childpath \<Rightarrow> ('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll option" and
ll_get_node_list :: "('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll list \<Rightarrow> childpath \<Rightarrow> ('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll option" where
"ll_get_node T [] = Some T"
| "ll_get_node (q, LSeq e ls) p =
ll_get_node_list ls p"
| "ll_get_node _ _ = None"
| "ll_get_node_list _ [] = None" (* this should never happen *)
| "ll_get_node_list [] _ = None" (* this case will happen when *)
| "ll_get_node_list (h#ls) (0#p) = ll_get_node h p"
| "ll_get_node_list (_#ls) (n#p) =
ll_get_node_list (ls) ((n-1)#p)"
(* TODO: maybe have a function for "reifying" a ll \<Rightarrow> childpath \<Rightarrow> ll function
back into an ll? I guess we just need to pass it nil. *)
value "ll_get_node ((0,0), ((llt.LSeq () [((0,0),llt.LLab () 0), ((0,0),llt.LLab () 1)]))::ll2t) [1]"
(* alternate definition of descend, good in certain situations *)
inductive_set ll_descend_alt :: "(('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll * ('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll * childpath) set" where
"\<And> t t' kh kt . ll_get_node t (kh#kt) = Some t' \<Longrightarrow>
(t, t', kh#kt) \<in> ll_descend_alt"
inductive_set ll3'_descend_alt :: "(('lix, 'ljx, 'ljix, 'ptx, 'pnx) ll3' * ('lix, 'ljx, 'ljix, 'ptx, 'pnx) ll3' * childpath) set"
where
"\<And> t t' kh kt . ll_get_node t (kh#kt) = Some t' \<Longrightarrow>
(t, t', kh#kt) \<in> ll3'_descend_alt"
(* TODO: later generalize this to all lls, for now we are avoiding type annoyances by not *)
inductive_set ll3'_descend :: "(('lix, 'ljx, 'ljix, 'ptx, 'pnx) ll3' * ('lix, 'ljx, 'ljix, 'ptx, 'pnx) ll3' * childpath) set"
where
"\<And> q e ls t .
c < length ls \<Longrightarrow>
List.nth ls c = t \<Longrightarrow>
((q, LSeq e ls), t, [c]) \<in> ll3'_descend"
| "\<And> t t' n t'' n' .
(t, t', n) \<in> ll3'_descend \<Longrightarrow>
(t', t'', n') \<in> ll3'_descend \<Longrightarrow>
(t, t'', n @ n') \<in> ll3'_descend"
lemma ll_get_node_len [rule_format] :
"(! kh kt t' . ll_get_node_list ts (kh#kt) = Some t' \<longrightarrow> kh < length ts)"
proof(induction ts)
case Nil
then show ?case by auto
next
case (Cons a ts)
then show ?case
apply(auto)
apply(case_tac kh) apply(auto)
apply(drule_tac[1] x = nat in spec) apply(auto)
done
qed
lemma ll_get_node_nth [rule_format] :
"(! kh t' . ll_get_node_list ts [kh] = Some t' \<longrightarrow>
ts ! kh = t')"
proof(induction ts)
case Nil
then show ?case by auto
next
case (Cons a ts)
then show ?case apply(auto)
apply(case_tac kh) apply(auto)
done
qed
lemma ll_get_node_nth2 [rule_format] :
"(! kh . kh < length ts \<longrightarrow>
(! t' . ts ! kh = t' \<longrightarrow>
ll_get_node_list ts [kh] = Some t'))"
proof(induction ts)
case Nil
then show ?case by auto
next
case (Cons a ts)
then show ?case
apply(auto)
apply(case_tac kh) apply(auto)
done
qed
(* version of this for last child? *)
lemma ll_get_node_child [rule_format] :
"(! kh kt t' . ll_get_node_list ts (kh#kt) = Some t' \<longrightarrow>
(kh < length ts \<and>
ll_get_node (ts ! kh) kt = Some t'))"
proof(induction ts)
case Nil
then show ?case by auto
next
case (Cons a ts)
then show ?case
apply(auto) apply(case_tac kh, auto)
apply(case_tac kh, auto)
done
qed
(* need converse of previous lemma, to prove last-child lemma *)
lemma ll_get_node_child2 [rule_format] :
"(! t kh kt t' . ll_get_node t kt = Some t' \<longrightarrow>
kh < length ts \<longrightarrow>
ts ! kh = t \<longrightarrow>
ll_get_node_list ts (kh#kt) = Some t'
)"
proof(induction ts)
case Nil
then show ?case by auto
next
case (Cons a ts)
then show ?case
apply(auto)
apply(case_tac kh, auto)
done
qed
lemma ll_get_node_last [rule_format] :
"(! t kl t'' . ll_get_node t (k@[kl]) = Some t'' \<longrightarrow>
(? t' . ll_get_node t k = Some t' \<and>
ll_get_node t' [kl] = Some t''))
"
proof(induction k)
case Nil
then show ?case by auto
next
case (Cons a k)
then show ?case
apply(auto)
apply(case_tac ba, auto)
apply(frule_tac[1] ll_get_node_child)
apply(case_tac "x52 ! a", auto)
apply (drule_tac x = ab in spec) apply(drule_tac x = b in spec) apply(drule_tac[1] x = ba in spec)
apply(drule_tac x = kl in spec)
apply(auto)
apply(rule_tac x = aba in exI) apply(rule_tac x = bd in exI) apply(rule_tac x = be in exI)
apply(auto)
apply(case_tac k, auto) apply(rule_tac[1] ll_get_node_nth2) apply(auto)
apply(thin_tac "ll_get_node ((ab, b), ba) (ac # list @ [kl]) =
Some ((aa, bb), bc)")
apply(drule_tac ll_get_node_child2) apply(auto)
done
qed
lemma ll_get_node_last2 [rule_format] :
"((! t t' . ll_get_node t k = Some t' \<longrightarrow>
(! t'' kl . ll_get_node t' [kl] = Some t'' \<longrightarrow>
ll_get_node t (k@[kl]) = Some t'')))
"
proof(induction k)
case Nil
then show ?case by auto
next
case (Cons a k)
then show ?case
apply(auto)
apply(case_tac ba, auto)
apply(frule_tac ll_get_node_child, auto)
apply(case_tac "x52 ! a", auto)
apply(drule_tac x = ac in spec) apply(drule_tac x = b in spec) apply(drule_tac x = ba in spec)
apply(auto)
apply(drule_tac x = ab in spec) apply(drule_tac x = bd in spec) apply(drule_tac x = be in spec) apply(drule_tac x = kl in spec)
apply(clarsimp)
apply(thin_tac "ll_get_node ((ac, b), ba) k =
Some ((aa, bb), bc)")
apply(thin_tac "ll_get_node ((aa, bb), bc) [kl] =
Some ((ab, bd), be)")
apply(frule_tac ll_get_node_child2) apply(auto)
done qed
lemma ll_descend_eq_l2r [rule_format] :
"(! t kh t' . ll_get_node t (kh#kt) = Some t' \<longrightarrow>
(t, t', kh#kt) \<in> ll3'_descend)"
proof(induction kt)
case Nil
then show ?case
apply(auto)
apply(case_tac ba, auto)
apply(rule_tac[1] ll3'_descend.intros(1))
apply(auto simp add:ll_get_node_len)
apply(auto simp add:ll_get_node_nth)
done
next
case (Cons a kt)
then show ?case
apply(auto)
apply(case_tac ba) apply(auto)
apply(frule_tac[1] ll_get_node_len)
apply(subgoal_tac[1]
" (((aa, b), llt.LSeq x51 x52),
((aaa, bb), bc), [kh] @ (a # kt))
\<in> ll3'_descend")
apply(rule_tac[2] ll3'_descend.intros(2)) apply(auto)
apply(rule_tac[1] ll3'_descend.intros) apply(auto)
apply(case_tac x52, auto)
apply(drule_tac[1] ll_get_node_child)
apply(case_tac[1] "(((ab, b), ba) # list) ! kh", auto)
done
qed
lemma ll3_descend_nonnil :
"(t, t', k) \<in> ll3'_descend \<Longrightarrow>
(? hd tl . k = hd # tl)"
proof(induction rule:ll3'_descend.induct)
case 1 thus ?case
apply(auto)
done next
case 2 thus ?case
apply(auto)
done qed
lemma ll_get_node_comp [rule_format] :
"(! t' t'' . ll_get_node t' p' = Some t'' \<longrightarrow>
(! t p . ll_get_node t p = Some t' \<longrightarrow>
ll_get_node t (p@p') = Some t''))
"
proof(induction p')
case Nil
then show ?case by auto
next
case (Cons a p)
then show ?case
apply(auto)
apply(case_tac ba, auto)
apply(frule_tac[1] ll_get_node_child)
apply(case_tac[1] "x52 ! a") apply(auto)
apply(drule_tac x = ac in spec) apply(drule_tac x = ba in spec) apply(drule_tac[1] x = baa in spec)
apply(auto)
apply(drule_tac x = ab in spec) apply(drule_tac x = bd in spec) apply(drule_tac x = be in spec)
apply(drule_tac x = "pa @ [a]" in spec) apply(clarsimp)
apply(thin_tac[1] "ll_get_node ((ac, ba), baa) p =
Some ((aaa, bb), bc)")
apply(drule_tac[1] ll_get_node_last2) apply(auto)
apply(rule_tac ll_get_node_nth2) apply(auto)
done qed
lemma ll_descend_eq_r2l :
"((q, t), (q', t'), k) \<in> ll3'_descend \<Longrightarrow>
ll_get_node (q, t) k = Some (q', t')"
proof(induction rule:ll3'_descend.induct)
case (1 c q e ls t)
then show ?case
apply(auto)
apply(frule_tac[1] ll_get_node_nth2, auto)
done
next
case (2 t t' n t'' n')
then show ?case
apply(frule_tac[1] ll3_descend_nonnil)
apply(auto) apply(rotate_tac[1] 1)
apply(frule_tac[1] ll3_descend_nonnil) apply(auto)
apply(subgoal_tac " ll_get_node t ((hd # tl) @ (hda # tla)) =
Some t''")
apply(rule_tac[2] ll_get_node_comp) apply(auto)
done qed
lemma ll_descend_eq_l2r2 :
"x \<in> ll3'_descend_alt \<Longrightarrow> x \<in> ll3'_descend"
apply(case_tac x) apply(auto)
apply(drule_tac[1] ll3'_descend_alt.cases) apply(auto)
apply(drule_tac ll_descend_eq_l2r) apply(auto)
done
lemma ll_descend_eq_r2l2 :
"x \<in> ll3'_descend \<Longrightarrow> x \<in> ll3'_descend_alt"
apply(case_tac x) apply(auto)
apply(frule_tac ll3_descend_nonnil)
apply(drule_tac ll_descend_eq_r2l) apply(auto)
apply(rule_tac ll3'_descend_alt.intros) apply(auto)
done
lemma ll_descend_eq :
"ll3'_descend = ll3'_descend_alt"
apply(insert ll_descend_eq_l2r2)
apply(insert ll_descend_eq_r2l2)
apply(blast)
done
definition ll_valid_q3 :: "ll3 set" where
"ll_valid_q3 = ll_valid_q"
definition ll_validl_q3 :: "(qan * ll3 list) set" where
"ll_validl_q3 = ll_validl_q"
(*definition ll_valid_q3' :: "('lix, 'llx, 'ljx, 'ljix, nat list, 'ptx, 'pnx) ll set" where
"ll_valid_q3' = ll_valid_q"*)
definition ll_valid_q3' :: "('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll set" where
"ll_valid_q3' = {}"
definition ll_validl_q3' :: "(qan * (('lix, 'llx, 'ljx, 'ljix, nat list, 'ptx, 'pnx) ll list)) set" where
"ll_validl_q3' = ll_validl_q"
(* NB this is the notion of validity for ll3
that I am using right now*)
inductive_set ll_valid3' :: "('lix, 'ljx, 'ljix, 'ptx, 'pnx) ll3' set" where
"\<And> i e x. (x, i) \<in> ll_valid_qi \<Longrightarrow>
(x, L e i) \<in> ll_valid3'"
| "\<And> x d. (x, d) \<in> ll_valid_ql \<Longrightarrow>
(x, LLab True d) \<in> ll_valid3'"
| "\<And> e x d s. (x, d, s) \<in> ll_valid_qj \<Longrightarrow>
(x, (LJmp e d s)) \<in> ll_valid3'"
| "\<And> e x d s. (x, d, s) \<in> ll_valid_qji \<Longrightarrow>
(x, (LJmpI e d s)) \<in> ll_valid3'"
| "\<And> x l e . (x, l) \<in> ll_validl_q \<Longrightarrow>
(! z . z \<in> set l \<longrightarrow> z \<in> ll_valid3') \<Longrightarrow>
(\<not> (\<exists> k y e' . ((x, LSeq e l), (y, LLab e' (List.length k - 1)), k) \<in> ll3'_descend)) \<Longrightarrow>
(x, (LSeq [] l)) \<in> ll_valid3'"
| "\<And> x l e k y. (x, l) \<in> ll_validl_q \<Longrightarrow>
(! z . z \<in> set l \<longrightarrow> z \<in> ll_valid3') \<Longrightarrow>
(((x, LSeq e l), (y, LLab True (List.length k - 1)), k) \<in> ll3'_descend) \<Longrightarrow>
(! k' y' b . (((x, LSeq e l), (y', LLab b (List.length k' - 1)), k') \<in> ll3'_descend) \<longrightarrow> k = k') \<Longrightarrow>
(x, LSeq k l) \<in> ll_valid3'"
(* dump an l2 to l3, marking all labels as unconsumed *)
fun ll3_init :: "ll2 \<Rightarrow> ll3" where
"ll3_init (x, L e i) = (x, L e i)"
| "ll3_init (x, LLab e idx) = (x, LLab False idx)"
| "ll3_init (x, LJmp e idx s) = (x, LJmp e idx s)"
| "ll3_init (x, LJmpI e idx s) = (x, LJmpI e idx s)"
| "ll3_init (x, LSeq e ls) =
(x, LSeq [] (map ll3_init ls))"
lemma ll3_init_noquant :
"(fst (ll3_init l) = fst l) \<and>
(List.map (\<lambda> t . fst (ll3_init t)) ls = List.map fst ls)"
apply(induction rule:my_ll_induct, auto)
done
(* step one: prove that ll3_init does not touch qan's
maaybe this could be done using parametricity? *)
lemma ll3_init_pres :
"((q, l2) \<in> ll_valid_q \<longrightarrow> (ll3_init (q, l2)) \<in> ll_valid_q)\<and>
(((x,y), ls) \<in> ll_validl_q \<longrightarrow> ((x,y), (map ll3_init ls)) \<in> ll_validl_q)"
proof(induction rule: ll_valid_q_ll_validl_q.induct)
case 1 thus ?case by (auto simp add:ll_valid_q_ll_validl_q.intros) next
case 2 thus ?case by (auto simp add:ll_valid_q_ll_validl_q.intros) next
case 3 thus ?case by (auto simp add:ll_valid_q_ll_validl_q.intros) next
case 4 thus ?case by (auto simp add:ll_valid_q_ll_validl_q.intros) next
case 5 thus ?case by (auto simp add:ll_valid_q_ll_validl_q.intros) next
case 6 thus ?case by (auto simp add:ll_valid_q_ll_validl_q.intros) next
case (7 n h n' t n'') thus ?case using ll3_init_noquant[of "((n,n'),h)" "[]"]
apply(auto)
apply(case_tac "ll3_init ((n,n'),h)", clarsimp)
apply(rule ll_valid_q_ll_validl_q.intros(7), auto)
done
qed
value "ll3_init (ll_pass1 (ll1.LSeq [ll1.LLab 0])) :: ll3"
(* All of these predicates might not be needed. *)
(* this one is not the one we are using for consumes *)
(* it is worth a shot though, directly encoding the reverse as an inductive seems hard *)
inductive cp_less :: "childpath \<Rightarrow> childpath \<Rightarrow> bool" where
"\<And> n t . cp_less [] (n#t)"
| "\<And> n n' t t' . n < n' \<Longrightarrow> cp_less (n#t) (n'#t')"
| "\<And> n t t' . cp_less t t' \<Longrightarrow> cp_less (n#t) (n#t')"
(* i'm worried this is not correctly capturing preorder traversal
it seems like it might be DFS instead...*)
inductive cp_rev_less' :: "childpath \<Rightarrow> childpath \<Rightarrow> bool" where
"\<And> n t . cp_rev_less' [] (n#t)"
| "\<And> n n' t . n < n' \<Longrightarrow> cp_rev_less' (n#t) (n'#t)"
| "\<And> t t' n n' . cp_rev_less' t t' \<Longrightarrow> cp_rev_less' (n#t) (n'#t')"
inductive cp_rev_less :: "childpath \<Rightarrow> childpath \<Rightarrow> bool" where
"\<And> (n::nat) (t::childpath) . cp_rev_less [] (t@[n])"
| "\<And> n n' t t' . n < n' \<Longrightarrow> cp_rev_less (t@[n]) (t'@[n'])"
| "\<And> (t :: childpath) (t' :: childpath) l. cp_rev_less t t' \<Longrightarrow> cp_rev_less (t@l) (t'@l)"
(* we need to capture incrementing a childpath *)
fun cp_next :: "childpath \<Rightarrow> childpath" where
"cp_next [] = []"
| "cp_next (h#t) = (Suc h)#t"
(* this should be "plus anything"? *)
lemma cp_rev_less'_suc1 :
"cp_rev_less' k p \<Longrightarrow>
(! n t . k = Suc n # t \<longrightarrow>
cp_rev_less' (n#t) p)"
apply(induction rule: cp_rev_less'.induct)
apply(auto simp add:cp_rev_less'.intros)
done
lemma cp_rev_less_sing' :
"n < n' \<Longrightarrow> cp_rev_less ([]@[n]) ([]@[n'])"
apply(rule_tac cp_rev_less.intros) apply(auto)
done
lemma cp_rev_less_sing :
"n < n' \<Longrightarrow> cp_rev_less [n] [n']"
apply(insert cp_rev_less_sing') apply(auto)
done
lemma cp_rev_less_least :
"cp_rev_less p k \<Longrightarrow> k \<noteq> []"
apply(induction rule:cp_rev_less.induct)
apply(auto)
done
lemma cp_less_least :
"cp_less p k \<Longrightarrow> k \<noteq> []"
apply(induction rule:cp_less.induct)
apply(auto)
done
type_synonym consume_label_result = "(ll3 list * childpath) option"
(* this prevents multiple locations for the same label name
because it will only "consume" one label per name
and then it will fail later on the other one *)
(* subroutine for assign_label, marks label as consumed *)
fun ll3_consume_label :: "childpath \<Rightarrow> nat \<Rightarrow> ll3 list \<Rightarrow> consume_label_result" where
"ll3_consume_label p n [] = Some ([], [])"
(* Actually consume the label, but it must not be consumed yet *)
| "ll3_consume_label p n ((x, LLab b idx) # ls) =
(if idx = length p then (if b = False then Some ((x, LLab True idx)#ls, n#p) else None)
else case (ll3_consume_label p (n+1) ls) of
Some (ls', p') \<Rightarrow> Some ((x, LLab b idx)#ls', p')
| None \<Rightarrow> None)"
| "ll3_consume_label p n ((x, LSeq e lsdec) # ls) =
(case ll3_consume_label (n#p) 0 lsdec of
Some (lsdec', []) \<Rightarrow> (case ll3_consume_label p (n+1) ls of
Some (ls', p') \<Rightarrow> Some (((x, LSeq e lsdec') # ls'), p')
| None \<Rightarrow> None)
| Some (lsdec', p') \<Rightarrow> Some (((x, LSeq e lsdec') # ls), p')
| None \<Rightarrow> None)"
| "ll3_consume_label p n (T#ls) =
(case ll3_consume_label p (n+1) ls of
Some (ls', p') \<Rightarrow> Some ((T#ls'), p')
| None \<Rightarrow> None)"
fun numnodes :: "('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll \<Rightarrow> nat" and
numnodes_l :: "('lix, 'llx, 'ljx, 'ljix, 'lsx, 'ptx, 'pnx) ll list \<Rightarrow> nat" where
"numnodes (_, LSeq _ xs) = 1 + numnodes_l xs"
| "numnodes _ = 1"
| "numnodes_l [] = 1"
| "numnodes_l (h#t) = numnodes h + numnodes_l t"
(* should we shove the quantifiers into the Some case? *)
(* Another option, return a bool representing failure ? *)
(* no, i think we can just add a thing to the first case about
how the numnodes of the result is less than original *)
(* we need another side for l, regarding what happens if l's head is an lseq *)
lemma ll3_consume_label_numnodes [rule_format] :
"
(! e l l' p p' n q . t = (q, LSeq e l) \<longrightarrow> ll3_consume_label p n l = Some (l',p') \<longrightarrow> numnodes t \<ge> numnodes_l l' + 1) \<and>
(! l' p p' n . ll3_consume_label p n l = Some (l', p') \<longrightarrow> numnodes_l l \<ge> numnodes_l l')"
proof(induction rule:my_ll_induct)
case 1 thus ?case by auto next
case 2 thus ?case by auto next
case 3 thus ?case by auto next
case 4 thus ?case by auto next
case (5 q e l) thus ?case by auto next
case 6 thus ?case by auto next
case (7 h l) thus ?case
apply(case_tac h)
apply(clarsimp)
apply(case_tac ba, clarsimp)
apply(case_tac[1] "ll3_consume_label p (Suc n) l", clarsimp, auto)
apply(blast)
apply(case_tac[1] "x22 = length p", clarsimp)
apply(case_tac[1] "x21", clarsimp, auto)
apply(case_tac[1] "ll3_consume_label p (Suc n) l", clarsimp, auto, blast)
apply(case_tac[1] "ll3_consume_label p (Suc n) l", clarsimp, auto, blast)
apply(case_tac[1] "ll3_consume_label p (Suc n) l", clarsimp, auto, blast)
apply(case_tac[1] "ll3_consume_label (n#p) 0 x52", clarsimp, auto)
apply(case_tac[1] "ba", clarsimp, auto)
apply(case_tac[1] "ll3_consume_label p (Suc n) l", clarsimp, auto)
apply(drule_tac [1] x = aa in spec)
apply(drule_tac [1] x = ab in spec)
apply(auto)
done
qed
lemma ll3_consume_label_numnodes1 : "ll3_consume_label p n l = Some (l', p') \<Longrightarrow> numnodes_l l \<ge> numnodes_l l'"
apply(insert ll3_consume_label_numnodes)
apply(blast)
done
lemma ll3_consume_label_qvalid' :
"((q, t) \<in> ll_valid_q \<longrightarrow> (! ls e . t = (LSeq e ls) \<longrightarrow> (! p p' n ls' . ll3_consume_label p n ls = Some (ls', p') \<longrightarrow> (q, LSeq e ls') \<in> ll_valid_q)))
\<and> (((x,x'), ls) \<in> ll_validl_q \<longrightarrow> (! p p' n ls' . ll3_consume_label p n ls = Some (ls', p') \<longrightarrow> ((x,x'), ls') \<in> ll_validl_q ))"
apply(induction rule:ll_valid_q_ll_validl_q.induct, auto simp add:ll_valid_q_ll_validl_q.intros)
apply(case_tac h, auto)
apply(case_tac[1] "ll3_consume_label p (Suc na) t", auto simp add:ll_valid_q_ll_validl_q.intros)
apply(case_tac [1] "x22 = length p", clarsimp)
apply(case_tac [1] "\<not>x21", clarsimp, auto)
apply(rule_tac [1] "ll_valid_q_ll_validl_q.intros", auto)
apply(erule_tac [1] "ll_valid_q.cases", auto simp add:ll_valid_q_ll_validl_q.intros)
apply(case_tac [1] "ll3_consume_label p (Suc na) t", auto)
apply(rule_tac [1] "ll_valid_q_ll_validl_q.intros", auto)
apply(case_tac [1] "ll3_consume_label p (Suc na) t", auto simp add:ll_valid_q_ll_validl_q.intros)
apply(case_tac [1] "ll3_consume_label p (Suc na) t", auto simp add:ll_valid_q_ll_validl_q.intros)
apply(case_tac "ll3_consume_label (na # p) 0 x52", auto)
apply(case_tac b, auto)
apply(case_tac [1] "ll3_consume_label p (Suc na) t", auto simp add:ll_valid_q_ll_validl_q.intros)
done
lemma ll3_consume_label_qvalid :
"(q,ls) \<in> ll_validl_q \<Longrightarrow> ll3_consume_label p n ls = Some (ls', p') \<Longrightarrow> (q, ls') \<in> ll_validl_q"
apply(insert ll3_consume_label_qvalid')
apply(case_tac q)
apply(auto)
done
lemma ll3_consume_label_hdq' :
"(! e q qh h ts. t = (q, LSeq e ((qh,h)#ts)) \<longrightarrow>
(! p n l' p'. ll3_consume_label p n ((qh,h)#ts) = Some (l',p') \<longrightarrow>
(? qh' h' ts' . l' = ((qh',h' )#ts') \<and> qh = qh')))
\<and>
(! qh h ts . l = ((qh,h)#ts) \<longrightarrow>
(! p n l' p' . ll3_consume_label p n l = Some (l', p') \<longrightarrow>
(? qh' h' ts' . l' = ((qh',h' )#ts') \<and> qh = qh')))"
apply(induction rule:my_ll_induct)
apply(auto)
apply(case_tac[1] h, auto)
apply(case_tac[1] "ll3_consume_label p (Suc n) ts", auto)
apply(case_tac [1] "x22 = length p", auto)
apply(case_tac [1] "\<not>x21", auto)
apply(case_tac[1] "ll3_consume_label p (Suc n) ts", auto)
apply(case_tac[1] "ll3_consume_label p (Suc n) ts", auto)
apply(case_tac[1] "ll3_consume_label p (Suc n) ts", auto)
apply(case_tac [1] "ll3_consume_label (n # p) 0 x52", auto)
apply(rename_tac [1] boo)
apply(case_tac [1] boo, auto)
apply(case_tac[1] "ll3_consume_label p (Suc n) ts", auto)
apply(case_tac[1] h, auto)
apply(case_tac[1] "ll3_consume_label p (Suc n) ts", auto)
apply(case_tac [1] "x22 = length p", auto)
apply(case_tac [1] "\<not>x21", auto)
apply(case_tac[1] "ll3_consume_label p (Suc n) ts", auto)
apply(case_tac[1] "ll3_consume_label p (Suc n) ts", auto)