src/HOL/MicroJava/DFA/Listn.thy
author haftmann
Tue Nov 24 14:37:23 2009 +0100 (2009-11-24)
changeset 33954 1bc3b688548c
child 35102 cc7a0b9f938c
permissions -rwxr-xr-x
backported parts of abstract byte code verifier from AFP/Jinja
haftmann@33954
     1
(*  Title:      HOL/MicroJava/BV/Listn.thy
haftmann@33954
     2
    Author:     Tobias Nipkow
haftmann@33954
     3
    Copyright   2000 TUM
haftmann@33954
     4
*)
haftmann@33954
     5
haftmann@33954
     6
header {* \isaheader{Fixed Length Lists} *}
haftmann@33954
     7
haftmann@33954
     8
theory Listn
haftmann@33954
     9
imports Err
haftmann@33954
    10
begin
haftmann@33954
    11
haftmann@33954
    12
constdefs
haftmann@33954
    13
haftmann@33954
    14
 list :: "nat \<Rightarrow> 'a set \<Rightarrow> 'a list set"
haftmann@33954
    15
"list n A == {xs. length xs = n & set xs <= A}"
haftmann@33954
    16
haftmann@33954
    17
 le :: "'a ord \<Rightarrow> ('a list)ord"
haftmann@33954
    18
"le r == list_all2 (%x y. x <=_r y)"
haftmann@33954
    19
haftmann@33954
    20
syntax "@lesublist" :: "'a list \<Rightarrow> 'a ord \<Rightarrow> 'a list \<Rightarrow> bool"
haftmann@33954
    21
       ("(_ /<=[_] _)" [50, 0, 51] 50)
haftmann@33954
    22
syntax "@lesssublist" :: "'a list \<Rightarrow> 'a ord \<Rightarrow> 'a list \<Rightarrow> bool"
haftmann@33954
    23
       ("(_ /<[_] _)" [50, 0, 51] 50)
haftmann@33954
    24
translations
haftmann@33954
    25
 "x <=[r] y" == "x <=_(Listn.le r) y"
haftmann@33954
    26
 "x <[r] y"  == "x <_(Listn.le r) y"
haftmann@33954
    27
haftmann@33954
    28
constdefs
haftmann@33954
    29
 map2 :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a list \<Rightarrow> 'b list \<Rightarrow> 'c list"
haftmann@33954
    30
"map2 f == (%xs ys. map (split f) (zip xs ys))"
haftmann@33954
    31
haftmann@33954
    32
syntax "@plussublist" :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b list \<Rightarrow> 'c list"
haftmann@33954
    33
       ("(_ /+[_] _)" [65, 0, 66] 65)
haftmann@33954
    34
translations  "x +[f] y" == "x +_(map2 f) y"
haftmann@33954
    35
haftmann@33954
    36
consts coalesce :: "'a err list \<Rightarrow> 'a list err"
haftmann@33954
    37
primrec
haftmann@33954
    38
"coalesce [] = OK[]"
haftmann@33954
    39
"coalesce (ex#exs) = Err.sup (op #) ex (coalesce exs)"
haftmann@33954
    40
haftmann@33954
    41
constdefs
haftmann@33954
    42
 sl :: "nat \<Rightarrow> 'a sl \<Rightarrow> 'a list sl"
haftmann@33954
    43
"sl n == %(A,r,f). (list n A, le r, map2 f)"
haftmann@33954
    44
haftmann@33954
    45
 sup :: "('a \<Rightarrow> 'b \<Rightarrow> 'c err) \<Rightarrow> 'a list \<Rightarrow> 'b list \<Rightarrow> 'c list err"
haftmann@33954
    46
"sup f == %xs ys. if size xs = size ys then coalesce(xs +[f] ys) else Err"
haftmann@33954
    47
haftmann@33954
    48
 upto_esl :: "nat \<Rightarrow> 'a esl \<Rightarrow> 'a list esl"
haftmann@33954
    49
"upto_esl m == %(A,r,f). (Union{list n A |n. n <= m}, le r, sup f)"
haftmann@33954
    50
haftmann@33954
    51
lemmas [simp] = set_update_subsetI
haftmann@33954
    52
haftmann@33954
    53
lemma unfold_lesub_list:
haftmann@33954
    54
  "xs <=[r] ys == Listn.le r xs ys"
haftmann@33954
    55
  by (simp add: lesub_def)
haftmann@33954
    56
haftmann@33954
    57
lemma Nil_le_conv [iff]:
haftmann@33954
    58
  "([] <=[r] ys) = (ys = [])"
haftmann@33954
    59
apply (unfold lesub_def Listn.le_def)
haftmann@33954
    60
apply simp
haftmann@33954
    61
done
haftmann@33954
    62
haftmann@33954
    63
lemma Cons_notle_Nil [iff]: 
haftmann@33954
    64
  "~ x#xs <=[r] []"
haftmann@33954
    65
apply (unfold lesub_def Listn.le_def)
haftmann@33954
    66
apply simp
haftmann@33954
    67
done
haftmann@33954
    68
haftmann@33954
    69
haftmann@33954
    70
lemma Cons_le_Cons [iff]:
haftmann@33954
    71
  "x#xs <=[r] y#ys = (x <=_r y & xs <=[r] ys)"
haftmann@33954
    72
apply (unfold lesub_def Listn.le_def)
haftmann@33954
    73
apply simp
haftmann@33954
    74
done
haftmann@33954
    75
haftmann@33954
    76
lemma Cons_less_Conss [simp]:
haftmann@33954
    77
  "order r \<Longrightarrow> 
haftmann@33954
    78
  x#xs <_(Listn.le r) y#ys = 
haftmann@33954
    79
  (x <_r y & xs <=[r] ys  |  x = y & xs <_(Listn.le r) ys)"
haftmann@33954
    80
apply (unfold lesssub_def)
haftmann@33954
    81
apply blast
haftmann@33954
    82
done  
haftmann@33954
    83
haftmann@33954
    84
lemma list_update_le_cong:
haftmann@33954
    85
  "\<lbrakk> i<size xs; xs <=[r] ys; x <=_r y \<rbrakk> \<Longrightarrow> xs[i:=x] <=[r] ys[i:=y]";
haftmann@33954
    86
apply (unfold unfold_lesub_list)
haftmann@33954
    87
apply (unfold Listn.le_def)
haftmann@33954
    88
apply (simp add: list_all2_conv_all_nth nth_list_update)
haftmann@33954
    89
done
haftmann@33954
    90
haftmann@33954
    91
haftmann@33954
    92
lemma le_listD:
haftmann@33954
    93
  "\<lbrakk> xs <=[r] ys; p < size xs \<rbrakk> \<Longrightarrow> xs!p <=_r ys!p"
haftmann@33954
    94
apply (unfold Listn.le_def lesub_def)
haftmann@33954
    95
apply (simp add: list_all2_conv_all_nth)
haftmann@33954
    96
done
haftmann@33954
    97
haftmann@33954
    98
lemma le_list_refl:
haftmann@33954
    99
  "!x. x <=_r x \<Longrightarrow> xs <=[r] xs"
haftmann@33954
   100
apply (unfold unfold_lesub_list)
haftmann@33954
   101
apply (simp add: Listn.le_def list_all2_conv_all_nth)
haftmann@33954
   102
done
haftmann@33954
   103
haftmann@33954
   104
lemma le_list_trans:
haftmann@33954
   105
  "\<lbrakk> order r; xs <=[r] ys; ys <=[r] zs \<rbrakk> \<Longrightarrow> xs <=[r] zs"
haftmann@33954
   106
apply (unfold unfold_lesub_list)
haftmann@33954
   107
apply (simp add: Listn.le_def list_all2_conv_all_nth)
haftmann@33954
   108
apply clarify
haftmann@33954
   109
apply simp
haftmann@33954
   110
apply (blast intro: order_trans)
haftmann@33954
   111
done
haftmann@33954
   112
haftmann@33954
   113
lemma le_list_antisym:
haftmann@33954
   114
  "\<lbrakk> order r; xs <=[r] ys; ys <=[r] xs \<rbrakk> \<Longrightarrow> xs = ys"
haftmann@33954
   115
apply (unfold unfold_lesub_list)
haftmann@33954
   116
apply (simp add: Listn.le_def list_all2_conv_all_nth)
haftmann@33954
   117
apply (rule nth_equalityI)
haftmann@33954
   118
 apply blast
haftmann@33954
   119
apply clarify
haftmann@33954
   120
apply simp
haftmann@33954
   121
apply (blast intro: order_antisym)
haftmann@33954
   122
done
haftmann@33954
   123
haftmann@33954
   124
lemma order_listI [simp, intro!]:
haftmann@33954
   125
  "order r \<Longrightarrow> order(Listn.le r)"
haftmann@33954
   126
apply (subst Semilat.order_def)
haftmann@33954
   127
apply (blast intro: le_list_refl le_list_trans le_list_antisym
haftmann@33954
   128
             dest: order_refl)
haftmann@33954
   129
done
haftmann@33954
   130
haftmann@33954
   131
haftmann@33954
   132
lemma lesub_list_impl_same_size [simp]:
haftmann@33954
   133
  "xs <=[r] ys \<Longrightarrow> size ys = size xs"  
haftmann@33954
   134
apply (unfold Listn.le_def lesub_def)
haftmann@33954
   135
apply (simp add: list_all2_conv_all_nth)
haftmann@33954
   136
done 
haftmann@33954
   137
haftmann@33954
   138
lemma lesssub_list_impl_same_size:
haftmann@33954
   139
  "xs <_(Listn.le r) ys \<Longrightarrow> size ys = size xs"
haftmann@33954
   140
apply (unfold lesssub_def)
haftmann@33954
   141
apply auto
haftmann@33954
   142
done  
haftmann@33954
   143
haftmann@33954
   144
lemma le_list_appendI:
haftmann@33954
   145
  "\<And>b c d. a <=[r] b \<Longrightarrow> c <=[r] d \<Longrightarrow> a@c <=[r] b@d"
haftmann@33954
   146
apply (induct a)
haftmann@33954
   147
 apply simp
haftmann@33954
   148
apply (case_tac b)
haftmann@33954
   149
apply auto
haftmann@33954
   150
done
haftmann@33954
   151
haftmann@33954
   152
lemma le_listI:
haftmann@33954
   153
  "length a = length b \<Longrightarrow> (\<And>n. n < length a \<Longrightarrow> a!n <=_r b!n) \<Longrightarrow> a <=[r] b"
haftmann@33954
   154
  apply (unfold lesub_def Listn.le_def)
haftmann@33954
   155
  apply (simp add: list_all2_conv_all_nth)
haftmann@33954
   156
  done
haftmann@33954
   157
haftmann@33954
   158
lemma listI:
haftmann@33954
   159
  "\<lbrakk> length xs = n; set xs <= A \<rbrakk> \<Longrightarrow> xs : list n A"
haftmann@33954
   160
apply (unfold list_def)
haftmann@33954
   161
apply blast
haftmann@33954
   162
done
haftmann@33954
   163
haftmann@33954
   164
lemma listE_length [simp]:
haftmann@33954
   165
   "xs : list n A \<Longrightarrow> length xs = n"
haftmann@33954
   166
apply (unfold list_def)
haftmann@33954
   167
apply blast
haftmann@33954
   168
done 
haftmann@33954
   169
haftmann@33954
   170
lemma less_lengthI:
haftmann@33954
   171
  "\<lbrakk> xs : list n A; p < n \<rbrakk> \<Longrightarrow> p < length xs"
haftmann@33954
   172
  by simp
haftmann@33954
   173
haftmann@33954
   174
lemma listE_set [simp]:
haftmann@33954
   175
  "xs : list n A \<Longrightarrow> set xs <= A"
haftmann@33954
   176
apply (unfold list_def)
haftmann@33954
   177
apply blast
haftmann@33954
   178
done 
haftmann@33954
   179
haftmann@33954
   180
lemma list_0 [simp]:
haftmann@33954
   181
  "list 0 A = {[]}"
haftmann@33954
   182
apply (unfold list_def)
haftmann@33954
   183
apply auto
haftmann@33954
   184
done 
haftmann@33954
   185
haftmann@33954
   186
lemma in_list_Suc_iff: 
haftmann@33954
   187
  "(xs : list (Suc n) A) = (\<exists>y\<in> A. \<exists>ys\<in> list n A. xs = y#ys)"
haftmann@33954
   188
apply (unfold list_def)
haftmann@33954
   189
apply (case_tac "xs")
haftmann@33954
   190
apply auto
haftmann@33954
   191
done 
haftmann@33954
   192
haftmann@33954
   193
lemma Cons_in_list_Suc [iff]:
haftmann@33954
   194
  "(x#xs : list (Suc n) A) = (x\<in> A & xs : list n A)";
haftmann@33954
   195
apply (simp add: in_list_Suc_iff)
haftmann@33954
   196
done 
haftmann@33954
   197
haftmann@33954
   198
lemma list_not_empty:
haftmann@33954
   199
  "\<exists>a. a\<in> A \<Longrightarrow> \<exists>xs. xs : list n A";
haftmann@33954
   200
apply (induct "n")
haftmann@33954
   201
 apply simp
haftmann@33954
   202
apply (simp add: in_list_Suc_iff)
haftmann@33954
   203
apply blast
haftmann@33954
   204
done
haftmann@33954
   205
haftmann@33954
   206
haftmann@33954
   207
lemma nth_in [rule_format, simp]:
haftmann@33954
   208
  "!i n. length xs = n \<longrightarrow> set xs <= A \<longrightarrow> i < n \<longrightarrow> (xs!i) : A"
haftmann@33954
   209
apply (induct "xs")
haftmann@33954
   210
 apply simp
haftmann@33954
   211
apply (simp add: nth_Cons split: nat.split)
haftmann@33954
   212
done
haftmann@33954
   213
haftmann@33954
   214
lemma listE_nth_in:
haftmann@33954
   215
  "\<lbrakk> xs : list n A; i < n \<rbrakk> \<Longrightarrow> (xs!i) : A"
haftmann@33954
   216
  by auto
haftmann@33954
   217
haftmann@33954
   218
haftmann@33954
   219
lemma listn_Cons_Suc [elim!]:
haftmann@33954
   220
  "l#xs \<in> list n A \<Longrightarrow> (\<And>n'. n = Suc n' \<Longrightarrow> l \<in> A \<Longrightarrow> xs \<in> list n' A \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@33954
   221
  by (cases n) auto
haftmann@33954
   222
haftmann@33954
   223
lemma listn_appendE [elim!]:
haftmann@33954
   224
  "a@b \<in> list n A \<Longrightarrow> (\<And>n1 n2. n=n1+n2 \<Longrightarrow> a \<in> list n1 A \<Longrightarrow> b \<in> list n2 A \<Longrightarrow> P) \<Longrightarrow> P" 
haftmann@33954
   225
proof -
haftmann@33954
   226
  have "\<And>n. a@b \<in> list n A \<Longrightarrow> \<exists>n1 n2. n=n1+n2 \<and> a \<in> list n1 A \<and> b \<in> list n2 A"
haftmann@33954
   227
    (is "\<And>n. ?list a n \<Longrightarrow> \<exists>n1 n2. ?P a n n1 n2")
haftmann@33954
   228
  proof (induct a)
haftmann@33954
   229
    fix n assume "?list [] n"
haftmann@33954
   230
    hence "?P [] n 0 n" by simp
haftmann@33954
   231
    thus "\<exists>n1 n2. ?P [] n n1 n2" by fast
haftmann@33954
   232
  next
haftmann@33954
   233
    fix n l ls
haftmann@33954
   234
    assume "?list (l#ls) n"
haftmann@33954
   235
    then obtain n' where n: "n = Suc n'" "l \<in> A" and list_n': "ls@b \<in> list n' A" by fastsimp
haftmann@33954
   236
    assume "\<And>n. ls @ b \<in> list n A \<Longrightarrow> \<exists>n1 n2. n = n1 + n2 \<and> ls \<in> list n1 A \<and> b \<in> list n2 A"
haftmann@33954
   237
    hence "\<exists>n1 n2. n' = n1 + n2 \<and> ls \<in> list n1 A \<and> b \<in> list n2 A" by this (rule list_n')
haftmann@33954
   238
    then obtain n1 n2 where "n' = n1 + n2" "ls \<in> list n1 A" "b \<in> list n2 A" by fast
haftmann@33954
   239
    with n have "?P (l#ls) n (n1+1) n2" by simp
haftmann@33954
   240
    thus "\<exists>n1 n2. ?P (l#ls) n n1 n2" by fastsimp
haftmann@33954
   241
  qed
haftmann@33954
   242
  moreover
haftmann@33954
   243
  assume "a@b \<in> list n A" "\<And>n1 n2. n=n1+n2 \<Longrightarrow> a \<in> list n1 A \<Longrightarrow> b \<in> list n2 A \<Longrightarrow> P"
haftmann@33954
   244
  ultimately
haftmann@33954
   245
  show ?thesis by blast
haftmann@33954
   246
qed
haftmann@33954
   247
haftmann@33954
   248
haftmann@33954
   249
lemma listt_update_in_list [simp, intro!]:
haftmann@33954
   250
  "\<lbrakk> xs : list n A; x\<in> A \<rbrakk> \<Longrightarrow> xs[i := x] : list n A"
haftmann@33954
   251
apply (unfold list_def)
haftmann@33954
   252
apply simp
haftmann@33954
   253
done 
haftmann@33954
   254
haftmann@33954
   255
lemma plus_list_Nil [simp]:
haftmann@33954
   256
  "[] +[f] xs = []"
haftmann@33954
   257
apply (unfold plussub_def map2_def)
haftmann@33954
   258
apply simp
haftmann@33954
   259
done 
haftmann@33954
   260
haftmann@33954
   261
lemma plus_list_Cons [simp]:
haftmann@33954
   262
  "(x#xs) +[f] ys = (case ys of [] \<Rightarrow> [] | y#ys \<Rightarrow> (x +_f y)#(xs +[f] ys))"
haftmann@33954
   263
  by (simp add: plussub_def map2_def split: list.split)
haftmann@33954
   264
haftmann@33954
   265
lemma length_plus_list [rule_format, simp]:
haftmann@33954
   266
  "!ys. length(xs +[f] ys) = min(length xs) (length ys)"
haftmann@33954
   267
apply (induct xs)
haftmann@33954
   268
 apply simp
haftmann@33954
   269
apply clarify
haftmann@33954
   270
apply (simp (no_asm_simp) split: list.split)
haftmann@33954
   271
done
haftmann@33954
   272
haftmann@33954
   273
lemma nth_plus_list [rule_format, simp]:
haftmann@33954
   274
  "!xs ys i. length xs = n \<longrightarrow> length ys = n \<longrightarrow> i<n \<longrightarrow> 
haftmann@33954
   275
  (xs +[f] ys)!i = (xs!i) +_f (ys!i)"
haftmann@33954
   276
apply (induct n)
haftmann@33954
   277
 apply simp
haftmann@33954
   278
apply clarify
haftmann@33954
   279
apply (case_tac xs)
haftmann@33954
   280
 apply simp
haftmann@33954
   281
apply (force simp add: nth_Cons split: list.split nat.split)
haftmann@33954
   282
done
haftmann@33954
   283
haftmann@33954
   284
haftmann@33954
   285
lemma (in Semilat) plus_list_ub1 [rule_format]:
haftmann@33954
   286
 "\<lbrakk> set xs <= A; set ys <= A; size xs = size ys \<rbrakk> 
haftmann@33954
   287
  \<Longrightarrow> xs <=[r] xs +[f] ys"
haftmann@33954
   288
apply (unfold unfold_lesub_list)
haftmann@33954
   289
apply (simp add: Listn.le_def list_all2_conv_all_nth)
haftmann@33954
   290
done
haftmann@33954
   291
haftmann@33954
   292
lemma (in Semilat) plus_list_ub2:
haftmann@33954
   293
 "\<lbrakk>set xs <= A; set ys <= A; size xs = size ys \<rbrakk>
haftmann@33954
   294
  \<Longrightarrow> ys <=[r] xs +[f] ys"
haftmann@33954
   295
apply (unfold unfold_lesub_list)
haftmann@33954
   296
apply (simp add: Listn.le_def list_all2_conv_all_nth)
haftmann@33954
   297
done
haftmann@33954
   298
haftmann@33954
   299
lemma (in Semilat) plus_list_lub [rule_format]:
haftmann@33954
   300
shows "!xs ys zs. set xs <= A \<longrightarrow> set ys <= A \<longrightarrow> set zs <= A 
haftmann@33954
   301
  \<longrightarrow> size xs = n & size ys = n \<longrightarrow> 
haftmann@33954
   302
  xs <=[r] zs & ys <=[r] zs \<longrightarrow> xs +[f] ys <=[r] zs"
haftmann@33954
   303
apply (unfold unfold_lesub_list)
haftmann@33954
   304
apply (simp add: Listn.le_def list_all2_conv_all_nth)
haftmann@33954
   305
done
haftmann@33954
   306
haftmann@33954
   307
lemma (in Semilat) list_update_incr [rule_format]:
haftmann@33954
   308
 "x\<in> A \<Longrightarrow> set xs <= A \<longrightarrow> 
haftmann@33954
   309
  (!i. i<size xs \<longrightarrow> xs <=[r] xs[i := x +_f xs!i])"
haftmann@33954
   310
apply (unfold unfold_lesub_list)
haftmann@33954
   311
apply (simp add: Listn.le_def list_all2_conv_all_nth)
haftmann@33954
   312
apply (induct xs)
haftmann@33954
   313
 apply simp
haftmann@33954
   314
apply (simp add: in_list_Suc_iff)
haftmann@33954
   315
apply clarify
haftmann@33954
   316
apply (simp add: nth_Cons split: nat.split)
haftmann@33954
   317
done
haftmann@33954
   318
haftmann@33954
   319
lemma equals0I_aux:
haftmann@33954
   320
  "(\<And>y. A y \<Longrightarrow> False) \<Longrightarrow> A = bot_class.bot"
haftmann@33954
   321
  by (rule equals0I) (auto simp add: mem_def)
haftmann@33954
   322
haftmann@33954
   323
lemma acc_le_listI [intro!]:
haftmann@33954
   324
  "\<lbrakk> order r; acc r \<rbrakk> \<Longrightarrow> acc(Listn.le r)"
haftmann@33954
   325
apply (unfold acc_def)
haftmann@33954
   326
apply (subgoal_tac
haftmann@33954
   327
 "wf(UN n. {(ys,xs). size xs = n \<and> size ys = n \<and> xs <_(Listn.le r) ys})")
haftmann@33954
   328
 apply (erule wf_subset)
haftmann@33954
   329
 apply (blast intro: lesssub_list_impl_same_size)
haftmann@33954
   330
apply (rule wf_UN)
haftmann@33954
   331
 prefer 2
haftmann@33954
   332
 apply clarify
haftmann@33954
   333
 apply (rename_tac m n)
haftmann@33954
   334
 apply (case_tac "m=n")
haftmann@33954
   335
  apply simp
haftmann@33954
   336
 apply (fast intro!: equals0I dest: not_sym)
haftmann@33954
   337
apply clarify
haftmann@33954
   338
apply (rename_tac n)
haftmann@33954
   339
apply (induct_tac n)
haftmann@33954
   340
 apply (simp add: lesssub_def cong: conj_cong)
haftmann@33954
   341
apply (rename_tac k)
haftmann@33954
   342
apply (simp add: wf_eq_minimal)
haftmann@33954
   343
apply (simp (no_asm) add: length_Suc_conv cong: conj_cong)
haftmann@33954
   344
apply clarify
haftmann@33954
   345
apply (rename_tac M m)
haftmann@33954
   346
apply (case_tac "\<exists>x xs. size xs = k \<and> x#xs \<in> M")
haftmann@33954
   347
 prefer 2
haftmann@33954
   348
 apply (erule thin_rl)
haftmann@33954
   349
 apply (erule thin_rl)
haftmann@33954
   350
 apply blast
haftmann@33954
   351
apply (erule_tac x = "{a. \<exists>xs. size xs = k \<and> a#xs:M}" in allE)
haftmann@33954
   352
apply (erule impE)
haftmann@33954
   353
 apply blast
haftmann@33954
   354
apply (thin_tac "\<exists>x xs. ?P x xs")
haftmann@33954
   355
apply clarify
haftmann@33954
   356
apply (rename_tac maxA xs)
haftmann@33954
   357
apply (erule_tac x = "{ys. size ys = size xs \<and> maxA#ys \<in> M}" in allE)
haftmann@33954
   358
apply (erule impE)
haftmann@33954
   359
 apply blast
haftmann@33954
   360
apply clarify
haftmann@33954
   361
apply (thin_tac "m \<in> M")
haftmann@33954
   362
apply (thin_tac "maxA#xs \<in> M")
haftmann@33954
   363
apply (rule bexI)
haftmann@33954
   364
 prefer 2
haftmann@33954
   365
 apply assumption
haftmann@33954
   366
apply clarify
haftmann@33954
   367
apply simp
haftmann@33954
   368
apply blast
haftmann@33954
   369
done
haftmann@33954
   370
haftmann@33954
   371
lemma closed_listI:
haftmann@33954
   372
  "closed S f \<Longrightarrow> closed (list n S) (map2 f)"
haftmann@33954
   373
apply (unfold closed_def)
haftmann@33954
   374
apply (induct n)
haftmann@33954
   375
 apply simp
haftmann@33954
   376
apply clarify
haftmann@33954
   377
apply (simp add: in_list_Suc_iff)
haftmann@33954
   378
apply clarify
haftmann@33954
   379
apply simp
haftmann@33954
   380
done
haftmann@33954
   381
haftmann@33954
   382
haftmann@33954
   383
lemma Listn_sl_aux:
haftmann@33954
   384
assumes "semilat (A, r, f)" shows "semilat (Listn.sl n (A,r,f))"
haftmann@33954
   385
proof -
haftmann@33954
   386
  interpret Semilat A r f using assms by (rule Semilat.intro)
haftmann@33954
   387
show ?thesis
haftmann@33954
   388
apply (unfold Listn.sl_def)
haftmann@33954
   389
apply (simp (no_asm) only: semilat_Def split_conv)
haftmann@33954
   390
apply (rule conjI)
haftmann@33954
   391
 apply simp
haftmann@33954
   392
apply (rule conjI)
haftmann@33954
   393
 apply (simp only: closedI closed_listI)
haftmann@33954
   394
apply (simp (no_asm) only: list_def)
haftmann@33954
   395
apply (simp (no_asm_simp) add: plus_list_ub1 plus_list_ub2 plus_list_lub)
haftmann@33954
   396
done
haftmann@33954
   397
qed
haftmann@33954
   398
haftmann@33954
   399
lemma Listn_sl: "\<And>L. semilat L \<Longrightarrow> semilat (Listn.sl n L)"
haftmann@33954
   400
 by(simp add: Listn_sl_aux split_tupled_all)
haftmann@33954
   401
haftmann@33954
   402
lemma coalesce_in_err_list [rule_format]:
haftmann@33954
   403
  "!xes. xes : list n (err A) \<longrightarrow> coalesce xes : err(list n A)"
haftmann@33954
   404
apply (induct n)
haftmann@33954
   405
 apply simp
haftmann@33954
   406
apply clarify
haftmann@33954
   407
apply (simp add: in_list_Suc_iff)
haftmann@33954
   408
apply clarify
haftmann@33954
   409
apply (simp (no_asm) add: plussub_def Err.sup_def lift2_def split: err.split)
haftmann@33954
   410
apply force
haftmann@33954
   411
done 
haftmann@33954
   412
haftmann@33954
   413
lemma lem: "\<And>x xs. x +_(op #) xs = x#xs"
haftmann@33954
   414
  by (simp add: plussub_def)
haftmann@33954
   415
haftmann@33954
   416
lemma coalesce_eq_OK1_D [rule_format]:
haftmann@33954
   417
  "semilat(err A, Err.le r, lift2 f) \<Longrightarrow> 
haftmann@33954
   418
  !xs. xs : list n A \<longrightarrow> (!ys. ys : list n A \<longrightarrow> 
haftmann@33954
   419
  (!zs. coalesce (xs +[f] ys) = OK zs \<longrightarrow> xs <=[r] zs))"
haftmann@33954
   420
apply (induct n)
haftmann@33954
   421
  apply simp
haftmann@33954
   422
apply clarify
haftmann@33954
   423
apply (simp add: in_list_Suc_iff)
haftmann@33954
   424
apply clarify
haftmann@33954
   425
apply (simp split: err.split_asm add: lem Err.sup_def lift2_def)
haftmann@33954
   426
apply (force simp add: semilat_le_err_OK1)
haftmann@33954
   427
done
haftmann@33954
   428
haftmann@33954
   429
lemma coalesce_eq_OK2_D [rule_format]:
haftmann@33954
   430
  "semilat(err A, Err.le r, lift2 f) \<Longrightarrow> 
haftmann@33954
   431
  !xs. xs : list n A \<longrightarrow> (!ys. ys : list n A \<longrightarrow> 
haftmann@33954
   432
  (!zs. coalesce (xs +[f] ys) = OK zs \<longrightarrow> ys <=[r] zs))"
haftmann@33954
   433
apply (induct n)
haftmann@33954
   434
 apply simp
haftmann@33954
   435
apply clarify
haftmann@33954
   436
apply (simp add: in_list_Suc_iff)
haftmann@33954
   437
apply clarify
haftmann@33954
   438
apply (simp split: err.split_asm add: lem Err.sup_def lift2_def)
haftmann@33954
   439
apply (force simp add: semilat_le_err_OK2)
haftmann@33954
   440
done 
haftmann@33954
   441
haftmann@33954
   442
lemma lift2_le_ub:
haftmann@33954
   443
  "\<lbrakk> semilat(err A, Err.le r, lift2 f); x\<in> A; y\<in> A; x +_f y = OK z; 
haftmann@33954
   444
      u\<in> A; x <=_r u; y <=_r u \<rbrakk> \<Longrightarrow> z <=_r u"
haftmann@33954
   445
apply (unfold semilat_Def plussub_def err_def)
haftmann@33954
   446
apply (simp add: lift2_def)
haftmann@33954
   447
apply clarify
haftmann@33954
   448
apply (rotate_tac -3)
haftmann@33954
   449
apply (erule thin_rl)
haftmann@33954
   450
apply (erule thin_rl)
haftmann@33954
   451
apply force
haftmann@33954
   452
done
haftmann@33954
   453
haftmann@33954
   454
lemma coalesce_eq_OK_ub_D [rule_format]:
haftmann@33954
   455
  "semilat(err A, Err.le r, lift2 f) \<Longrightarrow> 
haftmann@33954
   456
  !xs. xs : list n A \<longrightarrow> (!ys. ys : list n A \<longrightarrow> 
haftmann@33954
   457
  (!zs us. coalesce (xs +[f] ys) = OK zs & xs <=[r] us & ys <=[r] us 
haftmann@33954
   458
           & us : list n A \<longrightarrow> zs <=[r] us))"
haftmann@33954
   459
apply (induct n)
haftmann@33954
   460
 apply simp
haftmann@33954
   461
apply clarify
haftmann@33954
   462
apply (simp add: in_list_Suc_iff)
haftmann@33954
   463
apply clarify
haftmann@33954
   464
apply (simp (no_asm_use) split: err.split_asm add: lem Err.sup_def lift2_def)
haftmann@33954
   465
apply clarify
haftmann@33954
   466
apply (rule conjI)
haftmann@33954
   467
 apply (blast intro: lift2_le_ub)
haftmann@33954
   468
apply blast
haftmann@33954
   469
done 
haftmann@33954
   470
haftmann@33954
   471
lemma lift2_eq_ErrD:
haftmann@33954
   472
  "\<lbrakk> x +_f y = Err; semilat(err A, Err.le r, lift2 f); x\<in> A; y\<in> A \<rbrakk> 
haftmann@33954
   473
  \<Longrightarrow> ~(\<exists>u\<in> A. x <=_r u & y <=_r u)"
haftmann@33954
   474
  by (simp add: OK_plus_OK_eq_Err_conv [THEN iffD1])
haftmann@33954
   475
haftmann@33954
   476
haftmann@33954
   477
lemma coalesce_eq_Err_D [rule_format]:
haftmann@33954
   478
  "\<lbrakk> semilat(err A, Err.le r, lift2 f) \<rbrakk> 
haftmann@33954
   479
  \<Longrightarrow> !xs. xs\<in> list n A \<longrightarrow> (!ys. ys\<in> list n A \<longrightarrow> 
haftmann@33954
   480
      coalesce (xs +[f] ys) = Err \<longrightarrow> 
haftmann@33954
   481
      ~(\<exists>zs\<in> list n A. xs <=[r] zs & ys <=[r] zs))"
haftmann@33954
   482
apply (induct n)
haftmann@33954
   483
 apply simp
haftmann@33954
   484
apply clarify
haftmann@33954
   485
apply (simp add: in_list_Suc_iff)
haftmann@33954
   486
apply clarify
haftmann@33954
   487
apply (simp split: err.split_asm add: lem Err.sup_def lift2_def)
haftmann@33954
   488
 apply (blast dest: lift2_eq_ErrD)
haftmann@33954
   489
done 
haftmann@33954
   490
haftmann@33954
   491
lemma closed_err_lift2_conv:
haftmann@33954
   492
  "closed (err A) (lift2 f) = (\<forall>x\<in> A. \<forall>y\<in> A. x +_f y : err A)"
haftmann@33954
   493
apply (unfold closed_def)
haftmann@33954
   494
apply (simp add: err_def)
haftmann@33954
   495
done 
haftmann@33954
   496
haftmann@33954
   497
lemma closed_map2_list [rule_format]:
haftmann@33954
   498
  "closed (err A) (lift2 f) \<Longrightarrow> 
haftmann@33954
   499
  \<forall>xs. xs : list n A \<longrightarrow> (\<forall>ys. ys : list n A \<longrightarrow> 
haftmann@33954
   500
  map2 f xs ys : list n (err A))"
haftmann@33954
   501
apply (unfold map2_def)
haftmann@33954
   502
apply (induct n)
haftmann@33954
   503
 apply simp
haftmann@33954
   504
apply clarify
haftmann@33954
   505
apply (simp add: in_list_Suc_iff)
haftmann@33954
   506
apply clarify
haftmann@33954
   507
apply (simp add: plussub_def closed_err_lift2_conv)
haftmann@33954
   508
done
haftmann@33954
   509
haftmann@33954
   510
lemma closed_lift2_sup:
haftmann@33954
   511
  "closed (err A) (lift2 f) \<Longrightarrow> 
haftmann@33954
   512
  closed (err (list n A)) (lift2 (sup f))"
haftmann@33954
   513
  by (fastsimp  simp add: closed_def plussub_def sup_def lift2_def
haftmann@33954
   514
                          coalesce_in_err_list closed_map2_list
haftmann@33954
   515
                split: err.split)
haftmann@33954
   516
haftmann@33954
   517
lemma err_semilat_sup:
haftmann@33954
   518
  "err_semilat (A,r,f) \<Longrightarrow> 
haftmann@33954
   519
  err_semilat (list n A, Listn.le r, sup f)"
haftmann@33954
   520
apply (unfold Err.sl_def)
haftmann@33954
   521
apply (simp only: split_conv)
haftmann@33954
   522
apply (simp (no_asm) only: semilat_Def plussub_def)
haftmann@33954
   523
apply (simp (no_asm_simp) only: Semilat.closedI [OF Semilat.intro] closed_lift2_sup)
haftmann@33954
   524
apply (rule conjI)
haftmann@33954
   525
 apply (drule Semilat.orderI [OF Semilat.intro])
haftmann@33954
   526
 apply simp
haftmann@33954
   527
apply (simp (no_asm) only: unfold_lesub_err Err.le_def err_def sup_def lift2_def)
haftmann@33954
   528
apply (simp (no_asm_simp) add: coalesce_eq_OK1_D coalesce_eq_OK2_D split: err.split)
haftmann@33954
   529
apply (blast intro: coalesce_eq_OK_ub_D dest: coalesce_eq_Err_D)
haftmann@33954
   530
done 
haftmann@33954
   531
haftmann@33954
   532
lemma err_semilat_upto_esl:
haftmann@33954
   533
  "\<And>L. err_semilat L \<Longrightarrow> err_semilat(upto_esl m L)"
haftmann@33954
   534
apply (unfold Listn.upto_esl_def)
haftmann@33954
   535
apply (simp (no_asm_simp) only: split_tupled_all)
haftmann@33954
   536
apply simp
haftmann@33954
   537
apply (fastsimp intro!: err_semilat_UnionI err_semilat_sup
haftmann@33954
   538
                dest: lesub_list_impl_same_size 
haftmann@33954
   539
                simp add: plussub_def Listn.sup_def)
haftmann@33954
   540
done
haftmann@33954
   541
haftmann@33954
   542
end