haftmann@41829
|
1 |
(* Title: Tools/interpretation_with_defs.ML
|
haftmann@41829
|
2 |
Author: Florian Haftmann, TU Muenchen
|
haftmann@41829
|
3 |
|
haftmann@41829
|
4 |
Interpretation accompanied with mixin definitions. EXPERIMENTAL.
|
haftmann@41829
|
5 |
*)
|
haftmann@41829
|
6 |
|
haftmann@41829
|
7 |
signature INTERPRETATION_WITH_DEFS =
|
haftmann@41829
|
8 |
sig
|
haftmann@41829
|
9 |
val interpretation: Expression.expression_i ->
|
haftmann@41829
|
10 |
(Attrib.binding * ((binding * mixfix) * term)) list -> (Attrib.binding * term) list ->
|
haftmann@41829
|
11 |
theory -> Proof.state
|
haftmann@41829
|
12 |
val interpretation_cmd: Expression.expression ->
|
haftmann@41829
|
13 |
(Attrib.binding * ((binding * mixfix) * string)) list -> (Attrib.binding * string) list ->
|
haftmann@41829
|
14 |
theory -> Proof.state
|
haftmann@41829
|
15 |
end;
|
haftmann@41829
|
16 |
|
haftmann@41829
|
17 |
structure Interpretation_With_Defs : INTERPRETATION_WITH_DEFS =
|
haftmann@41829
|
18 |
struct
|
haftmann@41829
|
19 |
|
wenzelm@47730
|
20 |
fun note_eqns_register deps witss def_eqns attrss eqns export export' =
|
haftmann@41829
|
21 |
let
|
haftmann@41829
|
22 |
fun meta_rewrite context =
|
haftmann@41829
|
23 |
map (Local_Defs.meta_rewrite_rule (Context.proof_of context) #> Drule.abs_def) o
|
haftmann@41829
|
24 |
maps snd;
|
haftmann@41829
|
25 |
in
|
wenzelm@47730
|
26 |
Element.generic_note_thmss Thm.lemmaK
|
haftmann@41829
|
27 |
(attrss ~~ map (fn eqn => [([Morphism.thm (export' $> export) eqn], [])]) eqns)
|
wenzelm@47730
|
28 |
#-> (fn facts => `(fn context => meta_rewrite context facts))
|
wenzelm@47730
|
29 |
#-> (fn eqns => fold (fn ((dep, morph), wits) =>
|
haftmann@41829
|
30 |
fn context =>
|
wenzelm@47730
|
31 |
Locale.add_registration
|
wenzelm@47730
|
32 |
(dep, morph $> Element.satisfy_morphism (map (Element.transform_witness export') wits))
|
haftmann@41829
|
33 |
(Element.eq_morphism (Context.theory_of context) (def_eqns @ eqns) |>
|
haftmann@41829
|
34 |
Option.map (rpair true))
|
haftmann@41829
|
35 |
export context) (deps ~~ witss))
|
haftmann@41829
|
36 |
end;
|
haftmann@41829
|
37 |
|
haftmann@41829
|
38 |
local
|
haftmann@41829
|
39 |
|
haftmann@41829
|
40 |
fun gen_interpretation prep_expr prep_decl parse_term parse_prop prep_attr
|
haftmann@41829
|
41 |
expression raw_defs raw_eqns theory =
|
haftmann@41829
|
42 |
let
|
haftmann@41829
|
43 |
val (_, (_, defs_ctxt)) =
|
wenzelm@43232
|
44 |
prep_decl expression I [] (Proof_Context.init_global theory);
|
haftmann@41829
|
45 |
|
haftmann@41829
|
46 |
val rhss = map (parse_term defs_ctxt o snd o snd) raw_defs
|
haftmann@41829
|
47 |
|> Syntax.check_terms defs_ctxt;
|
wenzelm@47780
|
48 |
val defs = map2 (fn ((name, atts), ((b, mx), _)) => fn rhs =>
|
wenzelm@47780
|
49 |
((b, mx), ((Thm.def_binding_optional b name, atts), rhs))) raw_defs rhss;
|
haftmann@41829
|
50 |
|
haftmann@41829
|
51 |
val (def_eqns, theory') = theory
|
haftmann@41829
|
52 |
|> Named_Target.theory_init
|
haftmann@41829
|
53 |
|> fold_map (Local_Theory.define) defs
|
haftmann@41829
|
54 |
|>> map (Thm.symmetric o snd o snd)
|
haftmann@41829
|
55 |
|> Local_Theory.exit_result_global (map o Morphism.thm);
|
haftmann@41829
|
56 |
|
haftmann@41829
|
57 |
val ((propss, deps, export), expr_ctxt) = theory'
|
wenzelm@43232
|
58 |
|> Proof_Context.init_global
|
haftmann@41829
|
59 |
|> prep_expr expression;
|
haftmann@41829
|
60 |
|
haftmann@41829
|
61 |
val eqns = map (parse_prop expr_ctxt o snd) raw_eqns
|
haftmann@41829
|
62 |
|> Syntax.check_terms expr_ctxt;
|
haftmann@41829
|
63 |
val attrss = map ((apsnd o map) (prep_attr theory) o fst) raw_eqns;
|
haftmann@41829
|
64 |
val goal_ctxt = fold Variable.auto_fixes eqns expr_ctxt;
|
haftmann@41829
|
65 |
val export' = Variable.export_morphism goal_ctxt expr_ctxt;
|
haftmann@41829
|
66 |
|
haftmann@41829
|
67 |
fun after_qed witss eqns =
|
wenzelm@43232
|
68 |
(Proof_Context.background_theory o Context.theory_map)
|
haftmann@41829
|
69 |
(note_eqns_register deps witss def_eqns attrss eqns export export');
|
haftmann@41829
|
70 |
|
haftmann@41829
|
71 |
in Element.witness_proof_eqs after_qed propss eqns goal_ctxt end;
|
haftmann@41829
|
72 |
|
haftmann@41829
|
73 |
in
|
haftmann@41829
|
74 |
|
haftmann@41829
|
75 |
fun interpretation x = gen_interpretation Expression.cert_goal_expression
|
haftmann@41829
|
76 |
Expression.cert_declaration (K I) (K I) (K I) x;
|
haftmann@41829
|
77 |
fun interpretation_cmd x = gen_interpretation Expression.read_goal_expression
|
haftmann@41829
|
78 |
Expression.read_declaration Syntax.parse_term Syntax.parse_prop Attrib.intern_src x;
|
haftmann@41829
|
79 |
|
haftmann@41829
|
80 |
end;
|
haftmann@41829
|
81 |
|
haftmann@41829
|
82 |
val _ =
|
haftmann@41829
|
83 |
Outer_Syntax.command "interpretation"
|
haftmann@41829
|
84 |
"prove interpretation of locale expression in theory" Keyword.thy_goal
|
haftmann@41829
|
85 |
(Parse.!!! (Parse_Spec.locale_expression true) --
|
wenzelm@47823
|
86 |
Scan.optional (@{keyword "defines"} |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":"
|
wenzelm@47823
|
87 |
-- ((Parse.binding -- Parse.opt_mixfix') --| @{keyword "is"} -- Parse.term))) [] --
|
haftmann@41829
|
88 |
Scan.optional (Parse.where_ |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) []
|
haftmann@41829
|
89 |
>> (fn ((expr, defs), equations) => Toplevel.print o
|
haftmann@41829
|
90 |
Toplevel.theory_to_proof (interpretation_cmd expr defs equations)));
|
haftmann@41829
|
91 |
|
haftmann@41829
|
92 |
end;
|