wenzelm@404
|
1 |
(* Title: Pure/axclass.ML
|
wenzelm@404
|
2 |
Author: Markus Wenzel, TU Muenchen
|
wenzelm@404
|
3 |
|
wenzelm@24964
|
4 |
Type classes defined as predicates, associated with a record of
|
wenzelm@36417
|
5 |
parameters. Proven class relations and type arities.
|
wenzelm@404
|
6 |
*)
|
wenzelm@404
|
7 |
|
wenzelm@404
|
8 |
signature AX_CLASS =
|
wenzelm@3938
|
9 |
sig
|
wenzelm@36427
|
10 |
type info = {def: thm, intro: thm, axioms: thm list, params: (string * typ) list}
|
wenzelm@36427
|
11 |
val get_info: theory -> class -> info
|
wenzelm@36427
|
12 |
val class_of_param: theory -> string -> class option
|
wenzelm@36427
|
13 |
val instance_name: string * class -> string
|
wenzelm@36427
|
14 |
val thynames_of_arity: theory -> class * string -> string list
|
wenzelm@36427
|
15 |
val param_of_inst: theory -> string * string -> string
|
wenzelm@36427
|
16 |
val inst_of_param: theory -> string -> (string * string) option
|
wenzelm@36427
|
17 |
val unoverload: theory -> thm -> thm
|
wenzelm@36427
|
18 |
val overload: theory -> thm -> thm
|
wenzelm@36427
|
19 |
val unoverload_conv: theory -> conv
|
wenzelm@36427
|
20 |
val overload_conv: theory -> conv
|
wenzelm@36427
|
21 |
val lookup_inst_param: Consts.T -> ((string * string) * 'a) list -> string * typ -> 'a option
|
wenzelm@36427
|
22 |
val unoverload_const: theory -> string * typ -> string
|
wenzelm@36427
|
23 |
val cert_classrel: theory -> class * class -> class * class
|
wenzelm@36427
|
24 |
val read_classrel: theory -> xstring * xstring -> class * class
|
wenzelm@36427
|
25 |
val declare_overloaded: string * typ -> theory -> term * theory
|
wenzelm@36427
|
26 |
val define_overloaded: binding -> string * term -> theory -> thm * theory
|
haftmann@24589
|
27 |
val add_classrel: thm -> theory -> theory
|
haftmann@24589
|
28 |
val add_arity: thm -> theory -> theory
|
haftmann@24589
|
29 |
val prove_classrel: class * class -> tactic -> theory -> theory
|
haftmann@24589
|
30 |
val prove_arity: string * sort list * sort -> tactic -> theory -> theory
|
wenzelm@36427
|
31 |
val define_class: binding * class list -> string list ->
|
wenzelm@36427
|
32 |
(Thm.binding * term list) list -> theory -> class * theory
|
wenzelm@30344
|
33 |
val axiomatize_class: binding * class list -> theory -> theory
|
wenzelm@30344
|
34 |
val axiomatize_class_cmd: binding * xstring list -> theory -> theory
|
wenzelm@24929
|
35 |
val axiomatize_classrel: (class * class) list -> theory -> theory
|
wenzelm@24929
|
36 |
val axiomatize_classrel_cmd: (xstring * xstring) list -> theory -> theory
|
wenzelm@24929
|
37 |
val axiomatize_arity: arity -> theory -> theory
|
wenzelm@24929
|
38 |
val axiomatize_arity_cmd: xstring * string list * string -> theory -> theory
|
wenzelm@3938
|
39 |
end;
|
wenzelm@404
|
40 |
|
wenzelm@15801
|
41 |
structure AxClass: AX_CLASS =
|
wenzelm@404
|
42 |
struct
|
wenzelm@404
|
43 |
|
wenzelm@19405
|
44 |
(** theory data **)
|
wenzelm@423
|
45 |
|
wenzelm@36329
|
46 |
(* axclass info *)
|
wenzelm@36329
|
47 |
|
wenzelm@36329
|
48 |
type info =
|
wenzelm@36329
|
49 |
{def: thm,
|
wenzelm@36329
|
50 |
intro: thm,
|
wenzelm@36329
|
51 |
axioms: thm list,
|
wenzelm@36329
|
52 |
params: (string * typ) list};
|
wenzelm@36329
|
53 |
|
wenzelm@36329
|
54 |
fun make_axclass (def, intro, axioms, params): info =
|
wenzelm@36329
|
55 |
{def = def, intro = intro, axioms = axioms, params = params};
|
wenzelm@36329
|
56 |
|
wenzelm@36329
|
57 |
|
wenzelm@19405
|
58 |
(* class parameters (canonical order) *)
|
wenzelm@423
|
59 |
|
wenzelm@19405
|
60 |
type param = string * class;
|
wenzelm@423
|
61 |
|
wenzelm@19405
|
62 |
fun add_param pp ((x, c): param) params =
|
wenzelm@19405
|
63 |
(case AList.lookup (op =) params x of
|
wenzelm@19405
|
64 |
NONE => (x, c) :: params
|
wenzelm@19405
|
65 |
| SOME c' => error ("Duplicate class parameter " ^ quote x ^
|
wenzelm@19405
|
66 |
" for " ^ Pretty.string_of_sort pp [c] ^
|
wenzelm@19405
|
67 |
(if c = c' then "" else " and " ^ Pretty.string_of_sort pp [c'])));
|
wenzelm@423
|
68 |
|
haftmann@25597
|
69 |
|
wenzelm@19511
|
70 |
(* setup data *)
|
wenzelm@19392
|
71 |
|
wenzelm@36329
|
72 |
datatype data = Data of
|
wenzelm@36329
|
73 |
{axclasses: info Symtab.table,
|
wenzelm@36329
|
74 |
params: param list,
|
wenzelm@36418
|
75 |
proven_classrels: thm Symreltab.table,
|
wenzelm@36418
|
76 |
proven_arities: ((class * sort list) * (thm * string)) list Symtab.table,
|
wenzelm@36329
|
77 |
(*arity theorems with theory name*)
|
wenzelm@36329
|
78 |
inst_params:
|
wenzelm@36329
|
79 |
(string * thm) Symtab.table Symtab.table *
|
wenzelm@36329
|
80 |
(*constant name ~> type constructor ~> (constant name, equation)*)
|
wenzelm@36329
|
81 |
(string * string) Symtab.table (*constant name ~> (constant name, type constructor)*),
|
wenzelm@36420
|
82 |
diff_classrels: (class * class) list};
|
wenzelm@36329
|
83 |
|
wenzelm@36329
|
84 |
fun make_data
|
wenzelm@36420
|
85 |
(axclasses, params, proven_classrels, proven_arities, inst_params, diff_classrels) =
|
wenzelm@36329
|
86 |
Data {axclasses = axclasses, params = params, proven_classrels = proven_classrels,
|
wenzelm@36329
|
87 |
proven_arities = proven_arities, inst_params = inst_params,
|
wenzelm@36420
|
88 |
diff_classrels = diff_classrels};
|
wenzelm@36420
|
89 |
|
wenzelm@36420
|
90 |
fun diff_table tab1 tab2 =
|
wenzelm@36420
|
91 |
Symreltab.fold (fn (x, _) => if Symreltab.defined tab2 x then I else cons x) tab1 [];
|
wenzelm@36329
|
92 |
|
wenzelm@36327
|
93 |
structure Data = Theory_Data_PP
|
wenzelm@22846
|
94 |
(
|
wenzelm@36329
|
95 |
type T = data;
|
wenzelm@36329
|
96 |
val empty =
|
wenzelm@36329
|
97 |
make_data (Symtab.empty, [], Symreltab.empty, Symtab.empty, (Symtab.empty, Symtab.empty), []);
|
wenzelm@19574
|
98 |
val extend = I;
|
wenzelm@36329
|
99 |
fun merge pp
|
wenzelm@36329
|
100 |
(Data {axclasses = axclasses1, params = params1, proven_classrels = proven_classrels1,
|
wenzelm@36329
|
101 |
proven_arities = proven_arities1, inst_params = inst_params1,
|
wenzelm@36420
|
102 |
diff_classrels = diff_classrels1},
|
wenzelm@36329
|
103 |
Data {axclasses = axclasses2, params = params2, proven_classrels = proven_classrels2,
|
wenzelm@36329
|
104 |
proven_arities = proven_arities2, inst_params = inst_params2,
|
wenzelm@36420
|
105 |
diff_classrels = diff_classrels2}) =
|
wenzelm@36325
|
106 |
let
|
wenzelm@36329
|
107 |
val axclasses' = Symtab.merge (K true) (axclasses1, axclasses2);
|
wenzelm@36329
|
108 |
val params' =
|
wenzelm@36329
|
109 |
if null params1 then params2
|
wenzelm@36417
|
110 |
else fold_rev (fn p => if member (op =) params1 p then I else add_param pp p) params2 params1;
|
wenzelm@36329
|
111 |
|
wenzelm@36329
|
112 |
(*transitive closure of classrels and arity completion is done in Theory.at_begin hook*)
|
wenzelm@36329
|
113 |
val proven_classrels' = Symreltab.join (K #1) (proven_classrels1, proven_classrels2);
|
wenzelm@36329
|
114 |
val proven_arities' =
|
wenzelm@36329
|
115 |
Symtab.join (K (Library.merge (eq_fst op =))) (proven_arities1, proven_arities2);
|
wenzelm@36329
|
116 |
|
wenzelm@36420
|
117 |
val diff_classrels' =
|
wenzelm@36420
|
118 |
diff_table proven_classrels1 proven_classrels2 @
|
wenzelm@36420
|
119 |
diff_table proven_classrels2 proven_classrels1 @
|
wenzelm@36420
|
120 |
diff_classrels1 @ diff_classrels2;
|
wenzelm@36329
|
121 |
|
wenzelm@36329
|
122 |
val inst_params' =
|
wenzelm@36329
|
123 |
(Symtab.join (K (Symtab.merge (K true))) (#1 inst_params1, #1 inst_params2),
|
wenzelm@36329
|
124 |
Symtab.merge (K true) (#2 inst_params1, #2 inst_params2));
|
wenzelm@36325
|
125 |
in
|
wenzelm@36420
|
126 |
make_data
|
wenzelm@36420
|
127 |
(axclasses', params', proven_classrels', proven_arities', inst_params', diff_classrels')
|
wenzelm@36325
|
128 |
end;
|
wenzelm@22846
|
129 |
);
|
wenzelm@6379
|
130 |
|
wenzelm@36329
|
131 |
fun map_data f =
|
wenzelm@36420
|
132 |
Data.map (fn Data {axclasses, params, proven_classrels, proven_arities, inst_params, diff_classrels} =>
|
wenzelm@36420
|
133 |
make_data (f (axclasses, params, proven_classrels, proven_arities, inst_params, diff_classrels)));
|
wenzelm@36329
|
134 |
|
wenzelm@36329
|
135 |
fun map_axclasses f =
|
wenzelm@36420
|
136 |
map_data (fn (axclasses, params, proven_classrels, proven_arities, inst_params, diff_classrels) =>
|
wenzelm@36420
|
137 |
(f axclasses, params, proven_classrels, proven_arities, inst_params, diff_classrels));
|
wenzelm@36329
|
138 |
|
wenzelm@36329
|
139 |
fun map_params f =
|
wenzelm@36420
|
140 |
map_data (fn (axclasses, params, proven_classrels, proven_arities, inst_params, diff_classrels) =>
|
wenzelm@36420
|
141 |
(axclasses, f params, proven_classrels, proven_arities, inst_params, diff_classrels));
|
wenzelm@36329
|
142 |
|
wenzelm@36329
|
143 |
fun map_proven_classrels f =
|
wenzelm@36420
|
144 |
map_data (fn (axclasses, params, proven_classrels, proven_arities, inst_params, diff_classrels) =>
|
wenzelm@36420
|
145 |
(axclasses, params, f proven_classrels, proven_arities, inst_params, diff_classrels));
|
wenzelm@36329
|
146 |
|
wenzelm@36329
|
147 |
fun map_proven_arities f =
|
wenzelm@36420
|
148 |
map_data (fn (axclasses, params, proven_classrels, proven_arities, inst_params, diff_classrels) =>
|
wenzelm@36420
|
149 |
(axclasses, params, proven_classrels, f proven_arities, inst_params, diff_classrels));
|
wenzelm@36329
|
150 |
|
wenzelm@36329
|
151 |
fun map_inst_params f =
|
wenzelm@36420
|
152 |
map_data (fn (axclasses, params, proven_classrels, proven_arities, inst_params, diff_classrels) =>
|
wenzelm@36420
|
153 |
(axclasses, params, proven_classrels, proven_arities, f inst_params, diff_classrels));
|
wenzelm@36329
|
154 |
|
wenzelm@36420
|
155 |
val clear_diff_classrels =
|
wenzelm@36329
|
156 |
map_data (fn (axclasses, params, proven_classrels, proven_arities, inst_params, _) =>
|
wenzelm@36329
|
157 |
(axclasses, params, proven_classrels, proven_arities, inst_params, []));
|
wenzelm@36329
|
158 |
|
wenzelm@36329
|
159 |
val rep_data = Data.get #> (fn Data args => args);
|
wenzelm@36329
|
160 |
|
wenzelm@36329
|
161 |
val axclasses_of = #axclasses o rep_data;
|
wenzelm@36329
|
162 |
val params_of = #params o rep_data;
|
wenzelm@36329
|
163 |
val proven_classrels_of = #proven_classrels o rep_data;
|
wenzelm@36329
|
164 |
val proven_arities_of = #proven_arities o rep_data;
|
wenzelm@36329
|
165 |
val inst_params_of = #inst_params o rep_data;
|
wenzelm@36420
|
166 |
val diff_classrels_of = #diff_classrels o rep_data;
|
wenzelm@36329
|
167 |
|
wenzelm@6379
|
168 |
|
wenzelm@36346
|
169 |
(* axclasses with parameters *)
|
wenzelm@19392
|
170 |
|
wenzelm@24929
|
171 |
fun get_info thy c =
|
wenzelm@36329
|
172 |
(case Symtab.lookup (axclasses_of thy) c of
|
wenzelm@36327
|
173 |
SOME info => info
|
wenzelm@21919
|
174 |
| NONE => error ("No such axclass: " ^ quote c));
|
wenzelm@6379
|
175 |
|
wenzelm@36327
|
176 |
fun all_params_of thy S =
|
wenzelm@36329
|
177 |
let val params = params_of thy;
|
wenzelm@36327
|
178 |
in fold (fn (x, c) => if Sign.subsort thy (S, [c]) then cons x else I) params [] end;
|
wenzelm@19460
|
179 |
|
wenzelm@36329
|
180 |
fun class_of_param thy = AList.lookup (op =) (params_of thy);
|
wenzelm@19460
|
181 |
|
wenzelm@21919
|
182 |
|
wenzelm@19511
|
183 |
(* maintain instances *)
|
wenzelm@19503
|
184 |
|
wenzelm@36329
|
185 |
val classrel_prefix = "classrel_";
|
wenzelm@36329
|
186 |
val arity_prefix = "arity_";
|
haftmann@25486
|
187 |
|
wenzelm@36329
|
188 |
fun instance_name (a, c) = Long_Name.base_name c ^ "_" ^ Long_Name.base_name a;
|
wenzelm@19528
|
189 |
|
wenzelm@19528
|
190 |
|
wenzelm@36421
|
191 |
infix 0 RSO;
|
wenzelm@36421
|
192 |
|
wenzelm@36456
|
193 |
fun (SOME a) RSO (SOME b) = SOME (a RS b)
|
wenzelm@36456
|
194 |
| x RSO NONE = x
|
wenzelm@36456
|
195 |
| NONE RSO y = y;
|
wenzelm@36421
|
196 |
|
wenzelm@19574
|
197 |
fun the_classrel thy (c1, c2) =
|
wenzelm@36329
|
198 |
(case Symreltab.lookup (proven_classrels_of thy) (c1, c2) of
|
wenzelm@36881
|
199 |
SOME thm => thm
|
wenzelm@24920
|
200 |
| NONE => error ("Unproven class relation " ^
|
wenzelm@36881
|
201 |
Syntax.string_of_classrel (ProofContext.init_global thy) [c1, c2])); (* FIXME stale thy (!?) *)
|
wenzelm@19574
|
202 |
|
wenzelm@36325
|
203 |
fun put_trancl_classrel ((c1, c2), th) thy =
|
wenzelm@36325
|
204 |
let
|
wenzelm@36328
|
205 |
val classes = Sorts.classes_of (Sign.classes_of thy);
|
wenzelm@36329
|
206 |
val classrels = proven_classrels_of thy;
|
wenzelm@36325
|
207 |
|
wenzelm@36325
|
208 |
fun reflcl_classrel (c1', c2') =
|
wenzelm@36881
|
209 |
if c1' = c2' then NONE else SOME (Thm.transfer thy (the_classrel thy (c1', c2')));
|
wenzelm@36325
|
210 |
fun gen_classrel (c1_pred, c2_succ) =
|
wenzelm@36325
|
211 |
let
|
wenzelm@36421
|
212 |
val th' =
|
wenzelm@36421
|
213 |
the ((reflcl_classrel (c1_pred, c1) RSO SOME th) RSO reflcl_classrel (c2, c2_succ))
|
wenzelm@36421
|
214 |
|> Drule.instantiate' [SOME (ctyp_of thy (TVar ((Name.aT, 0), [])))] []
|
wenzelm@36327
|
215 |
|> Thm.close_derivation;
|
wenzelm@36418
|
216 |
in ((c1_pred, c2_succ), th') end;
|
wenzelm@36325
|
217 |
|
wenzelm@36327
|
218 |
val new_classrels =
|
wenzelm@36327
|
219 |
Library.map_product pair (c1 :: Graph.imm_preds classes c1) (c2 :: Graph.imm_succs classes c2)
|
wenzelm@36421
|
220 |
|> filter_out ((op =) orf Symreltab.defined classrels)
|
wenzelm@36327
|
221 |
|> map gen_classrel;
|
wenzelm@36327
|
222 |
val needed = not (null new_classrels);
|
wenzelm@36325
|
223 |
in
|
wenzelm@36325
|
224 |
(needed,
|
wenzelm@36329
|
225 |
if needed then map_proven_classrels (fold Symreltab.update new_classrels) thy
|
wenzelm@36329
|
226 |
else thy)
|
wenzelm@36325
|
227 |
end;
|
wenzelm@36325
|
228 |
|
wenzelm@36325
|
229 |
fun complete_classrels thy =
|
wenzelm@36325
|
230 |
let
|
wenzelm@36329
|
231 |
val classrels = proven_classrels_of thy;
|
wenzelm@36420
|
232 |
val diff_classrels = diff_classrels_of thy;
|
wenzelm@36325
|
233 |
val (needed, thy') = (false, thy) |>
|
wenzelm@36417
|
234 |
fold (fn rel => fn (needed, thy) =>
|
wenzelm@36418
|
235 |
put_trancl_classrel (rel, Symreltab.lookup classrels rel |> the) thy
|
wenzelm@36325
|
236 |
|>> (fn b => needed orelse b))
|
wenzelm@36420
|
237 |
diff_classrels;
|
wenzelm@36325
|
238 |
in
|
wenzelm@36420
|
239 |
if null diff_classrels then NONE
|
wenzelm@36420
|
240 |
else SOME (clear_diff_classrels thy')
|
wenzelm@36325
|
241 |
end;
|
wenzelm@19503
|
242 |
|
wenzelm@19503
|
243 |
|
wenzelm@36740
|
244 |
fun the_arity thy (a, Ss, c) =
|
wenzelm@36329
|
245 |
(case AList.lookup (op =) (Symtab.lookup_list (proven_arities_of thy) a) (c, Ss) of
|
wenzelm@36881
|
246 |
SOME (thm, _) => thm
|
wenzelm@24920
|
247 |
| NONE => error ("Unproven type arity " ^
|
wenzelm@36881
|
248 |
Syntax.string_of_arity (ProofContext.init_global thy) (a, Ss, [c]))); (* FIXME stale thy (!?) *)
|
wenzelm@19503
|
249 |
|
wenzelm@33172
|
250 |
fun thynames_of_arity thy (c, a) =
|
wenzelm@36329
|
251 |
Symtab.lookup_list (proven_arities_of thy) a
|
wenzelm@36418
|
252 |
|> map_filter (fn ((c', _), (_, name)) => if c = c' then SOME name else NONE)
|
haftmann@27497
|
253 |
|> rev;
|
haftmann@27397
|
254 |
|
wenzelm@36419
|
255 |
fun insert_arity_completions thy t ((c, Ss), ((th, thy_name))) (finished, arities) =
|
haftmann@27547
|
256 |
let
|
haftmann@27547
|
257 |
val algebra = Sign.classes_of thy;
|
wenzelm@36417
|
258 |
val ars = Symtab.lookup_list arities t;
|
wenzelm@33172
|
259 |
val super_class_completions =
|
wenzelm@33172
|
260 |
Sign.super_classes thy c
|
wenzelm@36417
|
261 |
|> filter_out (fn c1 => exists (fn ((c2, Ss2), _) =>
|
wenzelm@36417
|
262 |
c1 = c2 andalso Sorts.sorts_le algebra (Ss2, Ss)) ars);
|
wenzelm@36417
|
263 |
|
wenzelm@36417
|
264 |
val names = Name.invents Name.context Name.aT (length Ss);
|
wenzelm@36417
|
265 |
val std_vars = map (fn a => SOME (ctyp_of thy (TVar ((a, 0), [])))) names;
|
wenzelm@36417
|
266 |
|
wenzelm@36325
|
267 |
val completions = super_class_completions |> map (fn c1 =>
|
wenzelm@36325
|
268 |
let
|
wenzelm@36419
|
269 |
val th1 =
|
wenzelm@36881
|
270 |
(th RS Thm.transfer thy (the_classrel thy (c, c1)))
|
wenzelm@36417
|
271 |
|> Drule.instantiate' std_vars []
|
wenzelm@36327
|
272 |
|> Thm.close_derivation;
|
wenzelm@36418
|
273 |
in ((th1, thy_name), c1) end);
|
wenzelm@36419
|
274 |
|
wenzelm@36419
|
275 |
val finished' = finished andalso null completions;
|
wenzelm@36418
|
276 |
val arities' = fold (fn (th, c1) => Symtab.cons_list (t, ((c1, Ss), th))) completions arities;
|
wenzelm@36419
|
277 |
in (finished', arities') end;
|
wenzelm@19503
|
278 |
|
haftmann@27547
|
279 |
fun put_arity ((t, Ss, c), th) thy =
|
wenzelm@36419
|
280 |
let val ar = ((c, Ss), (th, Context.theory_name thy)) in
|
haftmann@27547
|
281 |
thy
|
wenzelm@36329
|
282 |
|> map_proven_arities
|
wenzelm@36419
|
283 |
(Symtab.insert_list (eq_fst op =) (t, ar) #>
|
wenzelm@36419
|
284 |
curry (insert_arity_completions thy t ar) true #> #2)
|
haftmann@27547
|
285 |
end;
|
wenzelm@19503
|
286 |
|
wenzelm@31944
|
287 |
fun complete_arities thy =
|
haftmann@27547
|
288 |
let
|
wenzelm@36329
|
289 |
val arities = proven_arities_of thy;
|
wenzelm@36419
|
290 |
val (finished, arities') =
|
wenzelm@36419
|
291 |
Symtab.fold (fn (t, ars) => fold (insert_arity_completions thy t) ars) arities (true, arities);
|
wenzelm@33172
|
292 |
in
|
wenzelm@36419
|
293 |
if finished then NONE
|
wenzelm@36329
|
294 |
else SOME (map_proven_arities (K arities') thy)
|
haftmann@27547
|
295 |
end;
|
haftmann@27547
|
296 |
|
wenzelm@36325
|
297 |
val _ = Context.>> (Context.map_theory
|
wenzelm@36740
|
298 |
(Theory.at_begin complete_classrels #>
|
wenzelm@36740
|
299 |
Theory.at_begin complete_arities));
|
haftmann@27397
|
300 |
|
wenzelm@36740
|
301 |
val _ = Proofterm.install_axclass_proofs
|
wenzelm@36740
|
302 |
{classrel_proof = Thm.proof_of oo the_classrel,
|
wenzelm@36740
|
303 |
arity_proof = Thm.proof_of oo the_arity};
|
wenzelm@36418
|
304 |
|
haftmann@27397
|
305 |
|
haftmann@25597
|
306 |
(* maintain instance parameters *)
|
haftmann@25597
|
307 |
|
haftmann@25597
|
308 |
fun get_inst_param thy (c, tyco) =
|
wenzelm@36329
|
309 |
(case Symtab.lookup (the_default Symtab.empty (Symtab.lookup (#1 (inst_params_of thy)) c)) tyco of
|
wenzelm@36327
|
310 |
SOME c' => c'
|
wenzelm@36327
|
311 |
| NONE => error ("No instance parameter for constant " ^ quote c ^ " on type " ^ quote tyco));
|
haftmann@25597
|
312 |
|
wenzelm@36327
|
313 |
fun add_inst_param (c, tyco) inst =
|
wenzelm@36327
|
314 |
(map_inst_params o apfst o Symtab.map_default (c, Symtab.empty)) (Symtab.update_new (tyco, inst))
|
wenzelm@36417
|
315 |
#> (map_inst_params o apsnd) (Symtab.update_new (#1 inst, (c, tyco)));
|
haftmann@25597
|
316 |
|
wenzelm@36329
|
317 |
val inst_of_param = Symtab.lookup o #2 o inst_params_of;
|
wenzelm@36417
|
318 |
val param_of_inst = #1 oo get_inst_param;
|
haftmann@25597
|
319 |
|
wenzelm@36327
|
320 |
fun inst_thms thy =
|
wenzelm@36329
|
321 |
Symtab.fold (Symtab.fold (cons o #2 o #2) o #2) (#1 (inst_params_of thy)) [];
|
haftmann@25597
|
322 |
|
wenzelm@36417
|
323 |
fun get_inst_tyco consts = try (#1 o dest_Type o the_single o Consts.typargs consts);
|
haftmann@25597
|
324 |
|
haftmann@25597
|
325 |
fun unoverload thy = MetaSimplifier.simplify true (inst_thms thy);
|
haftmann@25597
|
326 |
fun overload thy = MetaSimplifier.simplify true (map Thm.symmetric (inst_thms thy));
|
haftmann@25597
|
327 |
|
haftmann@25597
|
328 |
fun unoverload_conv thy = MetaSimplifier.rewrite true (inst_thms thy);
|
haftmann@25597
|
329 |
fun overload_conv thy = MetaSimplifier.rewrite true (map Thm.symmetric (inst_thms thy));
|
haftmann@25597
|
330 |
|
wenzelm@36327
|
331 |
fun lookup_inst_param consts params (c, T) =
|
wenzelm@36327
|
332 |
(case get_inst_tyco consts (c, T) of
|
wenzelm@36327
|
333 |
SOME tyco => AList.lookup (op =) params (c, tyco)
|
wenzelm@36327
|
334 |
| NONE => NONE);
|
haftmann@31249
|
335 |
|
haftmann@25597
|
336 |
fun unoverload_const thy (c_ty as (c, _)) =
|
wenzelm@36327
|
337 |
if is_some (class_of_param thy c) then
|
wenzelm@36327
|
338 |
(case get_inst_tyco (Sign.consts_of thy) c_ty of
|
wenzelm@36327
|
339 |
SOME tyco => try (param_of_inst thy) (c, tyco) |> the_default c
|
wenzelm@36327
|
340 |
| NONE => c)
|
haftmann@33969
|
341 |
else c;
|
haftmann@25597
|
342 |
|
wenzelm@404
|
343 |
|
wenzelm@36327
|
344 |
|
wenzelm@19511
|
345 |
(** instances **)
|
wenzelm@19418
|
346 |
|
wenzelm@19418
|
347 |
(* class relations *)
|
wenzelm@19418
|
348 |
|
wenzelm@19405
|
349 |
fun cert_classrel thy raw_rel =
|
wenzelm@15876
|
350 |
let
|
wenzelm@26939
|
351 |
val string_of_sort = Syntax.string_of_sort_global thy;
|
wenzelm@19405
|
352 |
val (c1, c2) = pairself (Sign.certify_class thy) raw_rel;
|
wenzelm@24271
|
353 |
val _ = Sign.primitive_classrel (c1, c2) (Theory.copy thy);
|
wenzelm@19405
|
354 |
val _ =
|
wenzelm@19460
|
355 |
(case subtract (op =) (all_params_of thy [c1]) (all_params_of thy [c2]) of
|
wenzelm@19405
|
356 |
[] => ()
|
wenzelm@26939
|
357 |
| xs => raise TYPE ("Class " ^ string_of_sort [c1] ^ " lacks parameter(s) " ^
|
wenzelm@26939
|
358 |
commas_quote xs ^ " of " ^ string_of_sort [c2], [], []));
|
wenzelm@19405
|
359 |
in (c1, c2) end;
|
wenzelm@19405
|
360 |
|
wenzelm@19405
|
361 |
fun read_classrel thy raw_rel =
|
wenzelm@36610
|
362 |
cert_classrel thy (pairself (ProofContext.read_class (ProofContext.init_global thy)) raw_rel)
|
wenzelm@19405
|
363 |
handle TYPE (msg, _, _) => error msg;
|
wenzelm@19405
|
364 |
|
wenzelm@19405
|
365 |
|
haftmann@25597
|
366 |
(* declaration and definition of instances of overloaded constants *)
|
haftmann@25597
|
367 |
|
wenzelm@35201
|
368 |
fun inst_tyco_of thy (c, T) =
|
wenzelm@35201
|
369 |
(case get_inst_tyco (Sign.consts_of thy) (c, T) of
|
wenzelm@35201
|
370 |
SOME tyco => tyco
|
wenzelm@35201
|
371 |
| NONE => error ("Illegal type for instantiation of class parameter: " ^
|
wenzelm@35201
|
372 |
quote (c ^ " :: " ^ Syntax.string_of_typ_global thy T)));
|
haftmann@31249
|
373 |
|
haftmann@25597
|
374 |
fun declare_overloaded (c, T) thy =
|
haftmann@25597
|
375 |
let
|
wenzelm@35201
|
376 |
val class =
|
wenzelm@35201
|
377 |
(case class_of_param thy c of
|
wenzelm@35201
|
378 |
SOME class => class
|
wenzelm@35201
|
379 |
| NONE => error ("Not a class parameter: " ^ quote c));
|
haftmann@31249
|
380 |
val tyco = inst_tyco_of thy (c, T);
|
haftmann@25597
|
381 |
val name_inst = instance_name (tyco, class) ^ "_inst";
|
wenzelm@36417
|
382 |
val c' = instance_name (tyco, c);
|
haftmann@25597
|
383 |
val T' = Type.strip_sorts T;
|
haftmann@25597
|
384 |
in
|
haftmann@25597
|
385 |
thy
|
wenzelm@35201
|
386 |
|> Sign.qualified_path true (Binding.name name_inst)
|
wenzelm@33173
|
387 |
|> Sign.declare_const ((Binding.name c', T'), NoSyn)
|
wenzelm@30344
|
388 |
|-> (fn const' as Const (c'', _) =>
|
wenzelm@30344
|
389 |
Thm.add_def false true
|
wenzelm@30344
|
390 |
(Binding.name (Thm.def_name c'), Logic.mk_equals (Const (c, T'), const'))
|
wenzelm@36106
|
391 |
#>> apsnd Thm.varifyT_global
|
wenzelm@36106
|
392 |
#-> (fn (_, thm) => add_inst_param (c, tyco) (c'', thm)
|
wenzelm@36106
|
393 |
#> PureThy.add_thm ((Binding.conceal (Binding.name c'), thm), [])
|
wenzelm@36417
|
394 |
#> #2
|
wenzelm@36106
|
395 |
#> pair (Const (c, T))))
|
wenzelm@35201
|
396 |
||> Sign.restore_naming thy
|
haftmann@25597
|
397 |
end;
|
haftmann@25597
|
398 |
|
haftmann@30519
|
399 |
fun define_overloaded b (c, t) thy =
|
haftmann@25597
|
400 |
let
|
haftmann@25597
|
401 |
val T = Term.fastype_of t;
|
haftmann@31249
|
402 |
val tyco = inst_tyco_of thy (c, T);
|
haftmann@25597
|
403 |
val (c', eq) = get_inst_param thy (c, tyco);
|
haftmann@25597
|
404 |
val prop = Logic.mk_equals (Const (c', T), t);
|
wenzelm@36417
|
405 |
val b' = Thm.def_binding_optional (Binding.name (instance_name (tyco, c))) b;
|
haftmann@25597
|
406 |
in
|
haftmann@25597
|
407 |
thy
|
haftmann@30519
|
408 |
|> Thm.add_def false false (b', prop)
|
wenzelm@36106
|
409 |
|>> (fn (_, thm) => Drule.transitive_thm OF [eq, thm])
|
haftmann@25597
|
410 |
end;
|
haftmann@25597
|
411 |
|
haftmann@25597
|
412 |
|
haftmann@30951
|
413 |
(* primitive rules *)
|
haftmann@30951
|
414 |
|
wenzelm@36329
|
415 |
val shyps_topped = forall null o #shyps o Thm.rep_thm;
|
wenzelm@36329
|
416 |
|
wenzelm@31948
|
417 |
fun add_classrel raw_th thy =
|
haftmann@30951
|
418 |
let
|
wenzelm@31948
|
419 |
val th = Thm.strip_shyps (Thm.transfer thy raw_th);
|
wenzelm@31948
|
420 |
val prop = Thm.plain_prop_of th;
|
haftmann@30951
|
421 |
fun err () = raise THM ("add_classrel: malformed class relation", 0, [th]);
|
haftmann@30951
|
422 |
val rel = Logic.dest_classrel prop handle TERM _ => err ();
|
haftmann@30951
|
423 |
val (c1, c2) = cert_classrel thy rel handle TYPE _ => err ();
|
wenzelm@36325
|
424 |
val th' = th
|
krauss@36934
|
425 |
|> Thm.unconstrainT
|
krauss@36934
|
426 |
|> Drule.instantiate' [SOME (ctyp_of thy (TVar ((Name.aT, 0), [])))] [];
|
wenzelm@36327
|
427 |
val _ = shyps_topped th' orelse raise Fail "add_classrel: nontop shyps after unconstrain";
|
haftmann@30951
|
428 |
in
|
haftmann@30951
|
429 |
thy
|
haftmann@30951
|
430 |
|> Sign.primitive_classrel (c1, c2)
|
wenzelm@36417
|
431 |
|> (#2 oo put_trancl_classrel) ((c1, c2), th')
|
haftmann@30951
|
432 |
|> perhaps complete_arities
|
haftmann@30951
|
433 |
end;
|
haftmann@30951
|
434 |
|
wenzelm@31948
|
435 |
fun add_arity raw_th thy =
|
haftmann@30951
|
436 |
let
|
wenzelm@31948
|
437 |
val th = Thm.strip_shyps (Thm.transfer thy raw_th);
|
wenzelm@31948
|
438 |
val prop = Thm.plain_prop_of th;
|
haftmann@30951
|
439 |
fun err () = raise THM ("add_arity: malformed type arity", 0, [th]);
|
haftmann@30951
|
440 |
val (t, Ss, c) = Logic.dest_arity prop handle TERM _ => err ();
|
wenzelm@36417
|
441 |
|
wenzelm@36417
|
442 |
val args = Name.names Name.context Name.aT Ss;
|
wenzelm@36417
|
443 |
val T = Type (t, map TFree args);
|
krauss@36934
|
444 |
val std_vars = map (fn (a, S) => SOME (ctyp_of thy (TVar ((a, 0), [])))) args;
|
wenzelm@36417
|
445 |
|
haftmann@30951
|
446 |
val missing_params = Sign.complete_sort thy [c]
|
haftmann@30951
|
447 |
|> maps (these o Option.map #params o try (get_info thy))
|
haftmann@30951
|
448 |
|> filter_out (fn (const, _) => can (get_inst_param thy) (const, t))
|
haftmann@30951
|
449 |
|> (map o apsnd o map_atyps) (K T);
|
wenzelm@36325
|
450 |
val th' = th
|
krauss@36934
|
451 |
|> Thm.unconstrainT
|
krauss@36934
|
452 |
|> Drule.instantiate' std_vars [];
|
wenzelm@36327
|
453 |
val _ = shyps_topped th' orelse raise Fail "add_arity: nontop shyps after unconstrain";
|
haftmann@30951
|
454 |
in
|
haftmann@30951
|
455 |
thy
|
wenzelm@36417
|
456 |
|> fold (#2 oo declare_overloaded) missing_params
|
haftmann@30951
|
457 |
|> Sign.primitive_arity (t, Ss, [c])
|
wenzelm@36325
|
458 |
|> put_arity ((t, Ss, c), th')
|
haftmann@30951
|
459 |
end;
|
haftmann@30951
|
460 |
|
haftmann@30951
|
461 |
|
haftmann@30951
|
462 |
(* tactical proofs *)
|
haftmann@30951
|
463 |
|
haftmann@30951
|
464 |
fun prove_classrel raw_rel tac thy =
|
haftmann@30951
|
465 |
let
|
wenzelm@36610
|
466 |
val ctxt = ProofContext.init_global thy;
|
haftmann@30951
|
467 |
val (c1, c2) = cert_classrel thy raw_rel;
|
haftmann@30951
|
468 |
val th = Goal.prove ctxt [] [] (Logic.mk_classrel (c1, c2)) (K tac) handle ERROR msg =>
|
haftmann@30951
|
469 |
cat_error msg ("The error(s) above occurred while trying to prove class relation " ^
|
haftmann@30951
|
470 |
quote (Syntax.string_of_classrel ctxt [c1, c2]));
|
haftmann@30951
|
471 |
in
|
haftmann@30951
|
472 |
thy
|
haftmann@30951
|
473 |
|> PureThy.add_thms [((Binding.name
|
haftmann@30951
|
474 |
(prefix classrel_prefix (Logic.name_classrel (c1, c2))), th), [])]
|
haftmann@30951
|
475 |
|-> (fn [th'] => add_classrel th')
|
haftmann@30951
|
476 |
end;
|
haftmann@30951
|
477 |
|
haftmann@30951
|
478 |
fun prove_arity raw_arity tac thy =
|
haftmann@30951
|
479 |
let
|
wenzelm@36610
|
480 |
val ctxt = ProofContext.init_global thy;
|
wenzelm@35669
|
481 |
val arity = ProofContext.cert_arity ctxt raw_arity;
|
haftmann@30951
|
482 |
val names = map (prefix arity_prefix) (Logic.name_arities arity);
|
haftmann@30951
|
483 |
val props = Logic.mk_arities arity;
|
haftmann@30951
|
484 |
val ths = Goal.prove_multi ctxt [] [] props
|
haftmann@30951
|
485 |
(fn _ => Goal.precise_conjunction_tac (length props) 1 THEN tac) handle ERROR msg =>
|
haftmann@30951
|
486 |
cat_error msg ("The error(s) above occurred while trying to prove type arity " ^
|
haftmann@30951
|
487 |
quote (Syntax.string_of_arity ctxt arity));
|
haftmann@30951
|
488 |
in
|
haftmann@30951
|
489 |
thy
|
haftmann@30951
|
490 |
|> PureThy.add_thms (map (rpair []) (map Binding.name names ~~ ths))
|
haftmann@30951
|
491 |
|-> fold add_arity
|
haftmann@30951
|
492 |
end;
|
haftmann@30951
|
493 |
|
haftmann@30951
|
494 |
|
wenzelm@19511
|
495 |
|
wenzelm@19511
|
496 |
(** class definitions **)
|
wenzelm@19511
|
497 |
|
wenzelm@23421
|
498 |
fun split_defined n eq =
|
wenzelm@23421
|
499 |
let
|
wenzelm@23421
|
500 |
val intro =
|
wenzelm@23421
|
501 |
(eq RS Drule.equal_elim_rule2)
|
wenzelm@23421
|
502 |
|> Conjunction.curry_balanced n
|
wenzelm@23421
|
503 |
|> n = 0 ? Thm.eq_assumption 1;
|
wenzelm@23421
|
504 |
val dests =
|
wenzelm@23421
|
505 |
if n = 0 then []
|
wenzelm@23421
|
506 |
else
|
wenzelm@23421
|
507 |
(eq RS Drule.equal_elim_rule1)
|
wenzelm@32765
|
508 |
|> Balanced_Tree.dest (fn th =>
|
wenzelm@23421
|
509 |
(th RS Conjunction.conjunctionD1, th RS Conjunction.conjunctionD2)) n;
|
wenzelm@23421
|
510 |
in (intro, dests) end;
|
wenzelm@23421
|
511 |
|
wenzelm@24964
|
512 |
fun define_class (bclass, raw_super) raw_params raw_specs thy =
|
wenzelm@19511
|
513 |
let
|
wenzelm@36610
|
514 |
val ctxt = ProofContext.init_global thy;
|
wenzelm@24964
|
515 |
val pp = Syntax.pp ctxt;
|
wenzelm@19511
|
516 |
|
wenzelm@19511
|
517 |
|
wenzelm@24964
|
518 |
(* class *)
|
wenzelm@19511
|
519 |
|
wenzelm@30344
|
520 |
val bconst = Binding.map_name Logic.const_of_class bclass;
|
wenzelm@30344
|
521 |
val class = Sign.full_name thy bclass;
|
wenzelm@24731
|
522 |
val super = Sign.minimize_sort thy (Sign.certify_sort thy raw_super);
|
wenzelm@19511
|
523 |
|
wenzelm@24964
|
524 |
fun check_constraint (a, S) =
|
wenzelm@24964
|
525 |
if Sign.subsort thy (super, S) then ()
|
wenzelm@24964
|
526 |
else error ("Sort constraint of type variable " ^
|
wenzelm@32966
|
527 |
setmp_CRITICAL show_sorts true (Pretty.string_of_typ pp) (TFree (a, S)) ^
|
wenzelm@24964
|
528 |
" needs to be weaker than " ^ Pretty.string_of_sort pp super);
|
wenzelm@24964
|
529 |
|
wenzelm@24964
|
530 |
|
wenzelm@24964
|
531 |
(* params *)
|
wenzelm@24964
|
532 |
|
wenzelm@24964
|
533 |
val params = raw_params |> map (fn p =>
|
wenzelm@24964
|
534 |
let
|
wenzelm@24964
|
535 |
val T = Sign.the_const_type thy p;
|
wenzelm@24964
|
536 |
val _ =
|
wenzelm@24964
|
537 |
(case Term.add_tvarsT T [] of
|
wenzelm@24964
|
538 |
[((a, _), S)] => check_constraint (a, S)
|
wenzelm@24964
|
539 |
| _ => error ("Exactly one type variable expected in class parameter " ^ quote p));
|
wenzelm@24964
|
540 |
val T' = Term.map_type_tvar (fn _ => TFree (Name.aT, [class])) T;
|
wenzelm@24964
|
541 |
in (p, T') end);
|
wenzelm@24964
|
542 |
|
wenzelm@24964
|
543 |
|
wenzelm@24964
|
544 |
(* axioms *)
|
wenzelm@24964
|
545 |
|
wenzelm@19511
|
546 |
fun prep_axiom t =
|
wenzelm@19511
|
547 |
(case Term.add_tfrees t [] of
|
wenzelm@24964
|
548 |
[(a, S)] => check_constraint (a, S)
|
wenzelm@24964
|
549 |
| [] => ()
|
wenzelm@24964
|
550 |
| _ => error ("Multiple type variables in class axiom:\n" ^ Pretty.string_of_term pp t);
|
wenzelm@24964
|
551 |
t
|
wenzelm@24964
|
552 |
|> Term.map_types (Term.map_atyps (fn TFree _ => Term.aT [] | U => U))
|
wenzelm@24964
|
553 |
|> Logic.close_form);
|
wenzelm@19511
|
554 |
|
wenzelm@24681
|
555 |
val axiomss = map (map (prep_axiom o Sign.cert_prop thy) o snd) raw_specs;
|
haftmann@22745
|
556 |
val name_atts = map fst raw_specs;
|
wenzelm@19511
|
557 |
|
wenzelm@19511
|
558 |
|
wenzelm@19511
|
559 |
(* definition *)
|
wenzelm@19511
|
560 |
|
wenzelm@35854
|
561 |
val conjs = Logic.mk_of_sort (Term.aT [], super) @ flat axiomss;
|
wenzelm@19511
|
562 |
val class_eq =
|
wenzelm@31943
|
563 |
Logic.mk_equals (Logic.mk_of_class (Term.aT [], class), Logic.mk_conjunction_balanced conjs);
|
wenzelm@19511
|
564 |
|
wenzelm@19511
|
565 |
val ([def], def_thy) =
|
wenzelm@19511
|
566 |
thy
|
wenzelm@19511
|
567 |
|> Sign.primitive_class (bclass, super)
|
wenzelm@35238
|
568 |
|> PureThy.add_defs false [((Thm.def_binding bconst, class_eq), [])];
|
wenzelm@19511
|
569 |
val (raw_intro, (raw_classrel, raw_axioms)) =
|
wenzelm@23421
|
570 |
split_defined (length conjs) def ||> chop (length super);
|
wenzelm@19392
|
571 |
|
wenzelm@19418
|
572 |
|
wenzelm@19511
|
573 |
(* facts *)
|
wenzelm@19511
|
574 |
|
wenzelm@19511
|
575 |
val class_triv = Thm.class_triv def_thy class;
|
wenzelm@19511
|
576 |
val ([(_, [intro]), (_, classrel), (_, axioms)], facts_thy) =
|
wenzelm@19511
|
577 |
def_thy
|
wenzelm@35201
|
578 |
|> Sign.qualified_path true bconst
|
haftmann@27691
|
579 |
|> PureThy.note_thmss ""
|
wenzelm@36326
|
580 |
[((Binding.name "intro", []), [([Drule.export_without_context raw_intro], [])]),
|
wenzelm@36326
|
581 |
((Binding.name "super", []), [(map Drule.export_without_context raw_classrel, [])]),
|
wenzelm@36326
|
582 |
((Binding.name "axioms", []),
|
wenzelm@35021
|
583 |
[(map (fn th => Drule.export_without_context (class_triv RS th)) raw_axioms, [])])]
|
haftmann@27691
|
584 |
||> Sign.restore_naming def_thy;
|
wenzelm@19511
|
585 |
|
wenzelm@24847
|
586 |
|
wenzelm@19511
|
587 |
(* result *)
|
wenzelm@19511
|
588 |
|
wenzelm@36329
|
589 |
val axclass = make_axclass (def, intro, axioms, params);
|
wenzelm@19511
|
590 |
val result_thy =
|
wenzelm@19511
|
591 |
facts_thy
|
wenzelm@36417
|
592 |
|> fold (#2 oo put_trancl_classrel) (map (pair class) super ~~ classrel)
|
wenzelm@35201
|
593 |
|> Sign.qualified_path false bconst
|
wenzelm@36417
|
594 |
|> PureThy.note_thmss "" (name_atts ~~ map Thm.simple_fact (unflat axiomss axioms)) |> #2
|
wenzelm@19511
|
595 |
|> Sign.restore_naming facts_thy
|
wenzelm@36329
|
596 |
|> map_axclasses (Symtab.update (class, axclass))
|
wenzelm@36329
|
597 |
|> map_params (fold (fn (x, _) => add_param pp (x, class)) params);
|
wenzelm@19511
|
598 |
|
wenzelm@19511
|
599 |
in (class, result_thy) end;
|
wenzelm@19511
|
600 |
|
wenzelm@19511
|
601 |
|
wenzelm@19531
|
602 |
|
wenzelm@19511
|
603 |
(** axiomatizations **)
|
wenzelm@19511
|
604 |
|
wenzelm@19511
|
605 |
local
|
wenzelm@19511
|
606 |
|
wenzelm@36417
|
607 |
(*old-style axioms*)
|
wenzelm@35896
|
608 |
fun add_axiom (b, prop) =
|
wenzelm@35896
|
609 |
Thm.add_axiom (b, prop) #->
|
wenzelm@36106
|
610 |
(fn (_, thm) => PureThy.add_thm ((b, Drule.export_without_context thm), []));
|
wenzelm@35896
|
611 |
|
wenzelm@20628
|
612 |
fun axiomatize prep mk name add raw_args thy =
|
wenzelm@20628
|
613 |
let
|
wenzelm@20628
|
614 |
val args = prep thy raw_args;
|
wenzelm@20628
|
615 |
val specs = mk args;
|
wenzelm@20628
|
616 |
val names = name args;
|
haftmann@29579
|
617 |
in
|
haftmann@29579
|
618 |
thy
|
wenzelm@35896
|
619 |
|> fold_map add_axiom (map Binding.name names ~~ specs)
|
haftmann@29579
|
620 |
|-> fold add
|
haftmann@29579
|
621 |
end;
|
wenzelm@19511
|
622 |
|
wenzelm@19511
|
623 |
fun ax_classrel prep =
|
wenzelm@20628
|
624 |
axiomatize (map o prep) (map Logic.mk_classrel)
|
wenzelm@20628
|
625 |
(map (prefix classrel_prefix o Logic.name_classrel)) add_classrel;
|
wenzelm@19511
|
626 |
|
wenzelm@19511
|
627 |
fun ax_arity prep =
|
wenzelm@36610
|
628 |
axiomatize (prep o ProofContext.init_global) Logic.mk_arities
|
wenzelm@20628
|
629 |
(map (prefix arity_prefix) o Logic.name_arities) add_arity;
|
wenzelm@19511
|
630 |
|
wenzelm@19706
|
631 |
fun class_const c =
|
wenzelm@19706
|
632 |
(Logic.const_of_class c, Term.itselfT (Term.aT []) --> propT);
|
wenzelm@19706
|
633 |
|
wenzelm@19511
|
634 |
fun ax_class prep_class prep_classrel (bclass, raw_super) thy =
|
wenzelm@19511
|
635 |
let
|
wenzelm@30344
|
636 |
val class = Sign.full_name thy bclass;
|
wenzelm@24731
|
637 |
val super = map (prep_class thy) raw_super |> Sign.minimize_sort thy;
|
wenzelm@19511
|
638 |
in
|
wenzelm@19511
|
639 |
thy
|
wenzelm@19511
|
640 |
|> Sign.primitive_class (bclass, super)
|
wenzelm@19511
|
641 |
|> ax_classrel prep_classrel (map (fn c => (class, c)) super)
|
wenzelm@19706
|
642 |
|> Theory.add_deps "" (class_const class) (map class_const super)
|
wenzelm@19511
|
643 |
end;
|
wenzelm@19511
|
644 |
|
wenzelm@19511
|
645 |
in
|
wenzelm@19511
|
646 |
|
wenzelm@24929
|
647 |
val axiomatize_class = ax_class Sign.certify_class cert_classrel;
|
wenzelm@36610
|
648 |
val axiomatize_class_cmd = ax_class (ProofContext.read_class o ProofContext.init_global) read_classrel;
|
wenzelm@24929
|
649 |
val axiomatize_classrel = ax_classrel cert_classrel;
|
wenzelm@24929
|
650 |
val axiomatize_classrel_cmd = ax_classrel read_classrel;
|
wenzelm@35669
|
651 |
val axiomatize_arity = ax_arity ProofContext.cert_arity;
|
wenzelm@35669
|
652 |
val axiomatize_arity_cmd = ax_arity ProofContext.read_arity;
|
wenzelm@19511
|
653 |
|
wenzelm@19511
|
654 |
end;
|
wenzelm@19511
|
655 |
|
wenzelm@19511
|
656 |
end;
|