-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rules.thy
184 lines (166 loc) · 7.79 KB
/
Rules.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
theory Rules
imports Interference
begin
chapter \<open>Rules\<close>
text \<open>Define the rely/guarantee rules for a concurrent program.\<close>
locale rules = interference
context rules
begin
section \<open>Global Rules\<close>
text \<open>Establish the rules of the logic, similar to standard Hoare-logic\<close>
inductive rules :: "'b rpred \<Rightarrow> 'b rpred \<Rightarrow> 'b set \<Rightarrow> ('a,'b) com \<Rightarrow> 'b set \<Rightarrow> bool"
("_,_ \<turnstile> _ {_} _" [65,0,0,0,65] 65)
where
basic[intro]: "R,G \<turnstile>\<^sub>A P {\<alpha>} Q \<Longrightarrow> R,G \<turnstile> P { Basic \<alpha> } Q" |
nil[intro]: "stable R P \<Longrightarrow> R,G \<turnstile> P { Nil } P" |
seq[intro]: "R,G \<turnstile> Q { c\<^sub>2 } M \<Longrightarrow> R,G \<turnstile> P { c\<^sub>1 } Q \<Longrightarrow> R,G \<turnstile> P { c\<^sub>1 ;\<^sub>w c\<^sub>2 } M" |
choice[intro]: "\<forall>l. R,G \<turnstile> P { S l } Q \<Longrightarrow> R,G \<turnstile> P { Choice S } Q" |
loop[intro]: "stable R P \<Longrightarrow> R,G \<turnstile> P { c } P \<Longrightarrow> R,G \<turnstile> P { c*\<^sub>w } P" |
thread[intro]: "R,G \<turnstile> P { c } Q \<Longrightarrow> rif R G c \<Longrightarrow> R,G \<turnstile> P { Thread c } Q" |
par[intro]: "R\<^sub>1,G\<^sub>1 \<turnstile> P\<^sub>1 { c\<^sub>1 } Q\<^sub>1 \<Longrightarrow> R\<^sub>2,G\<^sub>2 \<turnstile> P\<^sub>2 { c\<^sub>2 } Q\<^sub>2 \<Longrightarrow> G\<^sub>2 \<subseteq> R\<^sub>1 \<Longrightarrow> G\<^sub>1 \<subseteq> R\<^sub>2 \<Longrightarrow>
R\<^sub>1 \<inter> R\<^sub>2,G\<^sub>1 \<union> G\<^sub>2 \<turnstile> P\<^sub>1 \<inter> P\<^sub>2 { c\<^sub>1 || c\<^sub>2 } (Q\<^sub>1 \<inter> Q\<^sub>2)" |
conseq[intro]: "R,G \<turnstile> P { c } Q \<Longrightarrow> P' \<subseteq> P \<Longrightarrow> R' \<subseteq> R \<Longrightarrow> G \<subseteq> G' \<Longrightarrow> Q \<subseteq> Q' \<Longrightarrow>
R',G' \<turnstile> P' { c } Q'" |
inv[intro]: "R,G \<turnstile> P {c} Q \<Longrightarrow> stable R' I \<Longrightarrow> G \<subseteq> R' \<Longrightarrow> R \<inter> R',G \<turnstile> (P \<inter> I) {c} (Q \<inter> I)" |
capture[intro]: "uncapRely R,uncapGuar G \<turnstile> pushpred s P {c} pushpredAll Q \<Longrightarrow>
R,G \<turnstile> P {Capture s c} Q"
subsection \<open>Properties\<close>
lemma nilE [elim!]:
assumes "R,G \<turnstile> P {Nil} Q"
obtains M where "stable R M" "P \<subseteq> M" "M \<subseteq> Q"
using assms
by (induct R G P "Nil :: ('a,'b) com" Q) blast+
lemma nilE2:
assumes "R,G \<turnstile> P {Nil} Q"
shows "stabilise R P \<subseteq> Q"
using assms
proof (induct R G P "Nil :: ('a,'b) com" Q)
case (nil R P G)
then show ?case
by (simp add: stabilise_stable)
next
case (conseq R G P Q P' R' G' Q')
then show ?case
by (meson dual_order.trans stabilise_mono_RP)
next
case (inv R G P Q R' I)
then show ?case
by (metis Int_commute inf_mono order_refl stabilise_inter_RP stabilise_stable subset_trans)
qed
lemma basicE [elim!]:
assumes "R,G \<turnstile> P {Basic \<beta>} Q"
obtains Q' where "R,G \<turnstile>\<^sub>A stabilise R P {\<beta>} Q'" "Q' \<subseteq> Q"
using assms
proof (induct R G P "Basic \<beta> :: ('a,'b) com" Q arbitrary: \<beta>)
case (basic R G P \<alpha> Q)
then show ?case using stabilise_atomic by fast
next
case (conseq R G P Q P' R' G' Q')
show ?case
proof (rule conseq(2), goal_cases)
case (1 Q')
thus ?case using conseq
by (meson atomic_conseqI atomic_pre dual_order.trans stabilise_mono_RP stable_stabilise)
qed
next
case (inv R G P Q R' I)
show ?case
proof (rule inv(2), goal_cases)
case (1 Q')
thus ?case using inv(3,4) inv(5)[of "Q' \<inter> I"] atomic_invI
by (smt (verit, best) Int_greatest atomic_pre dual_order.eq_iff dual_order.trans
le_infE stabilise_inter_RP stabilise_stable stable_stabilise)
qed
qed
lemma seqE [elim]:
assumes "R,G \<turnstile> P {c\<^sub>1 ;\<^sub>w c\<^sub>2} Q"
obtains M where "R,G \<turnstile> P {c\<^sub>1} M" "R,G \<turnstile> M {c\<^sub>2} Q"
using assms by (induct R G P "c\<^sub>1 ;\<^sub>w c\<^sub>2" Q arbitrary: c\<^sub>1 c\<^sub>2) blast+
lemma captureE:
assumes "R,G \<turnstile> P {Capture s c} Q"
shows "uncapRely R,uncapGuar G \<turnstile> uncapPred s P {c} pushpredAll Q"
using assms
proof (induct R G P "Capture s c" Q arbitrary: s c)
case (conseq R G P Q P' R' G' Q')
thus ?case using rules.conseq by force
next
case (capture R G s P c Q)
thus ?case by simp
next
case (inv R G P Q R' I)
have "pushrelSame R,pushrelAll G \<turnstile> pushpred s P {c} pushpredAll Q"
using inv(2) by auto
moreover have "pushrelAll G \<subseteq> pushrelAll R'"
using inv by (intro pushrelAll_mono)
moreover have
"stable (pushrelAll R') (pushpredAll I)"
using inv by (intro stable_pushrelAll)
ultimately have
"pushrelSame R \<inter> pushrelAll R',pushrelAll G
\<turnstile> pushpred s P \<inter> pushpredAll I {c} pushpredAll Q \<inter> pushpredAll I"
by (intro rules.inv)
hence
"pushrelSame R \<inter> pushrelAll R',pushrelAll G
\<turnstile> pushpred s (P \<inter> I) {c} pushpredAll (Q \<inter> I)"
by (simp add: pushpred_inter_pushpredAll pushpredAll_inter)
hence
"pushrelSame (R \<inter> R'),pushrelAll G
\<turnstile> pushpred s (P \<inter> I) {c} pushpredAll (Q \<inter> I)"
using pushrelSame_in_pushrelAll by auto
thus ?case.
qed
text \<open>In fact, we can rephrase a judgement with an explicit stabilisation.\<close>
lemma stable_preE':
assumes "R,G \<turnstile> P {c} Q"
shows "R,G \<turnstile> stabilise R P {c} Q"
using assms
proof (induct)
case (basic R G P \<alpha> Q)
thus ?case using stabilise_atomic by (intro rules.basic, simp)
next
case (nil R P G)
thus ?case by (simp add: rules.nil stabilise_stable)
next
case (loop R P G c)
thus ?case by (simp add: rules.loop stabilise_stable)
next
case (par R\<^sub>1 G\<^sub>1 P\<^sub>1 c\<^sub>1 Q\<^sub>1 R\<^sub>2 G\<^sub>2 P\<^sub>2 c\<^sub>2 Q\<^sub>2)
hence "R\<^sub>1 \<inter> R\<^sub>2, G\<^sub>1 \<union> G\<^sub>2 \<turnstile> stabilise R\<^sub>1 P\<^sub>1 \<inter> stabilise R\<^sub>2 P\<^sub>2 {c\<^sub>1 || c\<^sub>2} Q\<^sub>1 \<inter> Q\<^sub>2"
by (intro rules.par)
thus ?case using stabilise_inter_RP by (rule conseq; simp)
next
case (conseq R G P c Q P' R' G' Q')
thus ?case using stabilise_mono_RP[of R' R P' P] by blast
next
case (inv R G P c Q R' I)
hence "R \<inter> R',G \<turnstile> stabilise R P \<inter> I {c} Q \<inter> I" by (intro rules.inv)
hence "R \<inter> R',G \<turnstile> stabilise R P \<inter> stabilise R' I {c} Q \<inter> I"
using inv stabilise_stable[of R' I] by simp
thus ?case using stabilise_inter_RP by (rule conseq; simp)
next
case (capture R G s P c Q)
thus ?case by (intro rules.capture, auto simp add: stabilise_pushrel)
qed auto
text \<open>It is always possible to rephrase a judgement in terms of a stable precondition\<close>
lemma stable_preE:
assumes "R,G \<turnstile> P {c} Q"
shows "\<exists>P'. P \<subseteq> P' \<and> stable R P' \<and> R,G \<turnstile> P' {c} Q"
using assms stabilise_supset stable_stabilise stable_preE'
by metis
text \<open>Universal quantification of top-most stack frame\<close>
lemma univ_captureI:
assumes "\<forall>l. pushrelSame R,pushrelAll G \<turnstile> pushpred l P {c} pushpredAll Q"
shows "R,G \<turnstile> P {\<forall>\<^sub>c c} Q"
using assms by (intro choice allI capture) simp
lemma falseI:
"local c \<Longrightarrow> R,G \<turnstile> {} {c} {}"
proof (induct c arbitrary: R G)
case (Basic x)
thus ?case by (intro basic) (auto simp: atomic_rule_def guar_def wp_def)
next
case (Seq c1 w c2)
hence "R,G \<turnstile> {} {c1} {}" "R,G \<turnstile> {} {c2} {}" by (meson local_simps(3) subsetD)+
then show ?case by auto
qed (auto)
end
end