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