author | nipkow |
Wed, 12 Oct 2011 09:16:30 +0200 | |
changeset 45127 | d2eb07a1e01b |
parent 45111 | 054a9ac0d7ef |
child 45200 | 1f1897ac7877 |
permissions | -rw-r--r-- |
45111 | 1 |
(* Author: Tobias Nipkow *) |
2 |
||
3 |
theory Abs_Int0_const |
|
4 |
imports Abs_Int0 |
|
5 |
begin |
|
6 |
||
7 |
subsection "Constant Propagation" |
|
8 |
||
9 |
datatype cval = Const val | Any |
|
10 |
||
11 |
fun rep_cval where |
|
12 |
"rep_cval (Const n) = {n}" | |
|
13 |
"rep_cval (Any) = UNIV" |
|
14 |
||
15 |
fun plus_cval where |
|
16 |
"plus_cval (Const m) (Const n) = Const(m+n)" | |
|
17 |
"plus_cval _ _ = Any" |
|
18 |
||
19 |
lemma plus_cval_cases: "plus_cval a1 a2 = |
|
20 |
(case (a1,a2) of (Const m, Const n) \<Rightarrow> Const(m+n) | _ \<Rightarrow> Any)" |
|
21 |
by(auto split: prod.split cval.split) |
|
22 |
||
23 |
instantiation cval :: SL_top |
|
24 |
begin |
|
25 |
||
26 |
fun le_cval where |
|
27 |
"_ \<sqsubseteq> Any = True" | |
|
28 |
"Const n \<sqsubseteq> Const m = (n=m)" | |
|
29 |
"Any \<sqsubseteq> Const _ = False" |
|
30 |
||
31 |
fun join_cval where |
|
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 |
|
49 |
case goal6 thus ?case by(simp add: Top_cval_def) |
|
50 |
qed |
|
51 |
||
52 |
end |
|
53 |
||
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
54 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
55 |
interpretation Val_abs rep_cval Const plus_cval |
45111 | 56 |
proof |
57 |
case goal1 thus ?case |
|
58 |
by(cases a, cases b, simp, simp, cases b, simp, simp) |
|
59 |
next |
|
60 |
case goal2 show ?case by(simp add: Top_cval_def) |
|
61 |
next |
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
62 |
case goal3 show ?case by simp |
45111 | 63 |
next |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
64 |
case goal4 thus ?case |
45111 | 65 |
by(auto simp: plus_cval_cases split: cval.split) |
66 |
qed |
|
67 |
||
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
68 |
interpretation Abs_Int rep_cval Const plus_cval |
45111 | 69 |
defines AI_const is AI |
70 |
and aval'_const is aval' |
|
71 |
and step_const is step |
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
72 |
proof qed |
45111 | 73 |
|
74 |
text{* Straight line code: *} |
|
75 |
definition "test1_const = |
|
76 |
''y'' ::= N 7; |
|
77 |
''z'' ::= Plus (V ''y'') (N 2); |
|
78 |
''y'' ::= Plus (V ''x'') (N 0)" |
|
79 |
||
80 |
text{* Conditional: *} |
|
81 |
definition "test2_const = |
|
82 |
IF Less (N 41) (V ''x'') THEN ''x'' ::= N 5 ELSE ''x'' ::= N 5" |
|
83 |
||
84 |
text{* Conditional, test is ignored: *} |
|
85 |
definition "test3_const = |
|
86 |
''x'' ::= N 42; |
|
87 |
IF Less (N 41) (V ''x'') THEN ''x'' ::= N 5 ELSE ''x'' ::= N 6" |
|
88 |
||
89 |
text{* While: *} |
|
90 |
definition "test4_const = |
|
91 |
''x'' ::= N 0; WHILE B True DO ''x'' ::= N 0" |
|
92 |
||
93 |
text{* While, test is ignored: *} |
|
94 |
definition "test5_const = |
|
95 |
''x'' ::= N 0; WHILE Less (V ''x'') (N 1) DO ''x'' ::= N 1" |
|
96 |
||
97 |
text{* Iteration is needed: *} |
|
98 |
definition "test6_const = |
|
99 |
''x'' ::= N 0; ''y'' ::= N 0; ''z'' ::= N 2; |
|
100 |
WHILE Less (V ''x'') (N 1) DO (''x'' ::= V ''y''; ''y'' ::= V ''z'')" |
|
101 |
||
102 |
text{* More iteration would be needed: *} |
|
103 |
definition "test7_const = |
|
104 |
''x'' ::= N 0; ''y'' ::= N 0; ''z'' ::= N 0; ''u'' ::= N 3; |
|
105 |
WHILE Less (V ''x'') (N 1) |
|
106 |
DO (''x'' ::= V ''y''; ''y'' ::= V ''z''; ''z'' ::= V ''u'')" |
|
107 |
||
108 |
value [code] "show_acom (((step_const \<top>)^^0) (\<bottom>\<^sub>c test1_const))" |
|
109 |
value [code] "show_acom (((step_const \<top>)^^1) (\<bottom>\<^sub>c test1_const))" |
|
110 |
value [code] "show_acom (((step_const \<top>)^^2) (\<bottom>\<^sub>c test1_const))" |
|
111 |
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
|
112 |
value [code] "show_acom_opt (AI_const test1_const)" |
45111 | 113 |
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
114 |
value [code] "show_acom_opt (AI_const test2_const)" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
115 |
value [code] "show_acom_opt (AI_const test3_const)" |
45111 | 116 |
|
117 |
value [code] "show_acom (((step_const \<top>)^^0) (\<bottom>\<^sub>c test4_const))" |
|
118 |
value [code] "show_acom (((step_const \<top>)^^1) (\<bottom>\<^sub>c test4_const))" |
|
119 |
value [code] "show_acom (((step_const \<top>)^^2) (\<bottom>\<^sub>c test4_const))" |
|
120 |
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
|
121 |
value [code] "show_acom_opt (AI_const test4_const)" |
45111 | 122 |
|
123 |
value [code] "show_acom (((step_const \<top>)^^0) (\<bottom>\<^sub>c test5_const))" |
|
124 |
value [code] "show_acom (((step_const \<top>)^^1) (\<bottom>\<^sub>c test5_const))" |
|
125 |
value [code] "show_acom (((step_const \<top>)^^2) (\<bottom>\<^sub>c test5_const))" |
|
126 |
value [code] "show_acom (((step_const \<top>)^^3) (\<bottom>\<^sub>c test5_const))" |
|
127 |
value [code] "show_acom (((step_const \<top>)^^4) (\<bottom>\<^sub>c test5_const))" |
|
128 |
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
|
129 |
value [code] "show_acom_opt (AI_const test5_const)" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
130 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
131 |
value [code] "show_acom_opt (AI_const test6_const)" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
132 |
value [code] "show_acom_opt (AI_const test7_const)" |
45111 | 133 |
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
134 |
text{* Monotonicity: *} |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
135 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
136 |
interpretation Abs_Int_mono rep_cval Const plus_cval |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
137 |
proof |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
138 |
case goal1 thus ?case |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
139 |
by(auto simp: plus_cval_cases split: cval.split) |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
140 |
qed |
45111 | 141 |
|
142 |
end |