src/HOL/IMP/Live.thy
author nipkow
Tue, 20 Sep 2011 05:48:23 +0200
changeset 45015 fdac1e9880eb
parent 44923 b80108b346a9
child 45212 e87feee00a4c
permissions -rw-r--r--
Updated IMP to use new induction method
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     1
(* Author: Tobias Nipkow *)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     2
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     3
header "Live Variable Analysis"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     4
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     5
theory Live imports Vars Big_Step
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     6
begin
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     7
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     8
subsection "Liveness Analysis"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     9
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    10
fun L :: "com \<Rightarrow> name set \<Rightarrow> name set" where
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    11
"L SKIP X = X" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    12
"L (x ::= a) X = X-{x} \<union> vars a" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    13
"L (c\<^isub>1; c\<^isub>2) X = (L c\<^isub>1 \<circ> L c\<^isub>2) X" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    14
"L (IF b THEN c\<^isub>1 ELSE c\<^isub>2) X = vars b \<union> L c\<^isub>1 X \<union> L c\<^isub>2 X" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    15
"L (WHILE b DO c) X = vars b \<union> X \<union> L c X"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    16
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    17
value "show (L (''y'' ::= V ''z''; ''x'' ::= Plus (V ''y'') (V ''z'')) {''x''})"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    18
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    19
value "show (L (WHILE Less (V ''x'') (V ''x'') DO ''y'' ::= V ''z'') {''x''})"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    20
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    21
fun "kill" :: "com \<Rightarrow> name set" where
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    22
"kill SKIP = {}" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    23
"kill (x ::= a) = {x}" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    24
"kill (c\<^isub>1; c\<^isub>2) = kill c\<^isub>1 \<union> kill c\<^isub>2" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    25
"kill (IF b THEN c\<^isub>1 ELSE c\<^isub>2) = kill c\<^isub>1 \<inter> kill c\<^isub>2" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    26
"kill (WHILE b DO c) = {}"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    27
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    28
fun gen :: "com \<Rightarrow> name set" where
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    29
"gen SKIP = {}" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    30
"gen (x ::= a) = vars a" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    31
"gen (c\<^isub>1; c\<^isub>2) = gen c\<^isub>1 \<union> (gen c\<^isub>2 - kill c\<^isub>1)" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    32
"gen (IF b THEN c\<^isub>1 ELSE c\<^isub>2) = vars b \<union> gen c\<^isub>1 \<union> gen c\<^isub>2" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    33
"gen (WHILE b DO c) = vars b \<union> gen c"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    34
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    35
lemma L_gen_kill: "L c X = (X - kill c) \<union> gen c"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    36
by(induct c arbitrary:X) auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    37
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    38
lemma L_While_subset: "L c (L (WHILE b DO c) X) \<subseteq> L (WHILE b DO c) X"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    39
by(auto simp add:L_gen_kill)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    40
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    41
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    42
subsection "Soundness"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    43
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    44
theorem L_sound:
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    45
  "(c,s) \<Rightarrow> s'  \<Longrightarrow> s = t on L c X \<Longrightarrow>
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    46
  \<exists> t'. (c,t) \<Rightarrow> t' & s' = t' on X"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
    47
proof (induction arbitrary: X t rule: big_step_induct)
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    48
  case Skip then show ?case by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    49
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    50
  case Assign then show ?case
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    51
    by (auto simp: ball_Un)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    52
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    53
  case (Semi c1 s1 s2 c2 s3 X t1)
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
    54
  from Semi.IH(1) Semi.prems obtain t2 where
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    55
    t12: "(c1, t1) \<Rightarrow> t2" and s2t2: "s2 = t2 on L c2 X"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    56
    by simp blast
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
    57
  from Semi.IH(2)[OF s2t2] obtain t3 where
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    58
    t23: "(c2, t2) \<Rightarrow> t3" and s3t3: "s3 = t3 on X"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    59
    by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    60
  show ?case using t12 t23 s3t3 by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    61
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    62
  case (IfTrue b s c1 s' c2)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    63
  hence "s = t on vars b" "s = t on L c1 X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    64
  from  bval_eq_if_eq_on_vars[OF this(1)] IfTrue(1) have "bval b t" by simp
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    65
  from IfTrue(3)[OF `s = t on L c1 X`] obtain t' where
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    66
    "(c1, t) \<Rightarrow> t'" "s' = t' on X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    67
  thus ?case using `bval b t` by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    68
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    69
  case (IfFalse b s c2 s' c1)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    70
  hence "s = t on vars b" "s = t on L c2 X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    71
  from  bval_eq_if_eq_on_vars[OF this(1)] IfFalse(1) have "~bval b t" by simp
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    72
  from IfFalse(3)[OF `s = t on L c2 X`] obtain t' where
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    73
    "(c2, t) \<Rightarrow> t'" "s' = t' on X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    74
  thus ?case using `~bval b t` by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    75
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    76
  case (WhileFalse b s c)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    77
  hence "~ bval b t" by (auto simp: ball_Un) (metis bval_eq_if_eq_on_vars)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    78
  thus ?case using WhileFalse(2) by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    79
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    80
  case (WhileTrue b s1 c s2 s3 X t1)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    81
  let ?w = "WHILE b DO c"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    82
  from `bval b s1` WhileTrue(6) have "bval b t1"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    83
    by (auto simp: ball_Un) (metis bval_eq_if_eq_on_vars)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    84
  have "s1 = t1 on L c (L ?w X)" using  L_While_subset WhileTrue.prems
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    85
    by (blast)
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
    86
  from WhileTrue.IH(1)[OF this] obtain t2 where
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    87
    "(c, t1) \<Rightarrow> t2" "s2 = t2 on L ?w X" by auto
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
    88
  from WhileTrue.IH(2)[OF this(2)] obtain t3 where "(?w,t2) \<Rightarrow> t3" "s3 = t3 on X"
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    89
    by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    90
  with `bval b t1` `(c, t1) \<Rightarrow> t2` show ?case by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    91
qed
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    92
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    93
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    94
subsection "Program Optimization"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    95
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    96
text{* Burying assignments to dead variables: *}
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    97
fun bury :: "com \<Rightarrow> name set \<Rightarrow> com" where
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    98
"bury SKIP X = SKIP" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    99
"bury (x ::= a) X = (if x:X then x::= a else SKIP)" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   100
"bury (c\<^isub>1; c\<^isub>2) X = (bury c\<^isub>1 (L c\<^isub>2 X); bury c\<^isub>2 X)" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   101
"bury (IF b THEN c\<^isub>1 ELSE c\<^isub>2) X = IF b THEN bury c\<^isub>1 X ELSE bury c\<^isub>2 X" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   102
"bury (WHILE b DO c) X = WHILE b DO bury c (vars b \<union> X \<union> L c X)"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   103
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   104
text{* We could prove the analogous lemma to @{thm[source]L_sound}, and the
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   105
proof would be very similar. However, we phrase it as a semantics
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   106
preservation property: *}
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   107
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   108
theorem bury_sound:
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   109
  "(c,s) \<Rightarrow> s'  \<Longrightarrow> s = t on L c X \<Longrightarrow>
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   110
  \<exists> t'. (bury c X,t) \<Rightarrow> t' & s' = t' on X"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   111
proof (induction arbitrary: X t rule: big_step_induct)
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   112
  case Skip then show ?case by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   113
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   114
  case Assign then show ?case
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   115
    by (auto simp: ball_Un)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   116
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   117
  case (Semi c1 s1 s2 c2 s3 X t1)
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   118
  from Semi.IH(1) Semi.prems obtain t2 where
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   119
    t12: "(bury c1 (L c2 X), t1) \<Rightarrow> t2" and s2t2: "s2 = t2 on L c2 X"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   120
    by simp blast
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   121
  from Semi.IH(2)[OF s2t2] obtain t3 where
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   122
    t23: "(bury c2 X, t2) \<Rightarrow> t3" and s3t3: "s3 = t3 on X"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   123
    by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   124
  show ?case using t12 t23 s3t3 by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   125
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   126
  case (IfTrue b s c1 s' c2)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   127
  hence "s = t on vars b" "s = t on L c1 X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   128
  from  bval_eq_if_eq_on_vars[OF this(1)] IfTrue(1) have "bval b t" by simp
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   129
  from IfTrue(3)[OF `s = t on L c1 X`] obtain t' where
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   130
    "(bury c1 X, t) \<Rightarrow> t'" "s' =t' on X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   131
  thus ?case using `bval b t` by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   132
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   133
  case (IfFalse b s c2 s' c1)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   134
  hence "s = t on vars b" "s = t on L c2 X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   135
  from  bval_eq_if_eq_on_vars[OF this(1)] IfFalse(1) have "~bval b t" by simp
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   136
  from IfFalse(3)[OF `s = t on L c2 X`] obtain t' where
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   137
    "(bury c2 X, t) \<Rightarrow> t'" "s' = t' on X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   138
  thus ?case using `~bval b t` by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   139
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   140
  case (WhileFalse b s c)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   141
  hence "~ bval b t" by (auto simp: ball_Un) (metis bval_eq_if_eq_on_vars)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   142
  thus ?case using WhileFalse(2) by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   143
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   144
  case (WhileTrue b s1 c s2 s3 X t1)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   145
  let ?w = "WHILE b DO c"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   146
  from `bval b s1` WhileTrue(6) have "bval b t1"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   147
    by (auto simp: ball_Un) (metis bval_eq_if_eq_on_vars)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   148
  have "s1 = t1 on L c (L ?w X)"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   149
    using L_While_subset WhileTrue.prems by blast
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   150
  from WhileTrue.IH(1)[OF this] obtain t2 where
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   151
    "(bury c (L ?w X), t1) \<Rightarrow> t2" "s2 = t2 on L ?w X" by auto
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   152
  from WhileTrue.IH(2)[OF this(2)] obtain t3
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   153
    where "(bury ?w X,t2) \<Rightarrow> t3" "s3 = t3 on X"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   154
    by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   155
  with `bval b t1` `(bury c (L ?w X), t1) \<Rightarrow> t2` show ?case by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   156
qed
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   157
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   158
corollary final_bury_sound: "(c,s) \<Rightarrow> s' \<Longrightarrow> (bury c UNIV,s) \<Rightarrow> s'"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   159
using bury_sound[of c s s' UNIV]
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   160
by (auto simp: fun_eq_iff[symmetric])
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   161
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   162
text{* Now the opposite direction. *}
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   163
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   164
lemma SKIP_bury[simp]:
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   165
  "SKIP = bury c X \<longleftrightarrow> c = SKIP | (EX x a. c = x::=a & x \<notin> X)"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   166
by (cases c) auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   167
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   168
lemma Assign_bury[simp]: "x::=a = bury c X \<longleftrightarrow> c = x::=a & x : X"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   169
by (cases c) auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   170
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   171
lemma Semi_bury[simp]: "bc\<^isub>1;bc\<^isub>2 = bury c X \<longleftrightarrow>
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   172
  (EX c\<^isub>1 c\<^isub>2. c = c\<^isub>1;c\<^isub>2 & bc\<^isub>2 = bury c\<^isub>2 X & bc\<^isub>1 = bury c\<^isub>1 (L c\<^isub>2 X))"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   173
by (cases c) auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   174
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   175
lemma If_bury[simp]: "IF b THEN bc1 ELSE bc2 = bury c X \<longleftrightarrow>
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   176
  (EX c1 c2. c = IF b THEN c1 ELSE c2 &
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   177
     bc1 = bury c1 X & bc2 = bury c2 X)"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   178
by (cases c) auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   179
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   180
lemma While_bury[simp]: "WHILE b DO bc' = bury c X \<longleftrightarrow>
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   181
  (EX c'. c = WHILE b DO c' & bc' = bury c' (vars b \<union> X \<union> L c X))"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   182
by (cases c) auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   183
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   184
theorem bury_sound2:
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   185
  "(bury c X,s) \<Rightarrow> s'  \<Longrightarrow> s = t on L c X \<Longrightarrow>
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   186
  \<exists> t'. (c,t) \<Rightarrow> t' & s' = t' on X"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   187
proof (induction "bury c X" s s' arbitrary: c X t rule: big_step_induct)
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   188
  case Skip then show ?case by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   189
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   190
  case Assign then show ?case
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   191
    by (auto simp: ball_Un)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   192
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   193
  case (Semi bc1 s1 s2 bc2 s3 c X t1)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   194
  then obtain c1 c2 where c: "c = c1;c2"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   195
    and bc2: "bc2 = bury c2 X" and bc1: "bc1 = bury c1 (L c2 X)" by auto
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   196
  note IH = Semi.hyps(2,4)
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   197
  from IH(1)[OF bc1, of t1] Semi.prems c obtain t2 where
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   198
    t12: "(c1, t1) \<Rightarrow> t2" and s2t2: "s2 = t2 on L c2 X" by auto
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   199
  from IH(2)[OF bc2 s2t2] obtain t3 where
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   200
    t23: "(c2, t2) \<Rightarrow> t3" and s3t3: "s3 = t3 on X"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   201
    by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   202
  show ?case using c t12 t23 s3t3 by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   203
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   204
  case (IfTrue b s bc1 s' bc2)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   205
  then obtain c1 c2 where c: "c = IF b THEN c1 ELSE c2"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   206
    and bc1: "bc1 = bury c1 X" and bc2: "bc2 = bury c2 X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   207
  have "s = t on vars b" "s = t on L c1 X" using IfTrue.prems c by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   208
  from bval_eq_if_eq_on_vars[OF this(1)] IfTrue(1) have "bval b t" by simp
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   209
  note IH = IfTrue.hyps(3)
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   210
  from IH[OF bc1 `s = t on L c1 X`] obtain t' where
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   211
    "(c1, t) \<Rightarrow> t'" "s' =t' on X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   212
  thus ?case using c `bval b t` by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   213
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   214
  case (IfFalse b s bc2 s' bc1)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   215
  then obtain c1 c2 where c: "c = IF b THEN c1 ELSE c2"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   216
    and bc1: "bc1 = bury c1 X" and bc2: "bc2 = bury c2 X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   217
  have "s = t on vars b" "s = t on L c2 X" using IfFalse.prems c by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   218
  from bval_eq_if_eq_on_vars[OF this(1)] IfFalse(1) have "~bval b t" by simp
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   219
  note IH = IfFalse.hyps(3)
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   220
  from IH[OF bc2 `s = t on L c2 X`] obtain t' where
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   221
    "(c2, t) \<Rightarrow> t'" "s' =t' on X" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   222
  thus ?case using c `~bval b t` by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   223
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   224
  case (WhileFalse b s c)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   225
  hence "~ bval b t" by (auto simp: ball_Un dest: bval_eq_if_eq_on_vars)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   226
  thus ?case using WhileFalse by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   227
next
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   228
  case (WhileTrue b s1 bc' s2 s3 c X t1)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   229
  then obtain c' where c: "c = WHILE b DO c'"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   230
    and bc': "bc' = bury c' (vars b \<union> X \<union> L c' X)" by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   231
  let ?w = "WHILE b DO c'"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   232
  from `bval b s1` WhileTrue.prems c have "bval b t1"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   233
    by (auto simp: ball_Un) (metis bval_eq_if_eq_on_vars)
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   234
  note IH = WhileTrue.hyps(3,5)
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   235
  have "s1 = t1 on L c' (L ?w X)"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   236
    using L_While_subset WhileTrue.prems c by blast
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   237
  with IH(1)[OF bc', of t1] obtain t2 where
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   238
    "(c', t1) \<Rightarrow> t2" "s2 = t2 on L ?w X" by auto
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44923
diff changeset
   239
  from IH(2)[OF WhileTrue.hyps(6), of t2] c this(2) obtain t3
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   240
    where "(?w,t2) \<Rightarrow> t3" "s3 = t3 on X"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   241
    by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   242
  with `bval b t1` `(c', t1) \<Rightarrow> t2` c show ?case by auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   243
qed
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   244
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   245
corollary final_bury_sound2: "(bury c UNIV,s) \<Rightarrow> s' \<Longrightarrow> (c,s) \<Rightarrow> s'"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   246
using bury_sound2[of c UNIV]
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   247
by (auto simp: fun_eq_iff[symmetric])
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   248
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   249
corollary bury_iff: "(bury c UNIV,s) \<Rightarrow> s' \<longleftrightarrow> (c,s) \<Rightarrow> s'"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   250
by(metis final_bury_sound final_bury_sound2)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   251
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
   252
end