author | nipkow |
Wed, 17 Apr 2013 21:23:35 +0200 | |
changeset 51712 | 30624dab6054 |
parent 50986 | c54ea7f5418f |
child 52019 | a4cbca8f7342 |
permissions | -rw-r--r-- |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
1 |
(* Author: Tobias Nipkow *) |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
2 |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
3 |
theory ACom |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
4 |
imports Com |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
5 |
begin |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
6 |
|
46225 | 7 |
subsection "Annotated Commands" |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
8 |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
9 |
datatype 'a acom = |
47818 | 10 |
SKIP 'a ("SKIP {_}" 61) | |
11 |
Assign vname aexp 'a ("(_ ::= _/ {_})" [1000, 61, 0] 61) | |
|
12 |
Seq "('a acom)" "('a acom)" ("_;//_" [60, 61] 60) | |
|
49095 | 13 |
If bexp 'a "('a acom)" 'a "('a acom)" 'a |
14 |
("(IF _/ THEN ({_}/ _)/ ELSE ({_}/ _)//{_})" [0, 0, 0, 61, 0, 0] 61) | |
|
15 |
While 'a bexp 'a "('a acom)" 'a |
|
49138 | 16 |
("({_}//WHILE _//DO ({_}//_)//{_})" [0, 0, 0, 61, 0] 61) |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
17 |
|
49603 | 18 |
text_raw{*\snip{postdef}{2}{1}{% *} |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
19 |
fun post :: "'a acom \<Rightarrow>'a" where |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
20 |
"post (SKIP {P}) = P" | |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
21 |
"post (x ::= e {P}) = P" | |
49603 | 22 |
"post (C\<^isub>1; C\<^isub>2) = post C\<^isub>2" | |
23 |
"post (IF b THEN {P\<^isub>1} C\<^isub>1 ELSE {P\<^isub>2} C\<^isub>2 {Q}) = Q" | |
|
24 |
"post ({I} WHILE b DO {P} C {Q}) = Q" |
|
25 |
text_raw{*}%endsnip*} |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
26 |
|
49603 | 27 |
text_raw{*\snip{stripdef}{1}{1}{% *} |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
28 |
fun strip :: "'a acom \<Rightarrow> com" where |
45746 | 29 |
"strip (SKIP {P}) = com.SKIP" | |
49603 | 30 |
"strip (x ::= e {P}) = x ::= e" | |
31 |
"strip (C\<^isub>1;C\<^isub>2) = strip C\<^isub>1; strip C\<^isub>2" | |
|
32 |
"strip (IF b THEN {P\<^isub>1} C\<^isub>1 ELSE {P\<^isub>2} C\<^isub>2 {P}) = |
|
33 |
IF b THEN strip C\<^isub>1 ELSE strip C\<^isub>2" | |
|
34 |
"strip ({I} WHILE b DO {P} C {Q}) = WHILE b DO strip C" |
|
35 |
text_raw{*}%endsnip*} |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
36 |
|
49603 | 37 |
text_raw{*\snip{annodef}{1}{1}{% *} |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
38 |
fun anno :: "'a \<Rightarrow> com \<Rightarrow> 'a acom" where |
49603 | 39 |
"anno A com.SKIP = SKIP {A}" | |
40 |
"anno A (x ::= e) = x ::= e {A}" | |
|
41 |
"anno A (c\<^isub>1;c\<^isub>2) = anno A c\<^isub>1; anno A c\<^isub>2" | |
|
42 |
"anno A (IF b THEN c\<^isub>1 ELSE c\<^isub>2) = |
|
43 |
IF b THEN {A} anno A c\<^isub>1 ELSE {A} anno A c\<^isub>2 {A}" | |
|
44 |
"anno A (WHILE b DO c) = |
|
45 |
{A} WHILE b DO {A} anno A c {A}" |
|
46 |
text_raw{*}%endsnip*} |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
47 |
|
49603 | 48 |
text_raw{*\snip{annosdef}{1}{1}{% *} |
47613 | 49 |
fun annos :: "'a acom \<Rightarrow> 'a list" where |
49603 | 50 |
"annos (SKIP {P}) = [P]" | |
51 |
"annos (x ::= e {P}) = [P]" | |
|
52 |
"annos (C\<^isub>1;C\<^isub>2) = annos C\<^isub>1 @ annos C\<^isub>2" | |
|
53 |
"annos (IF b THEN {P\<^isub>1} C\<^isub>1 ELSE {P\<^isub>2} C\<^isub>2 {Q}) = |
|
54 |
P\<^isub>1 # P\<^isub>2 # Q # annos C\<^isub>1 @ annos C\<^isub>2" | |
|
55 |
"annos ({I} WHILE b DO {P} C {Q}) = I # P # Q # annos C" |
|
56 |
text_raw{*}%endsnip*} |
|
47613 | 57 |
|
49603 | 58 |
text_raw{*\snip{mapacomdef}{1}{2}{% *} |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
59 |
fun map_acom :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a acom \<Rightarrow> 'b acom" where |
45746 | 60 |
"map_acom f (SKIP {P}) = SKIP {f P}" | |
49603 | 61 |
"map_acom f (x ::= e {P}) = x ::= e {f P}" | |
62 |
"map_acom f (C\<^isub>1;C\<^isub>2) = map_acom f C\<^isub>1; map_acom f C\<^isub>2" | |
|
63 |
"map_acom f (IF b THEN {P\<^isub>1} C\<^isub>1 ELSE {P\<^isub>2} C\<^isub>2 {Q}) = |
|
64 |
IF b THEN {f P\<^isub>1} map_acom f C\<^isub>1 ELSE {f P\<^isub>2} map_acom f C\<^isub>2 |
|
65 |
{f Q}" | |
|
66 |
"map_acom f ({I} WHILE b DO {P} C {Q}) = |
|
67 |
{f I} WHILE b DO {f P} map_acom f C {f Q}" |
|
68 |
text_raw{*}%endsnip*} |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
69 |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
70 |
|
49477 | 71 |
lemma post_map_acom[simp]: "post(map_acom f C) = f(post C)" |
72 |
by (induction C) simp_all |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
73 |
|
49477 | 74 |
lemma strip_acom[simp]: "strip (map_acom f C) = strip C" |
75 |
by (induction C) auto |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
76 |
|
46068 | 77 |
lemma map_acom_SKIP: |
49477 | 78 |
"map_acom f C = SKIP {S'} \<longleftrightarrow> (\<exists>S. C = SKIP {S} \<and> S' = f S)" |
79 |
by (cases C) auto |
|
46068 | 80 |
|
81 |
lemma map_acom_Assign: |
|
49477 | 82 |
"map_acom f C = x ::= e {S'} \<longleftrightarrow> (\<exists>S. C = x::=e {S} \<and> S' = f S)" |
83 |
by (cases C) auto |
|
46068 | 84 |
|
47818 | 85 |
lemma map_acom_Seq: |
49477 | 86 |
"map_acom f C = C1';C2' \<longleftrightarrow> |
87 |
(\<exists>C1 C2. C = C1;C2 \<and> map_acom f C1 = C1' \<and> map_acom f C2 = C2')" |
|
88 |
by (cases C) auto |
|
46068 | 89 |
|
90 |
lemma map_acom_If: |
|
49477 | 91 |
"map_acom f C = IF b THEN {P1'} C1' ELSE {P2'} C2' {Q'} \<longleftrightarrow> |
92 |
(\<exists>P1 P2 C1 C2 Q. C = IF b THEN {P1} C1 ELSE {P2} C2 {Q} \<and> |
|
93 |
map_acom f C1 = C1' \<and> map_acom f C2 = C2' \<and> P1' = f P1 \<and> P2' = f P2 \<and> Q' = f Q)" |
|
94 |
by (cases C) auto |
|
46068 | 95 |
|
96 |
lemma map_acom_While: |
|
49477 | 97 |
"map_acom f w = {I'} WHILE b DO {p'} C' {P'} \<longleftrightarrow> |
98 |
(\<exists>I p P C. w = {I} WHILE b DO {p} C {P} \<and> map_acom f C = C' \<and> I' = f I \<and> p' = f p \<and> P' = f P)" |
|
46068 | 99 |
by (cases w) auto |
100 |
||
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
101 |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
102 |
lemma strip_anno[simp]: "strip (anno a c) = c" |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
103 |
by(induct c) simp_all |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
104 |
|
46157 | 105 |
lemma strip_eq_SKIP: |
49095 | 106 |
"strip C = com.SKIP \<longleftrightarrow> (EX P. C = SKIP {P})" |
107 |
by (cases C) simp_all |
|
46157 | 108 |
|
109 |
lemma strip_eq_Assign: |
|
49095 | 110 |
"strip C = x::=e \<longleftrightarrow> (EX P. C = x::=e {P})" |
111 |
by (cases C) simp_all |
|
46157 | 112 |
|
47818 | 113 |
lemma strip_eq_Seq: |
49095 | 114 |
"strip C = c1;c2 \<longleftrightarrow> (EX C1 C2. C = C1;C2 & strip C1 = c1 & strip C2 = c2)" |
115 |
by (cases C) simp_all |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
116 |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
117 |
lemma strip_eq_If: |
49095 | 118 |
"strip C = IF b THEN c1 ELSE c2 \<longleftrightarrow> |
49477 | 119 |
(EX P1 P2 C1 C2 Q. C = IF b THEN {P1} C1 ELSE {P2} C2 {Q} & strip C1 = c1 & strip C2 = c2)" |
49095 | 120 |
by (cases C) simp_all |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
121 |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
122 |
lemma strip_eq_While: |
49095 | 123 |
"strip C = WHILE b DO c1 \<longleftrightarrow> |
49477 | 124 |
(EX I P C1 Q. C = {I} WHILE b DO {P} C1 {Q} & strip C1 = c1)" |
49095 | 125 |
by (cases C) simp_all |
47613 | 126 |
|
49477 | 127 |
lemma set_annos_anno[simp]: "set (annos (anno a c)) = {a}" |
128 |
by(induction c)(auto) |
|
47613 | 129 |
|
130 |
lemma size_annos_same: "strip C1 = strip C2 \<Longrightarrow> size(annos C1) = size(annos C2)" |
|
131 |
apply(induct C2 arbitrary: C1) |
|
47818 | 132 |
apply (auto simp: strip_eq_SKIP strip_eq_Assign strip_eq_Seq strip_eq_If strip_eq_While) |
47613 | 133 |
done |
134 |
||
135 |
lemmas size_annos_same2 = eqTrueI[OF size_annos_same] |
|
136 |
||
51712 | 137 |
lemma post_in_annos: "post C \<in> set(annos C)" |
138 |
by(induction C) auto |
|
139 |
||
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff
changeset
|
140 |
end |