src/Pure/Isar/proof_context.ML
author wenzelm
Mon, 16 Nov 1998 10:45:52 +0100
changeset 5874 a58d4528121d
parent 5819 5fff21d4ca3a
child 5919 a5b2d4b9ed6f
permissions -rw-r--r--
renamed init_context to init; added read_termTs; added declare_thm;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/proof_context.ML
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     4
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     5
Proof context information.
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     6
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     7
TODO:
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     8
  - pretty_bind: use syntax (!?) (show_types etc.);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
     9
  - smash_unifiers: ever invents new vars (???);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    10
*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    11
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    12
(* FIXME tmp *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    13
val proof_debug = ref false;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    14
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    15
signature PROOF_CONTEXT =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    16
sig
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    17
  type context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    18
  exception CONTEXT of string * context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    19
  val theory_of: context -> theory
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    20
  val sign_of: context -> Sign.sg
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    21
  val print_binds: context -> unit
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    22
  val print_thms: context -> unit
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    23
  val print_context: context -> unit
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    24
  val print_proof_data: theory -> unit
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
    25
  val init: theory -> context
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    26
  val read_typ: context -> string -> typ
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    27
  val cert_typ: context -> typ -> typ
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
    28
  val read_termTs: context -> (string * typ) list -> term list * (indexname * typ) list
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    29
  val read_term: context -> string -> term
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    30
  val read_prop: context -> string -> term
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    31
  val read_pat: context -> string -> term
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    32
  val cert_term: context -> term -> term
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    33
  val cert_prop: context -> term -> term
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    34
  val declare_term: term -> context -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    35
  val declare_terms: term list -> context -> context
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
    36
  val declare_thm: thm -> context -> context
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    37
  val add_binds: (indexname * string) list -> context -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    38
  val add_binds_i: (indexname * term) list -> context -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    39
  val match_binds: (string * string) list -> context -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    40
  val match_binds_i: (term * term) list -> context -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    41
  val thms_closure: context -> xstring -> tthm list option
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    42
  val get_tthm: context -> string -> tthm
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    43
  val get_tthms: context -> string -> tthm list
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    44
  val get_tthmss: context -> string list -> tthm list
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    45
  val put_tthm: string * tthm -> context -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    46
  val put_tthms: string * tthm list -> context -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    47
  val put_tthmss: (string * tthm list) list -> context -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    48
  val have_tthms: string -> context attribute list
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    49
    -> (tthm * context attribute list) list -> context -> context * (string * tthm list)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    50
  val assumptions: context -> tthm list
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    51
  val fixed_names: context -> string list
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    52
  val assume: string -> context attribute list -> string list -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    53
    -> context * (string * tthm list)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    54
  val assume_i: string -> context attribute list -> term list -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    55
    -> context * (string * tthm list)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    56
  val fix: (string * string option) list -> context -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    57
  val fix_i: (string * typ) list -> context -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    58
  val setup: (theory -> theory) list
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    59
end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    60
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    61
signature PROOF_CONTEXT_PRIVATE =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    62
sig
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    63
  include PROOF_CONTEXT
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    64
  val init_data: Object.kind -> (theory -> Object.T) * (context -> Object.T -> unit)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    65
    -> theory -> theory
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    66
  val print_data: Object.kind -> context -> unit
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    67
  val get_data: Object.kind -> (Object.T -> 'a) -> context -> 'a
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    68
  val put_data: Object.kind -> ('a -> Object.T) -> 'a -> context -> context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    69
end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    70
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    71
structure ProofContext: PROOF_CONTEXT_PRIVATE =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    72
struct
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    73
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    74
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    75
(** datatype context **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    76
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    77
datatype context =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    78
  Context of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    79
   {thy: theory,                                (*current theory*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    80
    data: Object.T Symtab.table,                (*user data*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    81
    asms:
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    82
      (string * tthm list) list *               (*assumes: A ==> _*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    83
      ((string * string) list * string list),   (*fixes: !!x. _*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    84
    binds: (term * typ) Vartab.table,           (*term bindings*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    85
    thms: tthm list Symtab.table,               (*local thms*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    86
    defs:
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    87
      typ Vartab.table *                        (*type constraints*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    88
      sort Vartab.table *                       (*default sorts*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    89
      int *					(*maxidx*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    90
      string list};                             (*used type variable names*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    91
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    92
exception CONTEXT of string * context;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    93
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    94
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    95
fun make_context (thy, data, asms, binds, thms, defs) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    96
  Context {thy = thy, data = data, asms = asms, binds = binds, thms = thms, defs = defs};
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    97
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    98
fun map_context f (Context {thy, data, asms, binds, thms, defs}) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
    99
  make_context (f (thy, data, asms, binds, thms, defs));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   100
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   101
fun theory_of (Context {thy, ...}) = thy;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   102
val sign_of = Theory.sign_of o theory_of;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   103
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   104
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   105
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   106
(** print context information **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   107
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   108
(* FIXME tmp*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   109
fun debug f x = if ! proof_debug then f x else ();
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   110
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   111
fun print_items prt name items =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   112
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   113
    fun pretty_itms (name, [x]) = Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, prt x]
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   114
      | pretty_itms (name, xs) = Pretty.big_list (name ^ ":") (map prt xs);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   115
  in Pretty.writeln (Pretty.big_list name (map pretty_itms items)) end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   116
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   117
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   118
(* term bindings *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   119
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   120
fun print_binds (Context {thy, binds, ...}) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   121
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   122
    val prt_term = Sign.pretty_term (Theory.sign_of thy);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   123
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   124
    fun fix_var (x, i) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   125
      (case try Syntax.dest_binding x of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   126
        None => Syntax.string_of_vname (x, i)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   127
      | Some x' => if i = 0 then "??" ^ x' else Syntax.string_of_vname (x, i));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   128
    fun pretty_bind (xi, (t, T)) = Pretty.block
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   129
      [Pretty.str (fix_var xi), Pretty.str " ==", Pretty.brk 1, prt_term t];
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   130
  in Pretty.writeln (Pretty.big_list "Term bindings:" (map pretty_bind (Vartab.dest binds))) end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   131
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   132
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   133
(* local theorems *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   134
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   135
fun print_thms (Context {thms, ...}) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   136
  print_items Attribute.pretty_tthm "Local theorems:" (Symtab.dest thms);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   137
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   138
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   139
(* main context *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   140
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   141
fun print_context (ctxt as Context {thy, data = _, asms = (assumes, (fixes, _)), binds = _,
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   142
    thms = _, defs = (types, sorts, maxidx, used)}) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   143
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   144
    val sign = Theory.sign_of thy;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   145
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   146
    val term_of_tthm = #prop o Thm.rep_thm o Attribute.thm_of;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   147
    val prt_term = Sign.pretty_term sign;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   148
    val prt_typ = Sign.pretty_typ sign;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   149
    val prt_sort = Sign.pretty_sort sign;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   150
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   151
    (*theory*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   152
    val pretty_thy = Pretty.block [Pretty.str "Theory:", Pretty.brk 1, Sign.pretty_sg sign];
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   153
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   154
    (*fixes*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   155
    fun prt_fix (x, x') = Pretty.str (x ^ " = " ^ x');
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   156
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   157
    (* defaults *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   158
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   159
    fun prt_atom prt prtT (x, X) = Pretty.block
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   160
      [prt x, Pretty.str " ::", Pretty.brk 1, prtT X];
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   161
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   162
    fun prt_var (x, ~1) = prt_term (Syntax.free x)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   163
      | prt_var xi = prt_term (Syntax.var xi);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   164
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   165
    fun prt_varT (x, ~1) = prt_typ (TFree (x, []))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   166
      | prt_varT xi = prt_typ (TVar (xi, []));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   167
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   168
    val prt_defT = prt_atom prt_var prt_typ;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   169
    val prt_defS = prt_atom prt_varT prt_sort;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   170
  in
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   171
    debug Pretty.writeln pretty_thy;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   172
    Pretty.writeln (Pretty.big_list "Fixed variables:" (map prt_fix (rev fixes)));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   173
    print_items (prt_term o term_of_tthm) "Assumptions:" assumes;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   174
    debug print_binds ctxt;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   175
    debug print_thms ctxt;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   176
    debug Pretty.writeln (Pretty.big_list "Type constraints:" (map prt_defT (Vartab.dest types)));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   177
    debug Pretty.writeln (Pretty.big_list "Default sorts:" (map prt_defS (Vartab.dest sorts)));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   178
    debug writeln ("Maxidx: " ^ string_of_int maxidx);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   179
    debug Pretty.writeln (Pretty.strs ("Used type variable names:" :: used))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   180
  end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   181
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   182
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   183
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   184
(** user data **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   185
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   186
(* errors *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   187
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   188
fun of_theory thy = "\nof theory " ^ Sign.str_of_sg (Theory.sign_of thy);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   189
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   190
fun err_inconsistent kinds =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   191
  error ("Attempt to merge different versions of " ^ commas_quote kinds ^ " proof data");
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   192
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   193
fun err_dup_init thy kind =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   194
  error ("Duplicate initialization of " ^ quote kind ^ " proof data" ^ of_theory thy);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   195
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   196
fun err_undef ctxt kind =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   197
  raise CONTEXT ("Tried to access undefined " ^ quote kind ^ " proof data", ctxt);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   198
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   199
fun err_uninit ctxt kind =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   200
  raise CONTEXT ("Tried to access uninitialized " ^ quote kind ^ " proof data" ^
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   201
    of_theory (theory_of ctxt), ctxt);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   202
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   203
fun err_access ctxt kind =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   204
  raise CONTEXT ("Unauthorized access to " ^ quote kind ^ " proof data" ^
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   205
    of_theory (theory_of ctxt), ctxt);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   206
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   207
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   208
(* data kind 'Isar/proof_data' *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   209
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   210
structure ProofDataDataArgs =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   211
struct
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   212
  val name = "Isar/proof_data";
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   213
  type T = (Object.kind * ((theory -> Object.T) * (context -> Object.T -> unit))) Symtab.table;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   214
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   215
  val empty = Symtab.empty;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   216
  val prep_ext = I;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   217
  fun merge tabs = Symtab.merge (Object.eq_kind o pairself fst) tabs
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   218
    handle Symtab.DUPS kinds => err_inconsistent kinds;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   219
  fun print _ tab = Pretty.writeln (Pretty.strs (map #1 (Symtab.dest tab)));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   220
end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   221
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   222
structure ProofDataData = TheoryDataFun(ProofDataDataArgs);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   223
val print_proof_data = ProofDataData.print;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   224
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   225
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   226
(* init proof data *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   227
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   228
fun init_data kind meths thy =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   229
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   230
    val name = Object.name_of_kind kind;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   231
    val tab = Symtab.update_new ((name, (kind, meths)), ProofDataData.get thy)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   232
      handle Symtab.DUP _ => err_dup_init thy name;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   233
  in thy |> ProofDataData.put tab end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   234
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   235
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   236
(* access data *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   237
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   238
fun lookup_data (ctxt as Context {data, ...}) kind =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   239
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   240
    val thy = theory_of ctxt;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   241
    val name = Object.name_of_kind kind;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   242
  in
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   243
    (case Symtab.lookup (ProofDataData.get thy, name) of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   244
      Some (k, meths) =>
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   245
        if Object.eq_kind (kind, k) then
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   246
          (case Symtab.lookup (data, name) of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   247
            Some x => (x, meths)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   248
          | None => err_undef ctxt name)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   249
        else err_access ctxt name
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   250
    | None => err_uninit ctxt name)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   251
  end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   252
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   253
fun get_data kind f ctxt =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   254
  let val (x, _) = lookup_data ctxt kind
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   255
  in f x handle Match => Object.kind_error kind end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   256
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   257
fun print_data kind ctxt =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   258
  let val (x, (_, prt)) = lookup_data ctxt kind
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   259
  in prt ctxt x end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   260
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   261
fun put_data kind f x ctxt =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   262
  (lookup_data ctxt kind;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   263
    ctxt |> map_context (fn (thy, data, asms, binds, thms, defs) =>
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   264
      (thy, Symtab.update ((Object.name_of_kind kind, f x), data), asms, binds, thms, defs)));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   265
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   266
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   267
(* init context *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   268
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   269
fun init thy =
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   270
  let val data = Symtab.map (fn (_, (f, _)) => f thy) (ProofDataData.get thy) in
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   271
    make_context (thy, data, ([], ([], [])), Vartab.empty, Symtab.empty,
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   272
      (Vartab.empty, Vartab.empty, ~1, []))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   273
  end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   274
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   275
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   276
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   277
(** prepare types **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   278
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   279
fun read_typ (ctxt as Context {defs = (_, sorts, _, _), ...}) s =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   280
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   281
    val sign = sign_of ctxt;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   282
    fun def_sort xi = Vartab.lookup (sorts, xi);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   283
  in
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   284
    transform_error (Sign.read_typ (sign, def_sort)) s
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   285
      handle ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   286
  end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   287
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   288
fun cert_typ ctxt raw_T =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   289
  Sign.certify_typ (sign_of ctxt) raw_T
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   290
    handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   291
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   292
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   293
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   294
(** prepare terms and propositions **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   295
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   296
(*
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   297
  (1) read / certify wrt. signature of context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   298
  (2) intern Skolem constants
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   299
  (3) expand term bindings
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   300
*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   301
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   302
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   303
(* read / certify wrt. signature *)     (*exception ERROR*) (*exception TERM*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   304
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   305
fun read_def_termTs freeze sg (types, sorts, used) sTs =
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   306
  let val (cts, env) = Thm.read_def_cterms (sg, types, sorts) used freeze sTs
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   307
  in (map Thm.term_of cts, env) end;
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   308
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   309
fun read_def_termT freeze sg defs sT = apfst hd (read_def_termTs freeze sg defs [sT]);
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   310
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   311
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   312
fun read_term_sg sg (defs as (_, _, used)) s =
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   313
  #1 (read_def_termT true sg defs (s, TVar ((variant used "'z", 0), logicS)));
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   314
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   315
fun read_prop_sg sg defs s =
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   316
  #1 (read_def_termT true sg defs (s, propT));
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   317
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   318
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   319
fun cert_term_sg sg t = Thm.term_of (Thm.cterm_of sg t);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   320
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   321
fun cert_prop_sg sg tm =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   322
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   323
    val ctm = Thm.cterm_of sg tm;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   324
    val {t, T, ...} = Thm.rep_cterm ctm;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   325
  in
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   326
    if T = propT then t
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   327
    else raise TERM ("Term not of type prop", [t])
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   328
  end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   329
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   330
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   331
(* intern_skolem *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   332
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   333
fun get_skolem (Context {asms = (_, (fixes, _)), ...}) x = assoc (fixes, x);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   334
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   335
fun check_skolem ctxt check x =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   336
  if check andalso can Syntax.dest_skolem x then
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   337
    raise CONTEXT ("Illegal reference to internal Skolem constant: " ^ quote x, ctxt)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   338
  else x;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   339
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   340
fun intern_skolem ctxt check =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   341
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   342
    fun intern (t as Free (x, T)) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   343
          (case get_skolem ctxt (check_skolem ctxt check x) of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   344
            Some x' => Free (x', T)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   345
          | None => t)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   346
      | intern (t $ u) = intern t $ intern u
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   347
      | intern (Abs (x, T, t)) = Abs (x, T, intern t)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   348
      | intern a = a;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   349
  in intern end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   350
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   351
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   352
(* norm_term *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   353
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   354
(*beta normal form for terms (not eta normal form), chase variables in
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   355
  bindings environment (code taken from Pure/envir.ML)*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   356
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   357
fun norm_term (ctxt as Context {binds, ...}) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   358
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   359
    (*raised when norm has no effect on a term, to do sharing instead of copying*)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   360
    exception SAME;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   361
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   362
    fun norm (t as Var (xi, T)) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   363
          (case Vartab.lookup (binds, xi) of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   364
            Some (u, U) =>
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   365
              if T = U then (norm u handle SAME => u)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   366
              else raise TYPE ("norm_term: ill-typed variable assigment", [T, U], [t, u])
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   367
          | None =>
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   368
              if can Syntax.dest_binding (#1 xi) then
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   369
                raise CONTEXT ("Unbound binding: " ^ Syntax.string_of_vname xi, ctxt)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   370
              else raise SAME)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   371
      | norm (Abs (a, T, body)) =  Abs (a, T, norm body)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   372
      | norm (Abs (_, _, body) $ t) = normh (subst_bound (t, body))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   373
      | norm (f $ t) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   374
          ((case norm f of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   375
            Abs (_, _, body) => normh (subst_bound (t, body))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   376
          | nf => nf $ (norm t handle SAME => t)) handle SAME => f $ norm t)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   377
      | norm _ =  raise SAME
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   378
    and normh t = norm t handle SAME => t
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   379
  in normh end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   380
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   381
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   382
(* read terms *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   383
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   384
fun gen_read read app is_pat (ctxt as Context {binds, defs = (types, sorts, _, used), ...}) s =
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   385
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   386
    val sign = sign_of ctxt;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   387
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   388
    fun def_type xi =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   389
      (case Vartab.lookup (types, xi) of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   390
        None => if is_pat then None else apsome #2 (Vartab.lookup (binds, xi))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   391
      | some => some);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   392
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   393
    fun def_sort xi = Vartab.lookup (sorts, xi);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   394
  in
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   395
    (transform_error (read sign (def_type, def_sort, used)) s
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   396
      handle TERM (msg, _) => raise CONTEXT (msg, ctxt)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   397
      | ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt))
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   398
    |> app (intern_skolem ctxt true)
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   399
    |> app (if is_pat then I else norm_term ctxt)
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   400
  end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   401
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   402
val read_termTs = gen_read (read_def_termTs false) (apfst o map) false;
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   403
val read_term = gen_read read_term_sg I false;
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   404
val read_prop = gen_read read_prop_sg I false;
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   405
val read_pat = gen_read read_term_sg I true;
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   406
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   407
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   408
(* certify terms *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   409
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   410
fun gen_cert cert is_pat ctxt t =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   411
  (cert (sign_of ctxt) t handle TERM (msg, _) => raise CONTEXT (msg, ctxt))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   412
  |> intern_skolem ctxt false
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   413
  |> (if is_pat then I else norm_term ctxt);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   414
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   415
val cert_term = gen_cert cert_term_sg false;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   416
val cert_prop = gen_cert cert_prop_sg false;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   417
val cert_pat = gen_cert cert_term_sg true;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   418
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   419
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   420
(* declare terms *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   421
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   422
val ins_types = foldl_aterms
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   423
  (fn (types, Free (x, T)) => Vartab.update (((x, ~1), T), types)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   424
    | (types, Var v) => Vartab.update (v, types)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   425
    | (types, _) => types);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   426
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   427
val ins_sorts = foldl_types (foldl_atyps
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   428
  (fn (sorts, TFree (x, S)) => Vartab.update (((x, ~1), S), sorts)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   429
    | (sorts, TVar v) => Vartab.update (v, sorts)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   430
    | (sorts, _) => sorts));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   431
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   432
val ins_used = foldl_types (foldl_atyps
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   433
  (fn (used, TFree (x, _)) => x ins used
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   434
    | (used, TVar ((x, _), _)) => x ins used
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   435
    | (used, _) => used));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   436
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   437
fun map_defaults f = map_context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   438
  (fn (thy, data, asms, binds, thms, defs) => (thy, data, asms, binds, thms, f defs));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   439
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   440
fun declare (ctxt, t) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   441
  ctxt
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   442
  |> map_defaults (fn (types, sorts, maxidx, used) => (ins_types (types, t), sorts, maxidx, used))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   443
  |> map_defaults (fn (types, sorts, maxidx, used) => (types, ins_sorts (sorts, t), maxidx, used))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   444
  |> map_defaults (fn (types, sorts, maxidx, used) => (types, sorts, maxidx, ins_used (used, t)))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   445
  |> map_defaults (fn (types, sorts, maxidx, used) =>
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   446
      (types, sorts, Int.max (maxidx, Term.maxidx_of_term t), used));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   447
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   448
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   449
fun declare_term t ctxt = declare (ctxt, t);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   450
fun declare_terms ts ctxt = foldl declare (ctxt, ts);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   451
5874
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   452
fun declare_thm thm ctxt =
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   453
  let val {prop, hyps, ...} = Thm.rep_thm thm
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   454
  in ctxt |> declare_terms (prop :: hyps) end;
a58d4528121d renamed init_context to init;
wenzelm
parents: 5819
diff changeset
   455
5819
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   456
fun prep_declare prep (ctxt, s) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   457
  let val t = prep ctxt s
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   458
  in (ctxt |> declare_term t, t) end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   459
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   460
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   461
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   462
(** bindings **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   463
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   464
(* update_binds *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   465
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   466
fun upd_bind (ctxt, (xi, t)) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   467
  let val T = fastype_of t in
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   468
    ctxt
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   469
    |> declare_term t
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   470
    |> map_context (fn (thy, data, asms, binds, thms, defs) =>
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   471
        (thy, data, asms, Vartab.update ((xi, (t, T)), binds), thms, defs))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   472
  end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   473
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   474
fun update_binds bs ctxt = foldl upd_bind (ctxt, bs);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   475
fun update_binds_env env = update_binds (Envir.alist_of env);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   476
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   477
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   478
(* add_binds(_i) -- sequential *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   479
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   480
fun gen_bind prep (ctxt, (xi as (x, _), raw_t)) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   481
  let val t = prep ctxt raw_t in
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   482
    if can Syntax.dest_binding x then ctxt |> update_binds [(xi, t)]
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   483
    else raise CONTEXT ("Illegal variable name for term binding: " ^
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   484
      quote (Syntax.string_of_vname xi), ctxt)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   485
  end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   486
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   487
fun gen_binds prep binds ctxt = foldl (gen_bind prep) (ctxt, binds);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   488
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   489
val add_binds = gen_binds read_term;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   490
val add_binds_i = gen_binds cert_term;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   491
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   492
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   493
(* match_binds(_i) -- parallel *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   494
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   495
fun prep_pair prep_pat prep (ctxt, (raw_pat, raw_t)) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   496
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   497
    val pat = prep_pat ctxt raw_pat;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   498
    val (ctxt', t) = prep_declare prep (ctxt, raw_t);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   499
  in (ctxt', (pat, t)) end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   500
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   501
fun gen_match_binds prep_pat prep raw_pairs ctxt =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   502
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   503
    val (ctxt', pairs) = foldl_map (prep_pair prep_pat prep) (ctxt, raw_pairs);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   504
    val Context {defs = (_, _, maxidx, _), ...} = ctxt';
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   505
    val envs = Unify.smash_unifiers (sign_of ctxt', Envir.empty maxidx, pairs);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   506
    val env =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   507
      (case Seq.pull envs of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   508
        None => raise CONTEXT ("Pattern match failed!", ctxt')
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   509
      | Some (env, _) => env);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   510
  in ctxt' |> update_binds_env env end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   511
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   512
val match_binds = gen_match_binds read_pat read_term;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   513
val match_binds_i = gen_match_binds cert_pat cert_term;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   514
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   515
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   516
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   517
(** theorems **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   518
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   519
(* thms_closure *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   520
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   521
fun thms_closure (Context {thy, thms, ...}) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   522
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   523
    val global_closure = PureThy.thms_closure thy;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   524
    fun get name =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   525
      (case global_closure name of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   526
        None => Symtab.lookup (thms, name)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   527
      | some => some);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   528
  in get end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   529
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   530
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   531
(* get_tthm(s) *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   532
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   533
fun get_tthm (ctxt as Context {thy, thms, ...}) name =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   534
  (case Symtab.lookup (thms, name) of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   535
    Some [th] => th
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   536
  | Some _ => raise CONTEXT ("Single theorem expected: " ^ quote name, ctxt)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   537
  | None => (PureThy.get_tthm thy name handle THEORY (msg, _) => raise CONTEXT (msg, ctxt)));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   538
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   539
fun get_tthms (ctxt as Context {thy, thms, ...}) name =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   540
  (case Symtab.lookup (thms, name) of
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   541
    Some ths => ths
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   542
  | None => (PureThy.get_tthms thy name handle THEORY (msg, _) => raise CONTEXT (msg, ctxt)));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   543
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   544
fun get_tthmss ctxt names = flat (map (get_tthms ctxt) names);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   545
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   546
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   547
(* put_tthm(s) *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   548
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   549
fun put_tthms (name, ths) = map_context
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   550
  (fn (thy, data, asms, binds, thms, defs) =>
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   551
    (thy, data, asms, binds, Symtab.update ((name, ths), thms), defs));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   552
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   553
fun put_tthm (name, th) = put_tthms (name, [th]);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   554
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   555
fun put_tthmss [] ctxt = ctxt
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   556
  | put_tthmss (th :: ths) ctxt = ctxt |> put_tthms th |> put_tthmss ths;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   557
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   558
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   559
(* have_tthms *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   560
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   561
fun have_tthms name more_attrs ths_attrs ctxt =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   562
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   563
    fun app ((ct, ths), (th, attrs)) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   564
      let val (ct', th') = Attribute.apply ((ct, th), attrs @ more_attrs)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   565
      in (ct', th' :: ths) end
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   566
    val (ctxt', rev_thms) = foldl app ((ctxt, []), ths_attrs);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   567
    val thms = rev rev_thms;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   568
  in (ctxt' |> put_tthms (name, thms), (name, thms)) end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   569
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   570
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   571
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   572
(** assumptions **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   573
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   574
(* get assumptions *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   575
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   576
fun assumptions (Context {asms = (asms, _), ...}) = flat (map #2 asms);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   577
fun fixed_names (Context {asms = (_, (fixes, _)), ...}) = map #2 fixes;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   578
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   579
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   580
(* assume *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   581
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   582
fun gen_assume prep name attrs raw_props ctxt =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   583
  let
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   584
    val (ctxt', props) = foldl_map prep (ctxt, raw_props);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   585
    val sign = sign_of ctxt';
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   586
    val ths = map (fn t => ((Thm.assume (Thm.cterm_of sign t), []), [])) props;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   587
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   588
    val (ctxt'', (_, tthms)) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   589
      ctxt'
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   590
      |> have_tthms name (Attribute.tag_assumption :: attrs) ths
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   591
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   592
    val ctxt''' =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   593
      ctxt''
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   594
      |> map_context (fn (thy, data, (assumes, fixes), binds, thms, defs) =>
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   595
        (thy, data, (assumes @ [(name, tthms)], fixes), binds, thms, defs));
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   596
  in (ctxt''', (name, tthms)) end;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   597
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   598
val assume = gen_assume (prep_declare read_prop);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   599
val assume_i = gen_assume (prep_declare cert_prop);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   600
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   601
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   602
(* fix *)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   603
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   604
fun read_skolemT (Context {defs = (_, _, _, used), ...}) None = Type.param used ("'z", logicS)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   605
  | read_skolemT ctxt (Some s) = read_typ ctxt s;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   606
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   607
fun gen_fix prep check (ctxt, (x, raw_T)) =
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   608
  ctxt
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   609
  |> declare_term (Free (check_skolem ctxt check x, prep ctxt raw_T))
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   610
  |> map_context (fn (thy, data, (assumes, (fixes, names)), binds, thms, defs) =>
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   611
      let val x' = variant names x in
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   612
        (thy, data, (assumes, ((x, Syntax.skolem x') :: fixes, x' :: names)), binds, thms, defs)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   613
      end);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   614
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   615
fun gen_fixs prep check xs ctxt = foldl (gen_fix prep check) (ctxt, xs);
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   616
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   617
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   618
val fix = gen_fixs read_skolemT true;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   619
val fix_i = gen_fixs cert_typ false;
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   620
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   621
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   622
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   623
(** theory setup **)
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   624
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   625
val setup = [ProofDataData.init];
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   626
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   627
5fff21d4ca3a Proof context information.
wenzelm
parents:
diff changeset
   628
end;