src/ZF/list.ML
author clasohm
Thu Sep 16 12:20:38 1993 +0200 (1993-09-16)
changeset 0 a5a9c433f639
child 6 8ce8c4d13d4d
permissions -rw-r--r--
Initial revision
clasohm@0
     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
clasohm@0
    10
 (val thy = Univ.thy;
clasohm@0
    11
  val rec_specs = 
clasohm@0
    12
      [("list", "univ(A)",
clasohm@0
    13
	  [(["Nil"],	"i"), 
clasohm@0
    14
	   (["Cons"],	"[i,i]=>i")])];
clasohm@0
    15
  val rec_styp = "i=>i";
clasohm@0
    16
  val ext = None
clasohm@0
    17
  val sintrs = 
clasohm@0
    18
      ["Nil : list(A)",
clasohm@0
    19
       "[| a: A;  l: list(A) |] ==> Cons(a,l) : list(A)"];
clasohm@0
    20
  val monos = [];
clasohm@0
    21
  val type_intrs = data_typechecks
clasohm@0
    22
  val type_elims = []);
clasohm@0
    23
clasohm@0
    24
val [NilI, ConsI] = List.intrs;
clasohm@0
    25
clasohm@0
    26
(*An elimination rule, for type-checking*)
clasohm@0
    27
val ConsE = List.mk_cases List.con_defs "Cons(a,l) : list(A)";
clasohm@0
    28
clasohm@0
    29
(*Proving freeness results*)
clasohm@0
    30
val Cons_iff     = List.mk_free "Cons(a,l)=Cons(a',l') <-> a=a' & l=l'";
clasohm@0
    31
val Nil_Cons_iff = List.mk_free "~ Nil=Cons(a,l)";
clasohm@0
    32
clasohm@0
    33
(*Perform induction on l, then prove the major premise using prems. *)
clasohm@0
    34
fun list_ind_tac a prems i = 
clasohm@0
    35
    EVERY [res_inst_tac [("x",a)] List.induct i,
clasohm@0
    36
	   rename_last_tac a ["1"] (i+2),
clasohm@0
    37
	   ares_tac prems i];
clasohm@0
    38
clasohm@0
    39
(**  Lemmas to justify using "list" in other recursive type definitions **)
clasohm@0
    40
clasohm@0
    41
goalw List.thy List.defs "!!A B. A<=B ==> list(A) <= list(B)";
clasohm@0
    42
by (rtac lfp_mono 1);
clasohm@0
    43
by (REPEAT (rtac List.bnd_mono 1));
clasohm@0
    44
by (REPEAT (ares_tac (univ_mono::basic_monos) 1));
clasohm@0
    45
val list_mono = result();
clasohm@0
    46
clasohm@0
    47
(*There is a similar proof by list induction.*)
clasohm@0
    48
goalw List.thy (List.defs@List.con_defs) "list(univ(A)) <= univ(A)";
clasohm@0
    49
by (rtac lfp_lowerbound 1);
clasohm@0
    50
by (rtac (A_subset_univ RS univ_mono) 2);
clasohm@0
    51
by (fast_tac (ZF_cs addSIs [zero_in_univ, Inl_in_univ, Inr_in_univ,
clasohm@0
    52
			    Pair_in_univ]) 1);
clasohm@0
    53
val list_univ = result();
clasohm@0
    54
clasohm@0
    55
val list_subset_univ = standard
clasohm@0
    56
    (list_mono RS (list_univ RSN (2,subset_trans)));
clasohm@0
    57
clasohm@0
    58
(*****
clasohm@0
    59
val major::prems = goal List.thy
clasohm@0
    60
    "[| l: list(A);    \
clasohm@0
    61
\       c: C(0);       \
clasohm@0
    62
\       !!x y. [| x: A;  y: list(A) |] ==> h(x,y): C(<x,y>)  \
clasohm@0
    63
\    |] ==> list_case(l,c,h) : C(l)";
clasohm@0
    64
by (rtac (major RS list_induct) 1);
clasohm@0
    65
by (ALLGOALS (ASM_SIMP_TAC (ZF_ss addrews
clasohm@0
    66
			    ([list_case_0,list_case_Pair]@prems))));
clasohm@0
    67
val list_case_type = result();
clasohm@0
    68
****)
clasohm@0
    69
clasohm@0
    70
clasohm@0
    71
(** For recursion **)
clasohm@0
    72
clasohm@0
    73
goalw List.thy List.con_defs "rank(a) : rank(Cons(a,l))";
clasohm@0
    74
by (SIMP_TAC rank_ss 1);
clasohm@0
    75
val rank_Cons1 = result();
clasohm@0
    76
clasohm@0
    77
goalw List.thy List.con_defs "rank(l) : rank(Cons(a,l))";
clasohm@0
    78
by (SIMP_TAC rank_ss 1);
clasohm@0
    79
val rank_Cons2 = result();
clasohm@0
    80