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