src/HOL/ind_syntax.ML
author wenzelm
Thu Jan 23 14:19:16 1997 +0100 (1997-01-23)
changeset 2545 d10abc8c11fb
parent 1746 f0c6aabc6c02
child 4807 013ba4c43832
permissions -rw-r--r--
added AxClasses test;
clasohm@1465
     1
(*  Title:      HOL/ind_syntax.ML
clasohm@923
     2
    ID:         $Id$
clasohm@1465
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@923
     4
    Copyright   1994  University of Cambridge
clasohm@923
     5
clasohm@923
     6
Abstract Syntax functions for Inductive Definitions
clasohm@923
     7
See also hologic.ML and ../Pure/section-utils.ML
clasohm@923
     8
*)
clasohm@923
     9
clasohm@923
    10
(*The structure protects these items from redeclaration (somewhat!).  The 
clasohm@923
    11
  datatype definitions in theory files refer to these items by name!
clasohm@923
    12
*)
clasohm@923
    13
structure Ind_Syntax =
clasohm@923
    14
struct
clasohm@923
    15
clasohm@923
    16
(** Abstract syntax definitions for HOL **)
clasohm@923
    17
clasohm@923
    18
open HOLogic;
clasohm@923
    19
clasohm@923
    20
fun Int_const T = 
clasohm@923
    21
  let val sT = mk_setT T
clasohm@923
    22
  in  Const("op Int", [sT,sT]--->sT)  end;
clasohm@923
    23
clasohm@923
    24
fun mk_exists (Free(x,T),P) = exists_const T $ (absfree (x,T,P));
clasohm@923
    25
clasohm@923
    26
fun mk_all (Free(x,T),P) = all_const T $ (absfree (x,T,P));
clasohm@923
    27
clasohm@923
    28
(*Creates All(%v.v:A --> P(v)) rather than Ball(A,P) *)
clasohm@923
    29
fun mk_all_imp (A,P) = 
clasohm@923
    30
  let val T = dest_setT (fastype_of A)
clasohm@923
    31
  in  all_const T $ Abs("v", T, imp $ (mk_mem (Bound 0, A)) $ (P $ Bound 0))
clasohm@923
    32
  end;
clasohm@923
    33
clasohm@923
    34
(** Disjoint sum type **)
clasohm@923
    35
clasohm@923
    36
fun mk_sum (T1,T2) = Type("+", [T1,T2]);
clasohm@1465
    37
val Inl = Const("Inl", dummyT)
clasohm@1465
    38
and Inr = Const("Inr", dummyT);         (*correct types added later!*)
clasohm@1465
    39
(*val elim      = Const("case", [iT-->iT, iT-->iT, iT]--->iT)*)
clasohm@923
    40
clasohm@923
    41
fun summands (Type("+", [T1,T2])) = summands T1 @ summands T2
clasohm@923
    42
  | summands T                    = [T];
clasohm@923
    43
clasohm@923
    44
(*Given the destination type, fills in correct types of an Inl/Inr nest*)
clasohm@923
    45
fun mend_sum_types (h,T) =
clasohm@923
    46
    (case (h,T) of
clasohm@1465
    47
         (Const("Inl",_) $ h1, Type("+", [T1,T2])) =>
clasohm@1465
    48
             Const("Inl", T1 --> T) $ (mend_sum_types (h1, T1))
clasohm@923
    49
       | (Const("Inr",_) $ h2, Type("+", [T1,T2])) =>
clasohm@1465
    50
             Const("Inr", T2 --> T) $ (mend_sum_types (h2, T2))
clasohm@923
    51
       | _ => h);
clasohm@923
    52
clasohm@923
    53
clasohm@923
    54
clasohm@923
    55
(*simple error-checking in the premises of an inductive definition*)
clasohm@923
    56
fun chk_prem rec_hd (Const("op &",_) $ _ $ _) =
clasohm@1465
    57
        error"Premises may not be conjuctive"
clasohm@923
    58
  | chk_prem rec_hd (Const("op :",_) $ t $ X) = 
clasohm@1465
    59
        deny (Logic.occs(rec_hd,t)) "Recursion term on left of member symbol"
clasohm@923
    60
  | chk_prem rec_hd t = 
clasohm@1465
    61
        deny (Logic.occs(rec_hd,t)) "Recursion term in side formula";
clasohm@923
    62
clasohm@923
    63
(*Return the conclusion of a rule, of the form t:X*)
clasohm@923
    64
fun rule_concl rl = 
clasohm@923
    65
    let val Const("Trueprop",_) $ (Const("op :",_) $ t $ X) = 
clasohm@1465
    66
                Logic.strip_imp_concl rl
clasohm@923
    67
    in  (t,X)  end;
clasohm@923
    68
clasohm@923
    69
(*As above, but return error message if bad*)
clasohm@923
    70
fun rule_concl_msg sign rl = rule_concl rl
clasohm@923
    71
    handle Bind => error ("Ill-formed conclusion of introduction rule: " ^ 
clasohm@1465
    72
                          Sign.string_of_term sign rl);
clasohm@923
    73
clasohm@923
    74
(*For simplifying the elimination rule*)
clasohm@923
    75
val sumprod_free_SEs = 
clasohm@923
    76
    Pair_inject ::
clasohm@923
    77
    map make_elim [(*Inl_neq_Inr, Inr_neq_Inl, Inl_inject, Inr_inject*)];
clasohm@923
    78
clasohm@923
    79
(*For deriving cases rules.  
clasohm@923
    80
  read_instantiate replaces a propositional variable by a formula variable*)
clasohm@923
    81
val equals_CollectD = 
clasohm@923
    82
    read_instantiate [("W","?Q")]
clasohm@923
    83
        (make_elim (equalityD1 RS subsetD RS CollectD));
clasohm@923
    84
clasohm@923
    85
(*Delete needless equality assumptions*)
clasohm@923
    86
val refl_thin = prove_goal HOL.thy "!!P. [| a=a;  P |] ==> P"
clasohm@923
    87
     (fn _ => [assume_tac 1]);
clasohm@923
    88
paulson@1430
    89
(*Includes rules for Suc and Pair since they are common constructions*)
nipkow@1433
    90
val elim_rls = [asm_rl, FalseE, (*Suc_neq_Zero, Zero_neq_Suc,
clasohm@1465
    91
                make_elim Suc_inject, *)
clasohm@1465
    92
                refl_thin, conjE, exE, disjE];
paulson@1430
    93
clasohm@923
    94
end;