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