src/Pure/Isar/element.ML
author wenzelm
Tue, 09 Oct 2007 00:20:13 +0200
changeset 24920 2a45e400fdad
parent 24637 4d1876424529
child 25202 3a539d9995fb
permissions -rw-r--r--
generic Syntax.pretty/string_of operations;
     1 (*  Title:      Pure/Isar/element.ML
     2     ID:         $Id$
     3     Author:     Makarius
     4 
     5 Explicit data structures for some Isar language elements, with derived
     6 logical operations.
     7 *)
     8 
     9 signature ELEMENT =
    10 sig
    11   datatype ('typ, 'term) stmt =
    12     Shows of ((string * Attrib.src list) * ('term * 'term list) list) list |
    13     Obtains of (string * ((string * 'typ option) list * 'term list)) list
    14   type statement  (*= (string, string) stmt*)
    15   type statement_i  (*= (typ, term) stmt*)
    16   datatype ('typ, 'term, 'fact) ctxt =
    17     Fixes of (string * 'typ option * mixfix) list |
    18     Constrains of (string * 'typ) list |
    19     Assumes of ((string * Attrib.src list) * ('term * 'term list) list) list |
    20     Defines of ((string * Attrib.src list) * ('term * 'term list)) list |
    21     Notes of string * ((string * Attrib.src list) * ('fact * Attrib.src list) list) list
    22   type context (*= (string, string, thmref) ctxt*)
    23   type context_i (*= (typ, term, thm list) ctxt*)
    24   val facts_map: (('typ, 'term, 'fact) ctxt -> ('a, 'b, 'c) ctxt) ->
    25    ((string * Attrib.src list) * ('fact * Attrib.src list) list) list ->
    26    ((string * Attrib.src list) * ('c * Attrib.src list) list) list
    27   val map_ctxt: {name: string -> string,
    28     var: string * mixfix -> string * mixfix,
    29     typ: 'typ -> 'a, term: 'term -> 'b, fact: 'fact -> 'c,
    30     attrib: Attrib.src -> Attrib.src} -> ('typ, 'term, 'fact) ctxt -> ('a, 'b, 'c) ctxt
    31   val map_ctxt_attrib: (Attrib.src -> Attrib.src) ->
    32     ('typ, 'term, 'fact) ctxt -> ('typ, 'term, 'fact) ctxt
    33   val morph_ctxt: morphism -> context_i -> context_i
    34   val params_of: context_i -> (string * typ) list
    35   val prems_of: context_i -> term list
    36   val facts_of: theory -> context_i ->
    37     ((string * Attrib.src list) * (thm list * Attrib.src list) list) list
    38   val pretty_stmt: Proof.context -> statement_i -> Pretty.T list
    39   val pretty_ctxt: Proof.context -> context_i -> Pretty.T list
    40   val pretty_statement: Proof.context -> string -> thm -> Pretty.T
    41   type witness
    42   val map_witness: (term * thm -> term * thm) -> witness -> witness
    43   val morph_witness: morphism -> witness -> witness
    44   val witness_prop: witness -> term
    45   val witness_hyps: witness -> term list
    46   val assume_witness: theory -> term -> witness
    47   val prove_witness: Proof.context -> term -> tactic -> witness
    48   val conclude_witness: witness -> thm
    49   val mark_witness: term -> term
    50   val make_witness: term -> thm -> witness
    51   val dest_witness: witness -> term * thm
    52   val transfer_witness: theory -> witness -> witness
    53   val refine_witness: Proof.state -> Proof.state Seq.seq
    54   val pretty_witness: Proof.context -> witness -> Pretty.T
    55   val rename: (string * (string * mixfix option)) list -> string -> string
    56   val rename_var: (string * (string * mixfix option)) list -> string * mixfix -> string * mixfix
    57   val rename_term: (string * (string * mixfix option)) list -> term -> term
    58   val rename_thm: (string * (string * mixfix option)) list -> thm -> thm
    59   val rename_morphism: (string * (string * mixfix option)) list -> morphism
    60   val instT_type: typ Symtab.table -> typ -> typ
    61   val instT_term: typ Symtab.table -> term -> term
    62   val instT_thm: theory -> typ Symtab.table -> thm -> thm
    63   val instT_morphism: theory -> typ Symtab.table -> morphism
    64   val inst_term: typ Symtab.table * term Symtab.table -> term -> term
    65   val inst_thm: theory -> typ Symtab.table * term Symtab.table -> thm -> thm
    66   val inst_morphism: theory -> typ Symtab.table * term Symtab.table -> morphism
    67   val inst_morphism': theory -> typ Symtab.table * term Symtab.table -> typ Symtab.table * term Symtab.table -> morphism
    68   val satisfy_thm: witness list -> thm -> thm
    69   val satisfy_morphism: witness list -> morphism
    70   val satisfy_facts: witness list ->
    71     ((string * Attrib.src list) * (thm list * Attrib.src list) list) list ->
    72     ((string * Attrib.src list) * (thm list * Attrib.src list) list) list
    73   val generalize_facts: Proof.context -> Proof.context ->
    74     ((string * Attrib.src list) * (thm list * Attrib.src list) list) list ->
    75     ((string * Attrib.src list) * (thm list * Attrib.src list) list) list
    76 end;
    77 
    78 structure Element: ELEMENT =
    79 struct
    80 
    81 (** language elements **)
    82 
    83 (* statement *)
    84 
    85 datatype ('typ, 'term) stmt =
    86   Shows of ((string * Attrib.src list) * ('term * 'term list) list) list |
    87   Obtains of (string * ((string * 'typ option) list * 'term list)) list;
    88 
    89 type statement = (string, string) stmt;
    90 type statement_i = (typ, term) stmt;
    91 
    92 
    93 (* context *)
    94 
    95 datatype ('typ, 'term, 'fact) ctxt =
    96   Fixes of (string * 'typ option * mixfix) list |
    97   Constrains of (string * 'typ) list |
    98   Assumes of ((string * Attrib.src list) * ('term * 'term list) list) list |
    99   Defines of ((string * Attrib.src list) * ('term * 'term list)) list |
   100   Notes of string * ((string * Attrib.src list) * ('fact * Attrib.src list) list) list;
   101 
   102 type context = (string, string, thmref) ctxt;
   103 type context_i = (typ, term, thm list) ctxt;
   104 
   105 fun facts_map f facts = Notes ("", facts) |> f |> (fn Notes (_, facts') => facts');
   106 
   107 fun map_ctxt {name, var, typ, term, fact, attrib} =
   108   fn Fixes fixes => Fixes (fixes |> map (fn (x, T, mx) =>
   109        let val (x', mx') = var (x, mx) in (x', Option.map typ T, mx') end))
   110    | Constrains xs => Constrains (xs |> map (fn (x, T) => (#1 (var (x, NoSyn)), typ T)))
   111    | Assumes asms => Assumes (asms |> map (fn ((a, atts), propps) =>
   112       ((name a, map attrib atts), propps |> map (fn (t, ps) => (term t, map term ps)))))
   113    | Defines defs => Defines (defs |> map (fn ((a, atts), (t, ps)) =>
   114       ((name a, map attrib atts), (term t, map term ps))))
   115    | Notes (kind, facts) => Notes (kind, facts |> map (fn ((a, atts), bs) =>
   116       ((name a, map attrib atts), bs |> map (fn (ths, btts) => (fact ths, map attrib btts)))));
   117 
   118 fun map_ctxt_attrib attrib =
   119   map_ctxt {name = I, var = I, typ = I, term = I, fact = I, attrib = attrib};
   120 
   121 fun morph_ctxt phi = map_ctxt
   122  {name = Morphism.name phi,
   123   var = Morphism.var phi,
   124   typ = Morphism.typ phi,
   125   term = Morphism.term phi,
   126   fact = Morphism.fact phi,
   127   attrib = Args.morph_values phi};
   128 
   129 
   130 (* logical content *)
   131 
   132 fun params_of (Fixes fixes) = fixes |> map
   133     (fn (x, SOME T, _) => (x, T)
   134       | (x, _, _) => raise TERM ("Untyped context element parameter " ^ quote x, []))
   135   | params_of _ = [];
   136 
   137 fun prems_of (Assumes asms) = maps (map fst o snd) asms
   138   | prems_of (Defines defs) = map (fst o snd) defs
   139   | prems_of _ = [];
   140 
   141 fun assume thy t = Assumption.assume (Thm.cterm_of thy t);
   142 
   143 fun facts_of thy (Assumes asms) = map (apsnd (map (fn (t, _) => ([assume thy t], [])))) asms
   144   | facts_of thy (Defines defs) = map (apsnd (fn (t, _) => [([assume thy t], [])])) defs
   145   | facts_of _ (Notes (_, facts)) = facts
   146   | facts_of _ _ = [];
   147 
   148 
   149 
   150 (** pretty printing **)
   151 
   152 fun pretty_items _ _ [] = []
   153   | pretty_items keyword sep (x :: ys) =
   154       Pretty.block [Pretty.keyword keyword, Pretty.brk 1, x] ::
   155         map (fn y => Pretty.block [Pretty.str "  ", Pretty.keyword sep, Pretty.brk 1, y]) ys;
   156 
   157 fun pretty_name_atts ctxt (name, atts) sep =
   158   if name = "" andalso null atts then []
   159   else [Pretty.block
   160     (Pretty.breaks (Pretty.str name :: Attrib.pretty_attribs ctxt atts @ [Pretty.str sep]))];
   161 
   162 
   163 (* pretty_stmt *)
   164 
   165 fun pretty_stmt ctxt =
   166   let
   167     val prt_typ = Pretty.quote o Syntax.pretty_typ ctxt;
   168     val prt_term = Pretty.quote o Syntax.pretty_term ctxt;
   169     val prt_terms = separate (Pretty.keyword "and") o map prt_term;
   170     val prt_name_atts = pretty_name_atts ctxt;
   171 
   172     fun prt_show (a, ts) =
   173       Pretty.block (Pretty.breaks (prt_name_atts a ":" @ prt_terms (map fst ts)));
   174 
   175     fun prt_var (x, SOME T) = Pretty.block [Pretty.str (x ^ " ::"), Pretty.brk 1, prt_typ T]
   176       | prt_var (x, NONE) = Pretty.str x;
   177     val prt_vars =  separate (Pretty.keyword "and") o map prt_var;
   178 
   179     fun prt_obtain (_, ([], ts)) = Pretty.block (Pretty.breaks (prt_terms ts))
   180       | prt_obtain (_, (xs, ts)) = Pretty.block (Pretty.breaks
   181           (prt_vars xs @ [Pretty.keyword "where"] @ prt_terms ts));
   182   in
   183     fn Shows shows => pretty_items "shows" "and" (map prt_show shows)
   184      | Obtains obtains => pretty_items "obtains" "|" (map prt_obtain obtains)
   185   end;
   186 
   187 
   188 (* pretty_ctxt *)
   189 
   190 fun pretty_ctxt ctxt =
   191   let
   192     val prt_typ = Pretty.quote o Syntax.pretty_typ ctxt;
   193     val prt_term = Pretty.quote o Syntax.pretty_term ctxt;
   194     val prt_thm = Pretty.backquote o ProofContext.pretty_thm ctxt;
   195     val prt_name_atts = pretty_name_atts ctxt;
   196 
   197     fun prt_mixfix NoSyn = []
   198       | prt_mixfix mx = [Pretty.brk 2, Syntax.pretty_mixfix mx];
   199 
   200     fun prt_fix (x, SOME T, mx) = Pretty.block (Pretty.str (x ^ " ::") :: Pretty.brk 1 ::
   201           prt_typ T :: Pretty.brk 1 :: prt_mixfix mx)
   202       | prt_fix (x, NONE, mx) = Pretty.block (Pretty.str x :: Pretty.brk 1 :: prt_mixfix mx);
   203     fun prt_constrain (x, T) = prt_fix (x, SOME T, NoSyn);
   204 
   205     fun prt_asm (a, ts) =
   206       Pretty.block (Pretty.breaks (prt_name_atts a ":" @ map (prt_term o fst) ts));
   207     fun prt_def (a, (t, _)) =
   208       Pretty.block (Pretty.breaks (prt_name_atts a ":" @ [prt_term t]));
   209 
   210     fun prt_fact (ths, []) = map prt_thm ths
   211       | prt_fact (ths, atts) = Pretty.enclose "(" ")"
   212           (Pretty.breaks (map prt_thm ths)) :: Attrib.pretty_attribs ctxt atts;
   213     fun prt_note (a, ths) =
   214       Pretty.block (Pretty.breaks (flat (prt_name_atts a "=" :: map prt_fact ths)));
   215   in
   216     fn Fixes fixes => pretty_items "fixes" "and" (map prt_fix fixes)
   217      | Constrains xs => pretty_items "constrains" "and" (map prt_constrain xs)
   218      | Assumes asms => pretty_items "assumes" "and" (map prt_asm asms)
   219      | Defines defs => pretty_items "defines" "and" (map prt_def defs)
   220      | Notes ("", facts) => pretty_items "notes" "and" (map prt_note facts)
   221      | Notes (kind, facts) => pretty_items ("notes " ^ kind) "and" (map prt_note facts)
   222   end;
   223 
   224 
   225 (* pretty_statement *)
   226 
   227 local
   228 
   229 fun thm_name kind th prts =
   230   let val head =
   231     if PureThy.has_name_hint th then
   232       Pretty.block [Pretty.command kind,
   233         Pretty.brk 1, Pretty.str (Sign.base_name (PureThy.get_name_hint th) ^ ":")]
   234     else Pretty.command kind
   235   in Pretty.block (Pretty.fbreaks (head :: prts)) end;
   236 
   237 fun obtain prop ctxt =
   238   let
   239     val ((xs, prop'), ctxt') = Variable.focus prop ctxt;
   240     val As = Logic.strip_imp_prems (Thm.term_of prop');
   241     fun var (x, T) = (ProofContext.revert_skolem ctxt' x, SOME T);
   242   in (("", (map (var o Term.dest_Free o Thm.term_of) xs, As)), ctxt') end;
   243 
   244 in
   245 
   246 fun pretty_statement ctxt kind raw_th =
   247   let
   248     val thy = ProofContext.theory_of ctxt;
   249     val cert = Thm.cterm_of thy;
   250 
   251     val th = MetaSimplifier.norm_hhf raw_th;
   252     val is_elim = ObjectLogic.is_elim th;
   253 
   254     val ((_, [th']), ctxt') = Variable.import_thms true [th] ctxt;
   255     val prop = Thm.prop_of th';
   256     val (prems, concl) = Logic.strip_horn prop;
   257     val concl_term = ObjectLogic.drop_judgment thy concl;
   258 
   259     val fixes = fold_aterms (fn v as Free (x, T) =>
   260         if Variable.newly_fixed ctxt' ctxt x andalso not (v aconv concl_term)
   261         then insert (op =) (x, T) else I | _ => I) prop []
   262       |> rev |> map (apfst (ProofContext.revert_skolem ctxt'));
   263     val (assumes, cases) = take_suffix (fn prem =>
   264       is_elim andalso concl aconv Logic.strip_assums_concl prem) prems;
   265   in
   266     pretty_ctxt ctxt' (Fixes (map (fn (x, T) => (x, SOME T, NoSyn)) fixes)) @
   267     pretty_ctxt ctxt' (Assumes (map (fn t => (("", []), [(t, [])])) assumes)) @
   268     pretty_stmt ctxt'
   269      (if null cases then Shows [(("", []), [(concl, [])])]
   270       else Obtains (#1 (fold_map (obtain o cert) cases ctxt')))
   271   end |> thm_name kind raw_th;
   272 
   273 end;
   274 
   275 
   276 
   277 (** logical operations **)
   278 
   279 (* witnesses -- hypotheses as protected facts *)
   280 
   281 datatype witness = Witness of term * thm;
   282 
   283 fun map_witness f (Witness witn) = Witness (f witn);
   284 
   285 fun morph_witness phi = map_witness (fn (t, th) => (Morphism.term phi t, Morphism.thm phi th));
   286 
   287 fun witness_prop (Witness (t, _)) = t;
   288 fun witness_hyps (Witness (_, th)) = #hyps (Thm.rep_thm th);
   289 
   290 fun assume_witness thy t =
   291   Witness (t, Goal.protect (Thm.assume (Thm.cterm_of thy t)));
   292 
   293 fun prove_witness ctxt t tac =
   294   Witness (t, Goal.prove ctxt [] [] (Logic.protect t) (fn _ =>
   295     Tactic.rtac Drule.protectI 1 THEN tac));
   296 
   297 fun conclude_witness (Witness (_, th)) = MetaSimplifier.norm_hhf_protect (Goal.conclude th);
   298 
   299 val mark_witness = Logic.protect;
   300 
   301 fun make_witness t th = Witness (t, th);
   302 fun dest_witness (Witness w) = w;
   303 
   304 fun transfer_witness thy (Witness (t, th)) = Witness (t, Thm.transfer thy th);
   305 
   306 val refine_witness =
   307   Proof.refine (Method.Basic (K (Method.RAW_METHOD
   308     (K (ALLGOALS
   309       (CONJUNCTS (ALLGOALS
   310         (CONJUNCTS (TRYALL (Tactic.rtac Drule.protectI)))))))), Position.none));
   311 
   312 fun pretty_witness ctxt witn =
   313   let val prt_term = Pretty.quote o Syntax.pretty_term ctxt in
   314     Pretty.block (prt_term (witness_prop witn) ::
   315       (if ! show_hyps then [Pretty.brk 2, Pretty.list "[" "]"
   316          (map prt_term (witness_hyps witn))] else []))
   317   end;
   318 
   319 
   320 (* derived rules *)
   321 
   322 fun instantiate_tfrees thy subst th =
   323   let
   324     val certT = Thm.ctyp_of thy;
   325     val idx = Thm.maxidx_of th + 1;
   326     fun cert_inst (a, (S, T)) = (certT (TVar ((a, idx), S)), certT T);
   327 
   328     fun add_inst (a, S) insts =
   329       if AList.defined (op =) insts a then insts
   330       else (case AList.lookup (op =) subst a of NONE => insts | SOME T => (a, (S, T)) :: insts);
   331     val insts =
   332       Term.fold_types (Term.fold_atyps (fn TFree v => add_inst v | _ => I))
   333         (Thm.full_prop_of th) [];
   334   in
   335     th
   336     |> Thm.generalize (map fst insts, []) idx
   337     |> Thm.instantiate (map cert_inst insts, [])
   338   end;
   339 
   340 fun instantiate_frees thy subst =
   341   let val cert = Thm.cterm_of thy in
   342     Drule.forall_intr_list (map (cert o Free o fst) subst) #>
   343     Drule.forall_elim_list (map (cert o snd) subst)
   344   end;
   345 
   346 fun hyps_rule rule th =
   347   let val {hyps, ...} = Thm.crep_thm th in
   348     Drule.implies_elim_list
   349       (rule (Drule.implies_intr_list hyps th))
   350       (map (Thm.assume o Drule.cterm_rule rule) hyps)
   351   end;
   352 
   353 
   354 (* rename *)
   355 
   356 fun rename ren x =
   357   (case AList.lookup (op =) ren (x: string) of
   358     NONE => x
   359   | SOME (x', _) => x');
   360 
   361 fun rename_var ren (x, mx) =
   362   (case (AList.lookup (op =) ren (x: string), mx) of
   363     (NONE, _) => (x, mx)
   364   | (SOME (x', NONE), Structure) => (x', mx)
   365   | (SOME (x', SOME _), Structure) =>
   366       error ("Attempt to change syntax of structure parameter " ^ quote x)
   367   | (SOME (x', NONE), _) => (x', NoSyn)
   368   | (SOME (x', SOME mx'), _) => (x', mx'));
   369 
   370 fun rename_term ren (Free (x, T)) = Free (rename ren x, T)
   371   | rename_term ren (t $ u) = rename_term ren t $ rename_term ren u
   372   | rename_term ren (Abs (x, T, t)) = Abs (x, T, rename_term ren t)
   373   | rename_term _ a = a;
   374 
   375 fun rename_thm ren th =
   376   let
   377     val thy = Thm.theory_of_thm th;
   378     val subst = (Thm.fold_terms o Term.fold_aterms)
   379       (fn Free (x, T) =>
   380         let val x' = rename ren x
   381         in if x = x' then I else insert (eq_fst (op =)) ((x, T), Free (x', T)) end
   382       | _ => I) th [];
   383   in
   384     if null subst then th
   385     else th |> hyps_rule (instantiate_frees thy subst)
   386   end;
   387 
   388 fun rename_morphism ren = Morphism.morphism
   389   {name = I, var = rename_var ren, typ = I, term = rename_term ren, fact = map (rename_thm ren)};
   390 
   391 
   392 (* instantiate types *)
   393 
   394 fun instT_type env =
   395   if Symtab.is_empty env then I
   396   else Term.map_type_tfree (fn (x, S) => the_default (TFree (x, S)) (Symtab.lookup env x));
   397 
   398 fun instT_term env =
   399   if Symtab.is_empty env then I
   400   else Term.map_types (instT_type env);
   401 
   402 fun instT_subst env th = (Thm.fold_terms o Term.fold_types o Term.fold_atyps)
   403   (fn T as TFree (a, _) =>
   404     let val T' = the_default T (Symtab.lookup env a)
   405     in if T = T' then I else insert (op =) (a, T') end
   406   | _ => I) th [];
   407 
   408 fun instT_thm thy env th =
   409   if Symtab.is_empty env then th
   410   else
   411     let val subst = instT_subst env th
   412     in if null subst then th else th |> hyps_rule (instantiate_tfrees thy subst) end;
   413 
   414 fun instT_morphism thy env =
   415   let val thy_ref = Theory.check_thy thy in
   416     Morphism.morphism
   417      {name = I, var = I,
   418       typ = instT_type env,
   419       term = instT_term env,
   420       fact = map (fn th => instT_thm (Theory.deref thy_ref) env th)}
   421   end;
   422 
   423 
   424 (* instantiate types and terms *)
   425 
   426 fun inst_term (envT, env) =
   427   if Symtab.is_empty env then instT_term envT
   428   else
   429     let
   430       val instT = instT_type envT;
   431       fun inst (Const (x, T)) = Const (x, instT T)
   432         | inst (Free (x, T)) =
   433             (case Symtab.lookup env x of
   434               NONE => Free (x, instT T)
   435             | SOME t => t)
   436         | inst (Var (xi, T)) = Var (xi, instT T)
   437         | inst (b as Bound _) = b
   438         | inst (Abs (x, T, t)) = Abs (x, instT T, inst t)
   439         | inst (t $ u) = inst t $ inst u;
   440     in Envir.beta_norm o inst end;
   441 
   442 fun inst_thm thy (envT, env) th =
   443   if Symtab.is_empty env then instT_thm thy envT th
   444   else
   445     let
   446       val substT = instT_subst envT th;
   447       val subst = (Thm.fold_terms o Term.fold_aterms)
   448        (fn Free (x, T) =>
   449           let
   450             val T' = instT_type envT T;
   451             val t = Free (x, T');
   452             val t' = the_default t (Symtab.lookup env x);
   453           in if t aconv t' then I else insert (eq_fst (op =)) ((x, T'), t') end
   454        | _ => I) th [];
   455     in
   456       if null substT andalso null subst then th
   457       else th |> hyps_rule
   458        (instantiate_tfrees thy substT #>
   459         instantiate_frees thy subst #>
   460         Conv.fconv_rule (Thm.beta_conversion true))
   461     end;
   462 
   463 fun inst_morphism thy envs =
   464   let val thy_ref = Theory.check_thy thy in
   465     Morphism.morphism
   466      {name = I, var = I,
   467       typ = instT_type (#1 envs),
   468       term = inst_term envs,
   469       fact = map (fn th => inst_thm (Theory.deref thy_ref) envs th)}
   470   end;
   471 
   472 (* separate instantiation for theorems -- cannot have vars *)
   473 fun inst_morphism' thy envs envs' =
   474   let val thy_ref = Theory.check_thy thy in
   475     Morphism.morphism
   476      {name = I, var = I,
   477       typ = instT_type (#1 envs),
   478       term = inst_term envs,
   479       fact = map (fn th => inst_thm (Theory.deref thy_ref) envs' th)}
   480   end;
   481 
   482 
   483 (* satisfy hypotheses *)
   484 
   485 fun satisfy_thm witns thm = thm |> fold (fn hyp =>
   486     (case find_first (fn Witness (t, _) => Thm.term_of hyp aconv t) witns of
   487       NONE => I
   488     | SOME (Witness (_, th)) => Drule.implies_intr_protected [hyp] #> Goal.comp_hhf th))
   489   (#hyps (Thm.crep_thm thm));
   490 
   491 fun satisfy_morphism witns = Morphism.thm_morphism (satisfy_thm witns);
   492 
   493 fun satisfy_facts witns = facts_map (morph_ctxt (satisfy_morphism witns));
   494 
   495 
   496 (* generalize type/term parameters *)
   497 
   498 val maxidx_atts = fold Args.maxidx_values;
   499 
   500 fun generalize_facts inner outer facts =
   501   let
   502     val thy = ProofContext.theory_of inner;
   503     val maxidx =
   504       fold (fn ((_, atts), bs) => maxidx_atts atts #> fold (maxidx_atts o #2) bs) facts ~1;
   505     val exp_fact = map (Thm.adjust_maxidx_thm maxidx) #> Variable.export inner outer;
   506     val exp_term = Drule.term_rule thy (singleton exp_fact);
   507     val exp_typ = Logic.type_map exp_term;
   508     val morphism =
   509       Morphism.morphism {name = I, var = I, typ = exp_typ, term = exp_term, fact = exp_fact};
   510   in facts_map (morph_ctxt morphism) facts end;
   511 
   512 end;