-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimplEmbedding.thy
1295 lines (1213 loc) · 46.3 KB
/
SimplEmbedding.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
(*
* Copyright (c) 2020, CleanQ Project - Systems Group, ETH Zurich
* All rights reserved.
*
* This software may be distributed and modified according to the terms of
* the BSD 2-Clause license. Note that NO WARRANTY is provided.
*
* See "LICENSE" for details.
*
* SPDX-License-Identifier: BSD-2-Clause
*)
theory SimplEmbedding imports "Simpl/Simpl" "Complx/OG_Hoare" begin
text \<open>All primitves are embedded 1-1\<close>
primrec embedSimpl :: "('s, 'p, 'f) Language.com \<Rightarrow> ('s, 'p, 'f) OG_Language.com"
where
"embedSimpl Language.com.Skip = OG_Language.com.Skip"
| "embedSimpl (Language.com.Basic f) = OG_Language.com.Basic f"
| "embedSimpl (Language.com.Spec S) = OG_Language.com.Spec S"
| "embedSimpl (Language.com.Seq a b) = OG_Language.com.Seq (embedSimpl a) (embedSimpl b)"
| "embedSimpl (Language.com.Cond G a b) = OG_Language.com.Cond G (embedSimpl a) (embedSimpl b)"
| "embedSimpl (Language.com.While G b) = OG_Language.com.While G (embedSimpl b)"
| "embedSimpl (Language.com.Call p) = OG_Language.com.Call p"
| "embedSimpl (Language.com.DynCom dc) = OG_Language.com.DynCom (embedSimpl o dc)"
| "embedSimpl (Language.com.Guard f G b) = OG_Language.com.Guard f G (embedSimpl b)"
| "embedSimpl Language.com.Throw = OG_Language.com.Throw"
| "embedSimpl (Language.com.Catch a b) = OG_Language.com.Catch (embedSimpl a) (embedSimpl b)"
lemma embedSimpl_inj:
"inj embedSimpl"
proof(rule injI)
fix c1 c2::"('s,'p,'f) Language.com"
assume "embedSimpl c1 = embedSimpl c2"
thus "c1 = c2"
proof(induct c1 arbitrary:c2)
case Skip
then show ?case by(cases c2, auto)
next
case (Basic f)
then show ?case by(cases c2, auto)
next
case (Spec r)
then show ?case by(cases c2, auto)
next
case (Seq c11 c12)
then show ?case by(cases c2, auto)
next
case (Cond b c11 c12)
then show ?case by(cases c2, auto)
next
case (While b c)
then show ?case by(cases c2, auto)
next
case (Call p)
then show ?case by(cases c2, auto)
next
case (DynCom c)
note outer = this
then show ?case
proof(cases c2)
case Skip
with DynCom show ?thesis by(auto)
next
case (Basic x2)
with DynCom show ?thesis by(auto)
next
case (Spec x3)
with DynCom show ?thesis by(auto)
next
case (Seq x41 x42)
with DynCom show ?thesis by(auto)
next
case (Cond x51 x52 x53)
with DynCom show ?thesis by(auto)
next
case (While x61 x62)
with DynCom show ?thesis by(auto)
next
case (Call x7)
with DynCom show ?thesis by(auto)
next
case (DynCom c')
text \<open>This is the only non-trivial case. The induction hypothesis + extensionality give us
equality on the computations: c = c'.\<close>
{
fix s
have "embedSimpl (c s) = (embedSimpl o c) s" by(simp)
also {
from DynCom outer have "OG_Language.DynCom (embedSimpl o c) = OG_Language.DynCom (embedSimpl o c')"
by(simp)
hence "(embedSimpl o c) s = (embedSimpl o c') s"
by(auto)
}
also have "(embedSimpl o c') s = embedSimpl (c' s)" by(simp)
finally have "c s = c' s"
using outer by(auto)
}
hence "c = c'" by(rule ext)
with DynCom outer show ?thesis by(simp)
next
case (Guard x91 x92 x93)
with DynCom show ?thesis by(auto)
next
case Throw
with DynCom show ?thesis by(auto)
next
case (Catch x111 x112)
with DynCom show ?thesis by(auto)
qed
next
case (Guard x1 x2a c1)
then show ?case by(cases c2, auto)
next
case Throw
then show ?case by(cases c2, auto)
next
case (Catch c11 c12)
then show ?case by(cases c2, auto)
qed
qed
definition embedContext :: "('s,'p,'f) Semantic.body \<Rightarrow> ('s,'p,'f) OG_SmallStep.body"
where
"embedContext \<Gamma> = (\<lambda>x. case x of None \<Rightarrow> None | Some c \<Rightarrow> Some (embedSimpl c)) o \<Gamma>"
text \<open>The Simpl-Complx state relation is 1-1, but excludes the Simpl Abrupt state.\<close>
function (sequential) stateRel :: "('s, 'f) Semantic.xstate \<Rightarrow> ('s, 'f) OG_SmallStep.xstate \<Rightarrow> bool"
where
"stateRel (Semantic.Normal s) (OG_SmallStep.Normal s_og) \<longleftrightarrow> s = s_og"
| "stateRel (Semantic.Fault f) (OG_SmallStep.Fault f_og) \<longleftrightarrow> f = f_og"
| "stateRel Semantic.Stuck OG_SmallStep.Stuck \<longleftrightarrow> True"
| "stateRel xs xs_og \<longleftrightarrow> False"
by(pat_completeness, auto)
termination by(lexicographic_order)
lemma stateRel_sv_fwd:
"single_valuedp stateRel"
proof(rule single_valuedpI)
fix x y z
assume rxy: "stateRel x y" and rxz: "stateRel x z"
show "y = z"
proof(cases x)
case (Normal s)
from Normal rxy have "y = OG_SmallStep.Normal s" by(cases y, auto)
moreover from Normal rxz have "z = OG_SmallStep.Normal s" by(cases z, auto)
ultimately show ?thesis by(simp)
next
case (Abrupt f)
with rxy show ?thesis by(auto)
next
case (Fault f)
from Fault rxy have "y = OG_SmallStep.Fault f" by(cases y, auto)
moreover from Fault rxz have "z = OG_SmallStep.Fault f" by(cases z, auto)
ultimately show ?thesis by(simp)
next
case Stuck
from Stuck rxy have "y = OG_SmallStep.Stuck" by(cases y, auto)
moreover from Stuck rxz have "z = OG_SmallStep.Stuck" by(cases z, auto)
ultimately show ?thesis by(simp)
qed
qed
lemma stateRel_sv_rev:
"single_valuedp (conversep stateRel)"
proof(rule single_valuedpI)
fix x y z
assume rxy: "(conversep stateRel) x y" and rxz: "(conversep stateRel) x z"
show "y = z"
proof(cases x)
case (Normal s)
from Normal rxy have "y = Semantic.Normal s" by(cases y, auto)
moreover from Normal rxz have "z = Semantic.Normal s" by(cases z, auto)
ultimately show ?thesis by(simp)
next
case (Fault f)
from Fault rxy have "y = Semantic.Fault f" by(cases y, auto)
moreover from Fault rxz have "z = Semantic.Fault f" by(cases z, auto)
ultimately show ?thesis by(simp)
next
case Stuck
from Stuck rxy have "y = Semantic.Stuck" by(cases y, auto)
moreover from Stuck rxz have "z = Semantic.Stuck" by(cases z, auto)
ultimately show ?thesis by(simp)
qed
qed
lemma stateRel_fw_Normal:
"stateRel (Semantic.Normal s) xs_og \<Longrightarrow> xs_og = OG_SmallStep.Normal s"
by(cases xs_og, auto)
lemma stateRel_rev_Normal:
"stateRel xs (OG_SmallStep.Normal s) \<Longrightarrow> xs = Semantic.Normal s"
by(cases xs, auto)
lemma stateRel_fw_Fault:
"stateRel (Semantic.Fault f) xs_og \<Longrightarrow> xs_og = OG_SmallStep.Fault f"
by(cases xs_og, auto)
lemma stateRel_rev_Fault:
"stateRel xs (OG_SmallStep.Fault f) \<Longrightarrow> xs = Semantic.Fault f"
by(cases xs, auto)
lemma stateRel_fw_Stuck:
"stateRel Semantic.Stuck xs_og \<Longrightarrow> xs_og = OG_SmallStep.Stuck"
by(cases xs_og, auto)
lemma stateRel_rev_Stuck:
"stateRel xs OG_SmallStep.Stuck \<Longrightarrow> xs = Semantic.Stuck"
by(cases xs, auto)
lemma stateRel_no_Abrupt:
"stateRel xs xs_og \<Longrightarrow> \<not>isAbr xs"
by(cases xs, auto)
lemmas stateRel_rewrites =
stateRel_fw_Normal stateRel_rev_Normal
stateRel_fw_Fault stateRel_rev_Fault
stateRel_fw_Stuck stateRel_rev_Stuck
stateRel_no_Abrupt
primrec com_size :: "('s,'p,'f) Language.com \<Rightarrow> nat"
where "com_size Language.Skip = 1" |
"com_size (Language.Basic f) = 1" |
"com_size (Language.Spec r) = 1" |
"com_size (Language.Seq c1 c2) = com_size c1 + com_size c2 + 1" |
"com_size (Language.Cond b c1 c2) = com_size c1 + com_size c2 + 1" |
"com_size (Language.While b c) = com_size c + 1" |
"com_size (Language.Call p) = 1" |
"com_size (Language.DynCom d) = 1" |
"com_size (Language.Guard f g c) = com_size c + 1" |
"com_size Language.Throw = 1" |
"com_size (Language.Catch c1 c2) = com_size c1 + com_size c2 + 1"
lemma redex_size_le:
"com_size (SmallStep.redex c) \<le> com_size c"
by(induct c, auto)
lemma redex_Seq_ne:
fixes c1 c2
shows "SmallStep.redex (Language.Seq c1 c2) \<noteq> Language.Seq c1 c2"
proof
assume "SmallStep.redex (Language.Seq c1 c2) = Language.Seq c1 c2"
hence "com_size (Language.Seq c1 c2) = com_size (SmallStep.redex c1)"
by(simp)
also from redex_size_le have "... \<le> com_size c1"
by(auto)
also have "... < com_size (Language.Seq c1 c2)"
by(simp)
finally show False
by(simp)
qed
lemma redex_Catch_ne:
fixes c1 c2
shows "SmallStep.redex (Language.Catch c1 c2) \<noteq> Language.Catch c1 c2"
proof
assume "SmallStep.redex (Language.Catch c1 c2) = Language.Catch c1 c2"
hence "com_size (Language.Catch c1 c2) = com_size (SmallStep.redex c1)"
by(simp)
also from redex_size_le have "... \<le> com_size c1"
by(auto)
also have "... < com_size (Language.Catch c1 c2)"
by(simp)
finally show False
by(simp)
qed
primrec og_com_size :: "('s,'p,'f) OG_Language.com \<Rightarrow> nat"
where "og_com_size OG_Language.Skip = 1" |
"og_com_size (OG_Language.Basic f) = 1" |
"og_com_size (OG_Language.Spec r) = 1" |
"og_com_size (OG_Language.Seq c1 c2) = og_com_size c1 + og_com_size c2 + 1" |
"og_com_size (OG_Language.Cond b c1 c2) = og_com_size c1 + og_com_size c2 + 1" |
"og_com_size (OG_Language.While b c) = og_com_size c + 1" |
"og_com_size (OG_Language.Call p) = 1" |
"og_com_size (OG_Language.DynCom d) = 1" |
"og_com_size (OG_Language.Guard f g c) = og_com_size c + 1" |
"og_com_size OG_Language.Throw = 1" |
"og_com_size (OG_Language.Catch c1 c2) = og_com_size c1 + og_com_size c2 + 1" |
"og_com_size (OG_Language.Parallel s) = (sum_list (map og_com_size s)) + 1" |
"og_com_size (OG_Language.Await g c) = og_com_size c + 1"
lemma og_redex_size_le:
"og_com_size (OG_SmallStep.redex c) \<le> og_com_size c"
by(induct c, auto)
lemma og_redex_Seq_ne:
fixes c1 c2
shows "OG_SmallStep.redex (OG_Language.Seq c1 c2) \<noteq> OG_Language.Seq c1 c2"
proof
assume "OG_SmallStep.redex (OG_Language.Seq c1 c2) = OG_Language.Seq c1 c2"
hence "og_com_size (OG_Language.Seq c1 c2) = og_com_size (OG_SmallStep.redex c1)"
by(simp)
also from og_redex_size_le have "... \<le> og_com_size c1"
by(auto)
also have "... < og_com_size (OG_Language.Seq c1 c2)"
by(simp)
finally show False
by(simp)
qed
lemma og_redex_Catch_ne:
fixes c1 c2
shows "OG_SmallStep.redex (OG_Language.Catch c1 c2) \<noteq> OG_Language.Catch c1 c2"
proof
assume "OG_SmallStep.redex (OG_Language.Catch c1 c2) = OG_Language.Catch c1 c2"
hence "og_com_size (OG_Language.Catch c1 c2) = og_com_size (OG_SmallStep.redex c1)"
by(simp)
also from og_redex_size_le have "... \<le> og_com_size c1"
by(auto)
also have "... < og_com_size (OG_Language.Catch c1 c2)"
by(simp)
finally show False
by(simp)
qed
text \<open>The embedding is closed: For any step of the embedded computation, we can find a step
in the Simpl semantics that corresponds to it.\<close>
lemma embedSimpl_fwd_refine:
assumes sr: "stateRel xs xs_og"
and embed_step: "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl c, xs_og) (c_og', xs_og')"
shows "\<exists>c' xs'. c_og' = embedSimpl c' \<and> SmallStep.step \<Gamma> (c, xs) (c', xs') \<and> stateRel xs' xs_og'"
using embed_step
proof(induct c arbitrary:c_og' xs_og')
case Skip
thus ?case
by(auto intro:OG_SmallStep.no_step_final[unfolded OG_SmallStep.final_def])
next
case (Basic f)
from Basic.prems[simplified] show ?case
proof(cases rule:OG_SmallStep.step_elim_cases(3))
case (1 s)
from 1 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 1 have "stateRel (Semantic.Normal (f s)) xs_og'" by(simp)
moreover {
from 1 sr have "xs = Semantic.Normal s" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Basic f, xs) (Language.Skip, Semantic.Normal (f s))"
by(auto intro:SmallStep.step.Basic)
}
ultimately show ?thesis by(blast)
next
case (2 flt)
from 2 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 2 have "stateRel (Semantic.Fault flt) xs_og'" by(simp)
moreover {
from 2 sr have "xs = Semantic.Fault flt" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Basic f, xs) (Language.Skip, Semantic.Fault flt)"
by(auto intro:SmallStep.step.FaultProp)
}
ultimately show ?thesis by(blast)
next
case 3
from 3 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 3 have "stateRel Semantic.Stuck xs_og'" by(simp)
moreover {
from 3 sr have "xs = Semantic.Stuck" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Basic f, xs) (Language.Skip, Semantic.Stuck)"
by(auto intro:SmallStep.step.StuckProp)
}
ultimately show ?thesis by(blast)
qed
next
case (Spec r)
from Spec.prems[simplified] show ?case
proof(cases rule:OG_SmallStep.step_elim_cases(4))
case (1 s t)
from 1 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 1 have "stateRel (Semantic.Normal t) xs_og'" by(simp)
moreover {
from 1 sr have "xs = Semantic.Normal s" by(cases xs, auto)
with 1 have "SmallStep.step \<Gamma> (Language.Spec r, xs) (Language.Skip, Semantic.Normal t)"
by(auto intro:SmallStep.step.Spec)
}
ultimately show ?thesis by(blast)
next
case (2 s)
from 2 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 2 have "stateRel Semantic.Stuck xs_og'" by(simp)
moreover {
from 2 sr have "xs = Semantic.Normal s" by(cases xs, auto)
with 2 have "SmallStep.step \<Gamma> (Language.Spec r, xs) (Language.Skip, Semantic.Stuck)"
by(auto intro:SmallStep.step.SpecStuck)
}
ultimately show ?thesis by(blast)
next
case (3 flt)
from 3 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 3 have "stateRel (Semantic.Fault flt) xs_og'" by(simp)
moreover {
from 3 sr have "xs = Semantic.Fault flt" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Spec r, xs) (Language.Skip, Semantic.Fault flt)"
by(auto intro:SmallStep.step.FaultProp)
}
ultimately show ?thesis by(blast)
next
case 4
from 4 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 4 have "stateRel Semantic.Stuck xs_og'" by(simp)
moreover {
from 4 sr have "xs = Semantic.Stuck" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Spec r, xs) (Language.Skip, Semantic.Stuck)"
by(auto intro:SmallStep.step.StuckProp)
}
ultimately show ?thesis by(blast)
qed
next
case (Seq c1 c2)
from Seq.prems[simplified] show ?case
proof(cases rule:OG_SmallStep.step_elim_cases(5))
case (1 c1_og s_og)
with Seq.hyps(1) obtain c' xs'
where embed_IH: "c1_og = embedSimpl c'"
and step_IH: "SmallStep.step \<Gamma> (c1, xs) (c', xs')"
and sr_IH: "stateRel xs' s_og"
by(blast)
from 1 embed_IH
have "c_og' = embedSimpl (Language.Seq c' c2)" by(simp)
moreover from 1 sr_IH
have "stateRel xs' xs_og'" by(simp)
moreover from step_IH
have "SmallStep.step \<Gamma> (Language.Seq c1 c2, xs) (Language.Seq c' c2, xs')"
by(rule SmallStep.step.Seq)
ultimately show ?thesis by(blast)
next
case 2
from 2 have "c_og' = embedSimpl c2" by(simp)
moreover from 2 sr have "stateRel xs xs_og'" by(simp)
moreover {
from 2 have "c1 = Language.Skip" by(cases c1, auto)
hence "SmallStep.step \<Gamma> (Language.Seq c1 c2, xs) (c2, xs)"
by(auto intro:SmallStep.step.SeqSkip)
}
ultimately show ?thesis by(blast)
next
case (3 s)
from 3 have "c_og' = embedSimpl Language.Throw" by(simp)
moreover from 3 sr have "stateRel xs xs_og'" by(simp)
moreover {
from 3 have "c1 = Language.Throw" by(cases c1, auto)
moreover from 3 sr have "xs = Semantic.Normal s" by(cases xs, auto)
ultimately have "SmallStep.step \<Gamma> (Language.Seq c1 c2, xs) (Language.Throw, xs)"
by(auto intro:SmallStep.step.SeqThrow)
}
ultimately show ?thesis by(blast)
next
case (4 f)
with og_redex_Seq_ne show ?thesis by(blast)
next
case 5
with og_redex_Seq_ne show ?thesis by(blast)
qed
next
case (Cond b c1 c2)
from Cond.prems[simplified] show ?case
proof(cases rule:OG_SmallStep.step_elim_cases(6))
case (1 s)
from 1 have "c_og' = embedSimpl c1" by(simp)
moreover from 1 sr have "stateRel xs xs_og'" by(simp)
moreover {
from 1 sr have "xs = Semantic.xstate.Normal s" by(cases xs, auto)
with 1 have "SmallStep.step \<Gamma> (Language.Cond b c1 c2, xs) (c1, xs)"
by(auto intro:SmallStep.step.CondTrue)
}
ultimately show ?thesis by(blast)
next
case (2 s)
from 2 have "c_og' = embedSimpl c2" by(simp)
moreover from 2 sr have "stateRel xs xs_og'" by(simp)
moreover {
from 2 sr have "xs = Semantic.xstate.Normal s" by(cases xs, auto)
with 2 have "SmallStep.step \<Gamma> (Language.Cond b c1 c2, xs) (c2, xs)"
by(auto intro:SmallStep.step.CondFalse)
}
ultimately show ?thesis by(blast)
next
case (3 flt)
from 3 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 3 have "stateRel (Semantic.Fault flt) xs_og'" by(simp)
moreover {
from 3 sr have "xs = Semantic.Fault flt" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Cond b c1 c2, xs) (Language.Skip, Semantic.Fault flt)"
by(auto intro:SmallStep.step.FaultProp)
}
ultimately show ?thesis by(blast)
next
case 4
from 4 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 4 have "stateRel Semantic.Stuck xs_og'" by(simp)
moreover {
from 4 sr have "xs = Semantic.Stuck" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Cond b c1 c2, xs) (Language.Skip, Semantic.Stuck)"
by(auto intro:SmallStep.step.StuckProp)
}
ultimately show ?thesis by(blast)
qed
next
case (While b c)
from While.prems[simplified] show ?case
proof(cases rule:OG_SmallStep.step_elim_cases(7))
case (1 s)
from 1 have "c_og' = embedSimpl (Language.Seq c (Language.While b c))" by(simp)
moreover from 1 sr have "stateRel xs xs_og'" by(simp)
moreover {
from 1 sr have "xs = Semantic.xstate.Normal s" by(cases xs, auto)
with 1 have "SmallStep.step \<Gamma> (Language.While b c, xs) (Language.Seq c (Language.While b c), xs)"
by(auto intro:SmallStep.step.WhileTrue)
}
ultimately show ?thesis by(blast)
next
case (2 s)
from 2 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 2 sr have "stateRel xs xs_og'" by(simp)
moreover {
from 2 sr have "xs = Semantic.xstate.Normal s" by(cases xs, auto)
with 2 have "SmallStep.step \<Gamma> (Language.While b c, xs) (Language.Skip, xs)"
by(auto intro:SmallStep.step.WhileFalse)
}
ultimately show ?thesis by(blast)
next
case (3 flt)
from 3 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 3 have "stateRel (Semantic.Fault flt) xs_og'" by(simp)
moreover {
from 3 sr have "xs = Semantic.Fault flt" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.While b c, xs) (Language.Skip, Semantic.Fault flt)"
by(auto intro:SmallStep.step.FaultProp)
}
ultimately show ?thesis by(blast)
next
case 4
from 4 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 4 have "stateRel Semantic.Stuck xs_og'" by(simp)
moreover {
from 4 sr have "xs = Semantic.Stuck" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.While b c, xs) (Language.Skip, Semantic.Stuck)"
by(auto intro:SmallStep.step.StuckProp)
}
ultimately show ?thesis by(blast)
qed
next
case (Call p)
from Call.prems[simplified] show ?case
proof(cases rule:OG_SmallStep.step_elim_cases(8))
case (1 b_og s)
from 1 obtain b where b_og_rw:"b_og = embedSimpl b" and lookup: "\<Gamma> p = Some b"
unfolding embedContext_def o_def
by(cases "\<Gamma> p", auto)
with 1 have "c_og' = embedSimpl b" by(simp)
moreover from 1 sr have "stateRel xs xs_og'" by(simp)
moreover {
from 1 sr have "xs = Semantic.xstate.Normal s" by(cases xs, auto)
with lookup have "SmallStep.step \<Gamma> (Language.Call p, xs) (b, xs)"
by(auto intro:SmallStep.step.Call)
}
ultimately show ?thesis by(blast)
next
case (2 s)
with 2 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 2 sr have "stateRel Semantic.Stuck xs_og'" by(simp)
moreover {
from 2 sr have "xs = Semantic.xstate.Normal s" by(cases xs, auto)
moreover from 2 have "\<Gamma> p = None"
unfolding embedContext_def o_def
by(cases "\<Gamma> p", auto)
ultimately have "SmallStep.step \<Gamma> (Language.Call p, xs) (Language.Skip, Semantic.Stuck)"
by(auto intro:SmallStep.step.CallUndefined)
}
ultimately show ?thesis by(blast)
next
case (3 flt)
from 3 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 3 have "stateRel (Semantic.Fault flt) xs_og'" by(simp)
moreover {
from 3 sr have "xs = Semantic.Fault flt" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Call p, xs) (Language.Skip, Semantic.Fault flt)"
by(auto intro:SmallStep.step.FaultProp)
}
ultimately show ?thesis by(blast)
next
case 4
from 4 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 4 have "stateRel Semantic.Stuck xs_og'" by(simp)
moreover {
from 4 sr have "xs = Semantic.Stuck" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Call p, xs) (Language.Skip, Semantic.Stuck)"
by(auto intro:SmallStep.step.StuckProp)
}
ultimately show ?thesis by(blast)
qed
next
case (DynCom c)
from DynCom.prems[simplified] show ?case
proof(cases rule:OG_SmallStep.step_elim_cases(9))
case (1 s)
from 1 have "c_og' = embedSimpl (c s)" by(simp)
moreover from 1 sr have "stateRel xs xs_og'" by(simp)
moreover {
from 1 sr have "xs = Semantic.xstate.Normal s" by(cases xs, auto)
with 1 have "SmallStep.step \<Gamma> (Language.DynCom c, xs) (c s, xs)"
by(auto intro:SmallStep.step.DynCom)
}
ultimately show ?thesis by(blast)
next
case (2 flt)
from 2 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 2 have "stateRel (Semantic.Fault flt) xs_og'" by(simp)
moreover {
from 2 sr have "xs = Semantic.Fault flt" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.DynCom c, xs) (Language.Skip, Semantic.Fault flt)"
by(auto intro:SmallStep.step.FaultProp)
}
ultimately show ?thesis by(blast)
next
case 3
from 3 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 3 have "stateRel Semantic.Stuck xs_og'" by(simp)
moreover {
from 3 sr have "xs = Semantic.Stuck" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.DynCom c, xs) (Language.Skip, Semantic.Stuck)"
by(auto intro:SmallStep.step.StuckProp)
}
ultimately show ?thesis by(blast)
qed
next
case (Guard f g c)
from Guard.prems[simplified] show ?case
proof(cases rule:OG_SmallStep.step_elim_cases(2))
case (1 s)
from 1 have "c_og' = embedSimpl c" by(simp)
moreover from 1 sr have "stateRel xs xs_og'" by(simp)
moreover {
from 1 sr have "xs = Semantic.xstate.Normal s" by(cases xs, auto)
with 1 have "SmallStep.step \<Gamma> (Language.Guard f g c, xs) (c, xs)"
by(auto intro:SmallStep.step.Guard)
}
ultimately show ?thesis by(blast)
next
case (2 s)
from 2 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 2 sr have "stateRel (Semantic.Fault f) xs_og'" by(simp)
moreover {
from 2 sr have "xs = Semantic.xstate.Normal s" by(cases xs, auto)
with 2 have "SmallStep.step \<Gamma> (Language.Guard f g c, xs) (Language.Skip, Semantic.Fault f)"
by(auto intro:SmallStep.step.GuardFault)
}
ultimately show ?thesis by(blast)
next
case (3 flt)
from 3 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 3 have "stateRel (Semantic.Fault flt) xs_og'" by(simp)
moreover {
from 3 sr have "xs = Semantic.Fault flt" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Guard f g c, xs) (Language.Skip, Semantic.Fault flt)"
by(auto intro:SmallStep.step.FaultProp)
}
ultimately show ?thesis by(blast)
next
case 4
from 4 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 4 have "stateRel Semantic.Stuck xs_og'" by(simp)
moreover {
from 4 sr have "xs = Semantic.Stuck" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Guard f g c, xs) (Language.Skip, Semantic.Stuck)"
by(auto intro:SmallStep.step.StuckProp)
}
ultimately show ?thesis by(blast)
qed
next
case Throw
from Throw.prems[simplified] show ?case
proof(cases rule:OG_SmallStep.step_elim_cases(10))
case (1 flt)
from 1 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 1 have "stateRel (Semantic.Fault flt) xs_og'" by(simp)
moreover {
from 1 sr have "xs = Semantic.Fault flt" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Throw, xs) (Language.Skip, Semantic.Fault flt)"
by(auto intro:SmallStep.step.FaultProp)
}
ultimately show ?thesis by(blast)
next
case 2
from 2 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 2 have "stateRel Semantic.Stuck xs_og'" by(simp)
moreover {
from 2 sr have "xs = Semantic.Stuck" by(cases xs, auto)
hence "SmallStep.step \<Gamma> (Language.Throw, xs) (Language.Skip, Semantic.Stuck)"
by(auto intro:SmallStep.step.StuckProp)
}
ultimately show ?thesis by(blast)
qed
next
case (Catch c1 c2)
from Catch.prems[simplified] show ?case
proof(cases rule:OG_SmallStep.step_elim_cases(11))
case (1 c1_og' s_og')
with Catch.hyps(1) obtain c1' xs'
where embed_IH: "c1_og' = embedSimpl c1'"
and step_IH: "SmallStep.step \<Gamma> (c1, xs) (c1', xs')"
and sr_IH: "stateRel xs' s_og'"
by(blast)
from 1 embed_IH
have "c_og' = embedSimpl (Language.Catch c1' c2)" by(simp)
moreover from 1 sr_IH
have "stateRel xs' xs_og'" by(simp)
moreover from step_IH
have "SmallStep.step \<Gamma> (Language.Catch c1 c2, xs) (Language.Catch c1' c2, xs')"
by(rule SmallStep.step.Catch)
ultimately show ?thesis by(blast)
next
case 2
from 2 have "c_og' = embedSimpl Language.Skip" by(simp)
moreover from 2 sr have "stateRel xs xs_og'" by(simp)
moreover {
from 2 have "c1 = Language.Skip" by(cases c1, auto)
hence "SmallStep.step \<Gamma> (Language.Catch c1 c2, xs) (Language.Skip, xs)"
by(auto intro:SmallStep.step.CatchSkip)
}
ultimately show ?thesis by(blast)
next
case (3 s)
from 3 have "c_og' = embedSimpl c2" by(simp)
moreover from 3 sr have "stateRel xs xs_og'" by(simp)
moreover {
from 3 have "c1 = Language.Throw" by(cases c1, auto)
moreover from 3 sr have "xs = Semantic.Normal s" by(cases xs, auto)
ultimately have "SmallStep.step \<Gamma> (Language.Catch c1 c2, xs) (c2, xs)"
by(auto intro:SmallStep.step.CatchThrow)
}
ultimately show ?thesis by(blast)
next
case (4 f)
with og_redex_Catch_ne show ?thesis by(blast)
next
case 5
with og_redex_Catch_ne show ?thesis by(blast)
qed
qed
text \<open>The forward embedding is single-valued.\<close>
lemma embedSimpl_fwd_refine1:
assumes sr: "stateRel xs xs_og"
and embed_step: "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl c, xs_og) (c_og', xs_og')"
shows "\<exists>!(c',xs'). c_og' = embedSimpl c' \<and> SmallStep.step \<Gamma> (c, xs) (c', xs') \<and> stateRel xs' xs_og'"
(is "\<exists>!(c',xs'). ?P c' \<and> ?Q c' xs' \<and> ?R xs'")
proof -
from embedSimpl_fwd_refine[OF assms] have "\<exists>c' xs'. ?P c' \<and> ?Q c' xs' \<and> ?R xs'"
by(blast)
moreover {
fix c' xs' c'' xs''
assume P1: "?P c' \<and> ?Q c' xs' \<and> ?R xs'"
and P2: "?P c'' \<and> ?Q c'' xs'' \<and> ?R xs''"
from embedSimpl_inj P1 P2 have "c' = c''" by(blast dest:inj_eq)
moreover from stateRel_sv_rev P1 P2 have "xs' = xs''"
unfolding single_valuedp_def by(auto)
ultimately have "(c',xs') = (c'',xs'')" by(simp)
}
ultimately show ?thesis by(auto)
qed
text \<open>Elimination rule form of forward refinement.\<close>
lemma embedSimpl_fwdE[consumes 2]:
assumes sr: "stateRel xs xs_og"
and embed_step: "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl c, xs_og) (c_og', xs_og')"
obtains (Simpl) c' xs'
where "c_og' = embedSimpl c'"
and "SmallStep.step \<Gamma> (c, xs) (c', xs')"
and "stateRel xs' xs_og'"
using embedSimpl_fwd_refine[OF assms] by(auto)
text \<open>Embedding is faithful - any step of the Simpl program is also a step of the Complx.\<close>
lemma embedSimpl_rev_refine:
assumes sr: "stateRel xs xs_og"
and step: "SmallStep.step \<Gamma> (c, xs) (c', xs')"
shows "\<exists>xs_og'. OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl c, xs_og) (embedSimpl c', xs_og') \<and> stateRel xs' xs_og'"
using step
proof(induct c arbitrary:c')
case Skip
thus ?case
by(auto intro:SmallStep.no_step_final[unfolded SmallStep.final_def])
next
case (Basic f)
from Basic show ?case
proof(cases rule:SmallStep.step_elim_cases(3))
case (1 s)
hence "stateRel xs' (OG_SmallStep.Normal (f s))" by(simp)
moreover {
from 1 sr have "xs_og = OG_SmallStep.Normal s" by(cases xs_og, auto)
with 1 have "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl (Language.Basic f), xs_og)
(embedSimpl c', OG_SmallStep.Normal (f s))"
by(auto intro:OG_SmallStep.step.Basic)
}
ultimately show ?thesis by(blast)
next
case (2 flt)
hence "stateRel xs' (OG_SmallStep.Fault flt)" by(simp)
moreover {
from 2 sr have "xs_og = OG_SmallStep.Fault flt" by(cases xs_og, auto)
with 2 have "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl (Language.Basic f), xs_og)
(embedSimpl c', OG_SmallStep.Fault flt)"
by(auto intro:OG_SmallStep.step.FaultProp)
}
ultimately show ?thesis by(blast)
next
case 3
hence "stateRel xs' OG_SmallStep.Stuck" by(simp)
moreover {
from 3 sr have "xs_og = OG_SmallStep.Stuck" by(cases xs_og, auto)
with 3 have "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl (Language.Basic f), xs_og)
(embedSimpl c', OG_SmallStep.Stuck)"
by(auto intro:OG_SmallStep.step.StuckProp)
}
ultimately show ?thesis by(blast)
next
text \<open>The Abrupt state is forbidden by the state relation.\<close>
case (4 f)
with sr show ?thesis by(simp)
qed
next
case (Spec r)
from Spec show ?case
proof(cases rule:SmallStep.step_elim_cases(4))
case (1 s t)
hence "stateRel xs' (OG_SmallStep.Normal t)" by(simp)
moreover {
from 1 sr have "xs_og = OG_SmallStep.Normal s" by(cases xs_og, auto)
with 1 have "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl (Language.Spec r), xs_og)
(embedSimpl c', OG_SmallStep.Normal t)"
by(auto intro:OG_SmallStep.step.Spec)
}
ultimately show ?thesis by(blast)
next
case (2 s)
hence "stateRel xs' (OG_SmallStep.Stuck)" by(simp)
moreover {
from 2 sr have "xs_og = OG_SmallStep.Normal s" by(cases xs_og, auto)
with 2 have "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl (Language.Spec r), xs_og)
(embedSimpl c', OG_SmallStep.Stuck)"
by(auto intro:OG_SmallStep.step.SpecStuck)
}
ultimately show ?thesis by(blast)
next
case (3 flt)
hence "stateRel xs' (OG_SmallStep.Fault flt)" by(simp)
moreover {
from 3 sr have "xs_og = OG_SmallStep.Fault flt" by(cases xs_og, auto)
with 3 have "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl (Language.Spec r), xs_og)
(embedSimpl c', OG_SmallStep.Fault flt)"
by(auto intro:OG_SmallStep.step.FaultProp)
}
ultimately show ?thesis by(blast)
next
case 4
hence "stateRel xs' OG_SmallStep.Stuck" by(simp)
moreover {
from 4 sr have "xs_og = OG_SmallStep.Stuck" by(cases xs_og, auto)
with 4 have "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl (Language.Spec r), xs_og)
(embedSimpl c', OG_SmallStep.Stuck)"
by(auto intro:OG_SmallStep.step.StuckProp)
}
ultimately show ?thesis by(blast)
next
case (5 f)
with sr show ?thesis by(simp)
qed
next
case (Seq c1 c2)
from Seq.prems show ?case
proof(cases rule:SmallStep.step_elim_cases(5))
case (1 c1' s')
with Seq.hyps(1) obtain xs_og'
where step_IH: "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl c1, xs_og) (embedSimpl c1', xs_og')"
and sr_IH: "stateRel xs' xs_og'"
by(blast)
from 1 step_IH
have "OG_SmallStep.step (embedContext \<Gamma>)
(embedSimpl (Language.Seq c1 c2), xs_og) (embedSimpl c', xs_og')"
by(auto intro: OG_SmallStep.step.Seq)
with sr_IH show ?thesis by(blast)
next
case 2
from 2 sr have "stateRel xs' xs_og" by(simp)
moreover {
from 2 have "OG_SmallStep.step (embedContext \<Gamma>)
(embedSimpl (Language.Seq c1 c2), xs_og)
(embedSimpl c', xs_og)"
by(auto intro:OG_SmallStep.step.SeqSkip)
}
ultimately show ?thesis by(blast)
next
case (3 s)
from 3 sr have "stateRel xs' (OG_SmallStep.Normal s)" by(simp)
moreover {
from 3 sr have "xs_og = OG_SmallStep.Normal s" by(cases xs_og, auto)
with 3 have "OG_SmallStep.step (embedContext \<Gamma>)
(embedSimpl (Language.Seq c1 c2), xs_og)
(embedSimpl c', OG_SmallStep.Normal s)"
by(auto intro:OG_SmallStep.step.SeqThrow)
}
ultimately show ?thesis by(blast)
next
case (4 flt)
with redex_Seq_ne show ?thesis by(blast)
next
case 5
with redex_Seq_ne show ?thesis by(blast)
next
case (6 f)
with sr show ?thesis by(simp)
qed
next
case (Cond b c1 c2)
from Cond.prems show ?case
proof(cases rule:SmallStep.step_elim_cases(6))
case (1 s)
hence "stateRel xs' (OG_SmallStep.Normal s)" by(simp)
moreover {
from 1 sr have "xs_og = OG_SmallStep.Normal s" by(cases xs_og, auto)
with 1 have "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl (Language.Cond b c1 c2), xs_og)
(embedSimpl c', OG_SmallStep.Normal s)"
by(auto intro:OG_SmallStep.step.CondTrue)
}
ultimately show ?thesis by(blast)
next
case (2 s)
hence "stateRel xs' (OG_SmallStep.Normal s)" by(simp)
moreover {
from 2 sr have "xs_og = OG_SmallStep.Normal s" by(cases xs_og, auto)
with 2 have "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl (Language.Cond b c1 c2), xs_og)
(embedSimpl c', OG_SmallStep.Normal s)"
by(auto intro:OG_SmallStep.step.CondFalse)
}
ultimately show ?thesis by(blast)
next
case (3 flt)
hence "stateRel xs' (OG_SmallStep.Fault flt)" by(simp)
moreover {
from 3 sr have "xs_og = OG_SmallStep.Fault flt" by(cases xs_og, auto)
with 3 have "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl (Language.Cond b c1 c2), xs_og)
(embedSimpl c', OG_SmallStep.Fault flt)"
by(auto intro:OG_SmallStep.step.FaultProp)
}
ultimately show ?thesis by(blast)
next
case 4
hence "stateRel xs' OG_SmallStep.Stuck" by(simp)
moreover {
from 4 sr have "xs_og = OG_SmallStep.Stuck" by(cases xs_og, auto)
with 4 have "OG_SmallStep.step (embedContext \<Gamma>) (embedSimpl (Language.Cond b c1 c2), xs_og)
(embedSimpl c', OG_SmallStep.Stuck)"
by(auto intro:OG_SmallStep.step.StuckProp)
}
ultimately show ?thesis by(blast)
next
case (5 f)
with sr show ?thesis by(simp)
qed
next
case (While b c)