-
Notifications
You must be signed in to change notification settings - Fork 0
/
hl-upd.html
1204 lines (970 loc) · 106 KB
/
hl-upd.html
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link rel="stylesheet" href="style.css" type="text/css">
<title>hl-upd.html</title>
</head>
<body>
<div class="why3doc">
<pre><span class="comment">(* Propositional Hoare logic with updates *)</span>
<span class="keyword1">theory</span> <a name="ImpLanguage_">ImpLanguage</a>
<span class="keyword1">use</span> <span class="keyword1">export</span> map.<a href="map.html#Map_">Map</a>
<span class="keyword1">use</span> <span class="keyword1">export</span> int.<a href="int.html#Int_">Int</a>
<span class="comment">(* identifiers *)</span>
<span class="keyword1">type</span> <a name="ident_15">ident</a> =
| <a name="MkIdent_16">MkIdent</a> int
<span class="comment">(* expressions *)</span>
<span class="keyword1">type</span> <a name="operator_22">operator</a> = <a name="Oplus_22">Oplus</a> | <a name="Ominus_22">Ominus</a> | <a name="Omult_22">Omult</a>
<span class="keyword1">type</span> <a name="expr_24">expr</a> =
| <a name="Econst_25">Econst</a> int
| <a name="Evar_26">Evar</a> <a href="#ident_15">ident</a>
| <a name="Ebin_27">Ebin</a> expr <a href="#operator_22">operator</a> expr
<span class="comment">(* Boolean expressions *)</span>
<span class="keyword1">type</span> <a name="boperator_32">boperator</a> = <a name="BOeq_32">BOeq</a> | <a name="BOlt_32">BOlt</a> | <a name="BOlteq_32">BOlteq</a> | <a name="BOgt_32">BOgt</a> | <a name="BOgteq_32">BOgteq</a>
<span class="keyword1">type</span> <a name="bexpr_34">bexpr</a> =
| <a name="Bcomp_35">Bcomp</a> <a href="#expr_24">expr</a> <a href="#boperator_32">boperator</a> <a href="#expr_24">expr</a>
| <a name="Btrue_36">Btrue</a>
| <a name="Bfalse_37">Bfalse</a>
| <a name="Band_38">Band</a> bexpr bexpr
| <a name="Bor_39">Bor</a> bexpr bexpr
| <a name="Bnot_40">Bnot</a> bexpr
<span class="comment">(* program states *)</span>
<span class="keyword1">type</span> <a name="state_45">state</a> = <a href="map.html#map_9">map</a> <a href="#ident_15">ident</a> int
<span class="comment">(* evaluation of expressions *)</span>
<span class="keyword1">function</span> <a name="eval_bin_49">eval_bin</a> (x:int) (op:<a href="#operator_22">operator</a>) (y:int) : int =
<span class="keyword1">match</span> op <span class="keyword1">with</span>
| <a href="#Oplus_22">Oplus</a> -> x<a href="int.html#infix%20+_19">+</a>y
| <a href="#Ominus_22">Ominus</a> -> x<a href="int.html#infix%20-_23">-</a>y
| <a href="#Omult_22">Omult</a> -> x<a href="int.html#infix%20*_20">*</a>y
<span class="keyword1">end</span>
<span class="keyword1">function</span> <a name="eval_expr_56">eval_expr</a> (s:<a href="#state_45">state</a>) (e:<a href="#expr_24">expr</a>) : int =
<span class="keyword1">match</span> e <span class="keyword1">with</span>
| <a href="#Econst_25">Econst</a> n -> n
| <a href="#Evar_26">Evar</a> x -> <a href="map.html#get_11">get</a> s x
| <a href="#Ebin_27">Ebin</a> e1 op e2 ->
<a href="#eval_bin_49">eval_bin</a> (<a href="#eval_expr_56">eval_expr</a> s e1) op (<a href="#eval_expr_56">eval_expr</a> s e2)
<span class="keyword1">end</span>
<span class="keyword1">predicate</span> <a name="eval_bop_64">eval_bop</a> (x:int) (bop:<a href="#boperator_32">boperator</a>) (y:int) =
<span class="keyword1">match</span> bop <span class="keyword1">with</span>
| <a href="#BOeq_32">BOeq</a> -> x = y
| <a href="#BOlt_32">BOlt</a> -> x <a href="int.html#infix%20%3C_21"><</a> y
| <a href="#BOlteq_32">BOlteq</a> -> x <a href="int.html#infix%20%3C=_25"><=</a> y
| <a href="#BOgt_32">BOgt</a> -> x <a href="int.html#infix%20%3E_24">></a> y
| <a href="#BOgteq_32">BOgteq</a> -> x <a href="int.html#infix%20%3E=_26">>=</a> y
<span class="keyword1">end</span>
<span class="comment">(* Boolean expressions *)</span>
<span class="comment">(* could be intepreted as Why3 bool instead *)</span>
<span class="keyword1">predicate</span> <a name="eval_bexpr_77">eval_bexpr</a> (s:<a href="#state_45">state</a>) (b:<a href="#bexpr_34">bexpr</a>) =
<span class="keyword1">match</span> b <span class="keyword1">with</span>
| <a href="#Bcomp_35">Bcomp</a> e1 bop e2 -> <a href="#eval_bop_64">eval_bop</a> (<a href="#eval_expr_56">eval_expr</a> s e1) bop (<a href="#eval_expr_56">eval_expr</a> s e2)
| <a href="#Btrue_36">Btrue</a> -> <span class="keyword1">true</span>
| <a href="#Bfalse_37">Bfalse</a> -> <span class="keyword1">false</span>
| <a href="#Band_38">Band</a> b1 b2 -> (<a href="#eval_bexpr_77">eval_bexpr</a> s b1) /\ (<a href="#eval_bexpr_77">eval_bexpr</a> s b2)
| <a href="#Bor_39">Bor</a> b1 b2 -> (<a href="#eval_bexpr_77">eval_bexpr</a> s b1) \/ (<a href="#eval_bexpr_77">eval_bexpr</a> s b2)
| <a href="#Bnot_40">Bnot</a> b1 -> <span class="keyword1">not</span> (<a href="#eval_bexpr_77">eval_bexpr</a> s b1)
<span class="keyword1">end</span>
<span class="comment">(* formulas - extension of bexpr *)</span>
<span class="comment">(* no quantifiers for now *)</span>
<span class="keyword1">type</span> <a name="fmla_94">fmla</a> =
| <a name="Fcomp_95">Fcomp</a> <a href="#expr_24">expr</a> <a href="#boperator_32">boperator</a> <a href="#expr_24">expr</a>
| <a name="Fembed_96">Fembed</a> <a href="#bexpr_34">bexpr</a>
| <a name="Ftrue_97">Ftrue</a>
| <a name="Ffalse_98">Ffalse</a>
| <a name="Fand_99">Fand</a> fmla fmla
| <a name="For_100">For</a> fmla fmla
| <a name="Fnot_101">Fnot</a> fmla
| <a name="Fimplies_102">Fimplies</a> fmla fmla
<span class="comment">(* semantics of formulas *)</span>
<span class="keyword1">predicate</span> <a name="satisfies_107">satisfies</a> (s:<a href="#state_45">state</a>) (p:<a href="#fmla_94">fmla</a>) =
<span class="keyword1">match</span> p <span class="keyword1">with</span>
| <a href="#Fcomp_95">Fcomp</a> e1 bop e2 -> <a href="#eval_bop_64">eval_bop</a> (<a href="#eval_expr_56">eval_expr</a> s e1) bop (<a href="#eval_expr_56">eval_expr</a> s e2)
| <a href="#Fembed_96">Fembed</a> b -> (<a href="#eval_bexpr_77">eval_bexpr</a> s b)
| <a href="#Ftrue_97">Ftrue</a> -> <span class="keyword1">true</span>
| <a href="#Ffalse_98">Ffalse</a> -> <span class="keyword1">false</span>
| <a href="#Fand_99">Fand</a> p1 p2 -> (<a href="#satisfies_107">satisfies</a> s p1) /\ (<a href="#satisfies_107">satisfies</a> s p2)
| <a href="#For_100">For</a> p1 p2 -> (<a href="#satisfies_107">satisfies</a> s p1) \/ (<a href="#satisfies_107">satisfies</a> s p2)
| <a href="#Fnot_101">Fnot</a> p1 -> <span class="keyword1">not</span> (<a href="#satisfies_107">satisfies</a> s p1)
| <a href="#Fimplies_102">Fimplies</a> p1 p2 -> (<span class="keyword1">not</span> (<a href="#satisfies_107">satisfies</a> s p1)) \/ (<a href="#satisfies_107">satisfies</a> s p2)
<span class="keyword1">end</span>
<span class="keyword1">predicate</span> <a name="valid_fmla_119">valid_fmla</a> (p:<a href="#fmla_94">fmla</a>) = <span class="keyword1">forall</span> s:<a href="#state_45">state</a>. <a href="#satisfies_107">satisfies</a> s p
<span class="comment">(* required by one of the VCs for completeness *)</span>
<span class="keyword1">lemma</span> <a name="deduction_124">deduction</a>:
<span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>.
(<span class="keyword1">forall</span> s: <a href="#state_45">state</a>. <a href="#satisfies_107">satisfies</a> s p -> <a href="#satisfies_107">satisfies</a> s q)
->
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p q)
<span class="comment">(* programs include invariants as annotations *)</span>
<span class="keyword1">type</span> <a name="stmt_135">stmt</a> =
| <a name="Sskip_136">Sskip</a>
| <a name="Sassign_137">Sassign</a> <a href="#ident_15">ident</a> <a href="#expr_24">expr</a>
| <a name="Sif_138">Sif</a> <a href="#bexpr_34">bexpr</a> stmt stmt
| <a name="Swhile_139">Swhile</a> <a href="#bexpr_34">bexpr</a> <a href="#fmla_94">fmla</a> stmt
| <a name="Sseq_140">Sseq</a> stmt stmt
<span class="comment">(* This notion of size of programs will be useful *)</span>
<span class="comment">(* to construct variants because of the seqseq rule *)</span>
<span class="keyword1">function</span> <a name="size_147">size</a> (c:<a href="#stmt_135">stmt</a>) : int =
<span class="keyword1">match</span> c <span class="keyword1">with</span>
| <a href="#Sskip_136">Sskip</a> -> 1
| <a href="#Sassign_137">Sassign</a> _ _ -> 1
| <a href="#Sif_138">Sif</a> _ c1 c2 -> 1 <a href="int.html#infix%20+_19">+</a> <a href="#size_147">size</a> c1 <a href="int.html#infix%20+_19">+</a> <a href="#size_147">size</a> c2
| <a href="#Sseq_140">Sseq</a> c1 c2 -> 1 <a href="int.html#infix%20+_19">+</a> 2<a href="int.html#infix%20*_20">*</a><a href="#size_147">size</a> c1 <a href="int.html#infix%20+_19">+</a> <a href="#size_147">size</a> c2
| <a href="#Swhile_139">Swhile</a> _ _ c -> 1 <a href="int.html#infix%20+_19">+</a> <a href="#size_147">size</a> c
<span class="keyword1">end</span>
<span class="comment">(* 3 ways to prove size c >= 0 for all c *)</span>
<span class="comment">(* induction_ty_lex *)</span>
<span class="comment">(* lemma size_pos : forall c[@induction] :stmt. size c >= 0 *)</span>
<span class="keyword1">let</span> <span class="keyword1">rec</span> <span class="keyword1">lemma</span> <a name="size_posLF_162">size_posLF</a> (c:<a href="#stmt_135">stmt</a>) =
<span class="keyword2">ensures</span> { <a href="#size_147">size</a> c <a href="int.html#infix%20%3E=_26">>=</a> 0 }
<span class="keyword1">match</span> c <span class="keyword1">with</span>
| <a href="#Sskip_136">Sskip</a> -> ()
| <a href="#Sassign_137">Sassign</a> _ _ -> ()
| <a href="#Sif_138">Sif</a> _ c1 c2 -> size_posLF c1 ; size_posLF c2
| <a href="#Sseq_140">Sseq</a> c1 c2 -> size_posLF c1 ; size_posLF c2
| <a href="#Swhile_139">Swhile</a> _ _ c -> size_posLF c
<span class="keyword1">end</span>
<span class="comment">(* An alternative would be to define size as a program function *)</span>
<span class="comment">(* [could be ghost] *)</span>
<span class="keyword1">let</span> <span class="keyword1">rec</span> <span class="keyword1">function</span> <a name="sizeC_176">sizeC</a> (c:<a href="#stmt_135">stmt</a>) : int =
<span class="keyword2">ensures</span> { result <a href="int.html#infix%20%3E=_26">>=</a> 0 }
<span class="keyword1">match</span> c <span class="keyword1">with</span>
| <a href="#Sskip_136">Sskip</a> -> 1
| <a href="#Sassign_137">Sassign</a> _ _ -> 1
| <a href="#Sif_138">Sif</a> _ c1 c2 -> 1 <a href="int.html#infix%20+_19">+</a> sizeC c1 <a href="int.html#infix%20+_19">+</a> sizeC c2
| <a href="#Sseq_140">Sseq</a> c1 c2 -> 1 <a href="int.html#infix%20+_19">+</a> 2<a href="int.html#infix%20*_20">*</a>sizeC c1 <a href="int.html#infix%20+_19">+</a> sizeC c2
| <a href="#Swhile_139">Swhile</a> _ _ c -> 1 <a href="int.html#infix%20+_19">+</a> sizeC c
<span class="keyword1">end</span>
<span class="comment">(* Natural Semantics *)</span>
<span class="keyword1">inductive</span> <a name="big_step_191">big_step</a> <a href="#state_45">state</a> <a href="#stmt_135">stmt</a> <a href="#state_45">state</a> =
| <a name="big_step_skip_192">big_step_skip</a>:
<span class="keyword1">forall</span> s:<a href="#state_45">state</a>. <a href="#big_step_191">big_step</a> s <a href="#Sskip_136">Sskip</a> s
| <a name="big_step_assign_195">big_step_assign</a>:
<span class="keyword1">forall</span> s:<a href="#state_45">state</a>, e:<a href="#expr_24">expr</a>, x:<a href="#ident_15">ident</a>.
<a href="#big_step_191">big_step</a> s (<a href="#Sassign_137">Sassign</a> x e) (<a href="map.html#set_13">set</a> s x (<a href="#eval_expr_56">eval_expr</a> s e))
| <a name="big_step_seq_199">big_step_seq</a>:
<span class="keyword1">forall</span> s1 s2 s3:<a href="#state_45">state</a>, c1 c2:<a href="#stmt_135">stmt</a>.
<a href="#big_step_191">big_step</a> s1 c1 s2 ->
<a href="#big_step_191">big_step</a> s2 c2 s3 ->
<a href="#big_step_191">big_step</a> s1 (<a href="#Sseq_140">Sseq</a> c1 c2) s3
| <a name="big_step_if_true_205">big_step_if_true</a>:
<span class="keyword1">forall</span> s s':<a href="#state_45">state</a>, b:<a href="#bexpr_34">bexpr</a>, c1 c2:<a href="#stmt_135">stmt</a>.
<a href="#eval_bexpr_77">eval_bexpr</a> s b ->
<a href="#big_step_191">big_step</a> s c1 s'->
<a href="#big_step_191">big_step</a> s (<a href="#Sif_138">Sif</a> b c1 c2) s'
| <a name="big_step_if_false_211">big_step_if_false</a>:
<span class="keyword1">forall</span> s s':<a href="#state_45">state</a>, b:<a href="#bexpr_34">bexpr</a>, c1 c2:<a href="#stmt_135">stmt</a>.
<span class="keyword1">not</span> (<a href="#eval_bexpr_77">eval_bexpr</a> s b) ->
<a href="#big_step_191">big_step</a> s c2 s' ->
<a href="#big_step_191">big_step</a> s (<a href="#Sif_138">Sif</a> b c1 c2) s'
| <a name="big_step_while_true_217">big_step_while_true</a>:
<span class="keyword1">forall</span> s s' s'':<a href="#state_45">state</a>, b:<a href="#bexpr_34">bexpr</a>, i:<a href="#fmla_94">fmla</a>, c:<a href="#stmt_135">stmt</a>.
<a href="#eval_bexpr_77">eval_bexpr</a> s b ->
<a href="#big_step_191">big_step</a> s c s' ->
<a href="#big_step_191">big_step</a> s' (<a href="#Swhile_139">Swhile</a> b i c) s'' ->
<a href="#big_step_191">big_step</a> s (<a href="#Swhile_139">Swhile</a> b i c) s''
| <a name="big_step_while_false_224">big_step_while_false</a>:
<span class="keyword1">forall</span> s:<a href="#state_45">state</a>, b:<a href="#bexpr_34">bexpr</a>, i:<a href="#fmla_94">fmla</a>, c:<a href="#stmt_135">stmt</a>.
<span class="keyword1">not</span> (<a href="#eval_bexpr_77">eval_bexpr</a> s b) ->
<a href="#big_step_191">big_step</a> s (<a href="#Swhile_139">Swhile</a> b i c) s
<span class="comment">(* not required but a nice example of using two forms of induction *)</span>
<span class="comment">(* use induction_ty_lex then induction_pr for the loop case *)</span>
<span class="keyword1">lemma</span> <a name="deterministic_execution_234">deterministic_execution</a> : <span class="keyword1">forall</span> c [@induction]:<a href="#stmt_135">stmt</a>, s s' s'' :<a href="#state_45">state</a>.
(<a href="#big_step_191">big_step</a> s c s') -> (<a href="#big_step_191">big_step</a> s c s'') -> s' = s''
<span class="comment">(* Required for soundness *)</span>
<span class="keyword1">lemma</span> <a name="AssignSeq_241">AssignSeq</a>:
<span class="keyword1">forall</span> x :<a href="#ident_15">ident</a>, e :<a href="#expr_24">expr</a>, c :<a href="#stmt_135">stmt</a>, s s' :<a href="#state_45">state</a>.
<a href="#big_step_191">big_step</a> s (<a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> x e) c) s' ->
<a href="#big_step_191">big_step</a> (<a href="map.html#set_13">set</a> s x (<a href="#eval_expr_56">eval_expr</a> s e)) c s'
<span class="keyword1">lemma</span> <a name="IfSeqTrue_246">IfSeqTrue</a>:
<span class="keyword1">forall</span> b :<a href="#bexpr_34">bexpr</a>, c1 c2 c :<a href="#stmt_135">stmt</a>, s s' :<a href="#state_45">state</a>.
<a href="#big_step_191">big_step</a> s (<a href="#Sseq_140">Sseq</a> (<a href="#Sif_138">Sif</a> b c1 c2) c) s' ->
<a href="#eval_bexpr_77">eval_bexpr</a> s b -> <a href="#big_step_191">big_step</a> s (<a href="#Sseq_140">Sseq</a> c1 c) s'
<span class="keyword1">lemma</span> <a name="IfSeqFalse_251">IfSeqFalse</a>:
<span class="keyword1">forall</span> b :<a href="#bexpr_34">bexpr</a>, c1 c2 c :<a href="#stmt_135">stmt</a>, s s' :<a href="#state_45">state</a>.
<a href="#big_step_191">big_step</a> s (<a href="#Sseq_140">Sseq</a> (<a href="#Sif_138">Sif</a> b c1 c2) c) s' ->
<a href="#eval_bexpr_77">eval_bexpr</a> s (<a href="#Bnot_40">Bnot</a> b) -> <a href="#big_step_191">big_step</a> s (<a href="#Sseq_140">Sseq</a> c2 c) s'
<span class="comment">(* Required for soundness and completeness *)</span>
<span class="keyword1">lemma</span> <a name="SeqSeq_260">SeqSeq</a>:
<span class="keyword1">forall</span> c1 c2 c:<a href="#stmt_135">stmt</a>, s s' :<a href="#state_45">state</a>.
<a href="#big_step_191">big_step</a> s (<a href="#Sseq_140">Sseq</a> c1 (<a href="#Sseq_140">Sseq</a> c2 c)) s'
<->
<a href="#big_step_191">big_step</a> s (<a href="#Sseq_140">Sseq</a> (<a href="#Sseq_140">Sseq</a> c1 c2) c) s'
<span class="keyword1">end</span>
<span class="keyword1">theory</span> <a name="Updates_">Updates</a>
<span class="keyword1">use</span> <a href="#ImpLanguage_">ImpLanguage</a>
<span class="comment">(* updates are (total) mappings *)</span>
<span class="keyword1">type</span> <a name="upd_281">upd</a> = <a href="map.html#map_9">map</a> <a href="#ident_15">ident</a> <a href="#expr_24">expr</a>
<span class="comment">(* The empty update will be represented as the identity mapping *)</span>
<span class="keyword1">let</span> <span class="keyword1">constant</span> <a name="idUpd_286">idUpd</a> : <a href="#upd_281">upd</a> =
<span class="keyword1">fun</span> (x:<a href="#ident_15">ident</a>) -> <a href="#Evar_26">Evar</a> x
<span class="keyword1">predicate</span> <a name="isId_289">isId</a> (u:<a href="#upd_281">upd</a>) =
<span class="keyword1">forall</span> a: <a href="#ident_15">ident</a>. <a href="map.html#get_11">get</a> u a = <a href="#Evar_26">Evar</a> a
<span class="comment">(* update application to states *)</span>
<span class="keyword1">function</span> <a name="applyS_296">applyS</a> (u:<a href="#upd_281">upd</a>) (s:<a href="#state_45">state</a>) : <a href="#state_45">state</a> =
<span class="keyword1">fun</span> (x:<a href="#ident_15">ident</a>) -> <a href="#eval_expr_56">eval_expr</a> s (u x)
<span class="keyword1">lemma</span> <a name="applySId_299">applySId</a>:
<span class="keyword1">forall</span> u :<a href="#upd_281">upd</a>, s :<a href="#state_45">state</a>.
<a href="#isId_289">isId</a> u -> <a href="#applyS_296">applyS</a> u s = s
<span class="comment">(* update application to expressions *)</span>
<span class="keyword1">let</span> <span class="keyword1">rec</span> <span class="keyword1">function</span> <a name="applyE_306">applyE</a> (u:<a href="#upd_281">upd</a>) (e:<a href="#expr_24">expr</a>) : <a href="#expr_24">expr</a> =
<span class="keyword2">ensures</span> { <span class="keyword1">forall</span> s :<a href="#state_45">state</a>. <a href="#eval_expr_56">eval_expr</a> s result = <a href="#eval_expr_56">eval_expr</a> (<a href="#applyS_296">applyS</a> u s) e }
<span class="keyword2">variant</span> { e }
<span class="keyword1">match</span> e <span class="keyword1">with</span>
| <a href="#Econst_25">Econst</a> n -> <a href="#Econst_25">Econst</a> n
| <a href="#Evar_26">Evar</a> x -> <a href="map.html#get_11">get</a> u x
| <a href="#Ebin_27">Ebin</a> e1 op e2 -> <a href="#Ebin_27">Ebin</a> (applyE u e1) op (applyE u e2)
<span class="keyword1">end</span>
<span class="comment">(* could be logic function + lemma *)</span>
<span class="comment">(* lemma exprUpdate: forall s:state, e[@induction]:expr, u: upd. *)</span>
<span class="comment">(* eval_expr s (applyE u e) = eval_expr (applyS u s) e *)</span>
<span class="comment">(* let rec lemma exprUpdateLF (s:state) (e: expr) (u: upd) : unit *)</span>
<span class="comment">(* ensures { eval_expr s (applyE u e) = eval_expr (applyS u s) e } *)</span>
<span class="comment">(* variant { e } *)</span>
<span class="comment">(* = match e with *)</span>
<span class="comment">(* | Econst _ -> () *)</span>
<span class="comment">(* | Evar _ -> () *)</span>
<span class="comment">(* | Ebin e1 _ e2 -> exprUpdateLF s e1 u; exprUpdateLF s e2 u *)</span>
<span class="comment">(* end *)</span>
<span class="comment">(* lemma applyEId: *)</span>
<span class="comment">(* forall u :upd, e[@induction] :expr. *)</span>
<span class="comment">(* isId u -> applyE u e = e *)</span>
<span class="keyword1">let</span> <span class="keyword1">rec</span> <span class="keyword1">lemma</span> <a name="applyEIdLF_339">applyEIdLF</a> (u:<a href="#upd_281">upd</a>) (e:<a href="#expr_24">expr</a>)
<span class="keyword2">requires</span> { <a href="#isId_289">isId</a> u }
<span class="keyword2">ensures</span> { <a href="#applyE_306">applyE</a> u e = e }
= <span class="keyword1">match</span> e <span class="keyword1">with</span>
| <a href="#Econst_25">Econst</a> _ -> ()
| <a href="#Evar_26">Evar</a> _ -> ()
| <a href="#Ebin_27">Ebin</a> e1 _ e2 -> applyEIdLF u e1 ; applyEIdLF u e2
<span class="keyword1">end</span>
<span class="comment">(* update application to Boolean expressions *)</span>
<span class="keyword1">let</span> <span class="keyword1">rec</span> <span class="keyword1">ghost</span> <span class="keyword1">function</span> <a name="applyB_351">applyB</a> (u:<a href="#upd_281">upd</a>) (b:<a href="#bexpr_34">bexpr</a>) : <a href="#bexpr_34">bexpr</a> =
<span class="keyword2">ensures</span> { <span class="keyword1">forall</span> s :<a href="#state_45">state</a>. <a href="#eval_bexpr_77">eval_bexpr</a> s result <-> <a href="#eval_bexpr_77">eval_bexpr</a> (<a href="#applyS_296">applyS</a> u s) b }
<span class="keyword2">variant</span> { b }
<span class="keyword1">match</span> b <span class="keyword1">with</span>
| <a href="#Bcomp_35">Bcomp</a> e1 bop e2 -> <a href="#Bcomp_35">Bcomp</a> (<a href="#applyE_306">applyE</a> u e1) bop (<a href="#applyE_306">applyE</a> u e2)
| <a href="#Btrue_36">Btrue</a> -> <a href="#Btrue_36">Btrue</a>
| <a href="#Bfalse_37">Bfalse</a> -> <a href="#Bfalse_37">Bfalse</a>
| <a href="#Band_38">Band</a> b1 b2 -> <a href="#Band_38">Band</a> (applyB u b1) (applyB u b2)
| <a href="#Bor_39">Bor</a> b1 b2 -> <a href="#Bor_39">Bor</a> (applyB u b1) (applyB u b2)
| <a href="#Bnot_40">Bnot</a> b1 -> <a href="#Bnot_40">Bnot</a> (applyB u b1)
<span class="keyword1">end</span>
<span class="comment">(* lemma applyBId: *)</span>
<span class="comment">(* forall u :upd, b[@induction] :bexpr. *)</span>
<span class="comment">(* isId u -> applyB u b = b *)</span>
<span class="keyword1">let</span> <span class="keyword1">rec</span> <span class="keyword1">lemma</span> <a name="applyBIdLF_369">applyBIdLF</a> (u:<a href="#upd_281">upd</a>) (b:<a href="#bexpr_34">bexpr</a>)
<span class="keyword2">requires</span> { <a href="#isId_289">isId</a> u }
<span class="keyword2">ensures</span> { <a href="#applyB_351">applyB</a> u b = b }
= <span class="keyword1">match</span> b <span class="keyword1">with</span>
| <a href="#Bcomp_35">Bcomp</a> _ _ _ -> ()
| <a href="#Btrue_36">Btrue</a> -> ()
| <a href="#Bfalse_37">Bfalse</a> -> ()
| <a href="#Band_38">Band</a> b1 b2 -> applyBIdLF u b1 ; applyBIdLF u b2
| <a href="#Bor_39">Bor</a> b1 b2 -> applyBIdLF u b1 ; applyBIdLF u b2
| <a href="#Bnot_40">Bnot</a> b1 -> applyBIdLF u b1
<span class="keyword1">end</span>
<span class="comment">(* update application to formulas *)</span>
<span class="keyword1">let</span> <span class="keyword1">rec</span> <span class="keyword1">ghost</span> <span class="keyword1">function</span> <a name="applyF_386">applyF</a> (u:<a href="#upd_281">upd</a>) (p:<a href="#fmla_94">fmla</a>) : <a href="#fmla_94">fmla</a> =
<span class="keyword2">ensures</span> { <span class="keyword1">forall</span> s :<a href="#state_45">state</a>. <a href="#satisfies_107">satisfies</a> s result <-> <a href="#satisfies_107">satisfies</a> (<a href="#applyS_296">applyS</a> u s) p }
<span class="keyword2">variant</span> { p }
<span class="keyword1">match</span> p <span class="keyword1">with</span>
| <a href="#Fcomp_95">Fcomp</a> e1 bop e2 -> <a href="#Fcomp_95">Fcomp</a> (<a href="#applyE_306">applyE</a> u e1) bop (<a href="#applyE_306">applyE</a> u e2)
| <a href="#Fembed_96">Fembed</a> b -> <a href="#Fembed_96">Fembed</a> (<a href="#applyB_351">applyB</a> u b)
| <a href="#Ftrue_97">Ftrue</a> -> <a href="#Ftrue_97">Ftrue</a>
| <a href="#Ffalse_98">Ffalse</a> -> <a href="#Ffalse_98">Ffalse</a>
| <a href="#Fand_99">Fand</a> p1 p2 -> <a href="#Fand_99">Fand</a> (applyF u p1) (applyF u p2)
| <a href="#For_100">For</a> p1 p2 -> <a href="#For_100">For</a> (applyF u p1) (applyF u p2)
| <a href="#Fnot_101">Fnot</a> p1 -> <a href="#Fnot_101">Fnot</a> (applyF u p1)
| <a href="#Fimplies_102">Fimplies</a> p1 p2 -> <a href="#Fimplies_102">Fimplies</a> (applyF u p1) (applyF u p2)
<span class="keyword1">end</span>
<span class="comment">(* lemma applyFId: *)</span>
<span class="comment">(* forall u :upd, p[@induction] :fmla. *)</span>
<span class="comment">(* isId u -> applyF u p = p *)</span>
<span class="keyword1">let</span> <span class="keyword1">rec</span> <span class="keyword1">lemma</span> <a name="applyFIdLF_405">applyFIdLF</a> (u:<a href="#upd_281">upd</a>) (p:<a href="#fmla_94">fmla</a>)
<span class="keyword2">requires</span> { <a href="#isId_289">isId</a> u }
<span class="keyword2">ensures</span> { <a href="#applyF_386">applyF</a> u p = p }
= <span class="keyword1">match</span> p <span class="keyword1">with</span>
| <a href="#Fcomp_95">Fcomp</a> _ _ _ -> ()
| <a href="#Fembed_96">Fembed</a> _ -> ()
| <a href="#Ftrue_97">Ftrue</a> -> ()
| <a href="#Ffalse_98">Ffalse</a> -> ()
| <a href="#Fand_99">Fand</a> p1 p2 -> applyFIdLF u p1 ; applyFIdLF u p2
| <a href="#For_100">For</a> p1 p2 -> applyFIdLF u p1 ; applyFIdLF u p2
| <a href="#Fnot_101">Fnot</a> p1 -> applyFIdLF u p1
| <a href="#Fimplies_102">Fimplies</a> p1 p2 -> applyFIdLF u p1 ; applyFIdLF u p2
<span class="keyword1">end</span>
<span class="comment">(* "update update" with an assignment *)</span>
<span class="comment">(* If defined as program function it would necessarily *)</span>
<span class="comment">(* be ghost since the map set function is ghost *)</span>
<span class="keyword1">function</span> <a name="assign_425">assign</a> (u:<a href="#upd_281">upd</a>) (x:<a href="#ident_15">ident</a>) (e:<a href="#expr_24">expr</a>) : <a href="#upd_281">upd</a> =
<a href="map.html#set_13">set</a> u x (<a href="#applyE_306">applyE</a> u e)
<span class="comment">(* interaction between assignment and application of update to state *)</span>
<span class="keyword1">lemma</span> <a name="applySAssign_431">applySAssign</a> :
<span class="keyword1">forall</span> x: <a href="#ident_15">ident</a>, e: <a href="#expr_24">expr</a>, u: <a href="#upd_281">upd</a>, s: <a href="#state_45">state</a>.
<a href="#applyS_296">applyS</a> (<a href="#assign_425">assign</a> u x e) s = <span class="keyword1">let</span> s' = <a href="#applyS_296">applyS</a> u s
<span class="keyword1">in</span> <a href="map.html#set_13">set</a> s' x (<a href="#eval_expr_56">eval_expr</a> s' e)
<span class="comment">(* Some tests... *)</span>
<span class="keyword1">goal</span> <a name="AssignTest1_440">AssignTest1</a> :
<span class="keyword1">let</span> x = <a href="#MkIdent_16">MkIdent</a> 0 <span class="keyword1">in</span>
<span class="keyword1">let</span> u = (<span class="keyword1">fun</span> _ -> <a href="#Econst_25">Econst</a> 2) <span class="keyword1">in</span> <span class="comment">(* constant update in two differente senses... *)</span>
<span class="keyword1">let</span> u = <a href="#assign_425">assign</a> u x (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> x) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 13)) <span class="keyword1">in</span>
<a href="map.html#get_11">get</a> u x = (<a href="#Ebin_27">Ebin</a> (<a href="#Econst_25">Econst</a> 2) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 13))
<span class="keyword1">goal</span> <a name="AssignTest2_446">AssignTest2</a> :
<span class="keyword1">let</span> x = <a href="#MkIdent_16">MkIdent</a> 0 <span class="keyword1">in</span>
<span class="keyword1">let</span> u = <a href="#idUpd_286">idUpd</a> <span class="keyword1">in</span> <span class="comment">(* identity update *)</span>
<span class="keyword1">let</span> u = <a href="#assign_425">assign</a> u x (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> x) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 10)) <span class="keyword1">in</span>
<span class="keyword1">let</span> u = <a href="#assign_425">assign</a> u x (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> x) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 20)) <span class="keyword1">in</span>
<a href="map.html#get_11">get</a> u x = <a href="#Ebin_27">Ebin</a> (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> x) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 10)) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 20)
<span class="keyword1">goal</span> <a name="AssignTestSwap_453">AssignTestSwap</a> :
<span class="keyword1">let</span> x = <a href="#MkIdent_16">MkIdent</a> 0 <span class="keyword1">in</span>
<span class="keyword1">let</span> y = <a href="#MkIdent_16">MkIdent</a> 1 <span class="keyword1">in</span>
<span class="keyword1">let</span> t = <a href="#MkIdent_16">MkIdent</a> 2 <span class="keyword1">in</span>
<span class="keyword1">let</span> u = <a href="#idUpd_286">idUpd</a> <span class="keyword1">in</span>
<span class="keyword1">let</span> u = <a href="#assign_425">assign</a> u t (<a href="#Evar_26">Evar</a> x) <span class="keyword1">in</span>
<span class="keyword1">let</span> u = <a href="#assign_425">assign</a> u x (<a href="#Evar_26">Evar</a> y) <span class="keyword1">in</span>
<span class="keyword1">let</span> u = <a href="#assign_425">assign</a> u y (<a href="#Evar_26">Evar</a> t) <span class="keyword1">in</span>
(<a href="map.html#get_11">get</a> u y = <a href="#Evar_26">Evar</a> x) /\ (<a href="map.html#get_11">get</a> u x = <a href="#Evar_26">Evar</a> y)
<span class="keyword1">goal</span> <a name="AssignTestSwap2_463">AssignTestSwap2</a> :
<span class="keyword1">forall</span> x y t :<a href="#ident_15">ident</a>, u u1 u2 u3 :<a href="#upd_281">upd</a>.
x <> t -> y <> t ->
<a href="#isId_289">isId</a> u ->
u1 = <a href="#assign_425">assign</a> u t (<a href="#Evar_26">Evar</a> x) ->
u2 = <a href="#assign_425">assign</a> u1 x (<a href="#Evar_26">Evar</a> y) ->
u3 = <a href="#assign_425">assign</a> u2 y (<a href="#Evar_26">Evar</a> t) ->
(<a href="map.html#get_11">get</a> u3 y = <a href="#Evar_26">Evar</a> x) /\ (<a href="map.html#get_11">get</a> u3 x = <a href="#Evar_26">Evar</a> y)
<span class="keyword1">end</span>
<span class="keyword1">theory</span> <a name="Semantics_">Semantics</a>
<span class="keyword1">use</span> <span class="keyword1">export</span> <a href="#ImpLanguage_">ImpLanguage</a>
<span class="keyword1">use</span> <span class="keyword1">export</span> <a href="#Updates_">Updates</a>
<span class="comment">(* Hoare triples *)</span>
<span class="keyword1">predicate</span> <a name="valid_triple_485">valid_triple</a> (p:<a href="#fmla_94">fmla</a>) (u:<a href="#upd_281">upd</a>) (c:<a href="#stmt_135">stmt</a>) (q:<a href="#fmla_94">fmla</a>) =
<span class="keyword1">forall</span> s s' :<a href="#state_45">state</a>.
<a href="#satisfies_107">satisfies</a> s p ->
<a href="#big_step_191">big_step</a> (<a href="#applyS_296">applyS</a> u s) c s' ->
<a href="#satisfies_107">satisfies</a> s' q
<span class="comment">(* Example triples tested for validity *)</span>
<span class="keyword1">goal</span> <a name="TestValidTripleSimpleProg1_495">TestValidTripleSimpleProg1</a> :
<span class="keyword1">let</span> x = <a href="#MkIdent_16">MkIdent</a> 0 <span class="keyword1">in</span>
<span class="keyword1">let</span> y = <a href="#MkIdent_16">MkIdent</a> 1 <span class="keyword1">in</span>
<span class="keyword1">let</span> prog = <a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> y (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> y) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 10))) <a href="#Sskip_136">Sskip</a> <span class="keyword1">in</span>
<span class="keyword1">let</span> p = <a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> x) <span class="keyword1">in</span>
<span class="keyword1">let</span> q = <a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> x) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 10)) <span class="keyword1">in</span>
<a href="#valid_triple_485">valid_triple</a> p <a href="#idUpd_286">idUpd</a> prog q
<span class="keyword1">goal</span> <a name="TestValidTripleSimpleProg2_504">TestValidTripleSimpleProg2</a> :
<span class="keyword1">let</span> x = <a href="#MkIdent_16">MkIdent</a> 0 <span class="keyword1">in</span>
<span class="keyword1">let</span> y = <a href="#MkIdent_16">MkIdent</a> 1 <span class="keyword1">in</span>
<span class="keyword1">let</span> prog = <a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> y (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> y) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 10))) <a href="#Sskip_136">Sskip</a> <span class="keyword1">in</span>
<span class="keyword1">let</span> p = <a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> x) <span class="keyword1">in</span>
<span class="keyword1">let</span> q = <a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> x) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 10)) <span class="keyword1">in</span>
<a href="#valid_triple_485">valid_triple</a> p <a href="#idUpd_286">idUpd</a> prog q
<span class="keyword1">goal</span> <a name="TestValidTripleSwapProg_513">TestValidTripleSwapProg</a> :
<span class="keyword1">let</span> x = <a href="#MkIdent_16">MkIdent</a> 0 <span class="keyword1">in</span>
<span class="keyword1">let</span> y = <a href="#MkIdent_16">MkIdent</a> 1 <span class="keyword1">in</span>
<span class="keyword1">let</span> t = <a href="#MkIdent_16">MkIdent</a> 2 <span class="keyword1">in</span>
<span class="keyword1">let</span> a = <a href="#MkIdent_16">MkIdent</a> 3 <span class="keyword1">in</span>
<span class="keyword1">let</span> b = <a href="#MkIdent_16">MkIdent</a> 4 <span class="keyword1">in</span>
<span class="keyword1">let</span> swap = <a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> t (<a href="#Evar_26">Evar</a> x))
(<a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> x (<a href="#Evar_26">Evar</a> y))
(<a href="#Sassign_137">Sassign</a> y (<a href="#Evar_26">Evar</a> t))) <span class="keyword1">in</span>
<span class="keyword1">let</span> p = <a href="#Fand_99">Fand</a> (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> x) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> a)) (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> b)) <span class="keyword1">in</span>
<span class="keyword1">let</span> q = <a href="#Fand_99">Fand</a> (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> a)) (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> x) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> b)) <span class="keyword1">in</span>
<a href="#valid_triple_485">valid_triple</a> p <a href="#idUpd_286">idUpd</a> swap q
<span class="keyword1">goal</span> <a name="TestValidTripleAltSwapProg_527">TestValidTripleAltSwapProg</a> :
<span class="keyword1">let</span> x = <a href="#MkIdent_16">MkIdent</a> 0 <span class="keyword1">in</span>
<span class="keyword1">let</span> y = <a href="#MkIdent_16">MkIdent</a> 1 <span class="keyword1">in</span>
<span class="keyword1">let</span> t = <a href="#MkIdent_16">MkIdent</a> 2 <span class="keyword1">in</span>
<span class="keyword1">let</span> a = <a href="#MkIdent_16">MkIdent</a> 3 <span class="keyword1">in</span>
<span class="keyword1">let</span> b = <a href="#MkIdent_16">MkIdent</a> 4 <span class="keyword1">in</span>
<span class="keyword1">let</span> swap = <a href="#Sseq_140">Sseq</a> (<a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> t (<a href="#Evar_26">Evar</a> x))
(<a href="#Sassign_137">Sassign</a> x (<a href="#Evar_26">Evar</a> y)))
(<a href="#Sassign_137">Sassign</a> y (<a href="#Evar_26">Evar</a> t)) <span class="keyword1">in</span>
<span class="keyword1">let</span> p = <a href="#Fand_99">Fand</a> (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> x) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> a)) (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> b)) <span class="keyword1">in</span>
<span class="keyword1">let</span> q = <a href="#Fand_99">Fand</a> (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> a)) (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> x) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> b)) <span class="keyword1">in</span>
<a href="#valid_triple_485">valid_triple</a> p <a href="#idUpd_286">idUpd</a> swap q
<span class="keyword1">end</span>
<span class="keyword1">theory</span> <a name="SystemHu_">SystemHu</a>
<span class="keyword1">use</span> <a href="#Semantics_">Semantics</a>
<span class="comment">(* Inference system of Hoare Logic with Updates *)</span>
<span class="comment">(* DOES NOT MAKE USE OF ANNOTATED LOOP INVARIANTS *)</span>
<span class="keyword1">inductive</span> <a name="infHu_554">infHu</a> <a href="#fmla_94">fmla</a> <a href="#upd_281">upd</a> <a href="#stmt_135">stmt</a> <a href="#fmla_94">fmla</a> =
| <a name="infHu_skip_556">infHu_skip</a>:
<span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>.
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u q)) ->
<a href="#infHu_554">infHu</a> p u <a href="#Sskip_136">Sskip</a> q
| <a name="infHu_assign_561">infHu_assign</a>:
<span class="keyword1">forall</span> p :<a href="#fmla_94">fmla</a>, q :<a href="#fmla_94">fmla</a>, x :<a href="#ident_15">ident</a>, e :<a href="#expr_24">expr</a>, u :<a href="#upd_281">upd</a>.
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> (<a href="#assign_425">assign</a> u x e) q)) ->
<a href="#infHu_554">infHu</a> p u (<a href="#Sassign_137">Sassign</a> x e) q
| <a name="infHu_if_566">infHu_if</a>:
<span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, c1 c2 :<a href="#stmt_135">stmt</a>, b :<a href="#bexpr_34">bexpr</a>, u :<a href="#upd_281">upd</a>.
<a href="#infHu_554">infHu</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fembed_96">Fembed</a> b))) u c1 q ->
<a href="#infHu_554">infHu</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b)))) u c2 q ->
<a href="#infHu_554">infHu</a> p u (<a href="#Sif_138">Sif</a> b c1 c2) q
| <a name="infHu_while_572">infHu_while</a>:
<span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, c :<a href="#stmt_135">stmt</a>, b :<a href="#bexpr_34">bexpr</a>, inv ainv :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>.
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u inv)) ->
<a href="#infHu_554">infHu</a> (<a href="#Fand_99">Fand</a> inv (<a href="#Fembed_96">Fembed</a> b)) <a href="#idUpd_286">idUpd</a> c inv ->
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> (<a href="#Fand_99">Fand</a> inv (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b))) q) ->
<a href="#infHu_554">infHu</a> p u (<a href="#Swhile_139">Swhile</a> b ainv c) q
| <a name="infHu_skipseq_579">infHu_skipseq</a>:
<span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>, c :<a href="#stmt_135">stmt</a>.
<a href="#infHu_554">infHu</a> p u c q ->
<a href="#infHu_554">infHu</a> p u (<a href="#Sseq_140">Sseq</a> <a href="#Sskip_136">Sskip</a> c) q
| <a name="infHu_assignseq_584">infHu_assignseq</a>:
<span class="keyword1">forall</span> p :<a href="#fmla_94">fmla</a>, q :<a href="#fmla_94">fmla</a>, x :<a href="#ident_15">ident</a>, e :<a href="#expr_24">expr</a>, c :<a href="#stmt_135">stmt</a>, u :<a href="#upd_281">upd</a>.
<a href="#infHu_554">infHu</a> p (<a href="#assign_425">assign</a> u x e) c q ->
<a href="#infHu_554">infHu</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> x e) c) q
| <a name="infHu_ifseq_589">infHu_ifseq</a>:
<span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, c1 c2 c :<a href="#stmt_135">stmt</a>, b :<a href="#bexpr_34">bexpr</a>, u :<a href="#upd_281">upd</a>.
<a href="#infHu_554">infHu</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fembed_96">Fembed</a> b))) u (<a href="#Sseq_140">Sseq</a> c1 c) q ->
<a href="#infHu_554">infHu</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b)))) u (<a href="#Sseq_140">Sseq</a> c2 c) q ->
<a href="#infHu_554">infHu</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Sif_138">Sif</a> b c1 c2) c) q
| <a name="infHu_whileseq_595">infHu_whileseq</a>:
<span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, c cc :<a href="#stmt_135">stmt</a>, b :<a href="#bexpr_34">bexpr</a>, inv ainv :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>.
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u inv)) ->
<a href="#infHu_554">infHu</a> (<a href="#Fand_99">Fand</a> inv (<a href="#Fembed_96">Fembed</a> b)) <a href="#idUpd_286">idUpd</a> c inv ->
<a href="#infHu_554">infHu</a> (<a href="#Fand_99">Fand</a> inv (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b))) <a href="#idUpd_286">idUpd</a> cc q ->
<a href="#infHu_554">infHu</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Swhile_139">Swhile</a> b ainv c) cc) q
| <a name="infHu_seqseq_602">infHu_seqseq</a>:
<span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, c1 c2 c :<a href="#stmt_135">stmt</a>, u :<a href="#upd_281">upd</a>.
<a href="#infHu_554">infHu</a> p u (<a href="#Sseq_140">Sseq</a> c1 (<a href="#Sseq_140">Sseq</a> c2 c)) q ->
<a href="#infHu_554">infHu</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Sseq_140">Sseq</a> c1 c2) c) q
<span class="comment">(* Example inferences *)</span>
<span class="keyword1">goal</span> <a name="TestInfSimpleProg1_612">TestInfSimpleProg1</a> :
<span class="keyword1">let</span> x = <a href="#MkIdent_16">MkIdent</a> 0 <span class="keyword1">in</span>
<span class="keyword1">let</span> y = <a href="#MkIdent_16">MkIdent</a> 1 <span class="keyword1">in</span>
<span class="keyword1">let</span> prog = <a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> y (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> y) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 10))) <a href="#Sskip_136">Sskip</a> <span class="keyword1">in</span>
<span class="keyword1">let</span> p = <a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> x) <span class="keyword1">in</span>
<span class="keyword1">let</span> q = <a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> x) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 10)) <span class="keyword1">in</span>
<a href="#infHu_554">infHu</a> p <a href="#idUpd_286">idUpd</a> prog q
<span class="keyword1">goal</span> <a name="TestInfSimpleProg2_621">TestInfSimpleProg2</a> :
<span class="keyword1">let</span> x = <a href="#MkIdent_16">MkIdent</a> 0 <span class="keyword1">in</span>
<span class="keyword1">let</span> y = <a href="#MkIdent_16">MkIdent</a> 1 <span class="keyword1">in</span>
<span class="keyword1">let</span> prog = <a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> y (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> y) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 10))) <a href="#Sskip_136">Sskip</a> <span class="keyword1">in</span>
<span class="keyword1">let</span> p = <a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> x) <span class="keyword1">in</span>
<span class="keyword1">let</span> q = <a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Ebin_27">Ebin</a> (<a href="#Evar_26">Evar</a> x) <a href="#Oplus_22">Oplus</a> (<a href="#Econst_25">Econst</a> 10)) <span class="keyword1">in</span>
<a href="#infHu_554">infHu</a> p <a href="#idUpd_286">idUpd</a> prog q
<span class="keyword1">goal</span> <a name="TestInfSwapProg_630">TestInfSwapProg</a> :
<span class="keyword1">let</span> x = <a href="#MkIdent_16">MkIdent</a> 0 <span class="keyword1">in</span>
<span class="keyword1">let</span> y = <a href="#MkIdent_16">MkIdent</a> 1 <span class="keyword1">in</span>
<span class="keyword1">let</span> t = <a href="#MkIdent_16">MkIdent</a> 2 <span class="keyword1">in</span>
<span class="keyword1">let</span> a = <a href="#MkIdent_16">MkIdent</a> 3 <span class="keyword1">in</span>
<span class="keyword1">let</span> b = <a href="#MkIdent_16">MkIdent</a> 4 <span class="keyword1">in</span>
<span class="keyword1">let</span> swap = <a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> t (<a href="#Evar_26">Evar</a> x))
(<a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> x (<a href="#Evar_26">Evar</a> y))
(<a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> y (<a href="#Evar_26">Evar</a> t))
<a href="#Sskip_136">Sskip</a>)) <span class="keyword1">in</span>
<span class="keyword1">let</span> p = <a href="#Fand_99">Fand</a> (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> x) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> a)) (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> b)) <span class="keyword1">in</span>
<span class="keyword1">let</span> q = <a href="#Fand_99">Fand</a> (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> a)) (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> x) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> b)) <span class="keyword1">in</span>
<a href="#infHu_554">infHu</a> p <a href="#idUpd_286">idUpd</a> swap q
<span class="keyword1">goal</span> <a name="TestInfAltSwapProg_645">TestInfAltSwapProg</a> :
<span class="keyword1">let</span> x = <a href="#MkIdent_16">MkIdent</a> 0 <span class="keyword1">in</span>
<span class="keyword1">let</span> y = <a href="#MkIdent_16">MkIdent</a> 1 <span class="keyword1">in</span>
<span class="keyword1">let</span> t = <a href="#MkIdent_16">MkIdent</a> 2 <span class="keyword1">in</span>
<span class="keyword1">let</span> a = <a href="#MkIdent_16">MkIdent</a> 3 <span class="keyword1">in</span>
<span class="keyword1">let</span> b = <a href="#MkIdent_16">MkIdent</a> 4 <span class="keyword1">in</span>
<span class="keyword1">let</span> swap = <a href="#Sseq_140">Sseq</a> (<a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> t (<a href="#Evar_26">Evar</a> x))
(<a href="#Sassign_137">Sassign</a> x (<a href="#Evar_26">Evar</a> y)))
(<a href="#Sassign_137">Sassign</a> y (<a href="#Evar_26">Evar</a> t)) <span class="keyword1">in</span>
<span class="keyword1">let</span> p = <a href="#Fand_99">Fand</a> (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> x) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> a)) (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> b)) <span class="keyword1">in</span>
<span class="keyword1">let</span> q = <a href="#Fand_99">Fand</a> (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> y) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> a)) (<a href="#Fcomp_95">Fcomp</a> (<a href="#Evar_26">Evar</a> x) <a href="#BOeq_32">BOeq</a> (<a href="#Evar_26">Evar</a> b)) <span class="keyword1">in</span>
<a href="#infHu_554">infHu</a> p <a href="#idUpd_286">idUpd</a> swap q
<span class="keyword1">end</span>
<span class="keyword1">theory</span> <a name="HuSoundness_">HuSoundness</a>
<span class="keyword1">use</span> <a href="#Semantics_">Semantics</a>
<span class="keyword1">use</span> <a href="#SystemHu_">SystemHu</a>
<span class="comment">(* The following three lemmas are required *)</span>
<span class="comment">(* the first is proved using "induction_pr" after "unfold valid_triple *)
(* the others follow from the first without induction *)
lemma core_while_rule:
forall c:stmt, b:bexpr, inv :fmla.
valid_triple (Fand inv (Fembed b)) idUpd c inv ->
forall ainv:fmla. valid_triple inv idUpd (Swhile b ainv c) (Fand inv (Fnot (Fembed b)))
lemma while_rule:
forall c:stmt, u:upd, b:bexpr, inv ainv p q :fmla.
valid_triple (Fand inv (Fembed b)) idUpd c inv ->
valid_fmla (Fimplies p (applyF u inv)) ->
valid_fmla (Fimplies (Fand inv (Fnot (Fembed b))) q) ->
valid_triple p u (Swhile b ainv c) q
lemma seq_while_rule:
forall c cc:stmt, b:bexpr, u:upd, p q inv ainv :fmla.
valid_fmla (Fimplies p (applyF u inv)) ->
valid_triple (Fand inv (Fembed b)) idUpd c inv ->
valid_triple (Fand inv (Fnot (Fembed b))) idUpd cc q ->
valid_triple p u (Sseq (Swhile b ainv c) cc) q
(* proved with "induction_pr" *)
lemma infHu_sound :
forall c :stmt, u :upd, p q :fmla.
infHu p u c q -> valid_triple p u c q
end
theory HuSoundness_LF
use Semantics
use SystemHu
(* Alternative proof using a lemma function *)
(* Interestingly, induction_pr can be replaced by structural induction *)
(* Only the following core rule about loops is required *)
(* The above proof needed more intermediate results *)
(* probably because with the function lemma the control *)
(* over quantifiers is tight, and no generality is lost *)
(* proved using "induction_pr" after "unfold valid_triple *)</span>
<span class="keyword1">lemma</span> <a name="core_while_rule_722">core_while_rule</a>:
<span class="keyword1">forall</span> c:<a href="#stmt_135">stmt</a>, b:<a href="#bexpr_34">bexpr</a>, inv :<a href="#fmla_94">fmla</a>.
<a href="#valid_triple_485">valid_triple</a> (<a href="#Fand_99">Fand</a> inv (<a href="#Fembed_96">Fembed</a> b)) <a href="#idUpd_286">idUpd</a> c inv ->
<span class="keyword1">forall</span> ainv :<a href="#fmla_94">fmla</a>. <a href="#valid_triple_485">valid_triple</a> inv <a href="#idUpd_286">idUpd</a> (<a href="#Swhile_139">Swhile</a> b ainv c) (<a href="#Fand_99">Fand</a> inv (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b)))
<span class="comment">(* Lemma function follows the structure of the inductive predicate *)</span>
<span class="comment">(* termination requires defining an appropriate variant *)</span>
<span class="comment">(* we use the previously defined function size *)</span>
<span class="keyword1">let</span> <span class="keyword1">rec</span> <span class="keyword1">lemma</span> <a name="infHu_sound_LF_733">infHu_sound_LF</a> (c:<a href="#stmt_135">stmt</a>)
<span class="keyword2">ensures</span> { <span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>. <a href="#infHu_554">infHu</a> p u c q -> <a href="#valid_triple_485">valid_triple</a> p u c q }
<span class="keyword2">variant</span> { <a href="#size_147">size</a> c }
= <span class="keyword1">match</span> c <span class="keyword1">with</span>
| <a href="#Sskip_136">Sskip</a> -> ()
| <a href="#Sassign_137">Sassign</a> _ _ -> ()
| <a href="#Sif_138">Sif</a> _ c1 c2 -> infHu_sound_LF c1 ; infHu_sound_LF c2
| <a href="#Swhile_139">Swhile</a> _ _ c -> infHu_sound_LF c
| <a href="#Sseq_140">Sseq</a> <a href="#Sskip_136">Sskip</a> c -> infHu_sound_LF c
| <a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> _ _) c -> infHu_sound_LF c
| <a href="#Sseq_140">Sseq</a> (<a href="#Sif_138">Sif</a> _ c1 c2) c -> infHu_sound_LF (<a href="#Sseq_140">Sseq</a> c1 c) ; infHu_sound_LF (<a href="#Sseq_140">Sseq</a> c2 c)
| <a href="#Sseq_140">Sseq</a> (<a href="#Swhile_139">Swhile</a> _ _ c1) c -> infHu_sound_LF c1 ; infHu_sound_LF c
| <a href="#Sseq_140">Sseq</a> (<a href="#Sseq_140">Sseq</a> c1 c2) c -> infHu_sound_LF (<a href="#Sseq_140">Sseq</a> c1 (<a href="#Sseq_140">Sseq</a> c2 c))
<span class="keyword1">end</span>
<span class="keyword1">end</span>
<span class="keyword1">theory</span> <a name="ReverseRules_">ReverseRules</a>
<span class="keyword1">use</span> <span class="keyword1">export</span> <a href="#Semantics_">Semantics</a>
<span class="keyword1">use</span> <span class="keyword1">export</span> <a href="#SystemHu_">SystemHu</a>
<span class="comment">(* Expressiveness *)</span>
<span class="comment">(* Following Cooke and Clarke, we postulate the existence of weakest preconditions *)</span>
<span class="comment">(* This implies that loop invariants exist, defined as the wp of the entire loop *)</span>
<span class="keyword1">predicate</span> <a name="pre_765">pre</a> (s:<a href="#state_45">state</a>) (c:<a href="#stmt_135">stmt</a>) (q:<a href="#fmla_94">fmla</a>) =
<span class="keyword1">forall</span> s' :<a href="#state_45">state</a>. <a href="#big_step_191">big_step</a> s c s' -> <a href="#satisfies_107">satisfies</a> s' q
<span class="keyword1">val</span> <span class="keyword1">function</span> <a name="wp_769">wp</a> (c:<a href="#stmt_135">stmt</a>) (q:<a href="#fmla_94">fmla</a>) : <a href="#fmla_94">fmla</a>
<span class="keyword2">ensures</span> { <span class="keyword1">forall</span> s :<a href="#state_45">state</a>. <a href="#satisfies_107">satisfies</a> s result <-> <a href="#pre_765">pre</a> s c q }
<span class="comment">(* axiom expressiveness : forall c :stmt, q :fmla. *)</span>
<span class="comment">(* exists p :fmla. forall s :state. (satisfies s p <-> pre s c q) *)</span>
<span class="comment">(* The following lemmas are required to prove the reverse Hu rules below *)</span>
<span class="comment">(* wp is used in the lemmas involving loops *)</span>
<span class="keyword1">lemma</span> <a name="valid_triple_skip_781">valid_triple_skip</a> :
<span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>, s :<a href="#state_45">state</a>.
<a href="#valid_triple_485">valid_triple</a> p u <a href="#Sskip_136">Sskip</a> q ->
<a href="#satisfies_107">satisfies</a> s p -> <a href="#big_step_191">big_step</a> (<a href="#applyS_296">applyS</a> u s) <a href="#Sskip_136">Sskip</a> (<a href="#applyS_296">applyS</a> u s) -> <a href="#satisfies_107">satisfies</a> (<a href="#applyS_296">applyS</a> u s) q
<span class="comment">(* This one does not seem to be required... *)</span>
<span class="comment">(* lemma valid_triple_assign : *)</span>
<span class="comment">(* forall p q :fmla, x :ident, e :expr, u :upd, s s' :state. *)</span>
<span class="comment">(* valid_triple p u (Sassign x e) q -> *)</span>
<span class="comment">(* satisfies s p -> *)</span>
<span class="comment">(* big_step (applyS u s) (Sassign x e) (set s x (eval_expr s e)) -> *)</span>
<span class="comment">(* satisfies (set s x (eval_expr s e)) q *)</span>
<span class="keyword1">lemma</span> <a name="valid_triple_if_true_794">valid_triple_if_true</a> :
<span class="keyword1">forall</span> c1 c2 :<a href="#stmt_135">stmt</a>, b: <a href="#bexpr_34">bexpr</a>, p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>, s s' :<a href="#state_45">state</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sif_138">Sif</a> b c1 c2) q ->
<a href="#satisfies_107">satisfies</a> s p ->
<a href="#eval_bexpr_77">eval_bexpr</a> (<a href="#applyS_296">applyS</a> u s) b ->
<a href="#big_step_191">big_step</a> (<a href="#applyS_296">applyS</a> u s) c1 s' ->
<a href="#big_step_191">big_step</a> (<a href="#applyS_296">applyS</a> u s) (<a href="#Sif_138">Sif</a> b c1 c2) s' /\
<a href="#satisfies_107">satisfies</a> s' q
<span class="keyword1">lemma</span> <a name="valid_triple_if_false_803">valid_triple_if_false</a> :
<span class="keyword1">forall</span> c1 c2 :<a href="#stmt_135">stmt</a>, b: <a href="#bexpr_34">bexpr</a>, p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>, s s' :<a href="#state_45">state</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sif_138">Sif</a> b c1 c2) q ->
<a href="#satisfies_107">satisfies</a> s p ->
<span class="keyword1">not</span> (<a href="#eval_bexpr_77">eval_bexpr</a> (<a href="#applyS_296">applyS</a> u s) b) ->
<a href="#big_step_191">big_step</a> (<a href="#applyS_296">applyS</a> u s) c2 s' ->
<a href="#big_step_191">big_step</a> (<a href="#applyS_296">applyS</a> u s) (<a href="#Sif_138">Sif</a> b c1 c2) s' /\
<a href="#satisfies_107">satisfies</a> s' q
<span class="keyword1">lemma</span> <a name="valid_triple_while_wp_812">valid_triple_while_wp</a> :
<span class="keyword1">forall</span> c :<a href="#stmt_135">stmt</a>, b: <a href="#bexpr_34">bexpr</a>, p q ainv :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Swhile_139">Swhile</a> b ainv c) q ->
<span class="keyword1">let</span> inv = <a href="#wp_769">wp</a> (<a href="#Swhile_139">Swhile</a> b ainv c) q <span class="keyword1">in</span>
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u inv)) /\
(<span class="keyword1">forall</span> s s':<a href="#state_45">state</a>. <a href="#satisfies_107">satisfies</a> s (<a href="#Fand_99">Fand</a> inv (<a href="#Fembed_96">Fembed</a> b)) -> <a href="#big_step_191">big_step</a> s c s' -> <a href="#satisfies_107">satisfies</a> s' inv) /\
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> (<a href="#Fand_99">Fand</a> inv (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b))) q)
<span class="keyword1">lemma</span> <a name="valid_triple_seq_820">valid_triple_seq</a> :
<span class="keyword1">forall</span> c1 c2 :<a href="#stmt_135">stmt</a>, p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>, s s' s'' :<a href="#state_45">state</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sseq_140">Sseq</a> c1 c2) q ->
<a href="#satisfies_107">satisfies</a> s p-> <a href="#big_step_191">big_step</a> (<a href="#applyS_296">applyS</a> u s) c1 s' -> <a href="#big_step_191">big_step</a> s' c2 s'' -> <a href="#satisfies_107">satisfies</a> s'' q
<span class="keyword1">lemma</span> <a name="valid_triple_if_seq_true_825">valid_triple_if_seq_true</a>:
<span class="keyword1">forall</span> c1 c2 cc :<a href="#stmt_135">stmt</a>, b: <a href="#bexpr_34">bexpr</a>, p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>, s s' s'' :<a href="#state_45">state</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Sif_138">Sif</a> b c1 c2) cc) q ->
<a href="#satisfies_107">satisfies</a> s p ->
<a href="#eval_bexpr_77">eval_bexpr</a> (<a href="#applyS_296">applyS</a> u s) b ->
<a href="#big_step_191">big_step</a> (<a href="#applyS_296">applyS</a> u s) c1 s' ->
<a href="#big_step_191">big_step</a> (<a href="#applyS_296">applyS</a> u s) (<a href="#Sif_138">Sif</a> b c1 c2) s' -> <span class="comment">(* this is not required in the lemma but allows it to be proved *)</span>
<a href="#big_step_191">big_step</a> s' cc s'' ->
<a href="#satisfies_107">satisfies</a> s'' q
<span class="keyword1">lemma</span> <a name="valid_triple_if_seq_false_835">valid_triple_if_seq_false</a> :
<span class="keyword1">forall</span> c1 c2 cc :<a href="#stmt_135">stmt</a>, b: <a href="#bexpr_34">bexpr</a>, p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>, s s' s'' :<a href="#state_45">state</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Sif_138">Sif</a> b c1 c2) cc) q ->
<a href="#satisfies_107">satisfies</a> s p ->
<span class="keyword1">not</span> (<a href="#eval_bexpr_77">eval_bexpr</a> (<a href="#applyS_296">applyS</a> u s) b) ->
<a href="#big_step_191">big_step</a> (<a href="#applyS_296">applyS</a> u s) c2 s' ->
<a href="#big_step_191">big_step</a> (<a href="#applyS_296">applyS</a> u s) (<a href="#Sif_138">Sif</a> b c1 c2) s' -> <span class="comment">(* same here *)</span>
<a href="#big_step_191">big_step</a> s' cc s'' ->
<a href="#satisfies_107">satisfies</a> s'' q
<span class="keyword1">lemma</span> <a name="valid_triple_while_seq_845">valid_triple_while_seq</a> :
<span class="keyword1">forall</span> c cc :<a href="#stmt_135">stmt</a>, b: <a href="#bexpr_34">bexpr</a>, p q ainv :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Swhile_139">Swhile</a> b ainv c) cc) q ->
<span class="keyword1">let</span> inv = <a href="#wp_769">wp</a> (<a href="#Swhile_139">Swhile</a> b ainv c) (<a href="#wp_769">wp</a> cc q) <span class="keyword1">in</span>
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u inv)) /\
(<span class="keyword1">forall</span> s s':<a href="#state_45">state</a>. <a href="#satisfies_107">satisfies</a> s (<a href="#Fand_99">Fand</a> inv (<a href="#Fembed_96">Fembed</a> b)) -> <a href="#big_step_191">big_step</a> s c s' -> <a href="#satisfies_107">satisfies</a> s' inv) /\
(<span class="keyword1">forall</span> s s':<a href="#state_45">state</a>. <a href="#satisfies_107">satisfies</a> s (<a href="#Fand_99">Fand</a> inv (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b))) -> <a href="#big_step_191">big_step</a> s cc s' -> <a href="#satisfies_107">satisfies</a> s' q)
<span class="comment">(* Reverse rules of Hu *)</span>
<span class="comment">(* the loop rules state the existence of an invariant *)</span>
<span class="keyword1">lemma</span> <a name="skip_rule_rev_859">skip_rule_rev</a>:
<span class="keyword1">forall</span> p q:<a href="#fmla_94">fmla</a>, u:<a href="#upd_281">upd</a>.
<a href="#valid_triple_485">valid_triple</a> p u <a href="#Sskip_136">Sskip</a> q -> <a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u q))
<span class="keyword1">lemma</span> <a name="assign_rule_rev_863">assign_rule_rev</a>:
<span class="keyword1">forall</span> p:<a href="#fmla_94">fmla</a>, q:<a href="#fmla_94">fmla</a>, x:<a href="#ident_15">ident</a>, e:<a href="#expr_24">expr</a>, u:<a href="#upd_281">upd</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sassign_137">Sassign</a> x e) q ->
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> (<a href="#assign_425">assign</a> u x e) q))
<span class="keyword1">lemma</span> <a name="if_rule_rev_868">if_rule_rev</a>:
<span class="keyword1">forall</span> p q:<a href="#fmla_94">fmla</a>, c1 c2 :<a href="#stmt_135">stmt</a>, b:<a href="#bexpr_34">bexpr</a>, u:<a href="#upd_281">upd</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sif_138">Sif</a> b c1 c2) q ->
<a href="#valid_triple_485">valid_triple</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fembed_96">Fembed</a> b))) u c1 q /\
<a href="#valid_triple_485">valid_triple</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b)))) u c2 q
<span class="keyword1">lemma</span> <a name="while_rule_rev_874">while_rule_rev</a>:
<span class="keyword1">forall</span> c:<a href="#stmt_135">stmt</a>, u:<a href="#upd_281">upd</a>, b:<a href="#bexpr_34">bexpr</a>, ainv p q :<a href="#fmla_94">fmla</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Swhile_139">Swhile</a> b ainv c) q ->
<span class="keyword1">exists</span> inv:<a href="#fmla_94">fmla</a>.
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u inv)) /\
<a href="#valid_triple_485">valid_triple</a> (<a href="#Fand_99">Fand</a> inv (<a href="#Fembed_96">Fembed</a> b)) <a href="#idUpd_286">idUpd</a> c inv /\
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> (<a href="#Fand_99">Fand</a> inv (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b))) q)
<span class="keyword1">lemma</span> <a name="seq_skip_rule_rev_882">seq_skip_rule_rev</a>:
<span class="keyword1">forall</span> p q:<a href="#fmla_94">fmla</a>, u:<a href="#upd_281">upd</a>, c :<a href="#stmt_135">stmt</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sseq_140">Sseq</a> <a href="#Sskip_136">Sskip</a> c) q -> <a href="#valid_triple_485">valid_triple</a> p u c q
<span class="keyword1">lemma</span> <a name="seq_assign_rule_rev_886">seq_assign_rule_rev</a>:
<span class="keyword1">forall</span> p:<a href="#fmla_94">fmla</a>, q:<a href="#fmla_94">fmla</a>, x:<a href="#ident_15">ident</a>, e:<a href="#expr_24">expr</a>, i:<a href="#stmt_135">stmt</a>, u:<a href="#upd_281">upd</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> x e) i) q ->
<a href="#valid_triple_485">valid_triple</a> p (<a href="#assign_425">assign</a> u x e) i q
<span class="keyword1">lemma</span> <a name="seq_if_rule_rev_891">seq_if_rule_rev</a>:
<span class="keyword1">forall</span> p q:<a href="#fmla_94">fmla</a>, s1 s2 s:<a href="#stmt_135">stmt</a>, b:<a href="#bexpr_34">bexpr</a>, u:<a href="#upd_281">upd</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Sif_138">Sif</a> b s1 s2) s) q ->
<a href="#valid_triple_485">valid_triple</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fembed_96">Fembed</a> b))) u (<a href="#Sseq_140">Sseq</a> s1 s) q /\
<a href="#valid_triple_485">valid_triple</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b)))) u (<a href="#Sseq_140">Sseq</a> s2 s) q
<span class="keyword1">lemma</span> <a name="seq_while_rule_rev_897">seq_while_rule_rev</a>:
<span class="keyword1">forall</span> p q ainv:<a href="#fmla_94">fmla</a>, c cc:<a href="#stmt_135">stmt</a>, b:<a href="#bexpr_34">bexpr</a>, u:<a href="#upd_281">upd</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Swhile_139">Swhile</a> b ainv c) cc) q ->
<span class="keyword1">exists</span> inv :<a href="#fmla_94">fmla</a>.
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u inv)) /\
<a href="#valid_triple_485">valid_triple</a> (<a href="#Fand_99">Fand</a> inv (<a href="#Fembed_96">Fembed</a> b)) <a href="#idUpd_286">idUpd</a> c inv /\
<a href="#valid_triple_485">valid_triple</a> (<a href="#Fand_99">Fand</a> inv (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b))) <a href="#idUpd_286">idUpd</a> cc q
<span class="keyword1">lemma</span> <a name="seq_seq_rule_rev_905">seq_seq_rule_rev</a>:
<span class="keyword1">forall</span> c1 c2 c:<a href="#stmt_135">stmt</a>, u:<a href="#upd_281">upd</a>, p q:<a href="#fmla_94">fmla</a>.
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Sseq_140">Sseq</a> c1 c2) c) q ->
<a href="#valid_triple_485">valid_triple</a> p u (<a href="#Sseq_140">Sseq</a> c1 (<a href="#Sseq_140">Sseq</a> c2 c)) q
<span class="keyword1">end</span>
<span class="keyword1">theory</span> <a name="HuCompleteness_">HuCompleteness</a>
<span class="keyword1">use</span> <a href="#Semantics_">Semantics</a>
<span class="keyword1">use</span> <a href="#SystemHu_">SystemHu</a>
<span class="keyword1">use</span> <a href="#ReverseRules_">ReverseRules</a>
<span class="comment">(* This cannot be proved with induction_ty_lex *)</span>
<span class="comment">(* lemma infHu_complete : *)</span>
<span class="comment">(* forall c[@induction] :stmt, p q :fmla, u :upd. *)</span>
<span class="comment">(* valid_triple p u c q -> infHu p u c q *)</span>
<span class="comment">(* Lemma Function CAN be proved *)</span>
<span class="keyword1">let</span> <span class="keyword1">rec</span> <span class="keyword1">lemma</span> <a name="infHu_complete_LF_931">infHu_complete_LF</a> (c:<a href="#stmt_135">stmt</a>) =
<span class="keyword2">ensures</span> { <span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>. <a href="#valid_triple_485">valid_triple</a> p u c q -> <a href="#infHu_554">infHu</a> p u c q }
<span class="keyword2">variant</span> { <a href="#size_147">size</a> c }
<span class="keyword1">match</span> c <span class="keyword1">with</span>
| <a href="#Sskip_136">Sskip</a> -> ()
| <a href="#Sassign_137">Sassign</a> _ _ -> ()
| <a href="#Sif_138">Sif</a> _ c1 c2 -> infHu_complete_LF c1 ; infHu_complete_LF c2
| <a href="#Swhile_139">Swhile</a> _ _ c -> infHu_complete_LF c
| <a href="#Sseq_140">Sseq</a> <a href="#Sskip_136">Sskip</a> c -> infHu_complete_LF c
| <a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> _ _) c -> infHu_complete_LF c
| <a href="#Sseq_140">Sseq</a> (<a href="#Sif_138">Sif</a> _ c1 c2) c -> infHu_complete_LF (<a href="#Sseq_140">Sseq</a> c1 c) ; infHu_complete_LF (<a href="#Sseq_140">Sseq</a> c2 c)
| <a href="#Sseq_140">Sseq</a> (<a href="#Swhile_139">Swhile</a> _ _ c1) c -> infHu_complete_LF c1 ; infHu_complete_LF c
| <a href="#Sseq_140">Sseq</a> (<a href="#Sseq_140">Sseq</a> c1 c2) c -> infHu_complete_LF (<a href="#Sseq_140">Sseq</a> c1 (<a href="#Sseq_140">Sseq</a> c2 c))
<span class="keyword1">end</span>
<span class="keyword1">end</span>
<span class="keyword1">theory</span> <a name="SystemHuAnnot_">SystemHuAnnot</a>
<span class="keyword1">use</span> <a href="#Semantics_">Semantics</a>
<span class="keyword1">use</span> <a href="#SystemHu_">SystemHu</a>
<span class="comment">(* Inference system directed by annotated invariants *)</span>
<span class="keyword1">inductive</span> <a name="infHuA_961">infHuA</a> <a href="#fmla_94">fmla</a> <a href="#upd_281">upd</a> <a href="#stmt_135">stmt</a> <a href="#fmla_94">fmla</a> =
| <a name="infHuA_skip_963">infHuA_skip</a>:
<span class="keyword1">forall</span> p q:<a href="#fmla_94">fmla</a>, u:<a href="#upd_281">upd</a>.
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u q)) ->
<a href="#infHuA_961">infHuA</a> p u <a href="#Sskip_136">Sskip</a> q
| <a name="infHuA_assign_968">infHuA_assign</a>:
<span class="keyword1">forall</span> p:<a href="#fmla_94">fmla</a>, q:<a href="#fmla_94">fmla</a>, x:<a href="#ident_15">ident</a>, e:<a href="#expr_24">expr</a>, u:<a href="#upd_281">upd</a>.
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> (<a href="#assign_425">assign</a> u x e) q)) ->
<a href="#infHuA_961">infHuA</a> p u (<a href="#Sassign_137">Sassign</a> x e) q
| <a name="infHuA_if_973">infHuA_if</a>:
<span class="keyword1">forall</span> p q:<a href="#fmla_94">fmla</a>, c1 c2 :<a href="#stmt_135">stmt</a>, b:<a href="#bexpr_34">bexpr</a>, u:<a href="#upd_281">upd</a>.
<a href="#infHuA_961">infHuA</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fembed_96">Fembed</a> b))) u c1 q ->
<a href="#infHuA_961">infHuA</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b)))) u c2 q ->
<a href="#infHuA_961">infHuA</a> p u (<a href="#Sif_138">Sif</a> b c1 c2) q
| <a name="infHuA_while_979">infHuA_while</a>:
<span class="keyword1">forall</span> p q:<a href="#fmla_94">fmla</a>, c :<a href="#stmt_135">stmt</a>, b:<a href="#bexpr_34">bexpr</a>, ainv:<a href="#fmla_94">fmla</a>, u:<a href="#upd_281">upd</a>.
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u ainv)) ->
<a href="#infHuA_961">infHuA</a> (<a href="#Fand_99">Fand</a> ainv (<a href="#Fembed_96">Fembed</a> b)) <a href="#idUpd_286">idUpd</a> c ainv ->
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> (<a href="#Fand_99">Fand</a> ainv (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b))) q) ->
<a href="#infHuA_961">infHuA</a> p u (<a href="#Swhile_139">Swhile</a> b ainv c) q
| <a name="infHuA_skipseq_986">infHuA_skipseq</a>:
<span class="keyword1">forall</span> p q:<a href="#fmla_94">fmla</a>, u:<a href="#upd_281">upd</a>, c :<a href="#stmt_135">stmt</a>.
<a href="#infHuA_961">infHuA</a> p u c q ->
<a href="#infHuA_961">infHuA</a> p u (<a href="#Sseq_140">Sseq</a> <a href="#Sskip_136">Sskip</a> c) q
| <a name="infHuA_assignseq_991">infHuA_assignseq</a>:
<span class="keyword1">forall</span> p:<a href="#fmla_94">fmla</a>, q:<a href="#fmla_94">fmla</a>, x:<a href="#ident_15">ident</a>, e:<a href="#expr_24">expr</a>, c:<a href="#stmt_135">stmt</a>, u:<a href="#upd_281">upd</a>.
<a href="#infHuA_961">infHuA</a> p (<a href="#assign_425">assign</a> u x e) c q ->
<a href="#infHuA_961">infHuA</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> x e) c) q
| <a name="infHuA_ifseq_996">infHuA_ifseq</a>:
<span class="keyword1">forall</span> p q:<a href="#fmla_94">fmla</a>, c1 c2 c:<a href="#stmt_135">stmt</a>, b:<a href="#bexpr_34">bexpr</a>, u:<a href="#upd_281">upd</a>.
<a href="#infHuA_961">infHuA</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fembed_96">Fembed</a> b))) u (<a href="#Sseq_140">Sseq</a> c1 c) q ->
<a href="#infHuA_961">infHuA</a> (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b)))) u (<a href="#Sseq_140">Sseq</a> c2 c) q ->
<a href="#infHuA_961">infHuA</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Sif_138">Sif</a> b c1 c2) c) q
| <a name="infHuA_whileseq_1002">infHuA_whileseq</a>:
<span class="keyword1">forall</span> p q:<a href="#fmla_94">fmla</a>, c cc:<a href="#stmt_135">stmt</a>, b:<a href="#bexpr_34">bexpr</a>, ainv:<a href="#fmla_94">fmla</a>, u:<a href="#upd_281">upd</a>.
<a href="#valid_fmla_119">valid_fmla</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u ainv)) ->
<a href="#infHuA_961">infHuA</a> (<a href="#Fand_99">Fand</a> ainv (<a href="#Fembed_96">Fembed</a> b)) <a href="#idUpd_286">idUpd</a> c ainv ->
<a href="#infHuA_961">infHuA</a> (<a href="#Fand_99">Fand</a> ainv (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b))) <a href="#idUpd_286">idUpd</a> cc q ->
<a href="#infHuA_961">infHuA</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Swhile_139">Swhile</a> b ainv c) cc) q
| <a name="infHuA_seqseq_1009">infHuA_seqseq</a>:
<span class="keyword1">forall</span> p q:<a href="#fmla_94">fmla</a>, c1 c2 c:<a href="#stmt_135">stmt</a>, u:<a href="#upd_281">upd</a>.
<a href="#infHuA_961">infHuA</a> p u (<a href="#Sseq_140">Sseq</a> c1 (<a href="#Sseq_140">Sseq</a> c2 c)) q ->
<a href="#infHuA_961">infHuA</a> p u (<a href="#Sseq_140">Sseq</a> (<a href="#Sseq_140">Sseq</a> c1 c2) c) q
<span class="comment">(* This system is of course sound *)</span>
<span class="comment">(* induction_pr *)</span>
<span class="keyword1">lemma</span> <a name="infHuA_sound_1019">infHuA_sound</a> : <span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>, c :<a href="#stmt_135">stmt</a>.
<a href="#infHuA_961">infHuA</a> p u c q -> <a href="#infHu_554">infHu</a> p u c q
<span class="comment">(* program is well-annotated w.r.t. p, u, q *)</span>
<span class="comment">(* if triple can be derived freely, it can be derived *)</span>
<span class="comment">(* directed by annotated invariants *)</span>
<span class="keyword1">predicate</span> <a name="ok_1028">ok</a> (p:<a href="#fmla_94">fmla</a>) (u:<a href="#upd_281">upd</a>) (c:<a href="#stmt_135">stmt</a>) (q:<a href="#fmla_94">fmla</a>) =
<a href="#infHu_554">infHu</a> p u c q -> <a href="#infHuA_961">infHuA</a> p u c q
<span class="keyword1">end</span>
<span class="keyword1">theory</span> <a name="VCGen_">VCGen</a>
<span class="keyword1">use</span> <a href="#Semantics_">Semantics</a>
<span class="keyword1">use</span> <a href="#SystemHu_">SystemHu</a>
<span class="keyword1">use</span> <a href="#SystemHuAnnot_">SystemHuAnnot</a>
<span class="keyword1">use</span> <a href="#HuSoundness_LF_">HuSoundness_LF</a>
<span class="keyword1">use</span> <a href="#HuCompleteness_">HuCompleteness</a>
<span class="keyword1">use</span> <span class="keyword1">export</span> set.<a href="set.html#Fset_">Fset</a>
<span class="keyword1">predicate</span> <a name="valid_fmlas_1051">valid_fmlas</a> (g: <a href="set.html#set_118">set</a> <a href="#fmla_94">fmla</a>) = <span class="keyword1">forall</span> p :<a href="#fmla_94">fmla</a>. <a href="set.html#mem_124">mem</a> p g -> <a href="#valid_fmla_119">valid_fmla</a> p
<span class="comment">(* One could write a VCGen for programs without annotations, *)</span>
<span class="comment">(* using the wp function declared above *)</span>
<span class="comment">(* but it could not be executed or extracted, of course *)</span>
<span class="comment">(* The VCGen below cannot be written as a logic function, because *)</span>
<span class="comment">(* termination is not established automatically *)</span>
<span class="comment">(* thus a variant must be used. *)</span>
<span class="comment">(* This is the only reason why it is a program function, *)</span>
<span class="comment">(* since it is not meant, in this version, to be executed. *)</span>
<span class="comment">(* But it must be ghost, since it modifies updates through *)</span>
<span class="comment">(* the assign function, which uses the ghost function Map.set *)</span>
<span class="keyword1">let</span> <span class="keyword1">rec</span> <span class="keyword1">ghost</span> <span class="keyword1">function</span> <a name="vcgen_l_1070">vcgen_l</a> (p:<a href="#fmla_94">fmla</a>) (u:<a href="#upd_281">upd</a>) (c:<a href="#stmt_135">stmt</a>) (q:<a href="#fmla_94">fmla</a>) : <a href="set.html#set_118">set</a> <a href="#fmla_94">fmla</a> =
<span class="keyword2">ensures</span> { <a href="#valid_fmlas_1051">valid_fmlas</a> result -> <a href="#infHuA_961">infHuA</a> p u c q }
<span class="comment">(* ensures { valid_fmlas result -> infHu p u c q } *)</span>
<span class="comment">(* ensures { valid_fmlas result -> valid_triple p u c q } *)</span>
<span class="keyword2">ensures</span> { <a href="#infHuA_961">infHuA</a> p u c q -> <a href="#valid_fmlas_1051">valid_fmlas</a> result }
<span class="keyword2">variant</span> { <a href="#size_147">size</a> c }
<span class="keyword1">match</span> c <span class="keyword1">with</span>
| <a href="#Sskip_136">Sskip</a> -> <a href="set.html#singleton_154">singleton</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u q))
| <a href="#Sassign_137">Sassign</a> x e -> <a href="set.html#singleton_154">singleton</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> (<a href="#assign_425">assign</a> u x e) q))
| <a href="#Sif_138">Sif</a> b c1 c2 -> <a href="set.html#union_170">union</a> (vcgen_l (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fembed_96">Fembed</a> b))) u c1 q)
(vcgen_l (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b)))) u c2 q)
| <a href="#Swhile_139">Swhile</a> b ainv cb -> <a href="set.html#add_151">add</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u ainv))
(<a href="set.html#add_151">add</a> (<a href="#Fimplies_102">Fimplies</a> (<a href="#Fand_99">Fand</a> ainv (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b))) q)
(vcgen_l (<a href="#Fand_99">Fand</a> ainv (<a href="#Fembed_96">Fembed</a> b)) <a href="#idUpd_286">idUpd</a> cb ainv))
| <a href="#Sseq_140">Sseq</a> (<a href="#Sskip_136">Sskip</a>) cc -> vcgen_l p u cc q
| <a href="#Sseq_140">Sseq</a> (<a href="#Sassign_137">Sassign</a> x e) cc -> vcgen_l p (<a href="#assign_425">assign</a> u x e) cc q
| <a href="#Sseq_140">Sseq</a> (<a href="#Sif_138">Sif</a> b c1 c2) cc -> <a href="set.html#union_170">union</a> (vcgen_l (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fembed_96">Fembed</a> b))) u (<a href="#Sseq_140">Sseq</a> c1 cc) q)
(vcgen_l (<a href="#Fand_99">Fand</a> p (<a href="#applyF_386">applyF</a> u (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b)))) u (<a href="#Sseq_140">Sseq</a> c2 cc) q)
| <a href="#Sseq_140">Sseq</a> (<a href="#Swhile_139">Swhile</a> b ainv cb) cc -> <a href="set.html#add_151">add</a> (<a href="#Fimplies_102">Fimplies</a> p (<a href="#applyF_386">applyF</a> u ainv))
(<a href="set.html#union_170">union</a> (vcgen_l (<a href="#Fand_99">Fand</a> ainv (<a href="#Fembed_96">Fembed</a> b)) <a href="#idUpd_286">idUpd</a> cb ainv)
(vcgen_l (<a href="#Fand_99">Fand</a> ainv (<a href="#Fnot_101">Fnot</a> (<a href="#Fembed_96">Fembed</a> b))) <a href="#idUpd_286">idUpd</a> cc q))
| <a href="#Sseq_140">Sseq</a> (<a href="#Sseq_140">Sseq</a> c1 c2) cc -> vcgen_l p u (<a href="#Sseq_140">Sseq</a> c1 (<a href="#Sseq_140">Sseq</a> c2 cc)) q
<span class="keyword1">end</span>
<span class="keyword1">lemma</span> <a name="vcgen_sound_1096">vcgen_sound</a> : <span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>, c :<a href="#stmt_135">stmt</a>.
<a href="#valid_fmlas_1051">valid_fmlas</a> (<a href="#vcgen_l_1070">vcgen_l</a> p u c q) -> <a href="#valid_triple_485">valid_triple</a> p u c q
<span class="keyword1">lemma</span> <a name="vcgen_cmplt_1099">vcgen_cmplt</a> : <span class="keyword1">forall</span> p q :<a href="#fmla_94">fmla</a>, u :<a href="#upd_281">upd</a>, c :<a href="#stmt_135">stmt</a>.
(<a href="#valid_triple_485">valid_triple</a> p u c q) /\ (<a href="#ok_1028">ok</a> p u c q) -> <a href="#valid_fmlas_1051">valid_fmlas</a> (<a href="#vcgen_l_1070">vcgen_l</a> p u c q)
<span class="keyword1">end</span>
<span class="keyword1">module</span> <a name="VCGenExtr_">VCGenExtr</a>
<span class="keyword1">use</span> <a href="#Semantics_">Semantics</a>
<span class="keyword1">use</span> <a href="#SystemHu_">SystemHu</a>
<span class="keyword1">use</span> <a href="#SystemHuAnnot_">SystemHuAnnot</a>
<span class="keyword1">use</span> <a href="#VCGen_">VCGen</a>
<span class="keyword1">use</span> option.<a href="option.html#Option_">Option</a>
<span class="comment">(* We will now use Impmaps to implement abstract maps *)</span>
<span class="comment">(* The .contents field is abstract and thus can be accessed *)</span>
<span class="comment">(* in logic / annotations / ghost code *)</span>
<span class="comment">(* But not in programs: they must access impmaps through the API [vals] *)</span>
<span class="keyword1">clone</span> impmap.<a href="impmap.html#Impmap_">Impmap</a> <span class="keyword1">with</span> <span class="keyword1">type</span> <a href="impmap.html#key_12">key</a> = <a href="#ident_15">ident</a>
<span class="keyword1">type</span> <a name="impupd_1127">impupd</a> = Impmap.<a href="#t_14">t</a> <a href="#expr_24">expr</a>