annotate paper/src/agda-hoare-soundness.agda.replaced @ 4:b5fffa8ae875

fix chapter hoare
author ryokka
date Wed, 29 Jan 2020 22:36:17 +0900
parents
children 196ba119ca89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
1 Soundness : {bPre : Cond} @$\rightarrow$@ {cm : Comm} @$\rightarrow$@ {bPost : Cond} @$\rightarrow$@
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
2 HTProof bPre cm bPost @$\rightarrow$@ Satisfies bPre cm bPost
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
3 Soundness (PrimRule {bPre} {cm} {bPost} pr) s1 s2 q1 q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
4 = axiomValid bPre cm bPost pr s1 s2 q1 q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
5 Soundness {.bPost} {.Skip} {bPost} (SkipRule .bPost) s1 s2 q1 q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
6 = substId1 State {Level.zero} {State} {s1} {s2} (proj@$\text{2}$@ q2) (SemCond bPost) q1
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
7 Soundness {bPre} {.Abort} {bPost} (AbortRule .bPre .bPost) s1 s2 q1 ()
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
8 Soundness (WeakeningRule {bPre} {bPre'} {cm} {bPost'} {bPost} tautPre pr tautPost)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
9 s1 s2 q1 q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
10 = let hyp : Satisfies bPre' cm bPost'
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
11 hyp = Soundness pr
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
12 r1 : SemCond bPre' s1
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
13 r1 = tautValid bPre bPre' tautPre s1 q1
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
14 r2 : SemCond bPost' s2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
15 r2 = hyp s1 s2 r1 q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
16 in tautValid bPost' bPost tautPost s2 r2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
17 Soundness (SeqRule {bPre} {cm1} {bMid} {cm2} {bPost} pr1 pr2)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
18 s1 s2 q1 q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
19 = let hyp1 : Satisfies bPre cm1 bMid
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
20 hyp1 = Soundness pr1
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
21 hyp2 : Satisfies bMid cm2 bPost
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
22 hyp2 = Soundness pr2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
23 sMid : State
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
24 sMid = proj@$\text{1}$@ q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
25 r1 : SemComm cm1 s1 sMid @$\times$@ SemComm cm2 sMid s2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
26 r1 = proj@$\text{2}$@ q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
27 r2 : SemComm cm1 s1 sMid
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
28 r2 = proj@$\text{1}$@ r1
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
29 r3 : SemComm cm2 sMid s2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
30 r3 = proj@$\text{2}$@ r1
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
31 r4 : SemCond bMid sMid
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
32 r4 = hyp1 s1 sMid q1 r2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
33 in hyp2 sMid s2 r4 r3
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
34 Soundness (IfRule {cmThen} {cmElse} {bPre} {bPost} {b} pThen pElse)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
35 s1 s2 q1 q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
36 = let hypThen : Satisfies (bPre /\ b) cmThen bPost
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
37 hypThen = Soundness pThen
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
38 hypElse : Satisfies (bPre /\ neg b) cmElse bPost
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
39 hypElse = Soundness pElse
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
40 rThen : RelOpState.comp
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
41 (RelOpState.delta (SemCond b))
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
42 (SemComm cmThen) s1 s2 @$\rightarrow$@
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
43 SemCond bPost s2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
44 rThen = @$\lambda$@ h @$\rightarrow$@
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
45 let t1 : SemCond b s1 @$\times$@ SemComm cmThen s1 s2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
46 t1 = (proj@$\text{2}$@ (RelOpState.deltaRestPre
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
47 (SemCond b)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
48 (SemComm cmThen) s1 s2)) h
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
49 t2 : SemCond (bPre /\ b) s1
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
50 t2 = (proj@$\text{2}$@ (respAnd bPre b s1))
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
51 (q1 , proj@$\text{1}$@ t1)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
52 in hypThen s1 s2 t2 (proj@$\text{2}$@ t1)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
53 rElse : RelOpState.comp
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
54 (RelOpState.delta (NotP (SemCond b)))
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
55 (SemComm cmElse) s1 s2 @$\rightarrow$@
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
56 SemCond bPost s2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
57 rElse = @$\lambda$@ h @$\rightarrow$@
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
58 let t10 : (NotP (SemCond b) s1) @$\times$@
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
59 (SemComm cmElse s1 s2)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
60 t10 = proj@$\text{2}$@ (RelOpState.deltaRestPre
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
61 (NotP (SemCond b)) (SemComm cmElse) s1 s2)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
62 h
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
63 t6 : SemCond (neg b) s1
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
64 t6 = proj@$\text{2}$@ (respNeg b s1) (proj@$\text{1}$@ t10)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
65 t7 : SemComm cmElse s1 s2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
66 t7 = proj@$\text{2}$@ t10
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
67 t8 : SemCond (bPre /\ neg b) s1
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
68 t8 = proj@$\text{2}$@ (respAnd bPre (neg b) s1)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
69 (q1 , t6)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
70 in hypElse s1 s2 t8 t7
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
71 in when rThen rElse q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
72 Soundness (WhileRule {cm'} {bInv} {b} pr) s1 s2 q1 q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
73 = proj@$\text{2}$@ (respAnd bInv (neg b) s2) t20
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
74 where
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
75 hyp : Satisfies (bInv /\ b) cm' bInv
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
76 hyp = Soundness pr
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
77 n : $mathbb{N}$
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
78 n = proj@$\text{1}$@ q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
79 Rel1 : $mathbb{N}$ @$\rightarrow$@ Rel State (Level.zero)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
80 Rel1 = @$\lambda$@ m @$\rightarrow$@
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
81 RelOpState.repeat
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
82 m
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
83 (RelOpState.comp (RelOpState.delta (SemCond b))
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
84 (SemComm cm'))
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
85 t1 : RelOpState.comp
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
86 (Rel1 n)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
87 (RelOpState.delta (NotP (SemCond b))) s1 s2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
88 t1 = proj@$\text{2}$@ q2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
89 t15 : (Rel1 n s1 s2) @$\times$@ (NotP (SemCond b) s2)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
90 t15 = proj@$\text{2}$@ (RelOpState.deltaRestPost
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
91 (NotP (SemCond b)) (Rel1 n) s1 s2)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
92 t1
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
93 t16 : Rel1 n s1 s2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
94 t16 = proj@$\text{1}$@ t15
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
95 t17 : NotP (SemCond b) s2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
96 t17 = proj@$\text{2}$@ t15
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
97 lem1 : (m : $mathbb{N}$) @$\rightarrow$@ (ss2 : State) @$\rightarrow$@ Rel1 m s1 ss2 @$\rightarrow$@
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
98 SemCond bInv ss2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
99 lem1 $mathbb{N}$.zero ss2 h
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
100 = substId1 State (proj@$\text{2}$@ h) (SemCond bInv) q1
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
101 lem1 ($mathbb{N}$.suc n) ss2 h
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
102 = let hyp2 : (z : State) @$\rightarrow$@ Rel1 n s1 z @$\rightarrow$@
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
103 SemCond bInv z
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
104 hyp2 = lem1 n
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
105 s20 : State
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
106 s20 = proj@$\text{1}$@ h
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
107 t21 : Rel1 n s1 s20
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
108 t21 = proj@$\text{1}$@ (proj@$\text{2}$@ h)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
109 t22 : (SemCond b s20) @$\times$@ (SemComm cm' s20 ss2)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
110 t22 = proj@$\text{2}$@ (RelOpState.deltaRestPre
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
111 (SemCond b) (SemComm cm') s20 ss2)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
112 (proj@$\text{2}$@ (proj@$\text{2}$@ h))
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
113 t23 : SemCond (bInv /\ b) s20
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
114 t23 = proj@$\text{2}$@ (respAnd bInv b s20)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
115 (hyp2 s20 t21 , proj@$\text{1}$@ t22)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
116 in hyp s20 ss2 t23 (proj@$\text{2}$@ t22)
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
117 t20 : SemCond bInv s2 @$\times$@ SemCond (neg b) s2
b5fffa8ae875 fix chapter hoare
ryokka
parents:
diff changeset
118 t20 = lem1 n s2 t16 , proj@$\text{2}$@ (respNeg b s2) t17