Skip to content

Commit 08295d7

Browse files
committed
Added total correctness law for relational Hoare logic
1 parent 1469c16 commit 08295d7

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

utp_hoare.thy

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
subsection \<open> Hoare Logic \<close>
22

33
theory utp_hoare
4-
imports utp_assertional utp_rel_prog
4+
imports utp_assertional utp_rel_prog utp_wp
55
begin
66

77
subsection \<open> Sequence Laws \<close>
@@ -262,6 +262,58 @@ next
262262
then show ?case by simp
263263
qed
264264

265+
lemma while_thoare_r [hoare_safe]:
266+
fixes V :: "'s \<Rightarrow> 'a::wellorder"
267+
assumes "\<And> z. H[P \<and> B \<and> V = \<guillemotleft>z\<guillemotright>] S [P \<and> V < \<guillemotleft>z\<guillemotright>]"
268+
shows "H[P] while B do S od [\<not> B \<and> P]"
269+
proof -
270+
from assms have "\<^bold>{P \<and> B\<^bold>} S \<^bold>{P\<^bold>}"
271+
by (auto simp add: hoare_rel_r_def thoare_rel_r_alt_def)
272+
hence partial: "\<^bold>{P\<^bold>} while B do S od \<^bold>{\<not> B \<and> P\<^bold>}"
273+
using while_hoare_r by blast
274+
from assms have S_term: "`B \<and> P \<longrightarrow> pre S`"
275+
by (simp add: pre_def thoare_rel_r_def)
276+
have wS_term: "`P \<longrightarrow> (while B do S od) wp True`"
277+
proof (rule tautI, simp, rule impI)
278+
fix s
279+
assume P: "P s"
280+
show "(while B do S od wp True) s"
281+
proof (cases "B s")
282+
case False
283+
then show ?thesis
284+
by (force simp add: wp_while)
285+
next
286+
case True
287+
with P have "\<exists> xs. xs \<noteq> [] \<and> (\<forall> i<length xs. B ((s # xs) ! i) \<and> S ((s # xs) ! i, xs ! i)) \<and> \<not> B(last xs) \<and> P (last xs)"
288+
proof (induct "V(s)" arbitrary: s rule: less_induct)
289+
case less
290+
with assms(1) obtain s' where s': "S (s, s')" "P s'" "V s' < V s"
291+
by (force simp add: pred)
292+
show ?case
293+
proof (cases "B s'")
294+
case False
295+
then show ?thesis
296+
by (metis add.right_neutral add_Suc_right last_single_element less.prems(2) less_Suc0 list.size(3,4) not_Cons_self2 nth_Cons_0 s'(1,2))
297+
next
298+
case True
299+
obtain xs where xs:"xs \<noteq> []" "\<forall> i<length xs. B ((s' # xs) ! i) \<and> S ((s' # xs) ! i, xs ! i)" "\<not> B(last xs)" "P (last xs)"
300+
using True less.hyps s'(2,3) by blast
301+
show ?thesis
302+
proof
303+
show "\<not> (s' # xs) = [] \<and> (\<forall>i. i < length (s' # xs) \<longrightarrow> B ((s # s' # xs) ! i) \<and> S ((s # s' # xs) ! i, (s' # xs) ! i)) \<and> \<not> B (last (s' # xs)) \<and> P (last (s' # xs))"
304+
using less.prems(2) less_Suc_eq_0_disj s'(1) xs(1,2,3,4) by force
305+
qed
306+
qed
307+
qed
308+
309+
then show ?thesis
310+
by (auto simp add: wp_while)
311+
qed
312+
qed
313+
show ?thesis
314+
using partial thoare_rel_r_alt_def wS_term by blast
315+
qed
316+
265317
subsection \<open> Verification Condition Generation \<close>
266318

267319
method vcg = (auto intro!: hoare_safe; expr_taut; auto)

0 commit comments

Comments
 (0)