src/HOL/Inductive.ML
author wenzelm
Tue, 20 May 1997 19:29:50 +0200
changeset 3257 4e3724e0659f
parent 2855 36f75c4a0047
child 3768 67f4ac759100
permissions -rw-r--r--
README generation;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
     1
(*  Title:      HOL/inductive.ML
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1430
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   1993  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
(Co)Inductive Definitions for HOL
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
Inductive definitions use least fixedpoints with standard products and sums
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
Coinductive definitions use greatest fixedpoints with Quine products and sums
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
Sums are used only for mutual recursion;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
Products are used only to derive "streamlined" induction rules for relations
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
fun gen_fp_oper a (X,T,t) = 
1430
439e1476a7f8 Improving space efficiency of inductive/datatype definitions.
paulson
parents: 923
diff changeset
    16
    let val setT = Ind_Syntax.mk_setT T
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
    in Const(a, (setT-->setT)-->setT) $ absfree(X, setT, t)  end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
structure Lfp_items =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
  struct
2855
36f75c4a0047 Now calls require_thy to ensure ancestors are present
paulson
parents: 1465
diff changeset
    21
  val checkThy	= (fn thy => require_thy thy "Lfp" "inductive definitions")
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    22
  val oper      = gen_fp_oper "lfp"
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    23
  val Tarski    = def_lfp_Tarski
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    24
  val induct    = def_induct
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    25
  end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
structure Gfp_items =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    28
  struct
2855
36f75c4a0047 Now calls require_thy to ensure ancestors are present
paulson
parents: 1465
diff changeset
    29
  val checkThy	= (fn thy => require_thy thy "Gfp" "coinductive definitions")
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    30
  val oper      = gen_fp_oper "gfp"
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    31
  val Tarski    = def_gfp_Tarski
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    32
  val induct    = def_Collect_coinduct
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
  end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
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
functor Ind_section_Fun (Inductive: sig include INDUCTIVE_ARG INDUCTIVE_I end) 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
  : sig include INTR_ELIM INDRULE end =
1430
439e1476a7f8 Improving space efficiency of inductive/datatype definitions.
paulson
parents: 923
diff changeset
    38
let
439e1476a7f8 Improving space efficiency of inductive/datatype definitions.
paulson
parents: 923
diff changeset
    39
  structure Intr_elim = Intr_elim_Fun(structure Inductive=Inductive and 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    40
                                          Fp=Lfp_items);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
1430
439e1476a7f8 Improving space efficiency of inductive/datatype definitions.
paulson
parents: 923
diff changeset
    42
  structure Indrule = Indrule_Fun
439e1476a7f8 Improving space efficiency of inductive/datatype definitions.
paulson
parents: 923
diff changeset
    43
      (structure Inductive=Inductive and Intr_elim=Intr_elim);
439e1476a7f8 Improving space efficiency of inductive/datatype definitions.
paulson
parents: 923
diff changeset
    44
in 
439e1476a7f8 Improving space efficiency of inductive/datatype definitions.
paulson
parents: 923
diff changeset
    45
   struct 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    46
   val thy      = Intr_elim.thy
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    47
   val defs     = Intr_elim.defs
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    48
   val mono     = Intr_elim.mono
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    49
   val intrs    = Intr_elim.intrs
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    50
   val elim     = Intr_elim.elim
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    51
   val mk_cases = Intr_elim.mk_cases
1430
439e1476a7f8 Improving space efficiency of inductive/datatype definitions.
paulson
parents: 923
diff changeset
    52
   open Indrule 
439e1476a7f8 Improving space efficiency of inductive/datatype definitions.
paulson
parents: 923
diff changeset
    53
   end
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
structure Ind = Add_inductive_def_Fun (Lfp_items);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    59
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
signature INDUCTIVE_STRING =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    61
  sig
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    62
  val thy_name   : string               (*name of the new theory*)
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    63
  val srec_tms   : string list          (*recursion terms*)
5d7a7e439cec expanded tabs
clasohm
parents: 1430
diff changeset
    64
  val sintrs     : string list          (*desired introduction rules*)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
  end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
2855
36f75c4a0047 Now calls require_thy to ensure ancestors are present
paulson
parents: 1465
diff changeset
    68
(*Called by the theory sections or directly from ML*)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
functor Inductive_Fun
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
 (Inductive: sig include INDUCTIVE_STRING INDUCTIVE_ARG end)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
   : sig include INTR_ELIM INDRULE end =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
Ind_section_Fun
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    73
   (open Inductive Ind_Syntax
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    74
    val sign = sign_of thy;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
    val rec_tms = map (readtm sign termTVar) srec_tms
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
    and intr_tms = map (readtm sign propT) sintrs;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
    val thy = thy |> Ind.add_fp_def_i(rec_tms, intr_tms) 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
                  |> add_thyname thy_name);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    79
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    80
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    81
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
signature COINDRULE =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
  sig
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
  val coinduct : thm
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    85
  end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    86
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    87
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
functor CoInd_section_Fun
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
 (Inductive: sig include INDUCTIVE_ARG INDUCTIVE_I end) 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
    : sig include INTR_ELIM COINDRULE end =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    91
struct
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    92
structure Intr_elim = Intr_elim_Fun(structure Inductive=Inductive and Fp=Gfp_items);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    94
open Intr_elim 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    95
val coinduct = raw_induct
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    96
end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    98
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    99
structure CoInd = Add_inductive_def_Fun(Gfp_items);