author | wenzelm |
Tue, 25 Apr 2006 22:22:58 +0200 | |
changeset 19460 | 2b37469d52ad |
parent 19418 | 03b01c9314fc |
child 19482 | 9f11af8f7ef9 |
permissions | -rw-r--r-- |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/axclass.ML |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
2 |
ID: $Id$ |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
3 |
Author: Markus Wenzel, TU Muenchen |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
4 |
|
19460 | 5 |
Axiomatic type classes: managing predicates and parameter collections. |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
6 |
*) |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
7 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
8 |
signature AX_CLASS = |
3938 | 9 |
sig |
6379 | 10 |
val print_axclasses: theory -> unit |
19460 | 11 |
val get_info: theory -> class -> {def: thm, intro: thm, axioms: thm list} |
19392 | 12 |
val get_instances: theory -> |
19405 | 13 |
{classes: unit Graph.T, |
14 |
classrel: ((class * class) * thm) list, |
|
15 |
arities: ((string * sort list * class) * thm) list} |
|
19243
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
16 |
val class_intros: theory -> thm list |
19460 | 17 |
val params_of: theory -> class -> string list |
18 |
val all_params_of: theory -> sort -> string list |
|
19405 | 19 |
val cert_classrel: theory -> class * class -> class * class |
20 |
val read_classrel: theory -> xstring * xstring -> class * class |
|
21 |
val add_classrel: thm -> theory -> theory |
|
22 |
val add_arity: thm -> theory -> theory |
|
23 |
val prove_classrel: class * class -> tactic -> theory -> theory |
|
19243
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
24 |
val prove_arity: string * sort list * sort -> tactic -> theory -> theory |
19418
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
25 |
val add_axclass: bstring * xstring list -> string list -> |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
26 |
((bstring * Attrib.src list) * string list) list -> theory -> class * theory |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
27 |
val add_axclass_i: bstring * class list -> string list -> |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
28 |
((bstring * attribute list) * term list) list -> theory -> class * theory |
3938 | 29 |
end; |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
30 |
|
15801 | 31 |
structure AxClass: AX_CLASS = |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
32 |
struct |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
33 |
|
19460 | 34 |
|
19405 | 35 |
(** theory data **) |
423 | 36 |
|
19405 | 37 |
(* class parameters (canonical order) *) |
423 | 38 |
|
19405 | 39 |
type param = string * class; |
423 | 40 |
|
19405 | 41 |
fun add_param pp ((x, c): param) params = |
42 |
(case AList.lookup (op =) params x of |
|
43 |
NONE => (x, c) :: params |
|
44 |
| SOME c' => error ("Duplicate class parameter " ^ quote x ^ |
|
45 |
" for " ^ Pretty.string_of_sort pp [c] ^ |
|
46 |
(if c = c' then "" else " and " ^ Pretty.string_of_sort pp [c']))); |
|
423 | 47 |
|
19405 | 48 |
fun merge_params _ ([], qs) = qs |
49 |
| merge_params pp (ps, qs) = |
|
50 |
fold_rev (fn q => if member (op =) ps q then I else add_param pp q) qs ps; |
|
423 | 51 |
|
52 |
||
19392 | 53 |
(* axclass *) |
6379 | 54 |
|
19243
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
55 |
val introN = "intro"; |
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
56 |
val axiomsN = "axioms"; |
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
57 |
|
19392 | 58 |
datatype axclass = AxClass of |
19460 | 59 |
{def: thm, |
19392 | 60 |
intro: thm, |
61 |
axioms: thm list}; |
|
62 |
||
19460 | 63 |
type axclasses = axclass Symtab.table * param list; |
19392 | 64 |
|
19460 | 65 |
fun make_axclass (def, intro, axioms) = |
66 |
AxClass {def = def, intro = intro, axioms = axioms}; |
|
19405 | 67 |
|
68 |
fun merge_axclasses pp ((tab1, params1), (tab2, params2)) : axclasses = |
|
69 |
(Symtab.merge (K true) (tab1, tab2), merge_params pp (params1, params2)); |
|
70 |
||
19392 | 71 |
|
72 |
(* instances *) |
|
73 |
||
74 |
datatype instances = Instances of |
|
19405 | 75 |
{classes: unit Graph.T, (*raw relation -- no closure!*) |
76 |
classrel: ((class * class) * thm) list, |
|
77 |
arities: ((string * sort list * class) * thm) list}; |
|
19392 | 78 |
|
19405 | 79 |
fun make_instances (classes, classrel, arities) = |
80 |
Instances {classes = classes, classrel = classrel, arities = arities}; |
|
6379 | 81 |
|
19405 | 82 |
fun map_instances f (Instances {classes, classrel, arities}) = |
83 |
make_instances (f (classes, classrel, arities)); |
|
19392 | 84 |
|
85 |
fun merge_instances |
|
19405 | 86 |
(Instances {classes = classes1, classrel = classrel1, arities = arities1}, |
87 |
Instances {classes = classes2, classrel = classrel2, arities = arities2}) = |
|
19392 | 88 |
make_instances |
19405 | 89 |
(Graph.merge (K true) (classes1, classes2), |
90 |
merge (eq_fst op =) (classrel1, classrel2), |
|
19392 | 91 |
merge (eq_fst op =) (arities1, arities2)); |
92 |
||
93 |
||
19405 | 94 |
(* data *) |
19392 | 95 |
|
96 |
structure AxClassData = TheoryDataFun |
|
16458 | 97 |
(struct |
19392 | 98 |
val name = "Pure/axclass"; |
19405 | 99 |
type T = axclasses * instances; |
100 |
val empty : T = ((Symtab.empty, []), make_instances (Graph.empty, [], [])); |
|
6546 | 101 |
val copy = I; |
16458 | 102 |
val extend = I; |
19405 | 103 |
fun merge pp ((axclasses1, instances1), (axclasses2, instances2)) = |
104 |
(merge_axclasses pp (axclasses1, axclasses2), merge_instances (instances1, instances2)); |
|
19460 | 105 |
fun print _ _ = (); |
16458 | 106 |
end); |
6379 | 107 |
|
19392 | 108 |
val _ = Context.add_setup AxClassData.init; |
6379 | 109 |
|
110 |
||
19460 | 111 |
(* lookup classes *) |
19392 | 112 |
|
19405 | 113 |
val lookup_info = Symtab.lookup o #1 o #1 o AxClassData.get; |
6379 | 114 |
|
17281
3b9ff0131ed1
name space prefix is now "c_class" instead of just "c";
wenzelm
parents:
17221
diff
changeset
|
115 |
fun get_info thy c = |
3b9ff0131ed1
name space prefix is now "c_class" instead of just "c";
wenzelm
parents:
17221
diff
changeset
|
116 |
(case lookup_info thy c of |
19392 | 117 |
SOME (AxClass info) => info |
118 |
| NONE => error ("Unknown axclass " ^ quote c)); |
|
6379 | 119 |
|
19123 | 120 |
fun class_intros thy = |
19392 | 121 |
let |
122 |
fun add_intro c = |
|
123 |
(case lookup_info thy c of SOME (AxClass {intro, ...}) => cons intro | _ => I); |
|
124 |
val classes = Sign.classes thy; |
|
125 |
in map (Thm.class_triv thy) classes @ fold add_intro classes [] end; |
|
15876
a67343c6ab2a
sane interfaces for tactical instance proofs (do not expand defs of theory, proper handling of sort instances);
wenzelm
parents:
15853
diff
changeset
|
126 |
|
a67343c6ab2a
sane interfaces for tactical instance proofs (do not expand defs of theory, proper handling of sort instances);
wenzelm
parents:
15853
diff
changeset
|
127 |
|
19460 | 128 |
(* lookup parameters *) |
129 |
||
130 |
fun get_params thy pred = |
|
131 |
let val params = #2 (#1 (AxClassData.get thy)) |
|
132 |
in fold (fn (x, c) => if pred c then cons x else I) params [] end; |
|
133 |
||
134 |
fun params_of thy c = get_params thy (fn c' => c' = c); |
|
135 |
fun all_params_of thy S = get_params thy (fn c => Sign.subsort thy (S, [c])); |
|
136 |
||
137 |
||
138 |
(* print_axclasses *) |
|
139 |
||
140 |
fun print_axclasses thy = |
|
141 |
let |
|
142 |
val axclasses = #1 (#1 (AxClassData.get thy)); |
|
143 |
val ctxt = ProofContext.init thy; |
|
144 |
||
145 |
fun pretty_axclass (class, AxClass {def, intro, axioms}) = |
|
146 |
Pretty.block (Pretty.fbreaks |
|
147 |
[Pretty.block |
|
148 |
[Pretty.str "axclass ", ProofContext.pretty_sort ctxt [class], Pretty.str ":"], |
|
149 |
Pretty.strs ("parameters:" :: params_of thy class), |
|
150 |
ProofContext.pretty_fact ctxt ("def", [def]), |
|
151 |
ProofContext.pretty_fact ctxt (introN, [intro]), |
|
152 |
ProofContext.pretty_fact ctxt (axiomsN, axioms)]); |
|
153 |
in Pretty.writeln (Pretty.chunks (map pretty_axclass (Symtab.dest axclasses))) end; |
|
154 |
||
155 |
||
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
156 |
|
19418
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
157 |
(** instances **) |
15876
a67343c6ab2a
sane interfaces for tactical instance proofs (do not expand defs of theory, proper handling of sort instances);
wenzelm
parents:
15853
diff
changeset
|
158 |
|
19460 | 159 |
val get_instances = AxClassData.get #> (fn (_, Instances insts) => insts); |
19405 | 160 |
|
19418
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
161 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
162 |
(* class relations *) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
163 |
|
19405 | 164 |
fun cert_classrel thy raw_rel = |
15876
a67343c6ab2a
sane interfaces for tactical instance proofs (do not expand defs of theory, proper handling of sort instances);
wenzelm
parents:
15853
diff
changeset
|
165 |
let |
19405 | 166 |
val (c1, c2) = pairself (Sign.certify_class thy) raw_rel; |
167 |
val _ = Type.add_classrel (Sign.pp thy) [(c1, c2)] (Sign.tsig_of thy); |
|
168 |
val _ = |
|
19460 | 169 |
(case subtract (op =) (all_params_of thy [c1]) (all_params_of thy [c2]) of |
19405 | 170 |
[] => () |
171 |
| xs => raise TYPE ("Class " ^ Sign.string_of_sort thy [c1] ^ " lacks parameter(s) " ^ |
|
172 |
commas_quote xs ^ " of " ^ Sign.string_of_sort thy [c2], [], [])); |
|
173 |
in (c1, c2) end; |
|
174 |
||
175 |
fun read_classrel thy raw_rel = |
|
176 |
cert_classrel thy (pairself (Sign.read_class thy) raw_rel) |
|
177 |
handle TYPE (msg, _, _) => error msg; |
|
178 |
||
179 |
||
180 |
(* primitive rules *) |
|
181 |
||
182 |
fun add_classrel th thy = |
|
183 |
let |
|
184 |
fun err () = raise THM ("add_classrel: malformed class relation", 0, [th]); |
|
185 |
val prop = Drule.plain_prop_of (Thm.transfer thy th); |
|
186 |
val rel = Logic.dest_classrel prop handle TERM _ => err (); |
|
187 |
val (c1, c2) = cert_classrel thy rel handle TYPE _ => err (); |
|
19392 | 188 |
in |
189 |
thy |
|
19405 | 190 |
|> Theory.add_classrel_i [(c1, c2)] |
191 |
|> AxClassData.map (apsnd (map_instances (fn (classes, classrel, arities) => |
|
19418
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
192 |
(classes |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
193 |
|> Graph.default_node (c1, ()) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
194 |
|> Graph.default_node (c2, ()) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
195 |
|> Graph.add_edge (c1, c2), |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
196 |
((c1, c2), th) :: classrel, arities)))) |
19392 | 197 |
end; |
15876
a67343c6ab2a
sane interfaces for tactical instance proofs (do not expand defs of theory, proper handling of sort instances);
wenzelm
parents:
15853
diff
changeset
|
198 |
|
19405 | 199 |
fun add_arity th thy = |
15876
a67343c6ab2a
sane interfaces for tactical instance proofs (do not expand defs of theory, proper handling of sort instances);
wenzelm
parents:
15853
diff
changeset
|
200 |
let |
19405 | 201 |
val prop = Drule.plain_prop_of (Thm.transfer thy th); |
202 |
val (t, Ss, c) = Logic.dest_arity prop handle TERM _ => |
|
203 |
raise THM ("add_arity: malformed type arity", 0, [th]); |
|
19392 | 204 |
in |
205 |
thy |
|
19405 | 206 |
|> Theory.add_arities_i [(t, Ss, [c])] |
207 |
|> AxClassData.map (apsnd (map_instances (fn (classes, classrel, arities) => |
|
208 |
(classes, classrel, ((t, Ss, c), th) :: arities)))) |
|
19392 | 209 |
end; |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
210 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
211 |
|
19243
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
212 |
(* tactical proofs *) |
15876
a67343c6ab2a
sane interfaces for tactical instance proofs (do not expand defs of theory, proper handling of sort instances);
wenzelm
parents:
15853
diff
changeset
|
213 |
|
19405 | 214 |
fun prove_classrel raw_rel tac thy = |
15876
a67343c6ab2a
sane interfaces for tactical instance proofs (do not expand defs of theory, proper handling of sort instances);
wenzelm
parents:
15853
diff
changeset
|
215 |
let |
19405 | 216 |
val (c1, c2) = cert_classrel thy raw_rel; |
217 |
val th = Goal.prove thy [] [] (Logic.mk_classrel (c1, c2)) (fn _ => tac) handle ERROR msg => |
|
19243
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
218 |
cat_error msg ("The error(s) above occurred while trying to prove class relation " ^ |
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
219 |
quote (Sign.string_of_classrel thy [c1, c2])); |
19405 | 220 |
in add_classrel th thy end; |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
221 |
|
19243
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
222 |
fun prove_arity raw_arity tac thy = |
15876
a67343c6ab2a
sane interfaces for tactical instance proofs (do not expand defs of theory, proper handling of sort instances);
wenzelm
parents:
15853
diff
changeset
|
223 |
let |
19243
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
224 |
val arity = Sign.cert_arity thy raw_arity; |
19405 | 225 |
val props = Logic.mk_arities arity; |
17956 | 226 |
val ths = Goal.prove_multi thy [] [] props |
18678 | 227 |
(fn _ => Tactic.precise_conjunction_tac (length props) 1 THEN tac) handle ERROR msg => |
19243
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
228 |
cat_error msg ("The error(s) above occurred while trying to prove type arity " ^ |
5dcb899a8486
moved read_class, read/cert_classrel/arity to sign.ML;
wenzelm
parents:
19134
diff
changeset
|
229 |
quote (Sign.string_of_arity thy arity)); |
19405 | 230 |
in fold add_arity ths thy end; |
19392 | 231 |
|
19418
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
232 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
233 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
234 |
(** axclass definitions **) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
235 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
236 |
(* add_axclass(_i) *) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
237 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
238 |
fun gen_axclass prep_class prep_att prep_propp |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
239 |
(bclass, raw_super) params raw_specs thy = |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
240 |
let |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
241 |
val ctxt = ProofContext.init thy; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
242 |
val pp = ProofContext.pp ctxt; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
243 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
244 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
245 |
(* prepare specification *) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
246 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
247 |
val bconst = Logic.const_of_class bclass; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
248 |
val class = Sign.full_name thy bclass; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
249 |
val super = map (prep_class thy) raw_super |> Sign.certify_sort thy; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
250 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
251 |
fun prep_axiom t = |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
252 |
(case Term.add_tfrees t [] of |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
253 |
[(a, S)] => |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
254 |
if Sign.subsort thy (super, S) then t |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
255 |
else error ("Sort constraint of type variable " ^ |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
256 |
setmp show_sorts true (Pretty.string_of_typ pp) (TFree (a, S)) ^ |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
257 |
" needs to be weaker than " ^ Pretty.string_of_sort pp super) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
258 |
| [] => t |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
259 |
| _ => error ("Multiple type variables in class axiom:\n" ^ Pretty.string_of_term pp t)) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
260 |
|> map_term_types (Term.map_atyps (fn TFree _ => Term.aT [] | U => U)) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
261 |
|> Logic.close_form; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
262 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
263 |
val axiomss = prep_propp (ctxt, map (map (rpair ([], [])) o snd) raw_specs) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
264 |
|> snd |> map (map (prep_axiom o fst)); |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
265 |
val name_atts = Attrib.map_specs (prep_att thy) raw_specs |> map fst; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
266 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
267 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
268 |
(* definition *) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
269 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
270 |
val conjs = map (curry Logic.mk_inclass (Term.aT [])) super @ List.concat axiomss; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
271 |
val class_eq = |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
272 |
Logic.mk_equals (Logic.mk_inclass (Term.aT [], class), Logic.mk_conjunction_list conjs); |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
273 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
274 |
val ([def], def_thy) = |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
275 |
thy |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
276 |
|> Theory.add_classes_i [(bclass, super)] |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
277 |
|> PureThy.add_defs_i false [((Thm.def_name bconst, class_eq), [])]; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
278 |
val (raw_intro, (raw_classrel, raw_axioms)) = |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
279 |
(Conjunction.split_defined (length conjs) def) ||> chop (length super); |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
280 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
281 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
282 |
(* facts *) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
283 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
284 |
val class_triv = Thm.class_triv def_thy class; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
285 |
val ([(_, [intro]), (_, axioms)], facts_thy) = |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
286 |
def_thy |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
287 |
|> PureThy.note_thmss_qualified "" bconst |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
288 |
[((introN, []), [([Drule.standard raw_intro], [])]), |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
289 |
((axiomsN, []), [(map (fn th => Drule.standard (class_triv RS th)) raw_axioms, [])])] |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
290 |
||> fold (fn th => add_classrel (Drule.standard' (class_triv RS th))) raw_classrel; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
291 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
292 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
293 |
(* result *) |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
294 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
295 |
val result_thy = |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
296 |
facts_thy |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
297 |
|> Sign.add_path bconst |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
298 |
|> PureThy.note_thmss_i "" (name_atts ~~ map Thm.simple_fact (unflat axiomss axioms)) |> snd |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
299 |
|> Sign.restore_naming facts_thy |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
300 |
|> AxClassData.map (apfst (fn (is, ps) => |
19460 | 301 |
(Symtab.update (class, make_axclass (def, intro, axioms)) is, |
19418
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
302 |
fold (fn x => add_param pp (x, class)) params ps))); |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
303 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
304 |
in (class, result_thy) end; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
305 |
|
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
306 |
val add_axclass = gen_axclass Sign.read_class Attrib.attribute ProofContext.read_propp; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
307 |
val add_axclass_i = gen_axclass Sign.certify_class (K I) ProofContext.cert_propp; |
03b01c9314fc
reworded add_axclass(_i): canonical specification format,
wenzelm
parents:
19405
diff
changeset
|
308 |
|
15876
a67343c6ab2a
sane interfaces for tactical instance proofs (do not expand defs of theory, proper handling of sort instances);
wenzelm
parents:
15853
diff
changeset
|
309 |
end; |