src/ZF/List.ML
author clasohm
Fri Jul 01 11:03:42 1994 +0200 (1994-07-01 ago)
changeset 444 3ca9d49fd662
parent 435 ca5356bd315a
child 477 53fc8ad84b33
permissions -rw-r--r--
replaced extend_theory by new add_* functions;
changed syntax of datatype declaration
lcp@435
     1
(*  Title: 	ZF/List.ML
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1993  University of Cambridge
clasohm@0
     5
clasohm@0
     6
Datatype definition of Lists
clasohm@0
     7
*)
clasohm@0
     8
clasohm@0
     9
structure List = Datatype_Fun
lcp@279
    10
 (val thy        = Univ.thy
lcp@279
    11
  val rec_specs  = [("list", "univ(A)",
clasohm@444
    12
                      [(["Nil"],    "i", NoSyn), 
clasohm@444
    13
                       (["Cons"],   "[i,i]=>i", NoSyn)])]
lcp@279
    14
  val rec_styp   = "i=>i"
lcp@279
    15
  val sintrs     = ["Nil : list(A)",
lcp@279
    16
                    "[| a: A;  l: list(A) |] ==> Cons(a,l) : list(A)"]
lcp@279
    17
  val monos      = []
lcp@70
    18
  val type_intrs = datatype_intrs
lcp@84
    19
  val type_elims = datatype_elims);
clasohm@0
    20
clasohm@124
    21
store_theory "List" List.thy;
clasohm@124
    22
clasohm@0
    23
val [NilI, ConsI] = List.intrs;
clasohm@0
    24
clasohm@0
    25
(*An elimination rule, for type-checking*)
clasohm@0
    26
val ConsE = List.mk_cases List.con_defs "Cons(a,l) : list(A)";
clasohm@0
    27
clasohm@0
    28
(*Proving freeness results*)
clasohm@0
    29
val Cons_iff     = List.mk_free "Cons(a,l)=Cons(a',l') <-> a=a' & l=l'";
clasohm@0
    30
val Nil_Cons_iff = List.mk_free "~ Nil=Cons(a,l)";
clasohm@0
    31
clasohm@0
    32
(*Perform induction on l, then prove the major premise using prems. *)
clasohm@0
    33
fun list_ind_tac a prems i = 
clasohm@0
    34
    EVERY [res_inst_tac [("x",a)] List.induct i,
clasohm@0
    35
	   rename_last_tac a ["1"] (i+2),
clasohm@0
    36
	   ares_tac prems i];
clasohm@0
    37
lcp@435
    38
goal List.thy "list(A) = {0} + (A * list(A))";
lcp@435
    39
by (rtac (List.unfold RS trans) 1);
lcp@435
    40
bws List.con_defs;
lcp@435
    41
by (fast_tac (sum_cs addIs ([equalityI] @ datatype_intrs)
lcp@435
    42
		     addDs [List.dom_subset RS subsetD]
lcp@435
    43
 	             addEs [A_into_univ]) 1);
lcp@435
    44
val list_unfold = result();
lcp@435
    45
clasohm@0
    46
(**  Lemmas to justify using "list" in other recursive type definitions **)
clasohm@0
    47
clasohm@0
    48
goalw List.thy List.defs "!!A B. A<=B ==> list(A) <= list(B)";
clasohm@0
    49
by (rtac lfp_mono 1);
clasohm@0
    50
by (REPEAT (rtac List.bnd_mono 1));
clasohm@0
    51
by (REPEAT (ares_tac (univ_mono::basic_monos) 1));
clasohm@0
    52
val list_mono = result();
clasohm@0
    53
clasohm@0
    54
(*There is a similar proof by list induction.*)
clasohm@0
    55
goalw List.thy (List.defs@List.con_defs) "list(univ(A)) <= univ(A)";
clasohm@0
    56
by (rtac lfp_lowerbound 1);
clasohm@0
    57
by (rtac (A_subset_univ RS univ_mono) 2);
clasohm@0
    58
by (fast_tac (ZF_cs addSIs [zero_in_univ, Inl_in_univ, Inr_in_univ,
clasohm@0
    59
			    Pair_in_univ]) 1);
clasohm@0
    60
val list_univ = result();
clasohm@0
    61
lcp@55
    62
val list_subset_univ = standard ([list_mono, list_univ] MRS subset_trans);
clasohm@0
    63
lcp@435
    64
goal List.thy "!!l A B. [| l: list(A);  A <= univ(B) |] ==> l: univ(B)";
lcp@435
    65
by (REPEAT (ares_tac [list_subset_univ RS subsetD] 1));
lcp@435
    66
val list_into_univ = result();
lcp@435
    67
clasohm@0
    68
val major::prems = goal List.thy
clasohm@0
    69
    "[| l: list(A);    \
lcp@15
    70
\       c: C(Nil);       \
lcp@15
    71
\       !!x y. [| x: A;  y: list(A) |] ==> h(x,y): C(Cons(x,y))  \
lcp@15
    72
\    |] ==> list_case(c,h,l) : C(l)";
lcp@15
    73
by (rtac (major RS List.induct) 1);
lcp@15
    74
by (ALLGOALS (asm_simp_tac (ZF_ss addsimps (List.case_eqns @ prems))));
clasohm@0
    75
val list_case_type = result();
clasohm@0
    76
clasohm@0
    77
clasohm@0
    78
(** For recursion **)
clasohm@0
    79
lcp@30
    80
goalw List.thy List.con_defs "rank(a) < rank(Cons(a,l))";
lcp@6
    81
by (simp_tac rank_ss 1);
clasohm@0
    82
val rank_Cons1 = result();
clasohm@0
    83
lcp@30
    84
goalw List.thy List.con_defs "rank(l) < rank(Cons(a,l))";
lcp@6
    85
by (simp_tac rank_ss 1);
clasohm@0
    86
val rank_Cons2 = result();
clasohm@0
    87