author | wenzelm |
Sat, 21 Nov 1998 12:17:18 +0100 | |
changeset 5944 | dcc446da8e19 |
parent 5685 | 1e5b4c66317f |
child 6084 | 842b059e023f |
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 |
|
560 | 5 |
User interfaces for 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 |
5685 | 10 |
val quiet_mode: bool ref |
1498 | 11 |
val add_classrel_thms: thm list -> theory -> theory |
12 |
val add_arity_thms: thm list -> theory -> theory |
|
3956 | 13 |
val add_axclass: bclass * xclass list -> (string * string) list |
1498 | 14 |
-> theory -> theory |
3956 | 15 |
val add_axclass_i: bclass * class list -> (string * term) list |
1498 | 16 |
-> theory -> theory |
3938 | 17 |
val add_inst_subclass: xclass * xclass -> string list -> thm list |
18 |
-> tactic option -> theory -> theory |
|
3788 | 19 |
val add_inst_subclass_i: class * class -> string list -> thm list |
20 |
-> tactic option -> theory -> theory |
|
3938 | 21 |
val add_inst_arity: xstring * xsort list * xclass list -> string list |
22 |
-> thm list -> tactic option -> theory -> theory |
|
3788 | 23 |
val add_inst_arity_i: string * sort list * class list -> string list |
24 |
-> thm list -> tactic option -> theory -> theory |
|
1498 | 25 |
val axclass_tac: theory -> thm list -> tactic |
26 |
val prove_subclass: theory -> class * class -> thm list |
|
27 |
-> tactic option -> thm |
|
28 |
val prove_arity: theory -> string * sort list * class -> thm list |
|
29 |
-> tactic option -> thm |
|
3949 | 30 |
val goal_subclass: theory -> xclass * xclass -> thm list |
31 |
val goal_arity: theory -> xstring * xsort list * xclass -> thm list |
|
3938 | 32 |
end; |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
33 |
|
1498 | 34 |
structure AxClass : AX_CLASS = |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
35 |
struct |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
36 |
|
4015 | 37 |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
38 |
(** utilities **) |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
39 |
|
5685 | 40 |
(* messages *) |
41 |
||
42 |
val quiet_mode = ref false; |
|
43 |
fun message s = if ! quiet_mode then () else writeln s; |
|
44 |
||
45 |
||
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
46 |
(* type vars *) |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
47 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
48 |
fun map_typ_frees f (Type (t, tys)) = Type (t, map (map_typ_frees f) tys) |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
49 |
| map_typ_frees f (TFree a) = f a |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
50 |
| map_typ_frees _ a = a; |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
51 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
52 |
val map_term_tfrees = map_term_types o map_typ_frees; |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
53 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
54 |
fun aT S = TFree ("'a", S); |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
55 |
|
3395 | 56 |
fun dest_varT (TFree (x, S)) = ((x, ~1), S) |
57 |
| dest_varT (TVar xi_S) = xi_S |
|
3788 | 58 |
| dest_varT T = raise TYPE ("dest_varT", [T], []); |
3395 | 59 |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
60 |
|
886
9af08725600b
instance: now automatically includes defs of current thy node as witnesses;
wenzelm
parents:
638
diff
changeset
|
61 |
(* get axioms and theorems *) |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
62 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
63 |
fun get_ax thy name = |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
64 |
Some (get_axiom thy name) handle THEORY _ => None; |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
65 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
66 |
val get_axioms = mapfilter o get_ax; |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
67 |
|
1498 | 68 |
val is_def = Logic.is_equals o #prop o rep_thm; |
886
9af08725600b
instance: now automatically includes defs of current thy node as witnesses;
wenzelm
parents:
638
diff
changeset
|
69 |
|
4934 | 70 |
fun witnesses thy names thms = |
71 |
flat (map (PureThy.get_thms thy) names) @ thms @ filter is_def (map snd (axioms_of thy)); |
|
886
9af08725600b
instance: now automatically includes defs of current thy node as witnesses;
wenzelm
parents:
638
diff
changeset
|
72 |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
73 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
74 |
|
560 | 75 |
(** abstract syntax operations **) |
423 | 76 |
|
77 |
(* subclass relations as terms *) |
|
78 |
||
1498 | 79 |
fun mk_classrel (c1, c2) = Logic.mk_inclass (aT [c1], c2); |
423 | 80 |
|
81 |
fun dest_classrel tm = |
|
82 |
let |
|
3788 | 83 |
fun err () = raise TERM ("dest_classrel", [tm]); |
423 | 84 |
|
3395 | 85 |
val (ty, c2) = Logic.dest_inclass tm handle TERM _ => err (); |
86 |
val c1 = (case dest_varT ty of (_, [c]) => c | _ => err ()) |
|
87 |
handle TYPE _ => err (); |
|
423 | 88 |
in |
89 |
(c1, c2) |
|
90 |
end; |
|
91 |
||
92 |
||
93 |
(* arities as terms *) |
|
94 |
||
95 |
fun mk_arity (t, ss, c) = |
|
96 |
let |
|
449 | 97 |
val names = tl (variantlist (replicate (length ss + 1) "'", [])); |
2266 | 98 |
val tfrees = ListPair.map TFree (names, ss); |
423 | 99 |
in |
1498 | 100 |
Logic.mk_inclass (Type (t, tfrees), c) |
423 | 101 |
end; |
102 |
||
103 |
fun dest_arity tm = |
|
104 |
let |
|
3788 | 105 |
fun err () = raise TERM ("dest_arity", [tm]); |
423 | 106 |
|
3395 | 107 |
val (ty, c) = Logic.dest_inclass tm handle TERM _ => err (); |
108 |
val (t, tvars) = |
|
423 | 109 |
(case ty of |
3395 | 110 |
Type (t, tys) => (t, map dest_varT tys handle TYPE _ => err ()) |
423 | 111 |
| _ => err ()); |
112 |
val ss = |
|
3395 | 113 |
if null (gen_duplicates eq_fst tvars) |
114 |
then map snd tvars else err (); |
|
423 | 115 |
in |
116 |
(t, ss, c) |
|
117 |
end; |
|
118 |
||
119 |
||
120 |
||
560 | 121 |
(** add theorems as axioms **) |
423 | 122 |
|
123 |
fun prep_thm_axm thy thm = |
|
124 |
let |
|
125 |
fun err msg = raise THM ("prep_thm_axm: " ^ msg, 0, [thm]); |
|
126 |
||
1237 | 127 |
val {sign, hyps, prop, ...} = rep_thm thm; |
423 | 128 |
in |
129 |
if not (Sign.subsig (sign, sign_of thy)) then |
|
130 |
err "theorem not of same theory" |
|
1237 | 131 |
else if not (null (extra_shyps thm)) orelse not (null hyps) then |
423 | 132 |
err "theorem may not contain hypotheses" |
133 |
else prop |
|
134 |
end; |
|
135 |
||
136 |
(*theorems expressing class relations*) |
|
137 |
fun add_classrel_thms thms thy = |
|
138 |
let |
|
139 |
fun prep_thm thm = |
|
140 |
let |
|
141 |
val prop = prep_thm_axm thy thm; |
|
142 |
val (c1, c2) = dest_classrel prop handle TERM _ => |
|
143 |
raise THM ("add_classrel_thms: theorem is not a class relation", 0, [thm]); |
|
144 |
in (c1, c2) end; |
|
145 |
in |
|
3764 | 146 |
Theory.add_classrel (map prep_thm thms) thy |
423 | 147 |
end; |
148 |
||
149 |
(*theorems expressing arities*) |
|
150 |
fun add_arity_thms thms thy = |
|
151 |
let |
|
152 |
fun prep_thm thm = |
|
153 |
let |
|
154 |
val prop = prep_thm_axm thy thm; |
|
155 |
val (t, ss, c) = dest_arity prop handle TERM _ => |
|
156 |
raise THM ("add_arity_thms: theorem is not an arity", 0, [thm]); |
|
157 |
in (t, ss, [c]) end; |
|
158 |
in |
|
3764 | 159 |
Theory.add_arities (map prep_thm thms) thy |
423 | 160 |
end; |
161 |
||
162 |
||
163 |
||
164 |
(** add axiomatic type classes **) |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
165 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
166 |
(* errors *) |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
167 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
168 |
fun err_not_logic c = |
4917 | 169 |
error ("Axiomatic class " ^ quote c ^ " not subclass of " ^ quote logicC); |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
170 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
171 |
fun err_bad_axsort ax c = |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
172 |
error ("Sort constraint in axiom " ^ quote ax ^ " not supersort of " ^ quote c); |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
173 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
174 |
fun err_bad_tfrees ax = |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
175 |
error ("More than one type variable in axiom " ^ quote ax); |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
176 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
177 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
178 |
(* ext_axclass *) |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
179 |
|
3788 | 180 |
fun ext_axclass int prep_axm (raw_class, raw_super_classes) raw_axioms old_thy = |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
181 |
let |
3938 | 182 |
val old_sign = sign_of old_thy; |
183 |
val axioms = map (prep_axm old_sign) raw_axioms; |
|
184 |
val class = Sign.full_name old_sign raw_class; |
|
185 |
||
3788 | 186 |
val thy = |
187 |
(if int then Theory.add_classes else Theory.add_classes_i) |
|
188 |
[(raw_class, raw_super_classes)] old_thy; |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
189 |
val sign = sign_of thy; |
3938 | 190 |
val super_classes = |
191 |
if int then map (Sign.intern_class sign) raw_super_classes |
|
192 |
else raw_super_classes; |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
193 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
194 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
195 |
(* prepare abstract axioms *) |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
196 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
197 |
fun abs_axm ax = |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
198 |
if null (term_tfrees ax) then |
1498 | 199 |
Logic.mk_implies (Logic.mk_inclass (aT logicS, class), ax) |
3788 | 200 |
else map_term_tfrees (K (aT [class])) ax; |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
201 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
202 |
val abs_axioms = map (apsnd abs_axm) axioms; |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
203 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
204 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
205 |
(* prepare introduction orule *) |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
206 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
207 |
val _ = |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
208 |
if Sign.subsort sign ([class], logicS) then () |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
209 |
else err_not_logic class; |
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 |
fun axm_sort (name, ax) = |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
212 |
(case term_tfrees ax of |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
213 |
[] => [] |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
214 |
| [(_, S)] => |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
215 |
if Sign.subsort sign ([class], S) then S |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
216 |
else err_bad_axsort name class |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
217 |
| _ => err_bad_tfrees name); |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
218 |
|
3788 | 219 |
val axS = Sign.norm_sort sign (logicC :: flat (map axm_sort axioms)) |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
220 |
|
1498 | 221 |
val int_axm = Logic.close_form o map_term_tfrees (K (aT axS)); |
222 |
fun inclass c = Logic.mk_inclass (aT axS, c); |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
223 |
|
1498 | 224 |
val intro_axm = Logic.list_implies |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
225 |
(map inclass super_classes @ map (int_axm o snd) axioms, inclass class); |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
226 |
in |
4845 | 227 |
thy |
228 |
|> PureThy.add_axioms_i (map Attribute.none ((raw_class ^ "I", intro_axm) :: abs_axioms)) |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
229 |
end; |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
230 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
231 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
232 |
(* external interfaces *) |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
233 |
|
3788 | 234 |
val add_axclass = ext_axclass true read_axm; |
235 |
val add_axclass_i = ext_axclass false cert_axm; |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
236 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
237 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
238 |
|
423 | 239 |
(** prove class relations and type arities **) |
240 |
||
241 |
(* class_axms *) |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
242 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
243 |
fun class_axms thy = |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
244 |
let |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
245 |
val classes = Sign.classes (sign_of thy); |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
246 |
val intros = map (fn c => c ^ "I") classes; |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
247 |
in |
1217 | 248 |
map (class_triv thy) classes @ |
249 |
get_axioms thy intros |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
250 |
end; |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
251 |
|
423 | 252 |
|
253 |
(* axclass_tac *) |
|
254 |
||
487
af83700cb771
added experimental add_defns (actually should be moved somewhere else);
wenzelm
parents:
474
diff
changeset
|
255 |
(*(1) repeatedly resolve goals of form "OFCLASS(ty, c_class)", |
1217 | 256 |
try class_trivs first, then "cI" axioms |
423 | 257 |
(2) rewrite goals using user supplied definitions |
258 |
(3) repeatedly resolve goals with user supplied non-definitions*) |
|
259 |
||
260 |
fun axclass_tac thy thms = |
|
1217 | 261 |
let |
262 |
val defs = filter is_def thms; |
|
263 |
val non_defs = filter_out is_def thms; |
|
264 |
in |
|
265 |
TRY (REPEAT_FIRST (resolve_tac (class_axms thy))) THEN |
|
266 |
TRY (rewrite_goals_tac defs) THEN |
|
267 |
TRY (REPEAT_FIRST (fn i => assume_tac i ORELSE resolve_tac non_defs i)) |
|
268 |
end; |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
269 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
270 |
|
423 | 271 |
(* provers *) |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
272 |
|
423 | 273 |
fun prove term_of str_of thy sig_prop thms usr_tac = |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
274 |
let |
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
275 |
val sign = sign_of thy; |
423 | 276 |
val goal = cterm_of sign (term_of sig_prop); |
277 |
val tac = axclass_tac thy thms THEN (if_none usr_tac all_tac); |
|
278 |
in |
|
279 |
prove_goalw_cterm [] goal (K [tac]) |
|
280 |
end |
|
281 |
handle ERROR => error ("The error(s) above occurred while trying to prove " |
|
3854
762606a888fe
uses Sign.str_of_classrel, Sign.str_of_arity, Sign.str_of_arity;
wenzelm
parents:
3809
diff
changeset
|
282 |
^ quote (str_of (sign_of thy, sig_prop))); |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
283 |
|
638 | 284 |
val prove_subclass = |
3854
762606a888fe
uses Sign.str_of_classrel, Sign.str_of_arity, Sign.str_of_arity;
wenzelm
parents:
3809
diff
changeset
|
285 |
prove mk_classrel (fn (sg, c1_c2) => Sign.str_of_classrel sg c1_c2); |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
286 |
|
423 | 287 |
val prove_arity = |
3854
762606a888fe
uses Sign.str_of_classrel, Sign.str_of_arity, Sign.str_of_arity;
wenzelm
parents:
3809
diff
changeset
|
288 |
prove mk_arity (fn (sg, (t, Ss, c)) => Sign.str_of_arity sg (t, Ss, [c])); |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
289 |
|
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
290 |
|
423 | 291 |
|
449 | 292 |
(** add proved subclass relations and arities **) |
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
293 |
|
3949 | 294 |
fun intrn_classrel sg c1_c2 = |
295 |
pairself (Sign.intern_class sg) c1_c2; |
|
296 |
||
4934 | 297 |
fun ext_inst_subclass int raw_c1_c2 names thms usr_tac thy = |
3788 | 298 |
let |
3949 | 299 |
val c1_c2 = |
300 |
if int then intrn_classrel (sign_of thy) raw_c1_c2 |
|
301 |
else raw_c1_c2; |
|
3788 | 302 |
in |
5685 | 303 |
message ("Proving class inclusion " ^ |
3854
762606a888fe
uses Sign.str_of_classrel, Sign.str_of_arity, Sign.str_of_arity;
wenzelm
parents:
3809
diff
changeset
|
304 |
quote (Sign.str_of_classrel (sign_of thy) c1_c2) ^ " ..."); |
3788 | 305 |
add_classrel_thms |
4934 | 306 |
[prove_subclass thy c1_c2 (witnesses thy names thms) usr_tac] thy |
3788 | 307 |
end; |
423 | 308 |
|
3788 | 309 |
|
3949 | 310 |
fun intrn_arity sg intrn (t, Ss, x) = |
311 |
(Sign.intern_tycon sg t, map (Sign.intern_sort sg) Ss, intrn sg x); |
|
312 |
||
4934 | 313 |
fun ext_inst_arity int (raw_t, raw_Ss, raw_cs) names thms usr_tac thy = |
423 | 314 |
let |
3788 | 315 |
val sign = sign_of thy; |
316 |
val (t, Ss, cs) = |
|
3949 | 317 |
if int then intrn_arity sign Sign.intern_sort (raw_t, raw_Ss, raw_cs) |
3788 | 318 |
else (raw_t, raw_Ss, raw_cs); |
4934 | 319 |
val wthms = witnesses thy names thms; |
423 | 320 |
fun prove c = |
5685 | 321 |
(message ("Proving type arity " ^ |
3854
762606a888fe
uses Sign.str_of_classrel, Sign.str_of_arity, Sign.str_of_arity;
wenzelm
parents:
3809
diff
changeset
|
322 |
quote (Sign.str_of_arity sign (t, Ss, [c])) ^ " ..."); |
762606a888fe
uses Sign.str_of_classrel, Sign.str_of_arity, Sign.str_of_arity;
wenzelm
parents:
3809
diff
changeset
|
323 |
prove_arity thy (t, Ss, c) wthms usr_tac); |
423 | 324 |
in |
325 |
add_arity_thms (map prove cs) thy |
|
326 |
end; |
|
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
327 |
|
3788 | 328 |
val add_inst_subclass = ext_inst_subclass true; |
329 |
val add_inst_subclass_i = ext_inst_subclass false; |
|
330 |
val add_inst_arity = ext_inst_arity true; |
|
331 |
val add_inst_arity_i = ext_inst_arity false; |
|
332 |
||
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
333 |
|
3949 | 334 |
(* make goals (for interactive use) *) |
335 |
||
336 |
fun mk_goal term_of thy sig_prop = |
|
337 |
goalw_cterm [] (cterm_of (sign_of thy) (term_of sig_prop)); |
|
338 |
||
339 |
fun goal_subclass thy = |
|
340 |
mk_goal (mk_classrel o intrn_classrel (sign_of thy)) thy; |
|
341 |
||
342 |
fun goal_arity thy = |
|
343 |
mk_goal (mk_arity o intrn_arity (sign_of thy) Sign.intern_class) thy; |
|
344 |
||
345 |
||
404
dd3d3d6467db
axiomatic type class 'package' for Pure (alpha version);
wenzelm
parents:
diff
changeset
|
346 |
end; |