9 signature METIS_CLAUSES = |
9 signature METIS_CLAUSES = |
10 sig |
10 sig |
11 type name = string * string |
11 type name = string * string |
12 datatype kind = Axiom | Conjecture |
12 datatype kind = Axiom | Conjecture |
13 datatype type_literal = |
13 datatype type_literal = |
14 TyLitVar of string * name | |
14 TyLitVar of name * name | |
15 TyLitFree of string * name |
15 TyLitFree of name * name |
16 datatype arLit = |
16 datatype arLit = |
17 TConsLit of class * string * string list |
17 TConsLit of name * name * name list | |
18 | TVarLit of class * string |
18 TVarLit of name * name |
19 datatype arity_clause = ArityClause of |
19 datatype arity_clause = ArityClause of |
20 {axiom_name: string, conclLit: arLit, premLits: arLit list} |
20 {axiom_name: string, conclLit: arLit, premLits: arLit list} |
21 datatype classrel_clause = ClassrelClause of |
21 datatype classrel_clause = ClassrelClause of |
22 {axiom_name: string, subclass: class, superclass: class} |
22 {axiom_name: string, subclass: name, superclass: name} |
23 datatype combtyp = |
23 datatype combtyp = |
24 TyVar of name | |
24 TyVar of name | |
25 TyFree of name | |
25 TyFree of name | |
26 TyConstr of name * combtyp list |
26 TyConstr of name * combtyp list |
27 datatype combterm = |
27 datatype combterm = |
37 val schematic_var_prefix: string |
37 val schematic_var_prefix: string |
38 val fixed_var_prefix: string |
38 val fixed_var_prefix: string |
39 val tvar_prefix: string |
39 val tvar_prefix: string |
40 val tfree_prefix: string |
40 val tfree_prefix: string |
41 val const_prefix: string |
41 val const_prefix: string |
42 val tconst_prefix: string |
42 val type_const_prefix: string |
43 val class_prefix: string |
43 val class_prefix: string |
44 val union_all: ''a list list -> ''a list |
44 val union_all: ''a list list -> ''a list |
45 val invert_const: string -> string |
45 val invert_const: string -> string |
46 val ascii_of: string -> string |
46 val ascii_of: string -> string |
47 val undo_ascii_of: string -> string |
47 val undo_ascii_of: string -> string |
86 val tfree_prefix = "t_"; |
86 val tfree_prefix = "t_"; |
87 |
87 |
88 val classrel_clause_prefix = "clsrel_"; |
88 val classrel_clause_prefix = "clsrel_"; |
89 |
89 |
90 val const_prefix = "c_"; |
90 val const_prefix = "c_"; |
91 val tconst_prefix = "tc_"; |
91 val type_const_prefix = "tc_"; |
92 val class_prefix = "class_"; |
92 val class_prefix = "class_"; |
93 |
93 |
94 fun union_all xss = fold (union (op =)) xss [] |
94 fun union_all xss = fold (union (op =)) xss [] |
95 |
95 |
96 (* Readable names for the more common symbolic functions. Do not mess with the |
96 (* Readable names for the more common symbolic functions. Do not mess with the |
97 last nine entries of the table unless you know what you are doing. *) |
97 last nine entries of the table unless you know what you are doing. *) |
98 val const_trans_table = |
98 val const_trans_table = |
99 Symtab.make [(@{const_name "op ="}, "equal"), |
99 Symtab.make [(@{type_name "*"}, "prod"), |
|
100 (@{type_name "+"}, "sum"), |
|
101 (@{const_name "op ="}, "equal"), |
100 (@{const_name "op &"}, "and"), |
102 (@{const_name "op &"}, "and"), |
101 (@{const_name "op |"}, "or"), |
103 (@{const_name "op |"}, "or"), |
102 (@{const_name "op -->"}, "implies"), |
104 (@{const_name "op -->"}, "implies"), |
103 (@{const_name "op :"}, "in"), |
105 (@{const_name "op :"}, "in"), |
104 (@{const_name fequal}, "fequal"), |
106 (@{const_name fequal}, "fequal"), |
107 (@{const_name COMBB}, "COMBB"), |
109 (@{const_name COMBB}, "COMBB"), |
108 (@{const_name COMBC}, "COMBC"), |
110 (@{const_name COMBC}, "COMBC"), |
109 (@{const_name COMBS}, "COMBS"), |
111 (@{const_name COMBS}, "COMBS"), |
110 (@{const_name True}, "True"), |
112 (@{const_name True}, "True"), |
111 (@{const_name False}, "False"), |
113 (@{const_name False}, "False"), |
112 (@{const_name If}, "If"), |
114 (@{const_name If}, "If")] |
113 (@{type_name "*"}, "prod"), |
|
114 (@{type_name "+"}, "sum")] |
|
115 |
115 |
116 (* Invert the table of translations between Isabelle and ATPs. *) |
116 (* Invert the table of translations between Isabelle and ATPs. *) |
117 val const_trans_table_inv = |
117 val const_trans_table_inv = |
118 Symtab.update ("fequal", @{const_name "op ="}) |
118 Symtab.update ("fequal", @{const_name "op ="}) |
119 (Symtab.make (map swap (Symtab.dest const_trans_table))) |
119 (Symtab.make (map swap (Symtab.dest const_trans_table))) |
193 |
193 |
194 (* "op =" MUST BE "equal" because it's built into ATPs. *) |
194 (* "op =" MUST BE "equal" because it's built into ATPs. *) |
195 fun make_fixed_const @{const_name "op ="} = "equal" |
195 fun make_fixed_const @{const_name "op ="} = "equal" |
196 | make_fixed_const c = const_prefix ^ lookup_const c |
196 | make_fixed_const c = const_prefix ^ lookup_const c |
197 |
197 |
198 fun make_fixed_type_const c = tconst_prefix ^ lookup_const c |
198 fun make_fixed_type_const c = type_const_prefix ^ lookup_const c |
199 |
199 |
200 fun make_type_class clas = class_prefix ^ ascii_of clas; |
200 fun make_type_class clas = class_prefix ^ ascii_of clas; |
201 |
201 |
202 val skolem_theory_name = "Sledgehammer" ^ Long_Name.separator ^ "Sko" |
202 val skolem_theory_name = "Sledgehammer" ^ Long_Name.separator ^ "Sko" |
203 val skolem_prefix = "sko_" |
203 val skolem_prefix = "sko_" |
228 |
228 |
229 (**** Isabelle FOL clauses ****) |
229 (**** Isabelle FOL clauses ****) |
230 |
230 |
231 (* The first component is the type class; the second is a TVar or TFree. *) |
231 (* The first component is the type class; the second is a TVar or TFree. *) |
232 datatype type_literal = |
232 datatype type_literal = |
233 TyLitVar of string * name | |
233 TyLitVar of name * name | |
234 TyLitFree of string * name |
234 TyLitFree of name * name |
235 |
235 |
236 exception CLAUSE of string * term; |
236 exception CLAUSE of string * term; |
237 |
237 |
238 (*Make literals for sorted type variables*) |
238 (*Make literals for sorted type variables*) |
239 fun sorts_on_typs_aux (_, []) = [] |
239 fun sorts_on_typs_aux (_, []) = [] |
240 | sorts_on_typs_aux ((x,i), s::ss) = |
240 | sorts_on_typs_aux ((x,i), s::ss) = |
241 let val sorts = sorts_on_typs_aux ((x,i), ss) |
241 let val sorts = sorts_on_typs_aux ((x,i), ss) |
242 in |
242 in |
243 if s = "HOL.type" then sorts |
243 if s = "HOL.type" then sorts |
244 else if i = ~1 then TyLitFree (make_type_class s, `make_fixed_type_var x) :: sorts |
244 else if i = ~1 then TyLitFree (`make_type_class s, `make_fixed_type_var x) :: sorts |
245 else TyLitVar (make_type_class s, (make_schematic_type_var (x,i), x)) :: sorts |
245 else TyLitVar (`make_type_class s, (make_schematic_type_var (x,i), x)) :: sorts |
246 end; |
246 end; |
247 |
247 |
248 fun sorts_on_typs (TFree (a,s)) = sorts_on_typs_aux ((a,~1),s) |
248 fun sorts_on_typs (TFree (a,s)) = sorts_on_typs_aux ((a,~1),s) |
249 | sorts_on_typs (TVar (v,s)) = sorts_on_typs_aux (v,s); |
249 | sorts_on_typs (TVar (v,s)) = sorts_on_typs_aux (v,s); |
250 |
250 |
254 |
254 |
255 (** make axiom and conjecture clauses. **) |
255 (** make axiom and conjecture clauses. **) |
256 |
256 |
257 (**** Isabelle arities ****) |
257 (**** Isabelle arities ****) |
258 |
258 |
259 datatype arLit = TConsLit of class * string * string list |
259 datatype arLit = |
260 | TVarLit of class * string; |
260 TConsLit of name * name * name list | |
|
261 TVarLit of name * name |
261 |
262 |
262 datatype arity_clause = |
263 datatype arity_clause = |
263 ArityClause of {axiom_name: string, conclLit: arLit, premLits: arLit list} |
264 ArityClause of {axiom_name: string, conclLit: arLit, premLits: arLit list} |
264 |
265 |
265 |
266 |
266 fun gen_TVars 0 = [] |
267 fun gen_TVars 0 = [] |
267 | gen_TVars n = ("T_" ^ Int.toString n) :: gen_TVars (n-1); |
268 | gen_TVars n = ("T_" ^ Int.toString n) :: gen_TVars (n-1); |
268 |
269 |
269 fun pack_sort(_,[]) = [] |
270 fun pack_sort(_,[]) = [] |
270 | pack_sort(tvar, "HOL.type"::srt) = pack_sort(tvar, srt) (*IGNORE sort "type"*) |
271 | pack_sort(tvar, "HOL.type"::srt) = pack_sort (tvar, srt) (*IGNORE sort "type"*) |
271 | pack_sort(tvar, cls::srt) = (cls, tvar) :: pack_sort(tvar, srt); |
272 | pack_sort(tvar, cls::srt) = |
|
273 (`make_type_class cls, (tvar, tvar)) :: pack_sort (tvar, srt) |
272 |
274 |
273 (*Arity of type constructor tcon :: (arg1,...,argN)res*) |
275 (*Arity of type constructor tcon :: (arg1,...,argN)res*) |
274 fun make_axiom_arity_clause (tcons, axiom_name, (cls,args)) = |
276 fun make_axiom_arity_clause (tcons, axiom_name, (cls,args)) = |
275 let val tvars = gen_TVars (length args) |
277 let |
276 val tvars_srts = ListPair.zip (tvars,args) |
278 val tvars = gen_TVars (length args) |
277 in |
279 val tvars_srts = ListPair.zip (tvars, args) |
278 ArityClause {axiom_name = axiom_name, |
280 in |
279 conclLit = TConsLit (cls, make_fixed_type_const tcons, tvars), |
281 ArityClause {axiom_name = axiom_name, |
280 premLits = map TVarLit (union_all(map pack_sort tvars_srts))} |
282 conclLit = TConsLit (`make_type_class cls, |
281 end; |
283 `make_fixed_type_const tcons, |
|
284 tvars ~~ tvars), |
|
285 premLits = map TVarLit (union_all (map pack_sort tvars_srts))} |
|
286 end |
282 |
287 |
283 |
288 |
284 (**** Isabelle class relations ****) |
289 (**** Isabelle class relations ****) |
285 |
290 |
286 datatype classrel_clause = |
291 datatype classrel_clause = |
287 ClassrelClause of {axiom_name: string, subclass: class, superclass: class} |
292 ClassrelClause of {axiom_name: string, subclass: name, superclass: name} |
288 |
293 |
289 (*Generate all pairs (sub,super) such that sub is a proper subclass of super in theory thy.*) |
294 (*Generate all pairs (sub,super) such that sub is a proper subclass of super in theory thy.*) |
290 fun class_pairs _ [] _ = [] |
295 fun class_pairs _ [] _ = [] |
291 | class_pairs thy subs supers = |
296 | class_pairs thy subs supers = |
292 let |
297 let |
296 in fold add_supers subs [] end |
301 in fold add_supers subs [] end |
297 |
302 |
298 fun make_classrel_clause (sub,super) = |
303 fun make_classrel_clause (sub,super) = |
299 ClassrelClause {axiom_name = classrel_clause_prefix ^ ascii_of sub ^ "_" ^ |
304 ClassrelClause {axiom_name = classrel_clause_prefix ^ ascii_of sub ^ "_" ^ |
300 ascii_of super, |
305 ascii_of super, |
301 subclass = make_type_class sub, |
306 subclass = `make_type_class sub, |
302 superclass = make_type_class super}; |
307 superclass = `make_type_class super}; |
303 |
308 |
304 fun make_classrel_clauses thy subs supers = |
309 fun make_classrel_clauses thy subs supers = |
305 map make_classrel_clause (class_pairs thy subs supers); |
310 map make_classrel_clause (class_pairs thy subs supers); |
306 |
311 |
307 |
312 |