diff -r 995eb45bbadc -r 545fef826fa9 thys/Hoare_gen.thy --- a/thys/Hoare_gen.thy Thu Mar 13 20:06:29 2014 +0000 +++ b/thys/Hoare_gen.thy Wed Mar 19 00:00:28 2014 +0000 @@ -7,17 +7,25 @@ "../Separation_Algebra/Sep_Tactics" begin -definition pasrt :: "bool \ (('a::sep_algebra) \ bool)" ("<_>" [72] 71) +definition + pasrt :: "bool \ 'a::sep_algebra \ bool" ("<_>" [72] 71) where "pasrt b = (\ s . s = 0 \ b)" -lemma sep_conj_cond1: "(p \* \* q) = ( \* p \* q)" - by(simp add: sep_conj_ac) + +(* smae as sep.mult.left_commute *) +lemma sep_conj_cond1: + "(p \* \* q) = ( \* p \* q)" + by (rule sep.mult.left_commute) -lemma sep_conj_cond2: "(p \* ) = ( \* p)" - by(simp add: sep_conj_ac) +(* same as sep.mult.commute *) +lemma sep_conj_cond2: + "(p \* ) = ( \* p)" + by(rule sep.mult.commute) -lemma sep_conj_cond3: "(( \* p) \* r) = ( \* p \* r)" - by (metis sep.mult_assoc) +(* same as sep.mult_assoc *) +lemma sep_conj_cond3: + "(( \* p) \* r) = ( \* p \* r)" + by (rule sep.mult_assoc) lemmas sep_conj_cond = sep_conj_cond1 sep_conj_cond2 sep_conj_cond3 @@ -33,7 +41,7 @@ lemma cond_true_eq2: "(p \* ) = p" by simp -lemma condD: "( ** r) s \ b \ r s" +lemma condD: "( \* r) s \ b \ r s" by (unfold sep_conj_def pasrt_def, auto) locale sep_exec = @@ -44,73 +52,60 @@ definition "run n = step ^^ n" lemma run_add: "run (n1 + n2) s = run n1 (run n2 s)" - apply (unfold run_def) - by (metis funpow_add o_apply) + unfolding run_def + by (simp add: funpow_add) +(* separation Hoare tripple *) definition - Hoare_gen :: "('a \ bool) \ ('a \ bool) \ ('a \ bool) \ bool" - ("(\(1_)\ / (_)/ \(1_)\)" 50) + Hoare_gen :: "('a \ bool) \ ('a \ bool) \ ('a \ bool) \ bool" ("(\(1_)\/ (_)/ \(1_)\)" 50) where - "\ p \ c \ q \ \ - (\ s r. (p**c**r) (recse s) \ (\ k. ((q ** c ** r) (recse (run (Suc k) s)))))" + "\p\ c \q\ \ + (\s r. (p \* c \* r) (recse s) \ (\k. ((q \* c \* r) (recse (run (Suc k) s)))))" lemma HoareI [case_names Pre]: - assumes h: "\ r s. (p**c**r) (recse s) \ (\ k. ((q ** c ** r) (recse (run (Suc k) s))))" - shows "\ p \ c \ q \" + assumes h: "\ r s. (p \* c \* r) (recse s) \ (\k. ((q \* c \* r) (recse (run (Suc k) s))))" + shows "\p\ c \q\" using h - by (unfold Hoare_gen_def, auto) + unfolding Hoare_gen_def + by simp lemma frame_rule: - assumes h: "\ p \ c \ q \" - shows "\ p ** r \ c \ q ** r \" -proof(induct rule: HoareI) - case (Pre r' s') - hence "(p \* c \* r \* r') (recse s')" by (auto simp:sep_conj_ac) - from h[unfolded Hoare_gen_def, rule_format, OF this] - show ?case - by (metis sep_conj_assoc sep_conj_left_commute) -qed + assumes "\p\ c \q\" + shows "\p \* r\ c \q \* r\" +using assms +unfolding Hoare_gen_def +by (metis sep_conj_assoc sep_conj_left_commute) lemma sequencing: assumes h1: "\p\ c \q\" and h2: "\q\ c \r\" shows "\p\ c \r\" -proof(induct rule:HoareI) +proof(induct rule: HoareI) case (Pre r' s') - from h1[unfolded Hoare_gen_def, rule_format, OF Pre] + have "(p \* c \* r') (recse s')" by fact + with h1[unfolded Hoare_gen_def] obtain k1 where "(q \* c \* r') (recse (run (Suc k1) s'))" by auto - from h2[unfolded Hoare_gen_def, rule_format, OF this] + with h2[unfolded Hoare_gen_def] obtain k2 where "(r \* c \* r') (recse (run (Suc k2) (run (Suc k1) s')))" by auto - thus ?case - apply (rule_tac x = "Suc (k1 + k2)" in exI) - by (metis add_Suc_right nat_add_commute sep_exec.run_add) + thus "\k. (r \* c \* r') (recse (run (Suc k) s'))" + by (auto simp add: run_add[symmetric]) qed lemma pre_stren: assumes h1: "\p\ c \q\" - and h2: "\s. r s \ p s" + and h2: "\s. r s \ p s" shows "\r\ c \q\" -proof(induct rule:HoareI) - case (Pre r' s') - with h2 - have "(p \* c \* r') (recse s')" - by (metis sep_conj_impl1) - from h1[unfolded Hoare_gen_def, rule_format, OF this] - show ?case . -qed +using assms +unfolding Hoare_gen_def +by (metis sep_globalise) lemma post_weaken: assumes h1: "\p\ c \q\" and h2: "\ s. q s \ r s" shows "\p\ c \r\" -proof(induct rule:HoareI) - case (Pre r' s') - from h1[unfolded Hoare_gen_def, rule_format, OF this] - obtain k where "(q \* c \* r') (recse (run (Suc k) s'))" by blast - with h2 - show ?case - by (metis sep_conj_impl1) -qed +using assms +unfolding Hoare_gen_def +by (metis sep_globalise) lemma hoare_adjust: assumes h1: "\p1\ c \q1\" @@ -118,65 +113,55 @@ and h3: "\s. q1 s \ q s" shows "\p\ c \q\" using h1 h2 h3 post_weaken pre_stren - by (metis) + by (blast) lemma code_exI: assumes h: "\ k. \p\ c(k) \q\" shows "\p\ EXS k. c(k) \q\" -proof(unfold pred_ex_def, induct rule:HoareI) +unfolding pred_ex_def +proof(induct rule:HoareI) case (Pre r' s') then obtain k where "(p \* (\ s. c k s) \* r') (recse s')" - by (auto elim!:sep_conjE intro!:sep_conjI) + by (auto elim!: sep_conjE intro!: sep_conjI) from h[unfolded Hoare_gen_def, rule_format, OF this] - show ?case - by (auto elim!:sep_conjE intro!:sep_conjI) + show "\k. (q \* (\s. \x. c x s) \* r') (recse (run (Suc k) s'))" + by (auto elim!: sep_conjE intro!: sep_conjI) qed lemma code_extension: - assumes h: "\ p \ c \ q \" - shows "\ p \ c ** e \ q \" -proof(induct rule:HoareI) - case (Pre r' s') - hence "(p \* c \* e \* r') (recse s')" by (auto simp:sep_conj_ac) - from h[unfolded Hoare_gen_def, rule_format, OF this] - show ?case - by (auto elim!:sep_conjE intro!:sep_conjI simp:sep_conj_ac) -qed + assumes "\p\ c \q\" + shows "\p\ c \* e \q\" +using assms +unfolding Hoare_gen_def +by (metis sep_conj_assoc) lemma code_extension1: - assumes h: "\ p \ c \ q \" - shows "\ p \ e ** c \ q \" - by (metis code_extension h sep.mult_commute) + assumes "\p\ c \q\" + shows "\p\ e \* c \q\" +using assms +unfolding Hoare_gen_def +by (metis sep_conj_commute sep_conj_left_commute) lemma composition: assumes h1: "\p\ c1 \q\" and h2: "\q\ c2 \r\" - shows "\p\ c1 ** c2 \r\" -proof(induct rule:HoareI) - case (Pre r' s') - hence "(p \* c1 \* c2 \* r') (recse s')" by (auto simp:sep_conj_ac) - from h1[unfolded Hoare_gen_def, rule_format, OF this] - obtain k1 where "(q \* c2 \* c1 \* r') (recse (run (Suc k1) s'))" - by (auto simp:sep_conj_ac) - from h2[unfolded Hoare_gen_def, rule_format, OF this, folded run_add] - show ?case - by (auto elim!:sep_conjE intro!:sep_conjI simp:sep_conj_ac) -qed + shows "\p\ c1 \* c2 \r\" +using assms +by (auto intro: sequencing code_extension code_extension1) definition - IHoare :: "('b::sep_algebra \ 'a \ bool) \ - ('b \ bool) \ ('a \ bool) \ ('b \ bool) \ bool" - ("(1_).(\(1_)\ / (_)/ \(1_)\)" 50) + IHoare :: "('b::sep_algebra \ 'a \ bool) \ ('b \ bool) \ ('a \ bool) \ ('b \ bool) \ bool" + ("(1_).(\(1_)\/ (_)/ \(1_)\)" 50) where "I. \P\ c \Q\ = (\s'. \ EXS s.

\* <(s ## s')> \* I(s + s')\ c - \ EXS s. \* <(s ## s')> \* I(s + s')\)" + \ EXS s. \* <(s ## s')> \* I(s + s')\)" lemma IHoareI [case_names IPre]: assumes h: "\s' s r cnf . (

\* <(s ## s')> \* I(s + s') \* c \* r) (recse cnf) \ (\k t. ( \* <(t ## s')> \* I(t + s') \* c \* r) (recse (run (Suc k) cnf)))" shows "I. \P\ c \Q\" - unfolding IHoare_def +unfolding IHoare_def proof fix s' show " \EXS s.

\* <(s ## s')> \* I (s + s')\ c