src/ZF/ind_syntax.ML
author paulson
Wed Dec 03 10:52:17 1997 +0100 (1997-12-03 ago)
changeset 4352 7ac9f3e8a97d
parent 3925 90f499226ab9
child 4804 02b7c759159b
permissions -rw-r--r--
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
     1 (*  Title:      ZF/ind-syntax.ML
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1993  University of Cambridge
     5 
     6 Abstract Syntax functions for Inductive Definitions
     7 *)
     8 
     9 (*The structure protects these items from redeclaration (somewhat!).  The 
    10   datatype definitions in theory files refer to these items by name!
    11 *)
    12 structure Ind_Syntax =
    13 struct
    14 
    15 (** Abstract syntax definitions for ZF **)
    16 
    17 val iT = Type("i",[]);
    18 
    19 val mem_const = Const("op :", [iT,iT]--->FOLogic.oT);
    20 
    21 (*Creates All(%v.v:A --> P(v)) rather than Ball(A,P) *)
    22 fun mk_all_imp (A,P) = 
    23     FOLogic.all_const iT $ 
    24       Abs("v", iT, FOLogic.imp $ (mem_const $ Bound 0 $ A) $ (P $ Bound 0));
    25 
    26 val Part_const = Const("Part", [iT,iT-->iT]--->iT);
    27 
    28 val Collect_const = Const("Collect", [iT, iT-->FOLogic.oT] ---> iT);
    29 fun mk_Collect (a,D,t) = Collect_const $ D $ absfree(a, iT, t);
    30 
    31 (*simple error-checking in the premises of an inductive definition*)
    32 fun chk_prem rec_hd (Const("op &",_) $ _ $ _) =
    33         error"Premises may not be conjuctive"
    34   | chk_prem rec_hd (Const("op :",_) $ t $ X) = 
    35         deny (Logic.occs(rec_hd,t)) "Recursion term on left of member symbol"
    36   | chk_prem rec_hd t = 
    37         deny (Logic.occs(rec_hd,t)) "Recursion term in side formula";
    38 
    39 (*Return the conclusion of a rule, of the form t:X*)
    40 fun rule_concl rl = 
    41     let val Const("Trueprop",_) $ (Const("op :",_) $ t $ X) = 
    42                 Logic.strip_imp_concl rl
    43     in  (t,X)  end;
    44 
    45 (*As above, but return error message if bad*)
    46 fun rule_concl_msg sign rl = rule_concl rl
    47     handle Bind => error ("Ill-formed conclusion of introduction rule: " ^ 
    48                           Sign.string_of_term sign rl);
    49 
    50 (*For deriving cases rules.  CollectD2 discards the domain, which is redundant;
    51   read_instantiate replaces a propositional variable by a formula variable*)
    52 val equals_CollectD = 
    53     read_instantiate [("W","?Q")]
    54         (make_elim (equalityD1 RS subsetD RS CollectD2));
    55 
    56 
    57 (** For datatype definitions **)
    58 
    59 fun dest_mem (Const("op :",_) $ x $ A) = (x,A)
    60   | dest_mem _ = error "Constructor specifications must have the form x:A";
    61 
    62 (*read a constructor specification*)
    63 fun read_construct sign (id, sprems, syn) =
    64     let val prems = map (readtm sign FOLogic.oT) sprems
    65         val args = map (#1 o dest_mem) prems
    66         val T = (map (#2 o dest_Free) args) ---> iT
    67                 handle TERM _ => error 
    68                     "Bad variable in constructor specification"
    69         val name = Syntax.const_name id syn  (*handle infix constructors*)
    70     in ((id,T,syn), name, args, prems) end;
    71 
    72 val read_constructs = map o map o read_construct;
    73 
    74 (*convert constructor specifications into introduction rules*)
    75 fun mk_intr_tms sg (rec_tm, constructs) =
    76   let
    77     fun mk_intr ((id,T,syn), name, args, prems) =
    78       Logic.list_implies
    79         (map FOLogic.mk_Trueprop prems,
    80 	 FOLogic.mk_Trueprop
    81 	    (mem_const $ list_comb (Const (Sign.full_name sg name, T), args)
    82 	               $ rec_tm))
    83   in  map mk_intr constructs  end;
    84 
    85 fun mk_all_intr_tms sg arg = List.concat (ListPair.map (mk_intr_tms sg) arg);
    86 
    87 val Un          = Const("op Un", [iT,iT]--->iT)
    88 and empty       = Const("0", iT)
    89 and univ        = Const("univ", iT-->iT)
    90 and quniv       = Const("quniv", iT-->iT);
    91 
    92 (*Make a datatype's domain: form the union of its set parameters*)
    93 fun union_params rec_tm =
    94   let val (_,args) = strip_comb rec_tm
    95   in  case (filter (fn arg => type_of arg = iT) args) of
    96          []    => empty
    97        | iargs => fold_bal (app Un) iargs
    98   end;
    99 
   100 (*Previously these both did    replicate (length rec_tms);  however now
   101   [q]univ itself constitutes the sum domain for mutual recursion!*)
   102 fun data_domain rec_tms = univ $ union_params (hd rec_tms);
   103 fun Codata_domain rec_tms = quniv $ union_params (hd rec_tms);
   104 
   105 (*Could go to FOL, but it's hardly general*)
   106 val def_swap_iff = prove_goal IFOL.thy "a==b ==> a=c <-> c=b"
   107  (fn [def] => [(rewtac def), (rtac iffI 1), (REPEAT (etac sym 1))]);
   108 
   109 val def_trans = prove_goal IFOL.thy "[| f==g;  g(a)=b |] ==> f(a)=b"
   110   (fn [rew,prem] => [ rewtac rew, rtac prem 1 ]);
   111 
   112 (*Delete needless equality assumptions*)
   113 val refl_thin = prove_goal IFOL.thy "!!P. [| a=a;  P |] ==> P"
   114      (fn _ => [assume_tac 1]);
   115 
   116 (*Includes rules for succ and Pair since they are common constructions*)
   117 val elim_rls = [asm_rl, FalseE, succ_neq_0, sym RS succ_neq_0, 
   118                 Pair_neq_0, sym RS Pair_neq_0, Pair_inject,
   119                 make_elim succ_inject, 
   120                 refl_thin, conjE, exE, disjE];
   121 
   122 (*Turns iff rules into safe elimination rules*)
   123 fun mk_free_SEs iffs = map (gen_make_elim [conjE,FalseE]) (iffs RL [iffD1]);
   124 
   125 end;
   126