src/HOL/IMP/ACom.thy
author nipkow
Wed, 17 Apr 2013 21:23:35 +0200
changeset 51712 30624dab6054
parent 50986 c54ea7f5418f
child 52019 a4cbca8f7342
permissions -rw-r--r--
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
nipkow
parents: 46157
diff changeset
     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
151d137f1095 renamed Semi to Seq
nipkow
parents: 47613
diff changeset
    10
  SKIP 'a                           ("SKIP {_}" 61) |
151d137f1095 renamed Semi to Seq
nipkow
parents: 47613
diff changeset
    11
  Assign vname aexp 'a              ("(_ ::= _/ {_})" [1000, 61, 0] 61) |
151d137f1095 renamed Semi to Seq
nipkow
parents: 47613
diff changeset
    12
  Seq "('a acom)" "('a acom)"       ("_;//_"  [60, 61] 60) |
49095
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
    13
  If bexp 'a "('a acom)" 'a "('a acom)" 'a
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
    14
    ("(IF _/ THEN ({_}/ _)/ ELSE ({_}/ _)//{_})"  [0, 0, 0, 61, 0, 0] 61) |
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
    15
  While 'a bexp 'a "('a acom)" 'a
49138
nipkow
parents: 49095
diff changeset
    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
nipkow
parents: 49477
diff changeset
    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
nipkow
parents: 49477
diff changeset
    22
"post (C\<^isub>1; C\<^isub>2) = post C\<^isub>2" |
nipkow
parents: 49477
diff changeset
    23
"post (IF b THEN {P\<^isub>1} C\<^isub>1 ELSE {P\<^isub>2} C\<^isub>2 {Q}) = Q" |
nipkow
parents: 49477
diff changeset
    24
"post ({I} WHILE b DO {P} C {Q}) = Q"
nipkow
parents: 49477
diff changeset
    25
text_raw{*}%endsnip*}
45623
f682f3f7b726 Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff changeset
    26
49603
nipkow
parents: 49477
diff changeset
    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
579fb74aa409 improved var names
nipkow
parents: 45623
diff changeset
    29
"strip (SKIP {P}) = com.SKIP" |
49603
nipkow
parents: 49477
diff changeset
    30
"strip (x ::= e {P}) = x ::= e" |
nipkow
parents: 49477
diff changeset
    31
"strip (C\<^isub>1;C\<^isub>2) = strip C\<^isub>1; strip C\<^isub>2" |
nipkow
parents: 49477
diff changeset
    32
"strip (IF b THEN {P\<^isub>1} C\<^isub>1 ELSE {P\<^isub>2} C\<^isub>2 {P}) =
nipkow
parents: 49477
diff changeset
    33
  IF b THEN strip C\<^isub>1 ELSE strip C\<^isub>2" |
nipkow
parents: 49477
diff changeset
    34
"strip ({I} WHILE b DO {P} C {Q}) = WHILE b DO strip C"
nipkow
parents: 49477
diff changeset
    35
text_raw{*}%endsnip*}
45623
f682f3f7b726 Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff changeset
    36
49603
nipkow
parents: 49477
diff changeset
    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
nipkow
parents: 49477
diff changeset
    39
"anno A com.SKIP = SKIP {A}" |
nipkow
parents: 49477
diff changeset
    40
"anno A (x ::= e) = x ::= e {A}" |
nipkow
parents: 49477
diff changeset
    41
"anno A (c\<^isub>1;c\<^isub>2) = anno A c\<^isub>1; anno A c\<^isub>2" |
nipkow
parents: 49477
diff changeset
    42
"anno A (IF b THEN c\<^isub>1 ELSE c\<^isub>2) =
nipkow
parents: 49477
diff changeset
    43
  IF b THEN {A} anno A c\<^isub>1 ELSE {A} anno A c\<^isub>2 {A}" |
nipkow
parents: 49477
diff changeset
    44
"anno A (WHILE b DO c) =
nipkow
parents: 49477
diff changeset
    45
  {A} WHILE b DO {A} anno A c {A}"
nipkow
parents: 49477
diff changeset
    46
text_raw{*}%endsnip*}
45623
f682f3f7b726 Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff changeset
    47
49603
nipkow
parents: 49477
diff changeset
    48
text_raw{*\snip{annosdef}{1}{1}{% *}
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents: 46225
diff changeset
    49
fun annos :: "'a acom \<Rightarrow> 'a list" where
49603
nipkow
parents: 49477
diff changeset
    50
"annos (SKIP {P}) = [P]" |
nipkow
parents: 49477
diff changeset
    51
"annos (x ::= e {P}) = [P]" |
nipkow
parents: 49477
diff changeset
    52
"annos (C\<^isub>1;C\<^isub>2) = annos C\<^isub>1 @ annos C\<^isub>2" |
nipkow
parents: 49477
diff changeset
    53
"annos (IF b THEN {P\<^isub>1} C\<^isub>1 ELSE {P\<^isub>2} C\<^isub>2 {Q}) =
nipkow
parents: 49477
diff changeset
    54
  P\<^isub>1 # P\<^isub>2 # Q # annos C\<^isub>1 @ annos C\<^isub>2" |
nipkow
parents: 49477
diff changeset
    55
"annos ({I} WHILE b DO {P} C {Q}) = I # P # Q # annos C"
nipkow
parents: 49477
diff changeset
    56
text_raw{*}%endsnip*}
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents: 46225
diff changeset
    57
49603
nipkow
parents: 49477
diff changeset
    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
579fb74aa409 improved var names
nipkow
parents: 45623
diff changeset
    60
"map_acom f (SKIP {P}) = SKIP {f P}" |
49603
nipkow
parents: 49477
diff changeset
    61
"map_acom f (x ::= e {P}) = x ::= e {f P}" |
nipkow
parents: 49477
diff changeset
    62
"map_acom f (C\<^isub>1;C\<^isub>2) = map_acom f C\<^isub>1; map_acom f C\<^isub>2" |
nipkow
parents: 49477
diff changeset
    63
"map_acom f (IF b THEN {P\<^isub>1} C\<^isub>1 ELSE {P\<^isub>2} C\<^isub>2 {Q}) =
nipkow
parents: 49477
diff changeset
    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
nipkow
parents: 49477
diff changeset
    65
  {f Q}" |
nipkow
parents: 49477
diff changeset
    66
"map_acom f ({I} WHILE b DO {P} C {Q}) =
nipkow
parents: 49477
diff changeset
    67
  {f I} WHILE b DO {f P} map_acom f C {f Q}"
nipkow
parents: 49477
diff changeset
    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
nipkow
parents: 49138
diff changeset
    71
lemma post_map_acom[simp]: "post(map_acom f C) = f(post C)"
nipkow
parents: 49138
diff changeset
    72
by (induction C) simp_all
45623
f682f3f7b726 Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff changeset
    73
49477
nipkow
parents: 49138
diff changeset
    74
lemma strip_acom[simp]: "strip (map_acom f C) = strip C"
nipkow
parents: 49138
diff changeset
    75
by (induction C) auto
45623
f682f3f7b726 Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff changeset
    76
46068
b9d4ec0f79ac tuned proofs
nipkow
parents: 45751
diff changeset
    77
lemma map_acom_SKIP:
49477
nipkow
parents: 49138
diff changeset
    78
 "map_acom f C = SKIP {S'} \<longleftrightarrow> (\<exists>S. C = SKIP {S} \<and> S' = f S)"
nipkow
parents: 49138
diff changeset
    79
by (cases C) auto
46068
b9d4ec0f79ac tuned proofs
nipkow
parents: 45751
diff changeset
    80
b9d4ec0f79ac tuned proofs
nipkow
parents: 45751
diff changeset
    81
lemma map_acom_Assign:
49477
nipkow
parents: 49138
diff changeset
    82
 "map_acom f C = x ::= e {S'} \<longleftrightarrow> (\<exists>S. C = x::=e {S} \<and> S' = f S)"
nipkow
parents: 49138
diff changeset
    83
by (cases C) auto
46068
b9d4ec0f79ac tuned proofs
nipkow
parents: 45751
diff changeset
    84
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 47613
diff changeset
    85
lemma map_acom_Seq:
49477
nipkow
parents: 49138
diff changeset
    86
 "map_acom f C = C1';C2' \<longleftrightarrow>
nipkow
parents: 49138
diff changeset
    87
 (\<exists>C1 C2. C = C1;C2 \<and> map_acom f C1 = C1' \<and> map_acom f C2 = C2')"
nipkow
parents: 49138
diff changeset
    88
by (cases C) auto
46068
b9d4ec0f79ac tuned proofs
nipkow
parents: 45751
diff changeset
    89
b9d4ec0f79ac tuned proofs
nipkow
parents: 45751
diff changeset
    90
lemma map_acom_If:
49477
nipkow
parents: 49138
diff changeset
    91
 "map_acom f C = IF b THEN {P1'} C1' ELSE {P2'} C2' {Q'} \<longleftrightarrow>
nipkow
parents: 49138
diff changeset
    92
 (\<exists>P1 P2 C1 C2 Q. C = IF b THEN {P1} C1 ELSE {P2} C2 {Q} \<and>
nipkow
parents: 49138
diff changeset
    93
     map_acom f C1 = C1' \<and> map_acom f C2 = C2' \<and> P1' = f P1 \<and> P2' = f P2 \<and> Q' = f Q)"
nipkow
parents: 49138
diff changeset
    94
by (cases C) auto
46068
b9d4ec0f79ac tuned proofs
nipkow
parents: 45751
diff changeset
    95
b9d4ec0f79ac tuned proofs
nipkow
parents: 45751
diff changeset
    96
lemma map_acom_While:
49477
nipkow
parents: 49138
diff changeset
    97
 "map_acom f w = {I'} WHILE b DO {p'} C' {P'} \<longleftrightarrow>
nipkow
parents: 49138
diff changeset
    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
b9d4ec0f79ac tuned proofs
nipkow
parents: 45751
diff changeset
    99
by (cases w) auto
b9d4ec0f79ac tuned proofs
nipkow
parents: 45751
diff changeset
   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
3d518b508bbb added lemmas
nipkow
parents: 46068
diff changeset
   105
lemma strip_eq_SKIP:
49095
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
   106
  "strip C = com.SKIP \<longleftrightarrow> (EX P. C = SKIP {P})"
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
   107
by (cases C) simp_all
46157
3d518b508bbb added lemmas
nipkow
parents: 46068
diff changeset
   108
3d518b508bbb added lemmas
nipkow
parents: 46068
diff changeset
   109
lemma strip_eq_Assign:
49095
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
   110
  "strip C = x::=e \<longleftrightarrow> (EX P. C = x::=e {P})"
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
   111
by (cases C) simp_all
46157
3d518b508bbb added lemmas
nipkow
parents: 46068
diff changeset
   112
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 47613
diff changeset
   113
lemma strip_eq_Seq:
49095
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
   114
  "strip C = c1;c2 \<longleftrightarrow> (EX C1 C2. C = C1;C2 & strip C1 = c1 & strip C2 = c2)"
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
   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
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
   118
  "strip C = IF b THEN c1 ELSE c2 \<longleftrightarrow>
49477
nipkow
parents: 49138
diff changeset
   119
  (EX P1 P2 C1 C2 Q. C = IF b THEN {P1} C1 ELSE {P2} C2 {Q} & strip C1 = c1 & strip C2 = c2)"
49095
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
   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
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
   123
  "strip C = WHILE b DO c1 \<longleftrightarrow>
49477
nipkow
parents: 49138
diff changeset
   124
  (EX I P C1 Q. C = {I} WHILE b DO {P} C1 {Q} & strip C1 = c1)"
49095
7df19036392e added annotations after condition in if and while
nipkow
parents: 47818
diff changeset
   125
by (cases C) simp_all
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents: 46225
diff changeset
   126
49477
nipkow
parents: 49138
diff changeset
   127
lemma set_annos_anno[simp]: "set (annos (anno a c)) = {a}"
nipkow
parents: 49138
diff changeset
   128
by(induction c)(auto)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents: 46225
diff changeset
   129
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents: 46225
diff changeset
   130
lemma size_annos_same: "strip C1 = strip C2 \<Longrightarrow> size(annos C1) = size(annos C2)"
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents: 46225
diff changeset
   131
apply(induct C2 arbitrary: C1)
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 47613
diff changeset
   132
apply (auto simp: strip_eq_SKIP strip_eq_Assign strip_eq_Seq strip_eq_If strip_eq_While)
47613
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents: 46225
diff changeset
   133
done
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents: 46225
diff changeset
   134
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents: 46225
diff changeset
   135
lemmas size_annos_same2 = eqTrueI[OF size_annos_same]
e72e44cee6f2 added revised version of Abs_Int
nipkow
parents: 46225
diff changeset
   136
51712
nipkow
parents: 50986
diff changeset
   137
lemma post_in_annos: "post C \<in> set(annos C)"
nipkow
parents: 50986
diff changeset
   138
by(induction C) auto
nipkow
parents: 50986
diff changeset
   139
45623
f682f3f7b726 Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
diff changeset
   140
end