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