src/ZF/List.ML
author berghofe
Mon, 21 Jan 2002 14:43:38 +0100
changeset 12822 073116d65bb9
parent 12789 459b5de466b2
child 12825 f1f7964ed05c
permissions -rw-r--r--
datatype_codegen now checks type of constructor.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 908
diff changeset
     1
(*  Title:      ZF/List.ML
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 908
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
Datatype definition of Lists
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
     9
(*** Aspects of the datatype definition ***)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
(*An elimination rule, for type-checking*)
9907
473a6604da94 tuned ML code (the_context, bind_thms(s));
wenzelm
parents: 9548
diff changeset
    12
bind_thm ("ConsE", list.mk_cases "Cons(a,l) : list(A)");
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
(*Proving freeness results*)
9907
473a6604da94 tuned ML code (the_context, bind_thms(s));
wenzelm
parents: 9548
diff changeset
    15
bind_thm ("Cons_iff", list.mk_free "Cons(a,l)=Cons(a',l') <-> a=a' & l=l'");
473a6604da94 tuned ML code (the_context, bind_thms(s));
wenzelm
parents: 9548
diff changeset
    16
bind_thm ("Nil_Cons_iff", list.mk_free "~ Nil=Cons(a,l)");
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    18
Goal "list(A) = {0} + (A * list(A))";
12789
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
    19
by (blast_tac (claset() addSIs (map (rewrite_rule list.con_defs) list.intrs) 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
    20
                        addEs [rewrite_rule list.con_defs list.elim]) 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    21
qed "list_unfold";
435
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    22
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
(**  Lemmas to justify using "list" in other recursive type definitions **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
5137
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5067
diff changeset
    25
Goalw list.defs "A<=B ==> list(A) <= list(B)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
by (rtac lfp_mono 1);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    27
by (REPEAT (rtac list.bnd_mono 1));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
by (REPEAT (ares_tac (univ_mono::basic_monos) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    29
qed "list_mono";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
(*There is a similar proof by list induction.*)
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    32
Goalw (list.defs@list.con_defs) "list(univ(A)) <= univ(A)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
by (rtac lfp_lowerbound 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
by (rtac (A_subset_univ RS univ_mono) 2);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
    35
by (blast_tac (claset() addSIs [zero_in_univ, Inl_in_univ, Inr_in_univ,
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
    36
				Pair_in_univ]) 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    37
qed "list_univ";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
908
1f99a44c10cb Updated comment about list_subset_univ and list_into_univ.
lcp
parents: 782
diff changeset
    39
(*These two theorems justify datatypes involving list(nat), list(A), ...*)
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
    40
bind_thm ("list_subset_univ", [list_mono, list_univ] MRS subset_trans);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
5137
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5067
diff changeset
    42
Goal "[| l: list(A);  A <= univ(B) |] ==> l: univ(B)";
435
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    43
by (REPEAT (ares_tac [list_subset_univ RS subsetD] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    44
qed "list_into_univ";
435
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    45
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
    46
val major::prems = Goal
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
    "[| l: list(A);    \
15
6c6d2f6e3185 ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents: 6
diff changeset
    48
\       c: C(Nil);       \
6c6d2f6e3185 ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents: 6
diff changeset
    49
\       !!x y. [| x: A;  y: list(A) |] ==> h(x,y): C(Cons(x,y))  \
6c6d2f6e3185 ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents: 6
diff changeset
    50
\    |] ==> list_case(c,h,l) : C(l)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    51
by (rtac (major RS list.induct) 1);
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 5529
diff changeset
    52
by (ALLGOALS (asm_simp_tac (simpset() addsimps prems)));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    53
qed "list_case_type";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    55
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    56
(*** List functions ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    57
5137
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5067
diff changeset
    58
Goal "l: list(A) ==> tl(l) : list(A)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
    59
by (exhaust_tac "l" 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
    60
by (ALLGOALS (asm_simp_tac (simpset() addsimps list.intrs)));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    61
qed "tl_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    62
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    63
(** drop **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    64
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    65
Goal "i:nat ==> drop(i, Nil) = Nil";
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    66
by (induct_tac "i" 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    67
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    68
qed "drop_Nil";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    69
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    70
Goal "i:nat ==> drop(succ(i), Cons(a,l)) = drop(i,l)";
2493
bdeb5024353a Removal of sum_cs and eq_cs
paulson
parents: 2469
diff changeset
    71
by (rtac sym 1);
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    72
by (induct_tac "i" 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    73
by (Simp_tac 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    74
by (Asm_simp_tac 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    75
qed "drop_succ_Cons";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    76
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    77
Addsimps [drop_Nil, drop_succ_Cons];
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    78
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    79
Goal "[| i:nat; l: list(A) |] ==> drop(i,l) : list(A)";
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    80
by (induct_tac "i" 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
    81
by (ALLGOALS (asm_simp_tac (simpset() addsimps [tl_type])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    82
qed "drop_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    83
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    84
Delsimps [drop_SUCC];
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    85
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    86
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 5529
diff changeset
    87
(** Type checking -- proved by induction, as usual **)
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    88
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
    89
val prems = Goal
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    90
    "[| l: list(A);    \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    91
\       c: C(Nil);       \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    92
\       !!x y r. [| x:A;  y: list(A);  r: C(y) |] ==> h(x,y,r): C(Cons(x,y))  \
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 5529
diff changeset
    93
\    |] ==> list_rec(c,h,l) : C(l)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
    94
by (cut_facts_tac prems 1);
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
    95
by (induct_tac "l" 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
    96
by (ALLGOALS (asm_simp_tac (simpset() addsimps prems)));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    97
qed "list_rec_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    98
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    99
(** map **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   100
11145
3e47692e3a3e eliminate get_def;
wenzelm
parents: 9907
diff changeset
   101
val prems = Goalw [thm "map_list_def"]
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   102
    "[| l: list(A);  !!x. x: A ==> h(x): B |] ==> map(h,l) : list(B)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   103
by (REPEAT (ares_tac (prems @ list.intrs @ [list_rec_type]) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   104
qed "map_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   105
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   106
Goal "l: list(A) ==> map(h,l) : list({h(u). u:A})";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   107
by (etac map_type 1);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   108
by (etac RepFunI 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   109
qed "map_type2";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   110
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   111
(** length **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   112
11145
3e47692e3a3e eliminate get_def;
wenzelm
parents: 9907
diff changeset
   113
Goalw [thm "length_list_def"]
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   114
    "l: list(A) ==> length(l) : nat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   115
by (REPEAT (ares_tac [list_rec_type, nat_0I, nat_succI] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   116
qed "length_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   117
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   118
(** app **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   119
11145
3e47692e3a3e eliminate get_def;
wenzelm
parents: 9907
diff changeset
   120
Goalw [thm "op @_list_def"]
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   121
    "[| xs: list(A);  ys: list(A) |] ==> xs@ys : list(A)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   122
by (REPEAT (ares_tac [list_rec_type, list.Cons_I] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   123
qed "app_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   124
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   125
(** rev **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   126
11145
3e47692e3a3e eliminate get_def;
wenzelm
parents: 9907
diff changeset
   127
Goalw [thm "rev_list_def"]
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   128
    "xs: list(A) ==> rev(xs) : list(A)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   129
by (REPEAT (ares_tac (list.intrs @ [list_rec_type, app_type]) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   130
qed "rev_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   131
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   132
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   133
(** flat **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   134
11145
3e47692e3a3e eliminate get_def;
wenzelm
parents: 9907
diff changeset
   135
Goalw [thm "flat_list_def"]
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   136
    "ls: list(list(A)) ==> flat(ls) : list(A)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   137
by (REPEAT (ares_tac (list.intrs @ [list_rec_type, app_type]) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   138
qed "flat_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   139
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   140
1926
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   141
(** set_of_list **)
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   142
11145
3e47692e3a3e eliminate get_def;
wenzelm
parents: 9907
diff changeset
   143
Goalw [thm "set_of_list_list_def"]
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   144
    "l: list(A) ==> set_of_list(l) : Pow(A)";
2033
639de962ded4 Ran expandshort; used stac instead of ssubst
paulson
parents: 1926
diff changeset
   145
by (etac list_rec_type 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   146
by (ALLGOALS (Blast_tac));
1926
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   147
qed "set_of_list_type";
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   148
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   149
Goal "xs: list(A) ==> \
1926
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   150
\         set_of_list (xs@ys) = set_of_list(xs) Un set_of_list(ys)";
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   151
by (etac list.induct 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   152
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Un_cons])));
1926
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   153
qed "set_of_list_append";
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   154
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   155
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   156
(** list_add **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   157
11145
3e47692e3a3e eliminate get_def;
wenzelm
parents: 9907
diff changeset
   158
Goalw [thm "list_add_list_def"] 
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   159
    "xs: list(nat) ==> list_add(xs) : nat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   160
by (REPEAT (ares_tac [list_rec_type, nat_0I, add_type] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   161
qed "list_add_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   162
9907
473a6604da94 tuned ML code (the_context, bind_thms(s));
wenzelm
parents: 9548
diff changeset
   163
bind_thms ("list_typechecks",
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   164
    list.intrs @
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   165
    [list_rec_type, map_type, map_type2, app_type, length_type, 
9907
473a6604da94 tuned ML code (the_context, bind_thms(s));
wenzelm
parents: 9548
diff changeset
   166
     rev_type, flat_type, list_add_type]);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   167
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6141
diff changeset
   168
AddTCs list_typechecks;
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   169
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   170
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   171
(*** theorems about map ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   172
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   173
Goal "l: list(A) ==> map(%u. u, l) = l";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   174
by (induct_tac "l" 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   175
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   176
qed "map_ident";
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   177
Addsimps [map_ident];
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   178
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   179
Goal "l: list(A) ==> map(h, map(j,l)) = map(%u. h(j(u)), l)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   180
by (induct_tac "l" 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   181
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   182
qed "map_compose";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   183
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   184
Goal "xs: list(A) ==> map(h, xs@ys) = map(h,xs) @ map(h,ys)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   185
by (induct_tac "xs" 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   186
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   187
qed "map_app_distrib";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   188
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   189
Goal "ls: list(list(A)) ==> map(h, flat(ls)) = flat(map(map(h),ls))";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   190
by (induct_tac "ls" 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   191
by (ALLGOALS (asm_simp_tac (simpset() addsimps [map_app_distrib])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   192
qed "map_flat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   193
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   194
Goal "l: list(A) ==> \
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 5529
diff changeset
   195
\    list_rec(c, d, map(h,l)) = \
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 5529
diff changeset
   196
\    list_rec(c, %x xs r. d(h(x), map(h,xs), r), l)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   197
by (induct_tac "l" 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   198
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   199
qed "list_rec_map";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   200
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   201
(** theorems about list(Collect(A,P)) -- used in ex/term.ML **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   202
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   203
(* c : list(Collect(B,P)) ==> c : list(B) *)
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   204
bind_thm ("list_CollectD", Collect_subset RS list_mono RS subsetD);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   205
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   206
Goal "l: list({x:A. h(x)=j(x)}) ==> map(h,l) = map(j,l)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   207
by (induct_tac "l" 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   208
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   209
qed "map_list_Collect";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   210
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   211
(*** theorems about length ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   212
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   213
Goal "xs: list(A) ==> length(map(h,xs)) = length(xs)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   214
by (induct_tac "xs" 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   215
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   216
qed "length_map";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   217
9491
1a36151ee2fc natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents: 6153
diff changeset
   218
Goal "[| xs: list(A); ys: list(A) |] \
1a36151ee2fc natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents: 6153
diff changeset
   219
\     ==> length(xs@ys) = length(xs) #+ length(ys)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   220
by (induct_tac "xs" 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   221
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   222
qed "length_app";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   223
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   224
Goal "xs: list(A) ==> length(rev(xs)) = length(xs)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   225
by (induct_tac "xs" 1);
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   226
by (ALLGOALS (asm_simp_tac (simpset() addsimps [length_app])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   227
qed "length_rev";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   228
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   229
Goal "ls: list(list(A)) ==> length(flat(ls)) = list_add(map(length,ls))";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   230
by (induct_tac "ls" 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   231
by (ALLGOALS (asm_simp_tac (simpset() addsimps [length_app])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   232
qed "length_flat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   233
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   234
(** Length and drop **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   235
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   236
(*Lemma for the inductive step of drop_length*)
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   237
Goal "xs: list(A) ==> \
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   238
\          ALL x.  EX z zs. drop(length(xs), Cons(x,xs)) = Cons(z,zs)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   239
by (etac list.induct 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   240
by (ALLGOALS Asm_simp_tac);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   241
by (Blast_tac 1);
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   242
qed_spec_mp "drop_length_Cons";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   243
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   244
Goal "l: list(A) ==> ALL i:length(l). (EX z zs. drop(i,l) = Cons(z,zs))";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   245
by (etac list.induct 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   246
by (ALLGOALS Asm_simp_tac);
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   247
by Safe_tac;
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   248
by (etac drop_length_Cons 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   249
by (rtac natE 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   250
by (etac ([asm_rl, length_type, Ord_nat] MRS Ord_trans) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   251
by (assume_tac 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   252
by (ALLGOALS Asm_simp_tac);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   253
by (ALLGOALS (blast_tac (claset() addIs [succ_in_naturalD, length_type])));
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   254
qed_spec_mp "drop_length";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   255
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   256
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   257
(*** theorems about app ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   258
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   259
Goal "xs: list(A) ==> xs@Nil=xs";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   260
by (etac list.induct 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   261
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   262
qed "app_right_Nil";
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   263
Addsimps [app_right_Nil];
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   264
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   265
Goal "xs: list(A) ==> (xs@ys)@zs = xs@(ys@zs)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   266
by (induct_tac "xs" 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   267
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   268
qed "app_assoc";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   269
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   270
Goal "ls: list(list(A)) ==> flat(ls@ms) = flat(ls)@flat(ms)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   271
by (induct_tac "ls" 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   272
by (ALLGOALS (asm_simp_tac (simpset() addsimps [app_assoc])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   273
qed "flat_app_distrib";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   274
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   275
(*** theorems about rev ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   276
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   277
Goal "l: list(A) ==> rev(map(h,l)) = map(h,rev(l))";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   278
by (induct_tac "l" 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   279
by (ALLGOALS (asm_simp_tac (simpset() addsimps [map_app_distrib])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   280
qed "rev_map_distrib";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   281
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   282
(*Simplifier needs the premises as assumptions because rewriting will not
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   283
  instantiate the variable ?A in the rules' typing conditions; note that
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   284
  rev_type does not instantiate ?A.  Only the premises do.
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   285
*)
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   286
Goal "[| xs: list(A);  ys: list(A) |] ==> rev(xs@ys) = rev(ys)@rev(xs)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   287
by (etac list.induct 1);
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   288
by (ALLGOALS (asm_simp_tac (simpset() addsimps [app_assoc])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   289
qed "rev_app_distrib";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   290
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   291
Goal "l: list(A) ==> rev(rev(l))=l";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   292
by (induct_tac "l" 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   293
by (ALLGOALS (asm_simp_tac (simpset() addsimps [rev_app_distrib])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   294
qed "rev_rev_ident";
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   295
Addsimps [rev_rev_ident];
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   296
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   297
Goal "ls: list(list(A)) ==> rev(flat(ls)) = flat(map(rev,rev(ls)))";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   298
by (induct_tac "ls" 1);
6112
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   299
by (ALLGOALS
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   300
    (asm_simp_tac (simpset() addsimps 
5e4871c5136b datatype package improvements
paulson
parents: 6070
diff changeset
   301
		   [map_app_distrib, flat_app_distrib, rev_app_distrib])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   302
qed "rev_flat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   303
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   304
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   305
(*** theorems about list_add ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   306
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   307
Goal "[| xs: list(nat);  ys: list(nat) |] ==> \
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   308
\    list_add(xs@ys) = list_add(ys) #+ list_add(xs)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   309
by (induct_tac "xs" 1);
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9491
diff changeset
   310
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   311
qed "list_add_app";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   312
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   313
Goal "l: list(nat) ==> list_add(rev(l)) = list_add(l)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   314
by (induct_tac "l" 1);
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9491
diff changeset
   315
by (ALLGOALS (asm_simp_tac (simpset() addsimps [list_add_app])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   316
qed "list_add_rev";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   317
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   318
Goal "ls: list(list(nat)) ==> list_add(flat(ls)) = list_add(map(list_add,ls))";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6053
diff changeset
   319
by (induct_tac "ls" 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   320
by (ALLGOALS (asm_simp_tac (simpset() addsimps [list_add_app])));
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   321
by (REPEAT (ares_tac [refl, list_add_type, map_type, add_commute] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   322
qed "list_add_flat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   323
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   324
(** New induction rule **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   325
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   326
val major::prems = Goal
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   327
    "[| l: list(A);  \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   328
\       P(Nil);        \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   329
\       !!x y. [| x: A;  y: list(A);  P(y) |] ==> P(y @ [x]) \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   330
\    |] ==> P(l)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   331
by (rtac (major RS rev_rev_ident RS subst) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   332
by (rtac (major RS rev_type RS list.induct) 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   333
by (ALLGOALS (asm_simp_tac (simpset() addsimps prems)));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   334
qed "list_append_induct";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   335
12789
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   336
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   337
(*** Thanks to Sidi Ehmety for these results about min, take, etc. ***)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   338
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   339
(** min **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   340
(* Min theorems are also true for i, j ordinals *)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   341
Goalw [min_def] "[| i:nat; j:nat |] ==> min(i,j)=min(j,i)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   342
by (auto_tac (claset() addSDs [not_lt_imp_le] 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   343
                       addDs [lt_not_sym] 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   344
                       addIs [le_anti_sym], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   345
qed "min_sym";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   346
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   347
Goalw [min_def] "[| i:nat; j:nat |] ==> min(i,j):nat";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   348
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   349
qed "min_type";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   350
AddTCs [min_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   351
Addsimps [min_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   352
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   353
Goalw [min_def]  "i:nat ==> min(0,i) = 0";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   354
by (auto_tac (claset() addDs [not_lt_imp_le], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   355
qed "min_0";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   356
Addsimps [min_0];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   357
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   358
Goalw [min_def] "i:nat ==> min(i, 0) = 0";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   359
by (auto_tac (claset() addDs [not_lt_imp_le], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   360
qed "min_02";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   361
Addsimps [min_02];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   362
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   363
Goalw [min_def] "[| i:nat; j:nat; k:nat |] ==> i<min(j,k) <-> i<j & i<k";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   364
by (auto_tac (claset() addSDs [not_lt_imp_le]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   365
                       addIs [lt_trans2, lt_trans], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   366
qed "lt_min_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   367
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   368
Goalw [min_def]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   369
     "[| i:nat; j:nat |] ==>  min(succ(i), succ(j))= succ(min(i, j))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   370
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   371
qed "min_succ_succ";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   372
Addsimps [min_succ_succ];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   373
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   374
(*** more theorems about lists ***)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   375
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   376
Goal "xs:list(A) ==> (xs~=Nil)<->(EX y:A. EX ys:list(A). xs=Cons(y,ys))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   377
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   378
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   379
qed "neq_Nil_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   380
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   381
(** filter **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   382
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   383
Goal "xs:list(A) ==> filter(P, xs@ys) = filter(P, xs) @ filter(P, ys)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   384
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   385
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   386
qed "filter_append";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   387
Addsimps [filter_append];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   388
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   389
Goal "xs:list(A) ==> filter(P, xs):list(A)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   390
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   391
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   392
qed "filter_type";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   393
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   394
Goal "xs:list(A) ==> length(filter(P, xs)) le length(xs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   395
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   396
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   397
by (res_inst_tac [("j", "length(l)")] le_trans 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   398
by (auto_tac (claset(), simpset() addsimps [le_iff]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   399
qed "length_filter";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   400
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   401
Goal "xs:list(A) ==> set_of_list(filter(P,xs)) <= set_of_list(xs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   402
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   403
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   404
qed "filter_is_subset";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   405
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   406
Goal "xs:list(A) ==> filter(%p. False, xs) = Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   407
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   408
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   409
qed "filter_False";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   410
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   411
Goal "xs:list(A) ==> filter(%p. True, xs) = xs";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   412
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   413
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   414
qed "filter_True";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   415
Addsimps [filter_False, filter_True];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   416
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   417
(** length **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   418
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   419
Goal "xs:list(A) ==> length(xs)=0 <-> xs=Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   420
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   421
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   422
qed "length_is_0_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   423
Addsimps [length_is_0_iff];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   424
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   425
Goal "xs:list(A) ==> 0 = length(xs) <-> xs=Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   426
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   427
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   428
qed "length_is_0_iff2";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   429
Addsimps [length_is_0_iff2];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   430
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   431
Goal "xs:list(A) ==> length(tl(xs)) = length(xs) #- 1";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   432
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   433
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   434
qed "length_tl";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   435
Addsimps [length_tl];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   436
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   437
Goal "xs:list(A) ==> 0<length(xs) <-> xs ~= Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   438
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   439
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   440
qed "length_greater_0_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   441
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   442
Goal "xs:list(A) ==> length(xs)=succ(n) <-> (EX y ys. xs=Cons(y, ys) & length(ys)=n)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   443
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   444
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   445
qed "length_succ_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   446
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   447
(** more theorems about append **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   448
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   449
Goal "xs:list(A) ==> (xs@ys = Nil) <-> (xs=Nil & ys = Nil)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   450
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   451
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   452
qed "append_is_Nil_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   453
Addsimps [append_is_Nil_iff];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   454
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   455
Goal "xs:list(A) ==> (Nil = xs@ys) <-> (xs=Nil & ys = Nil)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   456
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   457
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   458
qed "append_is_Nil_iff2";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   459
Addsimps [append_is_Nil_iff2];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   460
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   461
Goal "xs:list(A) ==> (xs@ys = xs) <-> (ys = Nil)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   462
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   463
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   464
qed "append_left_is_self_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   465
Addsimps [append_left_is_self_iff];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   466
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   467
Goal "xs:list(A) ==> (xs = xs@ys) <-> (ys = Nil)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   468
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   469
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   470
qed "append_left_is_self_iff2";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   471
Addsimps [append_left_is_self_iff2];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   472
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   473
Goal "[| xs:list(A); ys:list(A); zs:list(A) |] ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   474
\  length(ys)=length(zs) --> (xs@ys=zs <-> (xs=Nil & ys=zs))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   475
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   476
by (auto_tac (claset(), simpset() addsimps [length_app]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   477
qed_spec_mp "append_left_is_Nil_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   478
Addsimps [append_left_is_Nil_iff];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   479
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   480
Goal "[| xs:list(A); ys:list(A); zs:list(A) |] ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   481
\  length(ys)=length(zs) --> (zs=ys@xs <-> (xs=Nil & ys=zs))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   482
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   483
by (auto_tac (claset(), simpset() addsimps [length_app]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   484
qed_spec_mp "append_left_is_Nil_iff2";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   485
Addsimps [append_left_is_Nil_iff2];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   486
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   487
Goal "xs:list(A) ==> ALL ys:list(A). \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   488
\     length(xs)=length(ys) --> (xs@us = ys@vs) <-> (xs=ys & us=vs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   489
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   490
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   491
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   492
by (eres_inst_tac [("a", "ys")] list.elim 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   493
by (ALLGOALS(Asm_full_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   494
qed_spec_mp "append_eq_append_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   495
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   496
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   497
Goal "xs:list(A) ==>  \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   498
\  ALL ys:list(A). ALL us:list(A). ALL vs:list(A). \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   499
\  length(us) = length(vs) --> (xs@us = ys@vs) --> (xs=ys & us=vs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   500
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   501
by (ALLGOALS(Clarify_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   502
by (asm_full_simp_tac (simpset() addsimps [length_app]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   503
by (eres_inst_tac [("a", "ys")] list.elim 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   504
by (Asm_full_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   505
by (subgoal_tac "Cons(a, l) @ us =vs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   506
by (dtac (rotate_prems 4 (append_left_is_Nil_iff RS iffD1)) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   507
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   508
qed_spec_mp "append_eq_append";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   509
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   510
Goal "[| xs:list(A); ys:list(A); us:list(A); vs:list(A); length(us)=length(vs) |] \ 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   511
\ ==>  xs@us = ys@vs <-> (xs=ys & us=vs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   512
by (rtac iffI 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   513
by (rtac append_eq_append 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   514
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   515
qed "append_eq_append_iff2";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   516
Addsimps [append_eq_append_iff, append_eq_append_iff2];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   517
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   518
Goal "[| xs:list(A); ys:list(A); zs:list(A) |] ==> xs@ys=xs@zs <-> ys=zs";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   519
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   520
qed "append_self_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   521
Addsimps [append_self_iff];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   522
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   523
Goal "[| xs:list(A); ys:list(A); zs:list(A) |] ==> ys@xs=zs@xs <-> ys=zs";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   524
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   525
qed "append_self_iff2";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   526
Addsimps [append_self_iff2];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   527
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   528
(* Can also be proved from append_eq_append_iff2,
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   529
but the proof requires two more hypotheses: x:A and y:A *)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   530
Goal "xs:list(A) ==> ALL ys:list(A). xs@[x] = ys@[y] <-> (xs = ys & x=y)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   531
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   532
by (ALLGOALS(Clarify_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   533
by (ALLGOALS(eres_inst_tac [("a", "ys")] list.elim));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   534
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   535
qed_spec_mp "append1_eq_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   536
Addsimps [append1_eq_iff];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   537
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   538
Goal "[| xs:list(A); ys:list(A) |] ==> (xs@ys = ys) <-> (xs=Nil)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   539
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   540
qed "append_right_is_self_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   541
Addsimps [append_right_is_self_iff];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   542
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   543
Goal "[| xs:list(A); ys:list(A) |] ==> (ys = xs@ys) <-> (xs=Nil)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   544
by (rtac iffI 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   545
by (dtac sym 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   546
by (ALLGOALS(Asm_full_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   547
qed "append_right_is_self_iff2";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   548
Addsimps [append_right_is_self_iff2];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   549
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   550
Goal "xs:list(A) ==> xs ~= Nil --> hd(xs @ ys) = hd(xs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   551
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   552
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   553
qed_spec_mp "hd_append";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   554
Addsimps [hd_append];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   555
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   556
Goal "xs:list(A) ==> xs~=Nil --> tl(xs @ ys) = tl(xs)@ys";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   557
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   558
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   559
qed_spec_mp "tl_append";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   560
Addsimps [tl_append];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   561
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   562
(** rev **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   563
Goal "xs:list(A) ==> (rev(xs) = Nil <-> xs = Nil)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   564
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   565
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   566
qed "rev_is_Nil_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   567
Addsimps [rev_is_Nil_iff];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   568
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   569
Goal "xs:list(A) ==> (Nil = rev(xs) <-> xs = Nil)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   570
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   571
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   572
qed "Nil_is_rev_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   573
Addsimps [Nil_is_rev_iff];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   574
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   575
Goal "xs:list(A) ==> ALL ys:list(A). rev(xs)=rev(ys) <-> xs=ys";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   576
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   577
by (Force_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   578
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   579
by (eres_inst_tac [("a", "ys")] list.elim 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   580
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   581
qed_spec_mp "rev_is_rev_iff";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   582
Addsimps [rev_is_rev_iff];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   583
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   584
Goal "xs:list(A) ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   585
\ (xs=Nil --> P) --> (ALL ys:list(A). ALL y:A. xs =ys@[y] -->P)-->P";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   586
by (etac list_append_induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   587
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   588
qed_spec_mp "rev_list_elim_aux";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   589
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   590
bind_thm("rev_list_elim", impI RS ballI RS ballI RSN(3, rev_list_elim_aux));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   591
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   592
(** more theorems about drop **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   593
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   594
Goal "n:nat ==> ALL xs:list(A). length(drop(n, xs)) = length(xs) #- n";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   595
by (etac nat_induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   596
by (auto_tac (claset() addEs [list.elim], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   597
qed_spec_mp "length_drop";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   598
Addsimps [length_drop];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   599
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   600
Goal "n:nat ==> ALL xs:list(A). length(xs) le n --> drop(n, xs)=Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   601
by (etac nat_induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   602
by (auto_tac (claset() addEs [list.elim], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   603
qed_spec_mp "drop_all";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   604
Addsimps [drop_all];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   605
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   606
Goal "n:nat ==> ALL xs:list(A). drop(n, xs@ys) = \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   607
\ drop(n,xs) @ drop(n #- length(xs), ys)"; 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   608
by (induct_tac "n" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   609
by (auto_tac (claset() addEs [list.elim], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   610
qed_spec_mp "drop_append";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   611
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   612
Goal "m:nat ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   613
\ ALL xs:list(A). ALL n:nat. drop(n, drop(m, xs))=drop(n #+ m, xs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   614
by (induct_tac "m" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   615
by (auto_tac (claset() addEs [list.elim], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   616
qed "drop_drop";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   617
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   618
(** take **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   619
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   620
Goalw [take_def]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   621
 "xs:list(A) ==> take(0, xs) =  Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   622
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   623
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   624
qed "take_0";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   625
Addsimps [take_0];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   626
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   627
Goalw [take_def]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   628
"n:nat ==> take(succ(n), Cons(a, xs)) = Cons(a, take(n, xs))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   629
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   630
qed "take_succ_Cons";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   631
Addsimps [take_succ_Cons];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   632
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   633
(* Needed for proving take_all *)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   634
Goalw [take_def]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   635
 "n:nat ==> take(n, Nil) = Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   636
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   637
qed "take_Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   638
Addsimps [take_Nil];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   639
 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   640
Goal "n:nat ==> ALL xs:list(A). length(xs) le n  --> take(n, xs) = xs";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   641
by (etac nat_induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   642
by (auto_tac (claset() addEs [list.elim], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   643
qed_spec_mp  "take_all";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   644
Addsimps [take_all];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   645
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   646
Goal "xs:list(A) ==> ALL n:nat. take(n, xs):list(A)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   647
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   648
by (Clarify_tac 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   649
by (etac natE 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   650
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   651
qed_spec_mp "take_type";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   652
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   653
Goal "xs:list(A) ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   654
\ ALL ys:list(A). ALL n:nat. take(n, xs @ ys) = \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   655
\                           take(n, xs) @ take(n #- length(xs), ys)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   656
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   657
by (Clarify_tac 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   658
by (etac natE 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   659
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   660
qed_spec_mp "take_append";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   661
Addsimps [take_append];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   662
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   663
Goal
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   664
"m:nat ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   665
\ ALL xs:list(A). ALL n:nat. take(n, take(m,xs))= take(min(n, m), xs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   666
by (induct_tac "m" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   667
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   668
by (eres_inst_tac [("a", "xs")] list.elim 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   669
by (auto_tac (claset(), simpset() addsimps [take_Nil]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   670
by (rotate_tac 1 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   671
by (etac natE 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   672
by (auto_tac (claset() addIs [take_0, take_type], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   673
qed_spec_mp "take_take";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   674
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   675
(** nth **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   676
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   677
Goalw [nth_def] "nth(0, Cons(a, l))= a";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   678
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   679
qed "nth_0";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   680
Addsimps [nth_0];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   681
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   682
Goalw [nth_def]  
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   683
   "n:nat ==> nth(succ(n), Cons(a, l)) = nth(n, l)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   684
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   685
qed "nth_Cons";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   686
Addsimps [nth_Cons];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   687
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   688
Goal "xs:list(A) ==> ALL n:nat. n < length(xs) --> nth(n, xs):A";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   689
by (etac list.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   690
by (ALLGOALS(Clarify_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   691
by (etac natE 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   692
by (ALLGOALS(Asm_full_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   693
qed_spec_mp "nth_type";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   694
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   695
AddTCs [nth_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   696
Addsimps [nth_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   697
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   698
Goal 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   699
"xs:list(A) ==> ALL n:nat. \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   700
\ nth(n, xs @ ys) = (if n < length(xs) then nth(n,xs) \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   701
\                      else nth(n #- length(xs),ys))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   702
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   703
by (Clarify_tac 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   704
by (etac natE 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   705
by (ALLGOALS(Asm_full_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   706
qed_spec_mp "nth_append";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   707
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   708
Goal "xs:list(A) ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   709
\ set_of_list(xs) = {x:A. EX i:nat. i<length(xs) & x=nth(i, xs)}";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   710
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   711
by (ALLGOALS(Asm_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   712
by (rtac equalityI 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   713
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   714
by (res_inst_tac [("x", "0")] bexI 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   715
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   716
by (res_inst_tac [("x", "succ(i)")] bexI 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   717
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   718
by (etac natE 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   719
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   720
qed "set_of_list_conv_nth";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   721
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   722
(* Other theorems about lists *)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   723
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   724
Goalw [Ball_def]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   725
 "k:nat ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   726
\ ALL xs:list(A). (ALL ys:list(A). k le length(xs) --> k le length(ys) -->  \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   727
\     (ALL i:nat. i<k --> nth(i,xs)= nth(i,ys))--> take(k, xs) = take(k,ys))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   728
by (induct_tac "k" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   729
by (ALLGOALS (asm_simp_tac (simpset() addsimps 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   730
             [lt_succ_eq_0_disj, all_conj_distrib])));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   731
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   732
(*Both lists must be non-empty*)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   733
by (case_tac "xa=Nil" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   734
by (case_tac "xb=Nil" 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   735
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   736
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [neq_Nil_iff])));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   737
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   738
(*prenexing's needed, not miniscoping*)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   739
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   740
by (rtac conjI 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   741
by (Force_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   742
by (ALLGOALS (full_simp_tac (simpset() addsimps (all_simps RL [iff_sym])  
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   743
                                       delsimps (all_simps))));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   744
by (dres_inst_tac [("x", "ys"), ("x1", "ysa")] (spec RS spec) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   745
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   746
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   747
qed_spec_mp "nth_take_lemma";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   748
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   749
Goal "[| xs:list(A); ys:list(A); length(xs) = length(ys);  \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   750
\        ALL i:nat. i < length(xs) --> nth(i,xs) = nth(i,ys) |]  \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   751
\     ==> xs = ys";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   752
by (subgoal_tac "length(xs) le length(ys)" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   753
by (forw_inst_tac [("ys", "ys")] (rotate_prems 1 nth_take_lemma) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   754
by (ALLGOALS(Asm_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   755
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [take_all])));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   756
qed_spec_mp "nth_equalityI";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   757
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   758
(*The famous take-lemma*)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   759
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   760
Goal "[| xs:list(A); ys:list(A); (ALL i:nat. take(i, xs) = take(i,ys)) |] ==> xs = ys";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   761
by (case_tac "length(xs) le length(ys)" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   762
by (dres_inst_tac [("x", "length(ys)")] bspec 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   763
by (dtac not_lt_imp_le 3);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   764
by (subgoal_tac "length(ys) le length(xs)" 5);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   765
by (res_inst_tac [("j", "succ(length(ys))")] le_trans 6);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   766
by (rtac leI 6);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   767
by (dres_inst_tac [("x", "length(xs)")] bspec 5);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   768
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [take_all])));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   769
qed_spec_mp "take_equalityI";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   770
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   771
Goal "n:nat ==> ALL i:nat. ALL xs:list(A). n #+ i le length(xs) \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   772
\               --> nth(i, drop(n, xs)) = nth(n #+ i, xs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   773
by (induct_tac "n" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   774
by (ALLGOALS(Asm_full_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   775
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   776
by (case_tac "xb=Nil" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   777
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [neq_Nil_iff])));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   778
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   779
by (auto_tac (claset() addSEs [ConsE], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   780
qed_spec_mp "nth_drop";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   781
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   782
(** zip **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   783
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   784
Goal "l:list(A) ==> l:list(set_of_list(l))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   785
by (induct_tac "l" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   786
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   787
by (res_inst_tac [("A1", "set_of_list(l)")] (list_mono RS subsetD) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   788
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   789
qed "list_on_set_of_list";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   790
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   791
Goal "A<=C ==> ziprel(A, B) <= ziprel(C,B)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   792
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   793
by (forward_tac [ziprel.dom_subset RS subsetD] 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   794
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   795
by (etac ziprel.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   796
by (auto_tac (claset() addIs [list_mono RS subsetD]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   797
                       addSIs ziprel.intrs, simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   798
qed "ziprel_mono1";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   799
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   800
Goal "B<=C ==> ziprel(A, B) <= ziprel(A,C)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   801
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   802
by (forward_tac [ziprel.dom_subset RS subsetD] 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   803
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   804
by (etac ziprel.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   805
by (auto_tac (claset() addIs [list_mono RS subsetD]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   806
                       addSIs ziprel.intrs, simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   807
qed "ziprel_mono2";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   808
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   809
Goal "[| A<=C; B<=D |] ==> ziprel(A, B) <= ziprel(C,D)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   810
by (rtac subset_trans 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   811
by (rtac ziprel_mono1 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   812
by (rtac ziprel_mono2 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   813
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   814
qed "ziprel_mono";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   815
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   816
(* ziprel is a function *)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   817
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   818
Goal "<xs, ys, zs>:ziprel(A,B) \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   819
\     ==> ALL ks. <xs, ys, ks>:ziprel(A, B) --> ks=zs";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   820
by (etac ziprel.induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   821
by (ALLGOALS(Clarify_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   822
by (rotate_tac 1 3);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   823
by (ALLGOALS(etac ziprel.elim));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   824
by Safe_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   825
(* These hypotheses make Auto_tac loop! *)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   826
by (thin_tac "ALL k. ?P(k)" 3);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   827
by (thin_tac "ALL k. ?P(k)" 4);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   828
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   829
qed "ziprel_is_fun";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   830
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   831
Goal "ys:list(B)  ==> ALL xs:list(A). EX zs. <xs, ys, zs>:ziprel(A,B)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   832
by (induct_tac "ys" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   833
by (auto_tac (claset() addIs ziprel.intrs, simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   834
by (eres_inst_tac [("a", "xs")] list.elim 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   835
by (auto_tac (claset() addIs ziprel.intrs, simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   836
qed_spec_mp "ziprel_exist"; 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   837
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   838
Goalw [zip_def]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   839
 "[|xs:list(A); ys:list(B) |] ==> <xs, ys, zip(xs,ys)>:ziprel(A,B)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   840
by (rtac theI2 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   841
by (asm_full_simp_tac (simpset() addsimps [set_of_list_append]) 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   842
by (REPEAT(dtac set_of_list_type 2));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   843
by (rtac (ziprel_mono RS subsetD) 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   844
by (Blast_tac 3);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   845
by (dtac list_on_set_of_list 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   846
by (dtac list_on_set_of_list 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   847
by (subgoal_tac "xs:list(set_of_list(xs@ys)) & \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   848
\                ys:list(set_of_list(xs@ys))" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   849
by (auto_tac (claset() addIs [list_mono RS subsetD],
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   850
              simpset() addsimps [set_of_list_append]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   851
by (rtac (ziprel_is_fun RS spec RS mp) 2); 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   852
by (rtac ziprel_exist 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   853
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   854
qed "zip_in_ziprel";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   855
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   856
Goal
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   857
"<xs, ys, zs>:ziprel(A,B) ==> zip(xs, ys)=zs";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   858
by (rtac (ziprel_is_fun RS spec RS mp) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   859
by (Blast_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   860
by (blast_tac (claset() addDs [ziprel.dom_subset RS subsetD]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   861
                        addIs [zip_in_ziprel]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   862
qed "zip_eq";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   863
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   864
(* zip equations *)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   865
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   866
Goal "ys:list(A) ==> zip(Nil, ys)=Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   867
by (res_inst_tac [("A", "A")] zip_eq 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   868
by (auto_tac (claset() addIs ziprel.intrs, simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   869
qed "zip_Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   870
Addsimps [zip_Nil];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   871
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   872
Goal "xs:list(A) ==> zip(xs, Nil)=Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   873
by (res_inst_tac [("A", "A")] zip_eq 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   874
by (auto_tac (claset() addIs ziprel.intrs, simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   875
qed "zip_Nil2";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   876
Addsimps [zip_Nil2];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   877
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   878
Goal "[| xs:list(A); ys:list(B); x:A; y:B |] ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   879
\ zip(Cons(x,xs), Cons(y, ys)) = Cons(<x,y>, zip(xs, ys))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   880
by (res_inst_tac [("A", "A")] zip_eq 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   881
by (forw_inst_tac [("ys", "ys")] zip_in_ziprel 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   882
by (auto_tac (claset() addIs ziprel.intrs, simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   883
qed "zip_Cons_Cons";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   884
Addsimps [zip_Cons_Cons];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   885
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   886
Goal "xs:list(A) ==> ALL ys:list(B). zip(xs, ys):list(A*B)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   887
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   888
by (Simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   889
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   890
by (eres_inst_tac [("a", "ys")] list.elim 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   891
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   892
qed_spec_mp "zip_type";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   893
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   894
AddTCs [zip_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   895
Addsimps [zip_type];    
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   896
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   897
(* zip length *)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   898
Goalw [min_def] "xs:list(A) ==> ALL ys:list(B). length(zip(xs,ys)) = \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   899
\                               min(length(xs), length(ys))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   900
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   901
by (Clarify_tac 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   902
by (eres_inst_tac [("a", "ys")] list.elim 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   903
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   904
qed_spec_mp "length_zip";  
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   905
Addsimps [length_zip];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   906
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   907
AddTCs [take_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   908
Addsimps [take_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   909
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   910
Goal "[| ys:list(A); zs:list(B) |] ==> ALL xs:list(A). zip(xs @ ys, zs) = \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   911
\ zip(xs, take(length(xs), zs)) @ zip(ys, drop(length(xs),zs))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   912
by (induct_tac "zs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   913
by (Clarify_tac 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   914
by (eres_inst_tac [("a", "xs")] list.elim 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   915
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   916
qed_spec_mp "zip_append1";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   917
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   918
Goal
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   919
 "[| xs:list(A); zs:list(B) |] ==> ALL ys:list(B). zip(xs, ys@zs) = \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   920
\      zip(take(length(ys), xs), ys) @ zip(drop(length(ys), xs), zs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   921
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   922
by (Clarify_tac 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   923
by (eres_inst_tac [("a", "ys")] list.elim 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   924
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   925
qed_spec_mp "zip_append2";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   926
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   927
Goal
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   928
 "[| length(xs) = length(us); length(ys) = length(vs); \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   929
\  xs:list(A); us:list(B); ys:list(A); vs:list(B) |] ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   930
\ zip(xs@ys,us@vs) = zip(xs, us) @ zip(ys, vs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   931
by (asm_simp_tac (simpset() addsimps 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   932
                  [zip_append1, drop_append, diff_self_eq_0]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   933
qed_spec_mp "zip_append";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   934
Addsimps [zip_append];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   935
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   936
Goal "ys:list(B) ==> ALL xs:list(A).  \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   937
\ length(xs) = length(ys) --> zip(rev(xs), rev(ys)) = rev(zip(xs, ys))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   938
by (induct_tac "ys" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   939
by (Clarify_tac 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   940
by (eres_inst_tac [("a", "xs")] list.elim 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   941
by (auto_tac (claset(), simpset() addsimps [length_rev]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   942
qed_spec_mp "zip_rev";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   943
Addsimps [zip_rev];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   944
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   945
Goal
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   946
"ys:list(B) ==> ALL i:nat. ALL xs:list(A). \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   947
\                   i < length(xs) --> i < length(ys) --> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   948
\                   nth(i,zip(xs, ys)) = <nth(i,xs),nth(i, ys)>";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   949
by (induct_tac "ys" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   950
by (Clarify_tac 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   951
by (eres_inst_tac [("a", "xs")] list.elim 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   952
by (auto_tac (claset() addEs [natE], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   953
qed_spec_mp "nth_zip";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   954
Addsimps [nth_zip];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   955
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   956
Goal "[| xs:list(A); ys:list(B); i:nat |] \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   957
\     ==> set_of_list(zip(xs, ys)) = \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   958
\         {<x, y>:A*B. EX i:nat. i < min(length(xs), length(ys))  \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   959
\         & x=nth(i, xs) & y=nth(i, ys)}";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   960
by (force_tac (claset() addSIs [Collect_cong], 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   961
               simpset() addsimps [lt_min_iff, set_of_list_conv_nth]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   962
qed_spec_mp "set_of_list_zip";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   963
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   964
(** list_update **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   965
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   966
Goalw [list_update_def] "i:nat ==>list_update(Nil, i, v) = Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   967
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   968
qed "list_update_Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   969
Addsimps [list_update_Nil];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   970
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   971
Goalw [list_update_def] 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   972
"list_update(Cons(x, xs), 0, v)= Cons(v, xs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   973
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   974
qed "list_update_Cons_0";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   975
Addsimps [list_update_Cons_0];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   976
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   977
Goalw [list_update_def] 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   978
"n:nat ==>\
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   979
\ list_update(Cons(x, xs), succ(n), v)= Cons(x, list_update(xs, n, v))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   980
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   981
qed "list_update_Cons_succ";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   982
Addsimps [list_update_Cons_succ];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   983
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   984
Goal "[| xs:list(A); v:A |] ==> ALL n:nat. list_update(xs, n, v):list(A)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   985
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   986
by (Simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   987
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   988
by (etac natE 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   989
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   990
qed_spec_mp "list_update_type";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   991
Addsimps [list_update_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   992
AddTCs [list_update_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   993
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   994
Goal "xs:list(A) ==> ALL i:nat. length(list_update(xs, i, v))=length(xs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   995
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   996
by (Simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   997
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   998
by (etac natE 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
   999
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1000
qed_spec_mp "length_list_update";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1001
Addsimps [length_list_update];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1002
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1003
Goal "[| xs:list(A) |] ==> ALL i:nat. ALL j:nat. i < length(xs)  --> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1004
\ nth(j, list_update(xs, i, x)) = (if i=j then x else nth(j, xs))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1005
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1006
 by (Simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1007
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1008
by (etac natE 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1009
by (ALLGOALS(Asm_full_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1010
by (ALLGOALS(Clarify_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1011
by (etac natE 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1012
by (ALLGOALS(Asm_full_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1013
by Safe_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1014
by (etac natE 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1015
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [nth_Cons])));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1016
qed_spec_mp "nth_list_update";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1017
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1018
Goal "[| i < length(xs); xs:list(A); i:nat |] \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1019
\  ==> nth(i, list_update(xs, i,x)) = x";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1020
by (asm_simp_tac (simpset() addsimps [nth_list_update]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1021
qed "nth_list_update_eq";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1022
Addsimps [nth_list_update_eq];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1023
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1024
Goal "xs:list(A) ==> ALL i:nat. ALL j:nat. i ~= j \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1025
\ --> nth(j, list_update(xs, i,x)) = nth(j, xs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1026
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1027
 by (Simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1028
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1029
by (etac natE 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1030
by (etac natE 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1031
by (ALLGOALS(Asm_full_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1032
by (etac natE 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1033
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [nth_Cons])));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1034
qed_spec_mp "nth_list_update_neq";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1035
Addsimps [nth_list_update_neq];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1036
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1037
Goal "xs:list(A) ==> ALL i:nat. i < length(xs)\
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1038
\  --> list_update(list_update(xs, i, x), i, y) = list_update(xs, i,y)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1039
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1040
 by (Simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1041
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1042
by (etac natE 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1043
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1044
qed_spec_mp "list_update_overwrite";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1045
Addsimps [list_update_overwrite];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1046
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1047
Goal "xs:list(A) ==> ALL i:nat. i < length(xs) --> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1048
\ (list_update(xs, i, x) = xs) <-> (nth(i, xs) = x)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1049
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1050
 by (Simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1051
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1052
by (etac natE 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1053
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1054
qed_spec_mp "list_update_same_conv";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1055
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1056
Goal "ys:list(B) ==> ALL i:nat. ALL xy:A*B. ALL xs:list(A). \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1057
\ length(xs) = length(ys) --> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1058
\     list_update(zip(xs, ys), i, xy) = zip(list_update(xs, i, fst(xy)), \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1059
\                                         list_update(ys, i, snd(xy)))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1060
by (induct_tac "ys" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1061
 by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1062
by (eres_inst_tac [("a", "xc")] list.elim 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1063
by (auto_tac (claset() addEs [natE], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1064
qed_spec_mp "update_zip";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1065
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1066
Goal "xs:list(A) ==> ALL i:nat. set_of_list(list_update(xs, i, x)) \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1067
\  <= cons(x, set_of_list(xs))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1068
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1069
 by (asm_full_simp_tac (simpset() addsimps []) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1070
by (rtac ballI 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1071
by (etac natE 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1072
by (ALLGOALS(Asm_full_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1073
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1074
qed_spec_mp "set_update_subset_cons";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1075
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1076
Goal "[| set_of_list(xs) <= A; xs:list(A); x:A; i:nat|]  \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1077
\  ==> set_of_list(list_update(xs, i,x)) <= A";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1078
by (rtac subset_trans 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1079
by (rtac set_update_subset_cons 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1080
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1081
qed "set_of_list_update_subsetI";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1082
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1083
(** upt **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1084
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1085
Goal "[| i:nat; j:nat |] \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1086
\ ==> upt(i,j) = (if i<j then Cons(i, upt(succ(i), j)) else Nil)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1087
by (induct_tac "j" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1088
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1089
by (dtac not_lt_imp_le 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1090
by (auto_tac (claset() addIs [le_anti_sym], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1091
qed "upt_rec";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1092
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1093
Goal "[| j le i; i:nat; j:nat |] ==> upt(i,j) = Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1094
by (stac upt_rec 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1095
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1096
by (auto_tac (claset(), simpset() addsimps [le_iff]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1097
by (dtac (lt_asym RS notE) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1098
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1099
qed "upt_conv_Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1100
Addsimps [upt_conv_Nil];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1101
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1102
(*Only needed if upt_Suc is deleted from the simpset*)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1103
Goal "[| i le j; i:nat; j:nat |] ==> upt(i,succ(j)) = upt(i, j)@[j]";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1104
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1105
qed "upt_succ_append";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1106
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1107
Goal "[| i<j; i:nat; j:nat |]  ==> upt(i,j) = Cons(i,upt(succ(i),j))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1108
by (rtac trans 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1109
by (stac upt_rec 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1110
by (rtac refl 4);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1111
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1112
qed "upt_conv_Cons";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1113
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1114
Goal "[| i:nat; j:nat |] ==> upt(i,j):list(nat)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1115
by (induct_tac "j" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1116
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1117
qed "upt_type";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1118
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1119
AddTCs [upt_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1120
Addsimps [upt_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1121
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1122
(*LOOPS as a simprule, since j<=j*)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1123
Goal "[| i le j; i:nat; j:nat; k:nat |] ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1124
\ upt(i, j #+k) = upt(i,j)@upt(j,j#+k)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1125
by (induct_tac "k" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1126
by (auto_tac (claset(), simpset() addsimps [app_assoc, app_type]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1127
by (res_inst_tac [("j", "j")] le_trans 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1128
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1129
qed "upt_add_eq_append";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1130
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1131
Goal "[| i:nat; j:nat |] ==>length(upt(i,j)) = j #- i";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1132
by (induct_tac "j" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1133
by (rtac sym 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1134
by (auto_tac (claset() addSDs [not_lt_imp_le], 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1135
              simpset() addsimps [length_app, diff_succ, diff_is_0_iff]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1136
qed "length_upt";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1137
Addsimps [length_upt];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1138
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1139
Goal "[| i:nat; j:nat; k:nat |] ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1140
\ i #+ k < j --> nth(k, upt(i,j)) = i #+ k";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1141
by (induct_tac "j" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1142
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1143
by (asm_full_simp_tac (simpset() addsimps [nth_append,lt_succ_iff] 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1144
                                 addsplits [nat_diff_split]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1145
by Safe_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1146
by (auto_tac (claset() addSDs [not_lt_imp_le], 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1147
              simpset() addsimps [nth_append, diff_self_eq_0, 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1148
                                  less_diff_conv, add_commute])); 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1149
by (dres_inst_tac [("j", "x")] lt_trans2 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1150
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1151
qed_spec_mp "nth_upt";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1152
Addsimps [nth_upt];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1153
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1154
Goal "[| m:nat; n:nat |] ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1155
\ ALL i:nat. i #+ m le n --> take(m, upt(i,n)) = upt(i,i#+m)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1156
by (induct_tac "m" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1157
by (asm_simp_tac (simpset() addsimps [take_0]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1158
by (Clarify_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1159
by (stac upt_rec 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1160
by (rtac sym 3);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1161
by (stac upt_rec 3);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1162
by (ALLGOALS(asm_full_simp_tac (simpset() delsimps (thms"upt.simps"))));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1163
by (res_inst_tac [("j", "succ(i #+ x)")] lt_trans2 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1164
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1165
qed_spec_mp "take_upt";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1166
Addsimps [take_upt];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1167
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1168
Goal "[| m:nat; n:nat |] ==> map(succ, upt(m,n))= upt(succ(m), succ(n))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1169
by (induct_tac "n" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1170
by (auto_tac (claset(), simpset() addsimps [map_app_distrib]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1171
qed "map_succ_upt";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1172
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1173
Goal "xs:list(A) ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1174
\ ALL n:nat. n < length(xs) --> nth(n, map(f, xs)) = f(nth(n, xs))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1175
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1176
by (Asm_full_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1177
by (rtac ballI 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1178
by (induct_tac "n" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1179
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1180
qed_spec_mp "nth_map";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1181
Addsimps [nth_map];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1182
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1183
Goal "[| m:nat; n:nat |] ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1184
\ ALL i:nat. i < n #- m --> nth(i, map(f, upt(m,n))) = f(m #+ i)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1185
by (res_inst_tac [("n", "m"), ("m", "n")] diff_induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1186
by (stac (map_succ_upt RS sym) 5);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1187
by (ALLGOALS(Asm_full_simp_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1188
by (ALLGOALS(Clarify_tac));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1189
by (subgoal_tac "xa < length(upt(0, x))" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1190
by (Asm_simp_tac 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1191
by (subgoal_tac "xa < length(upt(y, x))" 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1192
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [map_compose, 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1193
          nth_map, add_commute, less_diff_conv])));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1194
by (res_inst_tac [("j", "succ(xa #+ y)")] lt_trans2 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1195
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1196
qed_spec_mp "nth_map_upt";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1197
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1198
(** sublist (a generalization of nth to sets) **)
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1199
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1200
Goalw [sublist_def] "xs:list(A) ==>sublist(xs, 0) =Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1201
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1202
qed "sublist_0";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1203
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1204
Goalw [sublist_def] "sublist(Nil, A) = Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1205
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1206
qed "sublist_Nil";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1207
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1208
AddTCs [filter_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1209
Addsimps [filter_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1210
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1211
Goal "[| xs:list(B); i:nat |] ==>\
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1212
\    map(fst, filter(%p. snd(p):A, zip(xs, upt(i,i #+ length(xs))))) = \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1213
\    map(fst, filter(%p. snd(p):nat & snd(p) #+ i:A, zip(xs,upt(0,length(xs)))))";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1214
by (etac list_append_induct  1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1215
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1216
by (auto_tac (claset(), simpset() addsimps 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1217
         [add_commute, length_app, filter_append, map_app_distrib]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1218
qed "sublist_shift_lemma";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1219
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1220
Goalw [sublist_def]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1221
 "xs:list(B) ==> sublist(xs, A):list(B)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1222
by (induct_tac "xs" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1223
by (auto_tac (claset(), simpset() addsimps [filter_append, map_app_distrib]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1224
by (auto_tac (claset() addIs [map_type,filter_type,zip_type], simpset()));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1225
qed "sublist_type";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1226
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1227
AddTCs [sublist_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1228
Addsimps [sublist_type];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1229
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1230
Goal "[| i:nat; j:nat |] ==> upt(0, i #+ j) = upt(0, i) @ upt(i, i #+ j)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1231
by (asm_simp_tac (simpset() addsimps 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1232
                [inst "i" "0" upt_add_eq_append, nat_0_le]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1233
qed "upt_add_eq_append2";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1234
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1235
Goalw [sublist_def]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1236
     "[| xs:list(B); ys:list(B)  |] ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1237
\ sublist(xs@ys, A) = sublist(xs, A) @ sublist(ys, {j:nat. j #+ length(xs): A})";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1238
by (eres_inst_tac [("l", "ys")] list_append_induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1239
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1240
by (asm_simp_tac (simpset() addsimps [upt_add_eq_append2, 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1241
                                      zip_append, length_app,  app_assoc RS sym]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1242
by (auto_tac (claset(), simpset() addsimps [sublist_shift_lemma, 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1243
                                           length_type, map_app_distrib, app_assoc]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1244
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [add_commute])));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1245
qed "sublist_append";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1246
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1247
Addsimps [sublist_0, sublist_Nil];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1248
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1249
Goal "[| xs:list(B); x:B |] ==> \
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1250
\ sublist(Cons(x, xs), A) = (if 0:A then [x] else []) @ sublist(xs, {j:nat. succ(j) : A})";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1251
by (eres_inst_tac [("l", "xs")] list_append_induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1252
by (asm_simp_tac (simpset() addsimps [sublist_def]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1253
by (asm_simp_tac (simpset() delsimps (thms "op @.simps") 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1254
                 addsimps [(hd (tl (thms "op @.simps"))) RS sym, sublist_append]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1255
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1256
qed "sublist_Cons";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1257
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1258
Goal "sublist([x], A) = (if 0 : A then [x] else [])";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1259
by (simp_tac (simpset() addsimps [sublist_Cons]) 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1260
qed "sublist_singleton";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1261
Addsimps [sublist_singleton];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1262
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1263
Goalw [less_than_def]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1264
    "[| xs:list(A); n:nat |] ==> sublist(xs, less_than(n)) = take(n,xs)";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1265
by (eres_inst_tac [("l", "xs")] list_append_induct 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1266
 by (asm_simp_tac (simpset() addsplits [nat_diff_split]
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1267
                             addsimps [sublist_append]) 2);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1268
by Auto_tac;
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1269
by (subgoal_tac "n #- length(y) = 0" 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1270
by (Asm_simp_tac 1);
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1271
by (auto_tac (claset() addSDs [not_lt_imp_le], 
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1272
          simpset() addsimps [diff_is_0_iff]));
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1273
qed "sublist_upt_eq_take";
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1274
Addsimps [sublist_upt_eq_take];
459b5de466b2 new definitions from Sidi Ehmety
paulson
parents: 11145
diff changeset
  1275