src/HOL/IMP/Abs_Int3.thy
changeset 51036 e7b54119c436
parent 50995 3371f5ee4ace
child 51245 311fe56541ea
equal deleted inserted replaced
51035:36aee533d7a7 51036:e7b54119c436
   356 locale Abs_Int2 = Abs_Int1_mono
   356 locale Abs_Int2 = Abs_Int1_mono
   357 where \<gamma>=\<gamma> for \<gamma> :: "'av::{WN,lattice} \<Rightarrow> val set"
   357 where \<gamma>=\<gamma> for \<gamma> :: "'av::{WN,lattice} \<Rightarrow> val set"
   358 begin
   358 begin
   359 
   359 
   360 definition AI_wn :: "com \<Rightarrow> 'av st option acom option" where
   360 definition AI_wn :: "com \<Rightarrow> 'av st option acom option" where
   361 "AI_wn c = pfp_wn (step' (top c)) (bot c)"
   361 "AI_wn c = pfp_wn (step' (top(vars c))) (bot c)"
   362 
   362 
   363 lemma AI_wn_sound: "AI_wn c = Some C \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c C"
   363 lemma AI_wn_sound: "AI_wn c = Some C \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c C"
   364 proof(simp add: CS_def AI_wn_def)
   364 proof(simp add: CS_def AI_wn_def)
   365   assume 1: "pfp_wn (step' (top c)) (bot c) = Some C"
   365   assume 1: "pfp_wn (step' (top(vars c))) (bot c) = Some C"
   366   have 2: "(strip C = c & C \<in> L(vars c)) \<and> step' \<top>\<^bsub>c\<^esub> C \<sqsubseteq> C"
   366   have 2: "(strip C = c & C \<in> L(vars c)) \<and> step' \<top>\<^bsub>vars c\<^esub> C \<sqsubseteq> C"
   367     by(rule pfp_wn_pfp[where x="bot c"])
   367     by(rule pfp_wn_pfp[where x="bot c"])
   368       (simp_all add: 1 mono_step'_top widen_c_in_L narrow_c_in_L)
   368       (simp_all add: 1 mono_step'_top widen_c_in_L narrow_c_in_L)
   369   have pfp: "step (\<gamma>\<^isub>o(top c)) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c C"
   369   have pfp: "step (\<gamma>\<^isub>o(top(vars c))) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c C"
   370   proof(rule order_trans)
   370   proof(rule order_trans)
   371     show "step (\<gamma>\<^isub>o (top c)) (\<gamma>\<^isub>c C) \<le>  \<gamma>\<^isub>c (step' (top c) C)"
   371     show "step (\<gamma>\<^isub>o (top(vars c))) (\<gamma>\<^isub>c C) \<le>  \<gamma>\<^isub>c (step' (top(vars c)) C)"
   372       by(rule step_step'[OF conjunct2[OF conjunct1[OF 2]] top_in_L])
   372       by(rule step_step'[OF conjunct2[OF conjunct1[OF 2]] top_in_L])
   373     show "... \<le> \<gamma>\<^isub>c C"
   373     show "... \<le> \<gamma>\<^isub>c C"
   374       by(rule mono_gamma_c[OF conjunct2[OF 2]])
   374       by(rule mono_gamma_c[OF conjunct2[OF 2]])
   375   qed
   375   qed
   376   have 3: "strip (\<gamma>\<^isub>c C) = c" by(simp add: strip_pfp_wn[OF _ 1])
   376   have 3: "strip (\<gamma>\<^isub>c C) = c" by(simp add: strip_pfp_wn[OF _ 1])
   377   have "lfp c (step (\<gamma>\<^isub>o (top c))) \<le> \<gamma>\<^isub>c C"
   377   have "lfp c (step (\<gamma>\<^isub>o (top(vars c)))) \<le> \<gamma>\<^isub>c C"
   378     by(rule lfp_lowerbound[simplified,where f="step (\<gamma>\<^isub>o(top c))", OF 3 pfp])
   378     by(rule lfp_lowerbound[simplified,where f="step (\<gamma>\<^isub>o(top(vars c)))", OF 3 pfp])
   379   thus "lfp c (step UNIV) \<le> \<gamma>\<^isub>c C" by simp
   379   thus "lfp c (step UNIV) \<le> \<gamma>\<^isub>c C" by simp
   380 qed
   380 qed
   381 
   381 
   382 end
   382 end
   383 
   383 
   394 (* Trick to make the code generator happy. *)
   394 (* Trick to make the code generator happy. *)
   395 lemma [code]: "equal_class.equal (x::'a st) y = equal_class.equal x y"
   395 lemma [code]: "equal_class.equal (x::'a st) y = equal_class.equal x y"
   396 by(rule refl)
   396 by(rule refl)
   397 
   397 
   398 definition "step_up_ivl n =
   398 definition "step_up_ivl n =
   399   ((\<lambda>C. C \<nabla> step_ivl (top(strip C)) C)^^n)"
   399   ((\<lambda>C. C \<nabla> step_ivl (top(vars(strip C))) C)^^n)"
   400 definition "step_down_ivl n =
   400 definition "step_down_ivl n =
   401   ((\<lambda>C. C \<triangle> step_ivl (top (strip C)) C)^^n)"
   401   ((\<lambda>C. C \<triangle> step_ivl (top(vars(strip C))) C)^^n)"
   402 
   402 
   403 text{* For @{const test3_ivl}, @{const AI_ivl} needed as many iterations as
   403 text{* For @{const test3_ivl}, @{const AI_ivl} needed as many iterations as
   404 the loop took to execute. In contrast, @{const AI_ivl'} converges in a
   404 the loop took to execute. In contrast, @{const AI_ivl'} converges in a
   405 constant number of steps: *}
   405 constant number of steps: *}
   406 
   406 
   414 value "show_acom (step_up_ivl 8 (bot test3_ivl))"
   414 value "show_acom (step_up_ivl 8 (bot test3_ivl))"
   415 value "show_acom (step_down_ivl 1 (step_up_ivl 8 (bot test3_ivl)))"
   415 value "show_acom (step_down_ivl 1 (step_up_ivl 8 (bot test3_ivl)))"
   416 value "show_acom (step_down_ivl 2 (step_up_ivl 8 (bot test3_ivl)))"
   416 value "show_acom (step_down_ivl 2 (step_up_ivl 8 (bot test3_ivl)))"
   417 value "show_acom (step_down_ivl 3 (step_up_ivl 8 (bot test3_ivl)))"
   417 value "show_acom (step_down_ivl 3 (step_up_ivl 8 (bot test3_ivl)))"
   418 value "show_acom (step_down_ivl 4 (step_up_ivl 8 (bot test3_ivl)))"
   418 value "show_acom (step_down_ivl 4 (step_up_ivl 8 (bot test3_ivl)))"
   419 value "show_acom (the(AI_ivl' test3_ivl))"
   419 value "show_acom_opt (AI_ivl' test3_ivl)"
   420 
   420 
   421 
   421 
   422 text{* Now all the analyses terminate: *}
   422 text{* Now all the analyses terminate: *}
   423 
   423 
   424 value "show_acom (the(AI_ivl' test4_ivl))"
   424 value "show_acom_opt (AI_ivl' test4_ivl)"
   425 value "show_acom (the(AI_ivl' test5_ivl))"
   425 value "show_acom_opt (AI_ivl' test5_ivl)"
   426 value "show_acom (the(AI_ivl' test6_ivl))"
   426 value "show_acom_opt (AI_ivl' test6_ivl)"
   427 
   427 
   428 
   428 
   429 subsubsection "Generic Termination Proof"
   429 subsubsection "Generic Termination Proof"
   430 
   430 
   431 locale Measure_WN = Measure1 where m=m for m :: "'av::WN \<Rightarrow> nat" +
   431 locale Measure_WN = Measure1 where m=m for m :: "'av::WN \<Rightarrow> nat" +
   627   -- "note that the first assms is unnecessary for intervals"
   627   -- "note that the first assms is unnecessary for intervals"
   628 qed
   628 qed
   629 
   629 
   630 
   630 
   631 lemma iter_winden_step_ivl_termination:
   631 lemma iter_winden_step_ivl_termination:
   632   "\<exists>C. iter_widen (step_ivl (top c)) (bot c) = Some C"
   632   "\<exists>C. iter_widen (step_ivl (top(vars c))) (bot c) = Some C"
   633 apply(rule iter_widen_termination[where m = "m_c" and P = "%C. C \<in> Lc c"])
   633 apply(rule iter_widen_termination[where m = "m_c" and P = "%C. C \<in> Lc c"])
   634 apply (simp_all add: step'_in_Lc m_c_widen)
   634 apply (simp_all add: step'_in_Lc m_c_widen)
   635 done
   635 done
   636 
   636 
   637 lemma iter_narrow_step_ivl_termination:
   637 lemma iter_narrow_step_ivl_termination:
   638   "C0 \<in> Lc c \<Longrightarrow> step_ivl (top c) C0 \<sqsubseteq> C0 \<Longrightarrow>
   638   "C0 \<in> Lc c \<Longrightarrow> step_ivl (top(vars c)) C0 \<sqsubseteq> C0 \<Longrightarrow>
   639   \<exists>C. iter_narrow (step_ivl (top c)) C0 = Some C"
   639   \<exists>C. iter_narrow (step_ivl (top(vars c))) C0 = Some C"
   640 apply(rule iter_narrow_termination[where n = "n_c" and P = "%C. C \<in> Lc c"])
   640 apply(rule iter_narrow_termination[where n = "n_c" and P = "%C. C \<in> Lc c"])
   641 apply (simp add: step'_in_Lc)
   641 apply (simp add: step'_in_Lc)
   642 apply (simp)
   642 apply (simp)
   643 apply(rule mono_step'_top)
   643 apply(rule mono_step'_top)
   644 apply(simp add: Lc_acom_def L_acom_def)
   644 apply(simp add: Lc_acom_def L_acom_def)
   652 theorem AI_ivl'_termination:
   652 theorem AI_ivl'_termination:
   653   "\<exists>C. AI_ivl' c = Some C"
   653   "\<exists>C. AI_ivl' c = Some C"
   654 apply(auto simp: AI_wn_def pfp_wn_def iter_winden_step_ivl_termination
   654 apply(auto simp: AI_wn_def pfp_wn_def iter_winden_step_ivl_termination
   655            split: option.split)
   655            split: option.split)
   656 apply(rule iter_narrow_step_ivl_termination)
   656 apply(rule iter_narrow_step_ivl_termination)
   657 apply(blast intro: iter_widen_inv[where f = "step' \<top>\<^bsub>c\<^esub>" and P = "%C. C \<in> Lc c"] bot_in_Lc Lc_widen step'_in_Lc[where S = "\<top>\<^bsub>c\<^esub>" and c=c, simplified])
   657 apply(blast intro: iter_widen_inv[where f = "step' \<top>\<^bsub>vars c\<^esub>" and P = "%C. C \<in> Lc c"] bot_in_Lc Lc_widen step'_in_Lc[where S = "\<top>\<^bsub>vars c\<^esub>" and c=c, simplified])
   658 apply(erule iter_widen_pfp)
   658 apply(erule iter_widen_pfp)
   659 done
   659 done
   660 
   660 
   661 (*unused_thms Abs_Int_init -*)
   661 (*unused_thms Abs_Int_init -*)
   662 
   662