src/HOL/Tools/Metis/metis_translate.ML
author blanchet
Tue May 31 16:38:36 2011 +0200 (2011-05-31)
changeset 43091 b0b30df60056
parent 43090 f6331d785128
child 43092 93ec303e1917
permissions -rw-r--r--
tuning
blanchet@39958
     1
(*  Title:      HOL/Tools/Metis/metis_translate.ML
blanchet@38027
     2
    Author:     Jia Meng, Cambridge University Computer Laboratory and NICTA
blanchet@39497
     3
    Author:     Kong W. Susanto, Cambridge University Computer Laboratory
blanchet@39497
     4
    Author:     Lawrence C. Paulson, Cambridge University Computer Laboratory
blanchet@36393
     5
    Author:     Jasmin Blanchette, TU Muenchen
paulson@15347
     6
blanchet@39494
     7
Translation of HOL to FOL for Metis.
paulson@15347
     8
*)
paulson@15347
     9
blanchet@39494
    10
signature METIS_TRANSLATE =
wenzelm@24310
    11
sig
blanchet@43085
    12
  type type_literal = ATP_Translate.type_literal
blanchet@37577
    13
blanchet@43087
    14
  datatype mode = FO | HO | FT | New
blanchet@43085
    15
blanchet@40157
    16
  type metis_problem =
blanchet@39497
    17
    {axioms: (Metis_Thm.thm * thm) list,
blanchet@39497
    18
     tfrees: type_literal list,
blanchet@39886
    19
     old_skolems: (string * term) list}
blanchet@39497
    20
blanchet@42098
    21
  val metis_generated_var_prefix : string
blanchet@39896
    22
  val new_skolem_const_prefix : string
blanchet@37618
    23
  val num_type_args: theory -> string -> int
blanchet@40259
    24
  val new_skolem_var_name_from_const : string -> string
blanchet@39886
    25
  val reveal_old_skolem_terms : (string * term) list -> term -> term
blanchet@39497
    26
  val string_of_mode : mode -> string
blanchet@40157
    27
  val prepare_metis_problem :
blanchet@43091
    28
    Proof.context -> mode -> thm list -> thm list list -> mode * metis_problem
wenzelm@24310
    29
end
paulson@15347
    30
blanchet@39494
    31
structure Metis_Translate : METIS_TRANSLATE =
paulson@15347
    32
struct
paulson@15347
    33
blanchet@43085
    34
open ATP_Translate
paulson@15347
    35
blanchet@43085
    36
val metis_generated_var_prefix = "_"
quigley@17150
    37
blanchet@37618
    38
(* The number of type arguments of a constant, zero if it's monomorphic. For
blanchet@37618
    39
   (instances of) Skolem pseudoconstants, this information is encoded in the
blanchet@37618
    40
   constant name. *)
blanchet@37618
    41
fun num_type_args thy s =
blanchet@39896
    42
  if String.isPrefix skolem_const_prefix s then
blanchet@39499
    43
    s |> space_explode Long_Name.separator |> List.last |> Int.fromString |> the
blanchet@37618
    44
  else
blanchet@37618
    45
    (s, Sign.the_const_type thy s) |> Sign.const_typargs thy |> length
quigley@17150
    46
blanchet@40259
    47
fun new_skolem_var_name_from_const s =
blanchet@40145
    48
  let val ss = s |> space_explode Long_Name.separator in
blanchet@40259
    49
    nth ss (length ss - 2)
blanchet@40145
    50
  end
blanchet@39886
    51
blanchet@40145
    52
fun predicate_of thy ((@{const Not} $ P), pos) = predicate_of thy (P, not pos)
blanchet@40145
    53
  | predicate_of thy (t, pos) =
blanchet@40145
    54
    (combterm_from_term thy [] (Envir.eta_contract t), pos)
blanchet@37577
    55
blanchet@40145
    56
fun literals_of_term1 args thy (@{const Trueprop} $ P) =
blanchet@40145
    57
    literals_of_term1 args thy P
blanchet@40145
    58
  | literals_of_term1 args thy (@{const HOL.disj} $ P $ Q) =
blanchet@40145
    59
    literals_of_term1 (literals_of_term1 args thy P) thy Q
blanchet@40145
    60
  | literals_of_term1 (lits, ts) thy P =
blanchet@40145
    61
    let val ((pred, ts'), pol) = predicate_of thy (P, true) in
blanchet@43085
    62
      ((pol, pred) :: lits, union (op =) ts ts')
blanchet@37577
    63
    end
blanchet@37577
    64
val literals_of_term = literals_of_term1 ([], [])
blanchet@37577
    65
blanchet@39896
    66
fun old_skolem_const_name i j num_T_args =
blanchet@39896
    67
  old_skolem_const_prefix ^ Long_Name.separator ^
wenzelm@41491
    68
  (space_implode Long_Name.separator (map string_of_int [i, j, num_T_args]))
blanchet@37577
    69
blanchet@39886
    70
fun conceal_old_skolem_terms i old_skolems t =
blanchet@39953
    71
  if exists_Const (curry (op =) @{const_name Meson.skolem} o fst) t then
blanchet@37577
    72
    let
blanchet@39886
    73
      fun aux old_skolems
blanchet@39953
    74
             (t as (Const (@{const_name Meson.skolem}, Type (_, [_, T])) $ _)) =
blanchet@37577
    75
          let
blanchet@39886
    76
            val (old_skolems, s) =
blanchet@37577
    77
              if i = ~1 then
blanchet@39886
    78
                (old_skolems, @{const_name undefined})
blanchet@39886
    79
              else case AList.find (op aconv) old_skolems t of
blanchet@39886
    80
                s :: _ => (old_skolems, s)
blanchet@37577
    81
              | [] =>
blanchet@37577
    82
                let
blanchet@39896
    83
                  val s = old_skolem_const_name i (length old_skolems)
blanchet@39896
    84
                                                (length (Term.add_tvarsT T []))
blanchet@39886
    85
                in ((s, t) :: old_skolems, s) end
blanchet@39886
    86
          in (old_skolems, Const (s, T)) end
blanchet@39886
    87
        | aux old_skolems (t1 $ t2) =
blanchet@37577
    88
          let
blanchet@39886
    89
            val (old_skolems, t1) = aux old_skolems t1
blanchet@39886
    90
            val (old_skolems, t2) = aux old_skolems t2
blanchet@39886
    91
          in (old_skolems, t1 $ t2) end
blanchet@39886
    92
        | aux old_skolems (Abs (s, T, t')) =
blanchet@39886
    93
          let val (old_skolems, t') = aux old_skolems t' in
blanchet@39886
    94
            (old_skolems, Abs (s, T, t'))
blanchet@37577
    95
          end
blanchet@39886
    96
        | aux old_skolems t = (old_skolems, t)
blanchet@39886
    97
    in aux old_skolems t end
blanchet@37577
    98
  else
blanchet@39886
    99
    (old_skolems, t)
blanchet@37577
   100
blanchet@39886
   101
fun reveal_old_skolem_terms old_skolems =
blanchet@37632
   102
  map_aterms (fn t as Const (s, _) =>
blanchet@39896
   103
                 if String.isPrefix old_skolem_const_prefix s then
blanchet@39886
   104
                   AList.lookup (op =) old_skolems s |> the
blanchet@37632
   105
                   |> map_types Type_Infer.paramify_vars
blanchet@37632
   106
                 else
blanchet@37632
   107
                   t
blanchet@37632
   108
               | t => t)
blanchet@37632
   109
blanchet@37577
   110
blanchet@39497
   111
(* ------------------------------------------------------------------------- *)
blanchet@39497
   112
(* HOL to FOL  (Isabelle to Metis)                                           *)
blanchet@39497
   113
(* ------------------------------------------------------------------------- *)
blanchet@39497
   114
blanchet@43087
   115
(* first-order, higher-order, fully-typed, new *)
blanchet@43087
   116
datatype mode = FO | HO | FT | New
blanchet@39497
   117
blanchet@39497
   118
fun string_of_mode FO = "FO"
blanchet@39497
   119
  | string_of_mode HO = "HO"
blanchet@39497
   120
  | string_of_mode FT = "FT"
blanchet@43087
   121
  | string_of_mode New = "New"
blanchet@39497
   122
blanchet@42745
   123
fun fn_isa_to_met_sublevel "equal" = "c_fequal"
blanchet@41139
   124
  | fn_isa_to_met_sublevel "c_False" = "c_fFalse"
blanchet@41139
   125
  | fn_isa_to_met_sublevel "c_True" = "c_fTrue"
blanchet@41139
   126
  | fn_isa_to_met_sublevel "c_Not" = "c_fNot"
blanchet@41139
   127
  | fn_isa_to_met_sublevel "c_conj" = "c_fconj"
blanchet@41139
   128
  | fn_isa_to_met_sublevel "c_disj" = "c_fdisj"
blanchet@41139
   129
  | fn_isa_to_met_sublevel "c_implies" = "c_fimplies"
blanchet@39497
   130
  | fn_isa_to_met_sublevel x = x
blanchet@42758
   131
blanchet@39497
   132
fun fn_isa_to_met_toplevel "equal" = "="
blanchet@39497
   133
  | fn_isa_to_met_toplevel x = x
blanchet@39497
   134
blanchet@39497
   135
fun metis_lit b c args = (b, (c, args));
blanchet@39497
   136
blanchet@42562
   137
fun metis_term_from_typ (Type (s, Ts)) =
blanchet@42562
   138
    Metis_Term.Fn (make_fixed_type_const s, map metis_term_from_typ Ts)
blanchet@42562
   139
  | metis_term_from_typ (TFree (s, _)) =
blanchet@42562
   140
    Metis_Term.Fn (make_fixed_type_var s, [])
blanchet@42562
   141
  | metis_term_from_typ (TVar (x, _)) =
blanchet@42562
   142
    Metis_Term.Var (make_schematic_type_var x)
blanchet@39497
   143
blanchet@39497
   144
(*These two functions insert type literals before the real literals. That is the
blanchet@39497
   145
  opposite order from TPTP linkup, but maybe OK.*)
blanchet@39497
   146
blanchet@39497
   147
fun hol_term_to_fol_FO tm =
blanchet@39497
   148
  case strip_combterm_comb tm of
blanchet@42562
   149
      (CombConst ((c, _), _, Ts), tms) =>
blanchet@42562
   150
        let val tyargs = map metis_term_from_typ Ts
blanchet@42562
   151
            val args = map hol_term_to_fol_FO tms
blanchet@39497
   152
        in Metis_Term.Fn (c, tyargs @ args) end
blanchet@39497
   153
    | (CombVar ((v, _), _), []) => Metis_Term.Var v
blanchet@39497
   154
    | _ => raise Fail "non-first-order combterm"
blanchet@39497
   155
blanchet@42562
   156
fun hol_term_to_fol_HO (CombConst ((a, _), _, Ts)) =
blanchet@42562
   157
      Metis_Term.Fn (fn_isa_to_met_sublevel a, map metis_term_from_typ Ts)
blanchet@39497
   158
  | hol_term_to_fol_HO (CombVar ((s, _), _)) = Metis_Term.Var s
blanchet@39497
   159
  | hol_term_to_fol_HO (CombApp (tm1, tm2)) =
blanchet@39497
   160
       Metis_Term.Fn (".", map hol_term_to_fol_HO [tm1, tm2]);
blanchet@39497
   161
blanchet@39497
   162
(*The fully-typed translation, to avoid type errors*)
blanchet@42562
   163
fun tag_with_type tm T =
blanchet@42562
   164
  Metis_Term.Fn (type_tag_name, [tm, metis_term_from_typ T])
blanchet@39497
   165
blanchet@41138
   166
fun hol_term_to_fol_FT (CombVar ((s, _), ty)) =
blanchet@41138
   167
    tag_with_type (Metis_Term.Var s) ty
blanchet@41138
   168
  | hol_term_to_fol_FT (CombConst ((a, _), ty, _)) =
blanchet@41138
   169
    tag_with_type (Metis_Term.Fn (fn_isa_to_met_sublevel a, [])) ty
blanchet@41138
   170
  | hol_term_to_fol_FT (tm as CombApp (tm1,tm2)) =
blanchet@41138
   171
    tag_with_type (Metis_Term.Fn (".", map hol_term_to_fol_FT [tm1, tm2]))
blanchet@41138
   172
                  (combtyp_of tm)
blanchet@39497
   173
blanchet@43085
   174
fun hol_literal_to_fol FO (pos, tm) =
blanchet@42562
   175
      let
blanchet@42562
   176
        val (CombConst((p, _), _, Ts), tms) = strip_combterm_comb tm
blanchet@42562
   177
        val tylits = if p = "equal" then [] else map metis_term_from_typ Ts
blanchet@42562
   178
        val lits = map hol_term_to_fol_FO tms
blanchet@39497
   179
      in metis_lit pos (fn_isa_to_met_toplevel p) (tylits @ lits) end
blanchet@43085
   180
  | hol_literal_to_fol HO (pos, tm) =
blanchet@39497
   181
     (case strip_combterm_comb tm of
blanchet@39497
   182
          (CombConst(("equal", _), _, _), tms) =>
blanchet@39497
   183
            metis_lit pos "=" (map hol_term_to_fol_HO tms)
blanchet@39497
   184
        | _ => metis_lit pos "{}" [hol_term_to_fol_HO tm])   (*hBOOL*)
blanchet@43085
   185
  | hol_literal_to_fol FT (pos, tm) =
blanchet@39497
   186
     (case strip_combterm_comb tm of
blanchet@39497
   187
          (CombConst(("equal", _), _, _), tms) =>
blanchet@39497
   188
            metis_lit pos "=" (map hol_term_to_fol_FT tms)
blanchet@39497
   189
        | _ => metis_lit pos "{}" [hol_term_to_fol_FT tm])   (*hBOOL*);
blanchet@39497
   190
blanchet@40145
   191
fun literals_of_hol_term thy mode t =
blanchet@40145
   192
  let val (lits, types_sorts) = literals_of_term thy t in
blanchet@40145
   193
    (map (hol_literal_to_fol mode) lits, types_sorts)
blanchet@40145
   194
  end
blanchet@39497
   195
blanchet@39497
   196
(*Sign should be "true" for conjecture type constraints, "false" for type lits in clauses.*)
blanchet@39497
   197
fun metis_of_type_literals pos (TyLitVar ((s, _), (s', _))) =
blanchet@39497
   198
    metis_lit pos s [Metis_Term.Var s']
blanchet@39497
   199
  | metis_of_type_literals pos (TyLitFree ((s, _), (s', _))) =
blanchet@39497
   200
    metis_lit pos s [Metis_Term.Fn (s',[])]
blanchet@39497
   201
blanchet@42352
   202
fun has_default_sort _ (TVar _) = false
blanchet@42352
   203
  | has_default_sort ctxt (TFree (x, s)) =
blanchet@42352
   204
    (s = the_default [] (Variable.def_sort ctxt (x, ~1)));
blanchet@39497
   205
blanchet@39497
   206
fun metis_of_tfree tf =
blanchet@39497
   207
  Metis_Thm.axiom (Metis_LiteralSet.singleton (metis_of_type_literals true tf));
blanchet@39497
   208
blanchet@43090
   209
fun hol_thm_to_fol is_conjecture ctxt mode j old_skolems th =
blanchet@39497
   210
  let
wenzelm@42361
   211
    val thy = Proof_Context.theory_of ctxt
blanchet@39886
   212
    val (old_skolems, (mlits, types_sorts)) =
blanchet@39888
   213
     th |> prop_of |> Logic.strip_imp_concl
blanchet@39888
   214
        |> conceal_old_skolem_terms j old_skolems
blanchet@40145
   215
        ||> (HOLogic.dest_Trueprop #> literals_of_hol_term thy mode)
blanchet@39497
   216
  in
blanchet@39497
   217
    if is_conjecture then
blanchet@39497
   218
      (Metis_Thm.axiom (Metis_LiteralSet.fromList mlits),
blanchet@43085
   219
       raw_type_literals_for_types types_sorts, old_skolems)
blanchet@39497
   220
    else
blanchet@39497
   221
      let
blanchet@42352
   222
        val tylits = types_sorts |> filter_out (has_default_sort ctxt)
blanchet@43085
   223
                                 |> raw_type_literals_for_types
blanchet@43090
   224
        val mtylits = map (metis_of_type_literals false) tylits
blanchet@39497
   225
      in
blanchet@39497
   226
        (Metis_Thm.axiom (Metis_LiteralSet.fromList(mtylits @ mlits)), [],
blanchet@39886
   227
         old_skolems)
blanchet@39497
   228
      end
blanchet@39497
   229
  end;
blanchet@39497
   230
blanchet@39497
   231
(* ------------------------------------------------------------------------- *)
blanchet@39497
   232
(* Logic maps manage the interface between HOL and first-order logic.        *)
blanchet@39497
   233
(* ------------------------------------------------------------------------- *)
blanchet@39497
   234
blanchet@40157
   235
type metis_problem =
blanchet@39497
   236
  {axioms: (Metis_Thm.thm * thm) list,
blanchet@39497
   237
   tfrees: type_literal list,
blanchet@39886
   238
   old_skolems: (string * term) list}
blanchet@39497
   239
blanchet@39497
   240
fun is_quasi_fol_clause thy =
blanchet@39886
   241
  Meson.is_fol_term thy o snd o conceal_old_skolem_terms ~1 [] o prop_of
blanchet@39497
   242
blanchet@39497
   243
(*Extract TFree constraints from context to include as conjecture clauses*)
blanchet@39497
   244
fun init_tfrees ctxt =
blanchet@39497
   245
  let fun add ((a,i),s) Ts = if i = ~1 then TFree(a,s) :: Ts else Ts in
blanchet@39497
   246
    Vartab.fold add (#2 (Variable.constraints_of ctxt)) []
blanchet@43085
   247
    |> raw_type_literals_for_types
blanchet@39497
   248
  end;
blanchet@39497
   249
blanchet@39497
   250
fun const_in_metis c (pred, tm_list) =
blanchet@39497
   251
  let
blanchet@39497
   252
    fun in_mterm (Metis_Term.Var _) = false
blanchet@41156
   253
      | in_mterm (Metis_Term.Fn (nm, tm_list)) =
blanchet@41156
   254
        c = nm orelse exists in_mterm tm_list
blanchet@41156
   255
  in c = pred orelse exists in_mterm tm_list end
blanchet@39497
   256
blanchet@39497
   257
(* ARITY CLAUSE *)
blanchet@39497
   258
fun m_arity_cls (TConsLit ((c, _), (t, _), args)) =
blanchet@39497
   259
    metis_lit true c [Metis_Term.Fn(t, map (Metis_Term.Var o fst) args)]
blanchet@39497
   260
  | m_arity_cls (TVarLit ((c, _), (s, _))) =
blanchet@39497
   261
    metis_lit false c [Metis_Term.Var s]
blanchet@39497
   262
(*TrueI is returned as the Isabelle counterpart because there isn't any.*)
blanchet@43086
   263
fun arity_cls ({prem_lits, concl_lits, ...} : arity_clause) =
blanchet@39497
   264
  (TrueI,
blanchet@42895
   265
   Metis_Thm.axiom (Metis_LiteralSet.fromList
blanchet@42895
   266
                        (map m_arity_cls (concl_lits :: prem_lits))));
blanchet@39497
   267
blanchet@39497
   268
(* CLASSREL CLAUSE *)
blanchet@39497
   269
fun m_class_rel_cls (subclass, _) (superclass, _) =
blanchet@43091
   270
  [metis_lit false subclass [Metis_Term.Var "T"],
blanchet@43091
   271
   metis_lit true superclass [Metis_Term.Var "T"]]
blanchet@43086
   272
fun class_rel_cls ({subclass, superclass, ...} : class_rel_clause) =
blanchet@43091
   273
  (TrueI, m_class_rel_cls subclass superclass
blanchet@43091
   274
          |> Metis_LiteralSet.fromList |> Metis_Thm.axiom)
blanchet@39497
   275
blanchet@39497
   276
fun type_ext thy tms =
blanchet@43091
   277
  let
blanchet@43091
   278
    val subs = tfree_classes_of_terms tms
blanchet@43091
   279
    val supers = tvar_classes_of_terms tms
blanchet@43091
   280
    val tycons = type_consts_of_terms thy tms
blanchet@43091
   281
    val (supers', arity_clauses) = make_arity_clauses thy tycons supers
blanchet@43091
   282
    val class_rel_clauses = make_class_rel_clauses thy subs supers'
blanchet@43091
   283
  in map class_rel_cls class_rel_clauses @ map arity_cls arity_clauses end
blanchet@39497
   284
blanchet@39497
   285
(* Function to generate metis clauses, including comb and type clauses *)
blanchet@43091
   286
fun prepare_metis_problem ctxt New conj_clauses fact_clausess =
blanchet@43091
   287
    let
blanchet@43091
   288
      val x = 1
blanchet@43091
   289
    in
blanchet@43091
   290
      error "Not implemented yet"
blanchet@43091
   291
    end
blanchet@43091
   292
  | prepare_metis_problem ctxt mode conj_clauses fact_clausess =
blanchet@43087
   293
    let
blanchet@43087
   294
      val thy = Proof_Context.theory_of ctxt
blanchet@43087
   295
      (* The modes FO and FT are sticky. HO can be downgraded to FO. *)
blanchet@43087
   296
      val mode =
blanchet@43087
   297
        if mode = HO andalso
blanchet@43091
   298
           forall (forall (is_quasi_fol_clause thy))
blanchet@43091
   299
                  (conj_clauses :: fact_clausess) then
blanchet@43087
   300
          FO
blanchet@43087
   301
        else
blanchet@43087
   302
          mode
blanchet@41139
   303
      fun add_thm is_conjecture (isa_ith, metis_ith)
blanchet@40157
   304
                  {axioms, tfrees, old_skolems} : metis_problem =
blanchet@39497
   305
        let
blanchet@39886
   306
          val (mth, tfree_lits, old_skolems) =
blanchet@43090
   307
            hol_thm_to_fol is_conjecture ctxt mode (length axioms) old_skolems
blanchet@43090
   308
                           metis_ith
blanchet@39497
   309
        in
blanchet@43091
   310
          {axioms = (mth, isa_ith) :: axioms,
blanchet@43091
   311
           tfrees = union (op =) tfree_lits tfrees, old_skolems = old_skolems}
blanchet@39497
   312
        end;
blanchet@43091
   313
      fun add_type_thm (ith, mth) {axioms, tfrees, old_skolems} =
blanchet@43091
   314
        {axioms = (mth, ith) :: axioms, tfrees = tfrees,
blanchet@43091
   315
         old_skolems = old_skolems}
blanchet@43091
   316
      fun add_tfrees {axioms, tfrees, old_skolems} =
blanchet@43091
   317
        {axioms =
blanchet@43091
   318
           map (rpair TrueI o metis_of_tfree) (distinct (op =) tfrees) @ axioms,
blanchet@43091
   319
         tfrees = tfrees, old_skolems = old_skolems}
blanchet@43091
   320
      val problem =
blanchet@43091
   321
        {axioms = [], tfrees = init_tfrees ctxt, old_skolems = []}
blanchet@43091
   322
        |> fold (add_thm true o `Meson.make_meta_clause) conj_clauses
blanchet@43091
   323
        |> add_tfrees
blanchet@43091
   324
        |> fold (fold (add_thm false o `Meson.make_meta_clause)) fact_clausess
blanchet@43091
   325
      val clause_lists = map (Metis_Thm.clause o #1) (#axioms problem)
blanchet@39497
   326
      fun is_used c =
blanchet@39497
   327
        exists (Metis_LiteralSet.exists (const_in_metis c o #2)) clause_lists
blanchet@43091
   328
      val problem =
blanchet@39497
   329
        if mode = FO then
blanchet@43091
   330
          problem
blanchet@39497
   331
        else
blanchet@39497
   332
          let
blanchet@41156
   333
            val fdefs = @{thms fFalse_def fTrue_def fNot_def fconj_def fdisj_def
blanchet@41156
   334
                               fimplies_def fequal_def}
blanchet@41139
   335
            val prepare_helper =
blanchet@41139
   336
              zero_var_indexes
blanchet@41139
   337
              #> `(Meson.make_meta_clause
blanchet@41139
   338
                   #> rewrite_rule (map safe_mk_meta_eq fdefs))
blanchet@39497
   339
            val helper_ths =
blanchet@43085
   340
              helper_table
blanchet@42561
   341
              |> filter (is_used o prefix const_prefix o fst)
blanchet@42894
   342
              |> maps (fn (_, (needs_full_types, thms)) =>
blanchet@41140
   343
                          if needs_full_types andalso mode <> FT then []
blanchet@41140
   344
                          else map prepare_helper thms)
blanchet@43091
   345
          in problem |> fold (add_thm false) helper_ths end
blanchet@43091
   346
      val type_ths =
blanchet@43091
   347
        type_ext thy (maps (map prop_of) (conj_clauses :: fact_clausess))
blanchet@43091
   348
    in (mode, fold add_type_thm type_ths problem) end
blanchet@39497
   349
paulson@15347
   350
end;