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