src/HOL/IMP/Abs_Int2.thy
changeset 51390 1dff81cf425b
parent 51389 8a9f0503b1c0
child 51711 df3426139651
equal deleted inserted replaced
51389:8a9f0503b1c0 51390:1dff81cf425b
    28 
    28 
    29 class lattice = semilattice + semilattice_inf + bot
    29 class lattice = semilattice + semilattice_inf + bot
    30 
    30 
    31 locale Val_abs1_gamma =
    31 locale Val_abs1_gamma =
    32   Gamma where \<gamma> = \<gamma> for \<gamma> :: "'av::lattice \<Rightarrow> val set" +
    32   Gamma where \<gamma> = \<gamma> for \<gamma> :: "'av::lattice \<Rightarrow> val set" +
    33 assumes inter_gamma_subset_gamma_meet:
    33 assumes inter_gamma_subset_gamma_inf:
    34   "\<gamma> a1 \<inter> \<gamma> a2 \<subseteq> \<gamma>(a1 \<sqinter> a2)"
    34   "\<gamma> a1 \<inter> \<gamma> a2 \<subseteq> \<gamma>(a1 \<sqinter> a2)"
    35 and gamma_bot[simp]: "\<gamma> \<bottom> = {}"
    35 and gamma_bot[simp]: "\<gamma> \<bottom> = {}"
    36 begin
    36 begin
    37 
    37 
    38 lemma in_gamma_meet: "x : \<gamma> a1 \<Longrightarrow> x : \<gamma> a2 \<Longrightarrow> x : \<gamma>(a1 \<sqinter> a2)"
    38 lemma in_gamma_inf: "x : \<gamma> a1 \<Longrightarrow> x : \<gamma> a2 \<Longrightarrow> x : \<gamma>(a1 \<sqinter> a2)"
    39 by (metis IntI inter_gamma_subset_gamma_meet set_mp)
    39 by (metis IntI inter_gamma_subset_gamma_inf set_mp)
    40 
    40 
    41 lemma gamma_meet[simp]: "\<gamma>(a1 \<sqinter> a2) = \<gamma> a1 \<inter> \<gamma> a2"
    41 lemma gamma_inf[simp]: "\<gamma>(a1 \<sqinter> a2) = \<gamma> a1 \<inter> \<gamma> a2"
    42 by(rule equalityI[OF _ inter_gamma_subset_gamma_meet])
    42 by(rule equalityI[OF _ inter_gamma_subset_gamma_inf])
    43   (metis inf_le1 inf_le2 le_inf_iff mono_gamma)
    43   (metis inf_le1 inf_le2 le_inf_iff mono_gamma)
    44 
    44 
    45 end
    45 end
    46 
    46 
    47 
    47 
   119   moreover hence "s x : \<gamma> (fun S' x)"
   119   moreover hence "s x : \<gamma> (fun S' x)"
   120     using V(1,2) by(simp add: \<gamma>_st_def L_st_def)
   120     using V(1,2) by(simp add: \<gamma>_st_def L_st_def)
   121   moreover have "s x : \<gamma> a" using V by simp
   121   moreover have "s x : \<gamma> a" using V by simp
   122   ultimately show ?case using V(3)
   122   ultimately show ?case using V(3)
   123     by(simp add: Let_def \<gamma>_st_def)
   123     by(simp add: Let_def \<gamma>_st_def)
   124       (metis mono_gamma emptyE in_gamma_meet gamma_bot subset_empty)
   124       (metis mono_gamma emptyE in_gamma_inf gamma_bot subset_empty)
   125 next
   125 next
   126   case (Plus e1 e2) thus ?case
   126   case (Plus e1 e2) thus ?case
   127     using filter_plus'[OF _ aval''_sound[OF Plus.prems(3)] aval''_sound[OF Plus.prems(3)]]
   127     using filter_plus'[OF _ aval''_sound[OF Plus.prems(3)] aval''_sound[OF Plus.prems(3)]]
   128     by (auto simp: afilter_in_L split: prod.split)
   128     by (auto simp: afilter_in_L split: prod.split)
   129 qed
   129 qed
   144   case (Less e1 e2) thus ?case
   144   case (Less e1 e2) thus ?case
   145     by(auto split: prod.split)
   145     by(auto split: prod.split)
   146       (metis (lifting) afilter_in_L afilter_sound aval''_sound filter_less')
   146       (metis (lifting) afilter_in_L afilter_sound aval''_sound filter_less')
   147 qed
   147 qed
   148 
   148 
   149 (* Interpretation would be nicer but is impossible *)
   149 definition "step' = Step
   150 definition "step' = Step.Step
       
   151   (\<lambda>x e S. case S of None \<Rightarrow> None | Some S \<Rightarrow> Some(update S x (aval' e S)))
   150   (\<lambda>x e S. case S of None \<Rightarrow> None | Some S \<Rightarrow> Some(update S x (aval' e S)))
   152   (\<lambda>b S. bfilter b True S)"
   151   (\<lambda>b S. bfilter b True S)"
   153 
   152 
   154 lemma [code,simp]: "step' S (SKIP {P}) = (SKIP {S})"
       
   155 by(simp add: step'_def Step.Step.simps)
       
   156 lemma [code,simp]: "step' S (x ::= e {P}) =
       
   157   x ::= e {case S of None \<Rightarrow> None | Some S \<Rightarrow> Some(update S x (aval' e S))}"
       
   158 by(simp add: step'_def Step.Step.simps)
       
   159 lemma [code,simp]: "step' S (C1; C2) = step' S C1; step' (post C1) C2"
       
   160 by(simp add: step'_def Step.Step.simps)
       
   161 lemma [code,simp]: "step' S (IF b THEN {P1} C1 ELSE {P2} C2 {Q}) =
       
   162   (let P1' = bfilter b True S; C1' = step' P1 C1;
       
   163        P2' = bfilter b False S; C2' = step' P2 C2
       
   164    in IF b THEN {P1'} C1' ELSE {P2'} C2' {post C1 \<squnion> post C2})"
       
   165 by(simp add: step'_def Step.Step.simps)
       
   166 lemma [code,simp]: "step' S ({I} WHILE b DO {p} C {Q}) =
       
   167    {S \<squnion> post C}
       
   168    WHILE b DO {bfilter b True I} step' p C
       
   169    {bfilter b False I}"
       
   170 by(simp add: step'_def Step.Step.simps)
       
   171 
       
   172 definition AI :: "com \<Rightarrow> 'av st option acom option" where
   153 definition AI :: "com \<Rightarrow> 'av st option acom option" where
   173 "AI c = pfp (step' \<top>\<^bsub>vars c\<^esub>) (bot c)"
   154 "AI c = pfp (step' \<top>\<^bsub>vars c\<^esub>) (bot c)"
   174 
   155 
   175 lemma strip_step'[simp]: "strip(step' S c) = strip c"
   156 lemma strip_step'[simp]: "strip(step' S c) = strip c"
   176 by(induct c arbitrary: S) (simp_all add: Let_def)
   157 by(simp add: step'_def)
   177 
   158 
   178 
   159 
   179 subsubsection "Soundness"
   160 subsubsection "Soundness"
   180 
   161 
   181 lemma in_gamma_update:
       
   182   "\<lbrakk> s : \<gamma>\<^isub>s S; i : \<gamma> a \<rbrakk> \<Longrightarrow> s(x := i) : \<gamma>\<^isub>s(update S x a)"
       
   183 by(simp add: \<gamma>_st_def)
       
   184 
       
   185 lemma step_step': "C \<in> L X \<Longrightarrow> S \<in> L X \<Longrightarrow> step (\<gamma>\<^isub>o S) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (step' S C)"
   162 lemma step_step': "C \<in> L X \<Longrightarrow> S \<in> L X \<Longrightarrow> step (\<gamma>\<^isub>o S) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (step' S C)"
   186 proof(induction C arbitrary: S)
   163 unfolding step_def step'_def
   187   case SKIP thus ?case by auto
   164 by(rule gamma_Step_subcomm)
   188 next
   165   (auto simp: L_st_def intro!: aval'_sound bfilter_sound in_gamma_update split: option.splits)
   189   case Assign thus ?case
       
   190     by (fastforce simp: L_st_def intro: aval'_sound in_gamma_update split: option.splits)
       
   191 next
       
   192   case Seq thus ?case by auto
       
   193 next
       
   194   case (If b _ C1 _ C2)
       
   195   hence 0: "post C1 \<le> post C1 \<squnion> post C2 \<and> post C2 \<le> post C1 \<squnion> post C2"
       
   196     by(simp, metis post_in_L sup_ge1 sup_ge2)
       
   197   have "vars b \<subseteq> X" using If.prems by simp
       
   198   note vars = `S \<in> L X` `vars b \<subseteq> X`
       
   199   show ?case using If 0
       
   200     by (auto simp: mono_gamma_o bfilter_sound[OF vars] bfilter_in_L[OF vars])
       
   201 next
       
   202   case (While I b)
       
   203   hence vars: "I \<in> L X" "vars b \<subseteq> X" by simp_all
       
   204   thus ?case using While
       
   205     by (auto simp: mono_gamma_o bfilter_sound[OF vars] bfilter_in_L[OF vars])
       
   206 qed
       
   207 
   166 
   208 lemma step'_in_L[simp]: "\<lbrakk> C \<in> L X; S \<in> L X \<rbrakk> \<Longrightarrow> step' S C \<in> L X"
   167 lemma step'_in_L[simp]: "\<lbrakk> C \<in> L X; S \<in> L X \<rbrakk> \<Longrightarrow> step' S C \<in> L X"
   209 proof(induction C arbitrary: S)
   168 unfolding step'_def
   210   case Assign thus ?case by(auto simp add: L_option_def L_st_def split: option.splits)
   169 by(rule Step_in_L)(auto simp: bfilter_in_L L_st_def step'_def split: option.splits)
   211 qed (auto simp add: bfilter_in_L)
       
   212 
   170 
   213 lemma AI_sound: "AI c = Some C \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c C"
   171 lemma AI_sound: "AI c = Some C \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c C"
   214 proof(simp add: CS_def AI_def)
   172 proof(simp add: CS_def AI_def)
   215   assume 1: "pfp (step' (Top(vars c))) (bot c) = Some C"
   173   assume 1: "pfp (step' (Top(vars c))) (bot c) = Some C"
   216   have "C \<in> L(vars c)"
   174   have "C \<in> L(vars c)"
   256 by (simp add: mono_aval')
   214 by (simp add: mono_aval')
   257 
   215 
   258 lemma mono_afilter: "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> vars e \<subseteq> X \<Longrightarrow>
   216 lemma mono_afilter: "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> vars e \<subseteq> X \<Longrightarrow>
   259   r1 \<le> r2 \<Longrightarrow> S1 \<le> S2 \<Longrightarrow> afilter e r1 S1 \<le> afilter e r2 S2"
   217   r1 \<le> r2 \<Longrightarrow> S1 \<le> S2 \<Longrightarrow> afilter e r1 S1 \<le> afilter e r2 S2"
   260 apply(induction e arbitrary: r1 r2 S1 S2)
   218 apply(induction e arbitrary: r1 r2 S1 S2)
   261 apply(auto simp: test_num' Let_def inf_mono split: option.splits prod.splits)
   219    apply(auto simp: test_num' Let_def inf_mono split: option.splits prod.splits)
   262 apply (metis mono_gamma subsetD)
   220    apply (metis mono_gamma subsetD)
   263 apply (metis inf_mono le_bot mono_fun_L)
   221   apply (metis inf_mono le_bot mono_fun_L)
   264 apply (metis inf_mono mono_fun_L mono_update)
   222  apply (metis inf_mono mono_fun_L mono_update)
   265 apply(metis mono_aval'' mono_filter_plus'[simplified less_eq_prod_def] fst_conv snd_conv afilter_in_L)
   223 apply(metis mono_aval'' mono_filter_plus'[simplified less_eq_prod_def] fst_conv snd_conv afilter_in_L)
   266 done
   224 done
   267 
   225 
   268 lemma mono_bfilter: "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> vars b \<subseteq> X \<Longrightarrow>
   226 lemma mono_bfilter: "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> vars b \<subseteq> X \<Longrightarrow>
   269   S1 \<le> S2 \<Longrightarrow> bfilter b bv S1 \<le> bfilter b bv S2"
   227   S1 \<le> S2 \<Longrightarrow> bfilter b bv S1 \<le> bfilter b bv S2"
   270 apply(induction b arbitrary: bv S1 S2)
   228 apply(induction b arbitrary: bv S1 S2)
   271 apply(simp)
   229    apply(simp)
   272 apply(simp)
   230   apply(simp)
   273 apply simp
   231  apply simp
   274 apply(metis sup_least order_trans[OF _ sup_ge1] order_trans[OF _ sup_ge2] bfilter_in_L)
   232  apply(metis sup_least order_trans[OF _ sup_ge1] order_trans[OF _ sup_ge2] bfilter_in_L)
   275 apply (simp split: prod.splits)
   233 apply (simp split: prod.splits)
   276 apply(metis mono_aval'' mono_afilter mono_filter_less'[simplified less_eq_prod_def] fst_conv snd_conv afilter_in_L)
   234 apply(metis mono_aval'' mono_afilter mono_filter_less'[simplified less_eq_prod_def] fst_conv snd_conv afilter_in_L)
   277 done
   235 done
   278 
   236 
   279 theorem mono_step': "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> C1 \<in> L X \<Longrightarrow> C2 \<in> L X \<Longrightarrow>
   237 theorem mono_step': "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> C1 \<in> L X \<Longrightarrow> C2 \<in> L X \<Longrightarrow>
   280   S1 \<le> S2 \<Longrightarrow> C1 \<le> C2 \<Longrightarrow> step' S1 C1 \<le> step' S2 C2"
   238   S1 \<le> S2 \<Longrightarrow> C1 \<le> C2 \<Longrightarrow> step' S1 C1 \<le> step' S2 C2"
   281 apply(induction C1 C2 arbitrary: S1 S2 rule: less_eq_acom.induct)
   239 unfolding step'_def
   282 apply (auto simp: Let_def mono_bfilter mono_aval' mono_post
   240 by(rule mono2_Step) (auto simp: mono_aval' mono_bfilter split: option.split)
   283   le_sup_disj le_sup_disj[OF  post_in_L post_in_L] bfilter_in_L
       
   284             split: option.split)
       
   285 done
       
   286 
   241 
   287 lemma mono_step'_top: "C1 \<in> L X \<Longrightarrow> C2 \<in> L X \<Longrightarrow>
   242 lemma mono_step'_top: "C1 \<in> L X \<Longrightarrow> C2 \<in> L X \<Longrightarrow>
   288   C1 \<le> C2 \<Longrightarrow> step' (Top X) C1 \<le> step' (Top X) C2"
   243   C1 \<le> C2 \<Longrightarrow> step' (Top X) C1 \<le> step' (Top X) C2"
   289 by (metis Top_in_L mono_step' order_refl)
   244 by (metis Top_in_L mono_step' order_refl)
   290 
   245