src/HOL/IMP/Small_Step.thy
author wenzelm
Tue, 13 Aug 2013 16:25:47 +0200
changeset 53015 a1119cf551e8
parent 52046 bc01725d7918
child 54192 a5eec4263b3a
permissions -rw-r--r--
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
     1
header "Small-Step Semantics of Commands"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
     2
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
     3
theory Small_Step imports Star Big_Step begin
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
     4
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
     5
subsection "The transition relation"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
     6
49191
3601bf546775 tuned latex
nipkow
parents: 47818
diff changeset
     7
text_raw{*\snip{SmallStepDef}{0}{2}{% *}
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
     8
inductive
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
     9
  small_step :: "com * state \<Rightarrow> com * state \<Rightarrow> bool" (infix "\<rightarrow>" 55)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    10
where
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    11
Assign:  "(x ::= a, s) \<rightarrow> (SKIP, s(x := aval a s))" |
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    12
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52046
diff changeset
    13
Seq1:    "(SKIP;;c\<^sub>2,s) \<rightarrow> (c\<^sub>2,s)" |
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52046
diff changeset
    14
Seq2:    "(c\<^sub>1,s) \<rightarrow> (c\<^sub>1',s') \<Longrightarrow> (c\<^sub>1;;c\<^sub>2,s) \<rightarrow> (c\<^sub>1';;c\<^sub>2,s')" |
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    15
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52046
diff changeset
    16
IfTrue:  "bval b s \<Longrightarrow> (IF b THEN c\<^sub>1 ELSE c\<^sub>2,s) \<rightarrow> (c\<^sub>1,s)" |
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52046
diff changeset
    17
IfFalse: "\<not>bval b s \<Longrightarrow> (IF b THEN c\<^sub>1 ELSE c\<^sub>2,s) \<rightarrow> (c\<^sub>2,s)" |
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    18
50054
6da283e4497b tuned layout
nipkow
parents: 49191
diff changeset
    19
While:   "(WHILE b DO c,s) \<rightarrow>
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 50054
diff changeset
    20
            (IF b THEN c;; WHILE b DO c ELSE SKIP,s)"
49191
3601bf546775 tuned latex
nipkow
parents: 47818
diff changeset
    21
text_raw{*}%endsnip*}
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    22
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    23
50054
6da283e4497b tuned layout
nipkow
parents: 49191
diff changeset
    24
abbreviation
6da283e4497b tuned layout
nipkow
parents: 49191
diff changeset
    25
  small_steps :: "com * state \<Rightarrow> com * state \<Rightarrow> bool" (infix "\<rightarrow>*" 55)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    26
where "x \<rightarrow>* y == star small_step x y"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    27
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    28
subsection{* Executability *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    29
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    30
code_pred small_step .
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    31
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    32
values "{(c',map t [''x'',''y'',''z'']) |c' t.
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 50054
diff changeset
    33
   (''x'' ::= V ''z'';; ''y'' ::= V ''x'',
44036
d03f9f28d01d new state syntax with less conflicts
kleing
parents: 43158
diff changeset
    34
    <''x'' := 3, ''y'' := 7, ''z'' := 5>) \<rightarrow>* (c',t)}"
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    35
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    36
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    37
subsection{* Proof infrastructure *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    38
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    39
subsubsection{* Induction rules *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    40
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    41
text{* The default induction rule @{thm[source] small_step.induct} only works
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    42
for lemmas of the form @{text"a \<rightarrow> b \<Longrightarrow> \<dots>"} where @{text a} and @{text b} are
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    43
not already pairs @{text"(DUMMY,DUMMY)"}. We can generate a suitable variant
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    44
of @{thm[source] small_step.induct} for pairs by ``splitting'' the arguments
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    45
@{text"\<rightarrow>"} into pairs: *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    46
lemmas small_step_induct = small_step.induct[split_format(complete)]
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    47
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    48
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    49
subsubsection{* Proof automation *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    50
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    51
declare small_step.intros[simp,intro]
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    52
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    53
text{* Rule inversion: *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    54
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    55
inductive_cases SkipE[elim!]: "(SKIP,s) \<rightarrow> ct"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    56
thm SkipE
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    57
inductive_cases AssignE[elim!]: "(x::=a,s) \<rightarrow> ct"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    58
thm AssignE
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 50054
diff changeset
    59
inductive_cases SeqE[elim]: "(c1;;c2,s) \<rightarrow> ct"
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 45415
diff changeset
    60
thm SeqE
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    61
inductive_cases IfE[elim!]: "(IF b THEN c1 ELSE c2,s) \<rightarrow> ct"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    62
inductive_cases WhileE[elim]: "(WHILE b DO c, s) \<rightarrow> ct"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    63
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    64
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    65
text{* A simple property: *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    66
lemma deterministic:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    67
  "cs \<rightarrow> cs' \<Longrightarrow> cs \<rightarrow> cs'' \<Longrightarrow> cs'' = cs'"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44036
diff changeset
    68
apply(induction arbitrary: cs'' rule: small_step.induct)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    69
apply blast+
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    70
done
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    71
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    72
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    73
subsection "Equivalence with big-step semantics"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    74
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 50054
diff changeset
    75
lemma star_seq2: "(c1,s) \<rightarrow>* (c1',s') \<Longrightarrow> (c1;;c2,s) \<rightarrow>* (c1';;c2,s')"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44036
diff changeset
    76
proof(induction rule: star_induct)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    77
  case refl thus ?case by simp
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    78
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    79
  case step
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 45415
diff changeset
    80
  thus ?case by (metis Seq2 star.step)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    81
qed
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    82
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 45415
diff changeset
    83
lemma seq_comp:
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    84
  "\<lbrakk> (c1,s1) \<rightarrow>* (SKIP,s2); (c2,s2) \<rightarrow>* (SKIP,s3) \<rbrakk>
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 50054
diff changeset
    85
   \<Longrightarrow> (c1;;c2, s1) \<rightarrow>* (SKIP,s3)"
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 45415
diff changeset
    86
by(blast intro: star.step star_seq2 star_trans)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    87
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    88
text{* The following proof corresponds to one on the board where one would
45218
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45114
diff changeset
    89
show chains of @{text "\<rightarrow>"} and @{text "\<rightarrow>*"} steps. *}
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    90
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    91
lemma big_to_small:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    92
  "cs \<Rightarrow> t \<Longrightarrow> cs \<rightarrow>* (SKIP,t)"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44036
diff changeset
    93
proof (induction rule: big_step.induct)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    94
  fix s show "(SKIP,s) \<rightarrow>* (SKIP,s)" by simp
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    95
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    96
  fix x a s show "(x ::= a,s) \<rightarrow>* (SKIP, s(x := aval a s))" by auto
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    97
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    98
  fix c1 c2 s1 s2 s3
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    99
  assume "(c1,s1) \<rightarrow>* (SKIP,s2)" and "(c2,s2) \<rightarrow>* (SKIP,s3)"
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 50054
diff changeset
   100
  thus "(c1;;c2, s1) \<rightarrow>* (SKIP,s3)" by (rule seq_comp)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   101
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   102
  fix s::state and b c0 c1 t
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   103
  assume "bval b s"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   104
  hence "(IF b THEN c0 ELSE c1,s) \<rightarrow> (c0,s)" by simp
45218
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45114
diff changeset
   105
  moreover assume "(c0,s) \<rightarrow>* (SKIP,t)"
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45114
diff changeset
   106
  ultimately 
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45114
diff changeset
   107
  show "(IF b THEN c0 ELSE c1,s) \<rightarrow>* (SKIP,t)" by (metis star.simps)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   108
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   109
  fix s::state and b c0 c1 t
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   110
  assume "\<not>bval b s"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   111
  hence "(IF b THEN c0 ELSE c1,s) \<rightarrow> (c1,s)" by simp
45218
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45114
diff changeset
   112
  moreover assume "(c1,s) \<rightarrow>* (SKIP,t)"
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45114
diff changeset
   113
  ultimately 
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45114
diff changeset
   114
  show "(IF b THEN c0 ELSE c1,s) \<rightarrow>* (SKIP,t)" by (metis star.simps)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   115
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   116
  fix b c and s::state
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   117
  assume b: "\<not>bval b s"
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 50054
diff changeset
   118
  let ?if = "IF b THEN c;; WHILE b DO c ELSE SKIP"
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   119
  have "(WHILE b DO c,s) \<rightarrow> (?if, s)" by blast
45218
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45114
diff changeset
   120
  moreover have "(?if,s) \<rightarrow> (SKIP, s)" by (simp add: b)
45265
521508e85c0d tuned names to avoid shadowing
nipkow
parents: 45218
diff changeset
   121
  ultimately show "(WHILE b DO c,s) \<rightarrow>* (SKIP,s)" by(metis star.refl star.step)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   122
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   123
  fix b c s s' t
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   124
  let ?w  = "WHILE b DO c"
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 50054
diff changeset
   125
  let ?if = "IF b THEN c;; ?w ELSE SKIP"
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   126
  assume w: "(?w,s') \<rightarrow>* (SKIP,t)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   127
  assume c: "(c,s) \<rightarrow>* (SKIP,s')"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   128
  assume b: "bval b s"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   129
  have "(?w,s) \<rightarrow> (?if, s)" by blast
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 50054
diff changeset
   130
  moreover have "(?if, s) \<rightarrow> (c;; ?w, s)" by (simp add: b)
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 50054
diff changeset
   131
  moreover have "(c;; ?w,s) \<rightarrow>* (SKIP,t)" by(rule seq_comp[OF c w])
45218
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45114
diff changeset
   132
  ultimately show "(WHILE b DO c,s) \<rightarrow>* (SKIP,t)" by (metis star.simps)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   133
qed
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   134
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   135
text{* Each case of the induction can be proved automatically: *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   136
lemma  "cs \<Rightarrow> t \<Longrightarrow> cs \<rightarrow>* (SKIP,t)"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44036
diff changeset
   137
proof (induction rule: big_step.induct)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   138
  case Skip show ?case by blast
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   139
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   140
  case Assign show ?case by blast
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   141
next
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 45415
diff changeset
   142
  case Seq thus ?case by (blast intro: seq_comp)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   143
next
45265
521508e85c0d tuned names to avoid shadowing
nipkow
parents: 45218
diff changeset
   144
  case IfTrue thus ?case by (blast intro: star.step)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   145
next
45265
521508e85c0d tuned names to avoid shadowing
nipkow
parents: 45218
diff changeset
   146
  case IfFalse thus ?case by (blast intro: star.step)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   147
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   148
  case WhileFalse thus ?case
45265
521508e85c0d tuned names to avoid shadowing
nipkow
parents: 45218
diff changeset
   149
    by (metis star.step star_step1 small_step.IfFalse small_step.While)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   150
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   151
  case WhileTrue
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   152
  thus ?case
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 45415
diff changeset
   153
    by(metis While seq_comp small_step.IfTrue star.step[of small_step])
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   154
qed
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   155
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   156
lemma small1_big_continue:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   157
  "cs \<rightarrow> cs' \<Longrightarrow> cs' \<Rightarrow> t \<Longrightarrow> cs \<Rightarrow> t"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44036
diff changeset
   158
apply (induction arbitrary: t rule: small_step.induct)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   159
apply auto
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   160
done
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   161
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   162
lemma small_big_continue:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   163
  "cs \<rightarrow>* cs' \<Longrightarrow> cs' \<Rightarrow> t \<Longrightarrow> cs \<Rightarrow> t"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44036
diff changeset
   164
apply (induction rule: star.induct)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   165
apply (auto intro: small1_big_continue)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   166
done
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   167
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   168
lemma small_to_big: "cs \<rightarrow>* (SKIP,t) \<Longrightarrow> cs \<Rightarrow> t"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   169
by (metis small_big_continue Skip)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   170
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   171
text {*
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   172
  Finally, the equivalence theorem:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   173
*}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   174
theorem big_iff_small:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   175
  "cs \<Rightarrow> t = cs \<rightarrow>* (SKIP,t)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   176
by(metis big_to_small small_to_big)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   177
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   178
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   179
subsection "Final configurations and infinite reductions"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   180
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   181
definition "final cs \<longleftrightarrow> \<not>(EX cs'. cs \<rightarrow> cs')"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   182
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   183
lemma finalD: "final (c,s) \<Longrightarrow> c = SKIP"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   184
apply(simp add: final_def)
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44036
diff changeset
   185
apply(induction c)
43141
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   186
apply blast+
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   187
done
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   188
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   189
lemma final_iff_SKIP: "final (c,s) = (c = SKIP)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   190
by (metis SkipE finalD final_def)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   191
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   192
text{* Now we can show that @{text"\<Rightarrow>"} yields a final state iff @{text"\<rightarrow>"}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   193
terminates: *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   194
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   195
lemma big_iff_small_termination:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   196
  "(EX t. cs \<Rightarrow> t) \<longleftrightarrow> (EX cs'. cs \<rightarrow>* cs' \<and> final cs')"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   197
by(simp add: big_iff_small final_iff_SKIP)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   198
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   199
text{* This is the same as saying that the absence of a big step result is
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   200
equivalent with absence of a terminating small step sequence, i.e.\ with
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   201
nontermination.  Since @{text"\<rightarrow>"} is determininistic, there is no difference
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   202
between may and must terminate. *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   203
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   204
end