src/HOL/IMP/Abs_Int0.thy
author bulwahn
Fri Oct 21 11:17:14 2011 +0200 (2011-10-21)
changeset 45231 d85a2fdc586c
parent 45127 d2eb07a1e01b
child 45623 f682f3f7b726
permissions -rw-r--r--
replacing code_inline by code_unfold, removing obsolete code_unfold, code_inline del now that the ancient code generator is removed
     1 (* Author: Tobias Nipkow *)
     2 
     3 theory Abs_Int0
     4 imports Abs_State
     5 begin
     6 
     7 subsection "Computable Abstract Interpretation"
     8 
     9 text{* Abstract interpretation over type @{text astate} instead of
    10 functions. *}
    11 
    12 locale Abs_Int = Val_abs
    13 begin
    14 
    15 fun aval' :: "aexp \<Rightarrow> 'a st \<Rightarrow> 'a" where
    16 "aval' (N n) _ = num' n" |
    17 "aval' (V x) S = lookup S x" |
    18 "aval' (Plus a1 a2) S = plus' (aval' a1 S) (aval' a2 S)"
    19 
    20 fun step :: "'a st up \<Rightarrow> 'a st up acom \<Rightarrow> 'a st up acom" where
    21 "step S (SKIP {P}) = (SKIP {S})" |
    22 "step S (x ::= e {P}) =
    23   x ::= e {case S of Bot \<Rightarrow> Bot | Up S \<Rightarrow> Up(update S x (aval' e S))}" |
    24 "step S (c1; c2) = step S c1; step (post c1) c2" |
    25 "step S (IF b THEN c1 ELSE c2 {P}) =
    26   (let c1' = step S c1; c2' = step S c2
    27    in IF b THEN c1' ELSE c2' {post c1 \<squnion> post c2})" |
    28 "step S ({Inv} WHILE b DO c {P}) =
    29    {S \<squnion> post c} WHILE b DO step Inv c {Inv}"
    30 
    31 definition AI :: "com \<Rightarrow> 'a st up acom option" where
    32 "AI = lpfp\<^isub>c (step \<top>)"
    33 
    34 
    35 lemma strip_step[simp]: "strip(step S c) = strip c"
    36 by(induct c arbitrary: S) (simp_all add: Let_def)
    37 
    38 
    39 text{* Soundness: *}
    40 
    41 lemma aval'_sound: "s <:f S \<Longrightarrow> aval a s <: aval' a S"
    42 by (induct a) (auto simp: rep_num' rep_plus' rep_st_def lookup_def)
    43 
    44 lemma in_rep_update: "\<lbrakk> s <:f S; i <: a \<rbrakk> \<Longrightarrow> s(x := i) <:f update S x a"
    45 by(simp add: rep_st_def lookup_update)
    46 
    47 lemma step_sound:
    48   "step S c \<sqsubseteq> c \<Longrightarrow> (strip c,s) \<Rightarrow> t \<Longrightarrow> s <:up S \<Longrightarrow> t <:up post c"
    49 proof(induction c arbitrary: S s t)
    50   case SKIP thus ?case
    51     by simp (metis skipE up_fun_in_rep_le)
    52 next
    53   case Assign thus ?case
    54     apply (auto simp del: fun_upd_apply simp: split: up.splits)
    55     by (metis aval'_sound fun_in_rep_le in_rep_update)
    56 next
    57   case Semi thus ?case by simp blast
    58 next
    59   case (If b c1 c2 S0) thus ?case
    60     apply(auto simp: Let_def)
    61     apply (metis up_fun_in_rep_le)+
    62     done
    63 next
    64   case (While Inv b c P)
    65   from While.prems have inv: "step Inv c \<sqsubseteq> c"
    66     and "post c \<sqsubseteq> Inv" and "S \<sqsubseteq> Inv" and "Inv \<sqsubseteq> P" by(auto simp: Let_def)
    67   { fix s t have "(WHILE b DO strip c,s) \<Rightarrow> t \<Longrightarrow> s <:up Inv \<Longrightarrow> t <:up Inv"
    68     proof(induction "WHILE b DO strip c" s t rule: big_step_induct)
    69       case WhileFalse thus ?case by simp
    70     next
    71       case (WhileTrue s1 s2 s3)
    72       from WhileTrue.hyps(5)[OF up_fun_in_rep_le[OF While.IH[OF inv `(strip c, s1) \<Rightarrow> s2` `s1 <:up Inv`] `post c \<sqsubseteq> Inv`]]
    73       show ?case .
    74     qed
    75   }
    76   thus ?case using While.prems(2)
    77     by simp (metis `s <:up S` `S \<sqsubseteq> Inv` `Inv \<sqsubseteq> P` up_fun_in_rep_le)
    78 qed
    79 
    80 lemma AI_sound: "\<lbrakk> AI c = Some c';  (c,s) \<Rightarrow> t \<rbrakk> \<Longrightarrow> t <:up post c'"
    81 by (metis AI_def in_rep_Top_up lpfpc_pfp step_sound strip_lpfpc strip_step)
    82 
    83 end
    84 
    85 
    86 subsubsection "Monotonicity"
    87 
    88 locale Abs_Int_mono = Abs_Int +
    89 assumes mono_plus': "a1 \<sqsubseteq> b1 \<Longrightarrow> a2 \<sqsubseteq> b2 \<Longrightarrow> plus' a1 a2 \<sqsubseteq> plus' b1 b2"
    90 begin
    91 
    92 lemma mono_aval': "S \<sqsubseteq> S' \<Longrightarrow> aval' e S \<sqsubseteq> aval' e S'"
    93 by(induction e) (auto simp: le_st_def lookup_def mono_plus')
    94 
    95 lemma mono_update: "a \<sqsubseteq> a' \<Longrightarrow> S \<sqsubseteq> S' \<Longrightarrow> update S x a \<sqsubseteq> update S' x a'"
    96 by(auto simp add: le_st_def lookup_def update_def)
    97 
    98 lemma step_mono: "S \<sqsubseteq> S' \<Longrightarrow> step S c \<sqsubseteq> step S' c"
    99 apply(induction c arbitrary: S S')
   100 apply (auto simp: Let_def mono_update mono_aval' le_join_disj split: up.split)
   101 done
   102 
   103 end
   104 
   105 end