src/HOL/IMP/AbsInt1_ivl.thy
author nipkow
Wed, 21 Sep 2011 06:26:15 +0200
changeset 45020 21334181f820
parent 45019 4e3b999c62fa
child 45023 76abd26e2e2d
permissions -rw-r--r--
added example
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
theory AbsInt1_ivl
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     4
imports AbsInt1
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     5
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     6
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     7
subsection "Interval Analysis"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     8
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     9
datatype ivl = I "int option" "int option"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    10
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    11
text{* We assume an important invariant: arithmetic operations are never
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    12
applied to empty intervals @{term"I (Some i) (Some j)"} with @{term"j <
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    13
i"}. This avoids special cases. Why can we assume this? Because an empty
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    14
interval of values for a variable means that the current program point is
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    15
unreachable. But this should actually translate into the bottom state, not a
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    16
state where some variables have empty intervals. *}
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    17
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    18
definition "rep_ivl i =
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    19
 (case i of I (Some l) (Some h) \<Rightarrow> {l..h} | I (Some l) None \<Rightarrow> {l..}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    20
  | I None (Some h) \<Rightarrow> {..h} | I None None \<Rightarrow> UNIV)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    21
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    22
definition "num_ivl n = I (Some n) (Some n)"
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    23
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    24
instantiation option :: (plus)plus
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    25
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    26
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    27
fun plus_option where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    28
"Some x + Some y = Some(x+y)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    29
"_ + _ = None"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    30
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    31
instance proof qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    32
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    33
end
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    34
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    35
definition empty where "empty = I (Some 1) (Some 0)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    36
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    37
fun is_empty where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    38
"is_empty(I (Some l) (Some h)) = (h<l)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    39
"is_empty _ = False"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    40
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    41
lemma [simp]: "is_empty(I l h) =
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    42
  (case l of Some l \<Rightarrow> (case h of Some h \<Rightarrow> h<l | None \<Rightarrow> False) | None \<Rightarrow> False)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    43
by(auto split:option.split)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    44
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    45
lemma [simp]: "is_empty i \<Longrightarrow> rep_ivl i = {}"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    46
by(auto simp add: rep_ivl_def split: ivl.split option.split)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    47
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    48
definition "plus_ivl i1 i2 = ((*if is_empty i1 | is_empty i2 then empty else*)
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    49
  case (i1,i2) of (I l1 h1, I l2 h2) \<Rightarrow> I (l1+l2) (h1+h2))"
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    50
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    51
instantiation ivl :: SL_top
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    52
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    53
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    54
definition le_option :: "bool \<Rightarrow> int option \<Rightarrow> int option \<Rightarrow> bool" where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    55
"le_option pos x y =
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    56
 (case x of (Some i) \<Rightarrow> (case y of Some j \<Rightarrow> i\<le>j | None \<Rightarrow> pos)
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
    57
  | None \<Rightarrow> (case y of Some j \<Rightarrow> \<not>pos | None \<Rightarrow> True))"
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    58
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    59
fun le_aux where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    60
"le_aux (I l1 h1) (I l2 h2) = (le_option False l2 l1 & le_option True h1 h2)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    61
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    62
definition le_ivl where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    63
"i1 \<sqsubseteq> i2 =
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    64
 (if is_empty i1 then True else
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    65
  if is_empty i2 then False else le_aux i1 i2)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    66
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    67
definition min_option :: "bool \<Rightarrow> int option \<Rightarrow> int option \<Rightarrow> int option" where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    68
"min_option pos o1 o2 = (if le_option pos o1 o2 then o1 else o2)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    69
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    70
definition max_option :: "bool \<Rightarrow> int option \<Rightarrow> int option \<Rightarrow> int option" where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    71
"max_option pos o1 o2 = (if le_option pos o1 o2 then o2 else o1)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    72
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    73
definition "i1 \<squnion> i2 =
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    74
 (if is_empty i1 then i2 else if is_empty i2 then i1
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    75
  else case (i1,i2) of (I l1 h1, I l2 h2) \<Rightarrow>
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    76
          I (min_option False l1 l2) (max_option True h1 h2))"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    77
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    78
definition "Top = I None None"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    79
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    80
instance
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    81
proof
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    82
  case goal1 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    83
    by(cases x, simp add: le_ivl_def le_option_def split: option.split)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    84
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    85
  case goal2 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    86
    by(cases x, cases y, cases z, auto simp: le_ivl_def le_option_def split: option.splits if_splits)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    87
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    88
  case goal3 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    89
    by(cases x, cases y, simp add: le_ivl_def join_ivl_def le_option_def min_option_def max_option_def split: option.splits)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    90
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    91
  case goal4 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    92
    by(cases x, cases y, simp add: le_ivl_def join_ivl_def le_option_def min_option_def max_option_def split: option.splits)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    93
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    94
  case goal5 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    95
    by(cases x, cases y, cases z, auto simp add: le_ivl_def join_ivl_def le_option_def min_option_def max_option_def split: option.splits if_splits)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    96
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    97
  case goal6 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    98
    by(cases x, simp add: Top_ivl_def le_ivl_def le_option_def split: option.split)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    99
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   100
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   101
end
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   102
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   103
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   104
instantiation ivl :: L_top_bot
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   105
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   106
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   107
definition "i1 \<sqinter> i2 = (if is_empty i1 \<or> is_empty i2 then empty else
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   108
  case (i1,i2) of (I l1 h1, I l2 h2) \<Rightarrow>
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   109
    I (max_option False l1 l2) (min_option True h1 h2))"
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   110
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   111
definition "Bot = empty"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   112
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   113
instance
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   114
proof
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   115
  case goal1 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   116
    by (simp add:meet_ivl_def empty_def meet_ivl_def le_ivl_def le_option_def max_option_def min_option_def split: ivl.splits option.splits)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   117
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   118
  case goal2 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   119
    by (simp add:meet_ivl_def empty_def meet_ivl_def le_ivl_def le_option_def max_option_def min_option_def split: ivl.splits option.splits)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   120
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   121
  case goal3 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   122
    by (cases x, cases y, cases z, auto simp add: le_ivl_def meet_ivl_def empty_def le_option_def max_option_def min_option_def split: option.splits if_splits)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   123
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   124
  case goal4 show ?case by(cases x, simp add: Bot_ivl_def empty_def le_ivl_def)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   125
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   126
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   127
end
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   128
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   129
instantiation option :: (minus)minus
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   130
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   131
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   132
fun minus_option where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   133
"Some x - Some y = Some(x-y)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   134
"_ - _ = None"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   135
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   136
instance proof qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   137
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   138
end
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   139
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   140
definition "minus_ivl i1 i2 = ((*if is_empty i1 | is_empty i2 then empty else*)
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   141
  case (i1,i2) of (I l1 h1, I l2 h2) \<Rightarrow> I (l1-h2) (h1-l2))"
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   142
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   143
lemma rep_minus_ivl:
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   144
  "n1 : rep_ivl i1 \<Longrightarrow> n2 : rep_ivl i2 \<Longrightarrow> n1-n2 : rep_ivl(minus_ivl i1 i2)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   145
by(auto simp add: minus_ivl_def rep_ivl_def split: ivl.splits option.splits)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   146
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   147
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   148
definition "inv_plus_ivl i1 i2 i = ((*if is_empty i then empty else*)
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   149
  i1 \<sqinter> minus_ivl i i2, i2 \<sqinter> minus_ivl i i1)"
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   150
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   151
fun inv_less_ivl :: "ivl \<Rightarrow> ivl \<Rightarrow> bool \<Rightarrow> ivl * ivl" where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   152
"inv_less_ivl (I l1 h1) (I l2 h2) res =
45019
nipkow
parents: 44944
diff changeset
   153
  ((*if is_empty(I l1 h1) \<or> is_empty(I l2 h2) then (empty, empty) else*)
nipkow
parents: 44944
diff changeset
   154
   if res
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   155
   then (I l1 (min_option True h1 (h2 - Some 1)),
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   156
         I (max_option False (l1 + Some 1) l2) h2)
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   157
   else (I (max_option False l1 l2) h1, I l2 (min_option True h1 h2)))"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   158
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   159
interpretation Rep rep_ivl
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   160
proof
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   161
  case goal1 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   162
    by(auto simp: rep_ivl_def le_ivl_def le_option_def split: ivl.split option.split if_splits)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   163
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   164
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   165
interpretation Val_abs rep_ivl num_ivl plus_ivl
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   166
proof
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   167
  case goal1 thus ?case by(simp add: rep_ivl_def num_ivl_def)
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   168
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   169
  case goal2 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   170
    by(auto simp add: rep_ivl_def plus_ivl_def split: ivl.split option.splits)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   171
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   172
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   173
interpretation Rep1 rep_ivl
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   174
proof
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   175
  case goal1 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   176
    by(auto simp add: rep_ivl_def meet_ivl_def empty_def min_option_def max_option_def split: ivl.split option.split)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   177
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   178
  case goal2 show ?case by(auto simp add: Bot_ivl_def rep_ivl_def empty_def)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   179
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   180
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   181
interpretation
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   182
  Val_abs1 rep_ivl num_ivl plus_ivl inv_plus_ivl inv_less_ivl
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   183
proof
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   184
  case goal1 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   185
    by(auto simp add: inv_plus_ivl_def)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   186
      (metis rep_minus_ivl add_diff_cancel add_commute)+
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   187
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   188
  case goal2 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   189
    by(cases a1, cases a2,
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   190
      auto simp: rep_ivl_def min_option_def max_option_def le_option_def split: if_splits option.splits)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   191
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   192
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   193
interpretation
44944
f136409c2cef tuned post fixpoint setup
nipkow
parents: 44932
diff changeset
   194
  Abs_Int1 rep_ivl num_ivl plus_ivl inv_plus_ivl inv_less_ivl "(iter' 3)"
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   195
defines afilter_ivl is afilter
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   196
and bfilter_ivl is bfilter
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   197
and AI_ivl is AI
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   198
and aval_ivl is aval'
44944
f136409c2cef tuned post fixpoint setup
nipkow
parents: 44932
diff changeset
   199
proof qed (auto simp: iter'_pfp_above)
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   200
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   201
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   202
fun list_up where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   203
"list_up bot = bot" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   204
"list_up (Up x) = Up(list x)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   205
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   206
value [code] "list_up(afilter_ivl (N 5) (I (Some 4) (Some 5)) Top)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   207
value [code] "list_up(afilter_ivl (N 5) (I (Some 4) (Some 4)) Top)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   208
value [code] "list_up(afilter_ivl (V ''x'') (I (Some 4) (Some 4))
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   209
 (Up(FunDom(Top(''x'':=I (Some 5) (Some 6))) [''x''])))"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   210
value [code] "list_up(afilter_ivl (V ''x'') (I (Some 4) (Some 5))
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   211
 (Up(FunDom(Top(''x'':=I (Some 5) (Some 6))) [''x''])))"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   212
value [code] "list_up(afilter_ivl (Plus (V ''x'') (V ''x'')) (I (Some 0) (Some 10))
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   213
  (Up(FunDom(Top(''x'':= I (Some 0) (Some 100)))[''x''])))"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   214
value [code] "list_up(afilter_ivl (Plus (V ''x'') (N 7)) (I (Some 0) (Some 10))
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   215
  (Up(FunDom(Top(''x'':= I (Some 0) (Some 100)))[''x''])))"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   216
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   217
value [code] "list_up(bfilter_ivl (Less (V ''x'') (V ''x'')) True
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   218
  (Up(FunDom(Top(''x'':= I (Some 0) (Some 0)))[''x''])))"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   219
value [code] "list_up(bfilter_ivl (Less (V ''x'') (V ''x'')) True
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   220
  (Up(FunDom(Top(''x'':= I (Some 0) (Some 2)))[''x''])))"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   221
value [code] "list_up(bfilter_ivl (Less (V ''x'') (Plus (N 10) (V ''y''))) True
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   222
  (Up(FunDom(Top(''x'':= I (Some 15) (Some 20),''y'':= I (Some 5) (Some 7)))[''x'', ''y''])))"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   223
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   224
definition "test_ivl1 =
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   225
 ''y'' ::= N 7;
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   226
 IF Less (V ''x'') (V ''y'')
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   227
 THEN ''y'' ::= Plus (V ''y'') (V ''x'')
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   228
 ELSE ''x'' ::= Plus (V ''x'') (V ''y'')"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   229
value [code] "list_up(AI_ivl test_ivl1 Top)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   230
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   231
value "list_up (AI_ivl test3_const Top)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   232
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   233
value "list_up (AI_ivl test5_const Top)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   234
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   235
value "list_up (AI_ivl test6_const Top)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   236
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   237
definition "test2_ivl =
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   238
 ''y'' ::= N 7;
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   239
 WHILE Less (V ''x'') (N 100) DO ''y'' ::= Plus (V ''y'') (N 1)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   240
value [code] "list_up(AI_ivl test2_ivl Top)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   241
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   242
definition "test3_ivl =
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   243
 ''x'' ::= N 0; ''y'' ::= N 100; ''z'' ::= Plus (V ''x'') (V ''y'');
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   244
 WHILE Less (V ''x'') (N 11)
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   245
 DO (''x'' ::= Plus (V ''x'') (N 1); ''y'' ::= Plus (V ''y'') (N -1))"
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   246
value [code] "list_up(AI_ivl test3_ivl Top)"
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   247
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   248
definition "test4_ivl =
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   249
 ''x'' ::= N 0; ''y'' ::= N 0;
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   250
 WHILE Less (V ''x'') (N 1001)
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   251
 DO (''y'' ::= V ''x''; ''x'' ::= Plus (V ''x'') (N 1))"
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   252
value [code] "list_up(AI_ivl test4_ivl Top)"
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44923
diff changeset
   253
45020
21334181f820 added example
nipkow
parents: 45019
diff changeset
   254
text{* Nontermination not detected: *}
21334181f820 added example
nipkow
parents: 45019
diff changeset
   255
definition "test5_ivl =
21334181f820 added example
nipkow
parents: 45019
diff changeset
   256
 ''x'' ::= N 0;
21334181f820 added example
nipkow
parents: 45019
diff changeset
   257
 WHILE Less (V ''x'') (N 1) DO ''x'' ::= Plus (V ''x'') (N -1)"
21334181f820 added example
nipkow
parents: 45019
diff changeset
   258
value [code] "list_up(AI_ivl test5_ivl Top)"
21334181f820 added example
nipkow
parents: 45019
diff changeset
   259
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   260
end