src/HOL/IMP/Live.thy
author nipkow
Tue, 07 Sep 2010 10:05:19 +0200
changeset 39198 f967a16dfcdd
parent 35802 362431732b5e
child 39302 d7728f65b353
permissions -rw-r--r--
expand_fun_eq -> ext_iff expand_set_eq -> set_ext_iff Naming in line now with multisets
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28583
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
     1
theory Live imports Natural
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
     2
begin
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
     3
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
     4
text{* Which variables/locations does an expression depend on?
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
     5
Any set of variables that completely determine the value of the expression,
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
     6
in the worst case all locations: *}
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
     7
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
     8
consts Dep :: "((loc \<Rightarrow> 'a) \<Rightarrow> 'b) \<Rightarrow> loc set"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
     9
specification (Dep)
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    10
dep_on: "(\<forall>x\<in>Dep e. s x = t x) \<Longrightarrow> e s = e t"
39198
f967a16dfcdd expand_fun_eq -> ext_iff
nipkow
parents: 35802
diff changeset
    11
by(rule_tac x="%x. UNIV" in exI)(simp add: ext_iff[symmetric])
28583
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    12
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    13
text{* The following definition of @{const Dep} looks very tempting
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    14
@{prop"Dep e = {a. EX s t. (ALL x. x\<noteq>a \<longrightarrow> s x = t x) \<and> e s \<noteq> e t}"}
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    15
but does not work in case @{text e} depends on an infinite set of variables.
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    16
For example, if @{term"e s"} tests if @{text s} is 0 at infinitely many locations. Then @{term"Dep e"} incorrectly yields the empty set!
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    17
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    18
If we had a concrete representation of expressions, we would simply write
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    19
a recursive free-variables function.
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    20
*}
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    21
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    22
primrec L :: "com \<Rightarrow> loc set \<Rightarrow> loc set" where
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    23
"L SKIP A = A" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    24
"L (x :== e) A = A-{x} \<union> Dep e" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    25
"L (c1; c2) A = (L c1 \<circ> L c2) A" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    26
"L (IF b THEN c1 ELSE c2) A = Dep b \<union> L c1 A \<union> L c2 A" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    27
"L (WHILE b DO c) A = Dep b \<union> A \<union> L c A"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    28
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    29
primrec "kill" :: "com \<Rightarrow> loc set" where
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    30
"kill SKIP = {}" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    31
"kill (x :== e) = {x}" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    32
"kill (c1; c2) = kill c1 \<union> kill c2" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    33
"kill (IF b THEN c1 ELSE c2) = Dep b \<union> kill c1 \<inter>  kill c2" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    34
"kill (WHILE b DO c) = {}"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    35
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    36
primrec gen :: "com \<Rightarrow> loc set" where
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    37
"gen SKIP = {}" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    38
"gen (x :== e) = Dep e" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    39
"gen (c1; c2) = gen c1 \<union> (gen c2-kill c1)" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    40
"gen (IF b THEN c1 ELSE c2) = Dep b \<union> gen c1 \<union> gen c2" |
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    41
"gen (WHILE b DO c) = Dep b \<union> gen c"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    42
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    43
lemma L_gen_kill: "L c A = gen c \<union> (A - kill c)"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    44
by(induct c arbitrary:A) auto
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    45
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    46
lemma L_idemp: "L c (L c A) \<subseteq> L c A"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    47
by(fastsimp simp add:L_gen_kill)
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    48
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    49
theorem L_sound: "\<forall> x \<in> L c A. s x = t x \<Longrightarrow> \<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s' \<Longrightarrow> \<langle>c,t\<rangle> \<longrightarrow>\<^sub>c t' \<Longrightarrow>
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    50
 \<forall>x\<in>A. s' x = t' x"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    51
proof (induct c arbitrary: A s t s' t')
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    52
  case SKIP then show ?case by auto
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    53
next
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    54
  case (Assign x e) then show ?case
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    55
    by (auto simp:update_def ball_Un dest!: dep_on)
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    56
next
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    57
  case (Semi c1 c2)
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    58
  from Semi(4) obtain s'' where s1: "\<langle>c1,s\<rangle> \<longrightarrow>\<^sub>c s''" and s2: "\<langle>c2,s''\<rangle> \<longrightarrow>\<^sub>c s'"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    59
    by auto
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    60
  from Semi(5) obtain t'' where t1: "\<langle>c1,t\<rangle> \<longrightarrow>\<^sub>c t''" and t2: "\<langle>c2,t''\<rangle> \<longrightarrow>\<^sub>c t'"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    61
    by auto
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    62
  show ?case using Semi(1)[OF _ s1 t1] Semi(2)[OF _ s2 t2] Semi(3) by fastsimp
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    63
next
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    64
  case (Cond b c1 c2)
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    65
  show ?case
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    66
  proof cases
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    67
    assume "b s"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    68
    hence s: "\<langle>c1,s\<rangle> \<longrightarrow>\<^sub>c s'" using Cond(4) by simp
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    69
    have "b t" using `b s` Cond(3) by (simp add: ball_Un)(blast dest: dep_on)
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    70
    hence t: "\<langle>c1,t\<rangle> \<longrightarrow>\<^sub>c t'" using Cond(5) by auto
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    71
    show ?thesis using Cond(1)[OF _ s t] Cond(3) by fastsimp
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    72
  next
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    73
    assume "\<not> b s"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    74
    hence s: "\<langle>c2,s\<rangle> \<longrightarrow>\<^sub>c s'" using Cond(4) by auto
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    75
    have "\<not> b t" using `\<not> b s` Cond(3) by (simp add: ball_Un)(blast dest: dep_on)
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    76
    hence t: "\<langle>c2,t\<rangle> \<longrightarrow>\<^sub>c t'" using Cond(5) by auto
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    77
    show ?thesis using Cond(2)[OF _ s t] Cond(3) by fastsimp
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    78
  qed
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    79
next
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    80
  case (While b c) note IH = this
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    81
  { fix cw
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    82
    have "\<langle>cw,s\<rangle> \<longrightarrow>\<^sub>c s' \<Longrightarrow> cw = (While b c) \<Longrightarrow> \<langle>cw,t\<rangle> \<longrightarrow>\<^sub>c t' \<Longrightarrow>
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    83
          \<forall> x \<in> L cw A. s x = t x \<Longrightarrow> \<forall>x\<in>A. s' x = t' x"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    84
    proof (induct arbitrary: t A pred:evalc)
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    85
      case WhileFalse
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    86
      have "\<not> b t" using WhileFalse by (simp add: ball_Un)(blast dest:dep_on)
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    87
      then have "t' = t" using WhileFalse by auto
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    88
      then show ?case using WhileFalse by auto
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    89
    next
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    90
      case (WhileTrue _ s _ s'' s')
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    91
      have "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s''" using WhileTrue(2,6) by simp
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    92
      have "b t" using WhileTrue by (simp add: ball_Un)(blast dest:dep_on)
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    93
      then obtain t'' where "\<langle>c,t\<rangle> \<longrightarrow>\<^sub>c t''" and "\<langle>While b c,t''\<rangle> \<longrightarrow>\<^sub>c t'"
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
    94
        using WhileTrue(6,7) by auto
28867
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
    95
      have "\<forall>x\<in>Dep b \<union> A \<union> L c A. s'' x = t'' x"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 28867
diff changeset
    96
        using IH(1)[OF _ `\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s''` `\<langle>c,t\<rangle> \<longrightarrow>\<^sub>c t''`] WhileTrue(6,8)
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 28867
diff changeset
    97
        by (auto simp:L_gen_kill)
35802
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
    98
      then have "\<forall>x\<in>L (While b c) A. s'' x = t'' x" by auto
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
    99
      then show ?case using WhileTrue(5,6) `\<langle>While b c,t''\<rangle> \<longrightarrow>\<^sub>c t'` by metis
28583
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
   100
    qed auto }
35802
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   101
-- "a terser version"
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   102
  { let ?w = "While b c"
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   103
    have "\<langle>?w,s\<rangle> \<longrightarrow>\<^sub>c s' \<Longrightarrow> \<langle>?w,t\<rangle> \<longrightarrow>\<^sub>c t' \<Longrightarrow>
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   104
          \<forall> x \<in> L ?w A. s x = t x \<Longrightarrow> \<forall>x\<in>A. s' x = t' x"
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   105
    proof (induct ?w s s' arbitrary: t A pred:evalc)
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   106
      case WhileFalse
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   107
      have "\<not> b t" using WhileFalse by (simp add: ball_Un)(blast dest:dep_on)
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   108
      then have "t' = t" using WhileFalse by auto
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   109
      then show ?case using WhileFalse by simp
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   110
    next
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   111
      case (WhileTrue s s'' s')
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   112
      have "b t" using WhileTrue by (simp add: ball_Un)(blast dest:dep_on)
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   113
      then obtain t'' where "\<langle>c,t\<rangle> \<longrightarrow>\<^sub>c t''" and "\<langle>While b c,t''\<rangle> \<longrightarrow>\<^sub>c t'"
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   114
        using WhileTrue(6,7) by auto
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   115
      have "\<forall>x\<in>Dep b \<union> A \<union> L c A. s'' x = t'' x"
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   116
        using IH(1)[OF _ `\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s''` `\<langle>c,t\<rangle> \<longrightarrow>\<^sub>c t''`] WhileTrue(7)
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   117
        by (auto simp:L_gen_kill)
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   118
      then have "\<forall>x\<in>L (While b c) A. s'' x = t'' x" by auto
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   119
      then show ?case using WhileTrue(5) `\<langle>While b c,t''\<rangle> \<longrightarrow>\<^sub>c t'` by metis
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   120
    qed }
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   121
  from this[OF IH(3) IH(4,2)] show ?case by metis
28583
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
   122
qed
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
   123
28867
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   124
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   125
primrec bury :: "com \<Rightarrow> loc set \<Rightarrow> com" where
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   126
"bury SKIP _ = SKIP" |
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   127
"bury (x :== e) A = (if x:A then x:== e else SKIP)" |
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   128
"bury (c1; c2) A = (bury c1 (L c2 A); bury c2 A)" |
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   129
"bury (IF b THEN c1 ELSE c2) A = (IF b THEN bury c1 A ELSE bury c2 A)" |
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   130
"bury (WHILE b DO c) A = (WHILE b DO bury c (Dep b \<union> A \<union> L c A))"
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   131
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   132
theorem bury_sound:
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   133
  "\<forall> x \<in> L c A. s x = t x \<Longrightarrow> \<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s' \<Longrightarrow> \<langle>bury c A,t\<rangle> \<longrightarrow>\<^sub>c t' \<Longrightarrow>
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   134
   \<forall>x\<in>A. s' x = t' x"
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   135
proof (induct c arbitrary: A s t s' t')
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   136
  case SKIP then show ?case by auto
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   137
next
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   138
  case (Assign x e) then show ?case
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   139
    by (auto simp:update_def ball_Un split:split_if_asm dest!: dep_on)
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   140
next
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   141
  case (Semi c1 c2)
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   142
  from Semi(4) obtain s'' where s1: "\<langle>c1,s\<rangle> \<longrightarrow>\<^sub>c s''" and s2: "\<langle>c2,s''\<rangle> \<longrightarrow>\<^sub>c s'"
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   143
    by auto
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   144
  from Semi(5) obtain t'' where t1: "\<langle>bury c1 (L c2 A),t\<rangle> \<longrightarrow>\<^sub>c t''" and t2: "\<langle>bury c2 A,t''\<rangle> \<longrightarrow>\<^sub>c t'"
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   145
    by auto
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   146
  show ?case using Semi(1)[OF _ s1 t1] Semi(2)[OF _ s2 t2] Semi(3) by fastsimp
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   147
next
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   148
  case (Cond b c1 c2)
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   149
  show ?case
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   150
  proof cases
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   151
    assume "b s"
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   152
    hence s: "\<langle>c1,s\<rangle> \<longrightarrow>\<^sub>c s'" using Cond(4) by simp
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   153
    have "b t" using `b s` Cond(3) by (simp add: ball_Un)(blast dest: dep_on)
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   154
    hence t: "\<langle>bury c1 A,t\<rangle> \<longrightarrow>\<^sub>c t'" using Cond(5) by auto
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   155
    show ?thesis using Cond(1)[OF _ s t] Cond(3) by fastsimp
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   156
  next
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   157
    assume "\<not> b s"
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   158
    hence s: "\<langle>c2,s\<rangle> \<longrightarrow>\<^sub>c s'" using Cond(4) by auto
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   159
    have "\<not> b t" using `\<not> b s` Cond(3) by (simp add: ball_Un)(blast dest: dep_on)
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   160
    hence t: "\<langle>bury c2 A,t\<rangle> \<longrightarrow>\<^sub>c t'" using Cond(5) by auto
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   161
    show ?thesis using Cond(2)[OF _ s t] Cond(3) by fastsimp
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   162
  qed
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   163
next
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   164
  case (While b c) note IH = this
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   165
  { fix cw
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   166
    have "\<langle>cw,s\<rangle> \<longrightarrow>\<^sub>c s' \<Longrightarrow> cw = (While b c) \<Longrightarrow> \<langle>bury cw A,t\<rangle> \<longrightarrow>\<^sub>c t' \<Longrightarrow>
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   167
          \<forall> x \<in> L cw A. s x = t x \<Longrightarrow> \<forall>x\<in>A. s' x = t' x"
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   168
    proof (induct arbitrary: t A pred:evalc)
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   169
      case WhileFalse
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   170
      have "\<not> b t" using WhileFalse by (simp add: ball_Un)(blast dest:dep_on)
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   171
      then have "t' = t" using WhileFalse by auto
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   172
      then show ?case using WhileFalse by auto
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   173
    next
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   174
      case (WhileTrue _ s _ s'' s')
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   175
      have "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s''" using WhileTrue(2,6) by simp
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   176
      have "b t" using WhileTrue by (simp add: ball_Un)(blast dest:dep_on)
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   177
      then obtain t'' where tt'': "\<langle>bury c (Dep b \<union> A \<union> L c A),t\<rangle> \<longrightarrow>\<^sub>c t''"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 28867
diff changeset
   178
        and "\<langle>bury (While b c) A,t''\<rangle> \<longrightarrow>\<^sub>c t'"
28867
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   179
        using WhileTrue(6,7) by auto
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   180
      have "\<forall>x\<in>Dep b \<union> A \<union> L c A. s'' x = t'' x"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 28867
diff changeset
   181
        using IH(1)[OF _ `\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s''` tt''] WhileTrue(6,8)
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 28867
diff changeset
   182
        by (auto simp:L_gen_kill)
28867
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   183
      moreover then have "\<forall>x\<in>L (While b c) A. s'' x = t'' x" by auto
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   184
      ultimately show ?case
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 28867
diff changeset
   185
        using WhileTrue(5,6) `\<langle>bury (While b c) A,t''\<rangle> \<longrightarrow>\<^sub>c t'` by metis
28867
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   186
    qed auto }
35802
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   187
  { let ?w = "While b c"
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   188
    have "\<langle>?w,s\<rangle> \<longrightarrow>\<^sub>c s' \<Longrightarrow> \<langle>bury ?w A,t\<rangle> \<longrightarrow>\<^sub>c t' \<Longrightarrow>
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   189
          \<forall> x \<in> L ?w A. s x = t x \<Longrightarrow> \<forall>x\<in>A. s' x = t' x"
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   190
    proof (induct ?w s s' arbitrary: t A pred:evalc)
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   191
      case WhileFalse
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   192
      have "\<not> b t" using WhileFalse by (simp add: ball_Un)(blast dest:dep_on)
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   193
      then have "t' = t" using WhileFalse by auto
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   194
      then show ?case using WhileFalse by simp
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   195
    next
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   196
      case (WhileTrue s s'' s')
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   197
      have "b t" using WhileTrue by (simp add: ball_Un)(blast dest:dep_on)
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   198
      then obtain t'' where tt'': "\<langle>bury c (Dep b \<union> A \<union> L c A),t\<rangle> \<longrightarrow>\<^sub>c t''"
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   199
        and "\<langle>bury (While b c) A,t''\<rangle> \<longrightarrow>\<^sub>c t'"
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   200
        using WhileTrue(6,7) by auto
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   201
      have "\<forall>x\<in>Dep b \<union> A \<union> L c A. s'' x = t'' x"
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   202
        using IH(1)[OF _ `\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s''` tt''] WhileTrue(7)
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   203
        by (auto simp:L_gen_kill)
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   204
      then have "\<forall>x\<in>L (While b c) A. s'' x = t'' x" by auto
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   205
      then show ?case
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   206
        using WhileTrue(5) `\<langle>bury (While b c) A,t''\<rangle> \<longrightarrow>\<^sub>c t'` by metis
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   207
    qed }
362431732b5e tuned inductions
nipkow
parents: 32960
diff changeset
   208
  from this[OF IH(3) IH(4,2)] show ?case by metis
28867
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   209
qed
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   210
3d9873c4c409 added optimizer
nipkow
parents: 28583
diff changeset
   211
28583
9bb9791bdc18 Added liveness analysis
nipkow
parents:
diff changeset
   212
end