src/ZF/constructor.ML
author lcp
Thu, 18 Aug 1994 17:41:40 +0200
changeset 543 e961b2092869
parent 516 1957113f0d7d
child 1103 08fda5148971
permissions -rw-r--r--
ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML ZF/ind_syntax/prove_term: deleted ZF/constructor, indrule, intr_elim: now call prove_goalw_cterm and Logic.unvarify
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     1
(*  Title: 	ZF/constructor.ML
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
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
     6
Constructor function module -- for (Co)Datatype Definitions
0
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: 477
diff changeset
     9
signature CONSTRUCTOR_ARG =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
  sig
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    11
  val thy    	   : theory		(*parent containing constructor defs*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    12
  val big_rec_name : string		(*name of mutually recursive set*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    13
  val con_ty_lists : ((string*typ*mixfix) * 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    14
		      string * term list * term list) list list
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    15
					(*description of constructors*)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
signature CONSTRUCTOR_RESULT =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
  sig
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    20
  val con_defs	 : thm list		(*definitions made in thy*)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
  val case_eqns  : thm list		(*equations for case operator*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
  val free_iffs  : thm list		(*freeness rewrite rules*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
  val free_SEs   : thm list		(*freeness destruct rules*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
  val mk_free    : string -> thm	(*makes freeness theorems*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    28
(*Proves theorems relating to constructors*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    29
functor Constructor_Fun (structure Const: CONSTRUCTOR_ARG and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
                      Pr : PR and Su : SU) : CONSTRUCTOR_RESULT =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
struct
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    32
open Logic Const Ind_Syntax;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    34
(*1st element is the case definition; others are the constructors*)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
val big_case_name = big_rec_name ^ "_case";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    37
val con_defs = get_def thy big_case_name :: 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    38
               map (get_def thy o #2) (flat con_ty_lists);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
(** Prove the case theorem **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    42
(*Get the case term from its definition*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    43
val Const("==",_) $ big_case_tm $ _ =
543
e961b2092869 ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 516
diff changeset
    44
    hd con_defs |> rep_thm |> #prop |> Logic.unvarify;
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    45
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    46
val (_, big_case_args) = strip_comb big_case_tm;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    47
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
(*Each equation has the form 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
  rec_case(f_con1,...,f_conn)(coni(args)) = f_coni(args) *)
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    50
fun mk_case_equation (((id,T,syn), name, args, prems), case_free) = 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    51
    mk_tprop (eq_const $ (big_case_tm $ (list_comb (Const(name,T), args)))
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    52
		         $ (list_comb (case_free, args))) ;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
val case_trans = hd con_defs RS def_trans;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    55
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    56
(*Proves a single case equation.  Could use simp_tac, but it's slower!*)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
fun case_tacsf con_def _ = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
  [rewtac con_def,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
   rtac case_trans 1,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
   REPEAT (resolve_tac [refl, Pr.split_eq RS trans, 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
			Su.case_inl RS trans, 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
			Su.case_inr RS trans] 1)];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
fun prove_case_equation (arg,con_def) =
543
e961b2092869 ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 516
diff changeset
    65
    prove_goalw_cterm [] 
e961b2092869 ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 516
diff changeset
    66
        (cterm_of (sign_of thy) (mk_case_equation arg))
e961b2092869 ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 516
diff changeset
    67
	(case_tacsf con_def);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
val free_iffs = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
    map standard (con_defs RL [def_swap_iff]) @
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
    [Su.distinct, Su.distinct', Su.inl_iff, Su.inr_iff, Pr.pair_iff];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    73
val free_SEs   = map (gen_make_elim [conjE,FalseE]) (free_iffs RL [iffD1]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
val free_cs = ZF_cs addSEs free_SEs;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
(*Typical theorems have the form ~con1=con2, con1=con2==>False,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
  con1(x)=con1(y) ==> x=y, con1(x)=con1(y) <-> x=y, etc.  *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
fun mk_free s =
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    80
    prove_goalw thy con_defs s
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
      (fn prems => [cut_facts_tac prems 1, fast_tac free_cs 1]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
val case_eqns = map prove_case_equation 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    84
		    (flat con_ty_lists ~~ big_case_args ~~ tl con_defs);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    85
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88