| author | wenzelm |
| Wed, 25 Jan 2006 00:21:44 +0100 | |
| changeset 18786 | 591a37d48794 |
| parent 18771 | 63efe00371af |
| child 18810 | 6dc5416368e9 |
| 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 |
ID: $Id$ |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
3 |
Author: Makarius |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
4 |
|
| 18771 | 5 |
Common theory/locale specifications --- with type-inference, but |
6 |
without internal polymorphism. |
|
|
18620
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 |
|
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
9 |
signature SPECIFICATION = |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
10 |
sig |
| 18771 | 11 |
val read_specification: (string * string option * mixfix) list -> |
12 |
((string * Attrib.src list) * string list) list -> Proof.context -> |
|
13 |
(((string * typ) * mixfix) list * ((string * Attrib.src list) * term list) list) * |
|
14 |
Proof.context |
|
15 |
val cert_specification: (string * typ option * mixfix) list -> |
|
16 |
((string * Attrib.src list) * term list) list -> Proof.context -> |
|
17 |
(((string * typ) * mixfix) list * ((string * Attrib.src list) * term list) list) * |
|
18 |
Proof.context |
|
19 |
val axiomatization: xstring option -> (string * string option * mixfix) list -> |
|
20 |
((bstring * Attrib.src list) * string list) list -> theory -> |
|
21 |
(term list * (bstring * thm list) list) * (theory * Proof.context) |
|
22 |
val axiomatization_i: string option -> (string * typ option * mixfix) list -> |
|
23 |
((bstring * Attrib.src list) * term list) list -> theory -> |
|
24 |
(term list * (bstring * thm list) list) * (theory * Proof.context) |
|
| 18786 | 25 |
val definition: xstring option -> |
26 |
((string * string option * mixfix) option * ((string * Attrib.src list) * string)) list -> |
|
27 |
theory -> (term * (bstring * thm)) list * (theory * Proof.context) |
|
28 |
val definition_i: string option -> |
|
29 |
((string * typ option * mixfix) option * ((string * Attrib.src list) * term)) list -> |
|
30 |
theory -> (term * (bstring * thm)) list * (theory * Proof.context) |
|
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
31 |
end; |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
32 |
|
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
33 |
structure Specification: SPECIFICATION = |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
34 |
struct |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
35 |
|
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
36 |
(* prepare specification *) |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
37 |
|
| 18670 | 38 |
fun prep_specification prep_vars prep_propp prep_att |
| 18771 | 39 |
raw_vars raw_specs ctxt = |
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
40 |
let |
| 18670 | 41 |
val thy = ProofContext.theory_of ctxt; |
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
42 |
|
| 18670 | 43 |
val (vars, vars_ctxt) = ctxt |> prep_vars raw_vars; |
44 |
val (xs, params_ctxt) = vars_ctxt |> ProofContext.add_fixes_i vars; |
|
45 |
val ((specs, vs), specs_ctxt) = |
|
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
46 |
prep_propp (params_ctxt, map (map (rpair ([], [])) o snd) raw_specs) |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
47 |
|> swap |>> map (map fst) |
| 18771 | 48 |
||>> fold_map ProofContext.inferred_param xs; |
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
49 |
|
| 18771 | 50 |
val params = vs ~~ map #3 vars; |
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
51 |
val names = map (fst o fst) raw_specs; |
| 18670 | 52 |
val atts = map (map (prep_att thy) o snd o fst) raw_specs; |
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
53 |
in ((params, (names ~~ atts) ~~ specs), specs_ctxt) end; |
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
54 |
|
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
55 |
fun read_specification x = |
| 18771 | 56 |
prep_specification ProofContext.read_vars ProofContext.read_propp Attrib.intern_src x; |
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
57 |
fun cert_specification x = |
| 18670 | 58 |
prep_specification ProofContext.cert_vars ProofContext.cert_propp (K I) x; |
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
59 |
|
|
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
60 |
|
| 18771 | 61 |
(* axiomatization *) |
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
62 |
|
| 18771 | 63 |
fun gen_axiomatization prep init locale raw_vars raw_specs thy = |
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
64 |
let |
| 18786 | 65 |
val ctxt = init locale thy; |
66 |
val (vars, specs) = fst (prep raw_vars raw_specs ctxt); |
|
67 |
||
| 18771 | 68 |
val (consts, consts_ctxt) = ctxt |> LocalTheory.consts vars; |
69 |
val subst = Term.subst_atomic (map (Free o fst) vars ~~ consts); |
|
| 18786 | 70 |
|
| 18771 | 71 |
val (axioms, axioms_ctxt) = |
72 |
consts_ctxt |
|
73 |
|> LocalTheory.axioms (specs |> map (fn (a, props) => (a, map subst props))) |
|
| 18786 | 74 |
||> LocalTheory.theory (Theory.add_finals_i false (map Term.head_of consts)); |
75 |
||
| 18771 | 76 |
val _ = Pretty.writeln (LocalTheory.pretty_consts ctxt (map fst vars)); |
77 |
in ((consts, axioms), `LocalTheory.exit axioms_ctxt) end; |
|
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
78 |
|
| 18771 | 79 |
val axiomatization = gen_axiomatization read_specification LocalTheory.init; |
80 |
val axiomatization_i = gen_axiomatization cert_specification LocalTheory.init_i; |
|
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
81 |
|
| 18786 | 82 |
|
83 |
(* definition *) |
|
84 |
||
85 |
fun gen_definition prep init locale args thy = |
|
86 |
let |
|
87 |
fun define (raw_var, (raw_a, raw_prop)) ctxt = |
|
88 |
let |
|
89 |
val (vars, [(a, [prop])]) = fst (prep (the_list raw_var) [(raw_a, [raw_prop])] ctxt); |
|
90 |
val ((x, T), rhs) = prop |
|
91 |
|> Logic.strip_imp_concl |
|
92 |
|> ObjectLogic.reverse_atomize_term thy |
|
93 |
|> (snd o ProofContext.cert_def ctxt) |
|
94 |
|> ProofContext.abs_def; |
|
95 |
val mx = (case vars of [] => NoSyn | [((x', _), mx)] => |
|
96 |
if x = x' then mx |
|
97 |
else error ("Head of definition " ^ quote x ^ " differs from declaration " ^ quote x'));
|
|
98 |
||
99 |
fun prove ctxt' const def = |
|
100 |
let |
|
101 |
val prop' = Term.subst_atomic [(Free (x, T), const)] prop; |
|
102 |
val (As, B) = Logic.strip_horn prop'; |
|
103 |
in |
|
104 |
(Goal.prove (ProofContext.theory_of ctxt') [] As B (K (ALLGOALS |
|
105 |
(ObjectLogic.reverse_atomize_tac THEN' |
|
106 |
Tactic.rewrite_goal_tac [def] THEN' |
|
107 |
Tactic.resolve_tac [Drule.reflexive_thm]))) |
|
108 |
handle ERROR msg => cat_error msg "Failed to prove definitional specification.") |
|
109 |
|> LocalTheory.standard (ProofContext.fix_frees prop' ctxt') |
|
110 |
end; |
|
111 |
in ctxt |> LocalTheory.def' prove ((x, mx), (a, rhs)) |>> pair (x, T) end; |
|
112 |
||
113 |
val ctxt = init locale thy; |
|
114 |
val ((decls, defs), defs_ctxt) = ctxt |> fold_map define args |>> split_list; |
|
115 |
val _ = Pretty.writeln (LocalTheory.pretty_consts ctxt decls); |
|
116 |
in (defs, `LocalTheory.exit defs_ctxt) end; |
|
117 |
||
118 |
val definition = gen_definition read_specification LocalTheory.init; |
|
119 |
val definition_i = gen_definition cert_specification LocalTheory.init_i; |
|
120 |
||
|
18620
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff
changeset
|
121 |
end; |