89 ((bstring * Attrib.src list) * (thmref * Attrib.src list) list) list -> |
89 ((bstring * Attrib.src list) * (thmref * Attrib.src list) list) list -> |
90 theory -> (theory * ProofContext.context) * (bstring * thm list) list |
90 theory -> (theory * ProofContext.context) * (bstring * thm list) list |
91 val note_thmss_i: string -> string -> |
91 val note_thmss_i: string -> string -> |
92 ((bstring * Attrib.src list) * (thm list * Attrib.src list) list) list -> |
92 ((bstring * Attrib.src list) * (thm list * Attrib.src list) list) list -> |
93 theory -> (theory * ProofContext.context) * (bstring * thm list) list |
93 theory -> (theory * ProofContext.context) * (bstring * thm list) list |
94 val theorem: string -> (context * thm list -> thm list list -> theory -> theory) -> |
94 val theorem: string -> Method.text option -> |
|
95 (context * thm list -> thm list list -> theory -> theory) -> |
95 string * Attrib.src list -> element elem_expr list -> |
96 string * Attrib.src list -> element elem_expr list -> |
96 ((string * Attrib.src list) * (string * (string list * string list)) list) list -> |
97 ((string * Attrib.src list) * (string * (string list * string list)) list) list -> |
97 theory -> Proof.state |
98 theory -> Proof.state |
98 val theorem_i: string -> (context * thm list -> thm list list -> theory -> theory) -> |
99 val theorem_i: string -> Method.text option -> |
|
100 (context * thm list -> thm list list -> theory -> theory) -> |
99 string * theory attribute list -> element_i elem_expr list -> |
101 string * theory attribute list -> element_i elem_expr list -> |
100 ((string * theory attribute list) * (term * (term list * term list)) list) list -> |
102 ((string * theory attribute list) * (term * (term list * term list)) list) list -> |
101 theory -> Proof.state |
103 theory -> Proof.state |
102 val theorem_in_locale: string -> |
104 val theorem_in_locale: string -> Method.text option -> |
103 ((context * context) * thm list -> thm list list -> theory -> theory) -> |
105 ((context * context) * thm list -> thm list list -> theory -> theory) -> |
104 xstring -> string * Attrib.src list -> element elem_expr list -> |
106 xstring -> string * Attrib.src list -> element elem_expr list -> |
105 ((string * Attrib.src list) * (string * (string list * string list)) list) list -> |
107 ((string * Attrib.src list) * (string * (string list * string list)) list) list -> |
106 theory -> Proof.state |
108 theory -> Proof.state |
107 val theorem_in_locale_i: string -> |
109 val theorem_in_locale_i: string -> Method.text option -> |
108 ((context * context) * thm list -> thm list list -> theory -> theory) -> |
110 ((context * context) * thm list -> thm list list -> theory -> theory) -> |
109 string -> string * Attrib.src list -> element_i elem_expr list -> |
111 string -> string * Attrib.src list -> element_i elem_expr list -> |
110 ((string * Attrib.src list) * (term * (term list * term list)) list) list -> |
112 ((string * Attrib.src list) * (term * (term list * term list)) list) list -> |
111 theory -> Proof.state |
113 theory -> Proof.state |
112 val smart_theorem: string -> xstring option -> |
114 val smart_theorem: string -> xstring option -> |
1085 | activate_elem _ ((ctxt, Assumed axs), Assumes asms) = |
1087 | activate_elem _ ((ctxt, Assumed axs), Assumes asms) = |
1086 let |
1088 let |
1087 val asms' = Attrib.map_specs (Attrib.context_attribute_i ctxt) asms; |
1089 val asms' = Attrib.map_specs (Attrib.context_attribute_i ctxt) asms; |
1088 val ts = List.concat (map (map #1 o #2) asms'); |
1090 val ts = List.concat (map (map #1 o #2) asms'); |
1089 val (ps, qs) = splitAt (length ts, axs); |
1091 val (ps, qs) = splitAt (length ts, axs); |
1090 val (ctxt', _) = |
1092 val (_, ctxt') = |
1091 ctxt |> ProofContext.fix_frees ts |
1093 ctxt |> ProofContext.fix_frees ts |
1092 |> ProofContext.assume_i (export_axioms ps) asms'; |
1094 |> ProofContext.assume_i (export_axioms ps) asms'; |
1093 in ((ctxt', Assumed qs), []) end |
1095 in ((ctxt', Assumed qs), []) end |
1094 | activate_elem _ ((ctxt, Derived ths), Assumes asms) = |
1096 | activate_elem _ ((ctxt, Derived ths), Assumes asms) = |
1095 ((ctxt, Derived ths), []) |
1097 ((ctxt, Derived ths), []) |
1096 | activate_elem _ ((ctxt, Assumed axs), Defines defs) = |
1098 | activate_elem _ ((ctxt, Assumed axs), Defines defs) = |
1097 let |
1099 let |
1098 val defs' = Attrib.map_specs (Attrib.context_attribute_i ctxt) defs; |
1100 val defs' = Attrib.map_specs (Attrib.context_attribute_i ctxt) defs; |
1099 val (ctxt', _) = |
1101 val (_, ctxt') = |
1100 ctxt |> ProofContext.assume_i ProofContext.export_def |
1102 ctxt |> ProofContext.assume_i ProofContext.export_def |
1101 (defs' |> map (fn ((name, atts), (t, ps)) => |
1103 (defs' |> map (fn ((name, atts), (t, ps)) => |
1102 let val (c, t') = ProofContext.cert_def ctxt t |
1104 let val (c, t') = ProofContext.cert_def ctxt t |
1103 in ((if name = "" then Thm.def_name c else name, atts), [(t', (ps, []))]) end)) |
1105 in ((if name = "" then Thm.def_name c else name, atts), [(t', (ps, []))]) end)) |
1104 in ((ctxt', Assumed axs), []) end |
1106 in ((ctxt', Assumed axs), []) end |
1105 | activate_elem _ ((ctxt, Derived ths), Defines defs) = |
1107 | activate_elem _ ((ctxt, Derived ths), Defines defs) = |
1106 ((ctxt, Derived ths), []) |
1108 ((ctxt, Derived ths), []) |
1107 | activate_elem is_ext ((ctxt, mode), Notes facts) = |
1109 | activate_elem is_ext ((ctxt, mode), Notes facts) = |
1108 let |
1110 let |
1109 val facts' = Attrib.map_facts (Attrib.context_attribute_i ctxt) facts; |
1111 val facts' = Attrib.map_facts (Attrib.context_attribute_i ctxt) facts; |
1110 val (ctxt', res) = ctxt |> ProofContext.note_thmss_i facts'; |
1112 val (res, ctxt') = ctxt |> ProofContext.note_thmss_i facts'; |
1111 in ((ctxt', mode), if is_ext then res else []) end; |
1113 in ((ctxt', mode), if is_ext then res else []) end; |
1112 |
1114 |
1113 fun activate_elems (((name, ps), mode), elems) ctxt = |
1115 fun activate_elems (((name, ps), mode), elems) ctxt = |
1114 let |
1116 let |
1115 val ((ctxt', _), res) = |
1117 val ((ctxt', _), res) = |
2050 local |
2052 local |
2051 |
2053 |
2052 fun global_goal prep_att = |
2054 fun global_goal prep_att = |
2053 Proof.global_goal ProofDisplay.present_results prep_att ProofContext.bind_propp_schematic_i; |
2055 Proof.global_goal ProofDisplay.present_results prep_att ProofContext.bind_propp_schematic_i; |
2054 |
2056 |
2055 fun gen_theorem prep_att prep_elem prep_stmt kind after_qed a raw_elems concl thy = |
2057 fun gen_theorem prep_att prep_elem prep_stmt kind before_qed after_qed a raw_elems concl thy = |
2056 let |
2058 let |
2057 val thy_ctxt = ProofContext.init thy; |
2059 val thy_ctxt = ProofContext.init thy; |
2058 val elems = map (prep_elem thy) raw_elems; |
2060 val elems = map (prep_elem thy) raw_elems; |
2059 val (_, (_, view), _, ctxt, propp) = prep_stmt NONE elems (map snd concl) thy_ctxt; |
2061 val (_, (_, view), _, ctxt, propp) = prep_stmt NONE elems (map snd concl) thy_ctxt; |
2060 val ctxt' = ctxt |> ProofContext.add_view thy_ctxt view; |
2062 val ctxt' = ctxt |> ProofContext.add_view thy_ctxt view; |
2061 val stmt = map fst concl ~~ propp; |
2063 val stmt = map fst concl ~~ propp; |
2062 in global_goal prep_att kind after_qed (SOME "") a stmt ctxt' end; |
2064 in global_goal prep_att kind before_qed after_qed (SOME "") a stmt ctxt' end; |
2063 |
2065 |
2064 fun gen_theorem_in_locale prep_locale prep_src prep_elem prep_stmt no_target |
2066 fun gen_theorem_in_locale prep_locale prep_src prep_elem prep_stmt no_target |
2065 kind after_qed raw_locale (name, atts) raw_elems concl thy = |
2067 kind before_qed after_qed raw_locale (name, atts) raw_elems concl thy = |
2066 let |
2068 let |
2067 val locale = prep_locale thy raw_locale; |
2069 val locale = prep_locale thy raw_locale; |
2068 val locale_atts = map (prep_src thy) atts; |
2070 val locale_atts = map (prep_src thy) atts; |
2069 val locale_attss = map (map (prep_src thy) o snd o fst) concl; |
2071 val locale_attss = map (map (prep_src thy) o snd o fst) concl; |
2070 val target = if no_target then NONE else SOME (extern thy locale); |
2072 val target = if no_target then NONE else SOME (extern thy locale); |
2088 if name = "" andalso null locale_atts then I |
2090 if name = "" andalso null locale_atts then I |
2089 else #2 o add_thmss kind locale [((name, locale_atts), List.concat (map #2 res'))]) |
2091 else #2 o add_thmss kind locale [((name, locale_atts), List.concat (map #2 res'))]) |
2090 #> #2 |
2092 #> #2 |
2091 #> after_qed ((goal_ctxt, locale_ctxt'), raw_results) results |
2093 #> after_qed ((goal_ctxt, locale_ctxt'), raw_results) results |
2092 end; |
2094 end; |
2093 in global_goal (K I) kind after_qed' target (name, []) stmt elems_ctxt'' end; |
2095 in global_goal (K I) kind before_qed after_qed' target (name, []) stmt elems_ctxt'' end; |
2094 |
2096 |
2095 in |
2097 in |
2096 |
2098 |
2097 val theorem = gen_theorem Attrib.global_attribute intern_attrib_elem_expr read_context_statement; |
2099 val theorem = gen_theorem Attrib.global_attribute intern_attrib_elem_expr read_context_statement; |
2098 val theorem_i = gen_theorem (K I) (K I) cert_context_statement; |
2100 val theorem_i = gen_theorem (K I) (K I) cert_context_statement; |
2101 val theorem_in_locale_i = gen_theorem_in_locale (K I) (K I) (K I) cert_context_statement false; |
2103 val theorem_in_locale_i = gen_theorem_in_locale (K I) (K I) (K I) cert_context_statement false; |
2102 val theorem_in_locale_no_target = |
2104 val theorem_in_locale_no_target = |
2103 gen_theorem_in_locale (K I) (K I) (K I) cert_context_statement true; |
2105 gen_theorem_in_locale (K I) (K I) (K I) cert_context_statement true; |
2104 |
2106 |
2105 fun smart_theorem kind NONE a [] concl = |
2107 fun smart_theorem kind NONE a [] concl = |
2106 Proof.theorem kind (K (K I)) (SOME "") a concl o ProofContext.init |
2108 Proof.theorem kind NONE (K (K I)) (SOME "") a concl o ProofContext.init |
2107 | smart_theorem kind NONE a elems concl = |
2109 | smart_theorem kind NONE a elems concl = |
2108 theorem kind (K (K I)) a elems concl |
2110 theorem kind NONE (K (K I)) a elems concl |
2109 | smart_theorem kind (SOME loc) a elems concl = |
2111 | smart_theorem kind (SOME loc) a elems concl = |
2110 theorem_in_locale kind (K (K I)) loc a elems concl; |
2112 theorem_in_locale kind NONE (K (K I)) loc a elems concl; |
2111 |
2113 |
2112 end; |
2114 end; |
2113 |
2115 |
2114 |
2116 |
2115 (** Interpretation commands **) |
2117 (** Interpretation commands **) |
2420 val thy_ctxt = ProofContext.init thy; |
2422 val thy_ctxt = ProofContext.init thy; |
2421 val (propss, activate) = prep_global_registration (prfx, atts) expr insts thy; |
2423 val (propss, activate) = prep_global_registration (prfx, atts) expr insts thy; |
2422 val kind = goal_name thy "interpretation" NONE propss; |
2424 val kind = goal_name thy "interpretation" NONE propss; |
2423 fun after_qed (goal_ctxt, raw_results) _ = |
2425 fun after_qed (goal_ctxt, raw_results) _ = |
2424 activate (map (ProofContext.export_plain goal_ctxt thy_ctxt) raw_results); |
2426 activate (map (ProofContext.export_plain goal_ctxt thy_ctxt) raw_results); |
2425 in Proof.theorem_i kind after_qed NONE ("", []) (prep_propp propss) thy_ctxt end; |
2427 in Proof.theorem_i kind NONE after_qed NONE ("", []) (prep_propp propss) thy_ctxt end; |
2426 |
2428 |
2427 fun interpretation_in_locale (raw_target, expr) thy = |
2429 fun interpretation_in_locale (raw_target, expr) thy = |
2428 let |
2430 let |
2429 val target = intern thy raw_target; |
2431 val target = intern thy raw_target; |
2430 val (propss, activate) = prep_registration_in_locale target expr thy; |
2432 val (propss, activate) = prep_registration_in_locale target expr thy; |
2431 val kind = goal_name thy "interpretation" (SOME target) propss; |
2433 val kind = goal_name thy "interpretation" (SOME target) propss; |
2432 fun after_qed ((goal_ctxt, locale_ctxt), raw_results) _ = |
2434 fun after_qed ((goal_ctxt, locale_ctxt), raw_results) _ = |
2433 activate (map (ProofContext.export_plain goal_ctxt locale_ctxt) raw_results); |
2435 activate (map (ProofContext.export_plain goal_ctxt locale_ctxt) raw_results); |
2434 in theorem_in_locale_no_target kind after_qed target ("", []) [] (prep_propp propss) thy end; |
2436 in theorem_in_locale_no_target kind NONE after_qed target ("", []) [] (prep_propp propss) thy end; |
2435 |
2437 |
2436 fun interpret (prfx, atts) expr insts int state = |
2438 fun interpret (prfx, atts) expr insts int state = |
2437 let |
2439 let |
2438 val ctxt = Proof.context_of state; |
2440 val ctxt = Proof.context_of state; |
2439 val (propss, activate) = prep_local_registration (prfx, atts) expr insts ctxt; |
2441 val (propss, activate) = prep_local_registration (prfx, atts) expr insts ctxt; |