src/HOL/IMP/Transition.thy
author berghofe
Fri, 01 Jul 2005 13:54:12 +0200
changeset 16633 208ebc9311f2
parent 16417 9bc16273c2d4
child 18372 2bffdf62fe7f
permissions -rw-r--r--
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification of premises of congruence rules.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
     1
(*  Title:        HOL/IMP/Transition.thy
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
     2
    ID:           $Id$
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
     3
    Author:       Tobias Nipkow & Robert Sandner, TUM
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
     4
    Isar Version: Gerwin Klein, 2001
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
     5
    Copyright     1996 TUM
1700
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
     6
*)
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
     7
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
     8
header "Transition Semantics of Commands"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
     9
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 14565
diff changeset
    10
theory Transition imports Natural begin
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    11
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    12
subsection "The transition relation"
1700
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
    13
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    14
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    15
  We formalize the transition semantics as in \cite{Nielson}. This
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    16
  makes some of the rules a bit more intuitive, but also requires
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    17
  some more (internal) formal overhead.
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    18
  
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    19
  Since configurations that have terminated are written without 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    20
  a statement, the transition relation is not 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    21
  @{typ "((com \<times> state) \<times> (com \<times> state)) set"}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    22
  but instead:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    23
*}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    24
consts evalc1 :: "((com option \<times> state) \<times> (com option \<times> state)) set"
4906
0537ee95d004 fixed translations;
wenzelm
parents: 4897
diff changeset
    25
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    26
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    27
  Some syntactic sugar that we will use to hide the 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    28
  @{text option} part in configurations:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    29
*}
4906
0537ee95d004 fixed translations;
wenzelm
parents: 4897
diff changeset
    30
syntax
12546
wenzelm
parents: 12434
diff changeset
    31
  "_angle" :: "[com, state] \<Rightarrow> com option \<times> state" ("<_,_>")
wenzelm
parents: 12434
diff changeset
    32
  "_angle2" :: "state \<Rightarrow> com option \<times> state" ("<_>")
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    33
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    34
syntax (xsymbols)
12546
wenzelm
parents: 12434
diff changeset
    35
  "_angle" :: "[com, state] \<Rightarrow> com option \<times> state" ("\<langle>_,_\<rangle>")
wenzelm
parents: 12434
diff changeset
    36
  "_angle2" :: "state \<Rightarrow> com option \<times> state" ("\<langle>_\<rangle>")
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    37
14565
c6dc17aab88a use more symbols in HTML output
kleing
parents: 13524
diff changeset
    38
syntax (HTML output)
c6dc17aab88a use more symbols in HTML output
kleing
parents: 13524
diff changeset
    39
  "_angle" :: "[com, state] \<Rightarrow> com option \<times> state" ("\<langle>_,_\<rangle>")
c6dc17aab88a use more symbols in HTML output
kleing
parents: 13524
diff changeset
    40
  "_angle2" :: "state \<Rightarrow> com option \<times> state" ("\<langle>_\<rangle>")
c6dc17aab88a use more symbols in HTML output
kleing
parents: 13524
diff changeset
    41
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    42
translations
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    43
  "\<langle>c,s\<rangle>" == "(Some c, s)"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    44
  "\<langle>s\<rangle>" == "(None, s)"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    45
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    46
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    47
  More syntactic sugar for the transition relation, and its
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    48
  iteration.
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    49
*}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    50
syntax
12546
wenzelm
parents: 12434
diff changeset
    51
  "_evalc1" :: "[(com option\<times>state),(com option\<times>state)] \<Rightarrow> bool"
12434
kleing
parents: 12431
diff changeset
    52
    ("_ -1-> _" [60,60] 60)
12546
wenzelm
parents: 12434
diff changeset
    53
  "_evalcn" :: "[(com option\<times>state),nat,(com option\<times>state)] \<Rightarrow> bool"
12434
kleing
parents: 12431
diff changeset
    54
    ("_ -_-> _" [60,60,60] 60)
12546
wenzelm
parents: 12434
diff changeset
    55
  "_evalc*" :: "[(com option\<times>state),(com option\<times>state)] \<Rightarrow> bool"
12434
kleing
parents: 12431
diff changeset
    56
    ("_ -*-> _" [60,60] 60)
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    57
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    58
syntax (xsymbols)
12546
wenzelm
parents: 12434
diff changeset
    59
  "_evalc1" :: "[(com option\<times>state),(com option\<times>state)] \<Rightarrow> bool"
12434
kleing
parents: 12431
diff changeset
    60
    ("_ \<longrightarrow>\<^sub>1 _" [60,60] 61)
12546
wenzelm
parents: 12434
diff changeset
    61
  "_evalcn" :: "[(com option\<times>state),nat,(com option\<times>state)] \<Rightarrow> bool"
12434
kleing
parents: 12431
diff changeset
    62
    ("_ -_\<rightarrow>\<^sub>1 _" [60,60,60] 60)
12546
wenzelm
parents: 12434
diff changeset
    63
  "_evalc*" :: "[(com option\<times>state),(com option\<times>state)] \<Rightarrow> bool"
12434
kleing
parents: 12431
diff changeset
    64
    ("_ \<longrightarrow>\<^sub>1\<^sup>* _" [60,60] 60)
1700
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
    65
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
    66
translations
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    67
  "cs \<longrightarrow>\<^sub>1 cs'" == "(cs,cs') \<in> evalc1"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    68
  "cs -n\<rightarrow>\<^sub>1 cs'" == "(cs,cs') \<in> evalc1^n" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    69
  "cs \<longrightarrow>\<^sub>1\<^sup>* cs'" == "(cs,cs') \<in> evalc1^*" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    70
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    71
  -- {* Isabelle converts @{text "(cs0,(c1,s1))"} to @{term "(cs0,c1,s1)"}, 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    72
        so we also include: *}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    73
  "cs0 \<longrightarrow>\<^sub>1 (c1,s1)" == "(cs0,c1,s1) \<in> evalc1"   
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    74
  "cs0 -n\<rightarrow>\<^sub>1 (c1,s1)" == "(cs0,c1,s1) \<in> evalc1^n"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    75
  "cs0 \<longrightarrow>\<^sub>1\<^sup>* (c1,s1)" == "(cs0,c1,s1) \<in> evalc1^*" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    76
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    77
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    78
  Now, finally, we are set to write down the rules for our small step semantics:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    79
*}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    80
inductive evalc1
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    81
  intros
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    82
  Skip:    "\<langle>\<SKIP>, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>s\<rangle>"  
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    83
  Assign:  "\<langle>x :== a, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>s[x \<mapsto> a s]\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    84
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    85
  Semi1:   "\<langle>c0,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>s'\<rangle> \<Longrightarrow> \<langle>c0;c1,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c1,s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    86
  Semi2:   "\<langle>c0,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c0',s'\<rangle> \<Longrightarrow> \<langle>c0;c1,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c0';c1,s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    87
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    88
  IfTrue:  "b s \<Longrightarrow> \<langle>\<IF> b \<THEN> c1 \<ELSE> c2,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c1,s\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    89
  IfFalse: "\<not>b s \<Longrightarrow> \<langle>\<IF> b \<THEN> c1 \<ELSE> c2,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c2,s\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    90
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    91
  While:   "\<langle>\<WHILE> b \<DO> c,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>\<IF> b \<THEN> c; \<WHILE> b \<DO> c \<ELSE> \<SKIP>,s\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    92
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    93
lemmas [intro] = evalc1.intros -- "again, use these rules in automatic proofs"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    94
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    95
(*<*)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    96
(* fixme: move to Relation_Power.thy *)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    97
lemma rel_pow_Suc_E2 [elim!]:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    98
  "[| (x, z) \<in> R ^ Suc n; !!y. [| (x, y) \<in> R; (y, z) \<in> R ^ n |] ==> P |] ==> P"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
    99
  by (drule rel_pow_Suc_D2) blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   100
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   101
lemma rtrancl_imp_rel_pow: "p \<in> R^* \<Longrightarrow> \<exists>n. p \<in> R^n"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   102
proof -
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   103
  assume "p \<in> R\<^sup>*"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   104
  moreover obtain x y where p: "p = (x,y)" by (cases p)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   105
  ultimately have "(x,y) \<in> R\<^sup>*" by hypsubst
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   106
  hence "\<exists>n. (x,y) \<in> R^n"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   107
  proof induct
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   108
    fix a have "(a,a) \<in> R^0" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   109
    thus "\<exists>n. (a,a) \<in> R ^ n" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   110
  next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   111
    fix a b c assume "\<exists>n. (a,b) \<in> R ^ n"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   112
    then obtain n where "(a,b) \<in> R^n" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   113
    moreover assume "(b,c) \<in> R"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   114
    ultimately have "(a,c) \<in> R^(Suc n)" by auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   115
    thus "\<exists>n. (a,c) \<in> R^n" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   116
  qed
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   117
  with p show ?thesis by hypsubst
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   118
qed  
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   119
(*>*)    
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   120
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   121
  As for the big step semantics you can read these rules in a 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   122
  syntax directed way:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   123
*}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   124
lemma SKIP_1: "\<langle>\<SKIP>, s\<rangle> \<longrightarrow>\<^sub>1 y = (y = \<langle>s\<rangle>)" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   125
  by (rule, cases set: evalc1, auto)      
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   126
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   127
lemma Assign_1: "\<langle>x :== a, s\<rangle> \<longrightarrow>\<^sub>1 y = (y = \<langle>s[x \<mapsto> a s]\<rangle>)"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   128
  by (rule, cases set: evalc1, auto)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   129
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   130
lemma Cond_1: 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   131
  "\<langle>\<IF> b \<THEN> c1 \<ELSE> c2, s\<rangle> \<longrightarrow>\<^sub>1 y = ((b s \<longrightarrow> y = \<langle>c1, s\<rangle>) \<and> (\<not>b s \<longrightarrow> y = \<langle>c2, s\<rangle>))"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   132
  by (rule, cases set: evalc1, auto)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   133
12434
kleing
parents: 12431
diff changeset
   134
lemma While_1: 
kleing
parents: 12431
diff changeset
   135
  "\<langle>\<WHILE> b \<DO> c, s\<rangle> \<longrightarrow>\<^sub>1 y = (y = \<langle>\<IF> b \<THEN> c; \<WHILE> b \<DO> c \<ELSE> \<SKIP>, s\<rangle>)"
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   136
  by (rule, cases set: evalc1, auto)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   137
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   138
lemmas [simp] = SKIP_1 Assign_1 Cond_1 While_1
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   139
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   140
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   141
subsection "Examples"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   142
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   143
lemma 
12434
kleing
parents: 12431
diff changeset
   144
  "s x = 0 \<Longrightarrow> \<langle>\<WHILE> \<lambda>s. s x \<noteq> 1 \<DO> (x:== \<lambda>s. s x+1), s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s[x \<mapsto> 1]\<rangle>"
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   145
  (is "_ \<Longrightarrow> \<langle>?w, _\<rangle> \<longrightarrow>\<^sub>1\<^sup>* _")
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   146
proof -
12434
kleing
parents: 12431
diff changeset
   147
  let ?c  = "x:== \<lambda>s. s x+1"
kleing
parents: 12431
diff changeset
   148
  let ?if = "\<IF> \<lambda>s. s x \<noteq> 1 \<THEN> ?c; ?w \<ELSE> \<SKIP>"
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   149
  assume [simp]: "s x = 0"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   150
  have "\<langle>?w, s\<rangle> \<longrightarrow>\<^sub>1  \<langle>?if, s\<rangle>" ..
12434
kleing
parents: 12431
diff changeset
   151
  also have "\<langle>?if, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>?c; ?w, s\<rangle>" by simp 
kleing
parents: 12431
diff changeset
   152
  also have "\<langle>?c; ?w, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>?w, s[x \<mapsto> 1]\<rangle>" by (rule Semi1, simp)
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   153
  also have "\<langle>?w, s[x \<mapsto> 1]\<rangle> \<longrightarrow>\<^sub>1 \<langle>?if, s[x \<mapsto> 1]\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   154
  also have "\<langle>?if, s[x \<mapsto> 1]\<rangle> \<longrightarrow>\<^sub>1 \<langle>\<SKIP>, s[x \<mapsto> 1]\<rangle>" by (simp add: update_def)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   155
  also have "\<langle>\<SKIP>, s[x \<mapsto> 1]\<rangle> \<longrightarrow>\<^sub>1 \<langle>s[x \<mapsto> 1]\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   156
  finally show ?thesis ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   157
qed
4906
0537ee95d004 fixed translations;
wenzelm
parents: 4897
diff changeset
   158
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   159
lemma 
12434
kleing
parents: 12431
diff changeset
   160
  "s x = 2 \<Longrightarrow> \<langle>\<WHILE> \<lambda>s. s x \<noteq> 1 \<DO> (x:== \<lambda>s. s x+1), s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* s'"
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   161
  (is "_ \<Longrightarrow> \<langle>?w, _\<rangle> \<longrightarrow>\<^sub>1\<^sup>* s'")
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   162
proof -
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   163
  let ?c = "x:== \<lambda>s. s x+1"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   164
  let ?if = "\<IF> \<lambda>s. s x \<noteq> 1 \<THEN> ?c; ?w \<ELSE> \<SKIP>"  
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   165
  assume [simp]: "s x = 2"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   166
  note update_def [simp]
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   167
  have "\<langle>?w, s\<rangle> \<longrightarrow>\<^sub>1  \<langle>?if, s\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   168
  also have "\<langle>?if, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>?c; ?w, s\<rangle>" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   169
  also have "\<langle>?c; ?w, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>?w, s[x \<mapsto> 3]\<rangle>" by (rule Semi1, simp)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   170
  also have "\<langle>?w, s[x \<mapsto> 3]\<rangle> \<longrightarrow>\<^sub>1 \<langle>?if, s[x \<mapsto> 3]\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   171
  also have "\<langle>?if, s[x \<mapsto> 3]\<rangle> \<longrightarrow>\<^sub>1  \<langle>?c; ?w, s[x \<mapsto> 3]\<rangle>" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   172
  also have "\<langle>?c; ?w, s[x \<mapsto> 3]\<rangle> \<longrightarrow>\<^sub>1 \<langle>?w, s[x \<mapsto> 4]\<rangle>" by (rule Semi1, simp)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   173
  also have "\<langle>?w, s[x \<mapsto> 4]\<rangle> \<longrightarrow>\<^sub>1 \<langle>?if, s[x \<mapsto> 4]\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   174
  also have "\<langle>?if, s[x \<mapsto> 4]\<rangle> \<longrightarrow>\<^sub>1  \<langle>?c; ?w, s[x \<mapsto> 4]\<rangle>" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   175
  also have "\<langle>?c; ?w, s[x \<mapsto> 4]\<rangle> \<longrightarrow>\<^sub>1 \<langle>?w, s[x \<mapsto> 5]\<rangle>" by (rule Semi1, simp) 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   176
  oops
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   177
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   178
subsection "Basic properties"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   179
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   180
text {* 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   181
  There are no \emph{stuck} programs:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   182
*}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   183
lemma no_stuck: "\<exists>y. \<langle>c,s\<rangle> \<longrightarrow>\<^sub>1 y"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   184
proof (induct c)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   185
  -- "case Semi:"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   186
  fix c1 c2 assume "\<exists>y. \<langle>c1,s\<rangle> \<longrightarrow>\<^sub>1 y" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   187
  then obtain y where "\<langle>c1,s\<rangle> \<longrightarrow>\<^sub>1 y" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   188
  then obtain c1' s' where "\<langle>c1,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>s'\<rangle> \<or> \<langle>c1,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c1',s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   189
    by (cases y, cases "fst y", auto)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   190
  thus "\<exists>s'. \<langle>c1;c2,s\<rangle> \<longrightarrow>\<^sub>1 s'" by auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   191
next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   192
  -- "case If:"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   193
  fix b c1 c2 assume "\<exists>y. \<langle>c1,s\<rangle> \<longrightarrow>\<^sub>1 y" and "\<exists>y. \<langle>c2,s\<rangle> \<longrightarrow>\<^sub>1 y"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   194
  thus "\<exists>y. \<langle>\<IF> b \<THEN> c1 \<ELSE> c2, s\<rangle> \<longrightarrow>\<^sub>1 y" by (cases "b s") auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   195
qed auto -- "the rest is trivial"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   196
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   197
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   198
  If a configuration does not contain a statement, the program
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   199
  has terminated and there is no next configuration:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   200
*}
12434
kleing
parents: 12431
diff changeset
   201
lemma stuck [elim!]: "\<langle>s\<rangle> \<longrightarrow>\<^sub>1 y \<Longrightarrow> P" 
kleing
parents: 12431
diff changeset
   202
  by (auto elim: evalc1.elims)
kleing
parents: 12431
diff changeset
   203
kleing
parents: 12431
diff changeset
   204
lemma evalc_None_retrancl [simp, dest!]: "\<langle>s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* s' \<Longrightarrow> s' = \<langle>s\<rangle>" 
kleing
parents: 12431
diff changeset
   205
  by (erule rtrancl_induct) auto 
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   206
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   207
(*<*)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   208
(* fixme: relpow.simps don't work *)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   209
lemma rel_pow_0 [simp]: "!!R::('a*'a) set. R^0 = Id" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   210
lemma rel_pow_Suc_0 [simp]: "!!R::('a*'a) set. R^(Suc 0) = R" by simp 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   211
lemmas [simp del] = relpow.simps
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   212
(*>*)
12434
kleing
parents: 12431
diff changeset
   213
lemma evalc1_None_0 [simp, dest!]: "\<langle>s\<rangle> -n\<rightarrow>\<^sub>1 y = (n = 0 \<and> y = \<langle>s\<rangle>)"
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   214
  by (cases n) auto
4906
0537ee95d004 fixed translations;
wenzelm
parents: 4897
diff changeset
   215
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   216
lemma SKIP_n: "\<langle>\<SKIP>, s\<rangle> -n\<rightarrow>\<^sub>1 \<langle>s'\<rangle> \<Longrightarrow> s' = s \<and> n=1" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   217
  by (cases n) auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   218
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   219
subsection "Equivalence to natural semantics (after Nielson and Nielson)"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   220
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   221
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   222
  We first need two lemmas about semicolon statements:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   223
  decomposition and composition.
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   224
*}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   225
lemma semiD:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   226
  "\<And>c1 c2 s s''. \<langle>c1; c2, s\<rangle> -n\<rightarrow>\<^sub>1 \<langle>s''\<rangle> \<Longrightarrow> 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   227
  \<exists>i j s'. \<langle>c1, s\<rangle> -i\<rightarrow>\<^sub>1 \<langle>s'\<rangle> \<and> \<langle>c2, s'\<rangle> -j\<rightarrow>\<^sub>1 \<langle>s''\<rangle> \<and> n = i+j"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   228
  (is "PROP ?P n")
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   229
proof (induct n)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   230
  show "PROP ?P 0" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   231
next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   232
  fix n assume IH: "PROP ?P n"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   233
  show "PROP ?P (Suc n)"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   234
  proof -
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   235
    fix c1 c2 s s''
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   236
    assume "\<langle>c1; c2, s\<rangle> -Suc n\<rightarrow>\<^sub>1 \<langle>s''\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   237
    then obtain y where
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   238
      1: "\<langle>c1; c2, s\<rangle> \<longrightarrow>\<^sub>1 y" and
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   239
      n: "y -n\<rightarrow>\<^sub>1 \<langle>s''\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   240
      by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   241
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   242
    from 1
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   243
    show "\<exists>i j s'. \<langle>c1, s\<rangle> -i\<rightarrow>\<^sub>1 \<langle>s'\<rangle> \<and> \<langle>c2, s'\<rangle> -j\<rightarrow>\<^sub>1 \<langle>s''\<rangle> \<and> Suc n = i+j"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   244
      (is "\<exists>i j s'. ?Q i j s'")
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   245
    proof (cases set: evalc1)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   246
      case Semi1
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   247
      then obtain s' where
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   248
        "y = \<langle>c2, s'\<rangle>" and "\<langle>c1, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   249
        by auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   250
      with 1 n have "?Q 1 n s'" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   251
      thus ?thesis by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   252
    next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   253
      case Semi2
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   254
      then obtain c1' s' where
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   255
        y:  "y = \<langle>c1'; c2, s'\<rangle>" and
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   256
        c1: "\<langle>c1, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c1', s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   257
        by auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   258
      with n have "\<langle>c1'; c2, s'\<rangle> -n\<rightarrow>\<^sub>1 \<langle>s''\<rangle>" by simp 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   259
      with IH obtain i j s0 where 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   260
        c1': "\<langle>c1',s'\<rangle> -i\<rightarrow>\<^sub>1 \<langle>s0\<rangle>" and
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   261
        c2:  "\<langle>c2,s0\<rangle> -j\<rightarrow>\<^sub>1 \<langle>s''\<rangle>" and
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   262
        i:   "n = i+j"
12434
kleing
parents: 12431
diff changeset
   263
        by fast
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   264
          
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   265
      from c1 c1'
12434
kleing
parents: 12431
diff changeset
   266
      have "\<langle>c1,s\<rangle> -(i+1)\<rightarrow>\<^sub>1 \<langle>s0\<rangle>" by (auto intro: rel_pow_Suc_I2)
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   267
      with c2 i
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   268
      have "?Q (i+1) j s0" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   269
      thus ?thesis by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   270
    qed auto -- "the remaining cases cannot occur"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   271
  qed
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   272
qed
1700
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
   273
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
   274
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   275
lemma semiI: 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   276
  "\<And>c0 s s''. \<langle>c0,s\<rangle> -n\<rightarrow>\<^sub>1 \<langle>s''\<rangle> \<Longrightarrow> \<langle>c1,s''\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle> \<Longrightarrow> \<langle>c0; c1, s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   277
proof (induct n)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   278
  fix c0 s s'' assume "\<langle>c0,s\<rangle> -(0::nat)\<rightarrow>\<^sub>1 \<langle>s''\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   279
  hence False by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   280
  thus "?thesis c0 s s''" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   281
next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   282
  fix c0 s s'' n 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   283
  assume c0: "\<langle>c0,s\<rangle> -Suc n\<rightarrow>\<^sub>1 \<langle>s''\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   284
  assume c1: "\<langle>c1,s''\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   285
  assume IH: "\<And>c0 s s''.
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   286
    \<langle>c0,s\<rangle> -n\<rightarrow>\<^sub>1 \<langle>s''\<rangle> \<Longrightarrow> \<langle>c1,s''\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle> \<Longrightarrow> \<langle>c0; c1,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   287
  from c0 obtain y where 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   288
    1: "\<langle>c0,s\<rangle> \<longrightarrow>\<^sub>1 y" and n: "y -n\<rightarrow>\<^sub>1 \<langle>s''\<rangle>" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   289
  from 1 obtain c0' s0' where
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   290
    "y = \<langle>s0'\<rangle> \<or> y = \<langle>c0', s0'\<rangle>" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   291
    by (cases y, cases "fst y", auto)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   292
  moreover
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   293
  { assume y: "y = \<langle>s0'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   294
    with n have "s'' = s0'" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   295
    with y 1 have "\<langle>c0; c1,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c1, s''\<rangle>" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   296
    with c1 have "\<langle>c0; c1,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>" by (blast intro: rtrancl_trans)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   297
  }
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   298
  moreover
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   299
  { assume y: "y = \<langle>c0', s0'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   300
    with n have "\<langle>c0', s0'\<rangle> -n\<rightarrow>\<^sub>1 \<langle>s''\<rangle>" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   301
    with IH c1 have "\<langle>c0'; c1,s0'\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   302
    moreover
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   303
    from y 1 have "\<langle>c0; c1,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c0'; c1,s0'\<rangle>" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   304
    hence "\<langle>c0; c1,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>c0'; c1,s0'\<rangle>" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   305
    ultimately
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   306
    have "\<langle>c0; c1,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>" by (blast intro: rtrancl_trans)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   307
  }
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   308
  ultimately
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   309
  show "\<langle>c0; c1,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   310
qed
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   311
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   312
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   313
  The easy direction of the equivalence proof:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   314
*}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   315
lemma evalc_imp_evalc1: 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   316
  "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s' \<Longrightarrow> \<langle>c, s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   317
proof -
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   318
  assume "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s'"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   319
  thus "\<langle>c, s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   320
  proof induct
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   321
    fix s show "\<langle>\<SKIP>,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s\<rangle>" by auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   322
  next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   323
    fix x a s show "\<langle>x :== a ,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s[x\<mapsto>a s]\<rangle>" by auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   324
  next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   325
    fix c0 c1 s s'' s'
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   326
    assume "\<langle>c0,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s''\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   327
    then obtain n where "\<langle>c0,s\<rangle> -n\<rightarrow>\<^sub>1 \<langle>s''\<rangle>" by (blast dest: rtrancl_imp_rel_pow)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   328
    moreover
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   329
    assume "\<langle>c1,s''\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   330
    ultimately
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   331
    show "\<langle>c0; c1,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>" by (rule semiI)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   332
  next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   333
    fix s::state and b c0 c1 s'
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   334
    assume "b s"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   335
    hence "\<langle>\<IF> b \<THEN> c0 \<ELSE> c1,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c0,s\<rangle>" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   336
    also assume "\<langle>c0,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   337
    finally show "\<langle>\<IF> b \<THEN> c0 \<ELSE> c1,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>" .
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   338
  next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   339
    fix s::state and b c0 c1 s'
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   340
    assume "\<not>b s"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   341
    hence "\<langle>\<IF> b \<THEN> c0 \<ELSE> c1,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c1,s\<rangle>" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   342
    also assume "\<langle>c1,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   343
    finally show "\<langle>\<IF> b \<THEN> c0 \<ELSE> c1,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>" .
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   344
  next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   345
    fix b c and s::state
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   346
    assume b: "\<not>b s"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   347
    let ?if = "\<IF> b \<THEN> c; \<WHILE> b \<DO> c \<ELSE> \<SKIP>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   348
    have "\<langle>\<WHILE> b \<DO> c,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>?if, s\<rangle>" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   349
    also have "\<langle>?if,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>\<SKIP>, s\<rangle>" by (simp add: b)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   350
    also have "\<langle>\<SKIP>, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>s\<rangle>" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   351
    finally show "\<langle>\<WHILE> b \<DO> c,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   352
  next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   353
    fix b c s s'' s'
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   354
    let ?w  = "\<WHILE> b \<DO> c"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   355
    let ?if = "\<IF> b \<THEN> c; ?w \<ELSE> \<SKIP>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   356
    assume w: "\<langle>?w,s''\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   357
    assume c: "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s''\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   358
    assume b: "b s"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   359
    have "\<langle>?w,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>?if, s\<rangle>" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   360
    also have "\<langle>?if, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c; ?w, s\<rangle>" by (simp add: b)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   361
    also 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   362
    from c obtain n where "\<langle>c,s\<rangle> -n\<rightarrow>\<^sub>1 \<langle>s''\<rangle>" by (blast dest: rtrancl_imp_rel_pow)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   363
    with w have "\<langle>c; ?w,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>" by - (rule semiI)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   364
    finally show "\<langle>\<WHILE> b \<DO> c,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   365
  qed
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   366
qed
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   367
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   368
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   369
  Finally, the equivalence theorem:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   370
*}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   371
theorem evalc_equiv_evalc1:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   372
  "\<langle>c, s\<rangle> \<longrightarrow>\<^sub>c s' = \<langle>c,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   373
proof
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   374
  assume "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s'"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   375
  show "\<langle>c, s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>" by (rule evalc_imp_evalc1)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   376
next  
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   377
  assume "\<langle>c, s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   378
  then obtain n where "\<langle>c, s\<rangle> -n\<rightarrow>\<^sub>1 \<langle>s'\<rangle>" by (blast dest: rtrancl_imp_rel_pow)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   379
  moreover
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   380
  have "\<And>c s s'. \<langle>c, s\<rangle> -n\<rightarrow>\<^sub>1 \<langle>s'\<rangle> \<Longrightarrow> \<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s'" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   381
  proof (induct rule: nat_less_induct)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   382
    fix n
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   383
    assume IH: "\<forall>m. m < n \<longrightarrow> (\<forall>c s s'. \<langle>c, s\<rangle> -m\<rightarrow>\<^sub>1 \<langle>s'\<rangle> \<longrightarrow> \<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s')"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   384
    fix c s s'
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   385
    assume c:  "\<langle>c, s\<rangle> -n\<rightarrow>\<^sub>1 \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   386
    then obtain m where n: "n = Suc m" by (cases n) auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   387
    with c obtain y where 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   388
      c': "\<langle>c, s\<rangle> \<longrightarrow>\<^sub>1 y" and m: "y -m\<rightarrow>\<^sub>1 \<langle>s'\<rangle>" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   389
    show "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s'" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   390
    proof (cases c)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   391
      case SKIP
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   392
      with c n show ?thesis by auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   393
    next 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   394
      case Assign
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   395
      with c n show ?thesis by auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   396
    next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   397
      fix c1 c2 assume semi: "c = (c1; c2)"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   398
      with c obtain i j s'' where
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   399
        c1: "\<langle>c1, s\<rangle> -i\<rightarrow>\<^sub>1 \<langle>s''\<rangle>" and
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   400
        c2: "\<langle>c2, s''\<rangle> -j\<rightarrow>\<^sub>1 \<langle>s'\<rangle>" and
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   401
        ij: "n = i+j"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   402
        by (blast dest: semiD)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   403
      from c1 c2 obtain 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   404
        "0 < i" and "0 < j" by (cases i, auto, cases j, auto)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   405
      with ij obtain
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   406
        i: "i < n" and j: "j < n" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   407
      from c1 i IH
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   408
      have "\<langle>c1,s\<rangle> \<longrightarrow>\<^sub>c s''" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   409
      moreover
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   410
      from c2 j IH
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   411
      have "\<langle>c2,s''\<rangle> \<longrightarrow>\<^sub>c s'" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   412
      moreover
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   413
      note semi
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   414
      ultimately
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   415
      show "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s'" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   416
    next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   417
      fix b c1 c2 assume If: "c = \<IF> b \<THEN> c1 \<ELSE> c2"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   418
      { assume True: "b s = True"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   419
        with If c n
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   420
        have "\<langle>c1,s\<rangle> -m\<rightarrow>\<^sub>1 \<langle>s'\<rangle>" by auto      
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   421
        with n IH
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   422
        have "\<langle>c1,s\<rangle> \<longrightarrow>\<^sub>c s'" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   423
        with If True
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   424
        have "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s'" by simp        
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   425
      }
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   426
      moreover
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   427
      { assume False: "b s = False"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   428
        with If c n
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   429
        have "\<langle>c2,s\<rangle> -m\<rightarrow>\<^sub>1 \<langle>s'\<rangle>" by auto      
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   430
        with n IH
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   431
        have "\<langle>c2,s\<rangle> \<longrightarrow>\<^sub>c s'" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   432
        with If False
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   433
        have "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s'" by simp        
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   434
      }
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   435
      ultimately
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   436
      show "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s'" by (cases "b s") auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   437
    next
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   438
      fix b c' assume w: "c = \<WHILE> b \<DO> c'"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   439
      with c n 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   440
      have "\<langle>\<IF> b \<THEN> c'; \<WHILE> b \<DO> c' \<ELSE> \<SKIP>,s\<rangle> -m\<rightarrow>\<^sub>1 \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   441
        (is "\<langle>?if,_\<rangle> -m\<rightarrow>\<^sub>1 _") by auto
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   442
      with n IH
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   443
      have "\<langle>\<IF> b \<THEN> c'; \<WHILE> b \<DO> c' \<ELSE> \<SKIP>,s\<rangle> \<longrightarrow>\<^sub>c s'" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   444
      moreover note unfold_while [of b c']
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   445
      -- {* @{thm unfold_while [of b c']} *}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   446
      ultimately      
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   447
      have "\<langle>\<WHILE> b \<DO> c',s\<rangle> \<longrightarrow>\<^sub>c s'" by (blast dest: equivD2)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   448
      with w show "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s'" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   449
    qed
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   450
  qed
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   451
  ultimately
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   452
  show "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s'" by blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   453
qed
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   454
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   455
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   456
subsection "Winskel's Proof"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   457
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   458
declare rel_pow_0_E [elim!]
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   459
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   460
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   461
  Winskel's small step rules are a bit different \cite{Winskel}; 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   462
  we introduce their equivalents as derived rules:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   463
*}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   464
lemma whileFalse1 [intro]:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   465
  "\<not> b s \<Longrightarrow> \<langle>\<WHILE> b \<DO> c,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s\<rangle>" (is "_ \<Longrightarrow> \<langle>?w, s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s\<rangle>")  
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   466
proof -
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   467
  assume "\<not>b s"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   468
  have "\<langle>?w, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>\<IF> b \<THEN> c;?w \<ELSE> \<SKIP>, s\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   469
  also have "\<langle>\<IF> b \<THEN> c;?w \<ELSE> \<SKIP>, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>\<SKIP>, s\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   470
  also have "\<langle>\<SKIP>, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>s\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   471
  finally show "\<langle>?w, s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   472
qed
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   473
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   474
lemma whileTrue1 [intro]:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   475
  "b s \<Longrightarrow> \<langle>\<WHILE> b \<DO> c,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>c;\<WHILE> b \<DO> c, s\<rangle>" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   476
  (is "_ \<Longrightarrow> \<langle>?w, s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>c;?w,s\<rangle>")
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   477
proof -
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   478
  assume "b s"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   479
  have "\<langle>?w, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>\<IF> b \<THEN> c;?w \<ELSE> \<SKIP>, s\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   480
  also have "\<langle>\<IF> b \<THEN> c;?w \<ELSE> \<SKIP>, s\<rangle> \<longrightarrow>\<^sub>1 \<langle>c;?w, s\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   481
  finally show "\<langle>?w, s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>c;?w,s\<rangle>" ..
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   482
qed
1700
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
   483
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   484
inductive_cases evalc1_SEs: 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   485
  "\<langle>\<SKIP>,s\<rangle> \<longrightarrow>\<^sub>1 t" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   486
  "\<langle>x:==a,s\<rangle> \<longrightarrow>\<^sub>1 t"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   487
  "\<langle>c1;c2, s\<rangle> \<longrightarrow>\<^sub>1 t"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   488
  "\<langle>\<IF> b \<THEN> c1 \<ELSE> c2, s\<rangle> \<longrightarrow>\<^sub>1 t"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   489
  "\<langle>\<WHILE> b \<DO> c, s\<rangle> \<longrightarrow>\<^sub>1 t"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   490
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   491
inductive_cases evalc1_E: "\<langle>\<WHILE> b \<DO> c, s\<rangle> \<longrightarrow>\<^sub>1 t"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   492
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   493
declare evalc1_SEs [elim!]
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   494
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   495
lemma evalc_impl_evalc1: "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s1 \<Longrightarrow> \<langle>c,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s1\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   496
apply (erule evalc.induct)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   497
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   498
-- SKIP 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   499
apply blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   500
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   501
-- ASSIGN 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   502
apply fast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   503
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   504
-- SEMI 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   505
apply (fast dest: rtrancl_imp_UN_rel_pow intro: semiI)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   506
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   507
-- IF 
12566
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12546
diff changeset
   508
apply (fast intro: converse_rtrancl_into_rtrancl)
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12546
diff changeset
   509
apply (fast intro: converse_rtrancl_into_rtrancl)
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   510
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   511
-- WHILE 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   512
apply fast
12566
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12546
diff changeset
   513
apply (fast dest: rtrancl_imp_UN_rel_pow intro: converse_rtrancl_into_rtrancl semiI)
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   514
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   515
done
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   516
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   517
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   518
lemma lemma2 [rule_format (no_asm)]: 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   519
  "\<forall>c d s u. \<langle>c;d,s\<rangle> -n\<rightarrow>\<^sub>1 \<langle>u\<rangle> \<longrightarrow> (\<exists>t m. \<langle>c,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>t\<rangle> \<and> \<langle>d,t\<rangle> -m\<rightarrow>\<^sub>1 \<langle>u\<rangle> \<and> m \<le> n)"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   520
apply (induct_tac "n")
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   521
 -- "case n = 0"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   522
 apply fastsimp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   523
-- "induction step"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   524
apply (fast intro!: le_SucI le_refl dest!: rel_pow_Suc_D2 
12566
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12546
diff changeset
   525
            elim!: rel_pow_imp_rtrancl converse_rtrancl_into_rtrancl)
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   526
done
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   527
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   528
lemma evalc1_impl_evalc [rule_format (no_asm)]: 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   529
  "\<forall>s t. \<langle>c,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>t\<rangle> \<longrightarrow> \<langle>c,s\<rangle> \<longrightarrow>\<^sub>c t"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   530
apply (induct_tac "c")
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   531
apply (safe dest!: rtrancl_imp_UN_rel_pow)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   532
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   533
-- SKIP
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   534
apply (simp add: SKIP_n)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   535
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   536
-- ASSIGN 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   537
apply (fastsimp elim: rel_pow_E2)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   538
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   539
-- SEMI
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   540
apply (fast dest!: rel_pow_imp_rtrancl lemma2)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   541
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   542
-- IF 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   543
apply (erule rel_pow_E2)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   544
apply simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   545
apply (fast dest!: rel_pow_imp_rtrancl)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   546
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   547
-- "WHILE, induction on the length of the computation"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   548
apply (rename_tac b c s t n)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   549
apply (erule_tac P = "?X -n\<rightarrow>\<^sub>1 ?Y" in rev_mp)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   550
apply (rule_tac x = "s" in spec)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   551
apply (induct_tac "n" rule: nat_less_induct)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   552
apply (intro strip)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   553
apply (erule rel_pow_E2)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   554
 apply simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   555
apply (erule evalc1_E)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   556
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   557
apply simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   558
apply (case_tac "b x")
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   559
 -- WhileTrue
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   560
 apply (erule rel_pow_E2)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   561
  apply simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   562
 apply (clarify dest!: lemma2)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   563
 apply (erule allE, erule allE, erule impE, assumption)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   564
 apply (erule_tac x=mb in allE, erule impE, fastsimp)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   565
 apply blast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   566
-- WhileFalse 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   567
apply (erule rel_pow_E2)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   568
 apply simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   569
apply (simp add: SKIP_n)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   570
done
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   571
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   572
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   573
text {* proof of the equivalence of evalc and evalc1 *}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   574
lemma evalc1_eq_evalc: "(\<langle>c, s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>t\<rangle>) = (\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c t)"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   575
apply (fast elim!: evalc1_impl_evalc evalc_impl_evalc1)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   576
done
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   577
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   578
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   579
subsection "A proof without n"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   580
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   581
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   582
  The inductions are a bit awkward to write in this section,
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   583
  because @{text None} as result statement in the small step
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   584
  semantics doesn't have a direct counterpart in the big step
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   585
  semantics. 
1700
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
   586
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   587
  Winskel's small step rule set (using the @{text "\<SKIP>"} statement
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   588
  to indicate termination) is better suited for this proof.
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   589
*}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   590
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   591
lemma my_lemma1 [rule_format (no_asm)]: 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   592
  "\<langle>c1,s1\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s2\<rangle> \<Longrightarrow> \<langle>c2,s2\<rangle> \<longrightarrow>\<^sub>1\<^sup>* cs3 \<Longrightarrow> \<langle>c1;c2,s1\<rangle> \<longrightarrow>\<^sub>1\<^sup>* cs3"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   593
proof -
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   594
  -- {* The induction rule needs @{text P} to be a function of @{term "Some c1"} *}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   595
  have "\<langle>c1,s1\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s2\<rangle> \<Longrightarrow> \<langle>c2,s2\<rangle> \<longrightarrow>\<^sub>1\<^sup>* cs3 \<longrightarrow> 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   596
       \<langle>(\<lambda>c. if c = None then c2 else the c; c2) (Some c1),s1\<rangle> \<longrightarrow>\<^sub>1\<^sup>* cs3"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   597
    apply (erule converse_rtrancl_induct2)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   598
     apply simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   599
    apply (rename_tac c s')
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   600
    apply simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   601
    apply (rule conjI)
12434
kleing
parents: 12431
diff changeset
   602
     apply fast 
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   603
    apply clarify
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   604
    apply (case_tac c)
12566
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12546
diff changeset
   605
    apply (auto intro: converse_rtrancl_into_rtrancl)
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   606
    done
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   607
  moreover assume "\<langle>c1,s1\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s2\<rangle>" "\<langle>c2,s2\<rangle> \<longrightarrow>\<^sub>1\<^sup>* cs3"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   608
  ultimately show "\<langle>c1;c2,s1\<rangle> \<longrightarrow>\<^sub>1\<^sup>* cs3" by simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   609
qed
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   610
13524
604d0f3622d6 *** empty log message ***
wenzelm
parents: 12566
diff changeset
   611
lemma evalc_impl_evalc1': "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c s1 \<Longrightarrow> \<langle>c,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>s1\<rangle>"
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   612
apply (erule evalc.induct)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   613
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   614
-- SKIP 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   615
apply fast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   616
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   617
-- ASSIGN
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   618
apply fast
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   619
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   620
-- SEMI 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   621
apply (fast intro: my_lemma1)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   622
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   623
-- IF
12566
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12546
diff changeset
   624
apply (fast intro: converse_rtrancl_into_rtrancl)
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12546
diff changeset
   625
apply (fast intro: converse_rtrancl_into_rtrancl) 
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   626
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   627
-- WHILE 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   628
apply fast
12566
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12546
diff changeset
   629
apply (fast intro: converse_rtrancl_into_rtrancl my_lemma1)
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   630
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   631
done
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   632
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   633
text {*
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   634
  The opposite direction is based on a Coq proof done by Ranan Fraer and
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   635
  Yves Bertot. The following sketch is from an email by Ranan Fraer.
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   636
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   637
\begin{verbatim}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   638
First we've broke it into 2 lemmas:
1700
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
   639
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   640
Lemma 1
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   641
((c,s) --> (SKIP,t)) => (<c,s> -c-> t)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   642
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   643
This is a quick one, dealing with the cases skip, assignment
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   644
and while_false.
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   645
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   646
Lemma 2
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   647
((c,s) -*-> (c',s')) /\ <c',s'> -c'-> t
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   648
  => 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   649
<c,s> -c-> t
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   650
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   651
This is proved by rule induction on the  -*-> relation
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   652
and the induction step makes use of a third lemma: 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   653
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   654
Lemma 3
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   655
((c,s) --> (c',s')) /\ <c',s'> -c'-> t
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   656
  => 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   657
<c,s> -c-> t
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   658
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   659
This captures the essence of the proof, as it shows that <c',s'> 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   660
behaves as the continuation of <c,s> with respect to the natural
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   661
semantics.
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   662
The proof of Lemma 3 goes by rule induction on the --> relation,
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   663
dealing with the cases sequence1, sequence2, if_true, if_false and
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   664
while_true. In particular in the case (sequence1) we make use again
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   665
of Lemma 1.
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   666
\end{verbatim}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   667
*}
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   668
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   669
inductive_cases evalc1_term_cases: "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>1 \<langle>s'\<rangle>"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   670
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   671
lemma FB_lemma3 [rule_format]:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   672
  "(c,s) \<longrightarrow>\<^sub>1 (c',s') \<Longrightarrow> c \<noteq> None \<longrightarrow>
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   673
  (\<forall>t. \<langle>if c'=None then \<SKIP> else the c',s'\<rangle> \<longrightarrow>\<^sub>c t \<longrightarrow> \<langle>the c,s\<rangle> \<longrightarrow>\<^sub>c t)"
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   674
  apply (erule evalc1.induct)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   675
  apply (auto elim!: evalc1_term_cases equivD2 [OF unfold_while])
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   676
  done
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   677
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   678
lemma FB_lemma2 [rule_format]:
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   679
  "(c,s) \<longrightarrow>\<^sub>1\<^sup>* (c',s') \<Longrightarrow> c \<noteq> None \<longrightarrow> 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   680
   \<langle>if c' = None then \<SKIP> else the c',s'\<rangle> \<longrightarrow>\<^sub>c t \<longrightarrow> \<langle>the c,s\<rangle> \<longrightarrow>\<^sub>c t" 
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   681
  apply (erule converse_rtrancl_induct2)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   682
   apply simp
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   683
  apply clarsimp
12434
kleing
parents: 12431
diff changeset
   684
  apply (fastsimp elim!: evalc1_term_cases intro: FB_lemma3)
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   685
  done
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   686
13524
604d0f3622d6 *** empty log message ***
wenzelm
parents: 12566
diff changeset
   687
lemma evalc1_impl_evalc': "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>1\<^sup>* \<langle>t\<rangle> \<Longrightarrow> \<langle>c,s\<rangle> \<longrightarrow>\<^sub>c t"
12431
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   688
  apply (fastsimp dest: FB_lemma2)
07ec657249e5 converted to Isar
kleing
parents: 9364
diff changeset
   689
  done
1700
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
   690
afd3b60660db Natural and Transition semantics.
nipkow
parents:
diff changeset
   691
end