6 toplevel polymorphism. |
6 toplevel polymorphism. |
7 *) |
7 *) |
8 |
8 |
9 signature SPECIFICATION = |
9 signature SPECIFICATION = |
10 sig |
10 sig |
11 val quiet_mode: bool ref |
|
12 val print_consts: local_theory -> (string * typ -> bool) -> (string * typ) list -> unit |
11 val print_consts: local_theory -> (string * typ -> bool) -> (string * typ) list -> unit |
13 val check_specification: (string * typ option * mixfix) list -> |
12 val check_specification: (string * typ option * mixfix) list -> |
14 ((string * Attrib.src list) * term list) list list -> Proof.context -> |
13 ((string * Attrib.src list) * term list) list list -> Proof.context -> |
15 (((string * typ) * mixfix) list * ((string * Attrib.src list) * term list) list) * |
14 (((string * typ) * mixfix) list * ((string * Attrib.src list) * term list) list) * |
16 Proof.context |
15 Proof.context |
46 val notation_cmd: bool -> Syntax.mode -> (string * mixfix) list -> local_theory -> local_theory |
45 val notation_cmd: bool -> Syntax.mode -> (string * mixfix) list -> local_theory -> local_theory |
47 val theorems: string -> ((bstring * Attrib.src list) * (thm list * Attrib.src list) list) list |
46 val theorems: string -> ((bstring * Attrib.src list) * (thm list * Attrib.src list) list) list |
48 -> local_theory -> (bstring * thm list) list * local_theory |
47 -> local_theory -> (bstring * thm list) list * local_theory |
49 val theorems_cmd: string -> ((bstring * Attrib.src list) * (thmref * Attrib.src list) list) list |
48 val theorems_cmd: string -> ((bstring * Attrib.src list) * (thmref * Attrib.src list) list) list |
50 -> local_theory -> (bstring * thm list) list * local_theory |
49 -> local_theory -> (bstring * thm list) list * local_theory |
51 val theorem: string -> Method.text option -> (thm list list -> local_theory -> local_theory) -> |
50 val theorem: string -> Method.text option -> |
|
51 (thm list list -> local_theory -> local_theory) -> |
52 string * Attrib.src list -> Element.context_i Locale.element list -> Element.statement_i -> |
52 string * Attrib.src list -> Element.context_i Locale.element list -> Element.statement_i -> |
53 bool -> local_theory -> Proof.state |
53 bool -> local_theory -> Proof.state |
54 val theorem_cmd: string -> Method.text option -> (thm list list -> local_theory -> local_theory) -> |
54 val theorem_cmd: string -> Method.text option -> |
|
55 (thm list list -> local_theory -> local_theory) -> |
55 string * Attrib.src list -> Element.context Locale.element list -> Element.statement -> |
56 string * Attrib.src list -> Element.context Locale.element list -> Element.statement -> |
56 bool -> local_theory -> Proof.state |
57 bool -> local_theory -> Proof.state |
57 val add_theorem_hook: (bool -> Proof.state -> Proof.state) -> Context.generic -> Context.generic |
58 val add_theorem_hook: (bool -> Proof.state -> Proof.state) -> Context.generic -> Context.generic |
58 end; |
59 end; |
59 |
60 |
61 struct |
62 struct |
62 |
63 |
63 |
64 |
64 (* diagnostics *) |
65 (* diagnostics *) |
65 |
66 |
66 val quiet_mode = ref false; |
|
67 |
|
68 fun print_consts _ _ [] = () |
67 fun print_consts _ _ [] = () |
69 | print_consts ctxt pred cs = |
68 | print_consts ctxt pred cs = Pretty.writeln (ProofDisplay.pretty_consts ctxt pred cs); |
70 if ! quiet_mode then () else Pretty.writeln (ProofDisplay.pretty_consts ctxt pred cs); |
|
71 |
|
72 fun present_results ctxt res = |
|
73 if ! quiet_mode then () else ProofDisplay.present_results ctxt res; |
|
74 |
|
75 fun present_results' ctxt kind res = present_results ctxt ((kind, ""), res); |
|
76 |
69 |
77 |
70 |
78 (* prepare specification *) |
71 (* prepare specification *) |
79 |
72 |
80 local |
73 local |
148 |
141 |
149 (* axiomatization *) |
142 (* axiomatization *) |
150 |
143 |
151 fun gen_axioms prep raw_vars raw_specs lthy = |
144 fun gen_axioms prep raw_vars raw_specs lthy = |
152 let |
145 let |
153 val (vars, specs) = fst (prep raw_vars [raw_specs] lthy); |
146 val ((vars, specs), _) = prep raw_vars [raw_specs] lthy; |
154 val cs = map fst vars; |
147 val ((consts, axioms), lthy') = LocalTheory.axioms Thm.axiomK (vars, specs) lthy; |
155 val spec_frees = member (op =) ((fold (fold Term.add_frees o snd) specs [])); |
|
156 |
|
157 val ((constants, axioms), lthy') = lthy |
|
158 |> LocalTheory.consts spec_frees vars |
|
159 ||>> LocalTheory.axioms Thm.axiomK specs; |
|
160 val consts = map #1 constants; |
|
161 val consts' = map (Morphism.term (LocalTheory.target_morphism lthy')) consts; |
148 val consts' = map (Morphism.term (LocalTheory.target_morphism lthy')) consts; |
162 |
149 val _ = print_consts lthy' (member (op =) (fold Term.add_frees consts' [])) (map fst vars); |
163 (* FIXME generic target!? *) |
150 in ((consts, axioms), lthy') end; |
164 val hs = map (Term.head_of o #2 o Logic.dest_equals o Thm.prop_of o #2) constants; |
|
165 val lthy'' = lthy' |> LocalTheory.theory (Theory.add_finals_i false hs); |
|
166 |
|
167 val _ = print_consts lthy' (member (op =) (fold Term.add_frees consts' [])) cs; |
|
168 in ((consts, axioms), lthy'') end; |
|
169 |
151 |
170 val axiomatization = gen_axioms check_specification; |
152 val axiomatization = gen_axioms check_specification; |
171 val axiomatization_cmd = gen_axioms read_specification; |
153 val axiomatization_cmd = gen_axioms read_specification; |
172 |
154 |
173 |
155 |
206 val ((x, T), rhs) = LocalDefs.abs_def (#2 (LocalDefs.cert_def lthy prop)); |
188 val ((x, T), rhs) = LocalDefs.abs_def (#2 (LocalDefs.cert_def lthy prop)); |
207 val mx = (case vars of [] => NoSyn | [((y, _), mx)] => |
189 val mx = (case vars of [] => NoSyn | [((y, _), mx)] => |
208 if x = y then mx |
190 if x = y then mx |
209 else error ("Head of abbreviation " ^ quote x ^ " differs from declaration " ^ quote y)); |
191 else error ("Head of abbreviation " ^ quote x ^ " differs from declaration " ^ quote y)); |
210 val lthy' = lthy |
192 val lthy' = lthy |
211 |> ProofContext.set_syntax_mode mode (* FIXME !? *) |
193 |> ProofContext.set_syntax_mode mode (* FIXME ?!? *) |
212 |> LocalTheory.abbrev mode ((x, mx), rhs) |> snd |
194 |> LocalTheory.abbrev mode ((x, mx), rhs) |> snd |
213 |> ProofContext.restore_syntax_mode lthy; |
195 |> ProofContext.restore_syntax_mode lthy; |
214 |
196 |
215 val _ = print_consts lthy' (K false) [(x, T)] |
197 val _ = print_consts lthy' (K false) [(x, T)] |
216 in lthy' end; |
198 in lthy' end; |
235 val attrib = prep_att (ProofContext.theory_of lthy); |
217 val attrib = prep_att (ProofContext.theory_of lthy); |
236 val facts = raw_facts |> map (fn ((name, atts), bs) => |
218 val facts = raw_facts |> map (fn ((name, atts), bs) => |
237 ((name, map attrib atts), |
219 ((name, map attrib atts), |
238 bs |> map (fn (b, more_atts) => (prep_thms lthy b, map attrib more_atts)))); |
220 bs |> map (fn (b, more_atts) => (prep_thms lthy b, map attrib more_atts)))); |
239 val (res, lthy') = lthy |> LocalTheory.notes kind facts; |
221 val (res, lthy') = lthy |> LocalTheory.notes kind facts; |
240 val _ = present_results' lthy' kind res; |
222 val _ = ProofDisplay.present_results lthy' ((kind, ""), res); |
241 in (res, lthy') end; |
223 in (res, lthy') end; |
242 |
224 |
243 val theorems = gen_theorems (K I) (K I); |
225 val theorems = gen_theorems (K I) (K I); |
244 val theorems_cmd = gen_theorems ProofContext.get_thms Attrib.intern_src; |
226 val theorems_cmd = gen_theorems ProofContext.get_thms Attrib.intern_src; |
245 |
227 |
333 burrow (map Goal.norm_result o ProofContext.export goal_ctxt' lthy) results |
315 burrow (map Goal.norm_result o ProofContext.export goal_ctxt' lthy) results |
334 in |
316 in |
335 lthy |
317 lthy |
336 |> LocalTheory.notes kind (map2 (fn (a, _) => fn ths => (a, [(ths, [])])) stmt results') |
318 |> LocalTheory.notes kind (map2 (fn (a, _) => fn ths => (a, [(ths, [])])) stmt results') |
337 |> (fn (res, lthy') => |
319 |> (fn (res, lthy') => |
338 (present_results lthy' ((kind, name), res); |
320 (ProofDisplay.present_results lthy' ((kind, name), res); |
339 if name = "" andalso null atts then lthy' |
321 if name = "" andalso null atts then lthy' |
340 else #2 (LocalTheory.notes kind [((name, atts), [(maps #2 res, [])])] lthy'))) |
322 else #2 (LocalTheory.notes kind [((name, atts), [(maps #2 res, [])])] lthy'))) |
341 |> after_qed results' |
323 |> after_qed results' |
342 end; |
324 end; |
343 in |
325 in |