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