author | blanchet |
Fri, 16 Apr 2010 14:48:34 +0200 | |
changeset 36169 | 27b1cc58715e |
parent 36168 | 0a6ed065683d |
child 36170 | 0cdb76723c88 |
permissions | -rw-r--r-- |
35826 | 1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_fol_clause.ML |
33311 | 2 |
Author: Jia Meng, Cambridge University Computer Laboratory |
15347 | 3 |
|
33311 | 4 |
Storing/printing FOL clauses and arity clauses. Typed equality is |
5 |
treated differently. |
|
6 |
||
7 |
FIXME: combine with res_hol_clause! |
|
15347 | 8 |
*) |
9 |
||
35826 | 10 |
signature SLEDGEHAMMER_FOL_CLAUSE = |
24310 | 11 |
sig |
12 |
val schematic_var_prefix: string |
|
13 |
val fixed_var_prefix: string |
|
14 |
val tvar_prefix: string |
|
15 |
val tfree_prefix: string |
|
16 |
val clause_prefix: string |
|
17 |
val const_prefix: string |
|
18 |
val tconst_prefix: string |
|
19 |
val class_prefix: string |
|
20 |
val union_all: ''a list list -> ''a list |
|
21 |
val const_trans_table: string Symtab.table |
|
22 |
val type_const_trans_table: string Symtab.table |
|
23 |
val ascii_of: string -> string |
|
24 |
val undo_ascii_of: string -> string |
|
25 |
val paren_pack : string list -> string |
|
26 |
val make_schematic_var : string * int -> string |
|
18868 | 27 |
val make_fixed_var : string -> string |
28 |
val make_schematic_type_var : string * int -> string |
|
24310 | 29 |
val make_fixed_type_var : string -> string |
30151 | 30 |
val make_fixed_const : bool -> string -> string |
31 |
val make_fixed_type_const : bool -> string -> string |
|
18868 | 32 |
val make_type_class : string -> string |
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
33 |
type name = string * string |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
34 |
type name_pool = string Symtab.table * string Symtab.table |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
35 |
val empty_name_pool : bool -> name_pool option |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
36 |
val pool_map : ('a -> 'b -> 'c * 'b) -> 'a list -> 'b -> 'c list * 'b |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
37 |
val nice_name : name -> name_pool option -> string * name_pool option |
24310 | 38 |
datatype kind = Axiom | Conjecture |
39 |
type axiom_name = string |
|
40 |
datatype fol_type = |
|
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
41 |
TyVar of name | |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
42 |
TyFree of name | |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
43 |
TyConstr of name * fol_type list |
18868 | 44 |
val string_of_fol_type : fol_type -> string |
24310 | 45 |
datatype type_literal = LTVar of string * string | LTFree of string * string |
46 |
exception CLAUSE of string * term |
|
24940 | 47 |
val add_typs : typ list -> type_literal list |
48 |
val get_tvar_strs: typ list -> string list |
|
24310 | 49 |
datatype arLit = |
50 |
TConsLit of class * string * string list |
|
51 |
| TVarLit of class * string |
|
35865 | 52 |
datatype arity_clause = ArityClause of |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
53 |
{axiom_name: axiom_name, conclLit: arLit, premLits: arLit list} |
35865 | 54 |
datatype classrel_clause = ClassrelClause of |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
55 |
{axiom_name: axiom_name, subclass: class, superclass: class} |
35865 | 56 |
val make_classrel_clauses: theory -> class list -> class list -> classrel_clause list |
57 |
val make_arity_clauses_dfg: bool -> theory -> string list -> class list -> class list * arity_clause list |
|
58 |
val make_arity_clauses: theory -> string list -> class list -> class list * arity_clause list |
|
24940 | 59 |
val add_type_sort_preds: typ * int Symtab.table -> int Symtab.table |
35865 | 60 |
val add_classrel_clause_preds : classrel_clause * int Symtab.table -> int Symtab.table |
24310 | 61 |
val class_of_arityLit: arLit -> class |
35865 | 62 |
val add_arity_clause_preds: arity_clause * int Symtab.table -> int Symtab.table |
24310 | 63 |
val add_foltype_funcs: fol_type * int Symtab.table -> int Symtab.table |
35865 | 64 |
val add_arity_clause_funcs: arity_clause * int Symtab.table -> int Symtab.table |
24310 | 65 |
val init_functab: int Symtab.table |
19719 | 66 |
val dfg_sign: bool -> string -> string |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
67 |
val dfg_of_typeLit: bool -> type_literal -> string |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
68 |
val gen_dfg_cls: int * string * kind * string list * string list * string list -> string |
24310 | 69 |
val string_of_preds: (string * Int.int) list -> string |
70 |
val string_of_funcs: (string * int) list -> string |
|
71 |
val string_of_symbols: string -> string -> string |
|
19719 | 72 |
val string_of_start: string -> string |
73 |
val string_of_descrip : string -> string |
|
24310 | 74 |
val dfg_tfree_clause : string -> string |
35865 | 75 |
val dfg_classrel_clause: classrel_clause -> string |
76 |
val dfg_arity_clause: arity_clause -> string |
|
24310 | 77 |
val tptp_sign: bool -> string -> string |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
78 |
val tptp_of_typeLit : bool -> type_literal -> string |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
79 |
val gen_tptp_cls : int * string * kind * string list * string list -> string |
24310 | 80 |
val tptp_tfree_clause : string -> string |
35865 | 81 |
val tptp_arity_clause : arity_clause -> string |
82 |
val tptp_classrel_clause : classrel_clause -> string |
|
24310 | 83 |
end |
15347 | 84 |
|
35826 | 85 |
structure Sledgehammer_FOL_Clause : SLEDGEHAMMER_FOL_CLAUSE = |
15347 | 86 |
struct |
87 |
||
36063
cdc6855a6387
make Sledgehammer output "by" vs. "apply", "qed" vs. "next", and any necessary "prefer"
blanchet
parents:
36062
diff
changeset
|
88 |
open Sledgehammer_Util |
cdc6855a6387
make Sledgehammer output "by" vs. "apply", "qed" vs. "next", and any necessary "prefer"
blanchet
parents:
36062
diff
changeset
|
89 |
|
15347 | 90 |
val schematic_var_prefix = "V_"; |
91 |
val fixed_var_prefix = "v_"; |
|
92 |
||
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
93 |
val tvar_prefix = "T_"; |
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
94 |
val tfree_prefix = "t_"; |
15347 | 95 |
|
24310 | 96 |
val clause_prefix = "cls_"; |
97 |
val arclause_prefix = "clsarity_" |
|
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
98 |
val clrelclause_prefix = "clsrel_"; |
15347 | 99 |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
100 |
val const_prefix = "c_"; |
24310 | 101 |
val tconst_prefix = "tc_"; |
102 |
val class_prefix = "class_"; |
|
15347 | 103 |
|
33042 | 104 |
fun union_all xss = List.foldl (uncurry (union (op =))) [] xss; |
17775 | 105 |
|
35865 | 106 |
(* Provide readable names for the more common symbolic functions *) |
15347 | 107 |
val const_trans_table = |
35865 | 108 |
Symtab.make [(@{const_name "op ="}, "equal"), |
109 |
(@{const_name Orderings.less_eq}, "lessequals"), |
|
110 |
(@{const_name "op &"}, "and"), |
|
111 |
(@{const_name "op |"}, "or"), |
|
112 |
(@{const_name "op -->"}, "implies"), |
|
113 |
(@{const_name "op :"}, "in"), |
|
114 |
(@{const_name fequal}, "fequal"), |
|
115 |
(@{const_name COMBI}, "COMBI"), |
|
116 |
(@{const_name COMBK}, "COMBK"), |
|
117 |
(@{const_name COMBB}, "COMBB"), |
|
118 |
(@{const_name COMBC}, "COMBC"), |
|
119 |
(@{const_name COMBS}, "COMBS")]; |
|
15347 | 120 |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
121 |
val type_const_trans_table = |
35865 | 122 |
Symtab.make [("*", "prod"), ("+", "sum"), ("~=>", "map")]; |
15347 | 123 |
|
15610 | 124 |
(*Escaping of special characters. |
125 |
Alphanumeric characters are left unchanged. |
|
126 |
The character _ goes to __ |
|
127 |
Characters in the range ASCII space to / go to _A to _P, respectively. |
|
24183 | 128 |
Other printing characters go to _nnn where nnn is the decimal ASCII code.*) |
129 |
val A_minus_space = Char.ord #"A" - Char.ord #" "; |
|
15610 | 130 |
|
24183 | 131 |
fun stringN_of_int 0 _ = "" |
132 |
| stringN_of_int k n = stringN_of_int (k-1) (n div 10) ^ Int.toString (n mod 10); |
|
15610 | 133 |
|
15347 | 134 |
fun ascii_of_c c = |
15610 | 135 |
if Char.isAlphaNum c then String.str c |
136 |
else if c = #"_" then "__" |
|
24310 | 137 |
else if #" " <= c andalso c <= #"/" |
15610 | 138 |
then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space)) |
24310 | 139 |
else if Char.isPrint c |
24183 | 140 |
then ("_" ^ stringN_of_int 3 (Char.ord c)) (*fixed width, in case more digits follow*) |
15610 | 141 |
else "" |
15347 | 142 |
|
15610 | 143 |
val ascii_of = String.translate ascii_of_c; |
144 |
||
24183 | 145 |
(** Remove ASCII armouring from names in proof files **) |
146 |
||
147 |
(*We don't raise error exceptions because this code can run inside the watcher. |
|
148 |
Also, the errors are "impossible" (hah!)*) |
|
149 |
fun undo_ascii_aux rcs [] = String.implode(rev rcs) |
|
150 |
| undo_ascii_aux rcs [#"_"] = undo_ascii_aux (#"_"::rcs) [] (*ERROR*) |
|
151 |
(*Three types of _ escapes: __, _A to _P, _nnn*) |
|
152 |
| undo_ascii_aux rcs (#"_" :: #"_" :: cs) = undo_ascii_aux (#"_"::rcs) cs |
|
24310 | 153 |
| undo_ascii_aux rcs (#"_" :: c :: cs) = |
24183 | 154 |
if #"A" <= c andalso c<= #"P" (*translation of #" " to #"/"*) |
155 |
then undo_ascii_aux (Char.chr(Char.ord c - A_minus_space) :: rcs) cs |
|
24310 | 156 |
else |
24183 | 157 |
let val digits = List.take (c::cs, 3) handle Subscript => [] |
24310 | 158 |
in |
24183 | 159 |
case Int.fromString (String.implode digits) of |
160 |
NONE => undo_ascii_aux (c:: #"_"::rcs) cs (*ERROR*) |
|
161 |
| SOME n => undo_ascii_aux (Char.chr n :: rcs) (List.drop (cs, 2)) |
|
162 |
end |
|
163 |
| undo_ascii_aux rcs (c::cs) = undo_ascii_aux (c::rcs) cs; |
|
164 |
||
165 |
val undo_ascii_of = undo_ascii_aux [] o String.explode; |
|
15347 | 166 |
|
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
167 |
(* convert a list of strings into one single string; surrounded by brackets *) |
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
168 |
fun paren_pack [] = "" (*empty argument list*) |
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
169 |
| paren_pack strings = "(" ^ commas strings ^ ")"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
170 |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
171 |
(*TSTP format uses (...) rather than the old [...]*) |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
172 |
fun tptp_pack strings = "(" ^ space_implode " | " strings ^ ")"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
173 |
|
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
174 |
|
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
175 |
(*Remove the initial ' character from a type variable, if it is present*) |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
176 |
fun trim_type_var s = |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
177 |
if s <> "" andalso String.sub(s,0) = #"'" then String.extract(s,1,NONE) |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
178 |
else error ("trim_type: Malformed type variable encountered: " ^ s); |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
179 |
|
16903 | 180 |
fun ascii_of_indexname (v,0) = ascii_of v |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
181 |
| ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ Int.toString i; |
15347 | 182 |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
183 |
fun make_schematic_var v = schematic_var_prefix ^ (ascii_of_indexname v); |
15347 | 184 |
fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x); |
185 |
||
24310 | 186 |
fun make_schematic_type_var (x,i) = |
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
187 |
tvar_prefix ^ (ascii_of_indexname (trim_type_var x,i)); |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
188 |
fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x)); |
15347 | 189 |
|
36062 | 190 |
(* HACK because SPASS 3.0 truncates identifiers to 63 characters. (This is |
191 |
solved in 3.7 and perhaps in earlier versions too.) *) |
|
192 |
(* 32-bit hash, so we expect no collisions. *) |
|
193 |
fun controlled_length dfg s = |
|
36063
cdc6855a6387
make Sledgehammer output "by" vs. "apply", "qed" vs. "next", and any necessary "prefer"
blanchet
parents:
36062
diff
changeset
|
194 |
if dfg andalso size s > 60 then Word.toString (hashw_string (s, 0w0)) else s; |
23075 | 195 |
|
30151 | 196 |
fun lookup_const dfg c = |
17412 | 197 |
case Symtab.lookup const_trans_table c of |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
198 |
SOME c' => c' |
30151 | 199 |
| NONE => controlled_length dfg (ascii_of c); |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
200 |
|
30151 | 201 |
fun lookup_type_const dfg c = |
17412 | 202 |
case Symtab.lookup type_const_trans_table c of |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
203 |
SOME c' => c' |
30151 | 204 |
| NONE => controlled_length dfg (ascii_of c); |
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
205 |
|
36062 | 206 |
(* "op =" MUST BE "equal" because it's built into ATPs. *) |
207 |
fun make_fixed_const _ (@{const_name "op ="}) = "equal" |
|
208 |
| make_fixed_const dfg c = const_prefix ^ lookup_const dfg c; |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
209 |
|
30151 | 210 |
fun make_fixed_type_const dfg c = tconst_prefix ^ lookup_type_const dfg c; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
211 |
|
17261 | 212 |
fun make_type_class clas = class_prefix ^ ascii_of clas; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
213 |
|
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
214 |
|
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
215 |
(**** name pool ****) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
216 |
|
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
217 |
type name = string * string |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
218 |
type name_pool = string Symtab.table * string Symtab.table |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
219 |
|
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
220 |
fun empty_name_pool debug = if debug then SOME (`I Symtab.empty) else NONE |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
221 |
|
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
222 |
fun pool_map f xs = |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
223 |
fold (fn x => fn (ys, pool) => f x pool |>> (fn y => y :: ys)) xs o pair [] |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
224 |
|
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
225 |
fun add_nice_name full_name nice_prefix j the_pool = |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
226 |
let |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
227 |
val nice_name = nice_prefix ^ (if j = 0 then "" else "_" ^ Int.toString j) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
228 |
in |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
229 |
case Symtab.lookup (snd the_pool) nice_name of |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
230 |
SOME full_name' => |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
231 |
if full_name = full_name' then (nice_name, the_pool) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
232 |
else add_nice_name full_name nice_prefix (j + 1) the_pool |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
233 |
| NONE => |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
234 |
(nice_name, (Symtab.update_new (full_name, nice_name) (fst the_pool), |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
235 |
Symtab.update_new (nice_name, full_name) (snd the_pool))) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
236 |
end |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
237 |
|
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
238 |
fun translate_first_char f s = |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
239 |
String.str (f (String.sub (s, 0))) ^ String.extract (s, 1, NONE) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
240 |
|
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
241 |
fun clean_short_name full_name s = |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
242 |
let |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
243 |
val s = s |> Long_Name.base_name |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
244 |
|> fold remove_all ["\<^sub>", "\<^bsub>", "\<^esub>", "\<^isub>"] |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
245 |
val s' = s |> explode |> rev |> dropwhile (curry (op =) "'") |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
246 |
val s' = |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
247 |
(s' |> rev |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
248 |
|> implode |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
249 |
|> String.translate |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
250 |
(fn c => if Char.isAlphaNum c then String.str c else "")) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
251 |
^ replicate_string (String.size s - length s') "_" |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
252 |
val s' = |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
253 |
if s' = "" orelse not (Char.isAlpha (String.sub (s', 0))) then "X" ^ s' |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
254 |
else s' |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
255 |
val s' = if s' = "op" then full_name else s' |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
256 |
in |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
257 |
case (Char.isLower (String.sub (full_name, 0)), |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
258 |
Char.isLower (String.sub (s', 0))) of |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
259 |
(true, false) => translate_first_char Char.toLower s' |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
260 |
| (false, true) => translate_first_char Char.toUpper s' |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
261 |
| _ => s' |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
262 |
end |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
263 |
|
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
264 |
fun nice_name (full_name, _) NONE = (full_name, NONE) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
265 |
| nice_name (full_name, desired_name) (SOME the_pool) = |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
266 |
case Symtab.lookup (fst the_pool) full_name of |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
267 |
SOME nice_name => (nice_name, SOME the_pool) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
268 |
| NONE => add_nice_name full_name (clean_short_name full_name desired_name) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
269 |
0 the_pool |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
270 |
|> apsnd SOME |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
271 |
|
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
272 |
(**** Definitions and functions for FOL clauses, for conversion to TPTP or DFG |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
273 |
format ****) |
15347 | 274 |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
275 |
datatype kind = Axiom | Conjecture; |
23385 | 276 |
|
15347 | 277 |
type axiom_name = string; |
278 |
||
279 |
(**** Isabelle FOL clauses ****) |
|
280 |
||
36168
0a6ed065683d
give more sensible names to "fol_type" constructors, as requested by a FIXME comment
blanchet
parents:
36167
diff
changeset
|
281 |
datatype fol_type = |
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
282 |
TyVar of name | |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
283 |
TyFree of name | |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
284 |
TyConstr of name * fol_type list |
18402
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
285 |
|
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
286 |
fun string_of_fol_type (TyVar (s, _)) = s |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
287 |
| string_of_fol_type (TyFree (s, _)) = s |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
288 |
| string_of_fol_type (TyConstr ((tcon, _), tps)) = |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
289 |
tcon ^ (paren_pack (map string_of_fol_type tps)); |
24310 | 290 |
|
18798 | 291 |
(*First string is the type class; the second is a TVar or TFfree*) |
292 |
datatype type_literal = LTVar of string * string | LTFree of string * string; |
|
15347 | 293 |
|
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
294 |
exception CLAUSE of string * term; |
15347 | 295 |
|
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
296 |
fun atomic_type (TFree (a,_)) = TyFree (`make_fixed_type_var a) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
297 |
| atomic_type (TVar (x, _)) = |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
298 |
TyVar (make_schematic_type_var x, string_of_indexname x) |
15390 | 299 |
|
24310 | 300 |
(*Make literals for sorted type variables*) |
24940 | 301 |
fun sorts_on_typs_aux (_, []) = [] |
302 |
| sorts_on_typs_aux ((x,i), s::ss) = |
|
303 |
let val sorts = sorts_on_typs_aux ((x,i), ss) |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
304 |
in |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
305 |
if s = "HOL.type" then sorts |
24940 | 306 |
else if i = ~1 then LTFree(make_type_class s, make_fixed_type_var x) :: sorts |
307 |
else LTVar(make_type_class s, make_schematic_type_var (x,i)) :: sorts |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
308 |
end; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
309 |
|
24940 | 310 |
fun sorts_on_typs (TFree (a,s)) = sorts_on_typs_aux ((a,~1),s) |
311 |
| sorts_on_typs (TVar (v,s)) = sorts_on_typs_aux (v,s); |
|
312 |
||
18798 | 313 |
fun pred_of_sort (LTVar (s,ty)) = (s,1) |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
314 |
| pred_of_sort (LTFree (s,ty)) = (s,1) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
315 |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
316 |
(*Given a list of sorted type variables, return a list of type literals.*) |
33042 | 317 |
fun add_typs Ts = List.foldl (uncurry (union (op =))) [] (map sorts_on_typs Ts); |
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
318 |
|
29676 | 319 |
(*The correct treatment of TFrees like 'a in lemmas (axiom clauses) is not clear. |
320 |
* Ignoring them leads to unsound proofs, since we do nothing to ensure that 'a |
|
321 |
in a lemma has the same sort as 'a in the conjecture. |
|
322 |
* Deleting such clauses will lead to problems with locales in other use of local results |
|
323 |
where 'a is fixed. Probably we should delete clauses unless the sorts agree. |
|
324 |
* Currently we include a class constraint in the clause, exactly as with TVars. |
|
325 |
*) |
|
326 |
||
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
327 |
(** make axiom and conjecture clauses. **) |
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
328 |
|
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
329 |
fun get_tvar_strs [] = [] |
24940 | 330 |
| get_tvar_strs ((TVar (indx,s))::Ts) = |
331 |
insert (op =) (make_schematic_type_var indx) (get_tvar_strs Ts) |
|
332 |
| get_tvar_strs((TFree _)::Ts) = get_tvar_strs Ts |
|
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
333 |
|
24310 | 334 |
|
19354 | 335 |
|
15347 | 336 |
(**** Isabelle arities ****) |
337 |
||
338 |
exception ARCLAUSE of string; |
|
339 |
||
24310 | 340 |
datatype arLit = TConsLit of class * string * string list |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
341 |
| TVarLit of class * string; |
24310 | 342 |
|
35865 | 343 |
datatype arity_clause = |
24310 | 344 |
ArityClause of {axiom_name: axiom_name, |
345 |
conclLit: arLit, |
|
346 |
premLits: arLit list}; |
|
15347 | 347 |
|
348 |
||
18798 | 349 |
fun gen_TVars 0 = [] |
350 |
| gen_TVars n = ("T_" ^ Int.toString n) :: gen_TVars (n-1); |
|
15347 | 351 |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
352 |
fun pack_sort(_,[]) = [] |
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
353 |
| pack_sort(tvar, "HOL.type"::srt) = pack_sort(tvar, srt) (*IGNORE sort "type"*) |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
354 |
| pack_sort(tvar, cls::srt) = (cls, tvar) :: pack_sort(tvar, srt); |
24310 | 355 |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
356 |
(*Arity of type constructor tcon :: (arg1,...,argN)res*) |
30151 | 357 |
fun make_axiom_arity_clause dfg (tcons, axiom_name, (cls,args)) = |
21560 | 358 |
let val tvars = gen_TVars (length args) |
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
359 |
val tvars_srts = ListPair.zip (tvars,args) |
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
360 |
in |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
361 |
ArityClause {axiom_name = axiom_name, |
30151 | 362 |
conclLit = TConsLit (cls, make_fixed_type_const dfg tcons, tvars), |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
363 |
premLits = map TVarLit (union_all(map pack_sort tvars_srts))} |
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
364 |
end; |
15347 | 365 |
|
366 |
||
367 |
(**** Isabelle class relations ****) |
|
368 |
||
35865 | 369 |
datatype classrel_clause = |
24310 | 370 |
ClassrelClause of {axiom_name: axiom_name, |
371 |
subclass: class, |
|
372 |
superclass: class}; |
|
373 |
||
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
374 |
(*Generate all pairs (sub,super) such that sub is a proper subclass of super in theory thy.*) |
21432
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset
|
375 |
fun class_pairs thy [] supers = [] |
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset
|
376 |
| class_pairs thy subs supers = |
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset
|
377 |
let val class_less = Sorts.class_less(Sign.classes_of thy) |
24310 | 378 |
fun add_super sub (super,pairs) = |
379 |
if class_less (sub,super) then (sub,super)::pairs else pairs |
|
30190 | 380 |
fun add_supers (sub,pairs) = List.foldl (add_super sub) pairs supers |
381 |
in List.foldl add_supers [] subs end; |
|
15347 | 382 |
|
35865 | 383 |
fun make_classrel_clause (sub,super) = |
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
384 |
ClassrelClause {axiom_name = clrelclause_prefix ^ ascii_of sub ^ "_" ^ ascii_of super, |
24310 | 385 |
subclass = make_type_class sub, |
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
386 |
superclass = make_type_class super}; |
15347 | 387 |
|
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
388 |
fun make_classrel_clauses thy subs supers = |
35865 | 389 |
map make_classrel_clause (class_pairs thy subs supers); |
18868 | 390 |
|
391 |
||
392 |
(** Isabelle arities **) |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
393 |
|
30151 | 394 |
fun arity_clause dfg _ _ (tcons, []) = [] |
395 |
| arity_clause dfg seen n (tcons, ("HOL.type",_)::ars) = (*ignore*) |
|
396 |
arity_clause dfg seen n (tcons,ars) |
|
397 |
| arity_clause dfg seen n (tcons, (ar as (class,_)) :: ars) = |
|
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
398 |
if class mem_string seen then (*multiple arities for the same tycon, class pair*) |
30151 | 399 |
make_axiom_arity_clause dfg (tcons, lookup_type_const dfg tcons ^ "_" ^ class ^ "_" ^ Int.toString n, ar) :: |
400 |
arity_clause dfg seen (n+1) (tcons,ars) |
|
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
401 |
else |
30151 | 402 |
make_axiom_arity_clause dfg (tcons, lookup_type_const dfg tcons ^ "_" ^ class, ar) :: |
403 |
arity_clause dfg (class::seen) n (tcons,ars) |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
404 |
|
30151 | 405 |
fun multi_arity_clause dfg [] = [] |
406 |
| multi_arity_clause dfg ((tcons,ars) :: tc_arlists) = |
|
407 |
arity_clause dfg [] 1 (tcons, ars) @ multi_arity_clause dfg tc_arlists |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
408 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
409 |
(*Generate all pairs (tycon,class,sorts) such that tycon belongs to class in theory thy |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
410 |
provided its arguments have the corresponding sorts.*) |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
411 |
fun type_class_pairs thy tycons classes = |
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
412 |
let val alg = Sign.classes_of thy |
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
413 |
fun domain_sorts (tycon,class) = Sorts.mg_domain alg tycon [class] |
24310 | 414 |
fun add_class tycon (class,pairs) = |
415 |
(class, domain_sorts(tycon,class))::pairs |
|
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
416 |
handle Sorts.CLASS_ERROR _ => pairs |
30190 | 417 |
fun try_classes tycon = (tycon, List.foldl (add_class tycon) [] classes) |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
418 |
in map try_classes tycons end; |
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
419 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
420 |
(*Proving one (tycon, class) membership may require proving others, so iterate.*) |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
421 |
fun iter_type_class_pairs thy tycons [] = ([], []) |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
422 |
| iter_type_class_pairs thy tycons classes = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
423 |
let val cpairs = type_class_pairs thy tycons classes |
33040 | 424 |
val newclasses = union_all (union_all (union_all (map (map #2 o #2) cpairs))) |
425 |
|> subtract (op =) classes |> subtract (op =) HOLogic.typeS |
|
24310 | 426 |
val (classes', cpairs') = iter_type_class_pairs thy tycons newclasses |
33042 | 427 |
in (union (op =) classes' classes, union (op =) cpairs' cpairs) end; |
24310 | 428 |
|
30151 | 429 |
fun make_arity_clauses_dfg dfg thy tycons classes = |
24310 | 430 |
let val (classes', cpairs) = iter_type_class_pairs thy tycons classes |
30151 | 431 |
in (classes', multi_arity_clause dfg cpairs) end; |
432 |
val make_arity_clauses = make_arity_clauses_dfg false; |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
433 |
|
18868 | 434 |
(**** Find occurrences of predicates in clauses ****) |
435 |
||
24310 | 436 |
(*FIXME: multiple-arity checking doesn't work, as update_new is the wrong |
18868 | 437 |
function (it flags repeated declarations of a function, even with the same arity)*) |
438 |
||
30190 | 439 |
fun update_many (tab, keypairs) = List.foldl (uncurry Symtab.update) tab keypairs; |
18868 | 440 |
|
24940 | 441 |
fun add_type_sort_preds (T, preds) = |
442 |
update_many (preds, map pred_of_sort (sorts_on_typs T)); |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
443 |
|
35865 | 444 |
fun add_classrel_clause_preds (ClassrelClause {subclass,superclass,...}, preds) = |
18868 | 445 |
Symtab.update (subclass,1) (Symtab.update (superclass,1) preds); |
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
446 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
447 |
fun class_of_arityLit (TConsLit (tclass, _, _)) = tclass |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
448 |
| class_of_arityLit (TVarLit (tclass, _)) = tclass; |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
449 |
|
35865 | 450 |
fun add_arity_clause_preds (ArityClause {conclLit,premLits,...}, preds) = |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
451 |
let val classes = map (make_type_class o class_of_arityLit) (conclLit::premLits) |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
452 |
fun upd (class,preds) = Symtab.update (class,1) preds |
30190 | 453 |
in List.foldl upd preds classes end; |
18868 | 454 |
|
455 |
(*** Find occurrences of functions in clauses ***) |
|
456 |
||
36168
0a6ed065683d
give more sensible names to "fol_type" constructors, as requested by a FIXME comment
blanchet
parents:
36167
diff
changeset
|
457 |
fun add_foltype_funcs (TyVar _, funcs) = funcs |
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
458 |
| add_foltype_funcs (TyFree (s, _), funcs) = Symtab.update (s, 0) funcs |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
459 |
| add_foltype_funcs (TyConstr ((s, _), tys), funcs) = |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
460 |
List.foldl add_foltype_funcs (Symtab.update (s, length tys) funcs) tys; |
18868 | 461 |
|
20038 | 462 |
(*TFrees are recorded as constants*) |
24940 | 463 |
fun add_type_sort_funcs (TVar _, funcs) = funcs |
464 |
| add_type_sort_funcs (TFree (a, _), funcs) = |
|
20038 | 465 |
Symtab.update (make_fixed_type_var a, 0) funcs |
466 |
||
35865 | 467 |
fun add_arity_clause_funcs (ArityClause {conclLit,...}, funcs) = |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
468 |
let val TConsLit (_, tcons, tvars) = conclLit |
18868 | 469 |
in Symtab.update (tcons, length tvars) funcs end; |
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
470 |
|
23075 | 471 |
(*This type can be overlooked because it is built-in...*) |
472 |
val init_functab = Symtab.update ("tc_itself", 1) Symtab.empty; |
|
473 |
||
18868 | 474 |
|
475 |
(**** String-oriented operations ****) |
|
15347 | 476 |
|
24310 | 477 |
fun string_of_clausename (cls_id,ax_name) = |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
478 |
clause_prefix ^ ascii_of ax_name ^ "_" ^ Int.toString cls_id; |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset
|
479 |
|
24310 | 480 |
fun string_of_type_clsname (cls_id,ax_name,idx) = |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
481 |
string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx); |
18863 | 482 |
|
24310 | 483 |
|
18868 | 484 |
(**** Producing DFG files ****) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
485 |
|
18863 | 486 |
(*Attach sign in DFG syntax: false means negate.*) |
487 |
fun dfg_sign true s = s |
|
24310 | 488 |
| dfg_sign false s = "not(" ^ s ^ ")" |
18863 | 489 |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
490 |
fun dfg_of_typeLit pos (LTVar (s,ty)) = dfg_sign pos (s ^ "(" ^ ty ^ ")") |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
491 |
| dfg_of_typeLit pos (LTFree (s,ty)) = dfg_sign pos (s ^ "(" ^ ty ^ ")"); |
24310 | 492 |
|
18868 | 493 |
(*Enclose the clause body by quantifiers, if necessary*) |
24310 | 494 |
fun dfg_forall [] body = body |
18868 | 495 |
| dfg_forall vars body = "forall([" ^ commas vars ^ "],\n" ^ body ^ ")" |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
496 |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
497 |
fun gen_dfg_cls (cls_id, ax_name, Axiom, lits, tylits, vars) = |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
498 |
"clause( %(axiom)\n" ^ |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
499 |
dfg_forall vars ("or(" ^ commas (tylits@lits) ^ ")") ^ ",\n" ^ |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
500 |
string_of_clausename (cls_id,ax_name) ^ ").\n\n" |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
501 |
| gen_dfg_cls (cls_id, ax_name, Conjecture, lits, _, vars) = |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
502 |
"clause( %(negated_conjecture)\n" ^ |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
503 |
dfg_forall vars ("or(" ^ commas lits ^ ")") ^ ",\n" ^ |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
504 |
string_of_clausename (cls_id,ax_name) ^ ").\n\n"; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
505 |
|
18798 | 506 |
fun string_of_arity (name, num) = "(" ^ name ^ "," ^ Int.toString num ^ ")" |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
507 |
|
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
508 |
fun string_of_preds [] = "" |
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
509 |
| string_of_preds preds = "predicates[" ^ commas(map string_of_arity preds) ^ "].\n"; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
510 |
|
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
511 |
fun string_of_funcs [] = "" |
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
512 |
| string_of_funcs funcs = "functions[" ^ commas(map string_of_arity funcs) ^ "].\n" ; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
513 |
|
24310 | 514 |
fun string_of_symbols predstr funcstr = |
17234 | 515 |
"list_of_symbols.\n" ^ predstr ^ funcstr ^ "end_of_list.\n\n"; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
516 |
|
18798 | 517 |
fun string_of_start name = "begin_problem(" ^ name ^ ").\n\n"; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
518 |
|
24310 | 519 |
fun string_of_descrip name = |
520 |
"list_of_descriptions.\nname({*" ^ name ^ |
|
18868 | 521 |
"*}).\nauthor({*Isabelle*}).\nstatus(unknown).\ndescription({*auto-generated*}).\nend_of_list.\n\n" |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
522 |
|
18863 | 523 |
fun dfg_tfree_clause tfree_lit = |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
524 |
"clause( %(negated_conjecture)\n" ^ "or( " ^ tfree_lit ^ "),\n" ^ "tfree_tcs" ^ ").\n\n" |
18863 | 525 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
526 |
fun dfg_of_arLit (TConsLit (c,t,args)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
527 |
dfg_sign true (make_type_class c ^ "(" ^ t ^ paren_pack args ^ ")") |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
528 |
| dfg_of_arLit (TVarLit (c,str)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
529 |
dfg_sign false (make_type_class c ^ "(" ^ str ^ ")") |
24310 | 530 |
|
20038 | 531 |
fun dfg_classrelLits sub sup = "not(" ^ sub ^ "(T)), " ^ sup ^ "(T)"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
532 |
|
35865 | 533 |
fun dfg_classrel_clause (ClassrelClause {axiom_name,subclass,superclass,...}) = |
18868 | 534 |
"clause(forall([T],\nor( " ^ dfg_classrelLits subclass superclass ^ ")),\n" ^ |
535 |
axiom_name ^ ").\n\n"; |
|
24310 | 536 |
|
21560 | 537 |
fun string_of_ar axiom_name = arclause_prefix ^ ascii_of axiom_name; |
538 |
||
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
539 |
fun dfg_arity_clause (ArityClause{axiom_name,conclLit,premLits,...}) = |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
540 |
let val TConsLit (_,_,tvars) = conclLit |
18868 | 541 |
val lits = map dfg_of_arLit (conclLit :: premLits) |
18863 | 542 |
in |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
543 |
"clause( %(axiom)\n" ^ |
18868 | 544 |
dfg_forall tvars ("or( " ^ commas lits ^ ")") ^ ",\n" ^ |
21560 | 545 |
string_of_ar axiom_name ^ ").\n\n" |
18863 | 546 |
end; |
547 |
||
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
548 |
|
18869
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
paulson
parents:
18868
diff
changeset
|
549 |
(**** Produce TPTP files ****) |
18868 | 550 |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
551 |
fun tptp_sign true s = s |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
552 |
| tptp_sign false s = "~ " ^ s |
18868 | 553 |
|
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
554 |
fun tptp_of_typeLit pos (LTVar (s, ty)) = tptp_sign pos (s ^ "(" ^ ty ^ ")") |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
555 |
| tptp_of_typeLit pos (LTFree (s, ty)) = tptp_sign pos (s ^ "(" ^ ty ^ ")") |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
556 |
|
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
557 |
fun tptp_cnf name kind formula = |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
558 |
"cnf(" ^ name ^ ", " ^ kind ^ ",\n " ^ formula ^ ").\n" |
24310 | 559 |
|
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
560 |
fun gen_tptp_cls (cls_id, ax_name, Axiom, lits, tylits) = |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
561 |
tptp_cnf (string_of_clausename (cls_id, ax_name)) "axiom" |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
562 |
(tptp_pack (tylits @ lits)) |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
563 |
| gen_tptp_cls (cls_id, ax_name, Conjecture, lits, _) = |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
564 |
tptp_cnf (string_of_clausename (cls_id, ax_name)) "negated_conjecture" |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
565 |
(tptp_pack lits) |
15347 | 566 |
|
18863 | 567 |
fun tptp_tfree_clause tfree_lit = |
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
568 |
tptp_cnf "tfree_tcs" "negated_conjecture" (tptp_pack [tfree_lit]) |
24310 | 569 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
570 |
fun tptp_of_arLit (TConsLit (c,t,args)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
571 |
tptp_sign true (make_type_class c ^ "(" ^ t ^ paren_pack args ^ ")") |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
572 |
| tptp_of_arLit (TVarLit (c,str)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
573 |
tptp_sign false (make_type_class c ^ "(" ^ str ^ ")") |
24310 | 574 |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
575 |
fun tptp_arity_clause (ArityClause{axiom_name,conclLit,premLits,...}) = |
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
576 |
tptp_cnf (string_of_ar axiom_name) "axiom" |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
577 |
(tptp_pack (map tptp_of_arLit (conclLit :: premLits))) |
15347 | 578 |
|
24310 | 579 |
fun tptp_classrelLits sub sup = |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
580 |
let val tvar = "(T)" |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
581 |
in tptp_pack [tptp_sign false (sub^tvar), tptp_sign true (sup^tvar)] end; |
15347 | 582 |
|
35865 | 583 |
fun tptp_classrel_clause (ClassrelClause {axiom_name,subclass,superclass,...}) = |
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36063
diff
changeset
|
584 |
tptp_cnf axiom_name "axiom" (tptp_classrelLits subclass superclass) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
585 |
|
15347 | 586 |
end; |