src/ZF/List.thy
author paulson
Wed, 10 Jul 2002 16:54:07 +0200
changeset 13339 0f89104dd377
parent 13327 be7105a066d3
child 13356 c9cfe1638bf2
permissions -rw-r--r--
Fixed quantified variable name preservation for ball and bex (bounded quants) Requires tweaking of other scripts. Also routine tidying.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1478
2b8c2a7547ab expanded tabs
clasohm
parents: 1401
diff changeset
     1
(*  Title:      ZF/List
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
     2
    ID:         $Id$
1478
2b8c2a7547ab expanded tabs
clasohm
parents: 1401
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
     4
    Copyright   1994  University of Cambridge
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
     5
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
     6
*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
     7
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
     8
header{*Lists in Zermelo-Fraenkel Set Theory*}
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
     9
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    10
theory List = Datatype + ArithSimp:
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    11
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    12
consts
12789
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    13
  list       :: "i=>i"
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    14
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    15
datatype
581
465075fd257b removal of needless quotes
lcp
parents: 516
diff changeset
    16
  "list(A)" = Nil | Cons ("a:A", "l: list(A)")
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    17
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    18
2539
ddd22ceee8cc turned some consts into syntax;
wenzelm
parents: 1926
diff changeset
    19
syntax
ddd22ceee8cc turned some consts into syntax;
wenzelm
parents: 1926
diff changeset
    20
 "[]"        :: i                                       ("[]")
12789
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    21
 "@List"     :: "is => i"                                 ("[(_)]")
2539
ddd22ceee8cc turned some consts into syntax;
wenzelm
parents: 1926
diff changeset
    22
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    23
translations
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    24
  "[x, xs]"     == "Cons(x, [xs])"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    25
  "[x]"         == "Cons(x, [])"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    26
  "[]"          == "Nil"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    27
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    28
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    29
consts
12789
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    30
  length :: "i=>i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    31
  hd      :: "i=>i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    32
  tl      :: "i=>i"
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    33
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    34
primrec
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    35
  "length([]) = 0"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    36
  "length(Cons(a,l)) = succ(length(l))"
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    37
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    38
primrec
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    39
  "hd(Cons(a,l)) = a"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    40
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    41
primrec
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    42
  "tl([]) = []"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    43
  "tl(Cons(a,l)) = l"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    44
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
    45
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
    46
consts
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    47
  map         :: "[i=>i, i] => i"
12789
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    48
  set_of_list :: "i=>i"
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    49
  app         :: "[i,i]=>i"                        (infixr "@" 60)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    50
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    51
(*map is a binding operator -- it applies to meta-level functions, not
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    52
object-level functions.  This simplifies the final form of term_rec_conv,
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    53
although complicating its derivation.*)
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    54
primrec
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    55
  "map(f,[]) = []"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    56
  "map(f,Cons(a,l)) = Cons(f(a), map(f,l))"
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    57
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    58
primrec
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    59
  "set_of_list([]) = 0"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    60
  "set_of_list(Cons(a,l)) = cons(a, set_of_list(l))"
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    61
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    62
primrec
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    63
  app_Nil:  "[] @ ys = ys"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    64
  app_Cons: "(Cons(a,l)) @ ys = Cons(a, l @ ys)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    65
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
    66
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
    67
consts
12789
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    68
  rev :: "i=>i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    69
  flat       :: "i=>i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    70
  list_add   :: "i=>i"
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
    71
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    72
primrec
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    73
  "rev([]) = []"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    74
  "rev(Cons(a,l)) = rev(l) @ [a]"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    75
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    76
primrec
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    77
  "flat([]) = []"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    78
  "flat(Cons(l,ls)) = l @ flat(ls)"
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    79
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    80
primrec
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    81
  "list_add([]) = 0"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3840
diff changeset
    82
  "list_add(Cons(a,l)) = a #+ list_add(l)"
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    83
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
    84
consts
12789
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    85
  drop       :: "[i,i]=>i"
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
    86
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
    87
primrec
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    88
  drop_0:    "drop(0,l) = l"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    89
  drop_SUCC: "drop(succ(i), l) = tl (drop(i,l))"
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
    90
12789
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    91
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    92
(*** Thanks to Sidi Ehmety for the following ***)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    93
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    94
constdefs
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    95
(* Function `take' returns the first n elements of a list *)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    96
  take     :: "[i,i]=>i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    97
  "take(n, as) == list_rec(lam n:nat. [],
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
    98
		%a l r. lam n:nat. nat_case([], %m. Cons(a, r`m), n), as)`n"
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
    99
12789
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   100
(* Function `nth' returns the (n+1)th element in a list (not defined at Nil) *)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   101
  nth :: "[i, i]=>i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   102
  "nth(n, as) == list_rec(lam n:nat. 0,
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   103
		%a l r. lam n:nat. nat_case(a, %m. r`m, n), as)`n"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   104
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   105
  list_update :: "[i, i, i]=>i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   106
  "list_update(xs, i, v) == list_rec(lam n:nat. Nil,
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   107
      %u us vs. lam n:nat. nat_case(Cons(v, us), %m. Cons(u, vs`m), n), xs)`i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   108
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   109
consts
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   110
  filter :: "[i=>o, i] => i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   111
  upt :: "[i, i] =>i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   112
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   113
primrec
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   114
  "filter(P, Nil) = Nil"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   115
  "filter(P, Cons(x, xs)) =
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   116
     (if P(x) then Cons(x, filter(P, xs)) else filter(P, xs))"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   117
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   118
primrec
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   119
  "upt(i, 0) = Nil"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   120
  "upt(i, succ(j)) = (if i le j then upt(i, j)@[j] else Nil)"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   121
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   122
constdefs
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   123
  min :: "[i,i] =>i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   124
    "min(x, y) == (if x le y then x else y)"
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   125
12789
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   126
  max :: "[i, i] =>i"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   127
    "max(x, y) == (if x le y then y else x)"
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 9548
diff changeset
   128
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   129
(*** Aspects of the datatype definition ***)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   130
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   131
declare list.intros [simp,TC]
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   132
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   133
(*An elimination rule, for type-checking*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   134
inductive_cases ConsE: "Cons(a,l) : list(A)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   135
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   136
(*Proving freeness results*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   137
lemma Cons_iff: "Cons(a,l)=Cons(a',l') <-> a=a' & l=l'"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   138
by auto
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   139
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   140
lemma Nil_Cons_iff: "~ Nil=Cons(a,l)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   141
by auto
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   142
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   143
lemma list_unfold: "list(A) = {0} + (A * list(A))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   144
by (blast intro!: list.intros [unfolded list.con_defs]
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   145
          elim: list.cases [unfolded list.con_defs])
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   146
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   147
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   148
(**  Lemmas to justify using "list" in other recursive type definitions **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   149
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   150
lemma list_mono: "A<=B ==> list(A) <= list(B)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   151
apply (unfold list.defs )
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   152
apply (rule lfp_mono)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   153
apply (simp_all add: list.bnd_mono)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   154
apply (assumption | rule univ_mono basic_monos)+
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   155
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   156
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   157
(*There is a similar proof by list induction.*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   158
lemma list_univ: "list(univ(A)) <= univ(A)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   159
apply (unfold list.defs list.con_defs)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   160
apply (rule lfp_lowerbound)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   161
apply (rule_tac [2] A_subset_univ [THEN univ_mono])
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   162
apply (blast intro!: zero_in_univ Inl_in_univ Inr_in_univ Pair_in_univ)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   163
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   164
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   165
(*These two theorems justify datatypes involving list(nat), list(A), ...*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   166
lemmas list_subset_univ = subset_trans [OF list_mono list_univ]
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   167
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   168
lemma list_into_univ: "[| l: list(A);  A <= univ(B) |] ==> l: univ(B)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   169
by (blast intro: list_subset_univ [THEN subsetD])
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   170
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   171
lemma list_case_type:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   172
    "[| l: list(A);
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   173
        c: C(Nil);
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   174
        !!x y. [| x: A;  y: list(A) |] ==> h(x,y): C(Cons(x,y))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   175
     |] ==> list_case(c,h,l) : C(l)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   176
apply (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   177
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   178
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   179
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   180
(*** List functions ***)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   181
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   182
lemma tl_type: "l: list(A) ==> tl(l) : list(A)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   183
apply (induct_tac "l")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   184
apply (simp_all (no_asm_simp) add: list.intros)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   185
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   186
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   187
(** drop **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   188
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   189
lemma drop_Nil [simp]: "i:nat ==> drop(i, Nil) = Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   190
apply (induct_tac "i")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   191
apply (simp_all (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   192
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   193
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   194
lemma drop_succ_Cons [simp]: "i:nat ==> drop(succ(i), Cons(a,l)) = drop(i,l)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   195
apply (rule sym)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   196
apply (induct_tac "i")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   197
apply (simp (no_asm))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   198
apply (simp (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   199
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   200
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   201
lemma drop_type [simp,TC]: "[| i:nat; l: list(A) |] ==> drop(i,l) : list(A)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   202
apply (induct_tac "i")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   203
apply (simp_all (no_asm_simp) add: tl_type)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   204
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   205
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   206
declare drop_SUCC [simp del]
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   207
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   208
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   209
(** Type checking -- proved by induction, as usual **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   210
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   211
lemma list_rec_type [TC]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   212
    "[| l: list(A);
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   213
        c: C(Nil);
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   214
        !!x y r. [| x:A;  y: list(A);  r: C(y) |] ==> h(x,y,r): C(Cons(x,y))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   215
     |] ==> list_rec(c,h,l) : C(l)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   216
by (induct_tac "l", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   217
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   218
(** map **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   219
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   220
lemma map_type [TC]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   221
    "[| l: list(A);  !!x. x: A ==> h(x): B |] ==> map(h,l) : list(B)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   222
apply (simp add: map_list_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   223
apply (typecheck add: list.intros list_rec_type, blast)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   224
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   225
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   226
lemma map_type2 [TC]: "l: list(A) ==> map(h,l) : list({h(u). u:A})"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   227
apply (erule map_type)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   228
apply (erule RepFunI)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   229
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   230
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   231
(** length **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   232
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   233
lemma length_type [TC]: "l: list(A) ==> length(l) : nat"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   234
by (simp add: length_list_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   235
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   236
lemma lt_length_in_nat:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   237
   "[|x < length(xs); xs \<in> list(A)|] ==> x \<in> nat"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   238
by (frule lt_nat_in_nat, typecheck) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   239
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   240
(** app **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   241
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   242
lemma app_type [TC]: "[| xs: list(A);  ys: list(A) |] ==> xs@ys : list(A)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   243
by (simp add: app_list_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   244
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   245
(** rev **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   246
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   247
lemma rev_type [TC]: "xs: list(A) ==> rev(xs) : list(A)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   248
by (simp add: rev_list_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   249
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   250
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   251
(** flat **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   252
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   253
lemma flat_type [TC]: "ls: list(list(A)) ==> flat(ls) : list(A)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   254
by (simp add: flat_list_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   255
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   256
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   257
(** set_of_list **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   258
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   259
lemma set_of_list_type [TC]: "l: list(A) ==> set_of_list(l) : Pow(A)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   260
apply (unfold set_of_list_list_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   261
apply (erule list_rec_type, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   262
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   263
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   264
lemma set_of_list_append:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   265
     "xs: list(A) ==> set_of_list (xs@ys) = set_of_list(xs) Un set_of_list(ys)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   266
apply (erule list.induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   267
apply (simp_all (no_asm_simp) add: Un_cons)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   268
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   269
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   270
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   271
(** list_add **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   272
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   273
lemma list_add_type [TC]: "xs: list(nat) ==> list_add(xs) : nat"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   274
by (simp add: list_add_list_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   275
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   276
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   277
(*** theorems about map ***)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   278
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   279
lemma map_ident [simp]: "l: list(A) ==> map(%u. u, l) = l"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   280
apply (induct_tac "l")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   281
apply (simp_all (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   282
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   283
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   284
lemma map_compose: "l: list(A) ==> map(h, map(j,l)) = map(%u. h(j(u)), l)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   285
apply (induct_tac "l")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   286
apply (simp_all (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   287
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   288
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   289
lemma map_app_distrib: "xs: list(A) ==> map(h, xs@ys) = map(h,xs) @ map(h,ys)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   290
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   291
apply (simp_all (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   292
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   293
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   294
lemma map_flat: "ls: list(list(A)) ==> map(h, flat(ls)) = flat(map(map(h),ls))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   295
apply (induct_tac "ls")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   296
apply (simp_all (no_asm_simp) add: map_app_distrib)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   297
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   298
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   299
lemma list_rec_map:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   300
     "l: list(A) ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   301
      list_rec(c, d, map(h,l)) =
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   302
      list_rec(c, %x xs r. d(h(x), map(h,xs), r), l)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   303
apply (induct_tac "l")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   304
apply (simp_all (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   305
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   306
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   307
(** theorems about list(Collect(A,P)) -- used in Induct/Term.thy **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   308
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   309
(* c : list(Collect(B,P)) ==> c : list(B) *)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   310
lemmas list_CollectD = Collect_subset [THEN list_mono, THEN subsetD, standard]
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   311
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   312
lemma map_list_Collect: "l: list({x:A. h(x)=j(x)}) ==> map(h,l) = map(j,l)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   313
apply (induct_tac "l")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   314
apply (simp_all (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   315
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   316
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   317
(*** theorems about length ***)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   318
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   319
lemma length_map [simp]: "xs: list(A) ==> length(map(h,xs)) = length(xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   320
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   321
apply simp_all
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   322
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   323
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   324
lemma length_app [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   325
     "[| xs: list(A); ys: list(A) |]
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   326
      ==> length(xs@ys) = length(xs) #+ length(ys)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   327
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   328
apply simp_all
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   329
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   330
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   331
lemma length_rev [simp]: "xs: list(A) ==> length(rev(xs)) = length(xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   332
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   333
apply (simp_all (no_asm_simp) add: length_app)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   334
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   335
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   336
lemma length_flat:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   337
     "ls: list(list(A)) ==> length(flat(ls)) = list_add(map(length,ls))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   338
apply (induct_tac "ls")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   339
apply (simp_all (no_asm_simp) add: length_app)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   340
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   341
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   342
(** Length and drop **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   343
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   344
(*Lemma for the inductive step of drop_length*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   345
lemma drop_length_Cons [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   346
     "xs: list(A) ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   347
           \<forall>x.  EX z zs. drop(length(xs), Cons(x,xs)) = Cons(z,zs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   348
apply (erule list.induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   349
apply simp_all
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   350
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   351
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   352
lemma drop_length [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   353
     "l: list(A) ==> \<forall>i \<in> length(l). (EX z zs. drop(i,l) = Cons(z,zs))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   354
apply (erule list.induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   355
apply simp_all
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   356
apply safe
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   357
apply (erule drop_length_Cons)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   358
apply (rule natE)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   359
apply (erule Ord_trans [OF asm_rl length_type Ord_nat], assumption)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   360
apply simp_all
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   361
apply (blast intro: succ_in_naturalD length_type)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   362
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   363
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   364
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   365
(*** theorems about app ***)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   366
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   367
lemma app_right_Nil [simp]: "xs: list(A) ==> xs@Nil=xs"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   368
apply (erule list.induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   369
apply simp_all
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   370
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   371
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   372
lemma app_assoc: "xs: list(A) ==> (xs@ys)@zs = xs@(ys@zs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   373
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   374
apply simp_all
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   375
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   376
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   377
lemma flat_app_distrib: "ls: list(list(A)) ==> flat(ls@ms) = flat(ls)@flat(ms)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   378
apply (induct_tac "ls")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   379
apply (simp_all (no_asm_simp) add: app_assoc)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   380
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   381
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   382
(*** theorems about rev ***)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   383
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   384
lemma rev_map_distrib: "l: list(A) ==> rev(map(h,l)) = map(h,rev(l))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   385
apply (induct_tac "l")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   386
apply (simp_all (no_asm_simp) add: map_app_distrib)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   387
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   388
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   389
(*Simplifier needs the premises as assumptions because rewriting will not
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   390
  instantiate the variable ?A in the rules' typing conditions; note that
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   391
  rev_type does not instantiate ?A.  Only the premises do.
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   392
*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   393
lemma rev_app_distrib:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   394
     "[| xs: list(A);  ys: list(A) |] ==> rev(xs@ys) = rev(ys)@rev(xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   395
apply (erule list.induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   396
apply (simp_all add: app_assoc)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   397
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   398
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   399
lemma rev_rev_ident [simp]: "l: list(A) ==> rev(rev(l))=l"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   400
apply (induct_tac "l")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   401
apply (simp_all (no_asm_simp) add: rev_app_distrib)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   402
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   403
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   404
lemma rev_flat: "ls: list(list(A)) ==> rev(flat(ls)) = flat(map(rev,rev(ls)))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   405
apply (induct_tac "ls")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   406
apply (simp_all add: map_app_distrib flat_app_distrib rev_app_distrib)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   407
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   408
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   409
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   410
(*** theorems about list_add ***)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   411
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   412
lemma list_add_app:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   413
     "[| xs: list(nat);  ys: list(nat) |]
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   414
      ==> list_add(xs@ys) = list_add(ys) #+ list_add(xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   415
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   416
apply simp_all
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   417
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   418
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   419
lemma list_add_rev: "l: list(nat) ==> list_add(rev(l)) = list_add(l)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   420
apply (induct_tac "l")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   421
apply (simp_all (no_asm_simp) add: list_add_app)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   422
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   423
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   424
lemma list_add_flat:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   425
     "ls: list(list(nat)) ==> list_add(flat(ls)) = list_add(map(list_add,ls))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   426
apply (induct_tac "ls")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   427
apply (simp_all (no_asm_simp) add: list_add_app)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   428
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   429
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   430
(** New induction rule **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   431
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   432
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   433
lemma list_append_induct:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   434
    "[| l: list(A);
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   435
        P(Nil);
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   436
        !!x y. [| x: A;  y: list(A);  P(y) |] ==> P(y @ [x])
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   437
     |] ==> P(l)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   438
apply (subgoal_tac "P(rev(rev(l)))", simp)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   439
apply (erule rev_type [THEN list.induct], simp_all)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   440
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   441
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   442
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   443
(*** Thanks to Sidi Ehmety for these results about min, take, etc. ***)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   444
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   445
(** min FIXME: replace by Int! **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   446
(* Min theorems are also true for i, j ordinals *)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   447
lemma min_sym: "[| i:nat; j:nat |] ==> min(i,j)=min(j,i)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   448
apply (unfold min_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   449
apply (auto dest!: not_lt_imp_le dest: lt_not_sym intro: le_anti_sym)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   450
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   451
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   452
lemma min_type [simp,TC]: "[| i:nat; j:nat |] ==> min(i,j):nat"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   453
by (unfold min_def, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   454
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   455
lemma min_0 [simp]: "i:nat ==> min(0,i) = 0"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   456
apply (unfold min_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   457
apply (auto dest: not_lt_imp_le)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   458
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   459
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   460
lemma min_02 [simp]: "i:nat ==> min(i, 0) = 0"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   461
apply (unfold min_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   462
apply (auto dest: not_lt_imp_le)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   463
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   464
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   465
lemma lt_min_iff: "[| i:nat; j:nat; k:nat |] ==> i<min(j,k) <-> i<j & i<k"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   466
apply (unfold min_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   467
apply (auto dest!: not_lt_imp_le intro: lt_trans2 lt_trans)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   468
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   469
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   470
lemma min_succ_succ [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   471
     "[| i:nat; j:nat |] ==>  min(succ(i), succ(j))= succ(min(i, j))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   472
apply (unfold min_def, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   473
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   474
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   475
(*** more theorems about lists ***)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   476
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   477
(** filter **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   478
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   479
lemma filter_append [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   480
     "xs:list(A) ==> filter(P, xs@ys) = filter(P, xs) @ filter(P, ys)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   481
by (induct_tac "xs", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   482
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   483
lemma filter_type [simp,TC]: "xs:list(A) ==> filter(P, xs):list(A)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   484
by (induct_tac "xs", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   485
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   486
lemma length_filter: "xs:list(A) ==> length(filter(P, xs)) le length(xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   487
apply (induct_tac "xs", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   488
apply (rule_tac j = "length (l) " in le_trans)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   489
apply (auto simp add: le_iff)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   490
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   491
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   492
lemma filter_is_subset: "xs:list(A) ==> set_of_list(filter(P,xs)) <= set_of_list(xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   493
by (induct_tac "xs", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   494
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   495
lemma filter_False [simp]: "xs:list(A) ==> filter(%p. False, xs) = Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   496
by (induct_tac "xs", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   497
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   498
lemma filter_True [simp]: "xs:list(A) ==> filter(%p. True, xs) = xs"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   499
by (induct_tac "xs", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   500
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   501
(** length **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   502
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   503
lemma length_is_0_iff [simp]: "xs:list(A) ==> length(xs)=0 <-> xs=Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   504
by (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   505
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   506
lemma length_is_0_iff2 [simp]: "xs:list(A) ==> 0 = length(xs) <-> xs=Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   507
by (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   508
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   509
lemma length_tl [simp]: "xs:list(A) ==> length(tl(xs)) = length(xs) #- 1"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   510
by (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   511
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   512
lemma length_greater_0_iff: "xs:list(A) ==> 0<length(xs) <-> xs ~= Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   513
by (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   514
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   515
lemma length_succ_iff: "xs:list(A) ==> length(xs)=succ(n) <-> (EX y ys. xs=Cons(y, ys) & length(ys)=n)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   516
by (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   517
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   518
(** more theorems about append **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   519
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   520
lemma append_is_Nil_iff [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   521
     "xs:list(A) ==> (xs@ys = Nil) <-> (xs=Nil & ys = Nil)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   522
by (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   523
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   524
lemma append_is_Nil_iff2 [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   525
     "xs:list(A) ==> (Nil = xs@ys) <-> (xs=Nil & ys = Nil)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   526
by (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   527
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   528
lemma append_left_is_self_iff [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   529
     "xs:list(A) ==> (xs@ys = xs) <-> (ys = Nil)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   530
by (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   531
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   532
lemma append_left_is_self_iff2 [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   533
     "xs:list(A) ==> (xs = xs@ys) <-> (ys = Nil)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   534
by (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   535
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   536
(*TOO SLOW as a default simprule!*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   537
lemma append_left_is_Nil_iff [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   538
     "[| xs:list(A); ys:list(A); zs:list(A) |] ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   539
   length(ys)=length(zs) --> (xs@ys=zs <-> (xs=Nil & ys=zs))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   540
apply (erule list.induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   541
apply (auto simp add: length_app)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   542
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   543
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   544
(*TOO SLOW as a default simprule!*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   545
lemma append_left_is_Nil_iff2 [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   546
     "[| xs:list(A); ys:list(A); zs:list(A) |] ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   547
   length(ys)=length(zs) --> (zs=ys@xs <-> (xs=Nil & ys=zs))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   548
apply (erule list.induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   549
apply (auto simp add: length_app)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   550
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   551
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   552
lemma append_eq_append_iff [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   553
     "xs:list(A) ==> \<forall>ys \<in> list(A).
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   554
      length(xs)=length(ys) --> (xs@us = ys@vs) <-> (xs=ys & us=vs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   555
apply (erule list.induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   556
apply (simp (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   557
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   558
apply (erule_tac a = "ys" in list.cases, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   559
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   560
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   561
lemma append_eq_append [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   562
  "xs:list(A) ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   563
   \<forall>ys \<in> list(A). \<forall>us \<in> list(A). \<forall>vs \<in> list(A).
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   564
   length(us) = length(vs) --> (xs@us = ys@vs) --> (xs=ys & us=vs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   565
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   566
apply (force simp add: length_app, clarify)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   567
apply (erule_tac a = "ys" in list.cases, simp)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   568
apply (subgoal_tac "Cons (a, l) @ us =vs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   569
 apply (drule rev_iffD1 [OF _ append_left_is_Nil_iff], simp_all)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   570
apply blast
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   571
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   572
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   573
lemma append_eq_append_iff2 [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   574
 "[| xs:list(A); ys:list(A); us:list(A); vs:list(A); length(us)=length(vs) |]
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   575
  ==>  xs@us = ys@vs <-> (xs=ys & us=vs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   576
apply (rule iffI)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   577
apply (rule append_eq_append, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   578
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   579
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   580
lemma append_self_iff [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   581
     "[| xs:list(A); ys:list(A); zs:list(A) |] ==> xs@ys=xs@zs <-> ys=zs"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   582
apply (simp (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   583
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   584
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   585
lemma append_self_iff2 [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   586
     "[| xs:list(A); ys:list(A); zs:list(A) |] ==> ys@xs=zs@xs <-> ys=zs"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   587
apply (simp (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   588
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   589
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   590
(* Can also be proved from append_eq_append_iff2,
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   591
but the proof requires two more hypotheses: x:A and y:A *)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   592
lemma append1_eq_iff [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   593
     "xs:list(A) ==> \<forall>ys \<in> list(A). xs@[x] = ys@[y] <-> (xs = ys & x=y)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   594
apply (erule list.induct)  
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   595
 apply clarify 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   596
 apply (erule list.cases)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   597
 apply simp_all
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   598
txt{*Inductive step*}  
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   599
apply clarify 
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13327
diff changeset
   600
apply (erule_tac a=ys in list.cases, simp_all)  
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   601
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   602
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   603
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   604
lemma append_right_is_self_iff [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   605
     "[| xs:list(A); ys:list(A) |] ==> (xs@ys = ys) <-> (xs=Nil)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   606
apply (simp (no_asm_simp) add: append_left_is_Nil_iff)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   607
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   608
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   609
lemma append_right_is_self_iff2 [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   610
     "[| xs:list(A); ys:list(A) |] ==> (ys = xs@ys) <-> (xs=Nil)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   611
apply (rule iffI)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   612
apply (drule sym, auto) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   613
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   614
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   615
lemma hd_append [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   616
     "xs:list(A) ==> xs ~= Nil --> hd(xs @ ys) = hd(xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   617
by (induct_tac "xs", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   618
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   619
lemma tl_append [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   620
     "xs:list(A) ==> xs~=Nil --> tl(xs @ ys) = tl(xs)@ys"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   621
by (induct_tac "xs", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   622
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   623
(** rev **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   624
lemma rev_is_Nil_iff [simp]: "xs:list(A) ==> (rev(xs) = Nil <-> xs = Nil)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   625
by (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   626
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   627
lemma Nil_is_rev_iff [simp]: "xs:list(A) ==> (Nil = rev(xs) <-> xs = Nil)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   628
by (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   629
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   630
lemma rev_is_rev_iff [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   631
     "xs:list(A) ==> \<forall>ys \<in> list(A). rev(xs)=rev(ys) <-> xs=ys"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   632
apply (erule list.induct, force)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   633
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   634
apply (erule_tac a = "ys" in list.cases, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   635
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   636
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   637
lemma rev_list_elim [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   638
     "xs:list(A) ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   639
      (xs=Nil --> P) --> (\<forall>ys \<in> list(A). \<forall>y \<in> A. xs =ys@[y] -->P)-->P"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   640
apply (erule list_append_induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   641
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   642
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   643
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   644
(** more theorems about drop **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   645
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   646
lemma length_drop [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   647
     "n:nat ==> \<forall>xs \<in> list(A). length(drop(n, xs)) = length(xs) #- n"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   648
apply (erule nat_induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   649
apply (auto elim: list.cases)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   650
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   651
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   652
lemma drop_all [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   653
     "n:nat ==> \<forall>xs \<in> list(A). length(xs) le n --> drop(n, xs)=Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   654
apply (erule nat_induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   655
apply (auto elim: list.cases)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   656
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   657
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   658
lemma drop_append [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   659
     "n:nat ==> 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   660
      \<forall>xs \<in> list(A). drop(n, xs@ys) = drop(n,xs) @ drop(n #- length(xs), ys)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   661
apply (induct_tac "n")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   662
apply (auto elim: list.cases)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   663
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   664
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   665
lemma drop_drop:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   666
    "m:nat ==> \<forall>xs \<in> list(A). \<forall>n \<in> nat. drop(n, drop(m, xs))=drop(n #+ m, xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   667
apply (induct_tac "m")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   668
apply (auto elim: list.cases)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   669
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   670
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   671
(** take **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   672
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   673
lemma take_0 [simp]: "xs:list(A) ==> take(0, xs) =  Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   674
apply (unfold take_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   675
apply (erule list.induct, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   676
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   677
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   678
lemma take_succ_Cons [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   679
    "n:nat ==> take(succ(n), Cons(a, xs)) = Cons(a, take(n, xs))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   680
by (simp add: take_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   681
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   682
(* Needed for proving take_all *)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   683
lemma take_Nil [simp]: "n:nat ==> take(n, Nil) = Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   684
by (unfold take_def, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   685
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   686
lemma take_all [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   687
     "n:nat ==> \<forall>xs \<in> list(A). length(xs) le n  --> take(n, xs) = xs"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   688
apply (erule nat_induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   689
apply (auto elim: list.cases) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   690
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   691
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   692
lemma take_type [rule_format,simp,TC]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   693
     "xs:list(A) ==> \<forall>n \<in> nat. take(n, xs):list(A)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   694
apply (erule list.induct, simp) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   695
apply clarify 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   696
apply (erule natE, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   697
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   698
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   699
lemma take_append [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   700
 "xs:list(A) ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   701
  \<forall>ys \<in> list(A). \<forall>n \<in> nat. take(n, xs @ ys) =
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   702
                            take(n, xs) @ take(n #- length(xs), ys)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   703
apply (erule list.induct, simp) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   704
apply clarify 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   705
apply (erule natE, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   706
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   707
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   708
lemma take_take [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   709
   "m : nat ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   710
    \<forall>xs \<in> list(A). \<forall>n \<in> nat. take(n, take(m,xs))= take(min(n, m), xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   711
apply (induct_tac "m", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   712
apply (erule_tac a = "xs" in list.cases)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   713
apply (auto simp add: take_Nil)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   714
apply (rotate_tac 1)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   715
apply (erule natE)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   716
apply (auto intro: take_0 take_type)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   717
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   718
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   719
(** nth **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   720
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   721
lemma nth_0 [simp]: "nth(0, Cons(a, l))= a"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   722
by (unfold nth_def, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   723
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   724
lemma nth_Cons [simp]: "n:nat ==> nth(succ(n), Cons(a, l)) = nth(n, l)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   725
apply (unfold nth_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   726
apply (simp (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   727
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   728
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   729
lemma nth_type [rule_format,simp,TC]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   730
     "xs:list(A) ==> \<forall>n \<in> nat. n < length(xs) --> nth(n, xs):A"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   731
apply (erule list.induct, simp) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   732
apply clarify 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   733
apply (erule natE, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   734
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   735
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   736
lemma nth_append [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   737
  "xs:list(A) ==> 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   738
   \<forall>n \<in> nat. nth(n, xs @ ys) = (if n < length(xs) then nth(n,xs)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   739
                                else nth(n #- length(xs),ys))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   740
apply (induct_tac "xs", simp) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   741
apply clarify 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   742
apply (erule natE, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   743
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   744
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   745
lemma set_of_list_conv_nth:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   746
    "xs:list(A)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   747
      ==> set_of_list(xs) = {x:A. EX i:nat. i<length(xs) & x=nth(i, xs)}"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   748
apply (induct_tac "xs", simp_all)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   749
apply (rule equalityI, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   750
apply (rule_tac x = "0" in bexI, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   751
apply (erule natE, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   752
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   753
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   754
(* Other theorems about lists *)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   755
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   756
lemma nth_take_lemma [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   757
 "k:nat ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   758
  \<forall>xs \<in> list(A). (\<forall>ys \<in> list(A). k le length(xs) --> k le length(ys) -->
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   759
      (\<forall>i \<in> nat. i<k --> nth(i,xs)= nth(i,ys))--> take(k, xs) = take(k,ys))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   760
apply (induct_tac "k")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   761
apply (simp_all (no_asm_simp) add: lt_succ_eq_0_disj all_conj_distrib)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   762
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   763
(*Both lists are non-empty*)
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13327
diff changeset
   764
apply (erule_tac a="xs" in list.cases, simp) 
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13327
diff changeset
   765
apply (erule_tac a="ys" in list.cases, clarify) 
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   766
apply (simp (no_asm_use) )
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   767
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   768
apply (simp (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   769
apply (rule conjI, force)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   770
apply (rename_tac y ys z zs) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   771
apply (drule_tac x = "zs" and x1 = "ys" in bspec [THEN bspec], auto)   
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   772
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   773
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   774
lemma nth_equalityI [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   775
     "[| xs:list(A); ys:list(A); length(xs) = length(ys);
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   776
         \<forall>i \<in> nat. i < length(xs) --> nth(i,xs) = nth(i,ys) |]
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   777
      ==> xs = ys"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   778
apply (subgoal_tac "length (xs) le length (ys) ")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   779
apply (cut_tac k="length(xs)" and xs=xs and ys=ys in nth_take_lemma) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   780
apply (simp_all add: take_all)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   781
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   782
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   783
(*The famous take-lemma*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   784
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   785
lemma take_equalityI [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   786
    "[| xs:list(A); ys:list(A); (\<forall>i \<in> nat. take(i, xs) = take(i,ys)) |] 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   787
     ==> xs = ys"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   788
apply (case_tac "length (xs) le length (ys) ")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   789
apply (drule_tac x = "length (ys) " in bspec)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   790
apply (drule_tac [3] not_lt_imp_le)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   791
apply (subgoal_tac [5] "length (ys) le length (xs) ")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   792
apply (rule_tac [6] j = "succ (length (ys))" in le_trans)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   793
apply (rule_tac [6] leI)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   794
apply (drule_tac [5] x = "length (xs) " in bspec)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   795
apply (simp_all add: take_all)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   796
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   797
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   798
lemma nth_drop [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   799
      "n:nat ==> \<forall>i \<in> nat. \<forall>xs \<in> list(A). n #+ i le length(xs)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   800
                      --> nth(i, drop(n, xs)) = nth(n #+ i, xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   801
apply (induct_tac "n", simp_all) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   802
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   803
apply (erule list.cases) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   804
apply (auto elim!: ConsE)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   805
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   806
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   807
subsection{*The function zip*}
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   808
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   809
text{*Crafty definition to eliminate a type argument*}
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   810
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   811
consts
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   812
  zip_aux        :: "[i,i]=>i"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   813
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   814
primrec (*explicit lambda is required because both arguments of "un" vary*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   815
  "zip_aux(B,[]) =
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   816
     (\<lambda>ys \<in> list(B). list_case([], %y l. [], ys))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   817
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   818
  "zip_aux(B,Cons(x,l)) =
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   819
     (\<lambda>ys \<in> list(B).
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   820
        list_case(Nil, %y zs. Cons(<x,y>, zip_aux(B,l)`zs), ys))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   821
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   822
constdefs
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   823
  zip :: "[i, i]=>i"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   824
   "zip(xs, ys) == zip_aux(set_of_list(ys),xs)`ys"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   825
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   826
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   827
(* zip equations *)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   828
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   829
lemma list_on_set_of_list: "xs \<in> list(A) ==> xs \<in> list(set_of_list(xs))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   830
apply (induct_tac xs, simp_all) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   831
apply (blast intro: list_mono [THEN subsetD]) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   832
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   833
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   834
lemma zip_Nil [simp]: "ys:list(A) ==> zip(Nil, ys)=Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   835
apply (simp add: zip_def list_on_set_of_list [of _ A])
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   836
apply (erule list.cases, simp_all) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   837
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   838
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   839
lemma zip_Nil2 [simp]: "xs:list(A) ==> zip(xs, Nil)=Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   840
apply (simp add: zip_def list_on_set_of_list [of _ A])
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   841
apply (erule list.cases, simp_all) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   842
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   843
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   844
lemma zip_aux_unique [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   845
     "[|B<=C;  xs \<in> list(A)|] 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   846
      ==> \<forall>ys \<in> list(B). zip_aux(C,xs) ` ys = zip_aux(B,xs) ` ys"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   847
apply (induct_tac xs) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   848
 apply simp_all 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   849
 apply (blast intro: list_mono [THEN subsetD], clarify) 
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13327
diff changeset
   850
apply (erule_tac a=ys in list.cases , auto) 
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   851
apply (blast intro: list_mono [THEN subsetD]) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   852
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   853
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   854
lemma zip_Cons_Cons [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   855
     "[| xs:list(A); ys:list(B); x:A; y:B |] ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   856
      zip(Cons(x,xs), Cons(y, ys)) = Cons(<x,y>, zip(xs, ys))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   857
apply (simp add: zip_def, auto) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   858
apply (rule zip_aux_unique, auto) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   859
apply (simp add: list_on_set_of_list [of _ B])
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   860
apply (blast intro: list_on_set_of_list list_mono [THEN subsetD]) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   861
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   862
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   863
lemma zip_type [rule_format,simp,TC]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   864
     "xs:list(A) ==> \<forall>ys \<in> list(B). zip(xs, ys):list(A*B)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   865
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   866
apply (simp (no_asm))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   867
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   868
apply (erule_tac a = "ys" in list.cases, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   869
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   870
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   871
(* zip length *)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   872
lemma length_zip [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   873
     "xs:list(A) ==> \<forall>ys \<in> list(B). length(zip(xs,ys)) =
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   874
                                     min(length(xs), length(ys))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   875
apply (unfold min_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   876
apply (induct_tac "xs", simp_all) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   877
apply clarify 
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13327
diff changeset
   878
apply (erule_tac a = ys in list.cases, auto)
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   879
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   880
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   881
lemma zip_append1 [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   882
 "[| ys:list(A); zs:list(B) |] ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   883
  \<forall>xs \<in> list(A). zip(xs @ ys, zs) = 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   884
                 zip(xs, take(length(xs), zs)) @ zip(ys, drop(length(xs),zs))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   885
apply (induct_tac "zs", force) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   886
apply clarify 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   887
apply (erule_tac a = "xs" in list.cases, simp_all) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   888
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   889
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   890
lemma zip_append2 [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   891
 "[| xs:list(A); zs:list(B) |] ==> \<forall>ys \<in> list(B). zip(xs, ys@zs) =
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   892
       zip(take(length(ys), xs), ys) @ zip(drop(length(ys), xs), zs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   893
apply (induct_tac "xs", force) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   894
apply clarify 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   895
apply (erule_tac a = "ys" in list.cases, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   896
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   897
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   898
lemma zip_append [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   899
 "[| length(xs) = length(us); length(ys) = length(vs);
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   900
     xs:list(A); us:list(B); ys:list(A); vs:list(B) |] 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   901
  ==> zip(xs@ys,us@vs) = zip(xs, us) @ zip(ys, vs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   902
by (simp (no_asm_simp) add: zip_append1 drop_append diff_self_eq_0)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   903
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   904
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   905
lemma zip_rev [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   906
 "ys:list(B) ==> \<forall>xs \<in> list(A).
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   907
    length(xs) = length(ys) --> zip(rev(xs), rev(ys)) = rev(zip(xs, ys))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   908
apply (induct_tac "ys", force) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   909
apply clarify 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   910
apply (erule_tac a = "xs" in list.cases)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   911
apply (auto simp add: length_rev)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   912
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   913
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   914
lemma nth_zip [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   915
   "ys:list(B) ==> \<forall>i \<in> nat. \<forall>xs \<in> list(A).
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   916
                    i < length(xs) --> i < length(ys) -->
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   917
                    nth(i,zip(xs, ys)) = <nth(i,xs),nth(i, ys)>"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   918
apply (induct_tac "ys", force) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   919
apply clarify 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   920
apply (erule_tac a = "xs" in list.cases, simp) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   921
apply (auto elim: natE)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   922
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   923
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   924
lemma set_of_list_zip [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   925
     "[| xs:list(A); ys:list(B); i:nat |]
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   926
      ==> set_of_list(zip(xs, ys)) =
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   927
          {<x, y>:A*B. EX i:nat. i < min(length(xs), length(ys))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   928
          & x=nth(i, xs) & y=nth(i, ys)}"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   929
by (force intro!: Collect_cong simp add: lt_min_iff set_of_list_conv_nth)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   930
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   931
(** list_update **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   932
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   933
lemma list_update_Nil [simp]: "i:nat ==>list_update(Nil, i, v) = Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   934
by (unfold list_update_def, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   935
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   936
lemma list_update_Cons_0 [simp]: "list_update(Cons(x, xs), 0, v)= Cons(v, xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   937
by (unfold list_update_def, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   938
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   939
lemma list_update_Cons_succ [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   940
  "n:nat ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   941
    list_update(Cons(x, xs), succ(n), v)= Cons(x, list_update(xs, n, v))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   942
apply (unfold list_update_def, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   943
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   944
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   945
lemma list_update_type [rule_format,simp,TC]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   946
     "[| xs:list(A); v:A |] ==> \<forall>n \<in> nat. list_update(xs, n, v):list(A)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   947
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   948
apply (simp (no_asm))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   949
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   950
apply (erule natE, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   951
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   952
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   953
lemma length_list_update [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   954
     "xs:list(A) ==> \<forall>i \<in> nat. length(list_update(xs, i, v))=length(xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   955
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   956
apply (simp (no_asm))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   957
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   958
apply (erule natE, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   959
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   960
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   961
lemma nth_list_update [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   962
     "[| xs:list(A) |] ==> \<forall>i \<in> nat. \<forall>j \<in> nat. i < length(xs)  -->
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   963
         nth(j, list_update(xs, i, x)) = (if i=j then x else nth(j, xs))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   964
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   965
 apply simp_all
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   966
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   967
apply (rename_tac i j) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   968
apply (erule_tac n=i in natE) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   969
apply (erule_tac [2] n=j in natE)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   970
apply (erule_tac n=j in natE, simp_all, force) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   971
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   972
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   973
lemma nth_list_update_eq [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   974
     "[| i < length(xs); xs:list(A) |] ==> nth(i, list_update(xs, i,x)) = x"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   975
by (simp (no_asm_simp) add: lt_length_in_nat nth_list_update)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   976
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   977
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   978
lemma nth_list_update_neq [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   979
     "xs:list(A) ==> \<forall>i \<in> nat. \<forall>j \<in> nat. i ~= j
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   980
  --> nth(j, list_update(xs, i,x)) = nth(j, xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   981
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   982
 apply (simp (no_asm))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   983
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   984
apply (erule natE)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   985
apply (erule_tac [2] natE, simp_all) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   986
apply (erule natE, simp_all)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   987
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   988
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   989
lemma list_update_overwrite [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   990
     "xs:list(A) ==> \<forall>i \<in> nat. i < length(xs)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   991
   --> list_update(list_update(xs, i, x), i, y) = list_update(xs, i,y)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   992
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   993
 apply (simp (no_asm))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   994
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   995
apply (erule natE, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   996
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   997
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   998
lemma list_update_same_conv [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
   999
     "xs:list(A) ==> \<forall>i \<in> nat. i < length(xs) -->
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1000
  (list_update(xs, i, x) = xs) <-> (nth(i, xs) = x)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1001
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1002
 apply (simp (no_asm))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1003
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1004
apply (erule natE, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1005
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1006
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1007
lemma update_zip [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1008
     "ys:list(B) ==> \<forall>i \<in> nat. \<forall>xy \<in> A*B. \<forall>xs \<in> list(A).
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1009
  length(xs) = length(ys) -->
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1010
      list_update(zip(xs, ys), i, xy) = zip(list_update(xs, i, fst(xy)),
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1011
                                          list_update(ys, i, snd(xy)))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1012
apply (induct_tac "ys")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1013
 apply auto
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13327
diff changeset
  1014
apply (erule_tac a = "xs" in list.cases)
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1015
apply (auto elim: natE)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1016
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1017
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1018
lemma set_update_subset_cons [rule_format]:
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13327
diff changeset
  1019
  "xs:list(A) ==> 
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13327
diff changeset
  1020
   \<forall>i \<in> nat. set_of_list(list_update(xs, i, x)) <= cons(x, set_of_list(xs))"
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1021
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1022
 apply simp
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1023
apply (rule ballI)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1024
apply (erule natE, simp_all)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1025
apply auto
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1026
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1027
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1028
lemma set_of_list_update_subsetI:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1029
     "[| set_of_list(xs) <= A; xs:list(A); x:A; i:nat|]
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1030
   ==> set_of_list(list_update(xs, i,x)) <= A"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1031
apply (rule subset_trans)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1032
apply (rule set_update_subset_cons, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1033
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1034
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1035
(** upt **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1036
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1037
lemma upt_rec:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1038
     "j:nat ==> upt(i,j) = (if i<j then Cons(i, upt(succ(i), j)) else Nil)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1039
apply (induct_tac "j", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1040
apply (drule not_lt_imp_le)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1041
apply (auto simp: lt_Ord intro: le_anti_sym)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1042
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1043
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1044
lemma upt_conv_Nil [simp]: "[| j le i; j:nat |] ==> upt(i,j) = Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1045
apply (subst upt_rec, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1046
apply (auto simp add: le_iff)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1047
apply (drule lt_asym [THEN notE], auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1048
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1049
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1050
(*Only needed if upt_Suc is deleted from the simpset*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1051
lemma upt_succ_append:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1052
     "[| i le j; j:nat |] ==> upt(i,succ(j)) = upt(i, j)@[j]"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1053
by simp
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1054
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1055
lemma upt_conv_Cons:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1056
     "[| i<j; j:nat |]  ==> upt(i,j) = Cons(i,upt(succ(i),j))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1057
apply (rule trans)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1058
apply (rule upt_rec, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1059
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1060
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1061
lemma upt_type [simp,TC]: "j:nat ==> upt(i,j):list(nat)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1062
by (induct_tac "j", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1063
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1064
(*LOOPS as a simprule, since j<=j*)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1065
lemma upt_add_eq_append:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1066
     "[| i le j; j:nat; k:nat |] ==> upt(i, j #+k) = upt(i,j)@upt(j,j#+k)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1067
apply (induct_tac "k")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1068
apply (auto simp add: app_assoc app_type)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1069
apply (rule_tac j = "j" in le_trans, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1070
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1071
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1072
lemma length_upt [simp]: "[| i:nat; j:nat |] ==>length(upt(i,j)) = j #- i"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1073
apply (induct_tac "j")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1074
apply (rule_tac [2] sym)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1075
apply (auto dest!: not_lt_imp_le simp add: length_app diff_succ diff_is_0_iff)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1076
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1077
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1078
lemma nth_upt [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1079
     "[| i:nat; j:nat; k:nat |] ==> i #+ k < j --> nth(k, upt(i,j)) = i #+ k"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1080
apply (induct_tac "j")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1081
apply (simp (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1082
apply (simp add: nth_append le_iff split add: nat_diff_split, safe)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1083
apply (auto dest!: not_lt_imp_le simp add: nth_append diff_self_eq_0 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1084
                   less_diff_conv add_commute)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1085
apply (drule_tac j = "x" in lt_trans2, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1086
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1087
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1088
lemma take_upt [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1089
     "[| m:nat; n:nat |] ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1090
      \<forall>i \<in> nat. i #+ m le n --> take(m, upt(i,n)) = upt(i,i#+m)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1091
apply (induct_tac "m")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1092
apply (simp (no_asm_simp) add: take_0)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1093
apply clarify
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1094
apply (subst upt_rec, simp) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1095
apply (rule sym)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1096
apply (subst upt_rec, simp) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1097
apply (simp_all del: upt.simps)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1098
apply (rule_tac j = "succ (i #+ x) " in lt_trans2)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1099
apply auto
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1100
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1101
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1102
lemma map_succ_upt:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1103
     "[| m:nat; n:nat |] ==> map(succ, upt(m,n))= upt(succ(m), succ(n))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1104
apply (induct_tac "n")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1105
apply (auto simp add: map_app_distrib)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1106
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1107
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1108
lemma nth_map [rule_format,simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1109
     "xs:list(A) ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1110
      \<forall>n \<in> nat. n < length(xs) --> nth(n, map(f, xs)) = f(nth(n, xs))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1111
apply (induct_tac "xs", simp)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1112
apply (rule ballI)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1113
apply (induct_tac "n", auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1114
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1115
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1116
lemma nth_map_upt [rule_format]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1117
     "[| m:nat; n:nat |] ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1118
      \<forall>i \<in> nat. i < n #- m --> nth(i, map(f, upt(m,n))) = f(m #+ i)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1119
apply (rule_tac n = "m" and m = "n" in diff_induct, typecheck)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1120
apply simp 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1121
apply simp 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1122
apply (subst map_succ_upt [symmetric], simp_all)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1123
apply clarify 
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13327
diff changeset
  1124
apply (subgoal_tac "i < length (upt (0, x))")
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1125
 prefer 2 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1126
 apply (simp add: less_diff_conv) 
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13327
diff changeset
  1127
 apply (rule_tac j = "succ (i #+ y) " in lt_trans2)
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1128
  apply simp 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1129
 apply simp 
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13327
diff changeset
  1130
apply (subgoal_tac "i < length (upt (y, x))")
13327
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1131
 apply (simp_all add: add_commute less_diff_conv)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1132
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1133
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1134
(** sublist (a generalization of nth to sets) **)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1135
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1136
constdefs
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1137
  sublist :: "[i, i] => i"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1138
    "sublist(xs, A)==
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1139
     map(fst, (filter(%p. snd(p): A, zip(xs, upt(0,length(xs))))))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1140
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1141
lemma sublist_0 [simp]: "xs:list(A) ==>sublist(xs, 0) =Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1142
by (unfold sublist_def, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1143
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1144
lemma sublist_Nil [simp]: "sublist(Nil, A) = Nil"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1145
by (unfold sublist_def, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1146
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1147
lemma sublist_shift_lemma:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1148
 "[| xs:list(B); i:nat |] ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1149
  map(fst, filter(%p. snd(p):A, zip(xs, upt(i,i #+ length(xs))))) =
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1150
  map(fst, filter(%p. snd(p):nat & snd(p) #+ i:A, zip(xs,upt(0,length(xs)))))"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1151
apply (erule list_append_induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1152
apply (simp (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1153
apply (auto simp add: add_commute length_app filter_append map_app_distrib)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1154
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1155
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1156
lemma sublist_type [simp,TC]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1157
     "xs:list(B) ==> sublist(xs, A):list(B)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1158
apply (unfold sublist_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1159
apply (induct_tac "xs")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1160
apply (auto simp add: filter_append map_app_distrib)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1161
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1162
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1163
lemma upt_add_eq_append2:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1164
     "[| i:nat; j:nat |] ==> upt(0, i #+ j) = upt(0, i) @ upt(i, i #+ j)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1165
by (simp add: upt_add_eq_append [of 0] nat_0_le)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1166
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1167
lemma sublist_append:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1168
 "[| xs:list(B); ys:list(B)  |] ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1169
  sublist(xs@ys, A) = sublist(xs, A) @ sublist(ys, {j:nat. j #+ length(xs): A})"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1170
apply (unfold sublist_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1171
apply (erule_tac l = "ys" in list_append_induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1172
apply (simp)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1173
apply (simp (no_asm_simp) add: upt_add_eq_append2 app_assoc [symmetric])
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1174
apply (auto simp add: sublist_shift_lemma length_type map_app_distrib app_assoc)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1175
apply (simp_all add: add_commute)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1176
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1177
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1178
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1179
lemma sublist_Cons:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1180
     "[| xs:list(B); x:B |] ==>
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1181
      sublist(Cons(x, xs), A) = 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1182
      (if 0:A then [x] else []) @ sublist(xs, {j:nat. succ(j) : A})"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1183
apply (erule_tac l = "xs" in list_append_induct)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1184
apply (simp (no_asm_simp) add: sublist_def)  
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1185
apply (simp del: app_Cons add: app_Cons [symmetric] sublist_append, simp) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1186
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1187
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1188
lemma sublist_singleton [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1189
     "sublist([x], A) = (if 0 : A then [x] else [])"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1190
by (simp (no_asm) add: sublist_Cons)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1191
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1192
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1193
lemma sublist_upt_eq_take [simp]:
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1194
    "[| xs:list(A); n:nat |] ==> sublist(xs, less_than(n)) = take(n,xs)"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1195
apply (unfold less_than_def)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1196
apply (erule_tac l = "xs" in list_append_induct, simp) 
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1197
apply (simp split add: nat_diff_split add: sublist_append, auto)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1198
apply (subgoal_tac "n #- length (y) = 0")
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1199
apply (simp (no_asm_simp))
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1200
apply (auto dest!: not_lt_imp_le simp add: diff_is_0_iff)
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1201
done
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1202
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1203
ML
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1204
{*
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1205
val ConsE = thm "ConsE";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1206
val Cons_iff = thm "Cons_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1207
val Nil_Cons_iff = thm "Nil_Cons_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1208
val list_unfold = thm "list_unfold";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1209
val list_mono = thm "list_mono";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1210
val list_univ = thm "list_univ";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1211
val list_subset_univ = thm "list_subset_univ";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1212
val list_into_univ = thm "list_into_univ";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1213
val list_case_type = thm "list_case_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1214
val tl_type = thm "tl_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1215
val drop_Nil = thm "drop_Nil";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1216
val drop_succ_Cons = thm "drop_succ_Cons";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1217
val drop_type = thm "drop_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1218
val list_rec_type = thm "list_rec_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1219
val map_type = thm "map_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1220
val map_type2 = thm "map_type2";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1221
val length_type = thm "length_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1222
val lt_length_in_nat = thm "lt_length_in_nat";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1223
val app_type = thm "app_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1224
val rev_type = thm "rev_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1225
val flat_type = thm "flat_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1226
val set_of_list_type = thm "set_of_list_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1227
val set_of_list_append = thm "set_of_list_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1228
val list_add_type = thm "list_add_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1229
val map_ident = thm "map_ident";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1230
val map_compose = thm "map_compose";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1231
val map_app_distrib = thm "map_app_distrib";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1232
val map_flat = thm "map_flat";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1233
val list_rec_map = thm "list_rec_map";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1234
val list_CollectD = thm "list_CollectD";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1235
val map_list_Collect = thm "map_list_Collect";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1236
val length_map = thm "length_map";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1237
val length_app = thm "length_app";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1238
val length_rev = thm "length_rev";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1239
val length_flat = thm "length_flat";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1240
val drop_length_Cons = thm "drop_length_Cons";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1241
val drop_length = thm "drop_length";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1242
val app_right_Nil = thm "app_right_Nil";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1243
val app_assoc = thm "app_assoc";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1244
val flat_app_distrib = thm "flat_app_distrib";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1245
val rev_map_distrib = thm "rev_map_distrib";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1246
val rev_app_distrib = thm "rev_app_distrib";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1247
val rev_rev_ident = thm "rev_rev_ident";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1248
val rev_flat = thm "rev_flat";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1249
val list_add_app = thm "list_add_app";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1250
val list_add_rev = thm "list_add_rev";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1251
val list_add_flat = thm "list_add_flat";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1252
val list_append_induct = thm "list_append_induct";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1253
val min_sym = thm "min_sym";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1254
val min_type = thm "min_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1255
val min_0 = thm "min_0";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1256
val min_02 = thm "min_02";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1257
val lt_min_iff = thm "lt_min_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1258
val min_succ_succ = thm "min_succ_succ";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1259
val filter_append = thm "filter_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1260
val filter_type = thm "filter_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1261
val length_filter = thm "length_filter";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1262
val filter_is_subset = thm "filter_is_subset";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1263
val filter_False = thm "filter_False";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1264
val filter_True = thm "filter_True";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1265
val length_is_0_iff = thm "length_is_0_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1266
val length_is_0_iff2 = thm "length_is_0_iff2";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1267
val length_tl = thm "length_tl";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1268
val length_greater_0_iff = thm "length_greater_0_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1269
val length_succ_iff = thm "length_succ_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1270
val append_is_Nil_iff = thm "append_is_Nil_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1271
val append_is_Nil_iff2 = thm "append_is_Nil_iff2";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1272
val append_left_is_self_iff = thm "append_left_is_self_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1273
val append_left_is_self_iff2 = thm "append_left_is_self_iff2";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1274
val append_left_is_Nil_iff = thm "append_left_is_Nil_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1275
val append_left_is_Nil_iff2 = thm "append_left_is_Nil_iff2";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1276
val append_eq_append_iff = thm "append_eq_append_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1277
val append_eq_append = thm "append_eq_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1278
val append_eq_append_iff2 = thm "append_eq_append_iff2";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1279
val append_self_iff = thm "append_self_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1280
val append_self_iff2 = thm "append_self_iff2";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1281
val append1_eq_iff = thm "append1_eq_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1282
val append_right_is_self_iff = thm "append_right_is_self_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1283
val append_right_is_self_iff2 = thm "append_right_is_self_iff2";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1284
val hd_append = thm "hd_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1285
val tl_append = thm "tl_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1286
val rev_is_Nil_iff = thm "rev_is_Nil_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1287
val Nil_is_rev_iff = thm "Nil_is_rev_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1288
val rev_is_rev_iff = thm "rev_is_rev_iff";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1289
val rev_list_elim = thm "rev_list_elim";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1290
val length_drop = thm "length_drop";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1291
val drop_all = thm "drop_all";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1292
val drop_append = thm "drop_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1293
val drop_drop = thm "drop_drop";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1294
val take_0 = thm "take_0";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1295
val take_succ_Cons = thm "take_succ_Cons";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1296
val take_Nil = thm "take_Nil";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1297
val take_all = thm "take_all";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1298
val take_type = thm "take_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1299
val take_append = thm "take_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1300
val take_take = thm "take_take";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1301
val nth_0 = thm "nth_0";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1302
val nth_Cons = thm "nth_Cons";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1303
val nth_type = thm "nth_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1304
val nth_append = thm "nth_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1305
val set_of_list_conv_nth = thm "set_of_list_conv_nth";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1306
val nth_take_lemma = thm "nth_take_lemma";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1307
val nth_equalityI = thm "nth_equalityI";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1308
val take_equalityI = thm "take_equalityI";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1309
val nth_drop = thm "nth_drop";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1310
val list_on_set_of_list = thm "list_on_set_of_list";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1311
val zip_Nil = thm "zip_Nil";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1312
val zip_Nil2 = thm "zip_Nil2";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1313
val zip_Cons_Cons = thm "zip_Cons_Cons";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1314
val zip_type = thm "zip_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1315
val length_zip = thm "length_zip";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1316
val zip_append1 = thm "zip_append1";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1317
val zip_append2 = thm "zip_append2";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1318
val zip_append = thm "zip_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1319
val zip_rev = thm "zip_rev";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1320
val nth_zip = thm "nth_zip";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1321
val set_of_list_zip = thm "set_of_list_zip";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1322
val list_update_Nil = thm "list_update_Nil";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1323
val list_update_Cons_0 = thm "list_update_Cons_0";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1324
val list_update_Cons_succ = thm "list_update_Cons_succ";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1325
val list_update_type = thm "list_update_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1326
val length_list_update = thm "length_list_update";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1327
val nth_list_update = thm "nth_list_update";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1328
val nth_list_update_eq = thm "nth_list_update_eq";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1329
val nth_list_update_neq = thm "nth_list_update_neq";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1330
val list_update_overwrite = thm "list_update_overwrite";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1331
val list_update_same_conv = thm "list_update_same_conv";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1332
val update_zip = thm "update_zip";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1333
val set_update_subset_cons = thm "set_update_subset_cons";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1334
val set_of_list_update_subsetI = thm "set_of_list_update_subsetI";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1335
val upt_rec = thm "upt_rec";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1336
val upt_conv_Nil = thm "upt_conv_Nil";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1337
val upt_succ_append = thm "upt_succ_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1338
val upt_conv_Cons = thm "upt_conv_Cons";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1339
val upt_type = thm "upt_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1340
val upt_add_eq_append = thm "upt_add_eq_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1341
val length_upt = thm "length_upt";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1342
val nth_upt = thm "nth_upt";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1343
val take_upt = thm "take_upt";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1344
val map_succ_upt = thm "map_succ_upt";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1345
val nth_map = thm "nth_map";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1346
val nth_map_upt = thm "nth_map_upt";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1347
val sublist_0 = thm "sublist_0";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1348
val sublist_Nil = thm "sublist_Nil";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1349
val sublist_shift_lemma = thm "sublist_shift_lemma";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1350
val sublist_type = thm "sublist_type";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1351
val upt_add_eq_append2 = thm "upt_add_eq_append2";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1352
val sublist_append = thm "sublist_append";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1353
val sublist_Cons = thm "sublist_Cons";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1354
val sublist_singleton = thm "sublist_singleton";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1355
val sublist_upt_eq_take = thm "sublist_upt_eq_take";
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1356
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1357
structure list =
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1358
struct
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1359
val induct = thm "list.induct"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1360
val elim   = thm "list.cases"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1361
val intrs  = thms "list.intros"
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1362
end;  
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1363
*}
be7105a066d3 converted List to new-style
paulson
parents: 12789
diff changeset
  1364
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 435
diff changeset
  1365
end