src/Pure/Isar/proof_context.ML
author wenzelm
Fri Oct 22 21:50:12 1999 +0200 (1999-10-22 ago)
changeset 7925 8c50b68b890b
parent 7679 99912beb8fa0
child 7928 06a11f8cf573
permissions -rw-r--r--
warn_extra_tfrees (after declare_term);
wenzelm@5819
     1
(*  Title:      Pure/Isar/proof_context.ML
wenzelm@5819
     2
    ID:         $Id$
wenzelm@5819
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@5819
     4
wenzelm@5819
     5
Proof context information.
wenzelm@5819
     6
*)
wenzelm@5819
     7
wenzelm@5819
     8
signature PROOF_CONTEXT =
wenzelm@5819
     9
sig
wenzelm@5819
    10
  type context
wenzelm@5819
    11
  exception CONTEXT of string * context
wenzelm@5819
    12
  val theory_of: context -> theory
wenzelm@5819
    13
  val sign_of: context -> Sign.sg
wenzelm@7557
    14
  val prems_of: context -> thm list
wenzelm@6985
    15
  val show_hyps: bool ref
wenzelm@6985
    16
  val pretty_thm: thm -> Pretty.T
wenzelm@6528
    17
  val verbose: bool ref
wenzelm@5819
    18
  val print_binds: context -> unit
wenzelm@5819
    19
  val print_thms: context -> unit
wenzelm@7575
    20
  val strings_of_prems: context -> string list
wenzelm@6847
    21
  val strings_of_context: context -> string list
wenzelm@5819
    22
  val print_proof_data: theory -> unit
wenzelm@5874
    23
  val init: theory -> context
wenzelm@5819
    24
  val read_typ: context -> string -> typ
wenzelm@5819
    25
  val cert_typ: context -> typ -> typ
wenzelm@7679
    26
  val cert_skolem: context -> string -> string
wenzelm@5874
    27
  val read_termTs: context -> (string * typ) list -> term list * (indexname * typ) list
wenzelm@5819
    28
  val read_term: context -> string -> term
wenzelm@5819
    29
  val read_prop: context -> string -> term
wenzelm@5935
    30
  val read_term_pat: context -> string -> term
wenzelm@5935
    31
  val read_prop_pat: context -> string -> term
wenzelm@5819
    32
  val cert_term: context -> term -> term
wenzelm@5819
    33
  val cert_prop: context -> term -> term
wenzelm@5819
    34
  val declare_term: term -> context -> context
wenzelm@5819
    35
  val declare_terms: term list -> context -> context
wenzelm@7925
    36
  val warn_extra_tfrees: context -> context -> context
wenzelm@7606
    37
  val add_binds: (indexname * string option) list -> context -> context
wenzelm@7606
    38
  val add_binds_i: (indexname * term option) list -> context -> context
wenzelm@7925
    39
  val auto_bind_goal: term -> context -> context
wenzelm@7925
    40
  val auto_bind_facts: string -> term list -> context -> context
wenzelm@5935
    41
  val match_binds: (string list * string) list -> context -> context
wenzelm@5935
    42
  val match_binds_i: (term list * term) list -> context -> context
wenzelm@7925
    43
  val bind_propps: bool -> (string * (string list * string list)) list
wenzelm@7925
    44
    -> context -> context * term list
wenzelm@7925
    45
  val bind_propps_i: bool -> (term * (term list * term list)) list
wenzelm@7925
    46
    -> context -> context * term list
wenzelm@6091
    47
  val get_thm: context -> string -> thm
wenzelm@6091
    48
  val get_thms: context -> string -> thm list
wenzelm@6091
    49
  val get_thmss: context -> string list -> thm list
wenzelm@6091
    50
  val put_thm: string * thm -> context -> context
wenzelm@6091
    51
  val put_thms: string * thm list -> context -> context
wenzelm@6091
    52
  val put_thmss: (string * thm list) list -> context -> context
wenzelm@7606
    53
  val reset_thms: string -> context -> context
wenzelm@6875
    54
  val have_thmss: thm list -> string -> context attribute list
wenzelm@6091
    55
    -> (thm list * context attribute list) list -> context -> context * (string * thm list)
wenzelm@6931
    56
  val assumptions: context -> (cterm * ((int -> tactic) * (int -> tactic))) list
wenzelm@5819
    57
  val fixed_names: context -> string list
wenzelm@7270
    58
  val assume: ((int -> tactic) * (int -> tactic))
wenzelm@7270
    59
    -> (string * context attribute list * (string * (string list * string list)) list) list
wenzelm@7270
    60
    -> context -> context * ((string * thm list) list * thm list)
wenzelm@7270
    61
  val assume_i: ((int -> tactic) * (int -> tactic))
wenzelm@7270
    62
    -> (string * context attribute list * (term * (term list * term list)) list) list
wenzelm@7270
    63
    -> context -> context * ((string * thm list) list * thm list)
wenzelm@7411
    64
  val fix: (string list * string option) list -> context -> context
wenzelm@7663
    65
  val fix_i: (string list * typ option) list -> context -> context
wenzelm@5819
    66
  val setup: (theory -> theory) list
wenzelm@5819
    67
end;
wenzelm@5819
    68
wenzelm@5819
    69
signature PROOF_CONTEXT_PRIVATE =
wenzelm@5819
    70
sig
wenzelm@5819
    71
  include PROOF_CONTEXT
wenzelm@5819
    72
  val init_data: Object.kind -> (theory -> Object.T) * (context -> Object.T -> unit)
wenzelm@5819
    73
    -> theory -> theory
wenzelm@5819
    74
  val print_data: Object.kind -> context -> unit
wenzelm@5819
    75
  val get_data: Object.kind -> (Object.T -> 'a) -> context -> 'a
wenzelm@5819
    76
  val put_data: Object.kind -> ('a -> Object.T) -> 'a -> context -> context
wenzelm@5819
    77
end;
wenzelm@5819
    78
wenzelm@5819
    79
structure ProofContext: PROOF_CONTEXT_PRIVATE =
wenzelm@5819
    80
struct
wenzelm@5819
    81
wenzelm@5819
    82
wenzelm@5819
    83
(** datatype context **)
wenzelm@5819
    84
wenzelm@5819
    85
datatype context =
wenzelm@5819
    86
  Context of
wenzelm@6847
    87
   {thy: theory,                                                        (*current theory*)
wenzelm@6847
    88
    data: Object.T Symtab.table,                                        (*user data*)
wenzelm@5819
    89
    asms:
wenzelm@7663
    90
      ((cterm * ((int -> tactic) * (int -> tactic))) list *             (*assumes: A ==> _*)
wenzelm@6931
    91
        (string * thm list) list) *
wenzelm@6847
    92
      ((string * string) list * string list),                           (*fixes: !!x. _*)
wenzelm@7606
    93
    binds: (term * typ) option Vartab.table,                            (*term bindings*)
wenzelm@7606
    94
    thms: thm list option Symtab.table,                                 (*local thms*)
wenzelm@5819
    95
    defs:
wenzelm@6847
    96
      typ Vartab.table *                                                (*type constraints*)
wenzelm@6847
    97
      sort Vartab.table *                                               (*default sorts*)
wenzelm@6847
    98
      string list};                                                     (*used type var names*)
wenzelm@5819
    99
wenzelm@5819
   100
exception CONTEXT of string * context;
wenzelm@5819
   101
wenzelm@5819
   102
wenzelm@5819
   103
fun make_context (thy, data, asms, binds, thms, defs) =
wenzelm@5819
   104
  Context {thy = thy, data = data, asms = asms, binds = binds, thms = thms, defs = defs};
wenzelm@5819
   105
wenzelm@5819
   106
fun map_context f (Context {thy, data, asms, binds, thms, defs}) =
wenzelm@5819
   107
  make_context (f (thy, data, asms, binds, thms, defs));
wenzelm@5819
   108
wenzelm@5819
   109
fun theory_of (Context {thy, ...}) = thy;
wenzelm@5819
   110
val sign_of = Theory.sign_of o theory_of;
wenzelm@5819
   111
wenzelm@7270
   112
fun prems_of (Context {asms = ((_, asms), _), ...}) = flat (map #2 asms);
wenzelm@7270
   113
wenzelm@5819
   114
wenzelm@5819
   115
wenzelm@5819
   116
(** print context information **)
wenzelm@5819
   117
wenzelm@6985
   118
val show_hyps = ref false;
wenzelm@7575
   119
wenzelm@7575
   120
fun pretty_thm thm =
wenzelm@7575
   121
  if ! show_hyps then setmp Display.show_hyps true Display.pretty_thm_no_quote thm
wenzelm@7575
   122
  else Display.pretty_cterm (#prop (Thm.crep_thm thm));
wenzelm@6985
   123
wenzelm@6528
   124
val verbose = ref false;
wenzelm@6847
   125
fun verb f x = if ! verbose then f x else [];
wenzelm@6847
   126
val verb_string = verb (Library.single o Pretty.string_of);
wenzelm@5819
   127
wenzelm@6847
   128
fun strings_of_items prt name items =
wenzelm@5819
   129
  let
wenzelm@5819
   130
    fun pretty_itms (name, [x]) = Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, prt x]
wenzelm@5819
   131
      | pretty_itms (name, xs) = Pretty.big_list (name ^ ":") (map prt xs);
wenzelm@6721
   132
  in
wenzelm@6847
   133
    if null items andalso not (! verbose) then []
wenzelm@6847
   134
    else [Pretty.string_of (Pretty.big_list name (map pretty_itms items))]
wenzelm@6721
   135
  end;
wenzelm@5819
   136
wenzelm@5819
   137
wenzelm@5819
   138
(* term bindings *)
wenzelm@5819
   139
wenzelm@7606
   140
val smash_option = fn (_, None) => None | (xi, Some b) => Some (xi, b);
wenzelm@7606
   141
wenzelm@7575
   142
fun strings_of_binds (ctxt as Context {binds, ...}) =
wenzelm@5819
   143
  let
wenzelm@7575
   144
    val prt_term = Sign.pretty_term (sign_of ctxt);
wenzelm@7479
   145
    fun pretty_bind (xi, (t, T)) = prt_term (Logic.mk_equals (Var (xi, T), t));
wenzelm@7606
   146
    val bs = mapfilter smash_option (Vartab.dest binds);
wenzelm@6721
   147
  in
wenzelm@7606
   148
    if null bs andalso not (! verbose) then []
wenzelm@7606
   149
    else [Pretty.string_of (Pretty.big_list "term bindings:" (map pretty_bind bs))]
wenzelm@6721
   150
  end;
wenzelm@5819
   151
wenzelm@6847
   152
val print_binds = seq writeln o strings_of_binds;
wenzelm@6847
   153
wenzelm@5819
   154
wenzelm@5819
   155
(* local theorems *)
wenzelm@5819
   156
wenzelm@6847
   157
fun strings_of_thms (Context {thms, ...}) =
wenzelm@7606
   158
  strings_of_items pretty_thm "local theorems:" (mapfilter smash_option (Symtab.dest thms));
wenzelm@6847
   159
wenzelm@6847
   160
val print_thms = seq writeln o strings_of_thms;
wenzelm@5819
   161
wenzelm@5819
   162
wenzelm@5819
   163
(* main context *)
wenzelm@5819
   164
wenzelm@7575
   165
fun strings_of_prems ctxt =
wenzelm@7575
   166
  (case prems_of ctxt of
wenzelm@7575
   167
    [] => []
wenzelm@7575
   168
  | prems => [Pretty.string_of (Pretty.big_list "prems:" (map pretty_thm prems))]);
wenzelm@7575
   169
wenzelm@7575
   170
fun strings_of_context (ctxt as Context {asms = (_, (fixes, _)),
wenzelm@7670
   171
    defs = (types, sorts, used), ...}) =
wenzelm@5819
   172
  let
wenzelm@7575
   173
    val sign = sign_of ctxt;
wenzelm@5819
   174
wenzelm@5819
   175
    val prt_term = Sign.pretty_term sign;
wenzelm@5819
   176
    val prt_typ = Sign.pretty_typ sign;
wenzelm@5819
   177
    val prt_sort = Sign.pretty_sort sign;
wenzelm@5819
   178
wenzelm@5819
   179
    (*theory*)
wenzelm@5819
   180
    val pretty_thy = Pretty.block [Pretty.str "Theory:", Pretty.brk 1, Sign.pretty_sg sign];
wenzelm@5819
   181
wenzelm@5819
   182
    (*fixes*)
wenzelm@7606
   183
    fun prt_fix (x, x') = Pretty.block
wenzelm@7606
   184
      [prt_term (Syntax.free x), Pretty.str " =", Pretty.brk 1, prt_term (Syntax.free x')];
wenzelm@7606
   185
wenzelm@7575
   186
    fun prt_fixes xs = Pretty.block (Pretty.str "fixed variables:" :: Pretty.brk 1 ::
wenzelm@7606
   187
      Pretty.commas (map prt_fix xs));
wenzelm@7200
   188
wenzelm@5819
   189
wenzelm@5819
   190
    (* defaults *)
wenzelm@5819
   191
wenzelm@5819
   192
    fun prt_atom prt prtT (x, X) = Pretty.block
wenzelm@5819
   193
      [prt x, Pretty.str " ::", Pretty.brk 1, prtT X];
wenzelm@5819
   194
wenzelm@5819
   195
    fun prt_var (x, ~1) = prt_term (Syntax.free x)
wenzelm@5819
   196
      | prt_var xi = prt_term (Syntax.var xi);
wenzelm@5819
   197
wenzelm@5819
   198
    fun prt_varT (x, ~1) = prt_typ (TFree (x, []))
wenzelm@5819
   199
      | prt_varT xi = prt_typ (TVar (xi, []));
wenzelm@5819
   200
wenzelm@5819
   201
    val prt_defT = prt_atom prt_var prt_typ;
wenzelm@5819
   202
    val prt_defS = prt_atom prt_varT prt_sort;
wenzelm@5819
   203
  in
wenzelm@6847
   204
    verb_string pretty_thy @
wenzelm@7575
   205
    (if null fixes then [] else [Pretty.string_of (prt_fixes (rev fixes))]) @
wenzelm@7575
   206
    strings_of_prems ctxt @
wenzelm@6847
   207
    verb strings_of_binds ctxt @
wenzelm@6847
   208
    verb strings_of_thms ctxt @
wenzelm@7575
   209
    verb_string (Pretty.big_list "type constraints:" (map prt_defT (Vartab.dest types))) @
wenzelm@7575
   210
    verb_string (Pretty.big_list "default sorts:" (map prt_defS (Vartab.dest sorts))) @
wenzelm@7575
   211
    verb_string (Pretty.strs ("used type variable names:" :: used))
wenzelm@5819
   212
  end;
wenzelm@5819
   213
wenzelm@5819
   214
wenzelm@5819
   215
wenzelm@5819
   216
(** user data **)
wenzelm@5819
   217
wenzelm@5819
   218
(* errors *)
wenzelm@5819
   219
wenzelm@5819
   220
fun of_theory thy = "\nof theory " ^ Sign.str_of_sg (Theory.sign_of thy);
wenzelm@5819
   221
wenzelm@5819
   222
fun err_inconsistent kinds =
wenzelm@5819
   223
  error ("Attempt to merge different versions of " ^ commas_quote kinds ^ " proof data");
wenzelm@5819
   224
wenzelm@5819
   225
fun err_dup_init thy kind =
wenzelm@5819
   226
  error ("Duplicate initialization of " ^ quote kind ^ " proof data" ^ of_theory thy);
wenzelm@5819
   227
wenzelm@5819
   228
fun err_undef ctxt kind =
wenzelm@5819
   229
  raise CONTEXT ("Tried to access undefined " ^ quote kind ^ " proof data", ctxt);
wenzelm@5819
   230
wenzelm@5819
   231
fun err_uninit ctxt kind =
wenzelm@5819
   232
  raise CONTEXT ("Tried to access uninitialized " ^ quote kind ^ " proof data" ^
wenzelm@5819
   233
    of_theory (theory_of ctxt), ctxt);
wenzelm@5819
   234
wenzelm@5819
   235
fun err_access ctxt kind =
wenzelm@5819
   236
  raise CONTEXT ("Unauthorized access to " ^ quote kind ^ " proof data" ^
wenzelm@5819
   237
    of_theory (theory_of ctxt), ctxt);
wenzelm@5819
   238
wenzelm@5819
   239
wenzelm@5819
   240
(* data kind 'Isar/proof_data' *)
wenzelm@5819
   241
wenzelm@5819
   242
structure ProofDataDataArgs =
wenzelm@5819
   243
struct
wenzelm@5819
   244
  val name = "Isar/proof_data";
wenzelm@5819
   245
  type T = (Object.kind * ((theory -> Object.T) * (context -> Object.T -> unit))) Symtab.table;
wenzelm@5819
   246
wenzelm@5819
   247
  val empty = Symtab.empty;
wenzelm@6550
   248
  val copy = I;
wenzelm@5819
   249
  val prep_ext = I;
wenzelm@5819
   250
  fun merge tabs = Symtab.merge (Object.eq_kind o pairself fst) tabs
wenzelm@5819
   251
    handle Symtab.DUPS kinds => err_inconsistent kinds;
wenzelm@5819
   252
  fun print _ tab = Pretty.writeln (Pretty.strs (map #1 (Symtab.dest tab)));
wenzelm@5819
   253
end;
wenzelm@5819
   254
wenzelm@5819
   255
structure ProofDataData = TheoryDataFun(ProofDataDataArgs);
wenzelm@5819
   256
val print_proof_data = ProofDataData.print;
wenzelm@5819
   257
wenzelm@5819
   258
wenzelm@5819
   259
(* init proof data *)
wenzelm@5819
   260
wenzelm@5819
   261
fun init_data kind meths thy =
wenzelm@5819
   262
  let
wenzelm@5819
   263
    val name = Object.name_of_kind kind;
wenzelm@5819
   264
    val tab = Symtab.update_new ((name, (kind, meths)), ProofDataData.get thy)
wenzelm@5819
   265
      handle Symtab.DUP _ => err_dup_init thy name;
wenzelm@5819
   266
  in thy |> ProofDataData.put tab end;
wenzelm@5819
   267
wenzelm@5819
   268
wenzelm@5819
   269
(* access data *)
wenzelm@5819
   270
wenzelm@5819
   271
fun lookup_data (ctxt as Context {data, ...}) kind =
wenzelm@5819
   272
  let
wenzelm@5819
   273
    val thy = theory_of ctxt;
wenzelm@5819
   274
    val name = Object.name_of_kind kind;
wenzelm@5819
   275
  in
wenzelm@5819
   276
    (case Symtab.lookup (ProofDataData.get thy, name) of
wenzelm@5819
   277
      Some (k, meths) =>
wenzelm@5819
   278
        if Object.eq_kind (kind, k) then
wenzelm@5819
   279
          (case Symtab.lookup (data, name) of
wenzelm@5819
   280
            Some x => (x, meths)
wenzelm@5819
   281
          | None => err_undef ctxt name)
wenzelm@5819
   282
        else err_access ctxt name
wenzelm@5819
   283
    | None => err_uninit ctxt name)
wenzelm@5819
   284
  end;
wenzelm@5819
   285
wenzelm@5819
   286
fun get_data kind f ctxt =
wenzelm@5819
   287
  let val (x, _) = lookup_data ctxt kind
wenzelm@5819
   288
  in f x handle Match => Object.kind_error kind end;
wenzelm@5819
   289
wenzelm@5819
   290
fun print_data kind ctxt =
wenzelm@5819
   291
  let val (x, (_, prt)) = lookup_data ctxt kind
wenzelm@5819
   292
  in prt ctxt x end;
wenzelm@5819
   293
wenzelm@5819
   294
fun put_data kind f x ctxt =
wenzelm@5819
   295
  (lookup_data ctxt kind;
wenzelm@5819
   296
    ctxt |> map_context (fn (thy, data, asms, binds, thms, defs) =>
wenzelm@5819
   297
      (thy, Symtab.update ((Object.name_of_kind kind, f x), data), asms, binds, thms, defs)));
wenzelm@5819
   298
wenzelm@5819
   299
wenzelm@5819
   300
(* init context *)
wenzelm@5819
   301
wenzelm@5874
   302
fun init thy =
wenzelm@5874
   303
  let val data = Symtab.map (fn (_, (f, _)) => f thy) (ProofDataData.get thy) in
wenzelm@6797
   304
    make_context (thy, data, (([], []), ([], [])), Vartab.empty, Symtab.empty,
wenzelm@7670
   305
      (Vartab.empty, Vartab.empty, []))
wenzelm@5819
   306
  end;
wenzelm@5819
   307
wenzelm@5819
   308
wenzelm@7663
   309
(** default sorts and types **)
wenzelm@7663
   310
wenzelm@7670
   311
fun def_sort (Context {defs = (_, sorts, _), ...}) xi = Vartab.lookup (sorts, xi);
wenzelm@7663
   312
wenzelm@7670
   313
fun def_type (Context {binds, defs = (types, _, _), ...}) is_pat xi =
wenzelm@7663
   314
  (case Vartab.lookup (types, xi) of
wenzelm@7663
   315
    None =>
wenzelm@7663
   316
      if is_pat then None
wenzelm@7663
   317
      else (case Vartab.lookup (binds, xi) of Some (Some (_, T)) => Some T | _ => None)
wenzelm@7663
   318
  | some => some);
wenzelm@7663
   319
wenzelm@7663
   320
wenzelm@5819
   321
wenzelm@5819
   322
(** prepare types **)
wenzelm@5819
   323
wenzelm@7663
   324
fun read_typ ctxt s =
wenzelm@7663
   325
  transform_error (Sign.read_typ (sign_of ctxt, def_sort ctxt)) s
wenzelm@7663
   326
    handle ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt);
wenzelm@5819
   327
wenzelm@5819
   328
fun cert_typ ctxt raw_T =
wenzelm@5819
   329
  Sign.certify_typ (sign_of ctxt) raw_T
wenzelm@5819
   330
    handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt);
wenzelm@5819
   331
wenzelm@5819
   332
wenzelm@5819
   333
wenzelm@7679
   334
(** prepare variables **)
wenzelm@7679
   335
wenzelm@7679
   336
fun prep_var prep_typ ctxt (x, T) =
wenzelm@7679
   337
  if not (Syntax.is_identifier x) then
wenzelm@7679
   338
    raise CONTEXT ("Bad variable name: " ^ quote x, ctxt)
wenzelm@7679
   339
  else (x, apsome (prep_typ ctxt) T);
wenzelm@7679
   340
wenzelm@7679
   341
val read_var = prep_var read_typ;
wenzelm@7679
   342
val cert_var = prep_var cert_typ;
wenzelm@7679
   343
wenzelm@7679
   344
wenzelm@7679
   345
(* internalize Skolem constants *)
wenzelm@7679
   346
wenzelm@7679
   347
fun get_skolem (Context {asms = (_, (fixes, _)), ...}) x = assoc (fixes, x);
wenzelm@7679
   348
wenzelm@7679
   349
fun check_skolem ctxt check x =
wenzelm@7679
   350
  if check andalso can Syntax.dest_skolem x then
wenzelm@7679
   351
    raise CONTEXT ("Illegal reference to internal Skolem constant: " ^ quote x, ctxt)
wenzelm@7679
   352
  else x;
wenzelm@7679
   353
wenzelm@7679
   354
fun intern_skolem ctxt check =
wenzelm@7679
   355
  let
wenzelm@7679
   356
    fun intern (t as Free (x, T)) =
wenzelm@7679
   357
          (case get_skolem ctxt (check_skolem ctxt check x) of
wenzelm@7679
   358
            Some x' => Free (x', T)
wenzelm@7679
   359
          | None => t)
wenzelm@7679
   360
      | intern (t $ u) = intern t $ intern u
wenzelm@7679
   361
      | intern (Abs (x, T, t)) = Abs (x, T, intern t)
wenzelm@7679
   362
      | intern a = a;
wenzelm@7679
   363
  in intern end;
wenzelm@7679
   364
wenzelm@7679
   365
fun cert_skolem ctxt x =
wenzelm@7679
   366
  (case get_skolem ctxt x of
wenzelm@7679
   367
    None => raise CONTEXT ("Undeclared variable: " ^ quote x, ctxt)
wenzelm@7679
   368
  | Some x' => x');
wenzelm@7679
   369
wenzelm@7679
   370
wenzelm@5819
   371
(** prepare terms and propositions **)
wenzelm@5819
   372
wenzelm@5819
   373
(*
wenzelm@5819
   374
  (1) read / certify wrt. signature of context
wenzelm@5819
   375
  (2) intern Skolem constants
wenzelm@5819
   376
  (3) expand term bindings
wenzelm@5819
   377
*)
wenzelm@5819
   378
wenzelm@5819
   379
wenzelm@5819
   380
(* read / certify wrt. signature *)     (*exception ERROR*) (*exception TERM*)
wenzelm@5819
   381
wenzelm@5874
   382
fun read_def_termTs freeze sg (types, sorts, used) sTs =
wenzelm@5874
   383
  let val (cts, env) = Thm.read_def_cterms (sg, types, sorts) used freeze sTs
wenzelm@5874
   384
  in (map Thm.term_of cts, env) end;
wenzelm@5874
   385
wenzelm@5874
   386
fun read_def_termT freeze sg defs sT = apfst hd (read_def_termTs freeze sg defs [sT]);
wenzelm@5874
   387
wenzelm@5819
   388
wenzelm@6762
   389
fun read_term_sg freeze sg (defs as (_, _, used)) s =
wenzelm@7505
   390
  #1 (read_def_termT freeze sg defs (s, dummyT));
wenzelm@5819
   391
wenzelm@6762
   392
fun read_prop_sg freeze sg defs s =
wenzelm@6762
   393
  #1 (read_def_termT freeze sg defs (s, propT));
wenzelm@5819
   394
wenzelm@5819
   395
wenzelm@5819
   396
fun cert_term_sg sg t = Thm.term_of (Thm.cterm_of sg t);
wenzelm@5819
   397
wenzelm@5819
   398
fun cert_prop_sg sg tm =
wenzelm@5819
   399
  let
wenzelm@5819
   400
    val ctm = Thm.cterm_of sg tm;
wenzelm@5819
   401
    val {t, T, ...} = Thm.rep_cterm ctm;
wenzelm@5819
   402
  in
wenzelm@5819
   403
    if T = propT then t
wenzelm@5819
   404
    else raise TERM ("Term not of type prop", [t])
wenzelm@5819
   405
  end;
wenzelm@5819
   406
wenzelm@5819
   407
wenzelm@5819
   408
(* norm_term *)
wenzelm@5819
   409
wenzelm@5819
   410
(*beta normal form for terms (not eta normal form), chase variables in
wenzelm@5819
   411
  bindings environment (code taken from Pure/envir.ML)*)
wenzelm@5819
   412
wenzelm@5819
   413
fun norm_term (ctxt as Context {binds, ...}) =
wenzelm@5819
   414
  let
wenzelm@5819
   415
    (*raised when norm has no effect on a term, to do sharing instead of copying*)
wenzelm@5819
   416
    exception SAME;
wenzelm@5819
   417
wenzelm@5819
   418
    fun norm (t as Var (xi, T)) =
wenzelm@5819
   419
          (case Vartab.lookup (binds, xi) of
wenzelm@7606
   420
            Some (Some (u, U)) =>
wenzelm@5819
   421
              if T = U then (norm u handle SAME => u)
wenzelm@5819
   422
              else raise TYPE ("norm_term: ill-typed variable assigment", [T, U], [t, u])
wenzelm@7606
   423
          | _ => raise CONTEXT ("Unbound schematic variable: " ^ Syntax.string_of_vname xi, ctxt))
wenzelm@5819
   424
      | norm (Abs (a, T, body)) =  Abs (a, T, norm body)
wenzelm@5819
   425
      | norm (Abs (_, _, body) $ t) = normh (subst_bound (t, body))
wenzelm@5819
   426
      | norm (f $ t) =
wenzelm@5819
   427
          ((case norm f of
wenzelm@5819
   428
            Abs (_, _, body) => normh (subst_bound (t, body))
wenzelm@5819
   429
          | nf => nf $ (norm t handle SAME => t)) handle SAME => f $ norm t)
wenzelm@5819
   430
      | norm _ =  raise SAME
wenzelm@5819
   431
    and normh t = norm t handle SAME => t
wenzelm@5819
   432
  in normh end;
wenzelm@5819
   433
wenzelm@5819
   434
wenzelm@6550
   435
(* dummy patterns *)
wenzelm@6550
   436
wenzelm@6762
   437
local
wenzelm@6762
   438
wenzelm@6560
   439
fun is_dummy (Const (c, _)) = c = PureThy.dummy_patternN
wenzelm@6550
   440
  | is_dummy _ = false;
wenzelm@6550
   441
wenzelm@6762
   442
fun prep_dummy (i, t) =
wenzelm@6762
   443
  if is_dummy t then (i + 1, Var (("_dummy_", i), Term.fastype_of t)) else (i, t);
wenzelm@6762
   444
wenzelm@6762
   445
in
wenzelm@6762
   446
wenzelm@6762
   447
fun prepare_dummies tm = #2 (Term.foldl_map_aterms prep_dummy (1, tm));
wenzelm@6762
   448
wenzelm@6550
   449
fun reject_dummies ctxt tm =
wenzelm@6550
   450
  if foldl_aterms (fn (ok, t) => ok andalso not (is_dummy t)) (true, tm) then tm
wenzelm@6550
   451
  else raise CONTEXT ("Illegal dummy pattern(s) in term", ctxt);
wenzelm@6550
   452
wenzelm@6762
   453
end;
wenzelm@6550
   454
wenzelm@6550
   455
wenzelm@5819
   456
(* read terms *)
wenzelm@5819
   457
wenzelm@7670
   458
fun gen_read read app is_pat (ctxt as Context {defs = (_, _, used), ...}) s =
wenzelm@7663
   459
  (transform_error (read (sign_of ctxt) (def_type ctxt is_pat, def_sort ctxt, used)) s
wenzelm@7663
   460
    handle TERM (msg, _) => raise CONTEXT (msg, ctxt)
wenzelm@7663
   461
    | ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt))
wenzelm@7663
   462
  |> app (intern_skolem ctxt true)
wenzelm@7663
   463
  |> app (if is_pat then I else norm_term ctxt)
wenzelm@7663
   464
  |> app (if is_pat then prepare_dummies else (reject_dummies ctxt));
wenzelm@5819
   465
wenzelm@5874
   466
val read_termTs = gen_read (read_def_termTs false) (apfst o map) false;
wenzelm@6762
   467
val read_term = gen_read (read_term_sg true) I false;
wenzelm@6762
   468
val read_prop = gen_read (read_prop_sg true) I false;
wenzelm@6762
   469
val read_term_pat = gen_read (read_term_sg false) I true;
wenzelm@6762
   470
val read_prop_pat = gen_read (read_prop_sg false) I true;
wenzelm@5819
   471
wenzelm@5819
   472
wenzelm@5819
   473
(* certify terms *)
wenzelm@5819
   474
wenzelm@5819
   475
fun gen_cert cert is_pat ctxt t =
wenzelm@5819
   476
  (cert (sign_of ctxt) t handle TERM (msg, _) => raise CONTEXT (msg, ctxt))
wenzelm@5819
   477
  |> intern_skolem ctxt false
wenzelm@5819
   478
  |> (if is_pat then I else norm_term ctxt);
wenzelm@5819
   479
wenzelm@5819
   480
val cert_term = gen_cert cert_term_sg false;
wenzelm@5819
   481
val cert_prop = gen_cert cert_prop_sg false;
wenzelm@5935
   482
val cert_term_pat = gen_cert cert_term_sg true;
wenzelm@5935
   483
val cert_prop_pat = gen_cert cert_prop_sg true;
wenzelm@5819
   484
wenzelm@5819
   485
wenzelm@5819
   486
(* declare terms *)
wenzelm@5819
   487
wenzelm@5819
   488
val ins_types = foldl_aterms
wenzelm@5819
   489
  (fn (types, Free (x, T)) => Vartab.update (((x, ~1), T), types)
wenzelm@5819
   490
    | (types, Var v) => Vartab.update (v, types)
wenzelm@5819
   491
    | (types, _) => types);
wenzelm@5819
   492
wenzelm@5819
   493
val ins_sorts = foldl_types (foldl_atyps
wenzelm@5819
   494
  (fn (sorts, TFree (x, S)) => Vartab.update (((x, ~1), S), sorts)
wenzelm@5819
   495
    | (sorts, TVar v) => Vartab.update (v, sorts)
wenzelm@5819
   496
    | (sorts, _) => sorts));
wenzelm@5819
   497
wenzelm@5819
   498
val ins_used = foldl_types (foldl_atyps
wenzelm@5819
   499
  (fn (used, TFree (x, _)) => x ins used
wenzelm@5819
   500
    | (used, TVar ((x, _), _)) => x ins used
wenzelm@5819
   501
    | (used, _) => used));
wenzelm@5819
   502
wenzelm@7663
   503
fun ins_skolem def_ty = foldr
wenzelm@5994
   504
  (fn ((x, x'), types) =>
wenzelm@7663
   505
    (case def_ty x' of
wenzelm@5994
   506
      Some T => Vartab.update (((x, ~1), T), types)
wenzelm@5994
   507
    | None => types));
wenzelm@5994
   508
wenzelm@5819
   509
fun map_defaults f = map_context
wenzelm@5819
   510
  (fn (thy, data, asms, binds, thms, defs) => (thy, data, asms, binds, thms, f defs));
wenzelm@5819
   511
wenzelm@5994
   512
fun declare (ctxt as Context {asms = (_, (fixes, _)), ...}, t) =
wenzelm@5819
   513
  ctxt
wenzelm@7670
   514
  |> map_defaults (fn (types, sorts, used) => (ins_types (types, t), sorts, used))
wenzelm@7670
   515
  |> map_defaults (fn (types, sorts, used) => (types, ins_sorts (sorts, t), used))
wenzelm@7670
   516
  |> map_defaults (fn (types, sorts, used) => (types, sorts, ins_used (used, t)))
wenzelm@7670
   517
  |> map_defaults (fn (types, sorts, used) =>
wenzelm@7670
   518
      (ins_skolem (fn x => Vartab.lookup (types, (x, ~1))) (fixes, types), sorts, used));
wenzelm@5819
   519
wenzelm@5819
   520
wenzelm@5819
   521
fun declare_term t ctxt = declare (ctxt, t);
wenzelm@5819
   522
fun declare_terms ts ctxt = foldl declare (ctxt, ts);
wenzelm@5819
   523
wenzelm@5819
   524
wenzelm@7925
   525
(* warn_extra_tfrees *)
wenzelm@7925
   526
wenzelm@7925
   527
fun warn_extra used1 used2 =
wenzelm@7925
   528
  if used1 = used2 then ()
wenzelm@7925
   529
  else
wenzelm@7925
   530
    (case Library.gen_rems (op =) (used2, used1) of
wenzelm@7925
   531
      [] => ()
wenzelm@7925
   532
    | extras => warning ("Introducing free type variables: " ^ commas extras));
wenzelm@7925
   533
wenzelm@7925
   534
fun warn_extra_tfrees (ctxt1 as Context {defs = (_, _, used1), ...})
wenzelm@7925
   535
    (ctxt2 as Context {defs = (_, _, used2), ...}) = (warn_extra used1 used2; ctxt2);
wenzelm@7925
   536
wenzelm@7925
   537
wenzelm@5819
   538
wenzelm@5819
   539
(** bindings **)
wenzelm@5819
   540
wenzelm@5819
   541
(* update_binds *)
wenzelm@5819
   542
wenzelm@7606
   543
fun del_bind (ctxt, xi) =
wenzelm@7606
   544
  ctxt
wenzelm@7606
   545
  |> map_context (fn (thy, data, asms, binds, thms, defs) =>
wenzelm@7606
   546
      (thy, data, asms, Vartab.update ((xi, None), binds), thms, defs));
wenzelm@7606
   547
wenzelm@5819
   548
fun upd_bind (ctxt, (xi, t)) =
wenzelm@5819
   549
  let val T = fastype_of t in
wenzelm@5819
   550
    ctxt
wenzelm@5819
   551
    |> declare_term t
wenzelm@5819
   552
    |> map_context (fn (thy, data, asms, binds, thms, defs) =>
wenzelm@7606
   553
        (thy, data, asms, Vartab.update ((xi, Some (t, T)), binds), thms, defs))
wenzelm@5819
   554
  end;
wenzelm@5819
   555
wenzelm@7606
   556
fun del_upd_bind (ctxt, (xi, None)) = del_bind (ctxt, xi)
wenzelm@7606
   557
  | del_upd_bind (ctxt, (xi, Some t)) = upd_bind (ctxt, (xi, t));
wenzelm@7606
   558
wenzelm@5819
   559
fun update_binds bs ctxt = foldl upd_bind (ctxt, bs);
wenzelm@7663
   560
fun update_binds_env env =      (*Note: Envir.norm_term ensures proper type instantiation*)
wenzelm@7479
   561
  update_binds (map (apsnd (Envir.norm_term env)) (Envir.alist_of env));
wenzelm@5819
   562
wenzelm@7606
   563
fun delete_update_binds bs ctxt = foldl del_upd_bind (ctxt, bs);
wenzelm@7606
   564
wenzelm@5819
   565
wenzelm@5819
   566
(* add_binds(_i) -- sequential *)
wenzelm@5819
   567
wenzelm@7925
   568
local
wenzelm@7925
   569
wenzelm@5819
   570
fun gen_bind prep (ctxt, (xi as (x, _), raw_t)) =
wenzelm@7606
   571
  ctxt |> delete_update_binds [(xi, apsome (prep ctxt) raw_t)];
wenzelm@5819
   572
wenzelm@7925
   573
fun gen_binds prep binds ctxt =
wenzelm@7925
   574
  warn_extra_tfrees ctxt (foldl (gen_bind prep) (ctxt, binds));
wenzelm@7925
   575
wenzelm@7925
   576
in
wenzelm@5819
   577
wenzelm@5819
   578
val add_binds = gen_binds read_term;
wenzelm@5819
   579
val add_binds_i = gen_binds cert_term;
wenzelm@7925
   580
val auto_bind_goal = add_binds_i o AutoBind.goal;
wenzelm@7925
   581
val auto_bind_facts = add_binds_i oo AutoBind.facts;
wenzelm@7925
   582
wenzelm@7925
   583
end;
wenzelm@5819
   584
wenzelm@5819
   585
wenzelm@5819
   586
(* match_binds(_i) -- parallel *)
wenzelm@5819
   587
wenzelm@5935
   588
fun prep_declare_match (prep_pat, prep) (ctxt, (raw_pats, raw_t)) =
wenzelm@5819
   589
  let
wenzelm@5935
   590
    val t = prep ctxt raw_t;
wenzelm@5994
   591
    val ctxt' = ctxt |> declare_term t;
wenzelm@6931
   592
    val matches = map (fn (f, raw_pat) => (prep_pat ctxt' raw_pat, f t)) raw_pats;
wenzelm@6931
   593
  in (ctxt', (matches, t)) end;
wenzelm@5819
   594
wenzelm@7670
   595
fun maxidx_of_pair (t1, t2) = Int.max (Term.maxidx_of_term t1, Term.maxidx_of_term t2);
wenzelm@7670
   596
wenzelm@5935
   597
fun gen_match_binds _ [] ctxt = ctxt
wenzelm@6931
   598
  | gen_match_binds prepp args ctxt =
wenzelm@5935
   599
      let
wenzelm@6931
   600
        val raw_pairs = map (apfst (map (pair I))) args;
wenzelm@5935
   601
        val (ctxt', matches) = foldl_map (prep_declare_match prepp) (ctxt, raw_pairs);
wenzelm@5935
   602
        val pairs = flat (map #1 matches);
wenzelm@7670
   603
        val maxidx = foldl (fn (i, p) => Int.max (i, maxidx_of_pair p)) (~1, pairs);
wenzelm@5935
   604
        val envs = Unify.smash_unifiers (sign_of ctxt', Envir.empty maxidx, pairs);
wenzelm@5935
   605
        val env =
wenzelm@5935
   606
          (case Seq.pull envs of
wenzelm@5935
   607
            None => raise CONTEXT ("Pattern match failed!", ctxt')
wenzelm@5935
   608
          | Some (env, _) => env);
wenzelm@7925
   609
      in ctxt' |> update_binds_env env |> warn_extra_tfrees ctxt end;
wenzelm@5935
   610
wenzelm@5935
   611
val match_binds = gen_match_binds (read_term_pat, read_term);
wenzelm@5935
   612
val match_binds_i = gen_match_binds (cert_term_pat, cert_term);
wenzelm@5935
   613
wenzelm@5935
   614
wenzelm@5935
   615
(* bind proposition patterns *)
wenzelm@5935
   616
wenzelm@7925
   617
local
wenzelm@7925
   618
wenzelm@6931
   619
fun gen_bind_propp prepp (ctxt, (raw_prop, (raw_pats1, raw_pats2))) =
wenzelm@6931
   620
  let
wenzelm@6931
   621
    val raw_pats = map (pair I) raw_pats1 @ map (pair Logic.strip_imp_concl) raw_pats2;
wenzelm@6931
   622
    val (ctxt', (pairs, prop)) = prep_declare_match prepp (ctxt, (raw_pats, raw_prop));
wenzelm@5935
   623
  in (ctxt' |> match_binds_i (map (apfst single) pairs), prop) end;
wenzelm@5935
   624
wenzelm@7925
   625
fun gen_bind_propps prepp warn args ctxt =
wenzelm@7925
   626
  apfst (if warn then warn_extra_tfrees ctxt else I)
wenzelm@7925
   627
    (foldl_map (gen_bind_propp prepp) (ctxt, args));
wenzelm@5819
   628
wenzelm@7925
   629
in
wenzelm@6789
   630
wenzelm@7925
   631
val bind_propps = gen_bind_propps (read_prop_pat, read_prop);
wenzelm@7925
   632
val bind_propps_i = gen_bind_propps (cert_prop_pat, cert_prop);
wenzelm@7925
   633
wenzelm@7925
   634
end;
wenzelm@6789
   635
wenzelm@6789
   636
wenzelm@5819
   637
wenzelm@5819
   638
(** theorems **)
wenzelm@5819
   639
wenzelm@6091
   640
(* get_thm(s) *)
wenzelm@5819
   641
wenzelm@6091
   642
fun get_thm (ctxt as Context {thy, thms, ...}) name =
wenzelm@5819
   643
  (case Symtab.lookup (thms, name) of
wenzelm@7606
   644
    Some (Some [th]) => th
wenzelm@7606
   645
  | Some (Some _) => raise CONTEXT ("Single theorem expected: " ^ quote name, ctxt)
wenzelm@7606
   646
  | _ => (PureThy.get_thm thy name handle THEORY (msg, _) => raise CONTEXT (msg, ctxt)));
wenzelm@5819
   647
wenzelm@6091
   648
fun get_thms (ctxt as Context {thy, thms, ...}) name =
wenzelm@5819
   649
  (case Symtab.lookup (thms, name) of
wenzelm@7606
   650
    Some (Some ths) => ths
wenzelm@7606
   651
  | _ => (PureThy.get_thms thy name handle THEORY (msg, _) => raise CONTEXT (msg, ctxt)));
wenzelm@5819
   652
wenzelm@6091
   653
fun get_thmss ctxt names = flat (map (get_thms ctxt) names);
wenzelm@5819
   654
wenzelm@5819
   655
wenzelm@6091
   656
(* put_thm(s) *)
wenzelm@5819
   657
wenzelm@7479
   658
fun put_thms ("", _) = I
wenzelm@7479
   659
  | put_thms (name, ths) = map_context
wenzelm@7479
   660
      (fn (thy, data, asms, binds, thms, defs) =>
wenzelm@7606
   661
        (thy, data, asms, binds, Symtab.update ((name, Some ths), thms), defs));
wenzelm@5819
   662
wenzelm@6091
   663
fun put_thm (name, th) = put_thms (name, [th]);
wenzelm@5819
   664
wenzelm@6091
   665
fun put_thmss [] ctxt = ctxt
wenzelm@6091
   666
  | put_thmss (th :: ths) ctxt = ctxt |> put_thms th |> put_thmss ths;
wenzelm@5819
   667
wenzelm@5819
   668
wenzelm@7606
   669
(* reset_thms *)
wenzelm@7606
   670
wenzelm@7606
   671
fun reset_thms name = map_context (fn (thy, data, asms, binds, thms, defs) =>
wenzelm@7606
   672
  (thy, data, asms, binds, Symtab.update ((name, None), thms), defs));
wenzelm@7606
   673
wenzelm@7606
   674
wenzelm@6091
   675
(* have_thmss *)
wenzelm@5819
   676
wenzelm@6875
   677
fun have_thmss more_ths name more_attrs ths_attrs ctxt =
wenzelm@5819
   678
  let
wenzelm@5819
   679
    fun app ((ct, ths), (th, attrs)) =
wenzelm@6091
   680
      let val (ct', th') = Thm.applys_attributes ((ct, th), attrs @ more_attrs)
wenzelm@5819
   681
      in (ct', th' :: ths) end
wenzelm@5819
   682
    val (ctxt', rev_thms) = foldl app ((ctxt, []), ths_attrs);
wenzelm@6875
   683
    val thms = flat (rev rev_thms) @ more_ths;
wenzelm@6091
   684
  in (ctxt' |> put_thms (name, thms), (name, thms)) end;
wenzelm@5819
   685
wenzelm@5819
   686
wenzelm@5819
   687
wenzelm@5819
   688
(** assumptions **)
wenzelm@5819
   689
wenzelm@5819
   690
(* get assumptions *)
wenzelm@5819
   691
wenzelm@6847
   692
fun assumptions (Context {asms = ((asms, _), _), ...}) = asms;
wenzelm@5819
   693
fun fixed_names (Context {asms = (_, (fixes, _)), ...}) = map #2 fixes;
wenzelm@5819
   694
wenzelm@5819
   695
wenzelm@5819
   696
(* assume *)
wenzelm@5819
   697
wenzelm@7270
   698
local
wenzelm@6797
   699
wenzelm@7270
   700
fun gen_assm prepp tac (ctxt, (name, attrs, raw_prop_pats)) =
wenzelm@5819
   701
  let
wenzelm@7925
   702
    val (ctxt', props) = prepp true raw_prop_pats ctxt;
wenzelm@5819
   703
wenzelm@7575
   704
    val cprops = map (Thm.cterm_of (sign_of ctxt')) props;
wenzelm@6847
   705
    val cprops_tac = map (rpair tac) cprops;
wenzelm@7670
   706
    val asms = map (Drule.forall_elim_vars 0 o Drule.assume_goal) cprops;
wenzelm@5919
   707
wenzelm@5919
   708
    val ths = map (fn th => ([th], [])) asms;
wenzelm@6091
   709
    val (ctxt'', (_, thms)) =
wenzelm@5819
   710
      ctxt'
wenzelm@6797
   711
      |> auto_bind_facts name props
wenzelm@6875
   712
      |> have_thmss [] name (attrs @ [Drule.tag_assumption]) ths;
wenzelm@5819
   713
wenzelm@5819
   714
    val ctxt''' =
wenzelm@5819
   715
      ctxt''
wenzelm@6797
   716
      |> map_context (fn (thy, data, ((asms_ct, asms_th), fixes), binds, thms, defs) =>
wenzelm@6847
   717
        (thy, data, ((asms_ct @ cprops_tac, asms_th @ [(name, asms)]), fixes), binds, thms, defs));
wenzelm@7270
   718
  in (ctxt''', (name, thms)) end;
wenzelm@7270
   719
wenzelm@7270
   720
fun gen_assms prepp tac args ctxt =
wenzelm@7270
   721
  let val (ctxt', thmss) = foldl_map (gen_assm prepp tac) (ctxt, args)
wenzelm@7270
   722
  in (ctxt', (thmss, prems_of ctxt')) end;
wenzelm@5819
   723
wenzelm@7270
   724
in
wenzelm@7270
   725
wenzelm@7925
   726
val assume = gen_assms bind_propps;
wenzelm@7925
   727
val assume_i = gen_assms bind_propps_i;
wenzelm@7270
   728
wenzelm@7270
   729
end;
wenzelm@5819
   730
wenzelm@5819
   731
wenzelm@5819
   732
(* fix *)
wenzelm@5819
   733
wenzelm@7679
   734
fun gen_fix prep_var check (ctxt, (x, raw_T)) =
wenzelm@7486
   735
  (check_skolem ctxt check x;
wenzelm@7486
   736
    ctxt
wenzelm@7679
   737
    |> (case snd (prep_var ctxt (x, raw_T)) of None => I | Some T => declare_term (Free (x, T)))
wenzelm@7486
   738
    |> map_context (fn (thy, data, (assumes, (fixes, names)), binds, thms, defs) =>
wenzelm@5819
   739
      let val x' = variant names x in
wenzelm@5819
   740
        (thy, data, (assumes, ((x, Syntax.skolem x') :: fixes, x' :: names)), binds, thms, defs)
wenzelm@7486
   741
      end));
wenzelm@5819
   742
wenzelm@7679
   743
fun dist_vars ctxt (xs, T) =
wenzelm@7679
   744
  (case Library.duplicates xs of
wenzelm@7679
   745
    [] => map (rpair T) xs
wenzelm@7679
   746
  | dups => raise CONTEXT ("Duplicate variable names in declaration: " ^ commas_quote dups, ctxt));
wenzelm@5819
   747
wenzelm@7679
   748
fun gen_fixs prep check vars ctxt =
wenzelm@7679
   749
  foldl (gen_fix prep check) (ctxt, flat (map (dist_vars ctxt) vars));
wenzelm@7679
   750
wenzelm@7679
   751
val fix = gen_fixs read_var true;
wenzelm@7679
   752
val fix_i = gen_fixs cert_var false;
wenzelm@5819
   753
wenzelm@6895
   754
wenzelm@5819
   755
wenzelm@5819
   756
(** theory setup **)
wenzelm@5819
   757
wenzelm@5819
   758
val setup = [ProofDataData.init];
wenzelm@5819
   759
wenzelm@5819
   760
wenzelm@5819
   761
end;