src/HOL/MicroJava/BV/Typing_Framework_err.thy
author kleing
Sun, 24 Mar 2002 19:16:51 +0100
changeset 13067 a59af3a83c61
parent 13066 b57d926d1de2
child 13224 6f0928a942d1
permissions -rw-r--r--
tuned
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
12911
704713ca07ea new document
kleing
parents: 12516
diff changeset
     8
header {* \isaheader{Static and Dynamic Welltyping} *}
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
     9
13062
4b1edf2f6bd2 small refactoring for lbv with semilattices
kleing
parents: 13006
diff changeset
    10
theory Typing_Framework_err = Typing_Framework + SemilatAlg:
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
13067
kleing
parents: 13066
diff changeset
    21
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    22
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
    23
"map_snd f \<equiv> map (\<lambda>(x,y). (x, f y))"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    24
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    25
error :: "nat \<Rightarrow> (nat \<times> 'a err) list"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    26
"error n \<equiv> map (\<lambda>x. (x,Err)) [0..n(]"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    27
13067
kleing
parents: 13066
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
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    35
lemmas err_step_defs = err_step_def map_snd_def error_def
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    36
13067
kleing
parents: 13066
diff changeset
    37
lemma bounded_err_stepD:
kleing
parents: 13066
diff changeset
    38
  "bounded (err_step n app step) n \<Longrightarrow> 
kleing
parents: 13066
diff changeset
    39
  p < n \<Longrightarrow>  app p a \<Longrightarrow> (q,b) \<in> set (step p a) \<Longrightarrow> 
kleing
parents: 13066
diff changeset
    40
  q < n"
kleing
parents: 13066
diff changeset
    41
  apply (simp add: bounded_def err_step_def)
kleing
parents: 13066
diff changeset
    42
  apply (erule allE, erule impE, assumption)
kleing
parents: 13066
diff changeset
    43
  apply (erule_tac x = "OK a" in allE, drule bspec)
kleing
parents: 13066
diff changeset
    44
   apply (simp add: map_snd_def)
kleing
parents: 13066
diff changeset
    45
   apply fast
kleing
parents: 13066
diff changeset
    46
  apply simp
kleing
parents: 13066
diff changeset
    47
  done
kleing
parents: 13066
diff changeset
    48
kleing
parents: 13066
diff changeset
    49
kleing
parents: 13066
diff changeset
    50
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
    51
  apply (induct xs)
kleing
parents: 13066
diff changeset
    52
  apply (auto simp add: map_snd_def)
kleing
parents: 13066
diff changeset
    53
  done
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    54
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    55
13067
kleing
parents: 13066
diff changeset
    56
lemma bounded_err_stepI:
kleing
parents: 13066
diff changeset
    57
  "\<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
    58
  \<Longrightarrow> bounded (err_step n ap step) n"
kleing
parents: 13066
diff changeset
    59
apply (unfold bounded_def)
kleing
parents: 13066
diff changeset
    60
apply clarify
kleing
parents: 13066
diff changeset
    61
apply (simp add: err_step_def split: err.splits)
kleing
parents: 13066
diff changeset
    62
apply (simp add: error_def)
kleing
parents: 13066
diff changeset
    63
 apply blast
kleing
parents: 13066
diff changeset
    64
apply (simp split: split_if_asm) 
kleing
parents: 13066
diff changeset
    65
 apply (blast dest: in_map_sndD)
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
done
kleing
parents: 13066
diff changeset
    69
kleing
parents: 13066
diff changeset
    70
kleing
parents: 13066
diff changeset
    71
text {*
kleing
parents: 13066
diff changeset
    72
  There used to be a condition here that each instruction must have a
kleing
parents: 13066
diff changeset
    73
  successor. This is not needed any more, because the definition of
kleing
parents: 13066
diff changeset
    74
  @{term error} trivially ensures that there is a successor for
kleing
parents: 13066
diff changeset
    75
  the critical case where @{term app} does not hold. 
kleing
parents: 13066
diff changeset
    76
*}
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    77
lemma wt_err_imp_wt_app_eff:
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    78
  assumes wt: "wt_err_step r (err_step (size ts) app step) ts"
13067
kleing
parents: 13066
diff changeset
    79
  assumes b:  "bounded (err_step (size ts) app step) (size ts)"
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    80
  shows "wt_app_eff r app step (map ok_val ts)"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    81
proof (unfold wt_app_eff_def, intro strip, rule conjI)
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    82
  fix p assume "p < size (map ok_val ts)"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    83
  hence lp: "p < size ts" by simp
13067
kleing
parents: 13066
diff changeset
    84
  hence ts: "0 < size ts" by (cases p) auto
kleing
parents: 13066
diff changeset
    85
  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
    86
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    87
  from wt lp
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    88
  have [intro?]: "\<And>p. p < size ts \<Longrightarrow> ts ! p \<noteq> Err" 
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    89
    by (unfold wt_err_step_def wt_step_def) simp
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    90
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    91
  show app: "app p (map ok_val ts ! p)"
13067
kleing
parents: 13066
diff changeset
    92
  proof (rule ccontr)
kleing
parents: 13066
diff changeset
    93
    from wt lp obtain s where
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    94
      OKp:  "ts ! p = OK s" and
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
    95
      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
    96
      by (unfold wt_err_step_def wt_step_def stable_def) 
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    97
         (auto iff: not_Err_eq)
13067
kleing
parents: 13066
diff changeset
    98
    assume "\<not> app p (map ok_val ts ! p)"
kleing
parents: 13066
diff changeset
    99
    with OKp lp have "\<not> app p s" by simp
kleing
parents: 13066
diff changeset
   100
    with OKp have "err_step (size ts) app step p (ts!p) = error (size ts)" 
kleing
parents: 13066
diff changeset
   101
      by (simp add: err_step_def)    
kleing
parents: 13066
diff changeset
   102
    with err ts obtain q where 
kleing
parents: 13066
diff changeset
   103
      "(q,Err) \<in> set (err_step (size ts) app step p (ts!p))" and
kleing
parents: 13066
diff changeset
   104
      q: "q < size ts" by auto    
kleing
parents: 13066
diff changeset
   105
    with less have "ts!q = Err" by auto
kleing
parents: 13066
diff changeset
   106
    moreover from q have "ts!q \<noteq> Err" ..
kleing
parents: 13066
diff changeset
   107
    ultimately show False by blast
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   108
  qed
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   109
  
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   110
  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
   111
  proof clarify
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   112
    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
   113
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   114
    from wt lp q
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   115
    obtain s where
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   116
      OKp:  "ts ! p = OK s" and
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   117
      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
   118
      by (unfold wt_err_step_def wt_step_def stable_def) 
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   119
         (auto iff: not_Err_eq)
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   120
13067
kleing
parents: 13066
diff changeset
   121
    from b lp app q have lq: "q < size ts" by (rule bounded_err_stepD)
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   122
    hence "ts!q \<noteq> Err" ..
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   123
    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
   124
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   125
    from lp lq OKp OKq app less q
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   126
    show "t <=_r map ok_val ts ! q"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   127
      by (auto simp add: err_step_def map_snd_def) 
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   128
  qed
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   129
qed
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   130
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   131
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   132
lemma wt_app_eff_imp_wt_err:
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   133
  assumes app_eff: "wt_app_eff r app step ts"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   134
  assumes bounded: "bounded (err_step (size ts) app step) (size ts)"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   135
  shows "wt_err_step r (err_step (size ts) app step) (map OK ts)"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   136
proof (unfold wt_err_step_def wt_step_def, intro strip, rule conjI)
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   137
  fix p assume "p < size (map OK ts)" 
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   138
  hence p: "p < size ts" by simp
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   139
  thus "map OK ts ! p \<noteq> Err" by simp
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   140
  { fix q t
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   141
    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
   142
    with p app_eff obtain 
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   143
      "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
   144
      by (unfold wt_app_eff_def) blast
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   145
    moreover
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   146
    from q p bounded have "q < size ts"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   147
      by - (rule boundedD)
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   148
    hence "map OK ts ! q = OK (ts!q)" by simp
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   149
    moreover
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   150
    have "p < size ts" by (rule p)
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   151
    moreover note q
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   152
    ultimately     
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   153
    have "t <=_(Err.le r) map OK ts ! q" 
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   154
      by (auto simp add: err_step_def map_snd_def)
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   155
  }
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13062
diff changeset
   156
  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
   157
    by (unfold stable_def) blast
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   158
qed
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   159
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   160
end