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