src/HOL/IMP/Abs_Int2.thy
author nipkow
Tue, 12 Feb 2013 12:22:44 +0100
changeset 51037 0a6d84c41dbf
parent 51036 e7b54119c436
child 51359 00b45c7e831f
permissions -rw-r--r--
tuned identifier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
     1
(* Author: Tobias Nipkow *)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
     2
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
     3
theory Abs_Int2
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
     4
imports Abs_Int1
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
     5
begin
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
     6
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
     7
instantiation prod :: (preord,preord) preord
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
     8
begin
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
     9
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    10
definition "le_prod p1 p2 = (fst p1 \<sqsubseteq> fst p2 \<and> snd p1 \<sqsubseteq> snd p2)"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    11
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    12
instance
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    13
proof
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    14
  case goal1 show ?case by(simp add: le_prod_def)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    15
next
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    16
  case goal2 thus ?case unfolding le_prod_def by(metis le_trans)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    17
qed
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    18
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    19
end
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    20
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    21
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    22
subsection "Backward Analysis of Expressions"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    23
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
    24
class lattice = semilattice + bot +
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    25
fixes meet :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 65)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    26
assumes meet_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    27
and meet_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    28
and meet_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    29
begin
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    30
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    31
lemma mono_meet: "x \<sqsubseteq> x' \<Longrightarrow> y \<sqsubseteq> y' \<Longrightarrow> x \<sqinter> y \<sqsubseteq> x' \<sqinter> y'"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    32
by (metis meet_greatest meet_le1 meet_le2 le_trans)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    33
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    34
end
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    35
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    36
locale Val_abs1_gamma =
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
    37
  Gamma where \<gamma> = \<gamma> for \<gamma> :: "'av::lattice \<Rightarrow> val set" +
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    38
assumes inter_gamma_subset_gamma_meet:
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    39
  "\<gamma> a1 \<inter> \<gamma> a2 \<subseteq> \<gamma>(a1 \<sqinter> a2)"
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
    40
and gamma_bot[simp]: "\<gamma> \<bottom> = {}"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    41
begin
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    42
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    43
lemma in_gamma_meet: "x : \<gamma> a1 \<Longrightarrow> x : \<gamma> a2 \<Longrightarrow> x : \<gamma>(a1 \<sqinter> a2)"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    44
by (metis IntI inter_gamma_subset_gamma_meet set_mp)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    45
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    46
lemma gamma_meet[simp]: "\<gamma>(a1 \<sqinter> a2) = \<gamma> a1 \<inter> \<gamma> a2"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    47
by (metis equalityI inter_gamma_subset_gamma_meet le_inf_iff mono_gamma meet_le1 meet_le2)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    48
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    49
end
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    50
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    51
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    52
locale Val_abs1 =
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    53
  Val_abs1_gamma where \<gamma> = \<gamma>
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
    54
   for \<gamma> :: "'av::lattice \<Rightarrow> val set" +
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    55
fixes test_num' :: "val \<Rightarrow> 'av \<Rightarrow> bool"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    56
and filter_plus' :: "'av \<Rightarrow> 'av \<Rightarrow> 'av \<Rightarrow> 'av * 'av"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    57
and filter_less' :: "bool \<Rightarrow> 'av \<Rightarrow> 'av \<Rightarrow> 'av * 'av"
51036
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
    58
assumes test_num': "test_num' n a = (n : \<gamma> a)"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    59
and filter_plus': "filter_plus' a a1 a2 = (b1,b2) \<Longrightarrow>
51036
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
    60
  n1 : \<gamma> a1 \<Longrightarrow> n2 : \<gamma> a2 \<Longrightarrow> n1+n2 : \<gamma> a \<Longrightarrow> n1 : \<gamma> b1 \<and> n2 : \<gamma> b2"
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
    61
and filter_less': "filter_less' (n1<n2) a1 a2 = (b1,b2) \<Longrightarrow>
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
    62
  n1 : \<gamma> a1 \<Longrightarrow> n2 : \<gamma> a2 \<Longrightarrow> n1 : \<gamma> b1 \<and> n2 : \<gamma> b2"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    63
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    64
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    65
locale Abs_Int1 =
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
    66
  Val_abs1 where \<gamma> = \<gamma> for \<gamma> :: "'av::lattice \<Rightarrow> val set"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    67
begin
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    68
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    69
lemma in_gamma_join_UpI:
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
    70
  "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> s : \<gamma>\<^isub>o S1 \<or> s : \<gamma>\<^isub>o S2 \<Longrightarrow> s : \<gamma>\<^isub>o(S1 \<squnion> S2)"
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
    71
by (metis (hide_lams, no_types) semilatticeL_class.join_ge1 semilatticeL_class.join_ge2 mono_gamma_o subsetD)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    72
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    73
fun aval'' :: "aexp \<Rightarrow> 'av st option \<Rightarrow> 'av" where
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    74
"aval'' e None = \<bottom>" |
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    75
"aval'' e (Some sa) = aval' e sa"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    76
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
    77
lemma aval''_sound: "s : \<gamma>\<^isub>o S \<Longrightarrow> S \<in> L X \<Longrightarrow> vars a \<subseteq> X \<Longrightarrow> aval a s : \<gamma>(aval'' a S)"
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
    78
by(simp add: L_option_def L_st_def aval'_sound split: option.splits)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    79
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    80
subsubsection "Backward analysis"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    81
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    82
fun afilter :: "aexp \<Rightarrow> 'av \<Rightarrow> 'av st option \<Rightarrow> 'av st option" where
51036
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
    83
"afilter (N n) a S = (if test_num' n a then S else None)" |
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    84
"afilter (V x) a S = (case S of None \<Rightarrow> None | Some S \<Rightarrow>
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    85
  let a' = fun S x \<sqinter> a in
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    86
  if a' \<sqsubseteq> \<bottom> then None else Some(update S x a'))" |
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    87
"afilter (Plus e1 e2) a S =
51036
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
    88
 (let (a1,a2) = filter_plus' a (aval'' e1 S) (aval'' e2 S)
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
    89
  in afilter e1 a1 (afilter e2 a2 S))"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    90
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    91
text{* The test for @{const bot} in the @{const V}-case is important: @{const
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    92
bot} indicates that a variable has no possible values, i.e.\ that the current
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    93
program point is unreachable. But then the abstract state should collapse to
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    94
@{const None}. Put differently, we maintain the invariant that in an abstract
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    95
state of the form @{term"Some s"}, all variables are mapped to non-@{const
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    96
bot} values. Otherwise the (pointwise) join of two abstract states, one of
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    97
which contains @{const bot} values, may produce too large a result, thus
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    98
making the analysis less precise. *}
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
    99
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   100
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   101
fun bfilter :: "bexp \<Rightarrow> bool \<Rightarrow> 'av st option \<Rightarrow> 'av st option" where
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   102
"bfilter (Bc v) res S = (if v=res then S else None)" |
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   103
"bfilter (Not b) res S = bfilter b (\<not> res) S" |
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   104
"bfilter (And b1 b2) res S =
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   105
  (if res then bfilter b1 True (bfilter b2 True S)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   106
   else bfilter b1 False S \<squnion> bfilter b2 False S)" |
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   107
"bfilter (Less e1 e2) res S =
51037
0a6d84c41dbf tuned identifier
nipkow
parents: 51036
diff changeset
   108
  (let (a1,a2) = filter_less' res (aval'' e1 S) (aval'' e2 S)
0a6d84c41dbf tuned identifier
nipkow
parents: 51036
diff changeset
   109
   in afilter e1 a1 (afilter e2 a2 S))"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   110
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   111
lemma afilter_in_L: "S \<in> L X \<Longrightarrow> vars e \<subseteq> X \<Longrightarrow> afilter e a S \<in> L X"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   112
by(induction e arbitrary: a S)
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   113
  (auto simp: Let_def update_def L_st_def
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   114
           split: option.splits prod.split)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   115
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   116
lemma afilter_sound: "S \<in> L X \<Longrightarrow> vars e \<subseteq> X \<Longrightarrow>
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   117
  s : \<gamma>\<^isub>o S \<Longrightarrow> aval e s : \<gamma> a \<Longrightarrow> s : \<gamma>\<^isub>o (afilter e a S)"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   118
proof(induction e arbitrary: a S)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   119
  case N thus ?case by simp (metis test_num')
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   120
next
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   121
  case (V x)
49497
860b7c6bd913 tuned names
nipkow
parents: 49464
diff changeset
   122
  obtain S' where "S = Some S'" and "s : \<gamma>\<^isub>s S'" using `s : \<gamma>\<^isub>o S`
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   123
    by(auto simp: in_gamma_option_iff)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   124
  moreover hence "s x : \<gamma> (fun S' x)"
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   125
    using V(1,2) by(simp add: \<gamma>_st_def L_st_def)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   126
  moreover have "s x : \<gamma> a" using V by simp
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   127
  ultimately show ?case using V(3)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   128
    by(simp add: Let_def \<gamma>_st_def)
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   129
      (metis mono_gamma emptyE in_gamma_meet gamma_bot subset_empty)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   130
next
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   131
  case (Plus e1 e2) thus ?case
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   132
    using filter_plus'[OF _ aval''_sound[OF Plus.prems(3)] aval''_sound[OF Plus.prems(3)]]
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   133
    by (auto simp: afilter_in_L split: prod.split)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   134
qed
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   135
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   136
lemma bfilter_in_L: "S \<in> L X \<Longrightarrow> vars b \<subseteq> X \<Longrightarrow> bfilter b bv S \<in> L X"
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   137
by(induction b arbitrary: bv S)(auto simp: afilter_in_L split: prod.split)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   138
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   139
lemma bfilter_sound: "S \<in> L X \<Longrightarrow> vars b \<subseteq> X \<Longrightarrow>
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   140
  s : \<gamma>\<^isub>o S \<Longrightarrow> bv = bval b s \<Longrightarrow> s : \<gamma>\<^isub>o(bfilter b bv S)"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   141
proof(induction b arbitrary: S bv)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   142
  case Bc thus ?case by simp
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   143
next
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   144
  case (Not b) thus ?case by simp
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   145
next
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   146
  case (And b1 b2) thus ?case
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   147
    by simp (metis And(1) And(2) bfilter_in_L in_gamma_join_UpI)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   148
next
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   149
  case (Less e1 e2) thus ?case
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   150
    by(auto split: prod.split)
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   151
      (metis (lifting) afilter_in_L afilter_sound aval''_sound filter_less')
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   152
qed
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   153
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   154
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   155
fun step' :: "'av st option \<Rightarrow> 'av st option acom \<Rightarrow> 'av st option acom"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   156
 where
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   157
"step' S (SKIP {P}) = (SKIP {S})" |
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   158
"step' S (x ::= e {P}) =
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   159
  x ::= e {case S of None \<Rightarrow> None | Some S \<Rightarrow> Some(update S x (aval' e S))}" |
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   160
"step' S (C1; C2) = step' S C1; step' (post C1) C2" |
49344
nipkow
parents: 49095
diff changeset
   161
"step' S (IF b THEN {P1} C1 ELSE {P2} C2 {Q}) =
nipkow
parents: 49095
diff changeset
   162
  (let P1' = bfilter b True S; C1' = step' P1 C1; P2' = bfilter b False S; C2' = step' P2 C2
nipkow
parents: 49095
diff changeset
   163
   in IF b THEN {P1'} C1' ELSE {P2'} C2' {post C1 \<squnion> post C2})" |
nipkow
parents: 49095
diff changeset
   164
"step' S ({I} WHILE b DO {p} C {Q}) =
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   165
   {S \<squnion> post C}
49095
7df19036392e added annotations after condition in if and while
nipkow
parents: 48759
diff changeset
   166
   WHILE b DO {bfilter b True I} step' p C
7df19036392e added annotations after condition in if and while
nipkow
parents: 48759
diff changeset
   167
   {bfilter b False I}"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   168
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   169
definition AI :: "com \<Rightarrow> 'av st option acom option" where
51036
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
   170
"AI c = pfp (step' \<top>\<^bsub>vars c\<^esub>) (bot c)"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   171
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   172
lemma strip_step'[simp]: "strip(step' S c) = strip c"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   173
by(induct c arbitrary: S) (simp_all add: Let_def)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   174
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   175
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   176
subsubsection "Soundness"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   177
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   178
lemma in_gamma_update:
49497
860b7c6bd913 tuned names
nipkow
parents: 49464
diff changeset
   179
  "\<lbrakk> s : \<gamma>\<^isub>s S; i : \<gamma> a \<rbrakk> \<Longrightarrow> s(x := i) : \<gamma>\<^isub>s(update S x a)"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   180
by(simp add: \<gamma>_st_def)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   181
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   182
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)"
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   183
proof(induction C arbitrary: S)
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   184
  case SKIP thus ?case by auto
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   185
next
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   186
  case Assign thus ?case
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   187
    by (fastforce simp: L_st_def intro: aval'_sound in_gamma_update split: option.splits)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   188
next
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   189
  case Seq thus ?case by auto
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   190
next
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   191
  case (If b _ C1 _ C2)
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   192
  hence 0: "post C1 \<sqsubseteq> post C1 \<squnion> post C2 \<and> post C2 \<sqsubseteq> post C1 \<squnion> post C2"
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   193
    by(simp, metis post_in_L join_ge1 join_ge2)
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   194
  have "vars b \<subseteq> X" using If.prems by simp
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   195
  note vars = `S \<in> L X` `vars b \<subseteq> X`
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   196
  show ?case using If 0
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   197
    by (auto simp: mono_gamma_o bfilter_sound[OF vars] bfilter_in_L[OF vars])
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   198
next
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   199
  case (While I b)
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   200
  hence vars: "I \<in> L X" "vars b \<subseteq> X" by simp_all
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   201
  thus ?case using While
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   202
    by (auto simp: mono_gamma_o bfilter_sound[OF vars] bfilter_in_L[OF vars])
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   203
qed
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   204
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   205
lemma step'_in_L[simp]: "\<lbrakk> C \<in> L X; S \<in> L X \<rbrakk> \<Longrightarrow> step' S C \<in> L X"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   206
proof(induction C arbitrary: S)
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   207
  case Assign thus ?case by(simp add: L_option_def L_st_def update_def split: option.splits)
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   208
qed (auto simp add: bfilter_in_L)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   209
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   210
lemma AI_sound: "AI c = Some C \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c C"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   211
proof(simp add: CS_def AI_def)
51036
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
   212
  assume 1: "pfp (step' (top(vars c))) (bot c) = Some C"
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   213
  have "C \<in> L(vars c)"
49464
4e4bdd12280f removed lpfp and proved least pfp thm
nipkow
parents: 49396
diff changeset
   214
    by(rule pfp_inv[where P = "%C. C \<in> L(vars c)", OF 1 _ bot_in_L])
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   215
      (erule step'_in_L[OF _ top_in_L])
51036
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
   216
  have pfp': "step' (top(vars c)) C \<sqsubseteq> C" by(rule pfp_pfp[OF 1])
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
   217
  have 2: "step (\<gamma>\<^isub>o(top(vars c))) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c C"
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   218
  proof(rule order_trans)
51036
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
   219
    show "step (\<gamma>\<^isub>o (top(vars c))) (\<gamma>\<^isub>c C) \<le>  \<gamma>\<^isub>c (step' (top(vars c)) C)"
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   220
      by(rule step_step'[OF `C \<in> L(vars c)` top_in_L])
51036
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
   221
    show "\<gamma>\<^isub>c (step' (top(vars c)) C) \<le> \<gamma>\<^isub>c C"
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   222
      by(rule mono_gamma_c[OF pfp'])
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   223
  qed
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   224
  have 3: "strip (\<gamma>\<^isub>c C) = c" by(simp add: strip_pfp[OF _ 1])
51036
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
   225
  have "lfp c (step (\<gamma>\<^isub>o(top(vars c)))) \<le> \<gamma>\<^isub>c C"
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
   226
    by(rule lfp_lowerbound[simplified,where f="step (\<gamma>\<^isub>o(top(vars c)))", OF 3 2])
50986
c54ea7f5418f simplified proofs
nipkow
parents: 49497
diff changeset
   227
  thus "lfp c (step UNIV) \<le> \<gamma>\<^isub>c C" by simp
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   228
qed
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   229
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   230
end
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   231
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   232
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   233
subsubsection "Monotonicity"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   234
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   235
locale Abs_Int1_mono = Abs_Int1 +
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   236
assumes mono_plus': "a1 \<sqsubseteq> b1 \<Longrightarrow> a2 \<sqsubseteq> b2 \<Longrightarrow> plus' a1 a2 \<sqsubseteq> plus' b1 b2"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   237
and mono_filter_plus': "a1 \<sqsubseteq> b1 \<Longrightarrow> a2 \<sqsubseteq> b2 \<Longrightarrow> r \<sqsubseteq> r' \<Longrightarrow>
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   238
  filter_plus' r a1 a2 \<sqsubseteq> filter_plus' r' b1 b2"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   239
and mono_filter_less': "a1 \<sqsubseteq> b1 \<Longrightarrow> a2 \<sqsubseteq> b2 \<Longrightarrow>
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   240
  filter_less' bv a1 a2 \<sqsubseteq> filter_less' bv b1 b2"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   241
begin
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   242
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   243
lemma mono_aval':
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   244
  "S1 \<sqsubseteq> S2 \<Longrightarrow> S1 \<in> L X \<Longrightarrow> vars e \<subseteq> X \<Longrightarrow> aval' e S1 \<sqsubseteq> aval' e S2"
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   245
by(induction e) (auto simp: le_st_def mono_plus' L_st_def)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   246
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   247
lemma mono_aval'':
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   248
  "S1 \<sqsubseteq> S2 \<Longrightarrow> S1 \<in> L X \<Longrightarrow> vars e \<subseteq> X \<Longrightarrow> aval'' e S1 \<sqsubseteq> aval'' e S2"
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   249
apply(cases S1)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   250
 apply simp
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   251
apply(cases S2)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   252
 apply simp
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   253
by (simp add: mono_aval')
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   254
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   255
lemma mono_afilter: "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> vars e \<subseteq> X \<Longrightarrow>
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   256
  r1 \<sqsubseteq> r2 \<Longrightarrow> S1 \<sqsubseteq> S2 \<Longrightarrow> afilter e r1 S1 \<sqsubseteq> afilter e r2 S2"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   257
apply(induction e arbitrary: r1 r2 S1 S2)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   258
apply(auto simp: test_num' Let_def mono_meet split: option.splits prod.splits)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   259
apply (metis mono_gamma subsetD)
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   260
apply(drule (2) mono_fun_L)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   261
apply (metis mono_meet le_trans)
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   262
apply(metis mono_aval'' mono_filter_plus'[simplified le_prod_def] fst_conv snd_conv afilter_in_L)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   263
done
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   264
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   265
lemma mono_bfilter: "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> vars b \<subseteq> X \<Longrightarrow>
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   266
  S1 \<sqsubseteq> S2 \<Longrightarrow> bfilter b bv S1 \<sqsubseteq> bfilter b bv S2"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   267
apply(induction b arbitrary: bv S1 S2)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   268
apply(simp)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   269
apply(simp)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   270
apply simp
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   271
apply(metis join_least le_trans[OF _ join_ge1] le_trans[OF _ join_ge2] bfilter_in_L)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   272
apply (simp split: prod.splits)
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   273
apply(metis mono_aval'' mono_afilter mono_filter_less'[simplified le_prod_def] fst_conv snd_conv afilter_in_L)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   274
done
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   275
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   276
theorem mono_step': "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> C1 \<in> L X \<Longrightarrow> C2 \<in> L X \<Longrightarrow>
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   277
  S1 \<sqsubseteq> S2 \<Longrightarrow> C1 \<sqsubseteq> C2 \<Longrightarrow> step' S1 C1 \<sqsubseteq> step' S2 C2"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   278
apply(induction C1 C2 arbitrary: S1 S2 rule: le_acom.induct)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   279
apply (auto simp: Let_def mono_bfilter mono_aval' mono_post
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   280
  le_join_disj le_join_disj[OF  post_in_L post_in_L] bfilter_in_L
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   281
            split: option.split)
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   282
done
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   283
51036
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
   284
lemma mono_step'_top: "C1 \<in> L X \<Longrightarrow> C2 \<in> L X \<Longrightarrow>
e7b54119c436 tuned top
nipkow
parents: 50995
diff changeset
   285
  C1 \<sqsubseteq> C2 \<Longrightarrow> step' (top X) C1 \<sqsubseteq> step' (top X) C2"
49396
73fb17ed2e08 converted wt into a set, tuned names
nipkow
parents: 49344
diff changeset
   286
by (metis top_in_L mono_step' preord_class.le_refl)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   287
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   288
end
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   289
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents:
diff changeset
   290
end