nipkow@45527
|
1 |
(* Author: Tobias Nipkow *)
|
nipkow@45527
|
2 |
|
nipkow@45963
|
3 |
theory Abs_Int_den0_const
|
nipkow@45963
|
4 |
imports Abs_Int_den0
|
nipkow@45527
|
5 |
begin
|
nipkow@45527
|
6 |
|
nipkow@45527
|
7 |
subsection "Constant Propagation"
|
nipkow@45527
|
8 |
|
nipkow@45527
|
9 |
datatype cval = Const val | Any
|
nipkow@45527
|
10 |
|
nipkow@45527
|
11 |
fun rep_cval where
|
nipkow@45527
|
12 |
"rep_cval (Const n) = {n}" |
|
nipkow@45527
|
13 |
"rep_cval (Any) = UNIV"
|
nipkow@45527
|
14 |
|
nipkow@45527
|
15 |
fun plus_cval where
|
nipkow@45527
|
16 |
"plus_cval (Const m) (Const n) = Const(m+n)" |
|
nipkow@45527
|
17 |
"plus_cval _ _ = Any"
|
nipkow@45527
|
18 |
|
nipkow@45527
|
19 |
instantiation cval :: SL_top
|
nipkow@45527
|
20 |
begin
|
nipkow@45527
|
21 |
|
nipkow@45527
|
22 |
fun le_cval where
|
nipkow@45527
|
23 |
"_ \<sqsubseteq> Any = True" |
|
nipkow@45527
|
24 |
"Const n \<sqsubseteq> Const m = (n=m)" |
|
nipkow@45527
|
25 |
"Any \<sqsubseteq> Const _ = False"
|
nipkow@45527
|
26 |
|
nipkow@45527
|
27 |
fun join_cval where
|
nipkow@45527
|
28 |
"Const m \<squnion> Const n = (if n=m then Const m else Any)" |
|
nipkow@45527
|
29 |
"_ \<squnion> _ = Any"
|
nipkow@45527
|
30 |
|
nipkow@45527
|
31 |
definition "Top = Any"
|
nipkow@45527
|
32 |
|
nipkow@45527
|
33 |
instance
|
nipkow@45527
|
34 |
proof
|
nipkow@45527
|
35 |
case goal1 thus ?case by (cases x) simp_all
|
nipkow@45527
|
36 |
next
|
nipkow@45527
|
37 |
case goal2 thus ?case by(cases z, cases y, cases x, simp_all)
|
nipkow@45527
|
38 |
next
|
nipkow@45527
|
39 |
case goal3 thus ?case by(cases x, cases y, simp_all)
|
nipkow@45527
|
40 |
next
|
nipkow@45527
|
41 |
case goal4 thus ?case by(cases y, cases x, simp_all)
|
nipkow@45527
|
42 |
next
|
nipkow@45527
|
43 |
case goal5 thus ?case by(cases z, cases y, cases x, simp_all)
|
nipkow@45527
|
44 |
next
|
nipkow@45527
|
45 |
case goal6 thus ?case by(simp add: Top_cval_def)
|
nipkow@45527
|
46 |
qed
|
nipkow@45527
|
47 |
|
nipkow@45527
|
48 |
end
|
nipkow@45527
|
49 |
|
nipkow@45527
|
50 |
interpretation Rep rep_cval
|
nipkow@45527
|
51 |
proof
|
nipkow@45527
|
52 |
case goal1 thus ?case
|
nipkow@45527
|
53 |
by(cases a, cases b, simp, simp, cases b, simp, simp)
|
nipkow@45527
|
54 |
qed
|
nipkow@45527
|
55 |
|
nipkow@45527
|
56 |
interpretation Val_abs rep_cval Const plus_cval
|
nipkow@45527
|
57 |
proof
|
nipkow@45527
|
58 |
case goal1 show ?case by simp
|
nipkow@45527
|
59 |
next
|
nipkow@45527
|
60 |
case goal2 thus ?case
|
nipkow@45527
|
61 |
by(cases a1, cases a2, simp, simp, cases a2, simp, simp)
|
nipkow@45527
|
62 |
qed
|
nipkow@45527
|
63 |
|
nipkow@45815
|
64 |
interpretation Abs_Int rep_cval Const plus_cval "(iter' 3)"
|
nipkow@45527
|
65 |
defines AI_const is AI
|
nipkow@45527
|
66 |
and aval'_const is aval'
|
nipkow@45815
|
67 |
proof qed (auto simp: iter'_pfp_above)
|
nipkow@45527
|
68 |
|
nipkow@45527
|
69 |
text{* Straight line code: *}
|
nipkow@45527
|
70 |
definition "test1_const =
|
nipkow@45527
|
71 |
''y'' ::= N 7;
|
nipkow@45527
|
72 |
''z'' ::= Plus (V ''y'') (N 2);
|
nipkow@45527
|
73 |
''y'' ::= Plus (V ''x'') (N 0)"
|
nipkow@45527
|
74 |
|
nipkow@45527
|
75 |
text{* Conditional: *}
|
nipkow@45527
|
76 |
definition "test2_const =
|
nipkow@45527
|
77 |
IF Less (N 41) (V ''x'') THEN ''x'' ::= N 5 ELSE ''x'' ::= N 5"
|
nipkow@45527
|
78 |
|
nipkow@45527
|
79 |
text{* Conditional, test is ignored: *}
|
nipkow@45527
|
80 |
definition "test3_const =
|
nipkow@45527
|
81 |
''x'' ::= N 42;
|
nipkow@45527
|
82 |
IF Less (N 41) (V ''x'') THEN ''x'' ::= N 5 ELSE ''x'' ::= N 6"
|
nipkow@45527
|
83 |
|
nipkow@45527
|
84 |
text{* While: *}
|
nipkow@45527
|
85 |
definition "test4_const =
|
nipkow@45527
|
86 |
''x'' ::= N 0; WHILE B True DO ''x'' ::= N 0"
|
nipkow@45527
|
87 |
|
nipkow@45527
|
88 |
text{* While, test is ignored: *}
|
nipkow@45527
|
89 |
definition "test5_const =
|
nipkow@45527
|
90 |
''x'' ::= N 0; WHILE Less (V ''x'') (N 1) DO ''x'' ::= N 1"
|
nipkow@45527
|
91 |
|
nipkow@45527
|
92 |
text{* Iteration is needed: *}
|
nipkow@45527
|
93 |
definition "test6_const =
|
nipkow@45527
|
94 |
''x'' ::= N 0; ''y'' ::= N 0; ''z'' ::= N 2;
|
nipkow@45527
|
95 |
WHILE Less (V ''x'') (N 1) DO (''x'' ::= V ''y''; ''y'' ::= V ''z'')"
|
nipkow@45527
|
96 |
|
nipkow@45527
|
97 |
text{* More iteration would be needed: *}
|
nipkow@45527
|
98 |
definition "test7_const =
|
nipkow@45527
|
99 |
''x'' ::= N 0; ''y'' ::= N 0; ''z'' ::= N 0; ''u'' ::= N 3;
|
nipkow@45803
|
100 |
WHILE Less (V ''x'') (N 1)
|
nipkow@45803
|
101 |
DO (''x'' ::= V ''y''; ''y'' ::= V ''z''; ''z'' ::= V ''u'')"
|
nipkow@45803
|
102 |
|
nipkow@45803
|
103 |
value [code] "list (AI_const test1_const Top)"
|
nipkow@45803
|
104 |
value [code] "list (AI_const test2_const Top)"
|
nipkow@45803
|
105 |
value [code] "list (AI_const test3_const Top)"
|
nipkow@45803
|
106 |
value [code] "list (AI_const test4_const Top)"
|
nipkow@45803
|
107 |
value [code] "list (AI_const test5_const Top)"
|
nipkow@45803
|
108 |
value [code] "list (AI_const test6_const Top)"
|
nipkow@45527
|
109 |
value [code] "list (AI_const test7_const Top)"
|
nipkow@45527
|
110 |
|
nipkow@45527
|
111 |
end
|