author | nipkow |
Fri, 27 Jan 2012 17:02:08 +0100 | |
changeset 46346 | 10c18630612a |
parent 46334 | 3858dc8eabd8 |
child 46353 | 66486acfa26a |
permissions | -rw-r--r-- |
45111 | 1 |
(* Author: Tobias Nipkow *) |
2 |
||
3 |
theory Abs_Int0_const |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
4 |
imports Abs_Int0 Abs_Int_Tests |
45111 | 5 |
begin |
6 |
||
7 |
subsection "Constant Propagation" |
|
8 |
||
46158 | 9 |
datatype const = Const val | Any |
45111 | 10 |
|
46158 | 11 |
fun \<gamma>_const where |
12 |
"\<gamma>_const (Const n) = {n}" | |
|
13 |
"\<gamma>_const (Any) = UNIV" |
|
45111 | 14 |
|
46158 | 15 |
fun plus_const where |
16 |
"plus_const (Const m) (Const n) = Const(m+n)" | |
|
17 |
"plus_const _ _ = Any" |
|
45111 | 18 |
|
46158 | 19 |
lemma plus_const_cases: "plus_const a1 a2 = |
45111 | 20 |
(case (a1,a2) of (Const m, Const n) \<Rightarrow> Const(m+n) | _ \<Rightarrow> Any)" |
46158 | 21 |
by(auto split: prod.split const.split) |
45111 | 22 |
|
46158 | 23 |
instantiation const :: SL_top |
45111 | 24 |
begin |
25 |
||
46158 | 26 |
fun le_const where |
45111 | 27 |
"_ \<sqsubseteq> Any = True" | |
28 |
"Const n \<sqsubseteq> Const m = (n=m)" | |
|
29 |
"Any \<sqsubseteq> Const _ = False" |
|
30 |
||
46158 | 31 |
fun join_const where |
45111 | 32 |
"Const m \<squnion> Const n = (if n=m then Const m else Any)" | |
33 |
"_ \<squnion> _ = Any" |
|
34 |
||
35 |
definition "\<top> = Any" |
|
36 |
||
37 |
instance |
|
38 |
proof |
|
39 |
case goal1 thus ?case by (cases x) simp_all |
|
40 |
next |
|
41 |
case goal2 thus ?case by(cases z, cases y, cases x, simp_all) |
|
42 |
next |
|
43 |
case goal3 thus ?case by(cases x, cases y, simp_all) |
|
44 |
next |
|
45 |
case goal4 thus ?case by(cases y, cases x, simp_all) |
|
46 |
next |
|
47 |
case goal5 thus ?case by(cases z, cases y, cases x, simp_all) |
|
48 |
next |
|
46158 | 49 |
case goal6 thus ?case by(simp add: Top_const_def) |
45111 | 50 |
qed |
51 |
||
52 |
end |
|
53 |
||
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
54 |
|
46063 | 55 |
interpretation Val_abs |
46158 | 56 |
where \<gamma> = \<gamma>_const and num' = Const and plus' = plus_const |
45111 | 57 |
proof |
58 |
case goal1 thus ?case |
|
59 |
by(cases a, cases b, simp, simp, cases b, simp, simp) |
|
60 |
next |
|
46158 | 61 |
case goal2 show ?case by(simp add: Top_const_def) |
45111 | 62 |
next |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
63 |
case goal3 show ?case by simp |
45111 | 64 |
next |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
65 |
case goal4 thus ?case |
46158 | 66 |
by(auto simp: plus_const_cases split: const.split) |
45111 | 67 |
qed |
68 |
||
46063 | 69 |
interpretation Abs_Int |
46158 | 70 |
where \<gamma> = \<gamma>_const and num' = Const and plus' = plus_const |
46346
10c18630612a
removed duplicate definitions that made locale inconsistent
nipkow
parents:
46334
diff
changeset
|
71 |
defines AI_const is AI and step_const is step' and aval'_const is aval' |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
72 |
proof qed |
45111 | 73 |
|
74 |
||
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
75 |
text{* Monotonicity: *} |
45111 | 76 |
|
46063 | 77 |
interpretation Abs_Int_mono |
46158 | 78 |
where \<gamma> = \<gamma>_const and num' = Const and plus' = plus_const |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
79 |
proof |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
80 |
case goal1 thus ?case |
46158 | 81 |
by(auto simp: plus_const_cases split: const.split) |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
82 |
qed |
45111 | 83 |
|
46158 | 84 |
text{* Termination: *} |
85 |
||
46334 | 86 |
definition "m_const x = (case x of Const _ \<Rightarrow> 1 | Any \<Rightarrow> 0)" |
87 |
||
46158 | 88 |
lemma measure_const: |
46334 | 89 |
"(strict{(x::const,y). x \<sqsubseteq> y})^-1 \<subseteq> measure m_const" |
90 |
by(auto simp: m_const_def split: const.splits) |
|
46158 | 91 |
|
92 |
lemma measure_const_eq: |
|
46334 | 93 |
"\<forall> x y::const. x \<sqsubseteq> y \<and> y \<sqsubseteq> x \<longrightarrow> m_const x = m_const y" |
94 |
by(auto simp: m_const_def split: const.splits) |
|
46158 | 95 |
|
96 |
lemma "EX c'. AI_const c = Some c'" |
|
46334 | 97 |
by(rule AI_Some_measure[OF measure_const measure_const_eq]) |
46158 | 98 |
|
45111 | 99 |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
100 |
subsubsection "Tests" |
45111 | 101 |
|
102 |
value [code] "show_acom (((step_const \<top>)^^0) (\<bottom>\<^sub>c test1_const))" |
|
103 |
value [code] "show_acom (((step_const \<top>)^^1) (\<bottom>\<^sub>c test1_const))" |
|
104 |
value [code] "show_acom (((step_const \<top>)^^2) (\<bottom>\<^sub>c test1_const))" |
|
105 |
value [code] "show_acom (((step_const \<top>)^^3) (\<bottom>\<^sub>c test1_const))" |
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
106 |
value [code] "show_acom_opt (AI_const test1_const)" |
45111 | 107 |
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
108 |
value [code] "show_acom_opt (AI_const test2_const)" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
109 |
value [code] "show_acom_opt (AI_const test3_const)" |
45111 | 110 |
|
111 |
value [code] "show_acom (((step_const \<top>)^^0) (\<bottom>\<^sub>c test4_const))" |
|
112 |
value [code] "show_acom (((step_const \<top>)^^1) (\<bottom>\<^sub>c test4_const))" |
|
113 |
value [code] "show_acom (((step_const \<top>)^^2) (\<bottom>\<^sub>c test4_const))" |
|
114 |
value [code] "show_acom (((step_const \<top>)^^3) (\<bottom>\<^sub>c test4_const))" |
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
115 |
value [code] "show_acom_opt (AI_const test4_const)" |
45111 | 116 |
|
117 |
value [code] "show_acom (((step_const \<top>)^^0) (\<bottom>\<^sub>c test5_const))" |
|
118 |
value [code] "show_acom (((step_const \<top>)^^1) (\<bottom>\<^sub>c test5_const))" |
|
119 |
value [code] "show_acom (((step_const \<top>)^^2) (\<bottom>\<^sub>c test5_const))" |
|
120 |
value [code] "show_acom (((step_const \<top>)^^3) (\<bottom>\<^sub>c test5_const))" |
|
121 |
value [code] "show_acom (((step_const \<top>)^^4) (\<bottom>\<^sub>c test5_const))" |
|
122 |
value [code] "show_acom (((step_const \<top>)^^5) (\<bottom>\<^sub>c test5_const))" |
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
123 |
value [code] "show_acom_opt (AI_const test5_const)" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
124 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
125 |
value [code] "show_acom_opt (AI_const test6_const)" |
45111 | 126 |
|
127 |
end |