Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refinement proof for AArch64 #668

Merged
merged 48 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
322f4f9
aarch64 refine: remove pspace_canonical'
lsf37 Jun 6, 2023
6e57667
aarch64 refine: invariant update lemmas
lsf37 Sep 27, 2023
7ae4e55
aarch64 refine: ArchAcc_R sorry free
lsf37 Jun 6, 2023
c77d649
aarch64 aspec: sync with Haskell
lsf37 Jun 7, 2023
d16b4fd
aarch64 ainvs: new invariant on vmid_table
lsf37 Jul 3, 2023
345818d
aarch64 aspec: cleanByVA_PoU in perform_pg_inv_map
lsf37 Jul 4, 2023
7713dff
aarch64 ainvs: updates for spec change
lsf37 Jul 4, 2023
438e27a
aarch64 aspec: fix do_flush spec bug
lsf37 Jul 5, 2023
c628181
aarch64 aspec+ainvs: add valid_asid_map invariant
lsf37 Jul 4, 2023
d16d35e
aarch64 refine: VSpace_R sorry-free
lsf37 Jul 3, 2023
f14217e
aarch64 refine: progress in Retype_R
lsf37 Jul 17, 2023
e74d5fe
aarch64 refine: progress in Retype_R
lsf37 Jul 18, 2023
4913aa8
aarch64 haskell: tweak createNewCaps definition
lsf37 Jul 18, 2023
2ec696f
aarch64 refine: Retype_R sorry-free
lsf37 Jul 18, 2023
1ea097a
aarch64 refine: Untyped_R sorry-free
lsf37 Jul 18, 2023
1f60044
aarch64 refine: Schedule_R sorry-free
lsf37 Jul 19, 2023
73ba0ce
aarch64 refine: IpcCancel_R sorry-free
lsf37 Jul 20, 2023
522cef1
aarch64 refine: Finalise_R sorry-free
lsf37 Jul 21, 2023
0e8048b
aarch64 aspec+ainvs: sync user_vtop check with C
lsf37 Jul 23, 2023
d849c0b
aarch64 haskell: fix syscall arg error reporting
lsf37 Jul 23, 2023
e2355c7
aarch64 haskell: check cap type in checkVSpaceRoot
lsf37 Jul 23, 2023
1fb96c7
aarch64 ainvs: mark addrFromPPtr_mask_ipa
lsf37 Jul 23, 2023
c745d4e
aarch64 aspec: fix flush type in decode_vspace_invocation
lsf37 Jul 23, 2023
da76bca
aarch64 refine: Arch_R sorry-free
lsf37 Jul 23, 2023
1f05109
aarch64 refine: Ipc_R sorry-free
lsf37 Jul 26, 2023
a0311bd
aarch64 refine: Interrupt_R sorry-free
lsf37 Jul 26, 2023
ffd038f
aarch64 refine: ADT_H sorry-free
lsf37 Jul 27, 2023
1fde048
aarch64 refine: progress in Detype_R
lsf37 Jul 28, 2023
8f2710d
aarch64 refine: Detype_R sorry-free
lsf37 Aug 9, 2023
2e3c97d
aarch64 refine: Orphanage sorry-free
Xaphiosis Aug 10, 2023
cf0e636
aarch64 refine: resolve trivial FIXMEs
lsf37 Aug 22, 2023
43c0759
aarch64 refine: leave comment instead of FIXME
lsf37 Aug 22, 2023
6bfdecd
aarch64 refine: defer some FIXMEs to CRefine
lsf37 Aug 22, 2023
c263749
aarch64 refine: consolidate dmo_invs_no_cicd' lemmas
lsf37 Aug 23, 2023
62618fc
aarch64 refine: improve decode invariance crunch
lsf37 Aug 23, 2023
4c69a42
lib: fix ML warning
lsf37 Aug 24, 2023
6793a94
lib: move lemmas from refine/AARCH64/ArchAcc
lsf37 Aug 24, 2023
5f74194
aarch64 refine: move lemmas to lib
lsf37 Aug 24, 2023
9f7e8f8
word_lib: anti-monotonicity of shiftr
lsf37 Aug 24, 2023
fe3ebf0
lib: lemmas moved from aarch64 refine
lsf37 Aug 24, 2023
dc4955d
aarch64 refine: lemma moved to Word_Lib
lsf37 Aug 24, 2023
2251bf8
aarch64 refine: lemmas moved to lib
lsf37 Aug 24, 2023
26a3a6e
aarch64 refine: lemmas moved to aarch64 ainvs
lsf37 Aug 24, 2023
a24ddbe
aarch64 refine: move lemmas internally
lsf37 Aug 24, 2023
de50741
lib+aarch64 refine: move lemmas to lib
lsf37 Aug 24, 2023
0369a4b
lib+ainvs+aarch64 refine: move+consolidate vcg_op_lift lemmas
lsf37 Aug 24, 2023
dcf6ee4
aarch64 ainvs+refine: move lemmas from Refine
lsf37 Aug 28, 2023
5497666
aarch64 ainvs+refine: remove unused dom_ucast_eq
lsf37 Aug 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/Corres_UL.thy
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ lemma corres_splitEE:
apply (clarsimp simp: lift_def y)+
done

lemma corres_splitEE_prod:
assumes x: "corres_underlying sr nf nf' (f \<oplus> r') P P' a c"
assumes y: "\<And>x y x' y'. r' (x, y) (x', y')
\<Longrightarrow> corres_underlying sr nf nf' (f \<oplus> r) (R x y) (R' x' y') (b x y) (d x' y')"
assumes z: "\<lbrace>Q\<rbrace> a \<lbrace>\<lambda>(x, y). R x y \<rbrace>,\<lbrace>\<top>\<top>\<rbrace>" "\<lbrace>Q'\<rbrace> c \<lbrace>\<lambda>(x, y). R' x y\<rbrace>,\<lbrace>\<top>\<top>\<rbrace>"
shows "corres_underlying sr nf nf' (f \<oplus> r) (P and Q) (P' and Q') (a >>=E (\<lambda>(x, y). b x y)) (c >>=E (\<lambda>(x, y). d x y))"
using assms
apply (unfold bindE_def validE_def)
apply (rule corres_split[rotated 2], assumption+)
apply (fastforce simp: lift_def y split: sum.splits)
done

lemma corres_split_handle:
assumes "corres_underlying sr nf nf' (f' \<oplus> r) P P' a c"
assumes y: "\<And>ft ft'. f' ft ft'
Expand Down Expand Up @@ -494,6 +506,8 @@ lemma corres_liftE_rel_sum[simp]:
corres_underlying sr nf nf' r P P' m m'"
by (simp add: liftE_liftM o_def)

lemmas corres_liftE_lift = corres_liftE_rel_sum[THEN iffD2]

text \<open>Support for proving correspondence to noop with hoare triples\<close>

lemma corres_noop:
Expand Down Expand Up @@ -689,6 +703,17 @@ lemma corres_trivial:
"corres_underlying sr nf nf' r \<top> \<top> f g \<Longrightarrow> corres_underlying sr nf nf' r \<top> \<top> f g"
by assumption

lemma corres_underlying_trivial[corres]:
"\<lbrakk> nf' \<Longrightarrow> no_fail P' f \<rbrakk> \<Longrightarrow> corres_underlying Id nf nf' (=) \<top> P' f f"
by (auto simp add: corres_underlying_def Id_def no_fail_def)

(* Instance of corres_underlying_trivial for unit type with dc instead of (=) as return relation,
for nicer return relation instantiation. *)
lemma corres_underlying_trivial_dc[corres]:
"(nf' \<Longrightarrow> no_fail P' f) \<Longrightarrow> corres_underlying Id nf nf' dc (\<lambda>_. True) P' f f"
for f :: "('s, unit) nondet_monad"
by (fastforce intro: corres_underlying_trivial corres_rrel_pre)

lemma corres_assume_pre:
assumes R: "\<And>s s'. \<lbrakk> P s; Q s'; (s,s') \<in> sr \<rbrakk> \<Longrightarrow> corres_underlying sr nf nf' r P Q f g"
shows "corres_underlying sr nf nf' r P Q f g"
Expand Down Expand Up @@ -855,6 +880,31 @@ lemma corres_assert_opt_assume:
by (auto simp: bind_def assert_opt_def assert_def fail_def return_def
corres_underlying_def split: option.splits)

lemma corres_assert_opt[corres]:
"r x x' \<Longrightarrow>
corres_underlying sr nf nf' (\<lambda>x x'. r (Some x) x') (\<lambda>s. x \<noteq> None) \<top> (assert_opt x) (return x')"
unfolding corres_underlying_def
by (clarsimp simp: assert_opt_def return_def split: option.splits)

lemma assert_opt_assert_corres[corres]:
"(x = None) = (x' = None) \<Longrightarrow>
corres_underlying sr nf nf' (\<lambda>y _. x = Some y) (K (x \<noteq> None)) \<top>
(assert_opt x) (assert (\<exists>y. x' = Some y))"
by (simp add: corres_underlying_def assert_opt_def return_def split: option.splits)

lemma corres_assert_opt_l:
assumes "\<And>x. P' = Some x \<Longrightarrow> corres_underlying sr nf nf' r (P x) Q (f x) g"
shows "corres_underlying sr nf nf' r (\<lambda>s. \<exists>x. P' = Some x \<and> P x s) Q (assert_opt P' >>= f) g"
using assms
by (auto simp: bind_def assert_opt_def assert_def fail_def return_def corres_underlying_def
split: option.splits)

lemma corres_gets_the_gets:
"corres_underlying sr False nf' r P P' (gets_the f) f' \<Longrightarrow>
corres_underlying sr nf nf' (\<lambda>x x'. x \<noteq> None \<and> r (the x) x') P P' (gets f) f'"
apply (simp add: gets_the_def bind_def simpler_gets_def assert_opt_def)
apply (fastforce simp: corres_underlying_def in_monad split: option.splits)
done

text \<open>Support for proving correspondance by decomposing the state relation\<close>

Expand Down
2 changes: 2 additions & 0 deletions lib/ExtraCorres.thy
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ lemma corres_mapM_x:
apply (simp | wp)+
done

lemmas corres_mapM_x' = corres_mapM_x[OF _ _ _ _ order_refl]

(* FIXME: see comment for mapM rule. Same applies for lemma strength *)
lemma corres_mapME:
assumes x: "r [] []"
Expand Down
4 changes: 0 additions & 4 deletions lib/LemmaBucket.thy
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ imports
SubMonadLib
begin

lemma corres_underlying_trivial:
"\<lbrakk> nf' \<Longrightarrow> no_fail P' f \<rbrakk> \<Longrightarrow> corres_underlying Id nf nf' (=) \<top> P' f f"
by (auto simp add: corres_underlying_def Id_def no_fail_def)

lemma hoare_spec_gen_asm:
"\<lbrakk> F \<Longrightarrow> s \<turnstile> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace> \<rbrakk> \<Longrightarrow> s \<turnstile> \<lbrace>P and K F\<rbrace> f \<lbrace>Q\<rbrace>"
"\<lbrakk> F \<Longrightarrow> s \<turnstile> \<lbrace>P\<rbrace> f' \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow> s \<turnstile> \<lbrace>P and K F\<rbrace> f' \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
Expand Down
8 changes: 8 additions & 0 deletions lib/Lib.thy
Original file line number Diff line number Diff line change
Expand Up @@ -2522,6 +2522,14 @@ lemma if_option_None_eq:
"((if P then Some x else None) = None) = (\<not>P)"
by simp+

lemma option_case_all_conv:
"(case x of None \<Rightarrow> True | Some v \<Rightarrow> P v) = (\<forall>v. x = Some v \<longrightarrow> P v)"
by (auto split: option.split)

lemma prod_o_comp:
"(case x of (a, b) \<Rightarrow> f a b) \<circ> g = (case x of (a, b) \<Rightarrow> f a b \<circ> g)"
by (auto simp: split_def)

lemma lhs_sym_eq:
"(a = b) = x \<longleftrightarrow> (b = a) = x"
by auto
Expand Down
7 changes: 7 additions & 0 deletions lib/MonadicRewrite.thy
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,13 @@ lemma monadic_rewrite_gets_the_gets:
apply (auto simp: simpler_gets_def return_def)
done

lemma gets_oapply_liftM_rewrite:
"monadic_rewrite False True (\<lambda>s. f s p \<noteq> None)
(gets (oapply p \<circ> f)) (liftM Some (gets_map f p))"
unfolding monadic_rewrite_def
by (simp add: liftM_def simpler_gets_def bind_def gets_map_def assert_opt_def return_def
split: option.splits)

text \<open>Option cases\<close>

lemma monadic_rewrite_case_option:
Expand Down
8 changes: 8 additions & 0 deletions lib/Monads/nondet/Nondet_Monad_Equations.thy
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ lemma gets_fold_into_modify:
by (simp_all add: fun_eq_iff modify_def bind_assoc exec_gets
exec_get exec_put)

lemma gets_return_gets_eq:
"gets f >>= (\<lambda>g. return (h g)) = gets (\<lambda>s. h (f s))"
by (simp add: simpler_gets_def bind_def return_def)

lemma gets_prod_comp:
"gets (case x of (a, b) \<Rightarrow> f a b) = (case x of (a, b) \<Rightarrow> gets (f a b))"
by (auto simp: split_def)

lemma bind_assoc2:
"(do x \<leftarrow> a; _ \<leftarrow> b; c x od) = (do x \<leftarrow> (do x' \<leftarrow> a; _ \<leftarrow> b; return x' od); c x od)"
by (simp add: bind_assoc)
Expand Down
26 changes: 0 additions & 26 deletions lib/Monads/nondet/Nondet_More_VCG.thy
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ lemma valid_prove_more: (* FIXME: duplicate *)
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace>"
by (rule hoare_post_add)

lemma hoare_vcg_if_lift:
"\<lbrace>R\<rbrace> f \<lbrace>\<lambda>rv s. (P \<longrightarrow> X rv s) \<and> (\<not>P \<longrightarrow> Y rv s)\<rbrace> \<Longrightarrow>
\<lbrace>R\<rbrace> f \<lbrace>\<lambda>rv s. if P then X rv s else Y rv s\<rbrace>"

"\<lbrace>R\<rbrace> f \<lbrace>\<lambda>rv s. (P \<longrightarrow> X rv s) \<and> (\<not>P \<longrightarrow> Y rv s)\<rbrace> \<Longrightarrow>
\<lbrace>R\<rbrace> f \<lbrace>\<lambda>rv. if P then X rv else Y rv\<rbrace>"
by (auto simp: valid_def split_def)

lemma hoare_vcg_if_lift_strong:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>P\<rbrace>; \<lbrace>\<lambda>s. \<not> P' s\<rbrace> f \<lbrace>\<lambda>rv s. \<not> P rv s\<rbrace>; \<lbrace>Q'\<rbrace> f \<lbrace>Q\<rbrace>; \<lbrace>R'\<rbrace> f \<lbrace>R\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>\<lambda>s. if P' s then Q' s else R' s\<rbrace> f \<lbrace>\<lambda>rv s. if P rv s then Q rv s else R rv s\<rbrace>"
Expand Down Expand Up @@ -248,13 +240,6 @@ lemma hoare_vcg_if_lift_ER: (* Required because of lack of rv in lifting rules *
\<lbrace>R\<rbrace> f \<lbrace>\<lambda>rv. if P' rv then X rv else Y rv\<rbrace>, -"
by (auto simp: valid_def validE_R_def validE_def split_def)

lemma hoare_vcg_imp_liftE:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>\<lambda>rv s. \<not> P rv s\<rbrace>, \<lbrace>A\<rbrace>; \<lbrace>Q'\<rbrace> f \<lbrace>Q\<rbrace>, \<lbrace>A\<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace>\<lambda>s. \<not> P' s \<longrightarrow> Q' s\<rbrace> f \<lbrace>\<lambda>rv s. P rv s \<longrightarrow> Q rv s\<rbrace>, \<lbrace>A\<rbrace>"
apply (simp only: imp_conv_disj)
apply (clarsimp simp: validE_def valid_def split_def sum.case_eq_if)
done

lemma hoare_list_all_lift:
"(\<And>r. r \<in> set xs \<Longrightarrow> \<lbrace>Q r\<rbrace> f \<lbrace>\<lambda>rv. Q r\<rbrace>)
\<Longrightarrow> \<lbrace>\<lambda>s. list_all (\<lambda>r. Q r s) xs\<rbrace> f \<lbrace>\<lambda>rv s. list_all (\<lambda>r. Q r s) xs\<rbrace>"
Expand Down Expand Up @@ -419,13 +404,6 @@ lemma hoare_vcg_const_imp_lift_R:
"\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,- \<Longrightarrow> \<lbrace>\<lambda>s. F \<longrightarrow> P s\<rbrace> f \<lbrace>\<lambda>rv s. F \<longrightarrow> Q rv s\<rbrace>,-"
by (cases F, simp_all)

lemma hoare_vcg_disj_lift_R:
assumes x: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,-"
assumes y: "\<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>,-"
shows "\<lbrace>\<lambda>s. P s \<or> P' s\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<or> Q' rv s\<rbrace>,-"
using assms
by (fastforce simp: validE_R_def validE_def valid_def split: sum.splits)

lemmas throwError_validE_R = throwError_wp [where E="\<top>\<top>", folded validE_R_def]

lemma valid_case_option_post_wp:
Expand Down Expand Up @@ -592,10 +570,6 @@ lemma hoare_const_imp_R:
"\<lbrace>Q\<rbrace> f \<lbrace>R\<rbrace>,- \<Longrightarrow> \<lbrace>\<lambda>s. P \<longrightarrow> Q s\<rbrace> f \<lbrace>\<lambda>rv s. P \<longrightarrow> R rv s\<rbrace>,-"
by (cases P, simp_all)

lemma hoare_vcg_imp_lift_R:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>\<lambda>rv s. \<not> P rv s\<rbrace>, -; \<lbrace>Q'\<rbrace> f \<lbrace>Q\<rbrace>, - \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. P' s \<or> Q' s\<rbrace> f \<lbrace>\<lambda>rv s. P rv s \<longrightarrow> Q rv s\<rbrace>, -"
by (auto simp add: valid_def validE_R_def validE_def split_def split: sum.splits)

lemma hoare_disj_division:
"\<lbrakk> P \<or> Q; P \<Longrightarrow> \<lbrace>R\<rbrace> f \<lbrace>S\<rbrace>; Q \<Longrightarrow> \<lbrace>T\<rbrace> f \<lbrace>S\<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace>\<lambda>s. (P \<longrightarrow> R s) \<and> (Q \<longrightarrow> T s)\<rbrace> f \<lbrace>S\<rbrace>"
Expand Down
78 changes: 78 additions & 0 deletions lib/Monads/nondet/Nondet_VCG.thy
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,15 @@ lemma hoare_vcg_conj_liftE1:
unfolding valid_def validE_R_def validE_def
by (fastforce simp: split_def split: sum.splits)

lemma hoare_vcg_conj_liftE_weaker:
assumes "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>, \<lbrace>E\<rbrace>"
assumes "\<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>, \<lbrace>E\<rbrace>"
shows "\<lbrace>\<lambda>s. P s \<and> P' s\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>, \<lbrace>E\<rbrace>"
apply (rule hoare_pre)
apply (fastforce intro: assms hoare_vcg_conj_liftE1 validE_validE_R hoare_post_impErr)
apply simp
done

lemma hoare_vcg_disj_lift:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>; \<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. P s \<or> P' s\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<or> Q' rv s\<rbrace>"
unfolding valid_def
Expand Down Expand Up @@ -547,6 +556,19 @@ lemma hoare_vcg_imp_lift':
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>\<lambda>rv s. \<not> P rv s\<rbrace>; \<lbrace>Q'\<rbrace> f \<lbrace>Q\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. \<not> P' s \<longrightarrow> Q' s\<rbrace> f \<lbrace>\<lambda>rv s. P rv s \<longrightarrow> Q rv s\<rbrace>"
by (wpsimp wp: hoare_vcg_imp_lift)

lemma hoare_vcg_imp_liftE:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>\<lambda>rv s. \<not> P rv s\<rbrace>, \<lbrace>A\<rbrace>; \<lbrace>Q'\<rbrace> f \<lbrace>Q\<rbrace>, \<lbrace>A\<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace>\<lambda>s. \<not> P' s \<longrightarrow> Q' s\<rbrace> f \<lbrace>\<lambda>rv s. P rv s \<longrightarrow> Q rv s\<rbrace>, \<lbrace>A\<rbrace>"
by (fastforce simp: validE_def valid_def split: sum.splits)

lemma hoare_vcg_imp_lift_R:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>\<lambda>rv s. \<not> P rv s\<rbrace>, -; \<lbrace>Q'\<rbrace> f \<lbrace>Q\<rbrace>, - \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. P' s \<or> Q' s\<rbrace> f \<lbrace>\<lambda>rv s. P rv s \<longrightarrow> Q rv s\<rbrace>, -"
by (auto simp add: valid_def validE_R_def validE_def split_def split: sum.splits)

lemma hoare_vcg_imp_lift_R':
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>\<lambda>rv s. \<not> P rv s\<rbrace>, -; \<lbrace>Q'\<rbrace> f \<lbrace>Q\<rbrace>, - \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. \<not>P' s \<longrightarrow> Q' s\<rbrace> f \<lbrace>\<lambda>rv s. P rv s \<longrightarrow> Q rv s\<rbrace>, -"
by (auto simp add: valid_def validE_R_def validE_def split_def split: sum.splits)

lemma hoare_vcg_imp_conj_lift[wp_comb]:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<longrightarrow> Q' rv s\<rbrace>; \<lbrace>P'\<rbrace> f \<lbrace>\<lambda>rv s. (Q rv s \<longrightarrow> Q'' rv s) \<and> Q''' rv s\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>P and P'\<rbrace> f \<lbrace>\<lambda>rv s. (Q rv s \<longrightarrow> Q' rv s \<and> Q'' rv s) \<and> Q''' rv s\<rbrace>"
Expand All @@ -567,6 +589,10 @@ lemma hoare_vcg_const_imp_lift:
"\<lbrakk> P \<Longrightarrow> \<lbrace>Q\<rbrace> m \<lbrace>R\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. P \<longrightarrow> Q s\<rbrace> m \<lbrace>\<lambda>rv s. P \<longrightarrow> R rv s\<rbrace>"
by (cases P, simp_all add: hoare_vcg_prop)

lemma hoare_vcg_const_imp_lift_E:
"(P \<Longrightarrow> \<lbrace>Q\<rbrace> f -, \<lbrace>R\<rbrace>) \<Longrightarrow> \<lbrace>\<lambda>s. P \<longrightarrow> Q s\<rbrace> f -, \<lbrace>\<lambda>rv s. P \<longrightarrow> R rv s\<rbrace>"
by (fastforce simp: validE_E_def validE_def valid_def split_def split: sum.splits)

lemma hoare_vcg_const_imp_lift_R:
"(P \<Longrightarrow> \<lbrace>Q\<rbrace> m \<lbrace>R\<rbrace>,-) \<Longrightarrow> \<lbrace>\<lambda>s. P \<longrightarrow> Q s\<rbrace> m \<lbrace>\<lambda>rv s. P \<longrightarrow> R rv s\<rbrace>,-"
by (fastforce simp: validE_R_def validE_def valid_def split_def split: sum.splits)
Expand Down Expand Up @@ -662,6 +688,58 @@ lemma hoare_post_comb_imp_conj:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace>; \<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace>; \<And>s. P s \<Longrightarrow> P' s \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>"
by (wpsimp wp: hoare_vcg_conj_lift)

lemma hoare_vcg_if_lift:
"\<lbrace>R\<rbrace> f \<lbrace>\<lambda>rv s. (P \<longrightarrow> X rv s) \<and> (\<not>P \<longrightarrow> Y rv s)\<rbrace> \<Longrightarrow>
\<lbrace>R\<rbrace> f \<lbrace>\<lambda>rv s. if P then X rv s else Y rv s\<rbrace>"

"\<lbrace>R\<rbrace> f \<lbrace>\<lambda>rv s. (P \<longrightarrow> X rv s) \<and> (\<not>P \<longrightarrow> Y rv s)\<rbrace> \<Longrightarrow>
\<lbrace>R\<rbrace> f \<lbrace>\<lambda>rv. if P then X rv else Y rv\<rbrace>"
by (auto simp: valid_def split_def)

lemma hoare_vcg_disj_lift_R:
assumes x: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,-"
assumes y: "\<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>,-"
shows "\<lbrace>\<lambda>s. P s \<or> P' s\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<or> Q' rv s\<rbrace>,-"
using assms
by (fastforce simp: validE_R_def validE_def valid_def split: sum.splits)

lemma hoare_vcg_all_liftE:
"\<lbrakk> \<And>x. \<lbrace>P x\<rbrace> f \<lbrace>Q x\<rbrace>,\<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. \<forall>x. P x s\<rbrace> f \<lbrace>\<lambda>rv s. \<forall>x. Q x rv s\<rbrace>,\<lbrace>E\<rbrace>"
by (fastforce simp: validE_def valid_def split: sum.splits)

lemma hoare_vcg_const_Ball_liftE:
"\<lbrakk> \<And>x. x \<in> S \<Longrightarrow> \<lbrace>P x\<rbrace> f \<lbrace>Q x\<rbrace>,\<lbrace>E\<rbrace>; \<lbrace>\<lambda>s. True\<rbrace> f \<lbrace>\<lambda>r s. True\<rbrace>, \<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. \<forall>x\<in>S. P x s\<rbrace> f \<lbrace>\<lambda>rv s. \<forall>x\<in>S. Q x rv s\<rbrace>,\<lbrace>E\<rbrace>"
by (fastforce simp: validE_def valid_def split: sum.splits)

lemma hoare_vcg_split_lift[wp]:
"\<lbrace>P\<rbrace> f x y \<lbrace>Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> case (x, y) of (a, b) \<Rightarrow> f a b \<lbrace>Q\<rbrace>"
by simp

named_theorems hoare_vcg_op_lift
lemmas [hoare_vcg_op_lift] =
hoare_vcg_const_imp_lift
hoare_vcg_const_imp_lift_E
hoare_vcg_const_imp_lift_R
(* leaving out hoare_vcg_conj_lift*, because that is built into wp *)
hoare_vcg_disj_lift
hoare_vcg_disj_lift_R
hoare_vcg_ex_lift
hoare_vcg_ex_liftE
hoare_vcg_ex_liftE_E
hoare_vcg_all_lift
hoare_vcg_all_liftE
hoare_vcg_all_liftE_E
hoare_vcg_all_lift_R
hoare_vcg_const_Ball_lift
hoare_vcg_const_Ball_lift_R
hoare_vcg_const_Ball_lift_E_E
hoare_vcg_split_lift
hoare_vcg_if_lift
hoare_vcg_imp_lift'
hoare_vcg_imp_liftE
hoare_vcg_imp_lift_R
hoare_vcg_imp_liftE_E


subsection \<open>Weakest Precondition Rules\<close>

Expand Down
9 changes: 9 additions & 0 deletions lib/Monads/reader_option/Reader_Option_ND.thy
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ lemma gets_the_Some:
"gets_the (\<lambda>_. Some x) = return x"
by (simp add: gets_the_def assert_opt_Some)

lemma gets_the_oapply2_comp:
"gets_the (oapply2 y x \<circ> f) = gets_map (swp f y) x"
by (clarsimp simp: gets_map_def gets_the_def o_def gets_def)

lemma gets_obind_bind_eq:
"(gets (f |>> (\<lambda>x. g x))) =
(gets f >>= (\<lambda>x. case x of None \<Rightarrow> return None | Some y \<Rightarrow> gets (g y)))"
by (auto simp: simpler_gets_def bind_def obind_def return_def split: option.splits)

lemma fst_assert_opt:
"fst (assert_opt opt s) = (if opt = None then {} else {(the opt,s)})"
by (clarsimp simp: assert_opt_def fail_def return_def split: option.split)
Expand Down
2 changes: 1 addition & 1 deletion lib/Monads/wp/WPBang.thy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ML \<open>
structure WP_Safe = struct

fun check_has_frees_tac Ps (_ : int) thm = let
val fs = Term.add_frees (Thm.prop_of thm) [] |> filter (member (=) Ps)
val fs = Term.add_frees (Thm.prop_of thm) [] |> filter (member (op =) Ps)
in if null fs then Seq.empty else Seq.single thm end

fun wp_bang wp_safe_rules ctxt = let
Expand Down
7 changes: 7 additions & 0 deletions lib/Word_Lib/Word_Lemmas_Internal.thy
Original file line number Diff line number Diff line change
Expand Up @@ -738,4 +738,11 @@ lemma aligned_mask_le_mask_minus:
by (metis and_mask_less' is_aligned_after_mask is_aligned_neg_mask_eq'
mask_2pm1 mask_sub neg_mask_mono_le word_less_sub_le)

lemma shiftr_anti_mono:
"m \<le> n \<Longrightarrow> w >> n \<le> w >> m" for w :: "'a::len word"
apply transfer
apply (simp add: take_bit_drop_bit)
apply (simp add: drop_bit_eq_div zdiv_mono2)
done

end
2 changes: 1 addition & 1 deletion proof/access-control/RISCV64/ArchArch_AC.thy
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ lemma unmap_page_table_respects:
unmap_page_table asid vaddr pt
\<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
apply (simp add: unmap_page_table_def sfence_def)
apply (wpsimp wp: pt_lookup_from_level_is_subject dmo_mol_respects hoare_vcg_conj_liftE
apply (wpsimp wp: pt_lookup_from_level_is_subject dmo_mol_respects hoare_vcg_conj_liftE_weaker
store_pte_respects pt_lookup_from_level_wrp[where Q="\<lambda>_. integrity aag X st"]
| wp (once) hoare_drop_imps hoare_vcg_E_elim)+
apply (intro conjI; clarsimp)
Expand Down
1 change: 0 additions & 1 deletion proof/infoflow/Syscall_IF.thy
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,6 @@ lemma handle_recv_reads_respects_f:
simp: aag_cap_auth_def cap_auth_conferred_def cap_rights_to_auth_def)[1]
apply (wp reads_respects_f[OF handle_fault_reads_respects,where st=st])
apply (wpsimp wp: get_simple_ko_wp get_cap_wp)+
apply (rule VSpaceEntries_AI.hoare_vcg_all_liftE)
apply (rule_tac Q="\<lambda>r s. silc_inv aag st s \<and> einvs s \<and> pas_refined aag s \<and>
tcb_at rv s \<and> pas_cur_domain aag s \<and> is_subject aag rv \<and>
is_subject aag (cur_thread s) \<and> is_subject aag (fst (fst r))"
Expand Down
Loading