-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmilExampleConditionalScript.sml
1777 lines (1619 loc) · 78.2 KB
/
milExampleConditionalScript.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
open HolKernel boolLib Parse bossLib metisTools wordsLib wordsTheory finite_mapTheory listTheory pred_setTheory relationTheory bisimulationTheory milUtilityTheory milTheory milSemanticsUtilityTheory milMetaTheory milMetaIOTheory milTracesTheory milExampleUtilityTheory milStoreTheory milExampleBisimulationTheory milNoninterferenceTheory milExecutableExamplesTheory milExecutableUtilityTheory milMaxExeTraceExampleConditionalTheory milLib;
(* ============================================= *)
(* Example MIL program for conditional branching *)
(* ============================================= *)
val _ = new_theory "milExampleConditional";
(* --------------------- *)
(* Definition of program *)
(* --------------------- *)
(* Translation of "beq a", example 2 in CCS20 paper *)
Definition example_conditional:
example_conditional (t00:t) (t11:t) (t12:t) (t21:t) (t31:t) (t41:t) (t42:t) (t51:t) (t52:t) (z:v) (a:v) : I =
{ i_assign t00 (e_val val_true) (o_internal (e_val val_zero)); (* zeroed name *)
i_assign t11 (e_val val_true) (o_internal (e_val z));
i_assign t12 (e_val val_true) (o_load res_REG t11);
i_assign t21 (e_val val_true) (o_internal (e_eq (e_name t12) (e_val val_one)));
i_assign t31 (e_val val_true) (o_load res_PC t00);
i_assign t41 (e_val val_true) (o_internal (e_val a));
i_assign t42 (e_name t21) (o_store res_PC t00 t41);
i_assign t51 (e_val val_true) (o_internal (e_add (e_name t31) (e_val 4w)));
i_assign t52 (e_not (e_name t21)) (o_store res_PC t00 t51)
}
End
(* ---------------------- *)
(* Example initial states *)
(* ---------------------- *)
(* Initial state of program example_conditional with empty s, C, and F *)
Definition example_conditional_initial_state:
example_conditional_initial_state t00 t11 t12 t21 t31 t41 t42 t51 t52 z a =
State_st (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) FEMPTY {} {}
End
(* An example initial state that is well-formed *)
Theorem example_conditional_initial_state1_well_formed[local]:
well_formed_state
(State_st (example_conditional 0 1 2 3 4 5 6 7 8 1w 4w) FEMPTY {} {})
Proof
rw [well_formed_state] >| [
rw [FINITE_DEF] >>
METIS_TAC [example_conditional],
Cases_on `i` >> Cases_on `o'` >>
rw [bound_name_instr] >>
fs [example_conditional] >>
rw [] >> fs [free_names_instr, names_o, names_e],
fs [example_conditional] >>
rw [] >> fs [bound_name_instr, names_e],
fs [example_conditional] >> rw [] >>
fs [free_names_instr, names_o, names_e] >> rw [] >>
METIS_TAC [bound_name_instr],
fs [map_down, example_conditional],
fs [example_conditional],
fs [example_conditional] >> rw [] >>
fs [names_e],
fs [example_conditional] >> rw [] >>
fs [names_o, names_e, bound_name_instr] >>
fs [sem_expr_correct, val_true, val_false],
fs [example_conditional]
]
QED
(* --------------------- *)
(* Bisimulation relation *)
(* --------------------- *)
Definition example_conditional_rel:
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 s1 C1 F1) (State_st I2 s2 C2 F2) =
? I0 I0' a a' .
t00 < t11 /\ t11 < t12 /\ t12 < t21 /\ t21 < t31 /\
t31 < t41 /\ t41 < t42 /\ t42 < t51 /\ t51 < t52 /\
well_formed_state (State_st I1 s1 C1 F1) /\
well_formed_state (State_st I2 s2 C2 F2) /\
I1 = I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a /\
I2 = I0' UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a' /\
FDOM s1 = FDOM s2 /\ C1 = C2 /\ F1 = F2 /\
bound_names_program I0 <
bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) /\
bound_names_program I0' <
bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a') /\
(!i. i IN I0 ==> Completed (State_st I1 s1 C1 F1) i) /\
(!i. i IN I0' ==> Completed (State_st I2 s2 C2 F2) i) /\
(* in both states, register z is initialized by store instruction ts_z with the same value *)
ts_z IN bound_names_program I0 /\
ts_z IN bound_names_program I0' /\
bound_names_program (str_act_addr (State_st I1 s1 C1 F1) t12 res_REG z) = { ts_z } /\
bound_names_program (str_act_addr (State_st I2 s2 C2 F2) t12 res_REG z) = { ts_z } /\
FLOOKUP s1 ts_z = FLOOKUP s2 ts_z /\
(* in both states, PC is initialized by store instruction ts_pc *)
ts_pc IN bound_names_program I0 /\
ts_pc IN bound_names_program I0' /\
bound_names_program (str_act_addr (State_st I1 s1 C1 F1) t31 res_PC val_zero) = { ts_pc } /\
bound_names_program (str_act_addr (State_st I2 s2 C2 F2) t31 res_PC val_zero) = { ts_pc } /\
FLOOKUP s1 t11 = FLOOKUP s2 t11 /\
FLOOKUP s1 t12 = FLOOKUP s2 t12 /\
FLOOKUP s1 t21 = FLOOKUP s2 t21 /\
((FLOOKUP s1 ts_z = SOME val_one /\
(map_down s1 t12 ==> FLOOKUP s1 t12 = SOME val_one) /\
(map_down s1 t21 ==> FLOOKUP s1 t21 = SOME val_true) /\
map_up s1 t52 /\ map_up s2 t52 /\
a = a' /\
FLOOKUP s1 t41 = FLOOKUP s2 t41 /\
FLOOKUP s1 t42 = FLOOKUP s2 t42) \/
(FLOOKUP s1 ts_z <> SOME val_one /\
(map_down s1 t12 ==> FLOOKUP s1 t12 <> SOME val_one) /\
(map_down s1 t21 ==> FLOOKUP s1 t21 = SOME val_false) /\
map_up s1 t42 /\ map_up s2 t42 /\
FLOOKUP s1 ts_pc = FLOOKUP s2 ts_pc /\
FLOOKUP s1 t31 = FLOOKUP s2 t31 /\
FLOOKUP s1 t51 = FLOOKUP s2 t51 /\
FLOOKUP s1 t52 = FLOOKUP s2 t52))
End
Theorem example_conditional_rel_symmetric[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc .
symmetric (example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc)
Proof
rw [symmetric_def] >>
Cases_on `x` >> Cases_on `y` >>
rw [example_conditional_rel] >>
fs [map_down] >>
METIS_TAC []
QED
(* TODO:
prove DISJOINT I0 (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)
to get transitivity
Theorem example_conditional_rel_transitive[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc .
transitive (example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc)
Proof
cheat
QED
*)
(* ------------- *)
(* Common lemmas *)
(* ------------- *)
(* Bound names of all instructions in the program *)
(* FIXME: executable definition of bound_names_program can be used here *)
Theorem example_conditional_bn[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z a .
bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)
= { t00; t11; t12; t21; t31; t41; t42; t51; t52 }
Proof
fs [bound_names_program, example_conditional, SET_EQ_SUBSET] >>
rw [] >>
(METIS_TAC [bound_name_instr] ORELSE
rw [SUBSET_DEF] >> fs [bound_name_instr])
QED
(* Any instruction t in the preamble I0 must be strictly less than t00. *)
Theorem example_conditional_I0_t_lt_t00[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z a I0 t c mop .
t00 < t11 /\ t11 < t12 /\ t12 < t21 /\ t21 < t31 /\
t31 < t41 /\ t41 < t42 /\ t42 < t51 /\ t51 < t52 ==>
bound_names_program I0 < bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) ==>
i_assign t c mop IN I0 ==>
t < t00
Proof
rw [] >>
`t IN bound_names_program I0`
by METIS_TAC [instr_in_bound_names_program] >>
`!t'. t' IN bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) ==> t' >= t00`
by fs [example_conditional_bn] >>
`i_assign t00 (e_val val_true) (o_internal (e_val val_zero))
IN example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a`
by rw [example_conditional] >>
`t00 IN bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)`
by METIS_TAC [instr_in_bound_names_program] >>
fs [names_lt]
QED
(* Address information of t42 *)
Theorem example_conditional_addr_of_t42[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z a I0 .
t00 < t11 /\ t11 < t12 /\ t12 < t21 /\ t21 < t31 /\
t31 < t41 /\ t41 < t42 /\ t42 < t51 /\ t51 < t52 ==>
bound_names_program I0 < bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) ==>
addr_of (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) t42
= SOME (res_PC, t00)
Proof
rw [addr_of] >>
`{ (r, ta) |
(?c.
i_assign t42 c (o_load r ta) IN I0 \/
i_assign t42 c (o_load r ta) IN example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) \/
(?c tv.
i_assign t42 c (o_store r ta tv) IN I0 \/
i_assign t42 c (o_store r ta tv) IN example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) }
= { (res_PC, t00) }`
by (
rw [SET_EQ_SUBSET] >| [
rw [SUBSET_DEF] >> (
`t42 < t00` by METIS_TAC [example_conditional_I0_t_lt_t00] >> fs [] ORELSE fs [example_conditional]
),
DISJ2_TAC >>
Q.EXISTS_TAC `e_name t21` >>
Q.EXISTS_TAC `t41` >>
rw [example_conditional]
]) >>
rw []
QED
(* Address information of t52 *)
Theorem example_conditional_addr_of_t52[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z a I0 .
t00 < t11 /\ t11 < t12 /\ t12 < t21 /\ t21 < t31 /\
t31 < t41 /\ t41 < t42 /\ t42 < t51 /\ t51 < t52 ==>
bound_names_program I0 < bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) ==>
addr_of (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) t52
= SOME (res_PC, t00)
Proof
rw [addr_of] >>
`{ (r, ta) |
(?c.
i_assign t52 c (o_load r ta) IN I0 \/
i_assign t52 c (o_load r ta) IN example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) \/
(?c tv.
i_assign t52 c (o_store r ta tv) IN I0 \/
i_assign t52 c (o_store r ta tv) IN example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) }
= { (res_PC, t00) }`
by (
rw [SET_EQ_SUBSET] >| [
rw [SUBSET_DEF] >> (
`t52 < t00` by METIS_TAC [example_conditional_I0_t_lt_t00] >> fs [] ORELSE fs [example_conditional]
),
DISJ2_TAC >>
Q.EXISTS_TAC `e_not (e_name t21)` >>
Q.EXISTS_TAC `t51` >>
rw [example_conditional]
]) >>
rw []
QED
(* str-may(σ1, t42) ⊆ I0. *)
Theorem example_conditional_str_may_t42_subset_I0[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z a I0 s1 C1 F1 .
t00 < t11 /\ t11 < t12 /\ t12 < t21 /\ t21 < t31 /\
t31 < t41 /\ t41 < t42 /\ t42 < t51 /\ t51 < t52 ==>
bound_names_program I0 < bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) ==>
str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1) t42
SUBSET I0
Proof
rw [SUBSET_DEF] >>
fs [str_may, bound_names_program, bound_name_instr] >>
TRY (
`i_assign t00 (e_val val_true) (o_internal (e_val val_zero))
IN example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a`
by fs [example_conditional] >>
METIS_TAC [bound_name_instr]
) >>
fs [example_conditional]
QED
(* If [t21]σ1 is false, then str-may(σ1, t52) ⊆ I0.
This holds because t42 cannot be in str-may then. *)
Theorem example_conditional_str_may_t52_subset_I0[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z a I0 s1 C1 F1 .
t00 < t11 /\ t11 < t12 /\ t12 < t21 /\ t21 < t31 /\
t31 < t41 /\ t41 < t42 /\ t42 < t51 /\ t51 < t52 ==>
bound_names_program I0 < bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) ==>
sem_expr (e_name t21) s1 = SOME val_false ==>
str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1) t52
SUBSET I0
Proof
rw [SUBSET_DEF] >>
fs [str_may, bound_names_program, bound_name_instr] >>
TRY (
`i_assign t00 (e_val val_true) (o_internal (e_val val_zero))
IN example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a`
by fs [example_conditional] >>
METIS_TAC [bound_name_instr]
) >>
fs [example_conditional] >>
rw [] >> fs [val_true, val_false]
QED
(* bn(str-may(σ1, t42)) ⊆ F1. *)
Theorem example_conditional_bn_str_may_t42_fetched[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z a I0 s1 C1 F1 .
t00 < t11 /\ t11 < t12 /\ t12 < t21 /\ t21 < t31 /\
t31 < t41 /\ t41 < t42 /\ t42 < t51 /\ t51 < t52 ==>
bound_names_program I0 < bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) ==>
(!i. i IN I0 ==>
Completed (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1) i) ==>
bound_names_program
(str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1) t42)
SUBSET F1
Proof
rw [] >>
`str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1) t42
SUBSET I0`
by rw [example_conditional_str_may_t42_subset_I0] >>
`!i. i IN (str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1)
t42) ==>
Completed (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1) i`
by fs [SUBSET_DEF] >>
`!i. i IN (str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1)
t42) ==>
?t c ta tv. i = i_assign t c (o_store res_PC ta tv)`
by (
rw [str_may] >>
`addr_of (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) t42 = SOME (res_PC, t00)`
by METIS_TAC [example_conditional_addr_of_t42] >>
fs []) >>
`!i. i IN (str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1)
t42) ==> bound_name_instr i IN F1`
by METIS_TAC [completed_store_PC_in_str_may_fetched, bound_name_instr] >>
rw [bound_names_program, SUBSET_DEF] >>
rw []
QED
(* If [t21]σ1 is false, then bn(str-may(σ1, t52)) ⊆ F1.
This holds because t42 cannot be in str-may then. *)
Theorem example_conditional_bn_str_may_t52_fetched[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z a I0 s1 C1 F1 .
t00 < t11 /\ t11 < t12 /\ t12 < t21 /\ t21 < t31 /\
t31 < t41 /\ t41 < t42 /\ t42 < t51 /\ t51 < t52 ==>
bound_names_program I0 < bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) ==>
(!i. i IN I0 ==>
Completed (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1) i) ==>
sem_expr (e_name t21) s1 = SOME val_false ==>
bound_names_program
(str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1) t52)
SUBSET F1
Proof
rw [] >>
`str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1) t52
SUBSET I0`
by rw [example_conditional_str_may_t52_subset_I0] >>
`!i. i IN (str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1)
t52) ==>
Completed (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1) i`
by fs [SUBSET_DEF] >>
`!i. i IN (str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1)
t52) ==>
?t c ta tv. i = i_assign t c (o_store res_PC ta tv)`
by (
rw [str_may] >>
`addr_of (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) t52 = SOME (res_PC, t00)`
by METIS_TAC [example_conditional_addr_of_t52] >>
fs []) >>
`!i. i IN (str_may (State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) s1 C1 F1)
t52) ==> bound_name_instr i IN F1`
by METIS_TAC [completed_store_PC_in_str_may_fetched, bound_name_instr] >>
rw [bound_names_program, SUBSET_DEF] >>
rw []
QED
Theorem example_conditional_t_gt_bn_str_may_addr_t12[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z a I0 s1 C1 F1 t .
t = t00 \/ t = t11 \/ t = t12 \/ t = t21 \/ t = t31 \/ t = t41 \/ t = t42 \/ t = t51 \/ t = t52 ==>
bound_names_program I0 < bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) ==>
bound_names_program (str_may_addr
(State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)
s1 C1 F1) t12 res_REG z) <> {} ==>
{t} > bound_names_program (str_may_addr
(State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)
s1 C1 F1) t12 res_REG z)
Proof
rw [names_gt] >>>
TACS_TO_LT [
Q.ABBREV_TAC `t00 = t`,
Q.ABBREV_TAC `t11 = t`,
Q.ABBREV_TAC `t12 = t`,
Q.ABBREV_TAC `t21 = t`,
Q.ABBREV_TAC `t31 = t`,
Q.ABBREV_TAC `t41 = t`,
Q.ABBREV_TAC `t42 = t`,
Q.ABBREV_TAC `t51 = t`,
Q.ABBREV_TAC `t52 = t` ] >>
fs [str_may_addr, bound_names_program, bound_name_instr] >> (
`t' IN bound_names_program I0` by METIS_TAC [instr_in_bound_names_program] >>
`t IN bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)`
by fs [example_conditional_bn] >>
`t' < t` by METIS_TAC [bound_names_program, bound_name_instr, names_lt] >>
fs [] ORELSE
fs [example_conditional])
QED
Theorem example_conditional_t_gt_bn_str_may_addr_t31[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z a I0 s1 C1 F1 t .
t31 < t42 /\ t31 < t52 ==>
t = t00 \/ t = t11 \/ t = t12 \/ t = t21 \/ t = t31 \/ t = t41 \/ t = t42 \/ t = t51 \/ t = t52 ==>
bound_names_program I0 < bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a) ==>
bound_names_program (str_may_addr
(State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)
s1 C1 F1) t31 res_PC val_zero) <> {} ==>
{t} > bound_names_program (str_may_addr
(State_st (I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)
s1 C1 F1) t31 res_PC val_zero)
Proof
rw [names_gt] >>>
TACS_TO_LT [
Q.ABBREV_TAC `t00 = t`,
Q.ABBREV_TAC `t11 = t`,
Q.ABBREV_TAC `t12 = t`,
Q.ABBREV_TAC `t21 = t`,
Q.ABBREV_TAC `t31 = t`,
Q.ABBREV_TAC `t41 = t`,
Q.ABBREV_TAC `t42 = t`,
Q.ABBREV_TAC `t51 = t`,
Q.ABBREV_TAC `t52 = t` ] >>
fs [str_may_addr, bound_names_program, bound_name_instr] >> (
`t' IN bound_names_program I0` by METIS_TAC [instr_in_bound_names_program] >>
`t IN bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)`
by fs [example_conditional_bn] >>
`t' < t` by METIS_TAC [bound_names_program, bound_name_instr, names_lt] >>
fs [] ORELSE
fs [example_conditional])
QED
(* ------------------- *)
(* Lemmas for executes *)
(* ------------------- *)
(* i_assign t00 (e_val val_true) (o_internal (e_val val_zero)) *)
Theorem example_conditional_rel_t00_exe_pre[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc I1 s1 C1 F1 I2 s2 C2 F2 v1 v2 .
well_formed_state (State_st I1 (s1 |+ (t00, v1)) C1 F1) ==>
well_formed_state (State_st I2 (s2 |+ (t00, v2)) C2 F2) ==>
map_up s1 t00 ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 s1 C1 F1) (State_st I2 s2 C2 F2) ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 (s1 |+ (t00, v1)) C1 F1) (State_st I2 (s2 |+ (t00, v2)) C2 F2)
Proof
REPEAT strip_tac >>
fs [example_conditional_rel] >>
rename1 `I1 = I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a` >>
`t00 NOTIN FDOM s1` by fs [map_up, map_down, flookup_thm] >>
`map_up s2 t00` by METIS_TAC [map_up, map_down, flookup_thm] >>
`ts_z <> t00 /\ ts_pc <> t00`
by (
`t00 IN bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)`
by fs [example_conditional_bn] >>
`ts_z < t00 /\ ts_pc < t00` by METIS_TAC [names_lt] >> fs []) >>
`t31 < t42 /\ t31 < t52` by fs [] >>
Q.EXISTS_TAC `I0` >> Q.EXISTS_TAC `I0'` >>
Q.EXISTS_TAC `a` >> Q.EXISTS_TAC `a'` >> rw [] >>
fs [completed_fupdate, FLOOKUP_UPDATE] >> (
METIS_TAC [example_conditional_t_gt_bn_str_may_addr_t12,
example_conditional_t_gt_bn_str_may_addr_t31,
bn_str_act_addr_eq_s,
bn_str_act_addr_singleton_bn_str_may_addr_nonempty]
ORELSE
fs [FLOOKUP_UPDATE, map_up, map_down] >> fs [] >>
PROVE_TAC [FLOOKUP_UPDATE, map_down])
QED
Theorem example_conditional_rel_t00_exe[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc .
internal_exe_preserving'
(example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc)
t00 (e_val val_true) (e_val val_zero) (e_val val_zero)
Proof
rw [internal_exe_preserving'] >>
FIRST_PROVE [
fs [example_conditional_rel, example_conditional, names_e],
METIS_TAC [example_conditional_rel_t00_exe_pre]
]
QED
Theorem example_conditional_rel_t00_exe_sim[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 S1' obs .
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 ==>
out_of_order_step' S1 (l_lb obs act_exe t00) S1' ==>
? S2' . out_of_order_step' S2 (l_lb obs act_exe t00) S2' /\
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1' S2'
Proof
rw [] >>
ASSUME_TAC (MATCH_MP (SPECL [``example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc``]
R_internal_exe_sim') (UNDISCH_ALL (SPEC_ALL example_conditional_rel_t00_exe))) >>
METIS_TAC []
QED
(* i_assign t11 (e_val val_true) (o_internal (e_val z)) *)
Theorem example_conditional_rel_t11_exe_pre[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc I1 s1 C1 F1 I2 s2 C2 F2 v1 v2 .
well_formed_state (State_st I1 (s1 |+ (t11, v1)) C1 F1) ==>
well_formed_state (State_st I2 (s2 |+ (t11, v2)) C2 F2) ==>
map_up s1 t11 ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 s1 C1 F1) (State_st I2 s2 C2 F2) ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 (s1 |+ (t11, v1)) C1 F1) (State_st I2 (s2 |+ (t11, v2)) C2 F2)
Proof
REPEAT strip_tac >>
fs [example_conditional_rel] >>
rename1 `I1 = I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a` >>
`t11 NOTIN FDOM s1` by fs [map_up, map_down, flookup_thm] >>
`map_up s2 t11` by METIS_TAC [map_up, map_down, flookup_thm] >>
`ts_z <> t11 /\ ts_pc <> t11`
by (
`t11 IN bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)`
by fs [example_conditional_bn] >>
`ts_z < t11 /\ ts_pc < t11` by METIS_TAC [names_lt] >> fs []) >>
`t31 < t42 /\ t31 < t52` by fs [] >>
`v1 = v2`
by (
`i_assign t11 (e_val val_true) (o_internal (e_val z)) IN I1` by fs [example_conditional] >>
`FLOOKUP (s1 |+ (t11, v1)) t11 = SOME v1` by fs [FLOOKUP_DEF] >>
`sem_expr (e_val z) (s1 |+ (t11, v1)) = SOME v1` by METIS_TAC [wfs_internal_flookup_sem_expr] >>
`i_assign t11 (e_val val_true) (o_internal (e_val z)) IN I2` by fs [example_conditional] >>
`FLOOKUP (s2 |+ (t11, v2)) t11 = SOME v2` by fs [FLOOKUP_DEF] >>
`sem_expr (e_val z) (s2 |+ (t11, v2)) = SOME v2` by METIS_TAC [wfs_internal_flookup_sem_expr] >>
fs [sem_expr_correct]) >>
Q.EXISTS_TAC `I0` >> Q.EXISTS_TAC `I0'` >>
Q.EXISTS_TAC `a` >> Q.EXISTS_TAC `a'` >> rw [] >>
fs [completed_fupdate, FLOOKUP_UPDATE] >> (
METIS_TAC [example_conditional_t_gt_bn_str_may_addr_t12,
example_conditional_t_gt_bn_str_may_addr_t31,
bn_str_act_addr_eq_s,
bn_str_act_addr_singleton_bn_str_may_addr_nonempty]
ORELSE
fs [FLOOKUP_UPDATE, map_up, map_down] >> fs [] >>
PROVE_TAC [FLOOKUP_UPDATE, map_down])
QED
Theorem example_conditional_rel_t11_exe[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc .
internal_exe_preserving'
(example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc)
t11 (e_val val_true) (e_val z) (e_val z)
Proof
rw [internal_exe_preserving'] >>
FIRST_PROVE [
fs [example_conditional_rel, example_conditional, names_e],
METIS_TAC [example_conditional_rel_t11_exe_pre]
]
QED
Theorem example_conditional_rel_t11_exe_sim[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 S1' obs .
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 ==>
out_of_order_step' S1 (l_lb obs act_exe t11) S1' ==>
? S2' . out_of_order_step' S2 (l_lb obs act_exe t11) S2' /\
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1' S2'
Proof
rw [] >>
ASSUME_TAC (MATCH_MP (SPECL [``example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 I0 ts_z ts_pc``]
R_internal_exe_sim') (UNDISCH_ALL (SPEC_ALL example_conditional_rel_t11_exe))) >>
METIS_TAC []
QED
(* i_assign t12 (e_val val_true) (o_load res_REG t11) *)
Theorem example_conditional_rel_t12_exe_pre[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc I1 s1 C1 F1 I2 s2 C2 F2 v1 v2 .
well_formed_state (State_st I1 (s1 |+ (t12, v1)) C1 F1) ==>
well_formed_state (State_st I2 (s2 |+ (t12, v2)) C2 F2) ==>
map_up s1 t12 ==>
FLOOKUP s1 ts_z = SOME v1 ==>
FLOOKUP s2 ts_z = SOME v2 ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 s1 C1 F1) (State_st I2 s2 C2 F2) ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 (s1 |+ (t12, v1)) C1 F1) (State_st I2 (s2 |+ (t12, v2)) C2 F2)
Proof
REPEAT strip_tac >>
fs [example_conditional_rel] >>
rename1 `I1 = I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a` >>
`t12 NOTIN FDOM s1` by fs [map_up, map_down, flookup_thm] >>
`map_up s2 t12` by METIS_TAC [map_up, map_down, flookup_thm] >>
`ts_z <> t12 /\ ts_pc <> t12`
by (
`t12 IN bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)`
by fs [example_conditional_bn] >>
`ts_z < t12 /\ ts_pc < t12` by METIS_TAC [names_lt] >> fs []) >>
`t31 < t42 /\ t31 < t52` by fs [] >>
(`v1 = val_one` by fs [] ORELSE `v1 <> val_one` by METIS_TAC []) >>
Q.EXISTS_TAC `I0` >> Q.EXISTS_TAC `I0'` >>
Q.EXISTS_TAC `a` >> Q.EXISTS_TAC `a'` >> rw [] >>
fs [completed_fupdate, FLOOKUP_UPDATE] >> (
METIS_TAC [example_conditional_t_gt_bn_str_may_addr_t12,
example_conditional_t_gt_bn_str_may_addr_t31,
bn_str_act_addr_eq_s,
bn_str_act_addr_singleton_bn_str_may_addr_nonempty]
ORELSE
fs [FLOOKUP_UPDATE, map_up, map_down] >> fs [] >>
PROVE_TAC [FLOOKUP_UPDATE, map_down])
QED
Theorem example_conditional_rel_t12_exe[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc .
load_exe_preserving'
(example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc)
t12 (e_val val_true) res_REG t11
Proof
rw [load_exe_preserving'] >>
FIRST_PROVE [
fs [example_conditional_rel, example_conditional, names_e],
`a = z`
by (
fs [example_conditional_rel] >>
`i_assign t11 (e_val val_true) (o_internal (e_val z)) IN I1` by fs [example_conditional] >>
`sem_expr (e_val z) s1 = SOME a` by METIS_TAC [wfs_internal_flookup_sem_expr] >>
`sem_expr (e_val z) s1 = SOME z` by fs [sem_expr_correct] >>
fs []) >>
TRY (
`ts = ts_z` by fs [example_conditional_rel] >>
METIS_TAC [example_conditional_rel_t12_exe_pre]) >>
fs [example_conditional_rel] >>
METIS_TAC []
]
QED
Theorem example_conditional_rel_t12_exe_sim[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 S1' obs .
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 ==>
out_of_order_step' S1 (l_lb obs act_exe t12) S1' ==>
? S2' . out_of_order_step' S2 (l_lb obs act_exe t12) S2' /\
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1' S2'
Proof
rw [] >>
ASSUME_TAC (MATCH_MP (SPECL [``example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc``]
R_load_exe_sim') (UNDISCH_ALL (SPEC_ALL example_conditional_rel_t12_exe))) >>
METIS_TAC []
QED
(* i_assign t21 (e_val val_true) (o_internal (e_eq (e_name t12) (e_val val_one))) *)
Theorem example_conditional_rel_t21_exe_pre[local]:
sem_expr = sem_expr_exe ==>
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc I1 s1 C1 F1 I2 s2 C2 F2 v1 v2 .
well_formed_state (State_st I1 (s1 |+ (t21, v1)) C1 F1) ==>
well_formed_state (State_st I2 (s2 |+ (t21, v2)) C2 F2) ==>
map_up s1 t21 ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 s1 C1 F1) (State_st I2 s2 C2 F2) ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 (s1 |+ (t21, v1)) C1 F1) (State_st I2 (s2 |+ (t21, v2)) C2 F2)
Proof
REPEAT strip_tac >>
fs [example_conditional_rel] >>
rename1 `I1 = I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a` >>
`t21 NOTIN FDOM s1` by fs [map_up, map_down, flookup_thm] >>
`map_up s2 t21` by METIS_TAC [map_up, map_down, flookup_thm] >>
`ts_z <> t21 /\ ts_pc <> t21`
by (
`t21 IN bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)`
by fs [example_conditional_bn] >>
`ts_z < t21 /\ ts_pc < t21` by METIS_TAC [names_lt] >> fs []) >>
`t31 < t42 /\ t31 < t52` by fs [] >>
`t21 NOTIN names_e (e_eq (e_name t12) (e_val val_one))`
by fs [names_e, names_o] >>
`i_assign t21 (e_val val_true) (o_internal (e_eq (e_name t12) (e_val val_one))) IN I1`
by fs [example_conditional] >>
`FLOOKUP (s1 |+ (t21, v1)) t21 = SOME v1` by fs [FLOOKUP_DEF] >>
`sem_expr (e_eq (e_name t12) (e_val val_one)) s1 = SOME v1`
by METIS_TAC [sem_expr_notin_names_fupdate_eq, wfs_internal_flookup_sem_expr] >>
`names_e (e_eq (e_name t12) (e_val val_one)) SUBSET FDOM s1` by METIS_TAC [sem_expr_correct] >>
`t12 IN FDOM s1` by fs [names_e] >>
`map_down s1 t12` by METIS_TAC [map_down, flookup_thm] >>
`i_assign t21 (e_val val_true) (o_internal (e_eq (e_name t12) (e_val val_one))) IN I2`
by fs [example_conditional] >>
`FLOOKUP (s2 |+ (t21, v2)) t21 = SOME v2` by fs [FLOOKUP_DEF] >>
`sem_expr (e_eq (e_name t12) (e_val val_one)) s2 = SOME v2`
by METIS_TAC [sem_expr_notin_names_fupdate_eq, wfs_internal_flookup_sem_expr] >>
`names_e (e_eq (e_name t12) (e_val val_one)) SUBSET FDOM s2` by METIS_TAC [sem_expr_correct] >>
`t12 IN FDOM s2` by fs [names_e] >>
`map_down s2 t12` by METIS_TAC [map_down, flookup_thm] >| [
`FLOOKUP s1 t12 = SOME val_one` by METIS_TAC [] >>
`sem_expr_exe (e_eq (e_name t12) (e_val val_one)) s1 = SOME val_true` by fs [sem_expr_exe, v_eq] >>
`sem_expr (e_eq (e_name t12) (e_val val_one)) s1 = SOME val_true` by METIS_TAC [] >>
`v1 = val_true` by fs [] >>
`FLOOKUP s2 t12 = SOME val_one` by METIS_TAC [] >>
`sem_expr_exe (e_eq (e_name t12) (e_val val_one)) s2 = SOME val_true` by fs [sem_expr_exe, v_eq] >>
`sem_expr (e_eq (e_name t12) (e_val val_one)) s2 = SOME val_true` by METIS_TAC [] >>
`v2 = val_true` by fs [],
`?v. FLOOKUP s1 t12 = SOME v ∧ v <> val_one` by METIS_TAC [map_down] >>
`sem_expr_exe (e_name t12) s1 = SOME v ∧ v <> val_one` by METIS_TAC [sem_expr_exe] >>
`v_eq v val_one = val_false` by fs [v_eq] >>
`sem_expr_exe (e_eq (e_name t12) (e_val val_one)) s1 = SOME (v_eq v val_one)` by rw [sem_expr_exe] >>
`sem_expr_exe (e_eq (e_name t12) (e_val val_one)) s1 = SOME val_false` by fs [] >>
`sem_expr (e_eq (e_name t12) (e_val val_one)) s1 = SOME val_false` by METIS_TAC [] >>
`v1 = val_false` by fs [] >>
`?v. FLOOKUP s2 t12 = SOME v ∧ v <> val_one` by METIS_TAC [map_down] >>
`sem_expr_exe (e_name t12) s2 = SOME v ∧ v <> val_one` by METIS_TAC [sem_expr_exe] >>
`v_eq v val_one = val_false` by fs [v_eq] >>
`sem_expr_exe (e_eq (e_name t12) (e_val val_one)) s2 = SOME (v_eq v val_one)` by rw [sem_expr_exe] >>
`sem_expr_exe (e_eq (e_name t12) (e_val val_one)) s2 = SOME val_false` by fs [] >>
`sem_expr (e_eq (e_name t12) (e_val val_one)) s2 = SOME val_false` by METIS_TAC [] >>
`v2 = val_false` by fs []
] >>
Q.EXISTS_TAC `I0` >> Q.EXISTS_TAC `I0'` >>
Q.EXISTS_TAC `a` >> Q.EXISTS_TAC `a'` >> rw [] >>
fs [completed_fupdate, FLOOKUP_UPDATE] >> (
METIS_TAC [example_conditional_t_gt_bn_str_may_addr_t12,
example_conditional_t_gt_bn_str_may_addr_t31,
bn_str_act_addr_eq_s,
bn_str_act_addr_singleton_bn_str_may_addr_nonempty]
ORELSE
fs [FLOOKUP_UPDATE, map_up, map_down] >> fs [] >>
PROVE_TAC [FLOOKUP_UPDATE, map_down])
QED
Theorem example_conditional_rel_t21_exe[local]:
sem_expr = sem_expr_exe ==>
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc .
internal_exe_preserving'
(example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc)
t21 (e_val val_true) (e_eq (e_name t12) (e_val val_one)) (e_eq (e_name t12) (e_val val_one))
Proof
rw [internal_exe_preserving'] >>
FIRST_PROVE [
fs [example_conditional_rel, example_conditional, names_e],
METIS_TAC [example_conditional_rel_t21_exe_pre]
]
QED
Theorem example_conditional_rel_t21_exe_sim[local]:
sem_expr = sem_expr_exe ==>
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 S1' obs .
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 ==>
out_of_order_step' S1 (l_lb obs act_exe t21) S1' ==>
? S2' . out_of_order_step' S2 (l_lb obs act_exe t21) S2' /\
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1' S2'
Proof
rw [] >>
ASSUME_TAC (MATCH_MP (SPECL [``example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc``]
R_internal_exe_sim') (UNDISCH_ALL (SPEC_ALL (UNDISCH_ALL example_conditional_rel_t21_exe)))) >>
METIS_TAC []
QED
(* i_assign t31 (e_val val_true) (o_load res_PC t00) *)
Theorem example_conditional_rel_t31_exe_pre[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc I1 s1 C1 F1 I2 s2 C2 F2 v1 v2 .
well_formed_state (State_st I1 (s1 |+ (t31, v1)) C1 F1) ==>
well_formed_state (State_st I2 (s2 |+ (t31, v2)) C2 F2) ==>
map_up s1 t31 ==>
FLOOKUP s1 ts_pc = SOME v1 ==>
FLOOKUP s2 ts_pc = SOME v2 ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 s1 C1 F1) (State_st I2 s2 C2 F2) ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 (s1 |+ (t31, v1)) C1 F1) (State_st I2 (s2 |+ (t31, v2)) C2 F2)
Proof
REPEAT strip_tac >>
fs [example_conditional_rel] >>
rename1 `I1 = I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a` >>
`t31 NOTIN FDOM s1` by fs [map_up, map_down, flookup_thm] >>
`map_up s2 t31` by METIS_TAC [map_up, map_down, flookup_thm] >>
`ts_z <> t31 /\ ts_pc <> t31`
by (
`t31 IN bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)`
by fs [example_conditional_bn] >>
`ts_z < t31 /\ ts_pc < t31` by METIS_TAC [names_lt] >> fs []) >>
`t31 < t42 /\ t31 < t52` by fs [] >>
TRY (`v1 = v2` by fs []) >>
Q.EXISTS_TAC `I0` >> Q.EXISTS_TAC `I0'` >>
Q.EXISTS_TAC `a` >> Q.EXISTS_TAC `a'` >> rw [] >>
fs [completed_fupdate, FLOOKUP_UPDATE] >> (
METIS_TAC [example_conditional_t_gt_bn_str_may_addr_t12,
example_conditional_t_gt_bn_str_may_addr_t31,
bn_str_act_addr_eq_s,
bn_str_act_addr_singleton_bn_str_may_addr_nonempty]
ORELSE
fs [FLOOKUP_UPDATE, map_up, map_down] >> fs [] >>
PROVE_TAC [FLOOKUP_UPDATE, map_down])
QED
Theorem example_conditional_rel_t31_exe[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc .
load_exe_preserving'
(example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc)
t31 (e_val val_true) res_PC t00
Proof
rw [load_exe_preserving'] >>
FIRST_PROVE [
fs [example_conditional_rel, example_conditional, names_e],
(* show bound_names_program (str_act_addr (State_st I1 s1 C1 F1) t31 res_PC a) = {ts_pc}:
since well-formedness of R and FLOOKUP s1 t00 = SOME a imply [t00]s1 = a, but [t00]s1 = val_zero,
so a = val_zero *)
`?I0 a. I1 = I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a /\
bound_names_program (str_act_addr (State_st I1 s1 C1 F1) t31 res_PC val_zero) = {ts_pc}`
by METIS_TAC [example_conditional_rel] >>
`i_assign t00 (e_val val_true) (o_internal (e_val val_zero)) IN I1`
by fs [example_conditional] >>
`sem_instr (i_assign t00 (e_val val_true) (o_internal (e_val val_zero))) (State_st I1 s1 C1 F1) =
SOME (a,obs_internal)`
by METIS_TAC [wfs_internal_flookup_sem_instr, example_conditional_rel] >>
`sem_instr (i_assign t00 (e_val val_true) (o_internal (e_val val_zero))) (State_st I1 s1 C1 F1) =
SOME (val_zero,obs_internal)`
by fs [sem_expr_correct, sem_instr] >>
`a = val_zero` by fs [] >>
(* show bound_names_program (str_act_addr (State_st I2 s2 C2 F2) t31 res_PC a') = {ts_pc}:
since well-formedness of R and FLOOKUP s2 t00 = SOME a' imply [t00]s2 = a', but [t00]s2 = val_zero,
so a' = val_zero *)
`?I0' a'. I2 = I0' UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a' /\
bound_names_program (str_act_addr (State_st I2 s2 C2 F2) t31 res_PC val_zero) = {ts_pc}`
by METIS_TAC [example_conditional_rel] >>
`i_assign t00 (e_val val_true) (o_internal (e_val val_zero)) IN I2`
by fs [example_conditional] >>
`sem_instr (i_assign t00 (e_val val_true) (o_internal (e_val val_zero))) (State_st I2 s2 C2 F2) =
SOME (a',obs_internal)`
by METIS_TAC [wfs_internal_flookup_sem_instr, example_conditional_rel] >>
`sem_instr (i_assign t00 (e_val val_true) (o_internal (e_val val_zero))) (State_st I2 s2 C2 F2) =
SOME (val_zero,obs_internal)`
by fs [sem_expr_correct, sem_instr] >>
`a' = val_zero` by fs [] >>
TRY (METIS_TAC []) >>
`bound_names_program (str_act_addr (State_st I1 s1 C1 F1) t31 res_PC val_zero) = {ts}`
by METIS_TAC [] >>
`ts = ts_pc` by fs [] >>
METIS_TAC [example_conditional_rel_t31_exe_pre]
]
QED
Theorem example_conditional_rel_t31_exe_sim[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 S1' obs .
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 ==>
out_of_order_step' S1 (l_lb obs act_exe t31) S1' ==>
? S2' . out_of_order_step' S2 (l_lb obs act_exe t31) S2' /\
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1' S2'
Proof
rw [] >>
ASSUME_TAC (MATCH_MP (SPECL [``example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc``]
R_load_exe_sim') (UNDISCH_ALL (SPEC_ALL example_conditional_rel_t31_exe))) >>
METIS_TAC []
QED
(* i_assign t41 (e_val val_true) (o_internal (e_val a)) *)
Theorem example_conditional_rel_t41_exe_pre[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc I1 s1 C1 F1 I2 s2 C2 F2 v1 v2 .
well_formed_state (State_st I1 (s1 |+ (t41, v1)) C1 F1) ==>
well_formed_state (State_st I2 (s2 |+ (t41, v2)) C2 F2) ==>
map_up s1 t41 ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 s1 C1 F1) (State_st I2 s2 C2 F2) ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 (s1 |+ (t41, v1)) C1 F1) (State_st I2 (s2 |+ (t41, v2)) C2 F2)
Proof
REPEAT strip_tac >>
fs [example_conditional_rel] >>
rename1 `I1 = I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a` >>
`t41 NOTIN FDOM s1` by fs [map_up, map_down, flookup_thm] >>
`map_up s2 t41` by METIS_TAC [map_up, map_down, flookup_thm] >>
`ts_z <> t41 /\ ts_pc <> t41`
by (
`t41 IN bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)`
by fs [example_conditional_bn] >>
`ts_z < t41 /\ ts_pc < t41` by METIS_TAC [names_lt] >> fs []) >>
`t31 < t42 /\ t31 < t52` by fs [] >>
`v1 = a`
by (
`i_assign t41 (e_val val_true) (o_internal (e_val a)) IN I1` by fs [example_conditional] >>
`FLOOKUP (s1 |+ (t41, v1)) t41 = SOME v1` by fs [FLOOKUP_DEF] >>
`sem_expr (e_val a) (s1 |+ (t41, v1)) = SOME v1` by METIS_TAC [wfs_internal_flookup_sem_expr] >>
fs [sem_expr_correct]) >>
`v2 = a'`
by (
`i_assign t41 (e_val val_true) (o_internal (e_val a')) IN I2` by fs [example_conditional] >>
`FLOOKUP (s2 |+ (t41, v2)) t41 = SOME v2` by fs [FLOOKUP_DEF] >>
`sem_expr (e_val a') (s2 |+ (t41, v2)) = SOME v2` by METIS_TAC [wfs_internal_flookup_sem_expr] >>
fs [sem_expr_correct]) >>
Q.EXISTS_TAC `I0` >> Q.EXISTS_TAC `I0'` >>
Q.EXISTS_TAC `a` >> Q.EXISTS_TAC `a'` >> rw [] >>
fs [completed_fupdate, FLOOKUP_UPDATE] >> (
METIS_TAC [example_conditional_t_gt_bn_str_may_addr_t12,
example_conditional_t_gt_bn_str_may_addr_t31,
bn_str_act_addr_eq_s,
bn_str_act_addr_singleton_bn_str_may_addr_nonempty]
ORELSE
fs [FLOOKUP_UPDATE, map_up, map_down] >> fs [] >>
PROVE_TAC [FLOOKUP_UPDATE, map_down])
QED
Theorem example_conditional_rel_t41_exe[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc .
internal_exe_preserving''
(example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc)
t41 (e_val val_true)
Proof
rw [internal_exe_preserving''] >>
fs [example_conditional_rel] >>
(* re-establish relation *)
(* TODO: make it more efficient *)
`example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 s1 C1 F1) (State_st I2 s2 C2 F2)`
by METIS_TAC [example_conditional_rel] >>
Q.EXISTS_TAC `e_val a` >>
Q.EXISTS_TAC `e_val a'` >>
REPEAT STRIP_TAC >>
FIRST_PROVE [
fs [example_conditional_rel, example_conditional, names_e],
`example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 (s1 |+ (t41, v1)) C1 F1) (State_st I2 (s2 |+ (t41, v2)) C2 F2)`
suffices_by rw [example_conditional_rel] >>
METIS_TAC [example_conditional_rel_t41_exe_pre]
]
QED
Theorem example_conditional_rel_t41_exe_sim[local]:
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 S1' obs .
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1 S2 ==>
out_of_order_step' S1 (l_lb obs act_exe t41) S1' ==>
? S2' . out_of_order_step' S2 (l_lb obs act_exe t41) S2' /\
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc S1' S2'
Proof
rw [] >>
ASSUME_TAC (MATCH_MP (SPECL [``example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc``]
R_internal_exe_sim'') (UNDISCH_ALL (SPEC_ALL example_conditional_rel_t41_exe))) >>
METIS_TAC []
QED
(* i_assign t42 (e_name t21) (o_store res_PC t00 t41) *)
Theorem example_conditional_rel_t42_exe_pre[local]:
sem_expr = sem_expr_exe ==>
! t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc I1 s1 C1 F1 I2 s2 C2 F2 v1 v2 .
well_formed_state (State_st I1 (s1 |+ (t42, v1)) C1 F1) ==>
well_formed_state (State_st I2 (s2 |+ (t42, v2)) C2 F2) ==>
map_up s1 t42 ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 s1 C1 F1) (State_st I2 s2 C2 F2) ==>
example_conditional_rel t00 t11 t12 t21 t31 t41 t42 t51 t52 z ts_z ts_pc
(State_st I1 (s1 |+ (t42, v1)) C1 F1) (State_st I2 (s2 |+ (t42, v2)) C2 F2)
Proof
REPEAT strip_tac >>
fs [example_conditional_rel] >>
rename1 `I1 = I0 UNION example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a` >>
`t42 NOTIN FDOM s1` by fs [map_up, map_down, flookup_thm] >>
`map_up s2 t42` by METIS_TAC [map_up, map_down, flookup_thm] >>
`ts_z <> t42 /\ ts_pc <> t42`
by (
`t42 IN bound_names_program (example_conditional t00 t11 t12 t21 t31 t41 t42 t51 t52 z a)`
by fs [example_conditional_bn] >>
`ts_z < t42 /\ ts_pc < t42` by METIS_TAC [names_lt] >> fs []) >>
`t31 < t42 /\ t31 < t52` by fs [] >>
`FLOOKUP s1 t41 = SOME v1`
by (
`i_assign t42 (e_name t21) (o_store res_PC t00 t41) IN I1` by fs [example_conditional] >>
`FLOOKUP (s1 |+ (t42, v1)) t42 = SOME v1` by fs [FLOOKUP_DEF] >>
`FLOOKUP (s1 |+ (t42, v1)) t41 = SOME v1` by METIS_TAC [wfs_store_flookup] >>
`t41 <> t42` by fs [] >>
METIS_TAC [FLOOKUP_UPDATE]) >>
`FLOOKUP s2 t41 = SOME v2`
by (
`i_assign t42 (e_name t21) (o_store res_PC t00 t41) IN I2` by fs [example_conditional] >>
`FLOOKUP (s2 |+ (t42, v2)) t42 = SOME v2` by fs [FLOOKUP_DEF] >>
`FLOOKUP (s2 |+ (t42, v2)) t41 = SOME v2` by METIS_TAC [wfs_store_flookup] >>
`t41 <> t42` by fs [] >>
METIS_TAC [FLOOKUP_UPDATE]) >| [
`v1 = v2` by fs [] >>
Q.EXISTS_TAC `I0` >> Q.EXISTS_TAC `I0'` >>
Q.EXISTS_TAC `a` >> Q.EXISTS_TAC `a'` >> rw [] >>
fs [completed_fupdate, FLOOKUP_UPDATE] >> (
METIS_TAC [example_conditional_t_gt_bn_str_may_addr_t12,
example_conditional_t_gt_bn_str_may_addr_t31,
bn_str_act_addr_eq_s,
bn_str_act_addr_singleton_bn_str_may_addr_nonempty]
ORELSE
fs [FLOOKUP_UPDATE, map_up, map_down] >> fs [] >>
PROVE_TAC [FLOOKUP_UPDATE, map_down]),
`i_assign t42 (e_name t21) (o_store res_PC t00 t41) IN I1` by fs [example_conditional] >>
`FLOOKUP (s1 |+ (t42,v1)) t42 = SOME v1` by rw [FLOOKUP_UPDATE] >>
`?v'. sem_expr (e_name t21) (s1 |+ (t42,v1)) = SOME v' /\ v' <> val_false`
by METIS_TAC [wfs_flookup_condition_not_false] >>
`FLOOKUP (s1 |+ (t42,v1)) t21 = SOME v'` by METIS_TAC [sem_expr_exe] >>
`t21 < t42` by fs [] >>