src/Pure/theory.ML
author paulson
Wed, 20 Mar 1996 18:42:31 +0100
changeset 1593 69ed69a9c32a
parent 1539 f21c8fab7c3c
child 1960 ae390b599213
permissions -rw-r--r--
New module for proof objects (deriviations)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     1
(*  Title:      Pure/theory.ML
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     2
    ID:         $Id$
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson and Markus Wenzel
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     4
    Copyright   1996  University of Cambridge
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     5
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     6
Theories
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     7
*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     8
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     9
signature THEORY =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    10
  sig
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    11
  type theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    12
  exception THEORY of string * theory list
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    13
  val rep_theory        : theory ->
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    14
    {sign: Sign.sg, oraopt: (Sign.sg * exn -> term) option,
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    15
     new_axioms: term Symtab.table, parents: theory list}
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    16
  val sign_of           : theory -> Sign.sg
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    17
  val syn_of            : theory -> Syntax.syntax
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    18
  val stamps_of_thy     : theory -> string ref list
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    19
  val parents_of        : theory -> theory list
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    20
  val subthy            : theory * theory -> bool
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    21
  val eq_thy            : theory * theory -> bool
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    22
  val proto_pure_thy    : theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    23
  val pure_thy          : theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    24
  val cpure_thy         : theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    25
  (*theory primitives*)
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    26
  val add_classes	: (class * class list) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    27
  val add_classrel	: (class * class) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    28
  val add_defsort	: sort -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    29
  val add_types		: (string * int * mixfix) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    30
  val add_tyabbrs	: (string * string list * string * mixfix) list
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    31
    -> theory -> theory
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    32
  val add_tyabbrs_i	: (string * string list * typ * mixfix) list
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    33
    -> theory -> theory
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    34
  val add_arities	: (string * sort list * sort) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    35
  val add_consts	: (string * string * mixfix) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    36
  val add_consts_i	: (string * typ * mixfix) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    37
  val add_syntax	: (string * string * mixfix) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    38
  val add_syntax_i	: (string * typ * mixfix) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    39
  val add_trfuns	:
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    40
    (string * (Syntax.ast list -> Syntax.ast)) list *
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    41
    (string * (term list -> term)) list *
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    42
    (string * (term list -> term)) list *
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    43
    (string * (Syntax.ast list -> Syntax.ast)) list -> theory -> theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    44
  val add_trrules     : (string * string)Syntax.trrule list -> theory -> theory
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    45
  val add_trrules_i	: Syntax.ast Syntax.trrule list -> theory -> theory
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    46
  val cert_axm          : Sign.sg -> string * term -> string * term
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    47
  val read_axm          : Sign.sg -> string * string -> string * term
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    48
  val inferT_axm        : Sign.sg -> string * term -> string * term
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    49
  val add_axioms	: (string * string) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    50
  val add_axioms_i	: (string * term) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    51
  val add_thyname	: string -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    52
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    53
  val set_oracle	: (Sign.sg * exn -> term) -> theory -> theory
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    54
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    55
  val merge_theories    : theory * theory -> theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    56
  val merge_thy_list    : bool -> theory list -> theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    57
end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    58
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    59
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    60
structure Theory : THEORY =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    61
struct
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    62
(*** Theories ***)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    63
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    64
datatype theory =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    65
  Theory of {
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    66
    sign: Sign.sg,
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    67
    oraopt: (Sign.sg * exn -> term) option,
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    68
    new_axioms: term Symtab.table,
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    69
    parents: theory list};
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    70
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    71
fun rep_theory (Theory args) = args;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    72
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    73
(*errors involving theories*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    74
exception THEORY of string * theory list;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    75
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    76
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    77
val sign_of = #sign o rep_theory;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    78
val syn_of = #syn o Sign.rep_sg o sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    79
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    80
(*stamps associated with a theory*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    81
val stamps_of_thy = #stamps o Sign.rep_sg o sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    82
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    83
(*return the immediate ancestors*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    84
val parents_of = #parents o rep_theory;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    85
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    86
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    87
(*compare theories*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    88
val subthy = Sign.subsig o pairself sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    89
val eq_thy = Sign.eq_sg o pairself sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    90
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    91
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    92
(* the Pure theories *)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    93
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    94
val proto_pure_thy =
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    95
  Theory {sign = Sign.proto_pure, oraopt = None, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    96
	  new_axioms = Symtab.null, parents = []};
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    97
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    98
val pure_thy =
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    99
  Theory {sign = Sign.pure, oraopt = None, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   100
	  new_axioms = Symtab.null, parents = []};
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   101
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   102
val cpure_thy =
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   103
  Theory {sign = Sign.cpure, oraopt = None, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   104
	  new_axioms = Symtab.null, parents = []};
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   105
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   106
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   107
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   108
(** extend theory **)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   109
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   110
fun err_dup_axms names =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   111
  error ("Duplicate axiom name(s) " ^ commas_quote names);
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   112
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   113
fun ext_thy (thy as Theory {sign, oraopt, new_axioms, parents}) 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   114
            sign1 new_axms =
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   115
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   116
    val draft = Sign.is_draft sign;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   117
    val new_axioms1 =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   118
      Symtab.extend_new (if draft then new_axioms else Symtab.null, new_axms)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   119
        handle Symtab.DUPS names => err_dup_axms names;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   120
    val parents1 = if draft then parents else [thy];
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   121
  in
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   122
    Theory {sign = sign1, oraopt = oraopt, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   123
	    new_axioms = new_axioms1, parents = parents1}
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   124
  end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   125
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   126
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   127
(* extend signature of a theory *)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   128
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   129
fun ext_sg extfun decls (thy as Theory {sign, ...}) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   130
  ext_thy thy (extfun decls sign) [];
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   131
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   132
val add_classes   = ext_sg Sign.add_classes;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   133
val add_classrel  = ext_sg Sign.add_classrel;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   134
val add_defsort   = ext_sg Sign.add_defsort;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   135
val add_types     = ext_sg Sign.add_types;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   136
val add_tyabbrs   = ext_sg Sign.add_tyabbrs;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   137
val add_tyabbrs_i = ext_sg Sign.add_tyabbrs_i;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   138
val add_arities   = ext_sg Sign.add_arities;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   139
val add_consts    = ext_sg Sign.add_consts;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   140
val add_consts_i  = ext_sg Sign.add_consts_i;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   141
val add_syntax    = ext_sg Sign.add_syntax;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   142
val add_syntax_i  = ext_sg Sign.add_syntax_i;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   143
val add_trfuns    = ext_sg Sign.add_trfuns;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   144
val add_trrules   = ext_sg Sign.add_trrules;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   145
val add_trrules_i = ext_sg Sign.add_trrules_i;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   146
val add_thyname   = ext_sg Sign.add_name;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   147
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   148
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   149
(* prepare axioms *)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   150
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   151
fun err_in_axm name =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   152
  error ("The error(s) above occurred in axiom " ^ quote name);
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   153
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   154
fun no_vars tm =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   155
  if null (term_vars tm) andalso null (term_tvars tm) then tm
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   156
  else error "Illegal schematic variable(s) in term";
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   157
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   158
fun cert_axm sg (name, raw_tm) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   159
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   160
    val (t, T, _) = Sign.certify_term sg raw_tm
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   161
      handle TYPE arg => error (Sign.exn_type_msg sg arg)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   162
	   | TERM (msg, _) => error msg;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   163
  in
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   164
    assert (T = propT) "Term not of type prop";
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   165
    (name, no_vars t)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   166
  end
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   167
  handle ERROR => err_in_axm name;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   168
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   169
(*Some duplication of code with read_def_cterm*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   170
fun read_axm sg (name, str) = 
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   171
  let val ts = Syntax.read (#syn (Sign.rep_sg sg)) propT str;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   172
      val (_, t, _) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   173
          Sign.infer_types sg (K None) (K None) [] true (ts,propT);
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   174
  in cert_axm sg (name,t) end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   175
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   176
fun inferT_axm sg (name, pre_tm) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   177
  let val t = #2(Sign.infer_types sg (K None) (K None) [] true
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   178
                                     ([pre_tm], propT))
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   179
  in  (name, no_vars t) end
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   180
  handle ERROR => err_in_axm name;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   181
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   182
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   183
(* extend axioms of a theory *)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   184
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   185
fun ext_axms prep_axm axms (thy as Theory {sign, ...}) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   186
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   187
    val sign1 = Sign.make_draft sign;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   188
    val axioms = map (apsnd (Term.compress_term o Logic.varify) o 
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   189
		      prep_axm sign) 
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   190
	         axms;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   191
  in
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   192
    ext_thy thy sign1 axioms
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   193
  end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   194
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   195
val add_axioms = ext_axms read_axm;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   196
val add_axioms_i = ext_axms cert_axm;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   197
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   198
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   199
(** Set oracle of theory **)
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   200
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   201
fun set_oracle oracle 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   202
               (thy as Theory {sign, oraopt = None, new_axioms, parents}) =
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   203
      if Sign.is_draft sign then
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   204
	Theory {sign = sign, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   205
		oraopt = Some oracle, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   206
		new_axioms = new_axioms, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   207
		parents = parents}
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   208
      else raise THEORY ("Can only set oracle of a draft", [thy])
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   209
  | set_oracle _ thy = raise THEORY ("Oracle already set", [thy]);
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   210
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   211
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   212
(** merge theories **)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   213
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   214
fun merge_thy_list mk_draft thys =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   215
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   216
    fun is_union thy = forall (fn t => subthy (t, thy)) thys;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   217
    val is_draft = Sign.is_draft o sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   218
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   219
    fun add_sign (sg, Theory {sign, ...}) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   220
      Sign.merge (sg, sign) handle TERM (msg, _) => error msg;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   221
  in
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   222
    case (find_first is_union thys, exists is_draft thys) of
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   223
      (Some thy, _) => thy
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   224
    | (None, true) => raise THEORY ("Illegal merge of draft theories", thys)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   225
    | (None, false) => Theory {
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   226
        sign =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   227
          (if mk_draft then Sign.make_draft else I)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   228
          (foldl add_sign (Sign.proto_pure, thys)),
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   229
	oraopt = None,
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   230
        new_axioms = Symtab.null,
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   231
        parents = thys}
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   232
  end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   233
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   234
fun merge_theories (thy1, thy2) = merge_thy_list false [thy1, thy2];
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   235
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   236
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   237
end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   238
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   239
open Theory;