| author | wenzelm | 
| Fri, 17 Mar 2023 12:10:14 +0100 | |
| changeset 77683 | 3e8e749935fc | 
| parent 74338 | 534b231ce041 | 
| child 78055 | 2d60172c0ade | 
| permissions | -rw-r--r-- | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 1 | (* Title: Pure/Isar/specification.ML | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 2 | Author: Makarius | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 3 | |
| 21036 | 4 | Derived local theory specifications --- with type-inference and | 
| 18810 | 5 | toplevel polymorphism. | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 6 | *) | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 7 | |
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 8 | signature SPECIFICATION = | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 9 | sig | 
| 59844 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 10 | val read_props: string list -> (binding * string option * mixfix) list -> Proof.context -> | 
| 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 11 | term list * Proof.context | 
| 63180 | 12 | val check_spec_open: (binding * typ option * mixfix) list -> | 
| 13 | (binding * typ option * mixfix) list -> term list -> term -> Proof.context -> | |
| 63395 | 14 | ((binding * typ option * mixfix) list * string list * (string -> Position.T list) * term) * | 
| 63180 | 15 | Proof.context | 
| 16 | val read_spec_open: (binding * string option * mixfix) list -> | |
| 17 | (binding * string option * mixfix) list -> string list -> string -> Proof.context -> | |
| 63395 | 18 | ((binding * typ option * mixfix) list * string list * (string -> Position.T list) * term) * | 
| 63180 | 19 | Proof.context | 
| 63182 | 20 | type multi_specs = | 
| 21 | ((Attrib.binding * term) * term list * (binding * typ option * mixfix) list) list | |
| 22 | type multi_specs_cmd = | |
| 23 | ((Attrib.binding * string) * string list * (binding * string option * mixfix) list) list | |
| 63064 
2f18172214c8
support 'assumes' in specifications, e.g. 'definition', 'inductive';
 wenzelm parents: 
63063diff
changeset | 24 | val check_multi_specs: (binding * typ option * mixfix) list -> multi_specs -> Proof.context -> | 
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 25 | (((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context | 
| 63064 
2f18172214c8
support 'assumes' in specifications, e.g. 'definition', 'inductive';
 wenzelm parents: 
63063diff
changeset | 26 | val read_multi_specs: (binding * string option * mixfix) list -> multi_specs_cmd -> Proof.context -> | 
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 27 | (((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context | 
| 63178 | 28 | val axiomatization: (binding * typ option * mixfix) list -> | 
| 29 | (binding * typ option * mixfix) list -> term list -> | |
| 30 | (Attrib.binding * term) list -> theory -> (term list * thm list) * theory | |
| 31 | val axiomatization_cmd: (binding * string option * mixfix) list -> | |
| 32 | (binding * string option * mixfix) list -> string list -> | |
| 33 | (Attrib.binding * string) list -> theory -> (term list * thm list) * theory | |
| 35894 | 34 | val axiom: Attrib.binding * term -> theory -> thm * theory | 
| 63180 | 35 | val definition: (binding * typ option * mixfix) option -> | 
| 36 | (binding * typ option * mixfix) list -> term list -> Attrib.binding * term -> | |
| 37 | local_theory -> (term * (string * thm)) * local_theory | |
| 38 | val definition_cmd: (binding * string option * mixfix) option -> | |
| 39 | (binding * string option * mixfix) list -> string list -> Attrib.binding * string -> | |
| 40 | bool -> local_theory -> (term * (string * thm)) * local_theory | |
| 41 | val abbreviation: Syntax.mode -> (binding * typ option * mixfix) option -> | |
| 42 | (binding * typ option * mixfix) list -> term -> bool -> local_theory -> local_theory | |
| 43 | val abbreviation_cmd: Syntax.mode -> (binding * string option * mixfix) option -> | |
| 44 | (binding * string option * mixfix) list -> string -> bool -> local_theory -> local_theory | |
| 66248 | 45 | val alias: binding * string -> local_theory -> local_theory | 
| 46 | val alias_cmd: binding * (xstring * Position.T) -> local_theory -> local_theory | |
| 47 | val type_alias: binding * string -> local_theory -> local_theory | |
| 48 | val type_alias_cmd: binding * (xstring * Position.T) -> local_theory -> local_theory | |
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 49 | val theorems: string -> | 
| 63267 | 50 | (Attrib.binding * Attrib.thms) list -> | 
| 45600 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 51 | (binding * typ option * mixfix) list -> | 
| 44192 
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
 wenzelm parents: 
43329diff
changeset | 52 | bool -> local_theory -> (string * thm list) list * local_theory | 
| 26336 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 wenzelm parents: 
25371diff
changeset | 53 | val theorems_cmd: string -> | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
56932diff
changeset | 54 | (Attrib.binding * (Facts.ref * Token.src list) list) list -> | 
| 45600 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 55 | (binding * string option * mixfix) list -> | 
| 44192 
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
 wenzelm parents: 
43329diff
changeset | 56 | bool -> local_theory -> (string * thm list) list * local_theory | 
| 63094 
056ea294c256
toplevel theorem statements support 'if'/'for' eigen-context;
 wenzelm parents: 
63069diff
changeset | 57 | val theorem: bool -> string -> Method.text option -> | 
| 28084 
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
 wenzelm parents: 
28080diff
changeset | 58 | (thm list list -> local_theory -> local_theory) -> Attrib.binding -> | 
| 47067 
4ef29b0c568f
optional 'includes' element for long theorem statements;
 wenzelm parents: 
47066diff
changeset | 59 | string list -> Element.context_i list -> Element.statement_i -> | 
| 24452 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 berghofe parents: 
24219diff
changeset | 60 | bool -> local_theory -> Proof.state | 
| 63094 
056ea294c256
toplevel theorem statements support 'if'/'for' eigen-context;
 wenzelm parents: 
63069diff
changeset | 61 | val theorem_cmd: bool -> string -> Method.text option -> | 
| 28084 
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
 wenzelm parents: 
28080diff
changeset | 62 | (thm list list -> local_theory -> local_theory) -> Attrib.binding -> | 
| 47067 
4ef29b0c568f
optional 'includes' element for long theorem statements;
 wenzelm parents: 
47066diff
changeset | 63 | (xstring * Position.T) list -> Element.context list -> Element.statement -> | 
| 24452 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 berghofe parents: 
24219diff
changeset | 64 | bool -> local_theory -> Proof.state | 
| 63094 
056ea294c256
toplevel theorem statements support 'if'/'for' eigen-context;
 wenzelm parents: 
63069diff
changeset | 65 | val schematic_theorem: bool -> string -> Method.text option -> | 
| 36317 
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
 wenzelm parents: 
36106diff
changeset | 66 | (thm list list -> local_theory -> local_theory) -> Attrib.binding -> | 
| 47067 
4ef29b0c568f
optional 'includes' element for long theorem statements;
 wenzelm parents: 
47066diff
changeset | 67 | string list -> Element.context_i list -> Element.statement_i -> | 
| 36317 
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
 wenzelm parents: 
36106diff
changeset | 68 | bool -> local_theory -> Proof.state | 
| 63094 
056ea294c256
toplevel theorem statements support 'if'/'for' eigen-context;
 wenzelm parents: 
63069diff
changeset | 69 | val schematic_theorem_cmd: bool -> string -> Method.text option -> | 
| 36317 
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
 wenzelm parents: 
36106diff
changeset | 70 | (thm list list -> local_theory -> local_theory) -> Attrib.binding -> | 
| 47067 
4ef29b0c568f
optional 'includes' element for long theorem statements;
 wenzelm parents: 
47066diff
changeset | 71 | (xstring * Position.T) list -> Element.context list -> Element.statement -> | 
| 36317 
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
 wenzelm parents: 
36106diff
changeset | 72 | bool -> local_theory -> Proof.state | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 73 | end; | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 74 | |
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 75 | structure Specification: SPECIFICATION = | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 76 | struct | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 77 | |
| 59844 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 78 | (* prepare propositions *) | 
| 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 79 | |
| 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 80 | fun read_props raw_props raw_fixes ctxt = | 
| 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 81 | let | 
| 60469 | 82 | val (_, ctxt1) = ctxt |> Proof_Context.add_fixes_cmd raw_fixes; | 
| 59844 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 83 | val props1 = map (Syntax.parse_prop ctxt1) raw_props; | 
| 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 84 | val (props2, ctxt2) = ctxt1 |> fold_map Variable.fix_dummy_patterns props1; | 
| 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 85 | val props3 = Syntax.check_props ctxt2 props2; | 
| 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 86 | val ctxt3 = ctxt2 |> fold Variable.declare_term props3; | 
| 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 87 | in (props3, ctxt3) end; | 
| 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 88 | |
| 
c648efffea73
support for minimal specifications, with usual treatment of fixes and dummies;
 wenzelm parents: 
58993diff
changeset | 89 | |
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 90 | (* prepare specification *) | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 91 | |
| 63394 | 92 | fun get_positions ctxt x = | 
| 93 | let | |
| 94 |     fun get Cs (Const ("_type_constraint_", C) $ t) = get (C :: Cs) t
 | |
| 95 | | get Cs (Free (y, T)) = | |
| 96 | if x = y then | |
| 97 | map_filter Term_Position.decode_positionT | |
| 98 | (T :: map (Type.constraint_type ctxt) Cs) | |
| 99 | else [] | |
| 100 | | get _ (t $ u) = get [] t @ get [] u | |
| 101 | | get _ (Abs (_, _, t)) = get [] t | |
| 102 | | get _ _ = []; | |
| 103 | in get [] end; | |
| 104 | ||
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 105 | local | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 106 | |
| 63180 | 107 | fun prep_decls prep_var raw_vars ctxt = | 
| 108 | let | |
| 109 | val (vars, ctxt') = fold_map prep_var raw_vars ctxt; | |
| 110 | val (xs, ctxt'') = ctxt' | |
| 111 | |> Context_Position.set_visible false | |
| 112 | |> Proof_Context.add_fixes vars | |
| 113 | ||> Context_Position.restore_visible ctxt'; | |
| 114 | val _ = | |
| 115 | Context_Position.reports ctxt'' | |
| 116 | (map (Binding.pos_of o #1) vars ~~ | |
| 117 | map (Variable.markup_entity_def ctxt'' ##> Properties.remove Markup.kindN) xs); | |
| 118 | in ((vars, xs), ctxt'') end; | |
| 119 | ||
| 63182 | 120 | fun close_form ctxt ys prems concl = | 
| 63396 | 121 | let | 
| 122 | val xs = rev (fold (Variable.add_free_names ctxt) (prems @ [concl]) (rev ys)); | |
| 123 | ||
| 124 | val pos_props = Logic.strip_imp_concl concl :: Logic.strip_imp_prems concl @ prems; | |
| 125 | fun get_pos x = maps (get_positions ctxt x) pos_props; | |
| 126 | val _ = Context_Position.reports ctxt (maps (Syntax_Phases.reports_of_scope o get_pos) xs); | |
| 63180 | 127 | in Logic.close_prop_constraint (Variable.default_type ctxt) (xs ~~ xs) prems concl end; | 
| 128 | ||
| 129 | fun dummy_frees ctxt xs tss = | |
| 130 | let | |
| 131 | val names = | |
| 132 | Variable.names_of ((fold o fold) Variable.declare_term tss ctxt) | |
| 133 | |> fold Name.declare xs; | |
| 134 | val (tss', _) = (fold_map o fold_map) Term.free_dummy_patterns tss names; | |
| 135 | in tss' end; | |
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 136 | |
| 63180 | 137 | fun prep_spec_open prep_var parse_prop raw_vars raw_params raw_prems raw_concl ctxt = | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 138 | let | 
| 63180 | 139 | val ((vars, xs), vars_ctxt) = prep_decls prep_var raw_vars ctxt; | 
| 140 | val (ys, params_ctxt) = vars_ctxt |> fold_map prep_var raw_params |-> Proof_Context.add_fixes; | |
| 141 | ||
| 142 | val props = | |
| 143 | map (parse_prop params_ctxt) (raw_concl :: raw_prems) | |
| 144 | |> singleton (dummy_frees params_ctxt (xs @ ys)); | |
| 145 | ||
| 146 | val concl :: prems = Syntax.check_props params_ctxt props; | |
| 147 | val spec = Logic.list_implies (prems, concl); | |
| 148 | val spec_ctxt = Variable.declare_term spec params_ctxt; | |
| 149 | ||
| 63395 | 150 | fun get_pos x = maps (get_positions spec_ctxt x) props; | 
| 63180 | 151 | in ((vars, xs, get_pos, spec), spec_ctxt) end; | 
| 152 | ||
| 153 | fun prep_specs prep_var parse_prop prep_att raw_vars raw_specss ctxt = | |
| 154 | let | |
| 155 | val ((vars, xs), vars_ctxt) = prep_decls prep_var raw_vars ctxt; | |
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 156 | |
| 63179 | 157 | val propss0 = | 
| 63182 | 158 | raw_specss |> map (fn ((_, raw_concl), raw_prems, raw_params) => | 
| 159 | let val (ys, ctxt') = vars_ctxt |> fold_map prep_var raw_params |-> Proof_Context.add_fixes | |
| 160 | in (ys, map (pair ctxt') (raw_concl :: raw_prems)) end); | |
| 63179 | 161 | val props = | 
| 63182 | 162 | burrow (grouped 10 Par_List.map_independent (uncurry parse_prop)) (map #2 propss0) | 
| 163 | |> dummy_frees vars_ctxt xs | |
| 164 | |> map2 (fn (ys, _) => fn concl :: prems => close_form vars_ctxt ys prems concl) propss0; | |
| 61947 | 165 | |
| 63180 | 166 | val specs = Syntax.check_props vars_ctxt props; | 
| 167 | val specs_ctxt = vars_ctxt |> fold Variable.declare_term specs; | |
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 168 | |
| 60407 | 169 | val ps = specs_ctxt |> fold_map Proof_Context.inferred_param xs |> fst; | 
| 170 | val params = map2 (fn (b, _, mx) => fn (_, T) => ((b, T), mx)) vars ps; | |
| 61947 | 171 | val name_atts: Attrib.binding list = | 
| 63179 | 172 | map (fn ((name, atts), _) => (name, map (prep_att ctxt) atts)) (map #1 raw_specss); | 
| 63180 | 173 | in ((params, name_atts ~~ specs), specs_ctxt) end; | 
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 174 | |
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 175 | in | 
| 21370 
d9dd7b4e5e69
replaced Variable.fix_frees by Variable.auto_fixes (depends on body mode);
 wenzelm parents: 
21359diff
changeset | 176 | |
| 63180 | 177 | val check_spec_open = prep_spec_open Proof_Context.cert_var (K I); | 
| 178 | val read_spec_open = prep_spec_open Proof_Context.read_var Syntax.parse_prop; | |
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 179 | |
| 63182 | 180 | type multi_specs = | 
| 181 | ((Attrib.binding * term) * term list * (binding * typ option * mixfix) list) list; | |
| 182 | type multi_specs_cmd = | |
| 183 | ((Attrib.binding * string) * string list * (binding * string option * mixfix) list) list; | |
| 61947 | 184 | |
| 63064 
2f18172214c8
support 'assumes' in specifications, e.g. 'definition', 'inductive';
 wenzelm parents: 
63063diff
changeset | 185 | fun check_multi_specs xs specs = | 
| 63180 | 186 | prep_specs Proof_Context.cert_var (K I) (K I) xs specs; | 
| 63064 
2f18172214c8
support 'assumes' in specifications, e.g. 'definition', 'inductive';
 wenzelm parents: 
63063diff
changeset | 187 | |
| 
2f18172214c8
support 'assumes' in specifications, e.g. 'definition', 'inductive';
 wenzelm parents: 
63063diff
changeset | 188 | fun read_multi_specs xs specs = | 
| 63180 | 189 | prep_specs Proof_Context.read_var Syntax.parse_prop Attrib.check_src xs specs; | 
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 190 | |
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 191 | end; | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 192 | |
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 193 | |
| 28114 | 194 | (* axiomatization -- within global theory *) | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 195 | |
| 63178 | 196 | fun gen_axioms prep_stmt prep_att raw_decls raw_fixes raw_prems raw_concls thy = | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 197 | let | 
| 63178 | 198 | (*specification*) | 
| 70734 | 199 |     val ({vars, propss = [prems, concls], ...}, vars_ctxt) =
 | 
| 63178 | 200 | Proof_Context.init_global thy | 
| 201 | |> prep_stmt (raw_decls @ raw_fixes) ((map o map) (rpair []) [raw_prems, map snd raw_concls]); | |
| 202 | val (decls, fixes) = chop (length raw_decls) vars; | |
| 203 | ||
| 204 | val frees = | |
| 205 | rev ((fold o fold) (Variable.add_frees vars_ctxt) [prems, concls] []) | |
| 206 | |> map (fn (x, T) => (x, Free (x, T))); | |
| 207 | val close = Logic.close_prop (map #2 fixes @ frees) prems; | |
| 208 | val specs = | |
| 209 | map ((apsnd o map) (prep_att vars_ctxt) o fst) raw_concls ~~ map close concls; | |
| 28114 | 210 | |
| 71213 | 211 | val spec_name = | 
| 71214 
5727bcc3c47c
proper spec_rule name via naming/binding/Morphism.binding;
 wenzelm parents: 
71213diff
changeset | 212 | Binding.conglomerate (if null decls then map (#1 o #1) specs else map (#1 o #1) decls); | 
| 71213 | 213 | |
| 214 | ||
| 28114 | 215 | (*consts*) | 
| 63178 | 216 | val (consts, consts_thy) = thy | 
| 217 | |> fold_map (fn ((b, _, mx), (_, t)) => Theory.specify_const ((b, Term.type_of t), mx)) decls; | |
| 218 | val subst = Term.subst_atomic (map (#2 o #2) decls ~~ consts); | |
| 28114 | 219 | |
| 220 | (*axioms*) | |
| 63178 | 221 | val (axioms, axioms_thy) = | 
| 222 | (specs, consts_thy) |-> fold_map (fn ((b, atts), prop) => | |
| 223 | Thm.add_axiom_global (b, subst prop) #>> (fn (_, th) => ((b, atts), [([th], [])]))); | |
| 30470 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 wenzelm parents: 
30434diff
changeset | 224 | |
| 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 wenzelm parents: 
30434diff
changeset | 225 | (*facts*) | 
| 33703 
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
 wenzelm parents: 
33671diff
changeset | 226 | val (facts, facts_lthy) = axioms_thy | 
| 38388 | 227 | |> Named_Target.theory_init | 
| 71213 | 228 | |> Spec_Rules.add spec_name Spec_Rules.Unknown consts (maps (maps #1 o #2) axioms) | 
| 33703 
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
 wenzelm parents: 
33671diff
changeset | 229 | |> Local_Theory.notes axioms; | 
| 30470 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 wenzelm parents: 
30434diff
changeset | 230 | |
| 63178 | 231 | in ((consts, map (the_single o #2) facts), Local_Theory.exit_global facts_lthy) end; | 
| 18786 | 232 | |
| 63178 | 233 | val axiomatization = gen_axioms Proof_Context.cert_stmt (K I); | 
| 234 | val axiomatization_cmd = gen_axioms Proof_Context.read_stmt Attrib.check_src; | |
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 235 | |
| 63178 | 236 | fun axiom (b, ax) = axiomatization [] [] [] [(b, ax)] #>> (hd o snd); | 
| 35894 | 237 | |
| 18786 | 238 | |
| 239 | (* definition *) | |
| 240 | ||
| 63180 | 241 | fun gen_def prep_spec prep_att raw_var raw_params raw_prems ((a, raw_atts), raw_spec) int lthy = | 
| 18786 | 242 | let | 
| 63180 | 243 | val atts = map (prep_att lthy) raw_atts; | 
| 244 | ||
| 63394 | 245 | val ((vars, xs, get_pos, spec), _) = lthy | 
| 63180 | 246 | |> prep_spec (the_list raw_var) raw_params raw_prems raw_spec; | 
| 63395 | 247 |     val (((x, T), rhs), prove) = Local_Defs.derived_def lthy get_pos {conditional = true} spec;
 | 
| 56169 
9b0dc5c704c9
reject internal names, notably from Term.free_dummy_patterns;
 wenzelm parents: 
56026diff
changeset | 248 | val _ = Name.reject_internal (x, []); | 
| 62770 | 249 | val (b, mx) = | 
| 63180 | 250 | (case (vars, xs) of | 
| 63395 | 251 | ([], []) => (Binding.make (x, (case get_pos x of [] => Position.none | p :: _ => p)), NoSyn) | 
| 63180 | 252 | | ([(b, _, mx)], [y]) => | 
| 253 | if x = y then (b, mx) | |
| 254 | else | |
| 255 |             error ("Head of definition " ^ quote x ^ " differs from declaration " ^ quote y ^
 | |
| 256 | Position.here (Binding.pos_of b))); | |
| 71179 | 257 | |
| 63180 | 258 | val name = Thm.def_binding_optional b a; | 
| 33455 
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
 wenzelm parents: 
33389diff
changeset | 259 | val ((lhs, (_, raw_th)), lthy2) = lthy | 
| 62770 | 260 | |> Local_Theory.define_internal ((b, mx), ((Binding.suffix_name "_raw" name, []), rhs)); | 
| 33455 
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
 wenzelm parents: 
33389diff
changeset | 261 | |
| 
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
 wenzelm parents: 
33389diff
changeset | 262 | val th = prove lthy2 raw_th; | 
| 71217 | 263 | val lthy3 = lthy2 |> Spec_Rules.add name Spec_Rules.equational [lhs] [th]; | 
| 33455 
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
 wenzelm parents: 
33389diff
changeset | 264 | |
| 33670 
02b7738aef6a
eliminated slightly odd kind argument of LocalTheory.note(s);
 wenzelm parents: 
33644diff
changeset | 265 | val ([(def_name, [th'])], lthy4) = lthy3 | 
| 66251 
cd935b7cb3fb
proper concept of code declaration wrt. atomicity and Isar declarations
 haftmann parents: 
66248diff
changeset | 266 | |> Local_Theory.notes [((name, atts), [([th], [])])]; | 
| 18786 | 267 | |
| 66251 
cd935b7cb3fb
proper concept of code declaration wrt. atomicity and Isar declarations
 haftmann parents: 
66248diff
changeset | 268 | val lthy5 = lthy4 | 
| 
cd935b7cb3fb
proper concept of code declaration wrt. atomicity and Isar declarations
 haftmann parents: 
66248diff
changeset | 269 | |> Code.declare_default_eqns [(th', true)]; | 
| 
cd935b7cb3fb
proper concept of code declaration wrt. atomicity and Isar declarations
 haftmann parents: 
66248diff
changeset | 270 | |
| 
cd935b7cb3fb
proper concept of code declaration wrt. atomicity and Isar declarations
 haftmann parents: 
66248diff
changeset | 271 | val lhs' = Morphism.term (Local_Theory.target_morphism lthy5) lhs; | 
| 44192 
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
 wenzelm parents: 
43329diff
changeset | 272 | |
| 56932 
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
 wenzelm parents: 
56897diff
changeset | 273 | val _ = | 
| 66251 
cd935b7cb3fb
proper concept of code declaration wrt. atomicity and Isar declarations
 haftmann parents: 
66248diff
changeset | 274 | Proof_Display.print_consts int (Position.thread_data ()) lthy5 | 
| 74266 | 275 | (Frees.defined (Frees.build (Frees.add_frees lhs'))) [(x, T)]; | 
| 66251 
cd935b7cb3fb
proper concept of code declaration wrt. atomicity and Isar declarations
 haftmann parents: 
66248diff
changeset | 276 | in ((lhs, (def_name, th')), lthy5) end; | 
| 18786 | 277 | |
| 74285 | 278 | fun definition xs ys As B = gen_def check_spec_open (K I) xs ys As B false; | 
| 63180 | 279 | val definition_cmd = gen_def read_spec_open Attrib.check_src; | 
| 18786 | 280 | |
| 19080 | 281 | |
| 282 | (* abbreviation *) | |
| 283 | ||
| 63180 | 284 | fun gen_abbrev prep_spec mode raw_var raw_params raw_spec int lthy = | 
| 19080 | 285 | let | 
| 63180 | 286 | val lthy1 = lthy |> Proof_Context.set_syntax_mode mode; | 
| 63394 | 287 | val ((vars, xs, get_pos, spec), _) = lthy | 
| 63180 | 288 | |> Proof_Context.set_mode Proof_Context.mode_abbrev | 
| 289 | |> prep_spec (the_list raw_var) raw_params [] raw_spec; | |
| 63395 | 290 | val ((x, T), rhs) = Local_Defs.abs_def (#2 (Local_Defs.cert_def lthy1 get_pos spec)); | 
| 56169 
9b0dc5c704c9
reject internal names, notably from Term.free_dummy_patterns;
 wenzelm parents: 
56026diff
changeset | 291 | val _ = Name.reject_internal (x, []); | 
| 62770 | 292 | val (b, mx) = | 
| 63180 | 293 | (case (vars, xs) of | 
| 63395 | 294 | ([], []) => (Binding.make (x, (case get_pos x of [] => Position.none | p :: _ => p)), NoSyn) | 
| 63180 | 295 | | ([(b, _, mx)], [y]) => | 
| 296 | if x = y then (b, mx) | |
| 297 | else | |
| 298 |             error ("Head of abbreviation " ^ quote x ^ " differs from declaration " ^ quote y ^
 | |
| 299 | Position.here (Binding.pos_of b))); | |
| 55119 
9ca72949ebac
observe local syntax mode (according to e3a39dae2004, which was lost in 0f3ad56548bc), e.g. relevant for "abbreviation (output)" with non-terminating syntax;
 wenzelm parents: 
54883diff
changeset | 300 | val lthy2 = lthy1 | 
| 62770 | 301 | |> Local_Theory.abbrev mode ((b, mx), rhs) |> snd | 
| 42360 | 302 | |> Proof_Context.restore_syntax_mode lthy; | 
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 303 | |
| 56932 
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
 wenzelm parents: 
56897diff
changeset | 304 | val _ = Proof_Display.print_consts int (Position.thread_data ()) lthy2 (K false) [(x, T)]; | 
| 55119 
9ca72949ebac
observe local syntax mode (according to e3a39dae2004, which was lost in 0f3ad56548bc), e.g. relevant for "abbreviation (output)" with non-terminating syntax;
 wenzelm parents: 
54883diff
changeset | 305 | in lthy2 end; | 
| 19080 | 306 | |
| 63180 | 307 | val abbreviation = gen_abbrev check_spec_open; | 
| 308 | val abbreviation_cmd = gen_abbrev read_spec_open; | |
| 19080 | 309 | |
| 19664 | 310 | |
| 66248 | 311 | (* alias *) | 
| 312 | ||
| 313 | fun gen_alias decl check (b, arg) lthy = | |
| 314 | let | |
| 315 |     val (c, reports) = check {proper = true, strict = false} lthy arg;
 | |
| 71674 | 316 | val _ = Context_Position.reports lthy reports; | 
| 66248 | 317 | in decl b c lthy end; | 
| 318 | ||
| 319 | val alias = | |
| 320 | gen_alias Local_Theory.const_alias (K (K (fn c => (c, [])))); | |
| 321 | val alias_cmd = | |
| 322 | gen_alias Local_Theory.const_alias | |
| 323 | (fn flags => fn ctxt => fn (c, pos) => | |
| 324 | apfst (#1 o dest_Const) (Proof_Context.check_const flags ctxt (c, [pos]))); | |
| 325 | ||
| 326 | val type_alias = | |
| 327 | gen_alias Local_Theory.type_alias (K (K (fn c => (c, [])))); | |
| 328 | val type_alias_cmd = | |
| 329 | gen_alias Local_Theory.type_alias (apfst (#1 o dest_Type) ooo Proof_Context.check_type_name); | |
| 330 | ||
| 331 | ||
| 21036 | 332 | (* fact statements *) | 
| 20914 | 333 | |
| 45600 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 334 | local | 
| 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 335 | |
| 60469 | 336 | fun gen_theorems prep_fact prep_att add_fixes | 
| 45600 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 337 | kind raw_facts raw_fixes int lthy = | 
| 20914 | 338 | let | 
| 339 | val facts = raw_facts |> map (fn ((name, atts), bs) => | |
| 55997 
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
 wenzelm parents: 
55955diff
changeset | 340 | ((name, map (prep_att lthy) atts), | 
| 
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
 wenzelm parents: 
55955diff
changeset | 341 | bs |> map (fn (b, more_atts) => (prep_fact lthy b, map (prep_att lthy) more_atts)))); | 
| 60469 | 342 | val (_, ctxt') = add_fixes raw_fixes lthy; | 
| 45600 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 343 | |
| 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 344 | val facts' = facts | 
| 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 345 | |> Attrib.partial_evaluation ctxt' | 
| 58028 
e4250d370657
tuned signature -- define some elementary operations earlier;
 wenzelm parents: 
58011diff
changeset | 346 | |> Attrib.transform_facts (Proof_Context.export_morphism ctxt' lthy); | 
| 45600 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 347 | val (res, lthy') = lthy |> Local_Theory.notes_kind kind facts'; | 
| 56932 
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
 wenzelm parents: 
56897diff
changeset | 348 | val _ = Proof_Display.print_results int (Position.thread_data ()) lthy' ((kind, ""), res); | 
| 20914 | 349 | in (res, lthy') end; | 
| 350 | ||
| 45600 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 351 | in | 
| 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 352 | |
| 60469 | 353 | val theorems = gen_theorems (K I) (K I) Proof_Context.add_fixes; | 
| 354 | val theorems_cmd = gen_theorems Proof_Context.get_fact Attrib.check_src Proof_Context.add_fixes_cmd; | |
| 45600 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 355 | |
| 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
45584diff
changeset | 356 | end; | 
| 20914 | 357 | |
| 21036 | 358 | |
| 21230 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 wenzelm parents: 
21206diff
changeset | 359 | (* complex goal statements *) | 
| 21036 | 360 | |
| 361 | local | |
| 362 | ||
| 60477 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 363 | fun prep_statement prep_att prep_stmt raw_elems raw_stmt ctxt = | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 364 | let | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 365 | val (stmt, elems_ctxt) = prep_stmt raw_elems raw_stmt ctxt; | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 366 | val prems = Assumption.local_prems_of elems_ctxt ctxt; | 
| 70308 | 367 | val stmt_ctxt = fold (fold (Proof_Context.augment o fst) o snd) stmt elems_ctxt; | 
| 60477 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 368 | in | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 369 | (case raw_stmt of | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 370 | Element.Shows _ => | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 371 | let val stmt' = Attrib.map_specs (map prep_att) stmt | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 372 | in (([], prems, stmt', NONE), stmt_ctxt) end | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 373 | | Element.Obtains raw_obtains => | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 374 | let | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 375 | val asms_ctxt = stmt_ctxt | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 376 | |> fold (fn ((name, _), asm) => | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 377 | snd o Proof_Context.add_assms Assumption.assume_export | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 378 | [((name, [Context_Rules.intro_query NONE]), asm)]) stmt; | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 379 | val that = Assumption.local_prems_of asms_ctxt stmt_ctxt; | 
| 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 380 | val ([(_, that')], that_ctxt) = asms_ctxt | 
| 63096 
7910b1db2596
re-enable fact index for 'obtains' assumption (amending 5c8e6a751adc);
 wenzelm parents: 
63094diff
changeset | 381 | |> Proof_Context.set_stmt true | 
| 
7910b1db2596
re-enable fact index for 'obtains' assumption (amending 5c8e6a751adc);
 wenzelm parents: 
63094diff
changeset | 382 | |> Proof_Context.note_thmss "" [((Binding.name Auto_Bind.thatN, []), [(that, [])])] | 
| 
7910b1db2596
re-enable fact index for 'obtains' assumption (amending 5c8e6a751adc);
 wenzelm parents: 
63094diff
changeset | 383 | ||> Proof_Context.restore_stmt asms_ctxt; | 
| 21036 | 384 | |
| 63352 | 385 | val stmt' = [(Binding.empty_atts, [(#2 (#1 (Obtain.obtain_thesis ctxt)), [])])]; | 
| 63019 | 386 | in ((Obtain.obtains_attribs raw_obtains, prems, stmt', SOME that'), that_ctxt) end) | 
| 60477 
051b200f7578
improved treatment of Element.Obtains via Expression.prepare_stmt;
 wenzelm parents: 
60469diff
changeset | 387 | end; | 
| 21036 | 388 | |
| 56026 
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
 wenzelm parents: 
56002diff
changeset | 389 | fun gen_theorem schematic bundle_includes prep_att prep_stmt | 
| 63094 
056ea294c256
toplevel theorem statements support 'if'/'for' eigen-context;
 wenzelm parents: 
63069diff
changeset | 390 | long kind before_qed after_qed (name, raw_atts) raw_includes raw_elems raw_concl int lthy = | 
| 21036 | 391 | let | 
| 47066 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47021diff
changeset | 392 | val _ = Local_Theory.assert lthy; | 
| 21036 | 393 | |
| 55997 
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
 wenzelm parents: 
55955diff
changeset | 394 | val elems = raw_elems |> map (Element.map_ctxt_attrib (prep_att lthy)); | 
| 47067 
4ef29b0c568f
optional 'includes' element for long theorem statements;
 wenzelm parents: 
47066diff
changeset | 395 | val ((more_atts, prems, stmt, facts), goal_ctxt) = lthy | 
| 56026 
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
 wenzelm parents: 
56002diff
changeset | 396 | |> bundle_includes raw_includes | 
| 55997 
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
 wenzelm parents: 
55955diff
changeset | 397 | |> prep_statement (prep_att lthy) prep_stmt elems raw_concl; | 
| 
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
 wenzelm parents: 
55955diff
changeset | 398 | val atts = more_atts @ map (prep_att lthy) raw_atts; | 
| 21036 | 399 | |
| 56932 
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
 wenzelm parents: 
56897diff
changeset | 400 | val pos = Position.thread_data (); | 
| 21036 | 401 | fun after_qed' results goal_ctxt' = | 
| 45584 
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
 wenzelm parents: 
45583diff
changeset | 402 | let | 
| 54883 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
51313diff
changeset | 403 | val results' = | 
| 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
51313diff
changeset | 404 | burrow (map (Goal.norm_result lthy) o Proof_Context.export goal_ctxt' lthy) results; | 
| 45584 
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
 wenzelm parents: 
45583diff
changeset | 405 | val (res, lthy') = | 
| 63352 | 406 | if forall (Binding.is_empty_atts o fst) stmt then (map (pair "") results', lthy) | 
| 45584 
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
 wenzelm parents: 
45583diff
changeset | 407 | else | 
| 
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
 wenzelm parents: 
45583diff
changeset | 408 | Local_Theory.notes_kind kind | 
| 
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
 wenzelm parents: 
45583diff
changeset | 409 | (map2 (fn (b, _) => fn ths => (b, [(ths, [])])) stmt results') lthy; | 
| 
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
 wenzelm parents: 
45583diff
changeset | 410 | val lthy'' = | 
| 63352 | 411 | if Binding.is_empty_atts (name, atts) then | 
| 56932 
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
 wenzelm parents: 
56897diff
changeset | 412 | (Proof_Display.print_results int pos lthy' ((kind, ""), res); lthy') | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 413 | else | 
| 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 414 | let | 
| 45584 
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
 wenzelm parents: 
45583diff
changeset | 415 | val ([(res_name, _)], lthy'') = | 
| 
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
 wenzelm parents: 
45583diff
changeset | 416 | Local_Theory.notes_kind kind [((name, atts), [(maps #2 res, [])])] lthy'; | 
| 56932 
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
 wenzelm parents: 
56897diff
changeset | 417 | val _ = Proof_Display.print_results int pos lthy' ((kind, res_name), res); | 
| 45584 
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
 wenzelm parents: 
45583diff
changeset | 418 | in lthy'' end; | 
| 
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
 wenzelm parents: 
45583diff
changeset | 419 | in after_qed results' lthy'' end; | 
| 63094 
056ea294c256
toplevel theorem statements support 'if'/'for' eigen-context;
 wenzelm parents: 
63069diff
changeset | 420 | |
| 
056ea294c256
toplevel theorem statements support 'if'/'for' eigen-context;
 wenzelm parents: 
63069diff
changeset | 421 | val prems_name = if long then Auto_Bind.assmsN else Auto_Bind.thatN; | 
| 21036 | 422 | in | 
| 423 | goal_ctxt | |
| 63094 
056ea294c256
toplevel theorem statements support 'if'/'for' eigen-context;
 wenzelm parents: 
63069diff
changeset | 424 | |> not (null prems) ? | 
| 
056ea294c256
toplevel theorem statements support 'if'/'for' eigen-context;
 wenzelm parents: 
63069diff
changeset | 425 | (Proof_Context.note_thmss "" [((Binding.name prems_name, []), [(prems, [])])] #> snd) | 
| 36323 
655e2d74de3a
modernized naming conventions of main Isar proof elements;
 wenzelm parents: 
36317diff
changeset | 426 | |> Proof.theorem before_qed after_qed' (map snd stmt) | 
| 32856 
92d9555ac790
clarified Proof.refine_insert -- always "refine" to apply standard method treatment (of conjunctions);
 wenzelm parents: 
32786diff
changeset | 427 | |> (case facts of NONE => I | SOME ths => Proof.refine_insert ths) | 
| 36317 
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
 wenzelm parents: 
36106diff
changeset | 428 | |> tap (fn state => not schematic andalso Proof.schematic_goal state andalso | 
| 
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
 wenzelm parents: 
36106diff
changeset | 429 | error "Illegal schematic goal statement") | 
| 21036 | 430 | end; | 
| 431 | ||
| 21230 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 wenzelm parents: 
21206diff
changeset | 432 | in | 
| 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 wenzelm parents: 
21206diff
changeset | 433 | |
| 56026 
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
 wenzelm parents: 
56002diff
changeset | 434 | val theorem = | 
| 
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
 wenzelm parents: 
56002diff
changeset | 435 | gen_theorem false Bundle.includes (K I) Expression.cert_statement; | 
| 47067 
4ef29b0c568f
optional 'includes' element for long theorem statements;
 wenzelm parents: 
47066diff
changeset | 436 | val theorem_cmd = | 
| 56026 
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
 wenzelm parents: 
56002diff
changeset | 437 | gen_theorem false Bundle.includes_cmd Attrib.check_src Expression.read_statement; | 
| 36317 
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
 wenzelm parents: 
36106diff
changeset | 438 | |
| 56026 
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
 wenzelm parents: 
56002diff
changeset | 439 | val schematic_theorem = | 
| 
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
 wenzelm parents: 
56002diff
changeset | 440 | gen_theorem true Bundle.includes (K I) Expression.cert_statement; | 
| 47067 
4ef29b0c568f
optional 'includes' element for long theorem statements;
 wenzelm parents: 
47066diff
changeset | 441 | val schematic_theorem_cmd = | 
| 56026 
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
 wenzelm parents: 
56002diff
changeset | 442 | gen_theorem true Bundle.includes_cmd Attrib.check_src Expression.read_statement; | 
| 21036 | 443 | |
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 444 | end; | 
| 21036 | 445 | |
| 446 | end; |