| author | haftmann | 
| Sun, 11 Apr 2010 16:51:06 +0200 | |
| changeset 36110 | 4ab91a42666a | 
| parent 35894 | ab6dc4d86ea1 | 
| child 36106 | 19deea200358 | 
| 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 | 
| 20890 | 10 | val print_consts: local_theory -> (string * typ -> bool) -> (string * typ) list -> unit | 
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 11 | val check_spec: | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 12 | (binding * typ option * mixfix) list -> (Attrib.binding * term) list -> Proof.context -> | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 13 | (((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 14 | val read_spec: | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 15 | (binding * string option * mixfix) list -> (Attrib.binding * string) list -> Proof.context -> | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 16 | (((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 17 | val check_free_spec: | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 18 | (binding * typ option * mixfix) list -> (Attrib.binding * term) list -> Proof.context -> | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 19 | (((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 20 | val read_free_spec: | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 21 | (binding * string option * mixfix) list -> (Attrib.binding * string) list -> Proof.context -> | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 22 | (((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context | 
| 29581 | 23 | val check_specification: (binding * typ option * mixfix) list -> | 
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 24 | (Attrib.binding * term list) list -> Proof.context -> | 
| 29581 | 25 | (((binding * typ) * mixfix) list * (Attrib.binding * term list) list) * Proof.context | 
| 26 | val read_specification: (binding * string option * mixfix) list -> | |
| 28084 
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
 wenzelm parents: 
28080diff
changeset | 27 | (Attrib.binding * string list) list -> Proof.context -> | 
| 29581 | 28 | (((binding * typ) * mixfix) list * (Attrib.binding * term list) list) * Proof.context | 
| 29 | val axiomatization: (binding * typ option * mixfix) list -> | |
| 28114 | 30 | (Attrib.binding * term list) list -> theory -> | 
| 33703 
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
 wenzelm parents: 
33671diff
changeset | 31 | (term list * thm list list) * theory | 
| 29581 | 32 | val axiomatization_cmd: (binding * string option * mixfix) list -> | 
| 28114 | 33 | (Attrib.binding * string list) list -> theory -> | 
| 33703 
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
 wenzelm parents: 
33671diff
changeset | 34 | (term list * thm list list) * theory | 
| 35894 | 35 | val axiom: Attrib.binding * term -> theory -> thm * theory | 
| 36 | val axiom_cmd: Attrib.binding * string -> theory -> thm * theory | |
| 18954 | 37 | val definition: | 
| 29581 | 38 | (binding * typ option * mixfix) option * (Attrib.binding * term) -> | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 39 | local_theory -> (term * (string * thm)) * local_theory | 
| 24927 
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
 wenzelm parents: 
24848diff
changeset | 40 | val definition_cmd: | 
| 29581 | 41 | (binding * string option * mixfix) option * (Attrib.binding * string) -> | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 42 | local_theory -> (term * (string * thm)) * local_theory | 
| 29581 | 43 | val abbreviation: Syntax.mode -> (binding * typ option * mixfix) option * term -> | 
| 21532 | 44 | local_theory -> local_theory | 
| 29581 | 45 | val abbreviation_cmd: Syntax.mode -> (binding * string option * mixfix) option * string -> | 
| 24927 
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
 wenzelm parents: 
24848diff
changeset | 46 | local_theory -> local_theory | 
| 35413 | 47 | val type_notation: bool -> Syntax.mode -> (typ * mixfix) list -> local_theory -> local_theory | 
| 48 | val type_notation_cmd: bool -> Syntax.mode -> (string * mixfix) list -> local_theory -> local_theory | |
| 24949 | 49 | val notation: bool -> Syntax.mode -> (term * mixfix) list -> local_theory -> local_theory | 
| 50 | val notation_cmd: bool -> Syntax.mode -> (string * mixfix) list -> local_theory -> local_theory | |
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 51 | val theorems: string -> | 
| 28084 
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
 wenzelm parents: 
28080diff
changeset | 52 | (Attrib.binding * (thm list * Attrib.src list) list) list -> | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 53 | local_theory -> (string * thm list) list * local_theory | 
| 26336 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 wenzelm parents: 
25371diff
changeset | 54 | val theorems_cmd: string -> | 
| 28084 
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
 wenzelm parents: 
28080diff
changeset | 55 | (Attrib.binding * (Facts.ref * Attrib.src list) list) list -> | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 56 | local_theory -> (string * thm list) list * local_theory | 
| 24986 | 57 | val theorem: 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 -> | 
| 28710 | 59 | 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 | 
| 24986 | 61 | val theorem_cmd: 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 -> | 
| 28710 | 63 | 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 | 
| 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 berghofe parents: 
24219diff
changeset | 65 | val add_theorem_hook: (bool -> Proof.state -> Proof.state) -> Context.generic -> Context.generic | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 66 | end; | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 67 | |
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 68 | structure Specification: SPECIFICATION = | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 69 | struct | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 70 | |
| 20890 | 71 | (* diagnostics *) | 
| 72 | ||
| 73 | fun print_consts _ _ [] = () | |
| 33389 | 74 | | print_consts ctxt pred cs = Pretty.writeln (Proof_Display.pretty_consts ctxt pred cs); | 
| 20914 | 75 | |
| 19664 | 76 | |
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 77 | (* prepare specification *) | 
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 78 | |
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 79 | local | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 80 | |
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 81 | fun close_forms ctxt i xs As = | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 82 | let | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 83 | fun add_free (Free (x, _)) = if Variable.is_fixed ctxt x then I else insert (op =) x | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 84 | | add_free _ = I; | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 85 | |
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 86 | val commons = map #1 xs; | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 87 | val _ = | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 88 | (case duplicates (op =) commons of [] => () | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 89 |       | dups => error ("Duplicate local variables " ^ commas_quote dups));
 | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 90 | val frees = rev ((fold o fold_aterms) add_free As (rev commons)); | 
| 24848 | 91 | val types = map (TypeInfer.param i o rpair []) (Name.invents Name.context Name.aT (length frees)); | 
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 92 | val uniform_typing = the o AList.lookup (op =) (frees ~~ types); | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 93 | |
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 94 | fun abs_body lev y (Abs (x, T, b)) = Abs (x, T, abs_body (lev + 1) y b) | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 95 | | abs_body lev y (t $ u) = abs_body lev y t $ abs_body lev y u | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 96 | | abs_body lev y (t as Free (x, T)) = | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 97 | if x = y then TypeInfer.constrain (uniform_typing x) (TypeInfer.constrain T (Bound lev)) | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 98 | else t | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 99 | | abs_body _ _ a = a; | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 100 | fun close (y, U) B = | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 101 | let val B' = abs_body 0 y (Term.incr_boundvars 1 B) | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 102 | in if Term.loose_bvar1 (B', 0) then Term.all dummyT $ Abs (y, U, B') else B end; | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 103 | fun close_form A = | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 104 | let | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 105 | val occ_frees = rev (fold_aterms add_free A []); | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 106 | val bounds = xs @ map (rpair dummyT) (subtract (op =) commons occ_frees); | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 107 | in fold_rev close bounds A end; | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 108 | in map close_form As end; | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 109 | |
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 110 | fun prepare prep_vars parse_prop prep_att do_close raw_vars raw_specss ctxt = | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 111 | let | 
| 18670 | 112 | val thy = ProofContext.theory_of ctxt; | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 113 | |
| 18670 | 114 | val (vars, vars_ctxt) = ctxt |> prep_vars raw_vars; | 
| 30763 
6976521b4263
renamed ProofContext.add_fixes_i to ProofContext.add_fixes, eliminated obsolete external version;
 wenzelm parents: 
30761diff
changeset | 115 | val (xs, params_ctxt) = vars_ctxt |> ProofContext.add_fixes vars; | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 116 | |
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 117 | val Asss = (map o map) (map (parse_prop params_ctxt) o snd) raw_specss; | 
| 24734 | 118 | val names = Variable.names_of (params_ctxt |> (fold o fold o fold) Variable.declare_term Asss) | 
| 119 | |> fold Name.declare xs; | |
| 120 | val Asss' = #1 ((fold_map o fold_map o fold_map) Term.free_dummy_patterns Asss names); | |
| 121 | val idx = (fold o fold o fold) Term.maxidx_term Asss' ~1 + 1; | |
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 122 | val specs = | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 123 | (if do_close then | 
| 24734 | 124 | #1 (fold_map | 
| 125 | (fn Ass => fn i => (burrow (close_forms params_ctxt i []) Ass, i + 1)) Asss' idx) | |
| 126 | else Asss') | |
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 127 | |> flat |> burrow (Syntax.check_props params_ctxt); | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 128 | val specs_ctxt = params_ctxt |> (fold o fold) Variable.declare_term specs; | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 129 | |
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 130 | val Ts = specs_ctxt |> fold_map ProofContext.inferred_param xs |> fst; | 
| 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 131 | val params = map2 (fn (b, _, mx) => fn T => ((b, T), mx)) vars Ts; | 
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 132 | val name_atts = map (fn ((name, atts), _) => (name, map (prep_att thy) atts)) (flat raw_specss); | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 133 | in ((params, name_atts ~~ specs), specs_ctxt) end; | 
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 134 | |
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 135 | |
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 136 | fun single_spec (a, prop) = [(a, [prop])]; | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 137 | fun the_spec (a, [prop]) = (a, prop); | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 138 | |
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 139 | fun prep_spec prep_vars parse_prop prep_att do_close vars specs = | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 140 | prepare prep_vars parse_prop prep_att do_close | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 141 | vars (map single_spec specs) #>> apsnd (map the_spec); | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 142 | |
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 143 | in | 
| 21370 
d9dd7b4e5e69
replaced Variable.fix_frees by Variable.auto_fixes (depends on body mode);
 wenzelm parents: 
21359diff
changeset | 144 | |
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 145 | fun check_spec x = prep_spec ProofContext.cert_vars (K I) (K I) true x; | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 146 | fun read_spec x = prep_spec ProofContext.read_vars Syntax.parse_prop Attrib.intern_src true x; | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 147 | |
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 148 | fun check_free_spec x = prep_spec ProofContext.cert_vars (K I) (K I) false x; | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 149 | fun read_free_spec x = prep_spec ProofContext.read_vars Syntax.parse_prop Attrib.intern_src false x; | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 150 | |
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 151 | fun check_specification vars specs = | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 152 | prepare ProofContext.cert_vars (K I) (K I) true vars [specs]; | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 153 | |
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 154 | fun read_specification vars specs = | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 155 | prepare ProofContext.read_vars Syntax.parse_prop Attrib.intern_src true vars [specs]; | 
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 156 | |
| 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 157 | end; | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 158 | |
| 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 159 | |
| 28114 | 160 | (* axiomatization -- within global theory *) | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 161 | |
| 28114 | 162 | fun gen_axioms do_print prep raw_vars raw_specs thy = | 
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 163 | let | 
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 164 | val ((vars, specs), _) = prep raw_vars raw_specs (ProofContext.init thy); | 
| 30585 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 wenzelm parents: 
30482diff
changeset | 165 | val xs = map (fn ((b, T), _) => (Name.of_binding b, T)) vars; | 
| 28114 | 166 | |
| 167 | (*consts*) | |
| 33173 
b8ca12f6681a
eliminated obsolete tags for types/consts -- now handled via name space, in strongly typed fashion;
 wenzelm parents: 
32856diff
changeset | 168 | val (consts, consts_thy) = thy |> fold_map Theory.specify_const vars; | 
| 28114 | 169 | val subst = Term.subst_atomic (map Free xs ~~ consts); | 
| 170 | ||
| 171 | (*axioms*) | |
| 30470 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 wenzelm parents: 
30434diff
changeset | 172 | val (axioms, axioms_thy) = (specs, consts_thy) |-> fold_map (fn ((b, atts), props) => | 
| 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 wenzelm parents: 
30434diff
changeset | 173 | fold_map Thm.add_axiom | 
| 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 wenzelm parents: 
30434diff
changeset | 174 | (map (apfst (fn a => Binding.map_name (K a) b)) | 
| 30585 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 wenzelm parents: 
30482diff
changeset | 175 | (PureThy.name_multi (Name.of_binding b) (map subst props))) | 
| 33703 
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
 wenzelm parents: 
33671diff
changeset | 176 | #>> (fn ths => ((b, atts), [(ths, [])]))); | 
| 30470 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 wenzelm parents: 
30434diff
changeset | 177 | |
| 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 wenzelm parents: 
30434diff
changeset | 178 | (*facts*) | 
| 33703 
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
 wenzelm parents: 
33671diff
changeset | 179 | val (facts, facts_lthy) = axioms_thy | 
| 
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
 wenzelm parents: 
33671diff
changeset | 180 | |> Theory_Target.init NONE | 
| 
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
 wenzelm parents: 
33671diff
changeset | 181 | |> Spec_Rules.add Spec_Rules.Unknown (consts, maps (maps #1 o #2) axioms) | 
| 
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
 wenzelm parents: 
33671diff
changeset | 182 | |> Local_Theory.notes axioms; | 
| 30470 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 wenzelm parents: 
30434diff
changeset | 183 | |
| 26595 | 184 | val _ = | 
| 185 | if not do_print then () | |
| 33703 
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
 wenzelm parents: 
33671diff
changeset | 186 | else print_consts facts_lthy (K false) xs; | 
| 
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
 wenzelm parents: 
33671diff
changeset | 187 | in ((consts, map #2 facts), Local_Theory.exit_global facts_lthy) end; | 
| 18786 | 188 | |
| 26595 | 189 | val axiomatization = gen_axioms false check_specification; | 
| 190 | val axiomatization_cmd = gen_axioms true read_specification; | |
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 191 | |
| 35894 | 192 | fun axiom (b, ax) = axiomatization [] [(b, [ax])] #>> (hd o hd o snd); | 
| 193 | fun axiom_cmd (b, ax) = axiomatization_cmd [] [(b, [ax])] #>> (hd o hd o snd); | |
| 194 | ||
| 18786 | 195 | |
| 196 | (* definition *) | |
| 197 | ||
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 198 | fun gen_def do_print prep (raw_var, raw_spec) lthy = | 
| 18786 | 199 | let | 
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 200 | val (vars, [((raw_name, atts), prop)]) = fst (prep (the_list raw_var) [raw_spec] lthy); | 
| 35624 | 201 | val (((x, T), rhs), prove) = Local_Defs.derived_def lthy true prop; | 
| 30434 | 202 | val var as (b, _) = | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 203 | (case vars of | 
| 28965 | 204 | [] => (Binding.name x, NoSyn) | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 205 | | [((b, _), mx)] => | 
| 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 206 | let | 
| 30585 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 wenzelm parents: 
30482diff
changeset | 207 | val y = Name.of_binding b; | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 208 | val _ = x = y orelse | 
| 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 209 |               error ("Head of definition " ^ quote x ^ " differs from declaration " ^ quote y ^
 | 
| 28941 | 210 | Position.str_of (Binding.pos_of b)); | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 211 | in (b, mx) end); | 
| 30434 | 212 | val name = Thm.def_binding_optional b raw_name; | 
| 33455 
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
 wenzelm parents: 
33389diff
changeset | 213 | val ((lhs, (_, raw_th)), lthy2) = lthy | 
| 33765 
47b5db097646
Specification.definition: Thm.definitionK marks exactly the high-level end-user result;
 wenzelm parents: 
33756diff
changeset | 214 | |> Local_Theory.define (var, ((Binding.suffix_name "_raw" name, []), rhs)); | 
| 33455 
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
 wenzelm parents: 
33389diff
changeset | 215 | |
| 
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
 wenzelm parents: 
33389diff
changeset | 216 | val th = prove lthy2 raw_th; | 
| 
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
 wenzelm parents: 
33389diff
changeset | 217 | val lthy3 = lthy2 |> Spec_Rules.add Spec_Rules.Equational ([lhs], [th]); | 
| 
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
 wenzelm parents: 
33389diff
changeset | 218 | |
| 33670 
02b7738aef6a
eliminated slightly odd kind argument of LocalTheory.note(s);
 wenzelm parents: 
33644diff
changeset | 219 | val ([(def_name, [th'])], lthy4) = lthy3 | 
| 33671 | 220 | |> Local_Theory.notes_kind Thm.definitionK | 
| 33756 
47b7c9e0bf6e
replacing Predicate_Compile_Preproc_Const_Defs by more general Spec_Rules
 bulwahn parents: 
33703diff
changeset | 221 | [((name, Code.add_default_eqn_attrib :: atts), [([th], [])])]; | 
| 18786 | 222 | |
| 33671 | 223 | val lhs' = Morphism.term (Local_Theory.target_morphism lthy4) lhs; | 
| 26595 | 224 | val _ = | 
| 225 | if not do_print then () | |
| 33455 
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
 wenzelm parents: 
33389diff
changeset | 226 | else print_consts lthy4 (member (op =) (Term.add_frees lhs' [])) [(x, T)]; | 
| 
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
 wenzelm parents: 
33389diff
changeset | 227 | in ((lhs, (def_name, th')), lthy4) end; | 
| 18786 | 228 | |
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 229 | val definition = gen_def false check_free_spec; | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 230 | val definition_cmd = gen_def true read_free_spec; | 
| 18786 | 231 | |
| 19080 | 232 | |
| 233 | (* abbreviation *) | |
| 234 | ||
| 26595 | 235 | fun gen_abbrev do_print prep mode (raw_var, raw_prop) lthy = | 
| 19080 | 236 | let | 
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 237 | val ((vars, [(_, prop)]), _) = | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 238 | prep (the_list raw_var) [(Attrib.empty_binding, raw_prop)] | 
| 24676 | 239 | (lthy |> ProofContext.set_mode ProofContext.mode_abbrev); | 
| 35624 | 240 | val ((x, T), rhs) = Local_Defs.abs_def (#2 (Local_Defs.cert_def lthy prop)); | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 241 | val var = | 
| 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 242 | (case vars of | 
| 28965 | 243 | [] => (Binding.name x, NoSyn) | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 244 | | [((b, _), mx)] => | 
| 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 245 | let | 
| 30585 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 wenzelm parents: 
30482diff
changeset | 246 | val y = Name.of_binding b; | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 247 | val _ = x = y orelse | 
| 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 248 |               error ("Head of abbreviation " ^ quote x ^ " differs from declaration " ^ quote y ^
 | 
| 28941 | 249 | Position.str_of (Binding.pos_of b)); | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 250 | in (b, mx) end); | 
| 21705 | 251 | val lthy' = lthy | 
| 24986 | 252 | |> ProofContext.set_syntax_mode mode (* FIXME ?!? *) | 
| 33671 | 253 | |> Local_Theory.abbrev mode (var, rhs) |> snd | 
| 21705 | 254 | |> ProofContext.restore_syntax_mode lthy; | 
| 24724 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 wenzelm parents: 
24676diff
changeset | 255 | |
| 26595 | 256 | val _ = if not do_print then () else print_consts lthy' (K false) [(x, T)]; | 
| 21532 | 257 | in lthy' end; | 
| 19080 | 258 | |
| 30482 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 259 | val abbreviation = gen_abbrev false check_free_spec; | 
| 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 wenzelm parents: 
30472diff
changeset | 260 | val abbreviation_cmd = gen_abbrev true read_free_spec; | 
| 19080 | 261 | |
| 19664 | 262 | |
| 21230 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 wenzelm parents: 
21206diff
changeset | 263 | (* notation *) | 
| 19664 | 264 | |
| 35413 | 265 | local | 
| 266 | ||
| 267 | fun gen_type_notation prep_type add mode args lthy = | |
| 268 | lthy |> Local_Theory.type_notation add mode (map (apfst (prep_type lthy)) args); | |
| 269 | ||
| 24949 | 270 | fun gen_notation prep_const add mode args lthy = | 
| 33671 | 271 | lthy |> Local_Theory.notation add mode (map (apfst (prep_const lthy)) args); | 
| 19664 | 272 | |
| 35413 | 273 | in | 
| 274 | ||
| 275 | val type_notation = gen_type_notation (K I); | |
| 276 | val type_notation_cmd = gen_type_notation (fn ctxt => ProofContext.read_type_name ctxt false); | |
| 277 | ||
| 24927 
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
 wenzelm parents: 
24848diff
changeset | 278 | val notation = gen_notation (K I); | 
| 35399 
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
 wenzelm parents: 
33765diff
changeset | 279 | val notation_cmd = gen_notation (fn ctxt => ProofContext.read_const ctxt false); | 
| 19664 | 280 | |
| 35413 | 281 | end; | 
| 282 | ||
| 20914 | 283 | |
| 21036 | 284 | (* fact statements *) | 
| 20914 | 285 | |
| 26345 
f70620a4cf81
renamed former get_thms(_silent) to get_fact(_silent);
 wenzelm parents: 
26336diff
changeset | 286 | fun gen_theorems prep_fact prep_att kind raw_facts lthy = | 
| 20914 | 287 | let | 
| 288 | val attrib = prep_att (ProofContext.theory_of lthy); | |
| 289 | val facts = raw_facts |> map (fn ((name, atts), bs) => | |
| 290 | ((name, map attrib atts), | |
| 26345 
f70620a4cf81
renamed former get_thms(_silent) to get_fact(_silent);
 wenzelm parents: 
26336diff
changeset | 291 | bs |> map (fn (b, more_atts) => (prep_fact lthy b, map attrib more_atts)))); | 
| 33671 | 292 | val (res, lthy') = lthy |> Local_Theory.notes_kind kind facts; | 
| 33389 | 293 | val _ = Proof_Display.print_results true lthy' ((kind, ""), res); | 
| 20914 | 294 | in (res, lthy') end; | 
| 295 | ||
| 24927 
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
 wenzelm parents: 
24848diff
changeset | 296 | val theorems = gen_theorems (K I) (K I); | 
| 26345 
f70620a4cf81
renamed former get_thms(_silent) to get_fact(_silent);
 wenzelm parents: 
26336diff
changeset | 297 | val theorems_cmd = gen_theorems ProofContext.get_fact Attrib.intern_src; | 
| 20914 | 298 | |
| 21036 | 299 | |
| 21230 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 wenzelm parents: 
21206diff
changeset | 300 | (* complex goal statements *) | 
| 21036 | 301 | |
| 302 | local | |
| 303 | ||
| 21236 | 304 | fun prep_statement prep_att prep_stmt elems concl ctxt = | 
| 305 | (case concl of | |
| 306 | Element.Shows shows => | |
| 21230 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 wenzelm parents: 
21206diff
changeset | 307 | let | 
| 28880 | 308 | val (propp, elems_ctxt) = prep_stmt elems (map snd shows) ctxt; | 
| 30472 | 309 | val prems = Assumption.local_prems_of elems_ctxt ctxt; | 
| 21450 | 310 | val stmt = Attrib.map_specs prep_att (map fst shows ~~ propp); | 
| 21370 
d9dd7b4e5e69
replaced Variable.fix_frees by Variable.auto_fixes (depends on body mode);
 wenzelm parents: 
21359diff
changeset | 311 | val goal_ctxt = fold (fold (Variable.auto_fixes o fst)) propp elems_ctxt; | 
| 32856 
92d9555ac790
clarified Proof.refine_insert -- always "refine" to apply standard method treatment (of conjunctions);
 wenzelm parents: 
32786diff
changeset | 312 | in ((prems, stmt, NONE), goal_ctxt) end | 
| 21236 | 313 | | Element.Obtains obtains => | 
| 21230 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 wenzelm parents: 
21206diff
changeset | 314 | let | 
| 28862 | 315 | val case_names = obtains |> map_index (fn (i, (b, _)) => | 
| 30585 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 wenzelm parents: 
30482diff
changeset | 316 | if Binding.is_empty b then string_of_int (i + 1) else Name.of_binding b); | 
| 21236 | 317 | val constraints = obtains |> map (fn (_, (vars, _)) => | 
| 28710 | 318 | Element.Constrains | 
| 30585 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 wenzelm parents: 
30482diff
changeset | 319 | (vars |> map_filter (fn (x, SOME T) => SOME (Name.of_binding x, T) | _ => NONE))); | 
| 21036 | 320 | |
| 21236 | 321 | val raw_propp = obtains |> map (fn (_, (_, props)) => map (rpair []) props); | 
| 28880 | 322 | val (propp, elems_ctxt) = prep_stmt (elems @ constraints) raw_propp ctxt; | 
| 21236 | 323 | |
| 35625 | 324 | val thesis = Object_Logic.fixed_judgment (ProofContext.theory_of ctxt) Auto_Bind.thesisN; | 
| 21036 | 325 | |
| 21236 | 326 | fun assume_case ((name, (vars, _)), asms) ctxt' = | 
| 327 | let | |
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 328 | val bs = map fst vars; | 
| 30585 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 wenzelm parents: 
30482diff
changeset | 329 | val xs = map Name.of_binding bs; | 
| 21236 | 330 | val props = map fst asms; | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 331 | val (Ts, _) = ctxt' | 
| 21236 | 332 | |> fold Variable.declare_term props | 
| 333 | |> fold_map ProofContext.inferred_param xs; | |
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 334 | val asm = Term.list_all_free (xs ~~ Ts, Logic.list_implies (props, thesis)); | 
| 21236 | 335 | in | 
| 30763 
6976521b4263
renamed ProofContext.add_fixes_i to ProofContext.add_fixes, eliminated obsolete external version;
 wenzelm parents: 
30761diff
changeset | 336 | ctxt' |> (snd o ProofContext.add_fixes (map (fn b => (b, NONE, NoSyn)) bs)); | 
| 21370 
d9dd7b4e5e69
replaced Variable.fix_frees by Variable.auto_fixes (depends on body mode);
 wenzelm parents: 
21359diff
changeset | 337 | ctxt' |> Variable.auto_fixes asm | 
| 21236 | 338 | |> ProofContext.add_assms_i Assumption.assume_export | 
| 33369 | 339 | [((name, [Context_Rules.intro_query NONE]), [(asm, [])])] | 
| 21236 | 340 | |>> (fn [(_, [th])] => th) | 
| 341 | end; | |
| 342 | ||
| 21658 | 343 | val atts = map (Attrib.internal o K) | 
| 33368 | 344 | [Rule_Cases.consumes (~ (length obtains)), Rule_Cases.case_names case_names]; | 
| 30472 | 345 | val prems = Assumption.local_prems_of elems_ctxt ctxt; | 
| 28965 | 346 | val stmt = [((Binding.empty, atts), [(thesis, [])])]; | 
| 21236 | 347 | |
| 348 | val (facts, goal_ctxt) = elems_ctxt | |
| 33386 | 349 | |> (snd o ProofContext.add_fixes [(Binding.name Auto_Bind.thesisN, NONE, NoSyn)]) | 
| 21236 | 350 | |> fold_map assume_case (obtains ~~ propp) | 
| 33644 
5266a72e0889
eliminated slightly odd (unused) "axiom" and "assumption" -- collapsed to unspecific "";
 wenzelm parents: 
33519diff
changeset | 351 | |-> (fn ths => | 
| 
5266a72e0889
eliminated slightly odd (unused) "axiom" and "assumption" -- collapsed to unspecific "";
 wenzelm parents: 
33519diff
changeset | 352 | ProofContext.note_thmss "" [((Binding.name Obtain.thatN, []), [(ths, [])])] #> | 
| 
5266a72e0889
eliminated slightly odd (unused) "axiom" and "assumption" -- collapsed to unspecific "";
 wenzelm parents: 
33519diff
changeset | 353 | #2 #> pair ths); | 
| 32856 
92d9555ac790
clarified Proof.refine_insert -- always "refine" to apply standard method treatment (of conjunctions);
 wenzelm parents: 
32786diff
changeset | 354 | in ((prems, stmt, SOME facts), goal_ctxt) end); | 
| 21036 | 355 | |
| 33519 | 356 | structure TheoremHook = Generic_Data | 
| 24452 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 berghofe parents: 
24219diff
changeset | 357 | ( | 
| 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 berghofe parents: 
24219diff
changeset | 358 | type T = ((bool -> Proof.state -> Proof.state) * stamp) list; | 
| 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 berghofe parents: 
24219diff
changeset | 359 | val empty = []; | 
| 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 berghofe parents: 
24219diff
changeset | 360 | val extend = I; | 
| 33519 | 361 | fun merge hooks : T = Library.merge (eq_snd op =) hooks; | 
| 24452 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 berghofe parents: 
24219diff
changeset | 362 | ); | 
| 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 berghofe parents: 
24219diff
changeset | 363 | |
| 21036 | 364 | fun gen_theorem prep_att prep_stmt | 
| 28858 | 365 | kind before_qed after_qed (name, raw_atts) raw_elems raw_concl int lthy = | 
| 21036 | 366 | let | 
| 33671 | 367 | val _ = Local_Theory.affirm lthy; | 
| 28858 | 368 | val thy = ProofContext.theory_of lthy; | 
| 21036 | 369 | |
| 21435 | 370 | val attrib = prep_att thy; | 
| 371 | val atts = map attrib raw_atts; | |
| 28710 | 372 | val elems = raw_elems |> map (Element.map_ctxt_attrib attrib); | 
| 21450 | 373 | val ((prems, stmt, facts), goal_ctxt) = | 
| 28880 | 374 | prep_statement attrib prep_stmt elems raw_concl lthy; | 
| 21036 | 375 | |
| 376 | fun after_qed' results goal_ctxt' = | |
| 21602 | 377 | let val results' = | 
| 378 | burrow (map Goal.norm_result o ProofContext.export goal_ctxt' lthy) results | |
| 379 | in | |
| 21036 | 380 | lthy | 
| 33671 | 381 | |> Local_Theory.notes_kind kind | 
| 33670 
02b7738aef6a
eliminated slightly odd kind argument of LocalTheory.note(s);
 wenzelm parents: 
33644diff
changeset | 382 | (map2 (fn (a, _) => fn ths => (a, [(ths, [])])) stmt results') | 
| 21036 | 383 | |> (fn (res, lthy') => | 
| 28965 | 384 | if Binding.is_empty name andalso null atts then | 
| 33389 | 385 | (Proof_Display.print_results true lthy' ((kind, ""), res); lthy') | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 386 | else | 
| 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 387 | let | 
| 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 388 | val ([(res_name, _)], lthy'') = lthy' | 
| 33671 | 389 | |> Local_Theory.notes_kind kind [((name, atts), [(maps #2 res, [])])]; | 
| 33389 | 390 | val _ = Proof_Display.print_results true lthy' ((kind, res_name), res); | 
| 28080 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27858diff
changeset | 391 | in lthy'' end) | 
| 21036 | 392 | |> after_qed results' | 
| 393 | end; | |
| 394 | in | |
| 395 | goal_ctxt | |
| 33644 
5266a72e0889
eliminated slightly odd (unused) "axiom" and "assumption" -- collapsed to unspecific "";
 wenzelm parents: 
33519diff
changeset | 396 | |> ProofContext.note_thmss "" [((Binding.name Auto_Bind.assmsN, []), [(prems, [])])] | 
| 21450 | 397 | |> snd | 
| 21435 | 398 | |> Proof.theorem_i 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 | 399 | |> (case facts of NONE => I | SOME ths => Proof.refine_insert ths) | 
| 24542 | 400 | |> Library.apply (map (fn (f, _) => f int) (rev (TheoremHook.get (Context.Proof goal_ctxt)))) | 
| 21036 | 401 | end; | 
| 402 | ||
| 21230 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 wenzelm parents: 
21206diff
changeset | 403 | in | 
| 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 wenzelm parents: 
21206diff
changeset | 404 | |
| 29249 | 405 | val theorem = gen_theorem (K I) Expression.cert_statement; | 
| 406 | val theorem_cmd = gen_theorem Attrib.intern_src Expression.read_statement; | |
| 21036 | 407 | |
| 24452 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 berghofe parents: 
24219diff
changeset | 408 | fun add_theorem_hook f = TheoremHook.map (cons (f, stamp ())); | 
| 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 berghofe parents: 
24219diff
changeset | 409 | |
| 18620 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 wenzelm parents: diff
changeset | 410 | end; | 
| 21036 | 411 | |
| 412 | end; |