src/HOL/MicroJava/BV/Kildall_Lift.thy
author wenzelm
Fri, 08 Mar 2002 16:24:06 +0100
changeset 13049 ce180e5b7fa0
parent 12516 d09d0f160888
child 13066 b57d926d1de2
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/Kildall_Lift.thy
d09d0f160888 exceptions
kleing
parents:
diff changeset
     2
    ID:         $Id$
d09d0f160888 exceptions
kleing
parents:
diff changeset
     3
    Author:     Gerwin Klein
d09d0f160888 exceptions
kleing
parents:
diff changeset
     4
    Copyright   2001 TUM
d09d0f160888 exceptions
kleing
parents:
diff changeset
     5
*)
d09d0f160888 exceptions
kleing
parents:
diff changeset
     6
d09d0f160888 exceptions
kleing
parents:
diff changeset
     7
theory Kildall_Lift = Kildall + Typing_Framework_err:
d09d0f160888 exceptions
kleing
parents:
diff changeset
     8
d09d0f160888 exceptions
kleing
parents:
diff changeset
     9
constdefs
d09d0f160888 exceptions
kleing
parents:
diff changeset
    10
 app_mono :: "'s ord \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> 's set \<Rightarrow> bool"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    11
"app_mono r app n A ==
d09d0f160888 exceptions
kleing
parents:
diff changeset
    12
 \<forall>s p t. s \<in> A \<and> p < n \<and> s <=_r t \<longrightarrow> app p t \<longrightarrow> app p s"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    13
d09d0f160888 exceptions
kleing
parents:
diff changeset
    14
 succs_stable :: "'s ord \<Rightarrow> 's step_type \<Rightarrow> bool"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    15
"succs_stable r step == \<forall>p t t'. map fst (step p t') = map fst (step p t)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    16
d09d0f160888 exceptions
kleing
parents:
diff changeset
    17
lemma succs_stableD:
d09d0f160888 exceptions
kleing
parents:
diff changeset
    18
  "succs_stable r step \<Longrightarrow> map fst (step p t) = map fst (step p t')"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    19
  by (unfold succs_stable_def) blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
    20
d09d0f160888 exceptions
kleing
parents:
diff changeset
    21
lemma eqsub_def [simp]: "a <=_(op =) b = (a = b)" by (simp add: lesub_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    22
d09d0f160888 exceptions
kleing
parents:
diff changeset
    23
lemma list_le_eq [simp]: "\<And>b. a <=[op =] b = (a = b)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    24
apply (induct a) 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    25
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    26
 apply rule
d09d0f160888 exceptions
kleing
parents:
diff changeset
    27
  apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    28
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    29
apply (case_tac b)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    30
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    31
apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    32
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
    33
d09d0f160888 exceptions
kleing
parents:
diff changeset
    34
lemma map_err: "map_err a = zip (map fst a) (map (\<lambda>x. Err) (map snd a))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    35
apply (induct a)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    36
apply (auto simp add: map_err_def map_snd_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    37
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
    38
d09d0f160888 exceptions
kleing
parents:
diff changeset
    39
lemma map_snd: "map_snd f a = zip (map fst a) (map f (map snd a))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    40
apply (induct a)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    41
apply (auto simp add: map_snd_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    42
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
    43
d09d0f160888 exceptions
kleing
parents:
diff changeset
    44
lemma zipI: 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    45
  "\<And>b c d. a <=[r1] c \<Longrightarrow> b <=[r2] d \<Longrightarrow> zip a b <=[Product.le r1 r2] zip c d"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    46
apply (induct a)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    47
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    48
apply (case_tac c)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    49
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    50
apply (case_tac b)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    51
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    52
apply (case_tac d)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    53
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    54
apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    55
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
    56
d09d0f160888 exceptions
kleing
parents:
diff changeset
    57
lemma step_type_ord: 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    58
  "\<And>b. a <=|r| b \<Longrightarrow> map snd a <=[r] map snd b \<and> map fst a = map fst b"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    59
apply (induct a)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    60
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    61
apply (case_tac b)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    62
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    63
apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    64
apply (auto simp add: Product.le_def lesub_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    65
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
    66
d09d0f160888 exceptions
kleing
parents:
diff changeset
    67
lemma map_OK_Err: 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    68
  "\<And>y. length y = length x \<Longrightarrow> map OK x <=[Err.le r] map (\<lambda>x. Err) y"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    69
apply (induct x)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    70
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    71
apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    72
apply (case_tac y)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    73
apply auto
d09d0f160888 exceptions
kleing
parents:
diff changeset
    74
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
    75
d09d0f160888 exceptions
kleing
parents:
diff changeset
    76
lemma map_Err_Err:
d09d0f160888 exceptions
kleing
parents:
diff changeset
    77
  "\<And>b. length a = length b \<Longrightarrow> map (\<lambda>x. Err) a <=[Err.le r] map (\<lambda>x. Err) b"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    78
apply (induct a)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    79
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    80
apply (case_tac b)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    81
apply auto
d09d0f160888 exceptions
kleing
parents:
diff changeset
    82
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
    83
d09d0f160888 exceptions
kleing
parents:
diff changeset
    84
lemma succs_stable_length: 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    85
  "succs_stable r step \<Longrightarrow> length (step p t) = length (step p t')"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    86
proof -
d09d0f160888 exceptions
kleing
parents:
diff changeset
    87
  assume "succs_stable r step"  
d09d0f160888 exceptions
kleing
parents:
diff changeset
    88
  hence "map fst (step p t) = map fst (step p t')" by (rule succs_stableD)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    89
  hence "length (map fst (step p t)) = length (map fst (step p t'))" by simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    90
  thus ?thesis by simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    91
qed
d09d0f160888 exceptions
kleing
parents:
diff changeset
    92
d09d0f160888 exceptions
kleing
parents:
diff changeset
    93
lemma le_list_map_OK [simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
    94
  "\<And>b. map OK a <=[Err.le r] map OK b = (a <=[r] b)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    95
  apply (induct a)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    96
   apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    97
  apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
    98
  apply (case_tac b)
d09d0f160888 exceptions
kleing
parents:
diff changeset
    99
   apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   100
  apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   101
  done
d09d0f160888 exceptions
kleing
parents:
diff changeset
   102
d09d0f160888 exceptions
kleing
parents:
diff changeset
   103
lemma mono_lift:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   104
  "order r \<Longrightarrow> succs_stable r step \<Longrightarrow> app_mono r app n A \<Longrightarrow> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   105
  \<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>
d09d0f160888 exceptions
kleing
parents:
diff changeset
   106
  mono (Err.le r) (err_step app step) n (err A)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   107
apply (unfold app_mono_def mono_def err_step_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   108
apply clarify
d09d0f160888 exceptions
kleing
parents:
diff changeset
   109
apply (case_tac s)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   110
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   111
 apply (rule le_list_refl)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   112
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   113
apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   114
apply (subgoal_tac "map fst (step p arbitrary) = map fst (step p a)")
d09d0f160888 exceptions
kleing
parents:
diff changeset
   115
 prefer 2
d09d0f160888 exceptions
kleing
parents:
diff changeset
   116
 apply (erule succs_stableD)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   117
apply (case_tac t)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   118
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   119
 apply (rule conjI)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   120
  apply clarify
d09d0f160888 exceptions
kleing
parents:
diff changeset
   121
  apply (simp add: map_err map_snd)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   122
  apply (rule zipI)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   123
   apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   124
  apply (rule map_OK_Err)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   125
  apply (subgoal_tac "length (step p arbitrary) = length (step p a)")
d09d0f160888 exceptions
kleing
parents:
diff changeset
   126
   prefer 2
d09d0f160888 exceptions
kleing
parents:
diff changeset
   127
   apply (erule succs_stable_length)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   128
  apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   129
 apply clarify
d09d0f160888 exceptions
kleing
parents:
diff changeset
   130
 apply (simp add: map_err)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   131
 apply (rule zipI)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   132
  apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   133
 apply (rule map_Err_Err)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   134
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   135
 apply (erule succs_stable_length)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   136
apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   137
apply (elim allE)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   138
apply (erule impE, blast)+
d09d0f160888 exceptions
kleing
parents:
diff changeset
   139
apply (rule conjI)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   140
 apply clarify
d09d0f160888 exceptions
kleing
parents:
diff changeset
   141
 apply (simp add: map_snd)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   142
 apply (rule zipI)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   143
  apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   144
  apply (erule succs_stableD)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   145
 apply (simp add: step_type_ord)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   146
apply clarify
d09d0f160888 exceptions
kleing
parents:
diff changeset
   147
apply (rule conjI)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   148
 apply clarify
d09d0f160888 exceptions
kleing
parents:
diff changeset
   149
 apply (simp add: map_snd map_err)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   150
 apply (rule zipI)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   151
  apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   152
  apply (erule succs_stableD)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   153
 apply (rule map_OK_Err)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   154
 apply (simp add: succs_stable_length)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   155
apply clarify
d09d0f160888 exceptions
kleing
parents:
diff changeset
   156
apply (simp add: map_err)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   157
apply (rule zipI)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   158
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   159
 apply (erule succs_stableD)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   160
apply (rule map_Err_Err)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   161
apply (simp add: succs_stable_length)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   162
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
   163
 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   164
lemma in_map_sndD: "(a,b) \<in> set (map_snd f xs) \<Longrightarrow> \<exists>b'. (a,b') \<in> set xs"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   165
apply (induct xs)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   166
apply (auto simp add: map_snd_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   167
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
   168
d09d0f160888 exceptions
kleing
parents:
diff changeset
   169
lemma bounded_lift:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   170
  "bounded (err_step app step) n = bounded step n"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   171
apply (unfold bounded_def err_step_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   172
apply rule
d09d0f160888 exceptions
kleing
parents:
diff changeset
   173
apply clarify
d09d0f160888 exceptions
kleing
parents:
diff changeset
   174
 apply (erule allE, erule impE, assumption)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   175
 apply (erule_tac x = "OK s" in allE)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   176
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   177
 apply (case_tac "app p s")
d09d0f160888 exceptions
kleing
parents:
diff changeset
   178
  apply (simp add: map_snd_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   179
  apply (drule bspec, assumption)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   180
  apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   181
 apply (simp add: map_err_def map_snd_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   182
 apply (drule bspec, assumption)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   183
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   184
apply clarify
d09d0f160888 exceptions
kleing
parents:
diff changeset
   185
apply (case_tac s)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   186
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   187
 apply (simp add: map_err_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   188
 apply (blast dest: in_map_sndD)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   189
apply (simp split: split_if_asm)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   190
 apply (blast dest: in_map_sndD)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   191
apply (simp add: map_err_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   192
apply (blast dest: in_map_sndD)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   193
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
   194
d09d0f160888 exceptions
kleing
parents:
diff changeset
   195
lemma set_zipD: "\<And>y. (a,b) \<in> set (zip x y) \<Longrightarrow> (a \<in> set x \<and> b \<in> set y)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   196
apply (induct x)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   197
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   198
apply (case_tac y)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   199
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   200
apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   201
apply blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
   202
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
   203
d09d0f160888 exceptions
kleing
parents:
diff changeset
   204
lemma pres_type_lift:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   205
  "\<forall>s\<in>A. \<forall>p. p < n \<longrightarrow> app p s \<longrightarrow> (\<forall>(q, s')\<in>set (step p s). s' \<in> A) 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   206
  \<Longrightarrow> pres_type (err_step app step) n (err A)"  
d09d0f160888 exceptions
kleing
parents:
diff changeset
   207
apply (unfold pres_type_def err_step_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   208
apply clarify
d09d0f160888 exceptions
kleing
parents:
diff changeset
   209
apply (case_tac b)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   210
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   211
apply (case_tac s)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   212
 apply (simp add: map_err)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   213
 apply (drule set_zipD)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   214
 apply clarify
d09d0f160888 exceptions
kleing
parents:
diff changeset
   215
 apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   216
 apply blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
   217
apply (simp add: map_err split: split_if_asm)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   218
 apply (simp add: map_snd_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   219
 apply fastsimp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   220
apply (drule set_zipD)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   221
apply simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   222
apply blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
   223
done
d09d0f160888 exceptions
kleing
parents:
diff changeset
   224
d09d0f160888 exceptions
kleing
parents:
diff changeset
   225
end