src/HOL/IMP/AbsInt0_fun.thy
author nipkow
Fri, 02 Sep 2011 19:25:18 +0200
changeset 44656 22bbd0d1b943
child 44890 22f665a2e91c
permissions -rw-r--r--
Added Abstract Interpretation theories
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     1
(* Author: Tobias Nipkow *)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     2
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     3
header "Abstract Interpretation"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     4
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     5
theory AbsInt0_fun
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     6
imports "~~/src/HOL/ex/Interpretation_with_Defs" Big_Step
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     7
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     8
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     9
subsection "Orderings"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    10
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    11
class preord =
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    12
fixes le :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<sqsubseteq>" 50)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    13
assumes le_refl[simp]: "x \<sqsubseteq> x"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    14
and le_trans: "x \<sqsubseteq> y \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> z"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    15
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    16
text{* Note: no antisymmetry. Allows implementations where some abstract
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    17
element is implemented by two different values @{prop "x \<noteq> y"}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    18
such that @{prop"x \<sqsubseteq> y"} and @{prop"y \<sqsubseteq> x"}. Antisymmetry is not
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    19
needed because we never compare elements for equality but only for @{text"\<sqsubseteq>"}.
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    20
*}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    21
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    22
class SL_top = preord +
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    23
fixes join :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    24
fixes Top :: "'a"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    25
assumes join_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    26
and join_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    27
and join_least: "x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> x \<squnion> y \<sqsubseteq> z"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    28
and top[simp]: "x \<sqsubseteq> Top"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    29
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    30
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    31
lemma join_le_iff[simp]: "x \<squnion> y \<sqsubseteq> z \<longleftrightarrow> x \<sqsubseteq> z \<and> y \<sqsubseteq> z"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    32
by (metis join_ge1 join_ge2 join_least le_trans)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    33
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    34
fun bpfp where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    35
"bpfp f 0 _ = Top" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    36
"bpfp f (Suc n) x = (if f x \<sqsubseteq> x then x else bpfp f n (f x))"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    37
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    38
definition "pfp f = bpfp f 3"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    39
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    40
lemma postfixedpoint: "f(bpfp f n x) \<sqsubseteq> bpfp f n x"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    41
apply (induct n arbitrary: x)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    42
 apply (simp)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    43
apply (simp)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    44
done
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    45
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    46
lemma bpfp_funpow: "bpfp f n x \<noteq> Top \<Longrightarrow> EX k. bpfp f n x = (f^^k) x"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    47
apply(induct n arbitrary: x)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    48
apply simp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    49
apply simp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    50
apply (auto)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    51
apply(rule_tac x=0 in exI)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    52
apply simp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    53
by (metis funpow.simps(2) funpow_swap1 o_apply)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    54
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    55
lemma pfp_funpow: "pfp f x \<noteq> Top \<Longrightarrow> EX k. pfp f x = (f^^k) x"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    56
by(simp add: pfp_def bpfp_funpow)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    57
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    58
abbreviation (input) lift (infix "\<up>" 65) where "f\<up>x0 == (%x. x0 \<squnion> f x)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    59
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    60
definition "pfp_above f x0 = pfp (f\<up>x0) x0"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    61
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    62
lemma pfp_above_pfp:
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    63
shows "f(pfp_above f x0) \<sqsubseteq> pfp_above f x0" and "x0 \<sqsubseteq> pfp_above f x0"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    64
using postfixedpoint[of "lift f x0"]
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    65
by(auto simp add: pfp_above_def pfp_def)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    66
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    67
lemma least_pfp:
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    68
assumes mono: "!!x y. x \<sqsubseteq> y \<Longrightarrow> f x \<sqsubseteq> f y" and "pfp_above f x0 \<noteq> Top"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    69
and "f p \<sqsubseteq> p" and "x0 \<sqsubseteq> p" shows "pfp_above f x0 \<sqsubseteq> p"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    70
proof-
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    71
  let ?F = "lift f x0"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    72
  obtain k where "pfp_above f x0 = (?F^^k) x0"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    73
    using pfp_funpow `pfp_above f x0 \<noteq> Top`
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    74
    by(fastsimp simp add: pfp_above_def)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    75
  moreover
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    76
  { fix n have "(?F^^n) x0 \<sqsubseteq> p"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    77
    proof(induct n)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    78
      case 0 show ?case by(simp add: `x0 \<sqsubseteq> p`)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    79
    next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    80
      case (Suc n) thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    81
        by (simp add: `x0 \<sqsubseteq> p`)(metis Suc assms(3) le_trans mono)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    82
    qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    83
  } ultimately show ?thesis by simp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    84
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    85
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    86
lemma chain: assumes "!!x y. x \<sqsubseteq> y \<Longrightarrow> f x \<sqsubseteq> f y"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    87
shows "((f\<up>x0)^^i) x0 \<sqsubseteq> ((f\<up>x0)^^(i+1)) x0"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    88
apply(induct i)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    89
 apply simp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    90
apply simp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    91
by (metis assms join_ge2 le_trans)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    92
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    93
lemma pfp_almost_fp:
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    94
assumes mono: "!!x y. x \<sqsubseteq> y \<Longrightarrow> f x \<sqsubseteq> f y" and "pfp_above f x0 \<noteq> Top"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    95
shows "pfp_above f x0 \<sqsubseteq> x0 \<squnion> f(pfp_above f x0)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    96
proof-
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    97
  let ?p = "pfp_above f x0"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    98
  obtain k where 1: "?p = ((f\<up>x0)^^k) x0"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    99
    using pfp_funpow `?p \<noteq> Top`
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   100
    by(fastsimp simp add: pfp_above_def)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   101
  thus ?thesis using chain mono by simp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   102
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   103
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   104
end
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   105
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   106
text{* The interface of abstract values: *}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   107
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   108
locale Rep =
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   109
fixes rep :: "'a::SL_top \<Rightarrow> 'b set"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   110
assumes le_rep: "a \<sqsubseteq> b \<Longrightarrow> rep a \<subseteq> rep b"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   111
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   112
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   113
abbreviation in_rep (infix "<:" 50) where "x <: a == x : rep a"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   114
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   115
lemma in_rep_join: "x <: a1 \<or> x <: a2 \<Longrightarrow> x <: a1 \<squnion> a2"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   116
by (metis SL_top_class.join_ge1 SL_top_class.join_ge2 le_rep subsetD)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   117
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   118
end
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   119
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   120
locale Val_abs = Rep rep
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   121
  for rep :: "'a::SL_top \<Rightarrow> val set" +
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   122
fixes num' :: "val \<Rightarrow> 'a"  ("num\<^isup>#")
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   123
and plus' :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  ("plus\<^isup>#")
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   124
assumes rep_num': "rep(num' n) = {n}"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   125
and rep_plus': "n1 <: a1 \<Longrightarrow> n2 <: a2 \<Longrightarrow> n1+n2 <: plus' a1 a2"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   126
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   127
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   128
instantiation "fun" :: (type, SL_top) SL_top
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   129
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   130
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   131
definition "f \<sqsubseteq> g = (ALL x. f x \<sqsubseteq> g x)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   132
definition "f \<squnion> g = (\<lambda>x. f x \<squnion> g x)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   133
definition "Top = (\<lambda>x. Top)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   134
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   135
lemma join_apply[simp]:
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   136
  "(f \<squnion> g) x = f x \<squnion> g x"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   137
by (simp add: join_fun_def)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   138
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   139
instance
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   140
proof
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   141
  case goal2 thus ?case by (metis le_fun_def preord_class.le_trans)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   142
qed (simp_all add: le_fun_def Top_fun_def)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   143
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   144
end
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   145
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   146
subsection "Abstract Interpretation Abstractly"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   147
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   148
text{* Abstract interpretation over abstract values.
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   149
Abstract states are simply functions. *}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   150
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   151
locale Abs_Int_Fun = Val_abs
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   152
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   153
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   154
fun aval' :: "aexp \<Rightarrow> (name \<Rightarrow> 'a) \<Rightarrow> 'a" ("aval\<^isup>#") where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   155
"aval' (N n) _ = num' n" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   156
"aval' (V x) S = S x" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   157
"aval' (Plus a1 a2) S = plus' (aval' a1 S) (aval' a2 S)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   158
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   159
abbreviation fun_in_rep (infix "<:" 50) where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   160
"f <: F == ALL x. f x <: F x"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   161
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   162
lemma fun_in_rep_le: "(s::state) <: S \<Longrightarrow> S \<sqsubseteq> T \<Longrightarrow> s <: T"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   163
by (metis le_fun_def le_rep subsetD)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   164
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   165
lemma aval'_sound: "s <: S \<Longrightarrow> aval a s <: aval' a S"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   166
by (induct a) (auto simp: rep_num' rep_plus')
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   167
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   168
fun AI :: "com \<Rightarrow> (name \<Rightarrow> 'a) \<Rightarrow> (name \<Rightarrow> 'a)" where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   169
"AI SKIP S = S" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   170
"AI (x ::= a) S = S(x := aval' a S)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   171
"AI (c1;c2) S = AI c2 (AI c1 S)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   172
"AI (IF b THEN c1 ELSE c2) S = (AI c1 S) \<squnion> (AI c2 S)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   173
"AI (WHILE b DO c) S = pfp_above (AI c) S"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   174
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   175
lemma AI_sound: "(c,s) \<Rightarrow> t \<Longrightarrow> s <: S0 \<Longrightarrow> t <: AI c S0"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   176
proof(induct c arbitrary: s t S0)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   177
  case SKIP thus ?case by fastsimp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   178
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   179
  case Assign thus ?case by (auto simp: aval'_sound)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   180
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   181
  case Semi thus ?case by auto
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   182
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   183
  case If thus ?case by(auto simp: in_rep_join)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   184
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   185
  case (While b c)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   186
  let ?P = "pfp_above (AI c) S0"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   187
  have pfp: "AI c ?P \<sqsubseteq> ?P" and "S0 \<sqsubseteq> ?P"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   188
    by(simp_all add: SL_top_class.pfp_above_pfp)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   189
  { fix s t have "(WHILE b DO c,s) \<Rightarrow> t \<Longrightarrow> s <: ?P \<Longrightarrow> t <: ?P"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   190
    proof(induct "WHILE b DO c" s t rule: big_step_induct)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   191
      case WhileFalse thus ?case by simp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   192
    next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   193
      case WhileTrue thus ?case using While.hyps pfp fun_in_rep_le by metis
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   194
    qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   195
  }
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   196
  with fun_in_rep_le[OF `s <: S0` `S0 \<sqsubseteq> ?P`]
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   197
  show ?case by (metis While(2) AI.simps(5))
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   198
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   199
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   200
end
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   201
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   202
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   203
text{* Problem: not executable because of the comparison of abstract states,
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   204
i.e. functions, in the post-fixedpoint computation. Need to implement
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   205
abstract states concretely. *}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   206
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   207
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   208
(* Exercises: show that <= is a preorder if
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   209
1. v1 <= v2  =  rep v1 <= rep v2
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   210
2. v1 <= v2  =  ALL x. lookup v1 x <= lookup v2 x
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   211
*)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   212
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   213
end