51 val print_locales: theory -> unit |
51 val print_locales: theory -> unit |
52 val print_locale: theory -> expr -> context attribute element list -> unit |
52 val print_locale: theory -> expr -> context attribute element list -> unit |
53 val add_locale: bool -> bstring -> expr -> context attribute element list -> theory -> theory |
53 val add_locale: bool -> bstring -> expr -> context attribute element list -> theory -> theory |
54 val add_locale_i: bool -> bstring -> expr -> context attribute element_i list |
54 val add_locale_i: bool -> bstring -> expr -> context attribute element_i list |
55 -> theory -> theory |
55 -> theory -> theory |
56 val smart_have_thmss: string -> (string * 'a) Library.option -> |
56 val smart_note_thmss: string -> (string * 'a) Library.option -> |
57 ((bstring * theory attribute list) * (thm list * theory attribute list) list) list -> |
57 ((bstring * theory attribute list) * (thm list * theory attribute list) list) list -> |
58 theory -> theory * (bstring * thm list) list |
58 theory -> theory * (bstring * thm list) list |
59 val have_thmss: string -> xstring -> |
59 val note_thmss: string -> xstring -> |
60 ((bstring * context attribute list) * (xstring * context attribute list) list) list -> |
60 ((bstring * context attribute list) * (xstring * context attribute list) list) list -> |
61 theory -> theory * (bstring * thm list) list |
61 theory -> theory * (bstring * thm list) list |
62 val have_thmss_i: string -> string -> |
62 val note_thmss_i: string -> string -> |
63 ((bstring * context attribute list) * (thm list * context attribute list) list) list -> |
63 ((bstring * context attribute list) * (thm list * context attribute list) list) list -> |
64 theory -> theory * (bstring * thm list) list |
64 theory -> theory * (bstring * thm list) list |
65 val add_thmss: string -> ((string * thm list) * context attribute list) list -> |
65 val add_thmss: string -> ((string * thm list) * context attribute list) list -> |
66 theory * context -> (theory * context) * (string * thm list) list |
66 theory * context -> (theory * context) * (string * thm list) list |
67 val prune_prems: theory -> thm -> thm |
67 val prune_prems: theory -> thm -> thm |
650 (defs |> map (fn ((name, atts), (t, ps)) => |
650 (defs |> map (fn ((name, atts), (t, ps)) => |
651 let val (c, t') = ProofContext.cert_def ctxt t |
651 let val (c, t') = ProofContext.cert_def ctxt t |
652 in ((if name = "" then Thm.def_name c else name, atts), [(t', (ps, []))]) end)) |
652 in ((if name = "" then Thm.def_name c else name, atts), [(t', (ps, []))]) end)) |
653 in ((ctxt', axs), []) end |
653 in ((ctxt', axs), []) end |
654 | activate_elem is_ext ((ctxt, axs), Notes facts) = |
654 | activate_elem is_ext ((ctxt, axs), Notes facts) = |
655 let val (ctxt', res) = ctxt |> ProofContext.have_thmss_i facts |
655 let val (ctxt', res) = ctxt |> ProofContext.note_thmss_i facts |
656 in ((ctxt', axs), if is_ext then res else []) end; |
656 in ((ctxt', axs), if is_ext then res else []) end; |
657 |
657 |
658 fun activate_elems ((name, ps), elems) (ctxt, axs) = |
658 fun activate_elems ((name, ps), elems) (ctxt, axs) = |
659 let val ((ctxt', axs'), res) = |
659 let val ((ctxt', axs'), res) = |
660 foldl_map (activate_elem (name = "")) ((ProofContext.qualified true ctxt, axs), elems) |
660 foldl_map (activate_elem (name = "")) ((ProofContext.qualified true ctxt, axs), elems) |
1193 cat_lines (map string_of_thm thms)) |
1193 cat_lines (map string_of_thm thms)) |
1194 (* rename fact *) |
1194 (* rename fact *) |
1195 val facts'' = map (apfst (apfst prefix_fact)) facts' |
1195 val facts'' = map (apfst (apfst prefix_fact)) facts' |
1196 (* add attributes *) |
1196 (* add attributes *) |
1197 val facts''' = map (apfst (apsnd (fn atts => atts @ attribs))) facts'' |
1197 val facts''' = map (apfst (apsnd (fn atts => atts @ attribs))) facts'' |
1198 in fst (ProofContext.have_thmss_i facts''' ctxt) |
1198 in fst (ProofContext.note_thmss_i facts''' ctxt) |
1199 end |
1199 end |
1200 | inst_elem (ctxt, (Int _)) = ctxt; |
1200 | inst_elem (ctxt, (Int _)) = ctxt; |
1201 |
1201 |
1202 fun inst_elems (ctxt, (id, elems)) = foldl inst_elem (ctxt, elems); |
1202 fun inst_elems (ctxt, (id, elems)) = foldl inst_elem (ctxt, elems); |
1203 |
1203 |
1258 thy |> PureThy.hide_thms false |
1258 thy |> PureThy.hide_thms false |
1259 (map (Sign.full_name (Theory.sign_of thy)) (filter_out (equal "") names)); |
1259 (map (Sign.full_name (Theory.sign_of thy)) (filter_out (equal "") names)); |
1260 |
1260 |
1261 in |
1261 in |
1262 |
1262 |
1263 fun have_thmss_qualified kind name args thy = |
1263 fun note_thmss_qualified kind name args thy = |
1264 thy |
1264 thy |
1265 |> Theory.add_path (Sign.base_name name) |
1265 |> Theory.add_path (Sign.base_name name) |
1266 |> PureThy.have_thmss_i (Drule.kind kind) args |
1266 |> PureThy.note_thmss_i (Drule.kind kind) args |
1267 |>> hide_bound_names (map (#1 o #1) args) |
1267 |>> hide_bound_names (map (#1 o #1) args) |
1268 |>> Theory.parent_path; |
1268 |>> Theory.parent_path; |
1269 |
1269 |
1270 fun smart_have_thmss kind None = PureThy.have_thmss_i (Drule.kind kind) |
1270 fun smart_note_thmss kind None = PureThy.note_thmss_i (Drule.kind kind) |
1271 | smart_have_thmss kind (Some (loc, _)) = have_thmss_qualified kind loc; |
1271 | smart_note_thmss kind (Some (loc, _)) = note_thmss_qualified kind loc; |
1272 (* CB: only used in Proof.finish_global. *) |
1272 (* CB: only used in Proof.finish_global. *) |
1273 |
1273 |
1274 end; |
1274 end; |
1275 |
1275 |
1276 local |
1276 local |
1280 val {view, import, elems, params} = the_locale thy loc; |
1280 val {view, import, elems, params} = the_locale thy loc; |
1281 val note = Notes (map (fn ((a, more_atts), th_atts) => |
1281 val note = Notes (map (fn ((a, more_atts), th_atts) => |
1282 ((a, more_atts), map (apfst (map (curry Thm.name_thm a))) th_atts)) args); |
1282 ((a, more_atts), map (apfst (map (curry Thm.name_thm a))) th_atts)) args); |
1283 in thy |> put_locale loc (make_locale view import (elems @ [(note, stamp ())]) params) end; |
1283 in thy |> put_locale loc (make_locale view import (elems @ [(note, stamp ())]) params) end; |
1284 |
1284 |
1285 fun gen_have_thmss prep_locale get_thms kind raw_loc raw_args thy = |
1285 fun gen_note_thmss prep_locale get_thms kind raw_loc raw_args thy = |
1286 let |
1286 let |
1287 val thy_ctxt = ProofContext.init thy; |
1287 val thy_ctxt = ProofContext.init thy; |
1288 val loc = prep_locale (Theory.sign_of thy) raw_loc; |
1288 val loc = prep_locale (Theory.sign_of thy) raw_loc; |
1289 val (_, view, loc_ctxt, _, _) = cert_context_statement (Some loc) [] [] thy_ctxt; |
1289 val (_, view, loc_ctxt, _, _) = cert_context_statement (Some loc) [] [] thy_ctxt; |
1290 val args = map (apsnd (map (apfst (get_thms loc_ctxt)))) raw_args; |
1290 val args = map (apsnd (map (apfst (get_thms loc_ctxt)))) raw_args; |
1291 val export = ProofContext.export_standard view loc_ctxt thy_ctxt; |
1291 val export = ProofContext.export_standard view loc_ctxt thy_ctxt; |
1292 val results = map (map export o #2) (#2 (ProofContext.have_thmss_i args loc_ctxt)); |
1292 val results = map (map export o #2) (#2 (ProofContext.note_thmss_i args loc_ctxt)); |
1293 val args' = map (rpair [] o #1 o #1) args ~~ map (single o Thm.no_attributes) results; |
1293 val args' = map (rpair [] o #1 o #1) args ~~ map (single o Thm.no_attributes) results; |
1294 in |
1294 in |
1295 thy |
1295 thy |
1296 |> put_facts loc args |
1296 |> put_facts loc args |
1297 |> have_thmss_qualified kind loc args' |
1297 |> note_thmss_qualified kind loc args' |
1298 end; |
1298 end; |
1299 |
1299 |
1300 in |
1300 in |
1301 |
1301 |
1302 val have_thmss = gen_have_thmss intern ProofContext.get_thms; |
1302 val note_thmss = gen_note_thmss intern ProofContext.get_thms; |
1303 val have_thmss_i = gen_have_thmss (K I) (K I); |
1303 val note_thmss_i = gen_note_thmss (K I) (K I); |
1304 (* CB: have_thmss(_i) is the base for the Isar commands |
1304 (* CB: note_thmss(_i) is the base for the Isar commands |
1305 "theorems (in loc)" and "declare (in loc)". *) |
1305 "theorems (in loc)" and "declare (in loc)". *) |
1306 |
1306 |
1307 fun add_thmss loc args (thy, ctxt) = |
1307 fun add_thmss loc args (thy, ctxt) = |
1308 let |
1308 let |
1309 val args' = map (fn ((a, ths), atts) => ((a, atts), [(ths, [])])) args; |
1309 val args' = map (fn ((a, ths), atts) => ((a, atts), [(ths, [])])) args; |
1403 val (def_thy, (statement, intro, axioms)) = |
1403 val (def_thy, (statement, intro, axioms)) = |
1404 thy |> def_pred aname parms defs exts exts'; |
1404 thy |> def_pred aname parms defs exts exts'; |
1405 val elemss' = change_elemss axioms elemss @ |
1405 val elemss' = change_elemss axioms elemss @ |
1406 [(("", []), [Assumes [((bname ^ "_" ^ axiomsN, []), [(statement, ([], []))])]])]; |
1406 [(("", []), [Assumes [((bname ^ "_" ^ axiomsN, []), [(statement, ([], []))])]])]; |
1407 in |
1407 in |
1408 def_thy |> have_thmss_qualified "" aname |
1408 def_thy |> note_thmss_qualified "" aname |
1409 [((introN, []), [([intro], [])])] |
1409 [((introN, []), [([intro], [])])] |
1410 |> #1 |> rpair (elemss', [statement]) |
1410 |> #1 |> rpair (elemss', [statement]) |
1411 end; |
1411 end; |
1412 val (thy'', view) = |
1412 val (thy'', view) = |
1413 if Library.null ints then (thy', ([], [])) |
1413 if Library.null ints then (thy', ([], [])) |
1415 let |
1415 let |
1416 val (def_thy, (statement, intro, axioms)) = |
1416 val (def_thy, (statement, intro, axioms)) = |
1417 thy' |> def_pred bname parms defs (ints @ more_ts) (ints' @ more_ts); |
1417 thy' |> def_pred bname parms defs (ints @ more_ts) (ints' @ more_ts); |
1418 val cstatement = Thm.cterm_of (Theory.sign_of def_thy) statement; |
1418 val cstatement = Thm.cterm_of (Theory.sign_of def_thy) statement; |
1419 in |
1419 in |
1420 def_thy |> have_thmss_qualified "" bname |
1420 def_thy |> note_thmss_qualified "" bname |
1421 [((introN, []), [([intro], [])]), |
1421 [((introN, []), [([intro], [])]), |
1422 ((axiomsN, []), [(map Drule.standard axioms, [])])] |
1422 ((axiomsN, []), [(map Drule.standard axioms, [])])] |
1423 |> #1 |> rpair ([cstatement], axioms) |
1423 |> #1 |> rpair ([cstatement], axioms) |
1424 end; |
1424 end; |
1425 in (thy'', (elemss', view)) end; |
1425 in (thy'', (elemss', view)) end; |
1453 val ((ctxt, _), (_, facts)) = activate_facts (K I) ((pred_ctxt, view_axioms), elemss'); |
1453 val ((ctxt, _), (_, facts)) = activate_facts (K I) ((pred_ctxt, view_axioms), elemss'); |
1454 val export = ProofContext.export_standard view_statement ctxt pred_ctxt; |
1454 val export = ProofContext.export_standard view_statement ctxt pred_ctxt; |
1455 val facts' = facts |> map (fn (a, ths) => ((a, []), [(map export ths, [])])); |
1455 val facts' = facts |> map (fn (a, ths) => ((a, []), [(map export ths, [])])); |
1456 in |
1456 in |
1457 pred_thy |
1457 pred_thy |
1458 |> have_thmss_qualified "" name facts' |> #1 |
1458 |> note_thmss_qualified "" name facts' |> #1 |
1459 |> declare_locale name |
1459 |> declare_locale name |
1460 |> put_locale name (make_locale view (prep_expr sign raw_import) |
1460 |> put_locale name (make_locale view (prep_expr sign raw_import) |
1461 (map (fn e => (e, stamp ())) (flat (map #2 (filter (equal "" o #1 o #1) elemss')))) |
1461 (map (fn e => (e, stamp ())) (flat (map #2 (filter (equal "" o #1 o #1) elemss')))) |
1462 (params_of elemss', map #1 (params_of body_elemss))) |
1462 (params_of elemss', map #1 (params_of body_elemss))) |
1463 end; |
1463 end; |