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