author | wenzelm |
Fri, 31 Oct 2014 17:08:54 +0100 | |
changeset 58848 | fd0c85d7da38 |
parent 58028 | e4250d370657 |
child 58993 | 302104d8366b |
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 |
30482
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
10 |
val check_spec: |
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
11 |
(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:
30472
diff
changeset
|
12 |
(((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:
30472
diff
changeset
|
13 |
val read_spec: |
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
14 |
(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:
30472
diff
changeset
|
15 |
(((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:
30472
diff
changeset
|
16 |
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:
30472
diff
changeset
|
17 |
(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:
30472
diff
changeset
|
18 |
(((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:
30472
diff
changeset
|
19 |
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:
30472
diff
changeset
|
20 |
(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:
30472
diff
changeset
|
21 |
(((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context |
29581 | 22 |
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:
30472
diff
changeset
|
23 |
(Attrib.binding * term list) list -> Proof.context -> |
29581 | 24 |
(((binding * typ) * mixfix) list * (Attrib.binding * term list) list) * Proof.context |
25 |
val read_specification: (binding * string option * mixfix) list -> |
|
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28080
diff
changeset
|
26 |
(Attrib.binding * string list) list -> Proof.context -> |
29581 | 27 |
(((binding * typ) * mixfix) list * (Attrib.binding * term list) list) * Proof.context |
28 |
val axiomatization: (binding * typ option * mixfix) list -> |
|
28114 | 29 |
(Attrib.binding * term list) list -> theory -> |
33703
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
wenzelm
parents:
33671
diff
changeset
|
30 |
(term list * thm list list) * theory |
29581 | 31 |
val axiomatization_cmd: (binding * string option * mixfix) list -> |
28114 | 32 |
(Attrib.binding * string list) list -> theory -> |
33703
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
wenzelm
parents:
33671
diff
changeset
|
33 |
(term list * thm list list) * theory |
35894 | 34 |
val axiom: Attrib.binding * term -> theory -> thm * theory |
18954 | 35 |
val definition: |
29581 | 36 |
(binding * typ option * mixfix) option * (Attrib.binding * term) -> |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
37 |
local_theory -> (term * (string * thm)) * local_theory |
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
38 |
val definition': |
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
39 |
(binding * typ option * mixfix) option * (Attrib.binding * term) -> |
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
40 |
bool -> local_theory -> (term * (string * thm)) * local_theory |
24927
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
wenzelm
parents:
24848
diff
changeset
|
41 |
val definition_cmd: |
29581 | 42 |
(binding * string option * mixfix) option * (Attrib.binding * string) -> |
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
43 |
bool -> local_theory -> (term * (string * thm)) * local_theory |
29581 | 44 |
val abbreviation: Syntax.mode -> (binding * typ option * mixfix) option * term -> |
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
45 |
bool -> local_theory -> local_theory |
29581 | 46 |
val abbreviation_cmd: Syntax.mode -> (binding * string option * mixfix) option * string -> |
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
47 |
bool -> local_theory -> local_theory |
35413 | 48 |
val type_notation: bool -> Syntax.mode -> (typ * mixfix) list -> local_theory -> local_theory |
55639 | 49 |
val type_notation_cmd: bool -> Syntax.mode -> (string * mixfix) list -> |
50 |
local_theory -> local_theory |
|
24949 | 51 |
val notation: bool -> Syntax.mode -> (term * mixfix) list -> local_theory -> local_theory |
52 |
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:
27858
diff
changeset
|
53 |
val theorems: string -> |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
56932
diff
changeset
|
54 |
(Attrib.binding * (thm list * Token.src list) list) list -> |
45600
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
55 |
(binding * typ option * mixfix) list -> |
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
56 |
bool -> local_theory -> (string * thm list) list * local_theory |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
25371
diff
changeset
|
57 |
val theorems_cmd: string -> |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
56932
diff
changeset
|
58 |
(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:
45584
diff
changeset
|
59 |
(binding * string option * mixfix) list -> |
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
60 |
bool -> local_theory -> (string * thm list) list * local_theory |
24986 | 61 |
val theorem: string -> Method.text option -> |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28080
diff
changeset
|
62 |
(thm list list -> local_theory -> local_theory) -> Attrib.binding -> |
47067
4ef29b0c568f
optional 'includes' element for long theorem statements;
wenzelm
parents:
47066
diff
changeset
|
63 |
string list -> Element.context_i list -> Element.statement_i -> |
24452
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
berghofe
parents:
24219
diff
changeset
|
64 |
bool -> local_theory -> Proof.state |
24986 | 65 |
val theorem_cmd: string -> Method.text option -> |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28080
diff
changeset
|
66 |
(thm list list -> local_theory -> local_theory) -> Attrib.binding -> |
47067
4ef29b0c568f
optional 'includes' element for long theorem statements;
wenzelm
parents:
47066
diff
changeset
|
67 |
(xstring * Position.T) list -> Element.context list -> Element.statement -> |
24452
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
berghofe
parents:
24219
diff
changeset
|
68 |
bool -> local_theory -> Proof.state |
36317
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents:
36106
diff
changeset
|
69 |
val schematic_theorem: string -> Method.text option -> |
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents:
36106
diff
changeset
|
70 |
(thm list list -> local_theory -> local_theory) -> Attrib.binding -> |
47067
4ef29b0c568f
optional 'includes' element for long theorem statements;
wenzelm
parents:
47066
diff
changeset
|
71 |
string list -> Element.context_i list -> Element.statement_i -> |
36317
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents:
36106
diff
changeset
|
72 |
bool -> local_theory -> Proof.state |
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents:
36106
diff
changeset
|
73 |
val schematic_theorem_cmd: string -> Method.text option -> |
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents:
36106
diff
changeset
|
74 |
(thm list list -> local_theory -> local_theory) -> Attrib.binding -> |
47067
4ef29b0c568f
optional 'includes' element for long theorem statements;
wenzelm
parents:
47066
diff
changeset
|
75 |
(xstring * Position.T) list -> Element.context list -> Element.statement -> |
36317
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents:
36106
diff
changeset
|
76 |
bool -> local_theory -> Proof.state |
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
77 |
end; |
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
78 |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
79 |
structure Specification: SPECIFICATION = |
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
80 |
struct |
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
81 |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
82 |
(* prepare specification *) |
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
83 |
|
24724
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
84 |
local |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
85 |
|
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
86 |
fun close_forms ctxt i xs As = |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
87 |
let |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
88 |
val commons = map #1 xs; |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
89 |
val _ = |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
90 |
(case duplicates (op =) commons of [] => () |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
91 |
| dups => error ("Duplicate local variables " ^ commas_quote dups)); |
42482 | 92 |
val frees = rev (fold (Variable.add_free_names ctxt) As (rev commons)); |
55639 | 93 |
val types = |
94 |
map (Type_Infer.param i o rpair []) (Name.invent Name.context Name.aT (length frees)); |
|
24724
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
95 |
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:
24676
diff
changeset
|
96 |
|
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
97 |
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:
24676
diff
changeset
|
98 |
| 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:
24676
diff
changeset
|
99 |
| abs_body lev y (t as Free (x, T)) = |
39288 | 100 |
if x = y then Type.constraint (uniform_typing x) (Type.constraint T (Bound lev)) |
24724
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
101 |
else t |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
102 |
| abs_body _ _ a = a; |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
103 |
fun close (y, U) B = |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
104 |
let val B' = abs_body 0 y (Term.incr_boundvars 1 B) |
46217
7b19666f0e3d
renamed Term.all to Logic.all_const, in accordance to HOLogic.all_const;
wenzelm
parents:
46215
diff
changeset
|
105 |
in if Term.is_dependent B' then Logic.all_const dummyT $ Abs (y, U, B') else B end; |
24724
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
106 |
fun close_form A = |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
107 |
let |
42482 | 108 |
val occ_frees = rev (Variable.add_free_names ctxt A []); |
24724
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
109 |
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:
24676
diff
changeset
|
110 |
in fold_rev close bounds A end; |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
111 |
in map close_form As end; |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
112 |
|
30482
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
113 |
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
|
114 |
let |
18670 | 115 |
val (vars, vars_ctxt) = ctxt |> prep_vars raw_vars; |
42360 | 116 |
val (xs, params_ctxt) = vars_ctxt |> Proof_Context.add_fixes vars; |
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
117 |
|
42265 | 118 |
val Asss = |
119 |
(map o map) snd raw_specss |
|
46989 | 120 |
|> (burrow o burrow) |
121 |
(grouped 10 (Par_List.map_name "Specification.parse_prop") (parse_prop params_ctxt)); |
|
24734 | 122 |
val names = Variable.names_of (params_ctxt |> (fold o fold o fold) Variable.declare_term Asss) |
123 |
|> fold Name.declare xs; |
|
124 |
val Asss' = #1 ((fold_map o fold_map o fold_map) Term.free_dummy_patterns Asss names); |
|
125 |
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:
24676
diff
changeset
|
126 |
val specs = |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
127 |
(if do_close then |
24734 | 128 |
#1 (fold_map |
129 |
(fn Ass => fn i => (burrow (close_forms params_ctxt i []) Ass, i + 1)) Asss' idx) |
|
130 |
else Asss') |
|
24724
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
131 |
|> flat |> burrow (Syntax.check_props params_ctxt); |
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
132 |
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:
24676
diff
changeset
|
133 |
|
42360 | 134 |
val Ts = specs_ctxt |> fold_map Proof_Context.inferred_param xs |> fst; |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
135 |
val params = map2 (fn (b, _, mx) => fn T => ((b, T), mx)) vars Ts; |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55955
diff
changeset
|
136 |
val name_atts = map (fn ((name, atts), _) => (name, map (prep_att ctxt) atts)) (flat raw_specss); |
24724
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
137 |
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:
24676
diff
changeset
|
138 |
|
30482
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
139 |
|
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
140 |
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:
30472
diff
changeset
|
141 |
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:
30472
diff
changeset
|
142 |
|
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
143 |
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:
30472
diff
changeset
|
144 |
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:
30472
diff
changeset
|
145 |
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:
30472
diff
changeset
|
146 |
|
24724
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
147 |
in |
21370
d9dd7b4e5e69
replaced Variable.fix_frees by Variable.auto_fixes (depends on body mode);
wenzelm
parents:
21359
diff
changeset
|
148 |
|
42360 | 149 |
fun check_spec x = prep_spec Proof_Context.cert_vars (K I) (K I) true x; |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55955
diff
changeset
|
150 |
fun read_spec x = prep_spec Proof_Context.read_vars Syntax.parse_prop Attrib.check_src true x; |
30482
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
151 |
|
42360 | 152 |
fun check_free_spec x = prep_spec Proof_Context.cert_vars (K I) (K I) false x; |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55955
diff
changeset
|
153 |
fun read_free_spec x = prep_spec Proof_Context.read_vars Syntax.parse_prop Attrib.check_src false x; |
30482
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
154 |
|
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
155 |
fun check_specification vars specs = |
42360 | 156 |
prepare Proof_Context.cert_vars (K I) (K I) true vars [specs]; |
30482
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
157 |
|
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
158 |
fun read_specification vars specs = |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55955
diff
changeset
|
159 |
prepare Proof_Context.read_vars Syntax.parse_prop Attrib.check_src true vars [specs]; |
24724
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
160 |
|
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
161 |
end; |
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
162 |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
163 |
|
28114 | 164 |
(* axiomatization -- within global theory *) |
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
165 |
|
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
166 |
fun gen_axioms prep raw_vars raw_specs thy = |
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
167 |
let |
42360 | 168 |
val ((vars, specs), _) = prep raw_vars raw_specs (Proof_Context.init_global thy); |
42494 | 169 |
val xs = map (fn ((b, T), _) => (Variable.check_name b, T)) vars; |
28114 | 170 |
|
171 |
(*consts*) |
|
33173
b8ca12f6681a
eliminated obsolete tags for types/consts -- now handled via name space, in strongly typed fashion;
wenzelm
parents:
32856
diff
changeset
|
172 |
val (consts, consts_thy) = thy |> fold_map Theory.specify_const vars; |
28114 | 173 |
val subst = Term.subst_atomic (map Free xs ~~ consts); |
174 |
||
175 |
(*axioms*) |
|
30470
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
wenzelm
parents:
30434
diff
changeset
|
176 |
val (axioms, axioms_thy) = (specs, consts_thy) |-> fold_map (fn ((b, atts), props) => |
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42360
diff
changeset
|
177 |
fold_map Thm.add_axiom_global |
30470
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
wenzelm
parents:
30434
diff
changeset
|
178 |
(map (apfst (fn a => Binding.map_name (K a) b)) |
47021
f35f654f297d
clarified Binding.name_of vs Name_Space.base_name vs Variable.check_name (see also 9bd8d4addd6e, 3305f573294e);
wenzelm
parents:
46992
diff
changeset
|
179 |
(Global_Theory.name_multi (Binding.name_of b) (map subst props))) |
36106
19deea200358
Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents:
35894
diff
changeset
|
180 |
#>> (fn ths => ((b, atts), [(map #2 ths, [])]))); |
30470
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
wenzelm
parents:
30434
diff
changeset
|
181 |
|
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
wenzelm
parents:
30434
diff
changeset
|
182 |
(*facts*) |
33703
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
wenzelm
parents:
33671
diff
changeset
|
183 |
val (facts, facts_lthy) = axioms_thy |
38388 | 184 |
|> Named_Target.theory_init |
33703
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
wenzelm
parents:
33671
diff
changeset
|
185 |
|> Spec_Rules.add Spec_Rules.Unknown (consts, maps (maps #1 o #2) axioms) |
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
wenzelm
parents:
33671
diff
changeset
|
186 |
|> Local_Theory.notes axioms; |
30470
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
wenzelm
parents:
30434
diff
changeset
|
187 |
|
33703
50b6c07c0dd4
axiomatization: declare Spec_Rules, direct result;
wenzelm
parents:
33671
diff
changeset
|
188 |
in ((consts, map #2 facts), Local_Theory.exit_global facts_lthy) end; |
18786 | 189 |
|
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
190 |
val axiomatization = gen_axioms check_specification; |
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
191 |
val axiomatization_cmd = gen_axioms read_specification; |
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
192 |
|
35894 | 193 |
fun axiom (b, ax) = axiomatization [] [(b, [ax])] #>> (hd o hd o snd); |
194 |
||
18786 | 195 |
|
196 |
(* definition *) |
|
197 |
||
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
198 |
fun gen_def prep (raw_var, raw_spec) int 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:
30472
diff
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; |
56169
9b0dc5c704c9
reject internal names, notably from Term.free_dummy_patterns;
wenzelm
parents:
56026
diff
changeset
|
202 |
val _ = Name.reject_internal (x, []); |
30434 | 203 |
val var as (b, _) = |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
204 |
(case vars of |
28965 | 205 |
[] => (Binding.name x, NoSyn) |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
206 |
| [((b, _), mx)] => |
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
207 |
let |
42494 | 208 |
val y = Variable.check_name b; |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
209 |
val _ = x = y orelse |
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
210 |
error ("Head of definition " ^ quote x ^ " differs from declaration " ^ quote y ^ |
48992 | 211 |
Position.here (Binding.pos_of b)); |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
212 |
in (b, mx) end); |
30434 | 213 |
val name = Thm.def_binding_optional b raw_name; |
33455
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
wenzelm
parents:
33389
diff
changeset
|
214 |
val ((lhs, (_, raw_th)), lthy2) = lthy |
46992
eeea81b86b70
refined Local_Theory.define vs. Local_Theory.define_internal, which allows to pass alternative name to the foundational axiom -- expecially important for 'instantiation' or 'overloading', which loose name information due to Long_Name.base_name cooking etc.;
wenzelm
parents:
46989
diff
changeset
|
215 |
|> Local_Theory.define_internal (var, ((Binding.suffix_name "_raw" name, []), rhs)); |
33455
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
wenzelm
parents:
33389
diff
changeset
|
216 |
|
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
wenzelm
parents:
33389
diff
changeset
|
217 |
val th = prove lthy2 raw_th; |
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
wenzelm
parents:
33389
diff
changeset
|
218 |
val lthy3 = lthy2 |> Spec_Rules.add Spec_Rules.Equational ([lhs], [th]); |
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
wenzelm
parents:
33389
diff
changeset
|
219 |
|
33670
02b7738aef6a
eliminated slightly odd kind argument of LocalTheory.note(s);
wenzelm
parents:
33644
diff
changeset
|
220 |
val ([(def_name, [th'])], lthy4) = lthy3 |
47080 | 221 |
|> Local_Theory.notes [((name, Code.add_default_eqn_attrib :: atts), [([th], [])])]; |
18786 | 222 |
|
33671 | 223 |
val lhs' = Morphism.term (Local_Theory.target_morphism lthy4) lhs; |
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
224 |
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
225 |
val _ = |
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
226 |
Proof_Display.print_consts int (Position.thread_data ()) lthy4 |
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
227 |
(member (op =) (Term.add_frees lhs' [])) [(x, T)]; |
33455
4da71b27b3fe
declare Spec_Rules for most basic definitional packages;
wenzelm
parents:
33389
diff
changeset
|
228 |
in ((lhs, (def_name, th')), lthy4) end; |
18786 | 229 |
|
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
230 |
val definition' = gen_def check_free_spec; |
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
231 |
fun definition spec = definition' spec false; |
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
232 |
val definition_cmd = gen_def read_free_spec; |
18786 | 233 |
|
19080 | 234 |
|
235 |
(* abbreviation *) |
|
236 |
||
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
237 |
fun gen_abbrev prep mode (raw_var, raw_prop) int lthy = |
19080 | 238 |
let |
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:
54883
diff
changeset
|
239 |
val lthy1 = lthy |
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:
54883
diff
changeset
|
240 |
|> Proof_Context.set_syntax_mode mode; |
30482
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
241 |
val ((vars, [(_, prop)]), _) = |
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents:
30472
diff
changeset
|
242 |
prep (the_list raw_var) [(Attrib.empty_binding, raw_prop)] |
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:
54883
diff
changeset
|
243 |
(lthy1 |> Proof_Context.set_mode Proof_Context.mode_abbrev); |
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:
54883
diff
changeset
|
244 |
val ((x, T), rhs) = Local_Defs.abs_def (#2 (Local_Defs.cert_def lthy1 prop)); |
56169
9b0dc5c704c9
reject internal names, notably from Term.free_dummy_patterns;
wenzelm
parents:
56026
diff
changeset
|
245 |
val _ = Name.reject_internal (x, []); |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
246 |
val var = |
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
247 |
(case vars of |
28965 | 248 |
[] => (Binding.name x, NoSyn) |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
249 |
| [((b, _), mx)] => |
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
250 |
let |
42494 | 251 |
val y = Variable.check_name b; |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
252 |
val _ = x = y orelse |
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
253 |
error ("Head of abbreviation " ^ quote x ^ " differs from declaration " ^ quote y ^ |
48992 | 254 |
Position.here (Binding.pos_of b)); |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
255 |
in (b, mx) end); |
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:
54883
diff
changeset
|
256 |
val lthy2 = lthy1 |
33671 | 257 |
|> Local_Theory.abbrev mode (var, rhs) |> snd |
42360 | 258 |
|> Proof_Context.restore_syntax_mode lthy; |
24724
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents:
24676
diff
changeset
|
259 |
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
260 |
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:
54883
diff
changeset
|
261 |
in lthy2 end; |
19080 | 262 |
|
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
263 |
val abbreviation = gen_abbrev check_free_spec; |
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
43329
diff
changeset
|
264 |
val abbreviation_cmd = gen_abbrev read_free_spec; |
19080 | 265 |
|
19664 | 266 |
|
21230
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents:
21206
diff
changeset
|
267 |
(* notation *) |
19664 | 268 |
|
35413 | 269 |
local |
270 |
||
271 |
fun gen_type_notation prep_type add mode args lthy = |
|
272 |
lthy |> Local_Theory.type_notation add mode (map (apfst (prep_type lthy)) args); |
|
273 |
||
24949 | 274 |
fun gen_notation prep_const add mode args lthy = |
33671 | 275 |
lthy |> Local_Theory.notation add mode (map (apfst (prep_const lthy)) args); |
19664 | 276 |
|
35413 | 277 |
in |
278 |
||
279 |
val type_notation = gen_type_notation (K I); |
|
55951
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55639
diff
changeset
|
280 |
val type_notation_cmd = |
56002 | 281 |
gen_type_notation (Proof_Context.read_type_name {proper = true, strict = false}); |
35413 | 282 |
|
24927
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
wenzelm
parents:
24848
diff
changeset
|
283 |
val notation = gen_notation (K I); |
56002 | 284 |
val notation_cmd = gen_notation (Proof_Context.read_const {proper = false, strict = false}); |
19664 | 285 |
|
35413 | 286 |
end; |
287 |
||
20914 | 288 |
|
21036 | 289 |
(* fact statements *) |
20914 | 290 |
|
45600
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
291 |
local |
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
292 |
|
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
293 |
fun gen_theorems prep_fact prep_att prep_vars |
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
294 |
kind raw_facts raw_fixes int lthy = |
20914 | 295 |
let |
296 |
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:
55955
diff
changeset
|
297 |
((name, map (prep_att lthy) atts), |
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55955
diff
changeset
|
298 |
bs |> map (fn (b, more_atts) => (prep_fact lthy b, map (prep_att lthy) more_atts)))); |
45600
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
299 |
val (_, ctxt') = lthy |> prep_vars raw_fixes |-> Proof_Context.add_fixes; |
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
300 |
|
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
301 |
val facts' = facts |
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
302 |
|> Attrib.partial_evaluation ctxt' |
58028
e4250d370657
tuned signature -- define some elementary operations earlier;
wenzelm
parents:
58011
diff
changeset
|
303 |
|> 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:
45584
diff
changeset
|
304 |
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:
56897
diff
changeset
|
305 |
val _ = Proof_Display.print_results int (Position.thread_data ()) lthy' ((kind, ""), res); |
20914 | 306 |
in (res, lthy') end; |
307 |
||
45600
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
308 |
in |
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
309 |
|
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
310 |
val theorems = gen_theorems (K I) (K I) Proof_Context.cert_vars; |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55955
diff
changeset
|
311 |
val theorems_cmd = gen_theorems Proof_Context.get_fact Attrib.check_src Proof_Context.read_vars; |
45600
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
312 |
|
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
45584
diff
changeset
|
313 |
end; |
20914 | 314 |
|
21036 | 315 |
|
21230
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents:
21206
diff
changeset
|
316 |
(* complex goal statements *) |
21036 | 317 |
|
318 |
local |
|
319 |
||
21236 | 320 |
fun prep_statement prep_att prep_stmt elems concl ctxt = |
321 |
(case concl of |
|
322 |
Element.Shows shows => |
|
21230
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents:
21206
diff
changeset
|
323 |
let |
28880 | 324 |
val (propp, elems_ctxt) = prep_stmt elems (map snd shows) ctxt; |
30472 | 325 |
val prems = Assumption.local_prems_of elems_ctxt ctxt; |
45390
e29521ef9059
tuned signature -- avoid spurious Thm.mixed_attribute;
wenzelm
parents:
45327
diff
changeset
|
326 |
val stmt = Attrib.map_specs (map prep_att) (map fst shows ~~ propp); |
45327 | 327 |
val goal_ctxt = (fold o fold) (Variable.auto_fixes o fst) propp elems_ctxt; |
45583
93499f36d59a
put structural attributes of 'obtains' in outer declarations, to make it actually work in local theory;
wenzelm
parents:
45390
diff
changeset
|
328 |
in (([], prems, stmt, NONE), goal_ctxt) end |
21236 | 329 |
| Element.Obtains obtains => |
21230
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents:
21206
diff
changeset
|
330 |
let |
28862 | 331 |
val case_names = obtains |> map_index (fn (i, (b, _)) => |
47021
f35f654f297d
clarified Binding.name_of vs Name_Space.base_name vs Variable.check_name (see also 9bd8d4addd6e, 3305f573294e);
wenzelm
parents:
46992
diff
changeset
|
332 |
if Binding.is_empty b then string_of_int (i + 1) else Name_Space.base_name b); |
21236 | 333 |
val constraints = obtains |> map (fn (_, (vars, _)) => |
28710 | 334 |
Element.Constrains |
42494 | 335 |
(vars |> map_filter (fn (x, SOME T) => SOME (Variable.check_name x, T) | _ => NONE))); |
21036 | 336 |
|
21236 | 337 |
val raw_propp = obtains |> map (fn (_, (_, props)) => map (rpair []) props); |
28880 | 338 |
val (propp, elems_ctxt) = prep_stmt (elems @ constraints) raw_propp ctxt; |
21236 | 339 |
|
42360 | 340 |
val thesis = Object_Logic.fixed_judgment (Proof_Context.theory_of ctxt) Auto_Bind.thesisN; |
21036 | 341 |
|
21236 | 342 |
fun assume_case ((name, (vars, _)), asms) ctxt' = |
343 |
let |
|
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
344 |
val bs = map fst vars; |
42494 | 345 |
val xs = map Variable.check_name bs; |
21236 | 346 |
val props = map fst asms; |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
347 |
val (Ts, _) = ctxt' |
21236 | 348 |
|> fold Variable.declare_term props |
42360 | 349 |
|> fold_map Proof_Context.inferred_param xs; |
46215
0da9433f959e
discontinued old-style Term.list_all_free in favour of plain Logic.all;
wenzelm
parents:
45601
diff
changeset
|
350 |
val params = map Free (xs ~~ Ts); |
0da9433f959e
discontinued old-style Term.list_all_free in favour of plain Logic.all;
wenzelm
parents:
45601
diff
changeset
|
351 |
val asm = fold_rev Logic.all params (Logic.list_implies (props, thesis)); |
45583
93499f36d59a
put structural attributes of 'obtains' in outer declarations, to make it actually work in local theory;
wenzelm
parents:
45390
diff
changeset
|
352 |
val _ = ctxt' |> Proof_Context.add_fixes (map (fn b => (b, NONE, NoSyn)) bs); |
21236 | 353 |
in |
45583
93499f36d59a
put structural attributes of 'obtains' in outer declarations, to make it actually work in local theory;
wenzelm
parents:
45390
diff
changeset
|
354 |
ctxt' |
93499f36d59a
put structural attributes of 'obtains' in outer declarations, to make it actually work in local theory;
wenzelm
parents:
45390
diff
changeset
|
355 |
|> Variable.auto_fixes asm |
42360 | 356 |
|> Proof_Context.add_assms_i Assumption.assume_export |
33369 | 357 |
[((name, [Context_Rules.intro_query NONE]), [(asm, [])])] |
21236 | 358 |
|>> (fn [(_, [th])] => th) |
359 |
end; |
|
360 |
||
45583
93499f36d59a
put structural attributes of 'obtains' in outer declarations, to make it actually work in local theory;
wenzelm
parents:
45390
diff
changeset
|
361 |
val more_atts = map (Attrib.internal o K) |
33368 | 362 |
[Rule_Cases.consumes (~ (length obtains)), Rule_Cases.case_names case_names]; |
30472 | 363 |
val prems = Assumption.local_prems_of elems_ctxt ctxt; |
45583
93499f36d59a
put structural attributes of 'obtains' in outer declarations, to make it actually work in local theory;
wenzelm
parents:
45390
diff
changeset
|
364 |
val stmt = [((Binding.empty, []), [(thesis, [])])]; |
21236 | 365 |
|
366 |
val (facts, goal_ctxt) = elems_ctxt |
|
42360 | 367 |
|> (snd o Proof_Context.add_fixes [(Binding.name Auto_Bind.thesisN, NONE, NoSyn)]) |
21236 | 368 |
|> fold_map assume_case (obtains ~~ propp) |
33644
5266a72e0889
eliminated slightly odd (unused) "axiom" and "assumption" -- collapsed to unspecific "";
wenzelm
parents:
33519
diff
changeset
|
369 |
|-> (fn ths => |
42360 | 370 |
Proof_Context.note_thmss "" [((Binding.name Obtain.thatN, []), [(ths, [])])] #> |
33644
5266a72e0889
eliminated slightly odd (unused) "axiom" and "assumption" -- collapsed to unspecific "";
wenzelm
parents:
33519
diff
changeset
|
371 |
#2 #> pair ths); |
45583
93499f36d59a
put structural attributes of 'obtains' in outer declarations, to make it actually work in local theory;
wenzelm
parents:
45390
diff
changeset
|
372 |
in ((more_atts, prems, stmt, SOME facts), goal_ctxt) end); |
21036 | 373 |
|
56026
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
wenzelm
parents:
56002
diff
changeset
|
374 |
fun gen_theorem schematic bundle_includes prep_att prep_stmt |
47067
4ef29b0c568f
optional 'includes' element for long theorem statements;
wenzelm
parents:
47066
diff
changeset
|
375 |
kind before_qed after_qed (name, raw_atts) raw_includes raw_elems raw_concl int lthy = |
21036 | 376 |
let |
47066
8a6124d09ff5
basic support for nested contexts including bundles;
wenzelm
parents:
47021
diff
changeset
|
377 |
val _ = Local_Theory.assert lthy; |
21036 | 378 |
|
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55955
diff
changeset
|
379 |
val elems = raw_elems |> map (Element.map_ctxt_attrib (prep_att lthy)); |
47067
4ef29b0c568f
optional 'includes' element for long theorem statements;
wenzelm
parents:
47066
diff
changeset
|
380 |
val ((more_atts, prems, stmt, facts), goal_ctxt) = lthy |
56026
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
wenzelm
parents:
56002
diff
changeset
|
381 |
|> bundle_includes raw_includes |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55955
diff
changeset
|
382 |
|> 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:
55955
diff
changeset
|
383 |
val atts = more_atts @ map (prep_att lthy) raw_atts; |
21036 | 384 |
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
385 |
val pos = Position.thread_data (); |
21036 | 386 |
fun after_qed' results goal_ctxt' = |
45584
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
wenzelm
parents:
45583
diff
changeset
|
387 |
let |
54883
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
51313
diff
changeset
|
388 |
val results' = |
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
51313
diff
changeset
|
389 |
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:
45583
diff
changeset
|
390 |
val (res, lthy') = |
49062
7e31dfd99ce7
discontinued complicated/unreliable notion of recent proofs within context;
wenzelm
parents:
49059
diff
changeset
|
391 |
if forall (Attrib.is_empty_binding o fst) stmt then (map (pair "") results', lthy) |
45584
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
wenzelm
parents:
45583
diff
changeset
|
392 |
else |
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
wenzelm
parents:
45583
diff
changeset
|
393 |
Local_Theory.notes_kind kind |
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
wenzelm
parents:
45583
diff
changeset
|
394 |
(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:
45583
diff
changeset
|
395 |
val lthy'' = |
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
wenzelm
parents:
45583
diff
changeset
|
396 |
if Attrib.is_empty_binding (name, atts) then |
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
397 |
(Proof_Display.print_results int pos lthy' ((kind, ""), res); lthy') |
28080
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
398 |
else |
4723eb2456ce
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27858
diff
changeset
|
399 |
let |
45584
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
wenzelm
parents:
45583
diff
changeset
|
400 |
val ([(res_name, _)], lthy'') = |
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
wenzelm
parents:
45583
diff
changeset
|
401 |
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:
56897
diff
changeset
|
402 |
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:
45583
diff
changeset
|
403 |
in lthy'' end; |
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
wenzelm
parents:
45583
diff
changeset
|
404 |
in after_qed results' lthy'' end; |
21036 | 405 |
in |
406 |
goal_ctxt |
|
42360 | 407 |
|> Proof_Context.note_thmss "" [((Binding.name Auto_Bind.assmsN, []), [(prems, [])])] |
21450 | 408 |
|> snd |
36323
655e2d74de3a
modernized naming conventions of main Isar proof elements;
wenzelm
parents:
36317
diff
changeset
|
409 |
|> 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:
32786
diff
changeset
|
410 |
|> (case facts of NONE => I | SOME ths => Proof.refine_insert ths) |
36317
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents:
36106
diff
changeset
|
411 |
|> tap (fn state => not schematic andalso Proof.schematic_goal state andalso |
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents:
36106
diff
changeset
|
412 |
error "Illegal schematic goal statement") |
21036 | 413 |
end; |
414 |
||
21230
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents:
21206
diff
changeset
|
415 |
in |
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents:
21206
diff
changeset
|
416 |
|
56026
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
wenzelm
parents:
56002
diff
changeset
|
417 |
val theorem = |
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
wenzelm
parents:
56002
diff
changeset
|
418 |
gen_theorem false Bundle.includes (K I) Expression.cert_statement; |
47067
4ef29b0c568f
optional 'includes' element for long theorem statements;
wenzelm
parents:
47066
diff
changeset
|
419 |
val theorem_cmd = |
56026
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
wenzelm
parents:
56002
diff
changeset
|
420 |
gen_theorem false Bundle.includes_cmd Attrib.check_src Expression.read_statement; |
36317
506d732cb522
explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents:
36106
diff
changeset
|
421 |
|
56026
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
wenzelm
parents:
56002
diff
changeset
|
422 |
val schematic_theorem = |
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
wenzelm
parents:
56002
diff
changeset
|
423 |
gen_theorem true Bundle.includes (K I) Expression.cert_statement; |
47067
4ef29b0c568f
optional 'includes' element for long theorem statements;
wenzelm
parents:
47066
diff
changeset
|
424 |
val schematic_theorem_cmd = |
56026
893fe12639bc
tuned signature -- prefer Name_Space.get with its builtin error;
wenzelm
parents:
56002
diff
changeset
|
425 |
gen_theorem true Bundle.includes_cmd Attrib.check_src Expression.read_statement; |
21036 | 426 |
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
427 |
end; |
21036 | 428 |
|
429 |
end; |