src/Pure/Isar/locale.ML
changeset 21441 940ef3e85c5a
parent 21393 c648e24fd7ee
child 21483 e4be91feca50
equal deleted inserted replaced
21440:807a39221a58 21441:940ef3e85c5a
   884           ctxt |> fold (Variable.auto_fixes o #1) asms
   884           ctxt |> fold (Variable.auto_fixes o #1) asms
   885           |> ProofContext.add_assms_i LocalDefs.def_export (map #2 asms);
   885           |> ProofContext.add_assms_i LocalDefs.def_export (map #2 asms);
   886       in ((ctxt', Assumed axs), []) end
   886       in ((ctxt', Assumed axs), []) end
   887   | activate_elem _ _ ((ctxt, Derived ths), Defines defs) =
   887   | activate_elem _ _ ((ctxt, Derived ths), Defines defs) =
   888       ((ctxt, Derived ths), [])
   888       ((ctxt, Derived ths), [])
   889   | activate_elem _ is_ext ((ctxt, mode), Notes facts) =
   889   | activate_elem _ is_ext ((ctxt, mode), Notes (kind, facts)) =
   890       let
   890       let
   891         val facts' = Attrib.map_facts (Attrib.attribute_i (ProofContext.theory_of ctxt)) facts;
   891         val facts' = Attrib.map_facts (Attrib.attribute_i (ProofContext.theory_of ctxt)) facts;
   892         val (res, ctxt') = ctxt |> ProofContext.note_thmss_i facts';
   892         val (res, ctxt') = ctxt |> ProofContext.note_thmss_i kind facts';
   893       in ((ctxt', mode), if is_ext then res else []) end;
   893       in ((ctxt', mode), if is_ext then res else []) end;
   894 
   894 
   895 fun activate_elems ax_in_ctxt (((name, ps), mode), elems) ctxt =
   895 fun activate_elems ax_in_ctxt (((name, ps), mode), elems) ctxt =
   896   let
   896   let
   897     val thy = ProofContext.theory_of ctxt;
   897     val thy = ProofContext.theory_of ctxt;
   898     val ((ctxt', _), res) =
   898     val ((ctxt', _), res) =
   899         foldl_map (activate_elem ax_in_ctxt (name = "")) ((ProofContext.qualified_names ctxt, mode), elems)
   899       foldl_map (activate_elem ax_in_ctxt (name = ""))
   900       handle ERROR msg => err_in_locale ctxt msg [(name, map fst ps)]
   900         ((ProofContext.qualified_names ctxt, mode), elems)
       
   901       handle ERROR msg => err_in_locale ctxt msg [(name, map fst ps)];
   901     val ctxt'' = if name = "" then ctxt'
   902     val ctxt'' = if name = "" then ctxt'
   902           else let
   903           else let
   903               val ps' = map (fn (n, SOME T) => Free (n, T)) ps;
   904               val ps' = map (fn (n, SOME T) => Free (n, T)) ps;
   904               val ctxt'' = put_local_registration (name, ps') ("", []) ctxt'
   905               val ctxt'' = put_local_registration (name, ps') ("", []) ctxt'
   905             in case mode of
   906             in case mode of
  1003   | declare_ext_elem prep_vars (ctxt, Constrains csts) =
  1004   | declare_ext_elem prep_vars (ctxt, Constrains csts) =
  1004       let val (_, ctxt') = prep_vars (map (fn (x, T) => (x, SOME T, NoSyn)) csts) ctxt
  1005       let val (_, ctxt') = prep_vars (map (fn (x, T) => (x, SOME T, NoSyn)) csts) ctxt
  1005       in (ctxt', []) end
  1006       in (ctxt', []) end
  1006   | declare_ext_elem _ (ctxt, Assumes asms) = (ctxt, map #2 asms)
  1007   | declare_ext_elem _ (ctxt, Assumes asms) = (ctxt, map #2 asms)
  1007   | declare_ext_elem _ (ctxt, Defines defs) = (ctxt, map (fn (_, (t, ps)) => [(t, ps)]) defs)
  1008   | declare_ext_elem _ (ctxt, Defines defs) = (ctxt, map (fn (_, (t, ps)) => [(t, ps)]) defs)
  1008   | declare_ext_elem _ (ctxt, Notes facts) = (ctxt, []);
  1009   | declare_ext_elem _ (ctxt, Notes _) = (ctxt, []);
  1009 
  1010 
  1010 fun declare_elems prep_vars (ctxt, (((name, ps), Assumed _), elems)) =
  1011 fun declare_elems prep_vars (ctxt, (((name, ps), Assumed _), elems)) =
  1011     let val (ctxt', propps) =
  1012     let val (ctxt', propps) =
  1012       (case elems of
  1013       (case elems of
  1013         Int es => foldl_map declare_int_elem (ctxt, es)
  1014         Int es => foldl_map declare_int_elem (ctxt, es)
  1091 
  1092 
  1092   | finish_derived _ _ (Derived _) (Fixes _) = NONE
  1093   | finish_derived _ _ (Derived _) (Fixes _) = NONE
  1093   | finish_derived _ _ (Derived _) (Constrains _) = NONE
  1094   | finish_derived _ _ (Derived _) (Constrains _) = NONE
  1094   | finish_derived sign wits (Derived _) (Assumes asms) = asms
  1095   | finish_derived sign wits (Derived _) (Assumes asms) = asms
  1095       |> map (apsnd (map (fn (a, _) => ([Thm.assume (cterm_of sign a)], []))))
  1096       |> map (apsnd (map (fn (a, _) => ([Thm.assume (cterm_of sign a)], []))))
  1096       |> Notes |> Element.map_ctxt_values I I (Element.satisfy_thm wits) |> SOME
  1097       |> pair Thm.assumptionK |> Notes
       
  1098       |> Element.map_ctxt_values I I (Element.satisfy_thm wits) |> SOME
  1097   | finish_derived sign wits (Derived _) (Defines defs) = defs
  1099   | finish_derived sign wits (Derived _) (Defines defs) = defs
  1098       |> map (apsnd (fn (d, _) => [([Thm.assume (cterm_of sign d)], [])]))
  1100       |> map (apsnd (fn (d, _) => [([Thm.assume (cterm_of sign d)], [])]))
  1099       |> Notes |> Element.map_ctxt_values I I (Element.satisfy_thm wits) |> SOME
  1101       |> pair Thm.definitionK |> Notes
  1100 
  1102       |> Element.map_ctxt_values I I (Element.satisfy_thm wits) |> SOME
  1101   | finish_derived _ wits _ (Notes facts) = (Notes facts)
  1103 
       
  1104   | finish_derived _ wits _ (Notes facts) = Notes facts
  1102       |> Element.map_ctxt_values I I (Element.satisfy_thm wits) |> SOME;
  1105       |> Element.map_ctxt_values I I (Element.satisfy_thm wits) |> SOME;
  1103 
  1106 
  1104 (* CB: for finish_elems (Ext) *)
  1107 (* CB: for finish_elems (Ext) *)
  1105 
  1108 
  1106 fun closeup _ false elem = elem
  1109 fun closeup _ false elem = elem
  1388     val (ps, qs) = chop (length raw_import_params_elemss + length raw_import_elemss) all_elemss';
  1391     val (ps, qs) = chop (length raw_import_params_elemss + length raw_import_elemss) all_elemss';
  1389     val (import_ctxt, (import_elemss, _)) =
  1392     val (import_ctxt, (import_elemss, _)) =
  1390       activate_facts false prep_facts (context, ps);
  1393       activate_facts false prep_facts (context, ps);
  1391 
  1394 
  1392     val (ctxt, (elemss, _)) =
  1395     val (ctxt, (elemss, _)) =
  1393       activate_facts false prep_facts (import_ctxt, qs);
  1396       activate_facts false prep_facts (ProofContext.set_stmt true import_ctxt, qs);
  1394   in
  1397   in
  1395     ((((import_ctxt, import_elemss), (ctxt, elemss, syn)),
  1398     ((((import_ctxt, import_elemss), (ctxt, elemss, syn)),
  1396       (parms, spec, defs)), concl)
  1399       (parms, spec, defs)), concl)
  1397   end;
  1400   end;
  1398 
  1401 
  1455   |> Theory.qualified_names
  1458   |> Theory.qualified_names
  1456   |> Theory.sticky_prefix prfx
  1459   |> Theory.sticky_prefix prfx
  1457   |> PureThy.note_thmss_i kind args
  1460   |> PureThy.note_thmss_i kind args
  1458   ||> Theory.restore_naming thy;
  1461   ||> Theory.restore_naming thy;
  1459 
  1462 
  1460 fun local_note_prefix_i prfx args ctxt =
  1463 fun local_note_prefix_i kind prfx args ctxt =
  1461   ctxt
  1464   ctxt
  1462   |> ProofContext.qualified_names
  1465   |> ProofContext.qualified_names
  1463   |> ProofContext.sticky_prefix prfx
  1466   |> ProofContext.sticky_prefix prfx
  1464   |> ProofContext.note_thmss_i args
  1467   |> ProofContext.note_thmss_i kind args
  1465   ||> ProofContext.restore_naming ctxt;
  1468   ||> ProofContext.restore_naming ctxt;
  1466 
  1469 
  1467 
  1470 
  1468 (* collect witnesses for global registration;
  1471 (* collect witnesses for global registration;
  1469    requires parameters and flattened list of (assumed!) identifiers
  1472    requires parameters and flattened list of (assumed!) identifiers
  1486 
  1489 
  1487 
  1490 
  1488 (* store instantiations of args for all registered interpretations
  1491 (* store instantiations of args for all registered interpretations
  1489    of the theory *)
  1492    of the theory *)
  1490 
  1493 
  1491 fun note_thmss_registrations kind target args thy =
  1494 fun note_thmss_registrations target (kind, args) thy =
  1492   let
  1495   let
  1493     val parms = the_locale thy target |> #params |> map fst;
  1496     val parms = the_locale thy target |> #params |> map fst;
  1494     val ids = flatten (ProofContext.init thy, intern_expr thy)
  1497     val ids = flatten (ProofContext.init thy, intern_expr thy)
  1495       (([], Symtab.empty), Expr (Locale target)) |> fst |> fst
  1498       (([], Symtab.empty), Expr (Locale target)) |> fst |> fst
  1496       |> map_filter (fn (id, (_, Assumed _)) => SOME id | _ => NONE)
  1499       |> map_filter (fn (id, (_, Assumed _)) => SOME id | _ => NONE)
  1533   #> (#2 o cert_context_statement (SOME loc) [] []);
  1536   #> (#2 o cert_context_statement (SOME loc) [] []);
  1534 
  1537 
  1535 
  1538 
  1536 (* locale results *)
  1539 (* locale results *)
  1537 
  1540 
  1538 fun add_thmss kind loc args ctxt =
  1541 fun add_thmss loc kind args ctxt =
  1539   let
  1542   let
  1540     val (ctxt', ([(_, [Notes args'])], facts)) =
  1543     val (ctxt', ([(_, [Notes args'])], facts)) =
  1541       activate_facts true cert_facts (ctxt, [((("", []), Assumed []), [Ext (Notes args)])]);
  1544       activate_facts true cert_facts
       
  1545         (ctxt, [((("", []), Assumed []), [Ext (Notes (kind, args))])]);
  1542     val ctxt'' = ctxt' |> ProofContext.theory
  1546     val ctxt'' = ctxt' |> ProofContext.theory
  1543       (change_locale loc
  1547       (change_locale loc
  1544         (fn (axiom, import, elems, params, lparams, term_syntax, regs, intros) =>
  1548         (fn (axiom, import, elems, params, lparams, term_syntax, regs, intros) =>
  1545           (axiom, import, elems @ [(Notes args', stamp ())],
  1549           (axiom, import, elems @ [(Notes args', stamp ())],
  1546             params, lparams, term_syntax, regs, intros))
  1550             params, lparams, term_syntax, regs, intros))
  1547       #> note_thmss_registrations kind loc args');
  1551       #> note_thmss_registrations loc args');
  1548   in (facts, ctxt'') end;
  1552   in (facts, ctxt'') end;
  1549 
  1553 
  1550 
  1554 
  1551 
  1555 
  1552 (** define locales **)
  1556 (** define locales **)
  1627        (Tactic.rewrite_goals_tac defs THEN
  1631        (Tactic.rewrite_goals_tac defs THEN
  1628         Tactic.compose_tac (false, ax, 0) 1));
  1632         Tactic.compose_tac (false, ax, 0) 1));
  1629   in ((statement, intro, axioms), defs_thy) end;
  1633   in ((statement, intro, axioms), defs_thy) end;
  1630 
  1634 
  1631 fun assumes_to_notes (Assumes asms) axms =
  1635 fun assumes_to_notes (Assumes asms) axms =
  1632     fold_map (fn (a, spec) => fn axs =>
  1636       fold_map (fn (a, spec) => fn axs =>
  1633        let val (ps, qs) = chop (length spec) axs
  1637           let val (ps, qs) = chop (length spec) axs
  1634        in ((a, [(ps, [])]), qs) end) asms axms
  1638           in ((a, [(ps, [])]), qs) end) asms axms
  1635     |> apfst Notes
  1639       |> apfst (curry Notes Thm.assumptionK)
  1636   | assumes_to_notes e axms = (e, axms);
  1640   | assumes_to_notes e axms = (e, axms);
  1637 
  1641 
  1638 (* CB: the following two change only "new" elems, these have identifier ("", _). *)
  1642 (* CB: the following two change only "new" elems, these have identifier ("", _). *)
  1639 
  1643 
  1640 (* turn Assumes into Notes elements *)
  1644 (* turn Assumes into Notes elements *)
  1653 (* adjust hyps of Notes elements *)
  1657 (* adjust hyps of Notes elements *)
  1654 
  1658 
  1655 fun change_elemss_hyps axioms elemss =
  1659 fun change_elemss_hyps axioms elemss =
  1656   let
  1660   let
  1657     fun change (id as ("", _), es) =
  1661     fun change (id as ("", _), es) =
  1658         (id, map (fn e as (Notes _) => Element.map_ctxt_values I I (Element.satisfy_thm axioms) e
  1662         (id, map (fn e as Notes _ => Element.map_ctxt_values I I (Element.satisfy_thm axioms) e
  1659                    | e => e) es)
  1663                    | e => e) es)
  1660       | change e = e;
  1664       | change e = e;
  1661   in map change elemss end;
  1665   in map change elemss end;
  1662 
  1666 
  1663 in
  1667 in
  1673           val aname = if null ints then bname else bname ^ "_" ^ axiomsN;
  1677           val aname = if null ints then bname else bname ^ "_" ^ axiomsN;
  1674           val ((statement, intro, axioms), def_thy) =
  1678           val ((statement, intro, axioms), def_thy) =
  1675             thy |> def_pred aname parms defs exts exts';
  1679             thy |> def_pred aname parms defs exts exts';
  1676           val elemss' = change_assumes_elemss axioms elemss;
  1680           val elemss' = change_assumes_elemss axioms elemss;
  1677           val def_thy' = def_thy
  1681           val def_thy' = def_thy
  1678             |> PureThy.note_thmss_qualified "" aname [((introN, []), [([intro], [])])]
  1682             |> PureThy.note_thmss_qualified Thm.definitionK
       
  1683               aname [((introN, []), [([intro], [])])]
  1679             |> snd;
  1684             |> snd;
  1680           val a_elem = [(("", []), [Assumes [((bname ^ "_" ^ axiomsN, []), [(statement, [])])]])];
  1685           val a_elem = [(("", []), [Assumes [((bname ^ "_" ^ axiomsN, []), [(statement, [])])]])];
  1681         in ((elemss', [statement]), a_elem, [intro], def_thy') end;
  1686         in ((elemss', [statement]), a_elem, [intro], def_thy') end;
  1682     val (predicate, stmt', elemss'', b_intro, thy'') =
  1687     val (predicate, stmt', elemss'', b_intro, thy'') =
  1683       if null ints then (([], []), more_ts, elemss' @ a_elem, [], thy')
  1688       if null ints then (([], []), more_ts, elemss' @ a_elem, [], thy')
  1687             thy' |> def_pred bname parms defs (ints @ more_ts) (ints' @ more_ts);
  1692             thy' |> def_pred bname parms defs (ints @ more_ts) (ints' @ more_ts);
  1688           val cstatement = Thm.cterm_of def_thy statement;
  1693           val cstatement = Thm.cterm_of def_thy statement;
  1689           val elemss'' = change_elemss_hyps axioms elemss';
  1694           val elemss'' = change_elemss_hyps axioms elemss';
  1690           val def_thy' =
  1695           val def_thy' =
  1691           def_thy
  1696           def_thy
  1692           |> PureThy.note_thmss_qualified "" bname
  1697           |> PureThy.note_thmss_qualified Thm.definitionK bname
  1693                [((introN, []), [([intro], [])]),
  1698               [((introN, []), [([intro], [])]),
  1694                 ((axiomsN, []), [(map (Drule.standard o Element.conclude_witness) axioms, [])])]
  1699                 ((axiomsN, []), [(map (Drule.standard o Element.conclude_witness) axioms, [])])]
  1695           |> snd;
  1700           |> snd;
  1696           val b_elem = [(("", []),
  1701           val b_elem = [(("", []),
  1697                [Assumes [((bname ^ "_" ^ axiomsN, []), [(statement, [])])]])];
  1702                [Assumes [((bname ^ "_" ^ axiomsN, []), [(statement, [])])]])];
  1698         in (([cstatement], axioms), [statement], elemss'' @ b_elem, [intro], def_thy') end;
  1703         in (([cstatement], axioms), [statement], elemss'' @ b_elem, [intro], def_thy') end;
  1710 fun defines_to_notes is_ext thy (Defines defs) defns =
  1715 fun defines_to_notes is_ext thy (Defines defs) defns =
  1711     let
  1716     let
  1712       val defs' = map (fn (_, (def, _)) => (("", []), (def, []))) defs
  1717       val defs' = map (fn (_, (def, _)) => (("", []), (def, []))) defs
  1713       val notes = map (fn (a, (def, _)) =>
  1718       val notes = map (fn (a, (def, _)) =>
  1714         (a, [([assume (cterm_of thy def)], [])])) defs
  1719         (a, [([assume (cterm_of thy def)], [])])) defs
  1715     in (if is_ext then SOME (Notes notes) else NONE, defns @ [Defines defs']) end
  1720     in
       
  1721       (if is_ext then SOME (Notes (Thm.definitionK, notes)) else NONE, defns @ [Defines defs'])
       
  1722     end
  1716   | defines_to_notes _ _ e defns = (SOME e, defns);
  1723   | defines_to_notes _ _ e defns = (SOME e, defns);
  1717 
  1724 
  1718 fun change_defines_elemss thy elemss defns =
  1725 fun change_defines_elemss thy elemss defns =
  1719   let
  1726   let
  1720     fun change (id as (n, _), es) defns =
  1727     fun change (id as (n, _), es) defns =
  1776     val facts' = facts |> map (fn (a, ths) => ((a, []), [(map export ths, [])]));
  1783     val facts' = facts |> map (fn (a, ths) => ((a, []), [(map export ths, [])]));
  1777     val elems' = maps #2 (filter (equal "" o #1 o #1) elemss');
  1784     val elems' = maps #2 (filter (equal "" o #1 o #1) elemss');
  1778     val elems'' = map_filter (fn (Fixes _) => NONE | e => SOME e) elems';
  1785     val elems'' = map_filter (fn (Fixes _) => NONE | e => SOME e) elems';
  1779     val axs' = map (Element.assume_witness pred_thy) stmt';
  1786     val axs' = map (Element.assume_witness pred_thy) stmt';
  1780     val loc_ctxt = pred_thy
  1787     val loc_ctxt = pred_thy
  1781       |> PureThy.note_thmss_qualified "" bname facts' |> snd
  1788       |> PureThy.note_thmss_qualified Thm.assumptionK bname facts' |> snd
  1782       |> declare_locale name
  1789       |> declare_locale name
  1783       |> put_locale name
  1790       |> put_locale name
  1784        {axiom = axs',
  1791        {axiom = axs',
  1785         import = import,
  1792         import = import,
  1786         elems = map (fn e => (e, stamp ())) elems'',
  1793         elems = map (fn e => (e, stamp ())) elems'',
  1869 (* activate instantiated facts in theory or context *)
  1876 (* activate instantiated facts in theory or context *)
  1870 
  1877 
  1871 fun gen_activate_facts_elemss get_reg note attrib std put_reg add_wit
  1878 fun gen_activate_facts_elemss get_reg note attrib std put_reg add_wit
  1872         attn all_elemss new_elemss propss thmss thy_ctxt =
  1879         attn all_elemss new_elemss propss thmss thy_ctxt =
  1873     let
  1880     let
  1874       fun activate_elem disch (prfx, atts) (Notes facts) thy_ctxt =
  1881       fun activate_elem disch (prfx, atts) (Notes (kind, facts)) thy_ctxt =
  1875           let
  1882           let
  1876             val facts' = facts
  1883             val facts' = facts
  1877               (* discharge hyps in attributes *)
  1884               (* discharge hyps in attributes *)
  1878               |> Attrib.map_facts (attrib thy_ctxt o Args.map_values I I I disch)
  1885               |> Attrib.map_facts (attrib thy_ctxt o Args.map_values I I I disch)
  1879               (* insert interpretation attributes *)
  1886               (* append interpretation attributes *)
  1880               |> map (apfst (apsnd (fn a => a @ map (attrib thy_ctxt) atts)))
  1887               |> map (apfst (apsnd (fn a => a @ map (attrib thy_ctxt) atts)))
  1881               (* discharge hyps *)
  1888               (* discharge hyps *)
  1882               |> map (apsnd (map (apfst (map disch))));
  1889               |> map (apsnd (map (apfst (map disch))));
  1883           in snd (note prfx facts' thy_ctxt) end
  1890           in snd (note kind prfx facts' thy_ctxt) end
  1884         | activate_elem _ _ _ thy_ctxt = thy_ctxt;
  1891         | activate_elem _ _ _ thy_ctxt = thy_ctxt;
  1885 
  1892 
  1886       fun activate_elems disch ((id, _), elems) thy_ctxt =
  1893       fun activate_elems disch ((id, _), elems) thy_ctxt =
  1887           let
  1894           let
  1888             val ((prfx, atts2), _) = the (get_reg thy_ctxt id)
  1895             val ((prfx, atts2), _) = the (get_reg thy_ctxt id)
  1915     end;
  1922     end;
  1916 
  1923 
  1917 fun global_activate_facts_elemss x = gen_activate_facts_elemss
  1924 fun global_activate_facts_elemss x = gen_activate_facts_elemss
  1918       (fn thy => fn (name, ps) =>
  1925       (fn thy => fn (name, ps) =>
  1919         get_global_registration thy (name, map Logic.varify ps))
  1926         get_global_registration thy (name, map Logic.varify ps))
  1920       (global_note_prefix_i "")
  1927       global_note_prefix_i
  1921       Attrib.attribute_i Drule.standard
  1928       Attrib.attribute_i Drule.standard
  1922       (fn (name, ps) => put_global_registration (name, map Logic.varify ps))
  1929       (fn (name, ps) => put_global_registration (name, map Logic.varify ps))
  1923       (fn (n, ps) => add_global_witness (n, map Logic.varify ps) o
  1930       (fn (n, ps) => add_global_witness (n, map Logic.varify ps) o
  1924         Element.map_witness (fn (t, th) => (Logic.legacy_unvarify t, legacy_unvarify th))
  1931         Element.map_witness (fn (t, th) => (Logic.legacy_unvarify t, legacy_unvarify th))
  1925         (* FIXME *)) x;
  1932         (* FIXME *)) x;
  2112                        (witn |> Element.map_witness (fn (t, th) =>  (* FIXME *)
  2119                        (witn |> Element.map_witness (fn (t, th) =>  (* FIXME *)
  2113                        (Element.inst_term insts t,
  2120                        (Element.inst_term insts t,
  2114                         disch (Element.inst_thm thy insts (satisfy th))))) thy) ths
  2121                         disch (Element.inst_thm thy insts (satisfy th))))) thy) ths
  2115               end;
  2122               end;
  2116 
  2123 
  2117             fun activate_elem (Notes facts) thy =
  2124             fun activate_elem (Notes (kind, facts)) thy =
  2118                 let
  2125                 let
  2119                   val facts' = facts
  2126                   val facts' = facts
  2120                       |> Attrib.map_facts (Attrib.attribute_i thy o
  2127                       |> Attrib.map_facts (Attrib.attribute_i thy o
  2121                          Args.map_values I (Element.instT_type (#1 insts))
  2128                          Args.map_values I (Element.instT_type (#1 insts))
  2122                            (Element.inst_term insts)
  2129                            (Element.inst_term insts)
  2123                            (disch o Element.inst_thm thy insts o satisfy))
  2130                            (disch o Element.inst_thm thy insts o satisfy))
  2124                       |> map (apfst (apsnd (fn a => a @ map (Attrib.attribute thy) atts2)))
  2131                       |> map (apfst (apsnd (fn a => a @ map (Attrib.attribute thy) atts2)))
  2125                       |> map (apsnd (map (apfst (map (disch o Element.inst_thm thy insts o satisfy)))))
  2132                       |> map (apsnd (map (apfst (map (disch o Element.inst_thm thy insts o satisfy)))))
  2126                 in
  2133                 in
  2127                   thy
  2134                   thy
  2128                   |> global_note_prefix_i "" prfx facts'
  2135                   |> global_note_prefix_i kind prfx facts'
  2129                   |> snd
  2136                   |> snd
  2130                 end
  2137                 end
  2131               | activate_elem _ thy = thy;
  2138               | activate_elem _ thy = thy;
  2132 
  2139 
  2133             fun activate_elems (_, elems) thy = fold activate_elem elems thy;
  2140             fun activate_elems (_, elems) thy = fold activate_elem elems thy;
  2156     fun after_qed' results =
  2163     fun after_qed' results =
  2157       ProofContext.theory (activate (prep_result propss results))
  2164       ProofContext.theory (activate (prep_result propss results))
  2158       #> after_qed;
  2165       #> after_qed;
  2159   in
  2166   in
  2160     ProofContext.init thy
  2167     ProofContext.init thy
  2161     |> Proof.theorem_i "interpretation" NONE after_qed' (prep_propp propss)
  2168     |> Proof.theorem_i NONE after_qed' (prep_propp propss)
  2162     |> Element.refine_witness |> Seq.hd
  2169     |> Element.refine_witness |> Seq.hd
  2163   end;
  2170   end;
  2164 
  2171 
  2165 fun interpretation_in_locale after_qed (raw_target, expr) thy =
  2172 fun interpretation_in_locale after_qed (raw_target, expr) thy =
  2166   let
  2173   let
  2175     fun after_qed' results =
  2182     fun after_qed' results =
  2176       ProofContext.theory (activate (prep_result propss results))
  2183       ProofContext.theory (activate (prep_result propss results))
  2177       #> after_qed;
  2184       #> after_qed;
  2178   in
  2185   in
  2179     goal_ctxt
  2186     goal_ctxt
  2180     |> Proof.theorem_i "interpretation" NONE after_qed' propp
  2187     |> Proof.theorem_i NONE after_qed' propp
  2181     |> Element.refine_witness |> Seq.hd
  2188     |> Element.refine_witness |> Seq.hd
  2182   end;
  2189   end;
  2183 
  2190 
  2184 fun interpret after_qed (prfx, atts) expr insts int state =
  2191 fun interpret after_qed (prfx, atts) expr insts int state =
  2185   let
  2192   let