src/HOL/IMP/ACom.thy
changeset 47818 151d137f1095
parent 47613 e72e44cee6f2
child 49095 7df19036392e
equal deleted inserted replaced
47817:5d2d63f4363e 47818:151d137f1095
     8 definition "show_state xs s = [(x,s x). x \<leftarrow> xs]"
     8 definition "show_state xs s = [(x,s x). x \<leftarrow> xs]"
     9 
     9 
    10 subsection "Annotated Commands"
    10 subsection "Annotated Commands"
    11 
    11 
    12 datatype 'a acom =
    12 datatype 'a acom =
    13   SKIP   'a                           ("SKIP {_}" 61) |
    13   SKIP 'a                           ("SKIP {_}" 61) |
    14   Assign vname aexp 'a                ("(_ ::= _/ {_})" [1000, 61, 0] 61) |
    14   Assign vname aexp 'a              ("(_ ::= _/ {_})" [1000, 61, 0] 61) |
    15   Semi   "('a acom)" "('a acom)"          ("_;//_"  [60, 61] 60) |
    15   Seq "('a acom)" "('a acom)"       ("_;//_"  [60, 61] 60) |
    16   If     bexp "('a acom)" "('a acom)" 'a
    16   If bexp "('a acom)" "('a acom)" 'a
    17     ("(IF _/ THEN _/ ELSE _//{_})"  [0, 0, 61, 0] 61) |
    17     ("(IF _/ THEN _/ ELSE _//{_})"  [0, 0, 61, 0] 61) |
    18   While  'a bexp "('a acom)" 'a
    18   While 'a bexp "('a acom)" 'a
    19     ("({_}//WHILE _/ DO (_)//{_})"  [0, 0, 61, 0] 61)
    19     ("({_}//WHILE _/ DO (_)//{_})"  [0, 0, 61, 0] 61)
    20 
    20 
    21 fun post :: "'a acom \<Rightarrow>'a" where
    21 fun post :: "'a acom \<Rightarrow>'a" where
    22 "post (SKIP {P}) = P" |
    22 "post (SKIP {P}) = P" |
    23 "post (x ::= e {P}) = P" |
    23 "post (x ::= e {P}) = P" |
    70 
    70 
    71 lemma map_acom_Assign:
    71 lemma map_acom_Assign:
    72  "map_acom f c = x ::= e {S'} \<longleftrightarrow> (\<exists>S. c = x::=e {S} \<and> S' = f S)"
    72  "map_acom f c = x ::= e {S'} \<longleftrightarrow> (\<exists>S. c = x::=e {S} \<and> S' = f S)"
    73 by (cases c) auto
    73 by (cases c) auto
    74 
    74 
    75 lemma map_acom_Semi:
    75 lemma map_acom_Seq:
    76  "map_acom f c = c1';c2' \<longleftrightarrow>
    76  "map_acom f c = c1';c2' \<longleftrightarrow>
    77  (\<exists>c1 c2. c = c1;c2 \<and> map_acom f c1 = c1' \<and> map_acom f c2 = c2')"
    77  (\<exists>c1 c2. c = c1;c2 \<and> map_acom f c1 = c1' \<and> map_acom f c2 = c2')"
    78 by (cases c) auto
    78 by (cases c) auto
    79 
    79 
    80 lemma map_acom_If:
    80 lemma map_acom_If:
    97 
    97 
    98 lemma strip_eq_Assign:
    98 lemma strip_eq_Assign:
    99   "strip c = x::=e \<longleftrightarrow> (EX P. c = x::=e {P})"
    99   "strip c = x::=e \<longleftrightarrow> (EX P. c = x::=e {P})"
   100 by (cases c) simp_all
   100 by (cases c) simp_all
   101 
   101 
   102 lemma strip_eq_Semi:
   102 lemma strip_eq_Seq:
   103   "strip c = c1;c2 \<longleftrightarrow> (EX d1 d2. c = d1;d2 & strip d1 = c1 & strip d2 = c2)"
   103   "strip c = c1;c2 \<longleftrightarrow> (EX d1 d2. c = d1;d2 & strip d1 = c1 & strip d2 = c2)"
   104 by (cases c) simp_all
   104 by (cases c) simp_all
   105 
   105 
   106 lemma strip_eq_If:
   106 lemma strip_eq_If:
   107   "strip c = IF b THEN c1 ELSE c2 \<longleftrightarrow>
   107   "strip c = IF b THEN c1 ELSE c2 \<longleftrightarrow>
   117 lemma set_annos_anno[simp]: "set (annos (anno a C)) = {a}"
   117 lemma set_annos_anno[simp]: "set (annos (anno a C)) = {a}"
   118 by(induction C)(auto)
   118 by(induction C)(auto)
   119 
   119 
   120 lemma size_annos_same: "strip C1 = strip C2 \<Longrightarrow> size(annos C1) = size(annos C2)"
   120 lemma size_annos_same: "strip C1 = strip C2 \<Longrightarrow> size(annos C1) = size(annos C2)"
   121 apply(induct C2 arbitrary: C1)
   121 apply(induct C2 arbitrary: C1)
   122 apply (auto simp: strip_eq_SKIP strip_eq_Assign strip_eq_Semi strip_eq_If strip_eq_While)
   122 apply (auto simp: strip_eq_SKIP strip_eq_Assign strip_eq_Seq strip_eq_If strip_eq_While)
   123 done
   123 done
   124 
   124 
   125 lemmas size_annos_same2 = eqTrueI[OF size_annos_same]
   125 lemmas size_annos_same2 = eqTrueI[OF size_annos_same]
   126 
   126 
   127 
   127