src/ZF/List.ML
author lcp
Fri, 12 Aug 1994 12:51:34 +0200
changeset 516 1957113f0d7d
parent 484 70b789956bd3
child 525 e62519a8497d
permissions -rw-r--r--
installation of new inductive/datatype sections
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
435
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
     1
(*  Title: 	ZF/List.ML
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
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
open List;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    11
(*** Aspects of the datatype definition ***)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
(*An elimination rule, for type-checking*)
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    14
val ConsE = list.mk_cases list.con_defs "Cons(a,l) : list(A)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
(*Proving freeness results*)
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    17
val Cons_iff     = list.mk_free "Cons(a,l)=Cons(a',l') <-> a=a' & l=l'";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    18
val Nil_Cons_iff = list.mk_free "~ Nil=Cons(a,l)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
(*Perform induction on l, then prove the major premise using prems. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
fun list_ind_tac a prems i = 
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    22
    EVERY [res_inst_tac [("x",a)] list.induct i,
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
	   rename_last_tac a ["1"] (i+2),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
	   ares_tac prems i];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
435
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    26
goal List.thy "list(A) = {0} + (A * list(A))";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    27
by (rtac (list.unfold RS trans) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    28
bws list.con_defs;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    29
br equalityI 1;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    30
by (fast_tac sum_cs 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    31
by (fast_tac (sum_cs addIs datatype_intrs
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    32
		     addDs [list.dom_subset RS subsetD]) 1);
435
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    33
val list_unfold = result();
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    34
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
(**  Lemmas to justify using "list" in other recursive type definitions **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    37
goalw List.thy list.defs "!!A B. A<=B ==> list(A) <= list(B)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
by (rtac lfp_mono 1);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    39
by (REPEAT (rtac list.bnd_mono 1));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
by (REPEAT (ares_tac (univ_mono::basic_monos) 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
val list_mono = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
(*There is a similar proof by list induction.*)
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    44
goalw List.thy (list.defs@list.con_defs) "list(univ(A)) <= univ(A)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
by (rtac lfp_lowerbound 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
by (rtac (A_subset_univ RS univ_mono) 2);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
by (fast_tac (ZF_cs addSIs [zero_in_univ, Inl_in_univ, Inr_in_univ,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
			    Pair_in_univ]) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
val list_univ = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
55
331d93292ee0 ZF/ind-syntax/refl_thin: new
lcp
parents: 30
diff changeset
    51
val list_subset_univ = standard ([list_mono, list_univ] MRS subset_trans);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
435
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    53
goal List.thy "!!l A B. [| l: list(A);  A <= univ(B) |] ==> l: univ(B)";
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    54
by (REPEAT (ares_tac [list_subset_univ RS subsetD] 1));
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    55
val list_into_univ = result();
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    56
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
val major::prems = goal List.thy
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
    "[| l: list(A);    \
15
6c6d2f6e3185 ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents: 6
diff changeset
    59
\       c: C(Nil);       \
6c6d2f6e3185 ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents: 6
diff changeset
    60
\       !!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
    61
\    |] ==> list_case(c,h,l) : C(l)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    62
by (rtac (major RS list.induct) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    63
by (ALLGOALS (asm_simp_tac (ZF_ss addsimps (list.case_eqns @ prems))));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
val list_case_type = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
(** For recursion **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    69
goalw List.thy list.con_defs "rank(a) < rank(Cons(a,l))";
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
    70
by (simp_tac rank_ss 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
val rank_Cons1 = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    73
goalw List.thy list.con_defs "rank(l) < rank(Cons(a,l))";
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
    74
by (simp_tac rank_ss 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
val rank_Cons2 = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    77
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    78
(*** List functions ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    79
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    80
(** hd and tl **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    81
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    82
goalw List.thy [hd_def] "hd(Cons(a,l)) = a";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    83
by (resolve_tac list.case_eqns 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    84
val hd_Cons = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    85
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    86
goalw List.thy [tl_def] "tl(Nil) = Nil";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    87
by (resolve_tac list.case_eqns 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    88
val tl_Nil = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    89
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    90
goalw List.thy [tl_def] "tl(Cons(a,l)) = l";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    91
by (resolve_tac list.case_eqns 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    92
val tl_Cons = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    93
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    94
goal List.thy "!!l. l: list(A) ==> tl(l) : list(A)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    95
by (etac list.elim 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    96
by (ALLGOALS (asm_simp_tac (ZF_ss addsimps (list.intrs @ [tl_Nil,tl_Cons]))));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    97
val tl_type = result();
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
(** drop **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   100
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   101
goalw List.thy [drop_def] "drop(0, l) = l";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   102
by (rtac rec_0 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   103
val drop_0 = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   104
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   105
goalw List.thy [drop_def] "!!i. i:nat ==> drop(i, Nil) = Nil";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   106
by (etac nat_induct 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   107
by (ALLGOALS (asm_simp_tac (nat_ss addsimps [tl_Nil])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   108
val drop_Nil = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   109
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   110
goalw List.thy [drop_def]
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   111
    "!!i. i:nat ==> drop(succ(i), Cons(a,l)) = drop(i,l)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   112
by (etac nat_induct 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   113
by (ALLGOALS (asm_simp_tac (nat_ss addsimps [tl_Cons])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   114
val drop_succ_Cons = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   115
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   116
goalw List.thy [drop_def] 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   117
    "!!i l. [| i:nat; l: list(A) |] ==> drop(i,l) : list(A)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   118
by (etac nat_induct 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   119
by (ALLGOALS (asm_simp_tac (nat_ss addsimps [tl_type])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   120
val drop_type = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   121
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   122
(** list_rec -- by Vset recursion **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   123
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   124
goal List.thy "list_rec(Nil,c,h) = c";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   125
by (rtac (list_rec_def RS def_Vrec RS trans) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   126
by (simp_tac (ZF_ss addsimps list.case_eqns) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   127
val list_rec_Nil = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   128
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   129
goal List.thy "list_rec(Cons(a,l), c, h) = h(a, l, list_rec(l,c,h))";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   130
by (rtac (list_rec_def RS def_Vrec RS trans) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   131
by (simp_tac (rank_ss addsimps (rank_Cons2::list.case_eqns)) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   132
val list_rec_Cons = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   133
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   134
(*Type checking -- proved by induction, as usual*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   135
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   136
    "[| l: list(A);    \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   137
\       c: C(Nil);       \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   138
\       !!x y r. [| x:A;  y: list(A);  r: C(y) |] ==> h(x,y,r): C(Cons(x,y))  \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   139
\    |] ==> list_rec(l,c,h) : C(l)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   140
by (list_ind_tac "l" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   141
by (ALLGOALS (asm_simp_tac
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   142
	      (ZF_ss addsimps (prems@[list_rec_Nil,list_rec_Cons]))));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   143
val list_rec_type = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   144
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   145
(** Versions for use with definitions **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   146
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   147
val [rew] = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   148
    "[| !!l. j(l)==list_rec(l, c, h) |] ==> j(Nil) = c";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   149
by (rewtac rew);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   150
by (rtac list_rec_Nil 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   151
val def_list_rec_Nil = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   152
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   153
val [rew] = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   154
    "[| !!l. j(l)==list_rec(l, c, h) |] ==> j(Cons(a,l)) = h(a,l,j(l))";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   155
by (rewtac rew);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   156
by (rtac list_rec_Cons 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   157
val def_list_rec_Cons = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   158
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   159
fun list_recs def = map standard
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   160
    	([def] RL [def_list_rec_Nil, def_list_rec_Cons]);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   161
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   162
(** map **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   163
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   164
val [map_Nil,map_Cons] = list_recs map_def;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   165
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   166
val prems = goalw List.thy [map_def] 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   167
    "[| 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
   168
by (REPEAT (ares_tac (prems @ list.intrs @ [list_rec_type]) 1));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   169
val map_type = result();
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
val [major] = goal List.thy "l: list(A) ==> map(h,l) : list({h(u). u:A})";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   172
by (rtac (major RS map_type) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   173
by (etac RepFunI 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   174
val map_type2 = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   175
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   176
(** length **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   177
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   178
val [length_Nil,length_Cons] = list_recs length_def;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   179
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   180
goalw List.thy [length_def] 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   181
    "!!l. l: list(A) ==> length(l) : nat";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   182
by (REPEAT (ares_tac [list_rec_type, nat_0I, nat_succI] 1));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   183
val length_type = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   184
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   185
(** app **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   186
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   187
val [app_Nil,app_Cons] = list_recs app_def;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   188
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   189
goalw List.thy [app_def] 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   190
    "!!xs ys. [| xs: list(A);  ys: list(A) |] ==> xs@ys : list(A)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   191
by (REPEAT (ares_tac [list_rec_type, list.Cons_I] 1));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   192
val app_type = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   193
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   194
(** rev **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   195
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   196
val [rev_Nil,rev_Cons] = list_recs rev_def;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   197
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   198
goalw List.thy [rev_def] 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   199
    "!!xs. xs: list(A) ==> rev(xs) : list(A)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   200
by (REPEAT (ares_tac (list.intrs @ [list_rec_type, app_type]) 1));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   201
val rev_type = result();
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
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   204
(** flat **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   205
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   206
val [flat_Nil,flat_Cons] = list_recs flat_def;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   207
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   208
goalw List.thy [flat_def] 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   209
    "!!ls. ls: list(list(A)) ==> flat(ls) : list(A)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   210
by (REPEAT (ares_tac (list.intrs @ [list_rec_type, app_type]) 1));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   211
val flat_type = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   212
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   213
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   214
(** list_add **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   215
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   216
val [list_add_Nil,list_add_Cons] = list_recs list_add_def;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   217
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   218
goalw List.thy [list_add_def] 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   219
    "!!xs. xs: list(nat) ==> list_add(xs) : nat";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   220
by (REPEAT (ares_tac [list_rec_type, nat_0I, add_type] 1));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   221
val list_add_type = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   222
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   223
(** List simplification **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   224
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   225
val list_typechecks =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   226
    list.intrs @
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   227
    [list_rec_type, map_type, map_type2, app_type, length_type, 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   228
     rev_type, flat_type, list_add_type];
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   229
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   230
val list_ss = arith_ss 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   231
    addsimps list.case_eqns
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   232
    addsimps [list_rec_Nil, list_rec_Cons, 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   233
	      map_Nil, map_Cons, app_Nil, app_Cons,
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   234
	      length_Nil, length_Cons, rev_Nil, rev_Cons,
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   235
	      flat_Nil, flat_Cons, list_add_Nil, list_add_Cons]
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   236
    setsolver (type_auto_tac list_typechecks);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   237
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   238
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   239
(*** theorems about map ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   240
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   241
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   242
    "l: list(A) ==> map(%u.u, l) = l";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   243
by (list_ind_tac "l" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   244
by (ALLGOALS (asm_simp_tac list_ss));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   245
val map_ident = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   246
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   247
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   248
    "l: list(A) ==> map(h, map(j,l)) = map(%u.h(j(u)), l)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   249
by (list_ind_tac "l" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   250
by (ALLGOALS (asm_simp_tac list_ss));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   251
val map_compose = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   252
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   253
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   254
    "xs: list(A) ==> map(h, xs@ys) = map(h,xs) @ map(h,ys)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   255
by (list_ind_tac "xs" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   256
by (ALLGOALS (asm_simp_tac list_ss));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   257
val map_app_distrib = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   258
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   259
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   260
    "ls: list(list(A)) ==> map(h, flat(ls)) = flat(map(map(h),ls))";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   261
by (list_ind_tac "ls" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   262
by (ALLGOALS (asm_simp_tac (list_ss addsimps [map_app_distrib])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   263
val map_flat = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   264
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   265
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   266
    "l: list(A) ==> \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   267
\    list_rec(map(h,l), c, d) = \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   268
\    list_rec(l, c, %x xs r. d(h(x), map(h,xs), r))";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   269
by (list_ind_tac "l" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   270
by (ALLGOALS (asm_simp_tac list_ss));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   271
val list_rec_map = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   272
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   273
(** theorems about list(Collect(A,P)) -- used in ex/term.ML **)
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
(* c : list(Collect(B,P)) ==> c : list(B) *)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   276
val list_CollectD = standard (Collect_subset RS list_mono RS subsetD);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   277
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   278
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   279
    "l: list({x:A. h(x)=j(x)}) ==> map(h,l) = map(j,l)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   280
by (list_ind_tac "l" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   281
by (ALLGOALS (asm_simp_tac list_ss));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   282
val map_list_Collect = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   283
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   284
(*** theorems about length ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   285
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   286
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   287
    "xs: list(A) ==> length(map(h,xs)) = length(xs)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   288
by (list_ind_tac "xs" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   289
by (ALLGOALS (asm_simp_tac list_ss));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   290
val length_map = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   291
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   292
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   293
    "xs: list(A) ==> length(xs@ys) = length(xs) #+ length(ys)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   294
by (list_ind_tac "xs" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   295
by (ALLGOALS (asm_simp_tac list_ss));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   296
val length_app = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   297
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   298
(* [| m: nat; n: nat |] ==> m #+ succ(n) = succ(n) #+ m 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   299
   Used for rewriting below*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   300
val add_commute_succ = nat_succI RSN (2,add_commute);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   301
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   302
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   303
    "xs: list(A) ==> length(rev(xs)) = length(xs)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   304
by (list_ind_tac "xs" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   305
by (ALLGOALS (asm_simp_tac (list_ss addsimps [length_app, add_commute_succ])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   306
val length_rev = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   307
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   308
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   309
    "ls: list(list(A)) ==> length(flat(ls)) = list_add(map(length,ls))";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   310
by (list_ind_tac "ls" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   311
by (ALLGOALS (asm_simp_tac (list_ss addsimps [length_app])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   312
val length_flat = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   313
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   314
(** Length and drop **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   315
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   316
(*Lemma for the inductive step of drop_length*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   317
goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   318
    "!!xs. xs: list(A) ==> \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   319
\          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
   320
by (etac list.induct 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   321
by (ALLGOALS (asm_simp_tac (list_ss addsimps [drop_0,drop_succ_Cons])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   322
by (fast_tac ZF_cs 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   323
val drop_length_Cons_lemma = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   324
val drop_length_Cons = standard (drop_length_Cons_lemma RS spec);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   325
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   326
goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   327
    "!!l. l: list(A) ==> ALL i: length(l).  EX z zs. drop(i,l) = Cons(z,zs)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   328
by (etac list.induct 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   329
by (ALLGOALS (asm_simp_tac (list_ss addsimps bquant_simps)));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   330
by (rtac conjI 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   331
by (etac drop_length_Cons 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   332
by (rtac ballI 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   333
by (rtac natE 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   334
by (etac ([asm_rl, length_type, Ord_nat] MRS Ord_trans) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   335
by (assume_tac 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   336
by (asm_simp_tac (list_ss addsimps [drop_0]) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   337
by (fast_tac ZF_cs 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   338
by (asm_simp_tac (list_ss addsimps [drop_succ_Cons]) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   339
by (dtac bspec 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   340
by (fast_tac ZF_cs 2);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   341
by (fast_tac (ZF_cs addEs [succ_in_naturalD,length_type]) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   342
val drop_length_lemma = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   343
val drop_length = standard (drop_length_lemma RS bspec);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   344
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   345
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   346
(*** theorems about app ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   347
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   348
val [major] = goal List.thy "xs: list(A) ==> xs@Nil=xs";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   349
by (rtac (major RS list.induct) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   350
by (ALLGOALS (asm_simp_tac list_ss));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   351
val app_right_Nil = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   352
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   353
val prems = goal List.thy "xs: list(A) ==> (xs@ys)@zs = xs@(ys@zs)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   354
by (list_ind_tac "xs" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   355
by (ALLGOALS (asm_simp_tac list_ss));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   356
val app_assoc = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   357
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   358
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   359
    "ls: list(list(A)) ==> flat(ls@ms) = flat(ls)@flat(ms)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   360
by (list_ind_tac "ls" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   361
by (ALLGOALS (asm_simp_tac (list_ss addsimps [app_assoc])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   362
val flat_app_distrib = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   363
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   364
(*** theorems about rev ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   365
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   366
val prems = goal List.thy "l: list(A) ==> rev(map(h,l)) = map(h,rev(l))";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   367
by (list_ind_tac "l" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   368
by (ALLGOALS (asm_simp_tac (list_ss addsimps [map_app_distrib])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   369
val rev_map_distrib = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   370
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   371
(*Simplifier needs the premises as assumptions because rewriting will not
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   372
  instantiate the variable ?A in the rules' typing conditions; note that
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   373
  rev_type does not instantiate ?A.  Only the premises do.
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   374
*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   375
goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   376
    "!!xs. [| xs: list(A);  ys: list(A) |] ==> rev(xs@ys) = rev(ys)@rev(xs)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   377
by (etac list.induct 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   378
by (ALLGOALS (asm_simp_tac (list_ss addsimps [app_right_Nil,app_assoc])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   379
val rev_app_distrib = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   380
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   381
val prems = goal List.thy "l: list(A) ==> rev(rev(l))=l";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   382
by (list_ind_tac "l" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   383
by (ALLGOALS (asm_simp_tac (list_ss addsimps [rev_app_distrib])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   384
val rev_rev_ident = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   385
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   386
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   387
    "ls: list(list(A)) ==> rev(flat(ls)) = flat(map(rev,rev(ls)))";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   388
by (list_ind_tac "ls" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   389
by (ALLGOALS (asm_simp_tac (list_ss addsimps 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   390
       [map_app_distrib, flat_app_distrib, rev_app_distrib, app_right_Nil])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   391
val rev_flat = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   392
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   393
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   394
(*** theorems about list_add ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   395
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   396
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   397
    "[| xs: list(nat);  ys: list(nat) |] ==> \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   398
\    list_add(xs@ys) = list_add(ys) #+ list_add(xs)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   399
by (cut_facts_tac prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   400
by (list_ind_tac "xs" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   401
by (ALLGOALS 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   402
    (asm_simp_tac (list_ss addsimps [add_0_right, add_assoc RS sym])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   403
by (rtac (add_commute RS subst_context) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   404
by (REPEAT (ares_tac [refl, list_add_type] 1));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   405
val list_add_app = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   406
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   407
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   408
    "l: list(nat) ==> list_add(rev(l)) = list_add(l)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   409
by (list_ind_tac "l" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   410
by (ALLGOALS
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   411
    (asm_simp_tac (list_ss addsimps [list_add_app, add_0_right])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   412
val list_add_rev = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   413
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   414
val prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   415
    "ls: list(list(nat)) ==> list_add(flat(ls)) = list_add(map(list_add,ls))";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   416
by (list_ind_tac "ls" prems 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   417
by (ALLGOALS (asm_simp_tac (list_ss addsimps [list_add_app])));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   418
by (REPEAT (ares_tac [refl, list_add_type, map_type, add_commute] 1));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   419
val list_add_flat = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   420
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   421
(** New induction rule **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   422
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   423
val major::prems = goal List.thy
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   424
    "[| l: list(A);  \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   425
\       P(Nil);        \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   426
\       !!x y. [| x: A;  y: list(A);  P(y) |] ==> P(y @ [x]) \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   427
\    |] ==> P(l)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   428
by (rtac (major RS rev_rev_ident RS subst) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   429
by (rtac (major RS rev_type RS list.induct) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   430
by (ALLGOALS (asm_simp_tac (list_ss addsimps prems)));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   431
val list_append_induct = result();
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   432