src/HOL/MicroJava/BV/Typing_Framework_err.thy
author kleing
Sat, 09 Mar 2002 20:39:46 +0100
changeset 13052 3bf41c474a88
parent 13006 51c5f3f11d16
child 13062 4b1edf2f6bd2
permissions -rw-r--r--
canonical start state
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
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    10
theory Typing_Framework_err = Typing_Framework:
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
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    14
dynamic_wt :: "'s ord \<Rightarrow> 's err step_type \<Rightarrow> 's err list \<Rightarrow> bool"
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    15
"dynamic_wt r step ts == wt_step (Err.le r) Err step ts"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    16
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    17
static_wt :: "'s ord \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> bool"
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    18
"static_wt r app step ts == 
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"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    22
"map_snd f == map (\<lambda>(x,y). (x, f y))"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    23
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    24
map_err :: "('a \<times> 'b) list \<Rightarrow> ('a \<times> 'b err) list"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    25
"map_err == map_snd (\<lambda>y. Err)"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    26
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    27
err_step :: "(nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's err step_type"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    28
"err_step app step p t == case t of Err \<Rightarrow> map_err (step p arbitrary) | OK t' \<Rightarrow> 
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    29
  if app p t' then map_snd OK (step p t') else map_err (step p t')"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    30
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    31
non_empty :: "'s step_type \<Rightarrow> bool"
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    32
"non_empty step == \<forall>p t. step p t \<noteq> []"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    33
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    34
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    35
lemmas err_step_defs = err_step_def map_snd_def map_err_def
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    36
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    37
lemma non_emptyD:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    38
  "non_empty step \<Longrightarrow> \<exists>q t'. (q,t') \<in> set(step p t)"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    39
proof (unfold non_empty_def)
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    40
  assume "\<forall>p t. step p t \<noteq> []"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    41
  hence "step p t \<noteq> []" by blast
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    42
  then obtain x xs where "step p t = x#xs"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    43
    by (auto simp add: neq_Nil_conv)
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    44
  hence "x \<in> set(step p t)" by simp
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    45
  thus ?thesis by (cases x) blast
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    46
qed
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    47
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    48
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    49
lemma dynamic_imp_static:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    50
  "\<lbrakk> bounded step (size ts); non_empty step;
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    51
      dynamic_wt r (err_step app step) ts \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    52
  \<Longrightarrow> static_wt r app step (map ok_val ts)"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    53
proof (unfold static_wt_def, intro strip, rule conjI)
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    54
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    55
  assume b:  "bounded step (size ts)"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    56
  assume n:  "non_empty step"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    57
  assume wt: "dynamic_wt r (err_step app step) ts"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    58
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    59
  fix p 
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    60
  assume "p < length (map ok_val ts)"
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    61
  hence lp: "p < length ts" by simp
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    62
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    63
  from wt lp
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    64
  have [intro?]: "\<And>p. p < length ts \<Longrightarrow> ts ! p \<noteq> Err" 
11299
1d3d110c456e welltyping -> wt_step
nipkow
parents: 11229
diff changeset
    65
    by (unfold dynamic_wt_def wt_step_def) simp
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    66
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    67
  show app: "app p (map ok_val ts ! p)"
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    68
  proof -
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    69
    from wt lp 
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    70
    obtain s where
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    71
      OKp:  "ts ! p = OK s" and
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    72
      less: "\<forall>(q,t) \<in> set (err_step app step p (ts!p)). t <=_(Err.le r) ts!q"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    73
      by (unfold dynamic_wt_def wt_step_def stable_def) 
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    74
         (auto iff: not_Err_eq)
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    75
    
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    76
    from n
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    77
    obtain q t where q: "(q,t) \<in> set(step p s)"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    78
      by (blast dest: non_emptyD)
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    79
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    80
    from lp b q
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    81
    have lq: "q < length ts" by (unfold bounded_def) blast
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    82
    hence "ts!q \<noteq> Err" ..
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    83
    then obtain s' where OKq: "ts ! q = OK s'" by (auto iff: not_Err_eq)      
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    84
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    85
    with OKp less q have "app p s"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    86
      by (auto simp add: err_step_defs split: err.split_asm split_if_asm)
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    87
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    88
    with lp OKp show ?thesis by simp
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    89
  qed
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    90
  
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    91
  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
    92
  proof clarify
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    93
    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
    94
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    95
    from wt lp q
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    96
    obtain s where
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
    97
      OKp:  "ts ! p = OK s" and
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
    98
      less: "\<forall>(q,t) \<in> set (err_step app step p (ts!p)). t <=_(Err.le r) ts!q"
11299
1d3d110c456e welltyping -> wt_step
nipkow
parents: 11229
diff changeset
    99
      by (unfold dynamic_wt_def wt_step_def stable_def) 
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   100
         (auto iff: not_Err_eq)
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   101
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   102
    from lp b q
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   103
    have lq: "q < length ts" by (unfold bounded_def) blast
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   104
    hence "ts!q \<noteq> Err" ..
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   105
    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
   106
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   107
    from lp lq OKp OKq app less q
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   108
    show "t <=_r map ok_val ts ! q"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   109
      by (auto simp add: err_step_def map_snd_def) 
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   110
  qed
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   111
qed
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   112
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   113
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   114
lemma static_imp_dynamic:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   115
  "\<lbrakk> static_wt r app step ts; bounded step (size ts) \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   116
  \<Longrightarrow> dynamic_wt r (err_step app step) (map OK ts)"
11299
1d3d110c456e welltyping -> wt_step
nipkow
parents: 11229
diff changeset
   117
proof (unfold dynamic_wt_def wt_step_def, intro strip, rule conjI)
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   118
  assume bounded: "bounded step (size ts)"
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   119
  assume static:  "static_wt r app step ts"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   120
  fix p assume "p < length (map OK ts)" 
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   121
  hence p: "p < length ts" by simp
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   122
  thus "map OK ts ! p \<noteq> Err" by simp
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   123
  { fix q t
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   124
    assume q: "(q,t) \<in> set (err_step app step p (map OK ts ! p))" 
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   125
    with p static obtain 
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   126
      "app p (ts ! p)" "\<forall>(q,t) \<in> set (step p (ts!p)). t <=_r ts!q"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   127
      by (unfold static_wt_def) blast
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   128
    moreover
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   129
    from q p bounded have "q < size ts" 
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   130
      by (clarsimp simp add: bounded_def err_step_defs 
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   131
          split: err.splits split_if_asm) blast+
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   132
    hence "map OK ts ! q = OK (ts!q)" by simp
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   133
    moreover
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   134
    have "p < size ts" by (rule p)
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   135
    moreover note q
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   136
    ultimately     
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   137
    have "t <=_(Err.le r) map OK ts ! q" 
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   138
      by (auto simp add: err_step_def map_snd_def)
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   139
  }
12516
d09d0f160888 exceptions
kleing
parents: 11299
diff changeset
   140
  thus "stable (Err.le r) (err_step app step) (map OK ts) p"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   141
    by (unfold stable_def) blast
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   142
qed
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   143
f417841385b7 Got rid of is_dfa
nipkow
parents:
diff changeset
   144
end