src/Pure/theory.ML
author paulson
Fri, 29 Nov 1996 18:03:21 +0100
changeset 2284 80ebd1a213fd
parent 2206 a9419797e196
child 2359 97b88cafe1e8
permissions -rw-r--r--
Swapped arguments of Crypt (for clarity and because it is conventional)
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
2206
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
    39
  val add_modesyntax	: string -> (string * string * mixfix) list -> theory -> theory
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
    40
  val add_modesyntax_i	: string -> (string * typ * mixfix) list -> theory -> theory
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    41
  val add_trfuns	:
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    42
    (string * (Syntax.ast list -> Syntax.ast)) list *
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    43
    (string * (term list -> term)) list *
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    44
    (string * (term list -> term)) list *
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    45
    (string * (Syntax.ast list -> Syntax.ast)) list -> theory -> theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    46
  val add_trrules     : (string * string)Syntax.trrule list -> theory -> theory
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    47
  val add_trrules_i	: Syntax.ast Syntax.trrule list -> theory -> theory
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    48
  val cert_axm          : Sign.sg -> string * term -> string * term
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    49
  val read_axm          : Sign.sg -> string * string -> string * term
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    50
  val inferT_axm        : Sign.sg -> string * term -> string * term
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    51
  val add_axioms	: (string * string) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    52
  val add_axioms_i	: (string * term) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    53
  val add_thyname	: string -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    54
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    55
  val set_oracle	: (Sign.sg * exn -> term) -> theory -> theory
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    56
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    57
  val merge_theories    : theory * theory -> theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    58
  val merge_thy_list    : bool -> theory list -> theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    59
end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    60
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    61
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    62
structure Theory : THEORY =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    63
struct
2206
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
    64
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
    65
(** datatype theory **)
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    66
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    67
datatype theory =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    68
  Theory of {
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    69
    sign: Sign.sg,
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    70
    oraopt: (Sign.sg * exn -> term) option,
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    71
    new_axioms: term Symtab.table,
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    72
    parents: theory list};
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    73
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    74
fun rep_theory (Theory args) = args;
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
(*errors involving theories*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    77
exception THEORY of string * theory list;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    78
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
val sign_of = #sign o rep_theory;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    81
val syn_of = #syn 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
(*stamps associated with a theory*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    84
val stamps_of_thy = #stamps o Sign.rep_sg o sign_of;
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
(*return the immediate ancestors*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    87
val parents_of = #parents o rep_theory;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    88
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    89
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    90
(*compare theories*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    91
val subthy = Sign.subsig o pairself sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    92
val eq_thy = Sign.eq_sg o pairself sign_of;
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
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    95
(* the Pure theories *)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    96
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    97
val proto_pure_thy =
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    98
  Theory {sign = Sign.proto_pure, oraopt = None, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    99
	  new_axioms = Symtab.null, parents = []};
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   100
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   101
val pure_thy =
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   102
  Theory {sign = Sign.pure, oraopt = None, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   103
	  new_axioms = Symtab.null, parents = []};
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   104
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   105
val cpure_thy =
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   106
  Theory {sign = Sign.cpure, oraopt = None, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   107
	  new_axioms = Symtab.null, parents = []};
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   108
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
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   111
(** extend theory **)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   112
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   113
fun err_dup_axms names =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   114
  error ("Duplicate axiom name(s) " ^ commas_quote names);
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   115
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   116
fun ext_thy (thy as Theory {sign, oraopt, new_axioms, parents}) 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   117
            sign1 new_axms =
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   118
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   119
    val draft = Sign.is_draft sign;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   120
    val new_axioms1 =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   121
      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
   122
        handle Symtab.DUPS names => err_dup_axms names;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   123
    val parents1 = if draft then parents else [thy];
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   124
  in
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   125
    Theory {sign = sign1, oraopt = oraopt, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   126
	    new_axioms = new_axioms1, parents = parents1}
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   127
  end;
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
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   130
(* extend signature of a theory *)
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
fun ext_sg extfun decls (thy as Theory {sign, ...}) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   133
  ext_thy thy (extfun decls sign) [];
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   134
2206
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   135
val add_classes      = ext_sg Sign.add_classes;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   136
val add_classrel     = ext_sg Sign.add_classrel;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   137
val add_defsort      = ext_sg Sign.add_defsort;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   138
val add_types        = ext_sg Sign.add_types;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   139
val add_tyabbrs      = ext_sg Sign.add_tyabbrs;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   140
val add_tyabbrs_i    = ext_sg Sign.add_tyabbrs_i;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   141
val add_arities      = ext_sg Sign.add_arities;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   142
val add_consts       = ext_sg Sign.add_consts;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   143
val add_consts_i     = ext_sg Sign.add_consts_i;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   144
val add_syntax       = ext_sg Sign.add_syntax;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   145
val add_syntax_i     = ext_sg Sign.add_syntax_i;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   146
val add_modesyntax   = curry (ext_sg Sign.add_modesyntax);
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   147
val add_modesyntax_i = curry (ext_sg Sign.add_modesyntax_i);
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   148
val add_trfuns       = ext_sg Sign.add_trfuns;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   149
val add_trrules      = ext_sg Sign.add_trrules;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   150
val add_trrules_i    = ext_sg Sign.add_trrules_i;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   151
val add_thyname      = ext_sg Sign.add_name;
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   152
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
(* prepare axioms *)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   155
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   156
fun err_in_axm name =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   157
  error ("The error(s) above occurred in axiom " ^ quote name);
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   158
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   159
fun no_vars tm =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   160
  if null (term_vars tm) andalso null (term_tvars tm) then tm
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   161
  else error "Illegal schematic variable(s) in term";
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   162
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   163
fun cert_axm sg (name, raw_tm) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   164
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   165
    val (t, T, _) = Sign.certify_term sg raw_tm
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   166
      handle TYPE arg => error (Sign.exn_type_msg sg arg)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   167
	   | TERM (msg, _) => error msg;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   168
  in
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   169
    assert (T = propT) "Term not of type prop";
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   170
    (name, no_vars t)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   171
  end
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   172
  handle ERROR => err_in_axm name;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   173
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   174
(*Some duplication of code with read_def_cterm*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   175
fun read_axm sg (name, str) = 
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   176
  let val ts = Syntax.read (#syn (Sign.rep_sg sg)) propT str;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   177
      val (_, t, _) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   178
          Sign.infer_types sg (K None) (K None) [] true (ts,propT);
1960
ae390b599213 Improved error handling: if there are syntax or type-checking
paulson
parents: 1539
diff changeset
   179
  in cert_axm sg (name,t) end
ae390b599213 Improved error handling: if there are syntax or type-checking
paulson
parents: 1539
diff changeset
   180
  handle ERROR => err_in_axm name;
1526
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
fun inferT_axm sg (name, pre_tm) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   183
  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
   184
                                     ([pre_tm], propT))
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   185
  in  (name, no_vars t) end
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   186
  handle ERROR => err_in_axm name;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   187
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   188
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   189
(* extend axioms of a theory *)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   190
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   191
fun ext_axms prep_axm axms (thy as Theory {sign, ...}) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   192
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   193
    val sign1 = Sign.make_draft sign;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   194
    val axioms = map (apsnd (Term.compress_term o Logic.varify) o 
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   195
		      prep_axm sign) 
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   196
	         axms;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   197
  in
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   198
    ext_thy thy sign1 axioms
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   199
  end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   200
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   201
val add_axioms = ext_axms read_axm;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   202
val add_axioms_i = ext_axms cert_axm;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   203
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   204
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   205
(** Set oracle of theory **)
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   206
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   207
fun set_oracle oracle 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   208
               (thy as Theory {sign, oraopt = None, new_axioms, parents}) =
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   209
      if Sign.is_draft sign then
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   210
	Theory {sign = sign, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   211
		oraopt = Some oracle, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   212
		new_axioms = new_axioms, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   213
		parents = parents}
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   214
      else raise THEORY ("Can only set oracle of a draft", [thy])
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   215
  | set_oracle _ thy = raise THEORY ("Oracle already set", [thy]);
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   216
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   217
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   218
(** merge theories **)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   219
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   220
fun merge_thy_list mk_draft thys =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   221
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   222
    fun is_union thy = forall (fn t => subthy (t, thy)) thys;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   223
    val is_draft = Sign.is_draft o sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   224
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   225
    fun add_sign (sg, Theory {sign, ...}) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   226
      Sign.merge (sg, sign) handle TERM (msg, _) => error msg;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   227
  in
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   228
    case (find_first is_union thys, exists is_draft thys) of
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   229
      (Some thy, _) => thy
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   230
    | (None, true) => raise THEORY ("Illegal merge of draft theories", thys)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   231
    | (None, false) => Theory {
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   232
        sign =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   233
          (if mk_draft then Sign.make_draft else I)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   234
          (foldl add_sign (Sign.proto_pure, thys)),
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   235
	oraopt = None,
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   236
        new_axioms = Symtab.null,
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   237
        parents = thys}
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   238
  end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   239
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   240
fun merge_theories (thy1, thy2) = merge_thy_list false [thy1, thy2];
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   241
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   242
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   243
end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   244
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   245
open Theory;