src/HOL/IMP/Small_Step.thy
author kleing
Mon, 06 Jun 2011 16:29:38 +0200
changeset 43158 686fa0a0696e
parent 43141 11fce8564415
child 44036 d03f9f28d01d
permissions -rw-r--r--
imported rest of new IMP
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
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
     7
inductive
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
     8
  small_step :: "com * state \<Rightarrow> com * state \<Rightarrow> bool" (infix "\<rightarrow>" 55)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
     9
where
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    10
Assign:  "(x ::= a, s) \<rightarrow> (SKIP, s(x := aval a s))" |
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    11
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    12
Semi1:   "(SKIP;c\<^isub>2,s) \<rightarrow> (c\<^isub>2,s)" |
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    13
Semi2:   "(c\<^isub>1,s) \<rightarrow> (c\<^isub>1',s') \<Longrightarrow> (c\<^isub>1;c\<^isub>2,s) \<rightarrow> (c\<^isub>1';c\<^isub>2,s')" |
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    14
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    15
IfTrue:  "bval b s \<Longrightarrow> (IF b THEN c\<^isub>1 ELSE c\<^isub>2,s) \<rightarrow> (c\<^isub>1,s)" |
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    16
IfFalse: "\<not>bval b s \<Longrightarrow> (IF b THEN c\<^isub>1 ELSE c\<^isub>2,s) \<rightarrow> (c\<^isub>2,s)" |
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    17
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    18
While:   "(WHILE b DO c,s) \<rightarrow> (IF b THEN c; WHILE b DO c ELSE SKIP,s)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    19
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    20
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    21
abbreviation small_steps :: "com * state \<Rightarrow> com * state \<Rightarrow> bool" (infix "\<rightarrow>*" 55)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    22
where "x \<rightarrow>* y == star small_step x y"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    23
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    24
subsection{* Executability *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    25
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    26
code_pred small_step .
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
values "{(c',map t [''x'',''y'',''z'']) |c' t.
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    29
   (''x'' ::= V ''z''; ''y'' ::= V ''x'',
43158
686fa0a0696e imported rest of new IMP
kleing
parents: 43141
diff changeset
    30
    [''x'' \<rightarrow> 3, ''y'' \<rightarrow> 7, ''z'' \<rightarrow> 5]) \<rightarrow>* (c',t)}"
43141
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
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    33
subsection{* Proof infrastructure *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    34
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    35
subsubsection{* Induction rules *}
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
text{* The default induction rule @{thm[source] small_step.induct} only works
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    38
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
    39
not already pairs @{text"(DUMMY,DUMMY)"}. We can generate a suitable variant
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    40
of @{thm[source] small_step.induct} for pairs by ``splitting'' the arguments
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    41
@{text"\<rightarrow>"} into pairs: *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    42
lemmas small_step_induct = small_step.induct[split_format(complete)]
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    43
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    44
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    45
subsubsection{* Proof automation *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    46
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    47
declare small_step.intros[simp,intro]
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
text{* So called transitivity rules. See below. *}
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 step[trans] step1[trans]
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
lemma step2[trans]:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    54
  "cs \<rightarrow> cs' \<Longrightarrow> cs' \<rightarrow> cs'' \<Longrightarrow> cs \<rightarrow>* cs''"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    55
by(metis refl step)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    56
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    57
declare star_trans[trans]
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    58
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    59
text{* Rule inversion: *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    60
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    61
inductive_cases SkipE[elim!]: "(SKIP,s) \<rightarrow> ct"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    62
thm SkipE
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    63
inductive_cases AssignE[elim!]: "(x::=a,s) \<rightarrow> ct"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    64
thm AssignE
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    65
inductive_cases SemiE[elim]: "(c1;c2,s) \<rightarrow> ct"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    66
thm SemiE
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    67
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
    68
inductive_cases WhileE[elim]: "(WHILE b DO c, s) \<rightarrow> ct"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    69
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    70
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    71
text{* A simple property: *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    72
lemma deterministic:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    73
  "cs \<rightarrow> cs' \<Longrightarrow> cs \<rightarrow> cs'' \<Longrightarrow> cs'' = cs'"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    74
apply(induct arbitrary: cs'' rule: small_step.induct)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    75
apply blast+
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    76
done
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    77
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    78
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    79
subsection "Equivalence with big-step semantics"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    80
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    81
lemma star_semi2: "(c1,s) \<rightarrow>* (c1',s') \<Longrightarrow> (c1;c2,s) \<rightarrow>* (c1';c2,s')"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    82
proof(induct rule: star_induct)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    83
  case refl thus ?case by simp
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    84
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    85
  case step
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    86
  thus ?case by (metis Semi2 star.step)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    87
qed
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    88
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    89
lemma semi_comp:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    90
  "\<lbrakk> (c1,s1) \<rightarrow>* (SKIP,s2); (c2,s2) \<rightarrow>* (SKIP,s3) \<rbrakk>
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    91
   \<Longrightarrow> (c1;c2, s1) \<rightarrow>* (SKIP,s3)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    92
by(blast intro: star.step star_semi2 star_trans)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    93
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    94
text{* The following proof corresponds to one on the board where one would
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    95
show chains of @{text "\<rightarrow>"} and @{text "\<rightarrow>*"} steps. This is what the
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    96
also/finally proof steps do: they compose chains, implicitly using the rules
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    97
declared with attribute [trans] above. *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    98
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
    99
lemma big_to_small:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   100
  "cs \<Rightarrow> t \<Longrightarrow> cs \<rightarrow>* (SKIP,t)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   101
proof (induct rule: big_step.induct)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   102
  fix s show "(SKIP,s) \<rightarrow>* (SKIP,s)" by simp
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   103
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   104
  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
   105
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   106
  fix c1 c2 s1 s2 s3
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   107
  assume "(c1,s1) \<rightarrow>* (SKIP,s2)" and "(c2,s2) \<rightarrow>* (SKIP,s3)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   108
  thus "(c1;c2, s1) \<rightarrow>* (SKIP,s3)" by (rule semi_comp)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   109
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   110
  fix s::state and b c0 c1 t
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   111
  assume "bval b s"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   112
  hence "(IF b THEN c0 ELSE c1,s) \<rightarrow> (c0,s)" by simp
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   113
  also assume "(c0,s) \<rightarrow>* (SKIP,t)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   114
  finally show "(IF b THEN c0 ELSE c1,s) \<rightarrow>* (SKIP,t)" . --"= by assumption"
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 s::state and b c0 c1 t
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   117
  assume "\<not>bval b s"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   118
  hence "(IF b THEN c0 ELSE c1,s) \<rightarrow> (c1,s)" by simp
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   119
  also assume "(c1,s) \<rightarrow>* (SKIP,t)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   120
  finally show "(IF b THEN c0 ELSE c1,s) \<rightarrow>* (SKIP,t)" .
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   121
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   122
  fix b c and s::state
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   123
  assume b: "\<not>bval b s"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   124
  let ?if = "IF b THEN c; WHILE b DO c ELSE SKIP"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   125
  have "(WHILE b DO c,s) \<rightarrow> (?if, s)" by blast
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   126
  also have "(?if,s) \<rightarrow> (SKIP, s)" by (simp add: b)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   127
  finally show "(WHILE b DO c,s) \<rightarrow>* (SKIP,s)" by auto
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   128
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   129
  fix b c s s' t
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   130
  let ?w  = "WHILE b DO c"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   131
  let ?if = "IF b THEN c; ?w ELSE SKIP"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   132
  assume w: "(?w,s') \<rightarrow>* (SKIP,t)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   133
  assume c: "(c,s) \<rightarrow>* (SKIP,s')"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   134
  assume b: "bval b s"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   135
  have "(?w,s) \<rightarrow> (?if, s)" by blast
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   136
  also have "(?if, s) \<rightarrow> (c; ?w, s)" by (simp add: b)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   137
  also have "(c; ?w,s) \<rightarrow>* (SKIP,t)" by(rule semi_comp[OF c w])
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   138
  finally show "(WHILE b DO c,s) \<rightarrow>* (SKIP,t)" by auto
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   139
qed
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   140
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   141
text{* Each case of the induction can be proved automatically: *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   142
lemma  "cs \<Rightarrow> t \<Longrightarrow> cs \<rightarrow>* (SKIP,t)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   143
proof (induct rule: big_step.induct)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   144
  case Skip show ?case by blast
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   145
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   146
  case Assign show ?case by blast
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 Semi thus ?case by (blast intro: semi_comp)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   149
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   150
  case IfTrue thus ?case by (blast intro: step)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   151
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   152
  case IfFalse thus ?case by (blast intro: step)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   153
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   154
  case WhileFalse thus ?case
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   155
    by (metis step step1 small_step.IfFalse small_step.While)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   156
next
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   157
  case WhileTrue
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   158
  thus ?case
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   159
    by(metis While semi_comp small_step.IfTrue step[of small_step])
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   160
qed
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 small1_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"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   164
apply (induct arbitrary: t rule: small_step.induct)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   165
apply auto
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_big_continue:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   169
  "cs \<rightarrow>* cs' \<Longrightarrow> cs' \<Rightarrow> t \<Longrightarrow> cs \<Rightarrow> t"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   170
apply (induct rule: star.induct)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   171
apply (auto intro: small1_big_continue)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   172
done
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
lemma small_to_big: "cs \<rightarrow>* (SKIP,t) \<Longrightarrow> cs \<Rightarrow> t"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   175
by (metis small_big_continue Skip)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   176
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   177
text {*
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   178
  Finally, the equivalence theorem:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   179
*}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   180
theorem big_iff_small:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   181
  "cs \<Rightarrow> t = cs \<rightarrow>* (SKIP,t)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   182
by(metis big_to_small small_to_big)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   183
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   184
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   185
subsection "Final configurations and infinite reductions"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   186
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   187
definition "final cs \<longleftrightarrow> \<not>(EX cs'. cs \<rightarrow> cs')"
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 finalD: "final (c,s) \<Longrightarrow> c = SKIP"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   190
apply(simp add: final_def)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   191
apply(induct c)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   192
apply blast+
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   193
done
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 final_iff_SKIP: "final (c,s) = (c = SKIP)"
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   196
by (metis SkipE finalD final_def)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   197
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   198
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
   199
terminates: *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   200
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   201
lemma big_iff_small_termination:
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   202
  "(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
   203
by(simp add: big_iff_small final_iff_SKIP)
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   204
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   205
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
   206
equivalent with absence of a terminating small step sequence, i.e.\ with
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   207
nontermination.  Since @{text"\<rightarrow>"} is determininistic, there is no difference
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   208
between may and must terminate. *}
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   209
11fce8564415 Replacing old IMP with new Semantics material
nipkow
parents:
diff changeset
   210
end