src/HOL/MicroJava/BV/Typing_Framework_err.thy
author paulson
Fri, 05 Oct 2007 09:59:03 +0200
changeset 24854 0ebcd575d3c6
parent 16417 9bc16273c2d4
child 27680 5a557a5afc48
permissions -rw-r--r--
filtering out some package theorems
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/Typing_Framework_err.thy
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
     2
    ID:         $Id$
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
     3
    Author:     Gerwin Klein
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
     4
    Copyright   2000 TUM
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
     5
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
     6
*)
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
     7
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
     8
header {* \isaheader{Lifting the Typing Framework to err, app, and eff} *}
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
     9
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 15425
diff changeset
    10
theory Typing_Framework_err imports Typing_Framework SemilatAlg begin
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    11
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    12
constdefs
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    13
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    14
wt_err_step :: "'s ord \<Rightarrow> 's err step_type \<Rightarrow> 's err list \<Rightarrow> bool"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    15
"wt_err_step r step ts \<equiv> wt_step (Err.le r) Err step ts"
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    16
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    17
wt_app_eff :: "'s ord \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> bool"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    18
"wt_app_eff r app step ts \<equiv>
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    19
  \<forall>p < size ts. app p (ts!p) \<and> (\<forall>(q,t) \<in> set (step p (ts!p)). t <=_r ts!q)"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    20
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    21
map_snd :: "('b \<Rightarrow> 'c) \<Rightarrow> ('a \<times> 'b) list \<Rightarrow> ('a \<times> 'c) list"
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    22
"map_snd f \<equiv> map (\<lambda>(x,y). (x, f y))"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    23
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    24
error :: "nat \<Rightarrow> (nat \<times> 'a err) list"
15425
6356d2523f73 [ .. (] -> [ ..< ]
nipkow
parents: 13224
diff changeset
    25
"error n \<equiv> map (\<lambda>x. (x,Err)) [0..<n]"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    26
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    27
err_step :: "nat \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's err step_type"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    28
"err_step n app step p t \<equiv> 
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    29
  case t of 
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    30
    Err   \<Rightarrow> error n
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    31
  | OK t' \<Rightarrow> if app p t' then map_snd OK (step p t') else error n"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    32
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    33
app_mono :: "'s ord \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> 's set \<Rightarrow> bool"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    34
"app_mono r app n A \<equiv>
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    35
 \<forall>s p t. s \<in> A \<and> p < n \<and> s <=_r t \<longrightarrow> app p t \<longrightarrow> app p s"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    36
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    37
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    38
lemmas err_step_defs = err_step_def map_snd_def error_def
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    39
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    40
13067
kleing
parents: 13066
diff changeset
    41
lemma bounded_err_stepD:
kleing
parents: 13066
diff changeset
    42
  "bounded (err_step n app step) n \<Longrightarrow> 
kleing
parents: 13066
diff changeset
    43
  p < n \<Longrightarrow>  app p a \<Longrightarrow> (q,b) \<in> set (step p a) \<Longrightarrow> 
kleing
parents: 13066
diff changeset
    44
  q < n"
kleing
parents: 13066
diff changeset
    45
  apply (simp add: bounded_def err_step_def)
kleing
parents: 13066
diff changeset
    46
  apply (erule allE, erule impE, assumption)
kleing
parents: 13066
diff changeset
    47
  apply (erule_tac x = "OK a" in allE, drule bspec)
kleing
parents: 13066
diff changeset
    48
   apply (simp add: map_snd_def)
kleing
parents: 13066
diff changeset
    49
   apply fast
kleing
parents: 13066
diff changeset
    50
  apply simp
kleing
parents: 13066
diff changeset
    51
  done
kleing
parents: 13066
diff changeset
    52
kleing
parents: 13066
diff changeset
    53
kleing
parents: 13066
diff changeset
    54
lemma in_map_sndD: "(a,b) \<in> set (map_snd f xs) \<Longrightarrow> \<exists>b'. (a,b') \<in> set xs"
kleing
parents: 13066
diff changeset
    55
  apply (induct xs)
kleing
parents: 13066
diff changeset
    56
  apply (auto simp add: map_snd_def)
kleing
parents: 13066
diff changeset
    57
  done
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    58
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    59
13067
kleing
parents: 13066
diff changeset
    60
lemma bounded_err_stepI:
kleing
parents: 13066
diff changeset
    61
  "\<forall>p. p < n \<longrightarrow> (\<forall>s. ap p s \<longrightarrow> (\<forall>(q,s') \<in> set (step p s). q < n))
kleing
parents: 13066
diff changeset
    62
  \<Longrightarrow> bounded (err_step n ap step) n"
kleing
parents: 13066
diff changeset
    63
apply (unfold bounded_def)
kleing
parents: 13066
diff changeset
    64
apply clarify
kleing
parents: 13066
diff changeset
    65
apply (simp add: err_step_def split: err.splits)
kleing
parents: 13066
diff changeset
    66
apply (simp add: error_def)
kleing
parents: 13066
diff changeset
    67
 apply blast
kleing
parents: 13066
diff changeset
    68
apply (simp split: split_if_asm) 
kleing
parents: 13066
diff changeset
    69
 apply (blast dest: in_map_sndD)
kleing
parents: 13066
diff changeset
    70
apply (simp add: error_def)
kleing
parents: 13066
diff changeset
    71
apply blast
kleing
parents: 13066
diff changeset
    72
done
kleing
parents: 13066
diff changeset
    73
kleing
parents: 13066
diff changeset
    74
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    75
lemma bounded_lift:
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    76
  "bounded step n \<Longrightarrow> bounded (err_step n app step) n"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    77
  apply (unfold bounded_def err_step_def error_def)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    78
  apply clarify
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    79
  apply (erule allE, erule impE, assumption)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    80
  apply (case_tac s)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    81
  apply (auto simp add: map_snd_def split: split_if_asm)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    82
  done
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    83
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    84
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    85
lemma le_list_map_OK [simp]:
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    86
  "\<And>b. map OK a <=[Err.le r] map OK b = (a <=[r] b)"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    87
  apply (induct a)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    88
   apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    89
  apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    90
  apply (case_tac b)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    91
   apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    92
  apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    93
  done
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    94
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    95
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    96
lemma map_snd_lessI:
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    97
  "x <=|r| y \<Longrightarrow> map_snd OK x <=|Err.le r| map_snd OK y"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    98
  apply (induct x)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
    99
  apply (unfold lesubstep_type_def map_snd_def)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   100
  apply auto
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   101
  done
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   102
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   103
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   104
lemma mono_lift:
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   105
  "order r \<Longrightarrow> app_mono r app n A \<Longrightarrow> bounded (err_step n app step) n \<Longrightarrow>
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   106
  \<forall>s p t. s \<in> A \<and> p < n \<and> s <=_r t \<longrightarrow> app p t \<longrightarrow> step p s <=|r| step p t \<Longrightarrow>
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   107
  mono (Err.le r) (err_step n app step) n (err A)"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   108
apply (unfold app_mono_def mono_def err_step_def)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   109
apply clarify
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   110
apply (case_tac s)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   111
 apply simp 
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   112
apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   113
apply (case_tac t)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   114
 apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   115
 apply clarify
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   116
 apply (simp add: lesubstep_type_def error_def)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   117
 apply clarify
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   118
 apply (drule in_map_sndD)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   119
 apply clarify
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   120
 apply (drule bounded_err_stepD, assumption+)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   121
 apply (rule exI [of _ Err])
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   122
 apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   123
apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   124
apply (erule allE, erule allE, erule allE, erule impE)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   125
 apply (rule conjI, assumption)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   126
 apply (rule conjI, assumption)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   127
 apply assumption
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   128
apply (rule conjI)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   129
apply clarify
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   130
apply (erule allE, erule allE, erule allE, erule impE)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   131
 apply (rule conjI, assumption)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   132
 apply (rule conjI, assumption)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   133
 apply assumption
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   134
apply (erule impE, assumption)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   135
apply (rule map_snd_lessI, assumption)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   136
apply clarify
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   137
apply (simp add: lesubstep_type_def error_def)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   138
apply clarify
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   139
apply (drule in_map_sndD)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   140
apply clarify
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   141
apply (drule bounded_err_stepD, assumption+)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   142
apply (rule exI [of _ Err])
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   143
apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   144
done
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   145
 
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   146
lemma in_errorD:
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   147
  "(x,y) \<in> set (error n) \<Longrightarrow> y = Err"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   148
  by (auto simp add: error_def)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   149
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   150
lemma pres_type_lift:
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   151
  "\<forall>s\<in>A. \<forall>p. p < n \<longrightarrow> app p s \<longrightarrow> (\<forall>(q, s')\<in>set (step p s). s' \<in> A) 
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   152
  \<Longrightarrow> pres_type (err_step n app step) n (err A)"  
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   153
apply (unfold pres_type_def err_step_def)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   154
apply clarify
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   155
apply (case_tac b)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   156
 apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   157
apply (case_tac s)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   158
 apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   159
 apply (drule in_errorD)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   160
 apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   161
apply (simp add: map_snd_def split: split_if_asm)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   162
 apply fast
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   163
apply (drule in_errorD)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   164
apply simp
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   165
done
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   166
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   167
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   168
13067
kleing
parents: 13066
diff changeset
   169
text {*
kleing
parents: 13066
diff changeset
   170
  There used to be a condition here that each instruction must have a
kleing
parents: 13066
diff changeset
   171
  successor. This is not needed any more, because the definition of
kleing
parents: 13066
diff changeset
   172
  @{term error} trivially ensures that there is a successor for
kleing
parents: 13066
diff changeset
   173
  the critical case where @{term app} does not hold. 
kleing
parents: 13066
diff changeset
   174
*}
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   175
lemma wt_err_imp_wt_app_eff:
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   176
  assumes wt: "wt_err_step r (err_step (size ts) app step) ts"
13067
kleing
parents: 13066
diff changeset
   177
  assumes b:  "bounded (err_step (size ts) app step) (size ts)"
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   178
  shows "wt_app_eff r app step (map ok_val ts)"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   179
proof (unfold wt_app_eff_def, intro strip, rule conjI)
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   180
  fix p assume "p < size (map ok_val ts)"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   181
  hence lp: "p < size ts" by simp
13067
kleing
parents: 13066
diff changeset
   182
  hence ts: "0 < size ts" by (cases p) auto
kleing
parents: 13066
diff changeset
   183
  hence err: "(0,Err) \<in> set (error (size ts))" by (simp add: error_def)
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   184
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   185
  from wt lp
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   186
  have [intro?]: "\<And>p. p < size ts \<Longrightarrow> ts ! p \<noteq> Err" 
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   187
    by (unfold wt_err_step_def wt_step_def) simp
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   188
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   189
  show app: "app p (map ok_val ts ! p)"
13067
kleing
parents: 13066
diff changeset
   190
  proof (rule ccontr)
kleing
parents: 13066
diff changeset
   191
    from wt lp obtain s where
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   192
      OKp:  "ts ! p = OK s" and
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   193
      less: "\<forall>(q,t) \<in> set (err_step (size ts) app step p (ts!p)). t <=_(Err.le r) ts!q"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   194
      by (unfold wt_err_step_def wt_step_def stable_def) 
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   195
         (auto iff: not_Err_eq)
13067
kleing
parents: 13066
diff changeset
   196
    assume "\<not> app p (map ok_val ts ! p)"
kleing
parents: 13066
diff changeset
   197
    with OKp lp have "\<not> app p s" by simp
kleing
parents: 13066
diff changeset
   198
    with OKp have "err_step (size ts) app step p (ts!p) = error (size ts)" 
kleing
parents: 13066
diff changeset
   199
      by (simp add: err_step_def)    
kleing
parents: 13066
diff changeset
   200
    with err ts obtain q where 
kleing
parents: 13066
diff changeset
   201
      "(q,Err) \<in> set (err_step (size ts) app step p (ts!p))" and
kleing
parents: 13066
diff changeset
   202
      q: "q < size ts" by auto    
kleing
parents: 13066
diff changeset
   203
    with less have "ts!q = Err" by auto
kleing
parents: 13066
diff changeset
   204
    moreover from q have "ts!q \<noteq> Err" ..
kleing
parents: 13066
diff changeset
   205
    ultimately show False by blast
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   206
  qed
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   207
  
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   208
  show "\<forall>(q,t)\<in>set(step p (map ok_val ts ! p)). t <=_r map ok_val ts ! q" 
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   209
  proof clarify
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   210
    fix q t assume q: "(q,t) \<in> set (step p (map ok_val ts ! p))"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   211
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   212
    from wt lp q
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   213
    obtain s where
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   214
      OKp:  "ts ! p = OK s" and
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   215
      less: "\<forall>(q,t) \<in> set (err_step (size ts) app step p (ts!p)). t <=_(Err.le r) ts!q"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   216
      by (unfold wt_err_step_def wt_step_def stable_def) 
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   217
         (auto iff: not_Err_eq)
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   218
13067
kleing
parents: 13066
diff changeset
   219
    from b lp app q have lq: "q < size ts" by (rule bounded_err_stepD)
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   220
    hence "ts!q \<noteq> Err" ..
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   221
    then obtain s' where OKq: "ts ! q = OK s'" by (auto iff: not_Err_eq)
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   222
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   223
    from lp lq OKp OKq app less q
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   224
    show "t <=_r map ok_val ts ! q"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   225
      by (auto simp add: err_step_def map_snd_def) 
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   226
  qed
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   227
qed
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   228
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   229
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   230
lemma wt_app_eff_imp_wt_err:
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   231
  assumes app_eff: "wt_app_eff r app step ts"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   232
  assumes bounded: "bounded (err_step (size ts) app step) (size ts)"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   233
  shows "wt_err_step r (err_step (size ts) app step) (map OK ts)"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   234
proof (unfold wt_err_step_def wt_step_def, intro strip, rule conjI)
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   235
  fix p assume "p < size (map OK ts)" 
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   236
  hence p: "p < size ts" by simp
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   237
  thus "map OK ts ! p \<noteq> Err" by simp
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   238
  { fix q t
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   239
    assume q: "(q,t) \<in> set (err_step (size ts) app step p (map OK ts ! p))" 
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   240
    with p app_eff obtain 
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   241
      "app p (ts ! p)" "\<forall>(q,t) \<in> set (step p (ts!p)). t <=_r ts!q"
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   242
      by (unfold wt_app_eff_def) blast
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   243
    moreover
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   244
    from q p bounded have "q < size ts"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   245
      by - (rule boundedD)
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   246
    hence "map OK ts ! q = OK (ts!q)" by simp
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   247
    moreover
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   248
    have "p < size ts" by (rule p)
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   249
    moreover note q
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   250
    ultimately     
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   251
    have "t <=_(Err.le r) map OK ts ! q" 
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   252
      by (auto simp add: err_step_def map_snd_def)
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   253
  }
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   254
  thus "stable (Err.le r) (err_step (size ts) app step) (map OK ts) p"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   255
    by (unfold stable_def) blast
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   256
qed
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   257
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   258
end
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13067
diff changeset
   259