| author | urbanc | 
| Thu, 22 Mar 2007 11:17:32 +0100 | |
| changeset 22495 | c54748fd1f43 | 
| parent 22383 | 01e90256550d | 
| child 22643 | bc3bb8e9594a | 
| permissions | -rw-r--r-- | 
| 15347 | 1 | (* Author: Jia Meng, Cambridge University Computer Laboratory | 
| 2 | ID: $Id$ | |
| 3 | Copyright 2004 University of Cambridge | |
| 4 | ||
| 5 | ML data structure for storing/printing FOL clauses and arity clauses. | |
| 6 | Typed equality is treated differently. | |
| 7 | *) | |
| 8 | ||
| 20422 
35a6a4c863f1
removed the (apparently pointless) signature constraint
 paulson parents: 
20418diff
changeset | 9 | (*FIXME: is this signature necessary? Or maybe define and open a Basic_ResClause?*) | 
| 15347 | 10 | signature RES_CLAUSE = | 
| 11 | sig | |
| 18868 | 12 | exception CLAUSE of string * term | 
| 13 | type clause and arityClause and classrelClause | |
| 20824 | 14 | datatype fol_type = AtomV of string | 
| 15 | | AtomF of string | |
| 16 | | Comp of string * fol_type list; | |
| 21813 | 17 | datatype fol_term = UVar of string | 
| 20824 | 18 | | Fun of string * fol_type list * fol_term list; | 
| 19 | datatype predicate = Predicate of string * fol_type list * fol_term list; | |
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 20 | datatype kind = Axiom | Conjecture; | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 21 | val name_of_kind : kind -> string | 
| 20824 | 22 | type typ_var and type_literal and literal | 
| 23 | val literals_of_term: Term.term -> literal list * (typ_var * Term.sort) list | |
| 18868 | 24 | val add_typs_aux : (typ_var * string list) list -> type_literal list * type_literal list | 
| 25 | val arity_clause_thy: theory -> arityClause list | |
| 26 | val ascii_of : string -> string | |
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 27 | val tptp_pack : string list -> string | 
| 21290 
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
 paulson parents: 
21254diff
changeset | 28 | val make_classrel_clauses: theory -> class list -> class list -> classrelClause list | 
| 18868 | 29 | val clause_prefix : string | 
| 30 | val clause2tptp : clause -> string * string list | |
| 31 | val const_prefix : string | |
| 20022 | 32 | val dfg_write_file: thm list -> string -> | 
| 33 | ((thm * (string * int)) list * classrelClause list * arityClause list) -> string list | |
| 18868 | 34 | val fixed_var_prefix : string | 
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 35 | val gen_tptp_cls : int * string * string * string list -> string | 
| 18868 | 36 | val get_axiomName : clause -> string | 
| 20824 | 37 | val get_literals : clause -> literal list | 
| 18868 | 38 | val init : theory -> unit | 
| 39 | val isMeta : string -> bool | |
| 40 | val isTaut : clause -> bool | |
| 41 |   val list_ord : ('a * 'b -> order) -> 'a list * 'b list -> order
 | |
| 19443 
e32a4703d834
Take conjectures and axioms as thms when convert them to ResClause.clause format.
 mengj parents: 
19354diff
changeset | 42 | val make_axiom_clause : thm -> string * int -> clause option | 
| 
e32a4703d834
Take conjectures and axioms as thms when convert them to ResClause.clause format.
 mengj parents: 
19354diff
changeset | 43 | val make_conjecture_clauses : thm list -> clause list | 
| 18868 | 44 | val make_fixed_const : string -> string | 
| 45 | val make_fixed_type_const : string -> string | |
| 46 | val make_fixed_type_var : string -> string | |
| 47 | val make_fixed_var : string -> string | |
| 48 | val make_schematic_type_var : string * int -> string | |
| 49 | val make_schematic_var : string * int -> string | |
| 50 | val make_type_class : string -> string | |
| 51 | val mk_typ_var_sort : Term.typ -> typ_var * sort | |
| 52 | val paren_pack : string list -> string | |
| 53 | val schematic_var_prefix : string | |
| 54 | val string_of_fol_type : fol_type -> string | |
| 55 | val tconst_prefix : string | |
| 56 | val tfree_prefix : string | |
| 21813 | 57 | val tvar_prefix : string | 
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 58 | val tptp_arity_clause : arityClause -> string | 
| 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 59 | val tptp_classrelClause : classrelClause -> string | 
| 18868 | 60 | val tptp_of_typeLit : type_literal -> string | 
| 18863 | 61 | val tptp_tfree_clause : string -> string | 
| 20022 | 62 | val tptp_write_file: thm list -> string -> | 
| 63 | ((thm * (string * int)) list * classrelClause list * arityClause list) -> string list | |
| 17908 
ac97527724ba
More functions are added to the signature of ResClause
 mengj parents: 
17888diff
changeset | 64 | val union_all : ''a list list -> ''a list | 
| 18863 | 65 | val writeln_strs: TextIO.outstream -> TextIO.vector list -> unit | 
| 19719 | 66 | val dfg_sign: bool -> string -> string | 
| 67 | val dfg_of_typeLit: type_literal -> string | |
| 68 | val get_tvar_strs: (typ_var * sort) list -> string list | |
| 69 | val gen_dfg_cls: int * string * string * string * string list -> string | |
| 70 | val add_foltype_funcs: fol_type * int Symtab.table -> int Symtab.table | |
| 71 | val add_arityClause_funcs: arityClause * int Symtab.table -> int Symtab.table | |
| 72 | val add_arityClause_preds: arityClause * int Symtab.table -> int Symtab.table | |
| 73 | val add_classrelClause_preds : classrelClause * int Symtab.table -> int Symtab.table | |
| 74 | val dfg_tfree_clause : string -> string | |
| 75 | val string_of_start: string -> string | |
| 76 | val string_of_descrip : string -> string | |
| 77 | val string_of_symbols: string -> string -> string | |
| 78 | val string_of_funcs: (string * int) list -> string | |
| 79 | val string_of_preds: (string * Int.int) list -> string | |
| 80 | val dfg_classrelClause: classrelClause -> string | |
| 81 | val dfg_arity_clause: arityClause -> string | |
| 82 | end; | |
| 15347 | 83 | |
| 20422 
35a6a4c863f1
removed the (apparently pointless) signature constraint
 paulson parents: 
20418diff
changeset | 84 | structure ResClause = | 
| 15347 | 85 | struct | 
| 86 | ||
| 87 | val schematic_var_prefix = "V_"; | |
| 88 | val fixed_var_prefix = "v_"; | |
| 89 | ||
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 90 | val tvar_prefix = "T_"; | 
| 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 91 | val tfree_prefix = "t_"; | 
| 15347 | 92 | |
| 93 | val clause_prefix = "cls_"; | |
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 94 | val arclause_prefix = "clsarity_" | 
| 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 95 | val clrelclause_prefix = "clsrel_"; | 
| 15347 | 96 | |
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 97 | val const_prefix = "c_"; | 
| 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 98 | val tconst_prefix = "tc_"; | 
| 16199 
ee95ab217fee
no longer emits literals for type class HOL.type; also minor tidying
 paulson parents: 
16039diff
changeset | 99 | val class_prefix = "class_"; | 
| 15347 | 100 | |
| 17775 | 101 | fun union_all xss = foldl (op union) [] xss; | 
| 102 | ||
| 103 | (*Provide readable names for the more common symbolic functions*) | |
| 15347 | 104 | val const_trans_table = | 
| 105 |       Symtab.make [("op =", "equal"),
 | |
| 19277 | 106 | 	  	   ("Orderings.less_eq", "lessequals"),
 | 
| 107 | 		   ("Orderings.less", "less"),
 | |
| 15347 | 108 | 		   ("op &", "and"),
 | 
| 109 | 		   ("op |", "or"),
 | |
| 19233 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
19207diff
changeset | 110 | 		   ("HOL.plus", "plus"),
 | 
| 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
19207diff
changeset | 111 | 		   ("HOL.minus", "minus"),
 | 
| 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
19207diff
changeset | 112 | 		   ("HOL.times", "times"),
 | 
| 21416 | 113 | 		   ("Divides.div", "div"),
 | 
| 18676 | 114 | 		   ("HOL.divide", "divide"),
 | 
| 15347 | 115 | 		   ("op -->", "implies"),
 | 
| 17375 | 116 | 		   ("{}", "emptyset"),
 | 
| 15347 | 117 | 		   ("op :", "in"),
 | 
| 118 | 		   ("op Un", "union"),
 | |
| 18390 | 119 | 		   ("op Int", "inter"),
 | 
| 20790 
a9595fdc02b1
Added the combinator constants to the constants table.
 mengj parents: 
20422diff
changeset | 120 | 		   ("List.op @", "append"),
 | 
| 21254 
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
 wenzelm parents: 
20854diff
changeset | 121 | 		   ("ATP_Linkup.fequal", "fequal"),
 | 
| 
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
 wenzelm parents: 
20854diff
changeset | 122 | 		   ("ATP_Linkup.COMBI", "COMBI"),
 | 
| 
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
 wenzelm parents: 
20854diff
changeset | 123 | 		   ("ATP_Linkup.COMBK", "COMBK"),
 | 
| 
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
 wenzelm parents: 
20854diff
changeset | 124 | 		   ("ATP_Linkup.COMBB", "COMBB"),
 | 
| 
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
 wenzelm parents: 
20854diff
changeset | 125 | 		   ("ATP_Linkup.COMBC", "COMBC"),
 | 
| 
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
 wenzelm parents: 
20854diff
changeset | 126 | 		   ("ATP_Linkup.COMBS", "COMBS"),
 | 
| 
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
 wenzelm parents: 
20854diff
changeset | 127 | 		   ("ATP_Linkup.COMBB'", "COMBB_e"),
 | 
| 
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
 wenzelm parents: 
20854diff
changeset | 128 | 		   ("ATP_Linkup.COMBC'", "COMBC_e"),
 | 
| 
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
 wenzelm parents: 
20854diff
changeset | 129 | 		   ("ATP_Linkup.COMBS'", "COMBS_e")];
 | 
| 15347 | 130 | |
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 131 | val type_const_trans_table = | 
| 18411 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 132 |       Symtab.make [("*", "prod"),
 | 
| 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 133 | 	  	   ("+", "sum"),
 | 
| 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 134 | 		   ("~=>", "map")];
 | 
| 15347 | 135 | |
| 15610 | 136 | (*Escaping of special characters. | 
| 137 | Alphanumeric characters are left unchanged. | |
| 138 | The character _ goes to __ | |
| 139 | Characters in the range ASCII space to / go to _A to _P, respectively. | |
| 140 | Other printing characters go to _NNN where NNN is the decimal ASCII code.*) | |
| 141 | local | |
| 142 | ||
| 143 | val A_minus_space = Char.ord #"A" - Char.ord #" "; | |
| 144 | ||
| 15347 | 145 | fun ascii_of_c c = | 
| 15610 | 146 | if Char.isAlphaNum c then String.str c | 
| 147 | else if c = #"_" then "__" | |
| 148 | else if #" " <= c andalso c <= #"/" | |
| 149 | then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space)) | |
| 150 |   else if Char.isPrint c then ("_" ^ Int.toString (Char.ord c))
 | |
| 151 | else "" | |
| 15347 | 152 | |
| 15610 | 153 | in | 
| 154 | ||
| 155 | val ascii_of = String.translate ascii_of_c; | |
| 156 | ||
| 157 | end; | |
| 15347 | 158 | |
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 159 | (* 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: 
18199diff
changeset | 160 | fun paren_pack [] = "" (*empty argument list*) | 
| 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
 paulson parents: 
18199diff
changeset | 161 |   | paren_pack strings = "(" ^ commas strings ^ ")";
 | 
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 162 | |
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 163 | (*TSTP format uses (...) rather than the old [...]*) | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 164 | fun tptp_pack strings = "(" ^ space_implode " | " strings ^ ")";
 | 
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 165 | |
| 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 166 | |
| 16925 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 167 | (*Remove the initial ' character from a type variable, if it is present*) | 
| 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 168 | fun trim_type_var s = | 
| 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 169 | 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: 
16903diff
changeset | 170 |   else error ("trim_type: Malformed type variable encountered: " ^ s);
 | 
| 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 171 | |
| 16903 | 172 | fun ascii_of_indexname (v,0) = ascii_of v | 
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 173 | | ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ Int.toString i; | 
| 15347 | 174 | |
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 175 | fun make_schematic_var v = schematic_var_prefix ^ (ascii_of_indexname v); | 
| 15347 | 176 | fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x); | 
| 177 | ||
| 16925 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 178 | fun make_schematic_type_var (x,i) = | 
| 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 179 | tvar_prefix ^ (ascii_of_indexname (trim_type_var x,i)); | 
| 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 180 | fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x)); | 
| 15347 | 181 | |
| 18411 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 182 | fun lookup_const c = | 
| 17412 | 183 | case Symtab.lookup const_trans_table c of | 
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 184 | SOME c' => c' | 
| 18411 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 185 | | NONE => ascii_of c; | 
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 186 | |
| 18411 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 187 | fun lookup_type_const c = | 
| 17412 | 188 | case Symtab.lookup type_const_trans_table c of | 
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 189 | SOME c' => c' | 
| 18411 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 190 | | NONE => ascii_of c; | 
| 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 191 | |
| 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 192 | fun make_fixed_const "op =" = "equal" (*MUST BE "equal" because it's built-in to ATPs*) | 
| 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 193 | | make_fixed_const c = const_prefix ^ lookup_const c; | 
| 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 194 | |
| 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 195 | fun make_fixed_type_const c = tconst_prefix ^ lookup_type_const c; | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 196 | |
| 17261 | 197 | fun make_type_class clas = class_prefix ^ ascii_of clas; | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 198 | |
| 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 199 | |
| 18798 | 200 | (***** definitions and functions for FOL clauses, for conversion to TPTP or DFG format. *****) | 
| 15347 | 201 | |
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 202 | datatype kind = Axiom | Conjecture; | 
| 15347 | 203 | fun name_of_kind Axiom = "axiom" | 
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 204 | | name_of_kind Conjecture = "negated_conjecture"; | 
| 15347 | 205 | |
| 206 | type clause_id = int; | |
| 207 | type axiom_name = string; | |
| 208 | type polarity = bool; | |
| 209 | ||
| 210 | (**** Isabelle FOL clauses ****) | |
| 211 | ||
| 18402 
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
 mengj parents: 
18390diff
changeset | 212 | datatype typ_var = FOLTVar of indexname | FOLTFree of string; | 
| 
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
 mengj parents: 
18390diff
changeset | 213 | |
| 18798 | 214 | (*FIXME: give the constructors more sensible names*) | 
| 18402 
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
 mengj parents: 
18390diff
changeset | 215 | datatype fol_type = AtomV of string | 
| 
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
 mengj parents: 
18390diff
changeset | 216 | | AtomF of string | 
| 
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
 mengj parents: 
18390diff
changeset | 217 | | Comp of string * fol_type list; | 
| 
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
 mengj parents: 
18390diff
changeset | 218 | |
| 
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
 mengj parents: 
18390diff
changeset | 219 | fun string_of_fol_type (AtomV x) = x | 
| 
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
 mengj parents: 
18390diff
changeset | 220 | | string_of_fol_type (AtomF x) = x | 
| 
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
 mengj parents: 
18390diff
changeset | 221 | | string_of_fol_type (Comp(tcon,tps)) = | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 222 | tcon ^ (paren_pack (map string_of_fol_type tps)); | 
| 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 223 | |
| 18798 | 224 | (*First string is the type class; the second is a TVar or TFfree*) | 
| 225 | datatype type_literal = LTVar of string * string | LTFree of string * string; | |
| 15347 | 226 | |
| 21813 | 227 | datatype fol_term = UVar of string | 
| 20038 | 228 | | Fun of string * fol_type list * fol_term list; | 
| 20824 | 229 | datatype predicate = Predicate of string * fol_type list * fol_term list; | 
| 15347 | 230 | |
| 20018 | 231 | datatype literal = Literal of polarity * predicate; | 
| 15347 | 232 | |
| 17999 | 233 | fun mk_typ_var_sort (TFree(a,s)) = (FOLTFree a,s) | 
| 234 | | mk_typ_var_sort (TVar(v,s)) = (FOLTVar v,s); | |
| 235 | ||
| 236 | ||
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 237 | (*A clause has first-order literals and other, type-related literals*) | 
| 15347 | 238 | datatype clause = | 
| 239 | 	 Clause of {clause_id: clause_id,
 | |
| 240 | axiom_name: axiom_name, | |
| 19447 | 241 | th: thm, | 
| 15347 | 242 | kind: kind, | 
| 243 | literals: literal list, | |
| 18869 
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
 paulson parents: 
18868diff
changeset | 244 | types_sorts: (typ_var * sort) list}; | 
| 
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
 paulson parents: 
18868diff
changeset | 245 | |
| 
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
 paulson parents: 
18868diff
changeset | 246 | fun get_axiomName (Clause cls) = #axiom_name cls; | 
| 15347 | 247 | |
| 20824 | 248 | fun get_literals (Clause cls) = #literals cls; | 
| 249 | ||
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 250 | exception CLAUSE of string * term; | 
| 15347 | 251 | |
| 20018 | 252 | fun isFalse (Literal (pol, Predicate(pname,_,[]))) = | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 253 | (pol andalso pname = "c_False") orelse | 
| 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 254 | (not pol andalso pname = "c_True") | 
| 17317 
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
 paulson parents: 
17312diff
changeset | 255 | | isFalse _ = false; | 
| 
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
 paulson parents: 
17312diff
changeset | 256 | |
| 20018 | 257 | fun isTrue (Literal (pol, Predicate(pname,_,[]))) = | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 258 | (pol andalso pname = "c_True") orelse | 
| 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 259 | (not pol andalso pname = "c_False") | 
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 260 | | isTrue _ = false; | 
| 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 261 | |
| 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 262 | fun isTaut (Clause {literals,...}) = exists isTrue literals;  
 | 
| 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 263 | |
| 17317 
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
 paulson parents: 
17312diff
changeset | 264 | |
| 18218 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
 paulson parents: 
18199diff
changeset | 265 | (*Declarations of the current theory--to allow suppressing types.*) | 
| 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
 paulson parents: 
18199diff
changeset | 266 | val const_typargs = ref (Library.K [] : (string*typ -> typ list)); | 
| 17317 
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
 paulson parents: 
17312diff
changeset | 267 | |
| 21790 
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
 paulson parents: 
21564diff
changeset | 268 | fun num_typargs(s,T) = length (!const_typargs (s,T)); | 
| 16925 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 269 | |
| 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 270 | (*Initialize the type suppression mechanism with the current theory before | 
| 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 271 | producing any clauses!*) | 
| 18218 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
 paulson parents: 
18199diff
changeset | 272 | fun init thy = (const_typargs := Sign.const_typargs thy); | 
| 16925 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 273 | |
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 274 | |
| 18402 
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
 mengj parents: 
18390diff
changeset | 275 | (*Flatten a type to a fol_type while accumulating sort constraints on the TFrees and | 
| 16925 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 276 | TVars it contains.*) | 
| 18218 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
 paulson parents: 
18199diff
changeset | 277 | fun type_of (Type (a, Ts)) = | 
| 18798 | 278 | let val (folTyps, ts) = types_of Ts | 
| 18218 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
 paulson parents: 
18199diff
changeset | 279 | val t = make_fixed_type_const a | 
| 18798 | 280 | in (Comp(t,folTyps), ts) end | 
| 281 | | type_of (TFree (a,s)) = (AtomF(make_fixed_type_var a), [(FOLTFree a, s)]) | |
| 282 | | type_of (TVar (v, s)) = (AtomV(make_schematic_type_var v), [(FOLTVar v, s)]) | |
| 18218 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
 paulson parents: 
18199diff
changeset | 283 | and types_of Ts = | 
| 18798 | 284 | let val (folTyps,ts) = ListPair.unzip (map type_of Ts) | 
| 285 | in (folTyps, union_all ts) end; | |
| 15390 | 286 | |
| 18439 
4b517881ac7e
Added functions for fol_type; also put some functions to the signature, used by ResHolClause.
 mengj parents: 
18420diff
changeset | 287 | |
| 18218 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
 paulson parents: 
18199diff
changeset | 288 | fun const_types_of (c,T) = types_of (!const_typargs (c,T)); | 
| 16925 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
 paulson parents: 
16903diff
changeset | 289 | |
| 16903 | 290 | (* Any variables created via the METAHYPS tactical should be treated as | 
| 291 | universal vars, although it is represented as "Free(...)" by Isabelle *) | |
| 292 | val isMeta = String.isPrefix "METAHYP1_" | |
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 293 | |
| 18798 | 294 | fun pred_name_type (Const(c,T)) = (make_fixed_const c, const_types_of (c,T)) | 
| 15390 | 295 | | pred_name_type (Free(x,T)) = | 
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 296 |       if isMeta x then raise CLAUSE("Predicate Not First Order 1", Free(x,T)) 
 | 
| 18798 | 297 | else (make_fixed_var x, ([],[])) | 
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 298 |   | pred_name_type (v as Var _) = raise CLAUSE("Predicate Not First Order 2", v)
 | 
| 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 299 |   | pred_name_type t        = raise CLAUSE("Predicate input unexpected", t);
 | 
| 15347 | 300 | |
| 18798 | 301 | fun fun_name_type (Const(c,T)) args = (make_fixed_const c, const_types_of (c,T)) | 
| 302 | | fun_name_type (Free(x,T)) args = | |
| 303 |        if isMeta x then raise CLAUSE("Function Not First Order", Free(x,T))
 | |
| 304 | else (make_fixed_var x, ([],[])) | |
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 305 |   | fun_name_type f args = raise CLAUSE("Function Not First Order 1", f);
 | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 306 | |
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 307 | (*Convert a term to a fol_term while accumulating sort constraints on the TFrees and | 
| 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 308 | TVars it contains.*) | 
| 15347 | 309 | fun term_of (Var(ind_nm,T)) = | 
| 21813 | 310 | let val (_,ts) = type_of T | 
| 311 | in (UVar(make_schematic_var ind_nm), ts) end | |
| 15347 | 312 | | term_of (Free(x,T)) = | 
| 21813 | 313 | let val (_,ts) = type_of T | 
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 314 | in | 
| 21813 | 315 | if isMeta x then (UVar(make_schematic_var(x,0)), ts) | 
| 316 | else (Fun(make_fixed_var x, [], []), ts) | |
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 317 | end | 
| 18218 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
 paulson parents: 
18199diff
changeset | 318 | | term_of app = | 
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 319 | let val (f,args) = strip_comb app | 
| 18798 | 320 | val (funName,(contys,ts1)) = fun_name_type f args | 
| 321 | val (args',ts2) = terms_of args | |
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 322 | in | 
| 18868 | 323 | (Fun(funName,contys,args'), union_all (ts1::ts2)) | 
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 324 | end | 
| 18798 | 325 | and terms_of ts = ListPair.unzip (map term_of ts) | 
| 15390 | 326 | |
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 327 | (*Create a predicate value, again accumulating sort constraints.*) | 
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 328 | fun pred_of (Const("op =", typ), args) =
 | 
| 21813 | 329 | let val (args',ts) = terms_of args | 
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 330 | in | 
| 21813 | 331 | (Predicate(make_fixed_const "op =", [], args'), | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 332 | union_all ts) | 
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 333 | end | 
| 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 334 | | pred_of (pred,args) = | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 335 | let val (pname, (predType,ts1)) = pred_name_type pred | 
| 18798 | 336 | val (args',ts2) = terms_of args | 
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 337 | in | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 338 | (Predicate(pname,predType,args'), union_all (ts1::ts2)) | 
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 339 | end; | 
| 15347 | 340 | |
| 20018 | 341 | (*Treatment of literals, possibly negated*) | 
| 342 | fun predicate_of ((Const("Not",_) $ P), polarity) = predicate_of (P, not polarity)
 | |
| 343 | | predicate_of (term,polarity) = (pred_of (strip_comb term), polarity); | |
| 15347 | 344 | |
| 17888 | 345 | fun literals_of_term1 args (Const("Trueprop",_) $ P) = literals_of_term1 args P
 | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 346 |   | literals_of_term1 args (Const("op |",_) $ P $ Q) = 
 | 
| 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 347 | literals_of_term1 (literals_of_term1 args P) Q | 
| 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 348 | | literals_of_term1 (lits, ts) P = | 
| 20018 | 349 | let val ((pred, ts'), polarity) = predicate_of (P,true) | 
| 350 | val lits' = Literal(polarity,pred) :: lits | |
| 17234 | 351 | in | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 352 | (lits', ts union ts') | 
| 17234 | 353 | end; | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 354 | |
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 355 | val literals_of_term = literals_of_term1 ([],[]); | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 356 | |
| 18403 
df0c0f35c897
Changed literals' ordering and the functions for sorting literals.
 mengj parents: 
18402diff
changeset | 357 | |
| 
df0c0f35c897
Changed literals' ordering and the functions for sorting literals.
 mengj parents: 
18402diff
changeset | 358 | fun list_ord _ ([],[]) = EQUAL | 
| 
df0c0f35c897
Changed literals' ordering and the functions for sorting literals.
 mengj parents: 
18402diff
changeset | 359 | | list_ord _ ([],_) = LESS | 
| 
df0c0f35c897
Changed literals' ordering and the functions for sorting literals.
 mengj parents: 
18402diff
changeset | 360 | | list_ord _ (_,[]) = GREATER | 
| 19207 
33f1b4515ce4
Tidying and tracing. Handling exn CLAUSE so that errors don't reach top-level.
 paulson parents: 
19197diff
changeset | 361 | | list_ord ord (x::xs, y::ys) = | 
| 
33f1b4515ce4
Tidying and tracing. Handling exn CLAUSE so that errors don't reach top-level.
 paulson parents: 
19197diff
changeset | 362 | (case ord(x,y) of EQUAL => list_ord ord (xs,ys) | 
| 
33f1b4515ce4
Tidying and tracing. Handling exn CLAUSE so that errors don't reach top-level.
 paulson parents: 
19197diff
changeset | 363 | | xy_ord => xy_ord); | 
| 
33f1b4515ce4
Tidying and tracing. Handling exn CLAUSE so that errors don't reach top-level.
 paulson parents: 
19197diff
changeset | 364 | |
| 18798 | 365 | (*Make literals for sorted type variables. FIXME: can it use map?*) | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 366 | fun sorts_on_typs (_, []) = ([]) | 
| 16199 
ee95ab217fee
no longer emits literals for type class HOL.type; also minor tidying
 paulson parents: 
16039diff
changeset | 367 | | sorts_on_typs (v, "HOL.type" :: s) = | 
| 18411 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 368 | sorts_on_typs (v,s) (*IGNORE sort "type"*) | 
| 18798 | 369 | | sorts_on_typs ((FOLTVar indx), s::ss) = | 
| 370 | LTVar(make_type_class s, make_schematic_type_var indx) :: | |
| 371 | sorts_on_typs ((FOLTVar indx), ss) | |
| 372 | | sorts_on_typs ((FOLTFree x), s::ss) = | |
| 373 | LTFree(make_type_class s, make_fixed_type_var x) :: | |
| 374 | sorts_on_typs ((FOLTFree x), ss); | |
| 15347 | 375 | |
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 376 | |
| 18798 | 377 | fun pred_of_sort (LTVar (s,ty)) = (s,1) | 
| 378 | | pred_of_sort (LTFree (s,ty)) = (s,1) | |
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 379 | |
| 16199 
ee95ab217fee
no longer emits literals for type class HOL.type; also minor tidying
 paulson parents: 
16039diff
changeset | 380 | (*Given a list of sorted type variables, return two separate lists. | 
| 
ee95ab217fee
no longer emits literals for type class HOL.type; also minor tidying
 paulson parents: 
16039diff
changeset | 381 | The first is for TVars, the second for TFrees.*) | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 382 | fun add_typs_aux [] = ([],[]) | 
| 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 383 | | add_typs_aux ((FOLTVar indx,s)::tss) = | 
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 384 | let val vs = sorts_on_typs (FOLTVar indx, s) | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 385 | val (vss,fss) = add_typs_aux tss | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 386 | in | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 387 | (vs union vss, fss) | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 388 | end | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 389 | | add_typs_aux ((FOLTFree x,s)::tss) = | 
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 390 | let val fs = sorts_on_typs (FOLTFree x, s) | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 391 | val (vss,fss) = add_typs_aux tss | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 392 | in | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 393 | (vss, fs union fss) | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 394 | end; | 
| 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 395 | |
| 20015 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 396 | |
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 397 | (** make axiom and conjecture clauses. **) | 
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 398 | |
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 399 | exception MAKE_CLAUSE; | 
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 400 | fun make_clause (clause_id, axiom_name, th, kind) = | 
| 21470 
7c1b59ddcd56
Consolidation of code to "blacklist" unhelpful theorems, including record
 paulson parents: 
21432diff
changeset | 401 | let val (lits,types_sorts) = literals_of_term (prop_of th) | 
| 20018 | 402 | in if forall isFalse lits | 
| 403 | then error "Problem too trivial for resolution (empty clause)" | |
| 404 |      else Clause {clause_id = clause_id, axiom_name = axiom_name, th = th, 
 | |
| 405 | kind = kind, literals = lits, types_sorts = types_sorts} | |
| 406 | end; | |
| 20015 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 407 | |
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 408 | fun get_tvar_strs [] = [] | 
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 409 | | get_tvar_strs ((FOLTVar indx,s)::tss) = | 
| 20854 | 410 | insert (op =) (make_schematic_type_var indx) (get_tvar_strs tss) | 
| 20015 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 411 | | get_tvar_strs((FOLTFree x,s)::tss) = get_tvar_strs tss | 
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 412 | |
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 413 | (* check if a clause is first-order before making a conjecture clause*) | 
| 20418 | 414 | fun make_conjecture_clause n th = | 
| 22383 
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
 paulson parents: 
22130diff
changeset | 415 | if Meson.is_fol_term (theory_of_thm th) (prop_of th) | 
| 
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
 paulson parents: 
22130diff
changeset | 416 | then make_clause(n, "conjecture", th, Conjecture) | 
| 20418 | 417 |   else raise CLAUSE("Goal is not FOL", prop_of th);
 | 
| 418 | ||
| 20015 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 419 | fun make_conjecture_clauses_aux _ [] = [] | 
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 420 | | make_conjecture_clauses_aux n (t::ts) = | 
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 421 | make_conjecture_clause n t :: make_conjecture_clauses_aux (n+1) ts | 
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 422 | |
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 423 | val make_conjecture_clauses = make_conjecture_clauses_aux 0 | 
| 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 424 | |
| 18199 
d236379ea408
-- before converting axiom and conjecture clauses into ResClause.clause format, perform "check_is_fol_term" first.
 mengj parents: 
18056diff
changeset | 425 | (*before converting an axiom clause to "clause" format, check if it is FOL*) | 
| 22383 
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
 paulson parents: 
22130diff
changeset | 426 | fun make_axiom_clause th (ax_name,cls_id) = | 
| 
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
 paulson parents: 
22130diff
changeset | 427 | if Meson.is_fol_term (theory_of_thm th) (prop_of th) | 
| 
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
 paulson parents: 
22130diff
changeset | 428 | then (SOME (make_clause(cls_id, ax_name, th, Axiom)) handle MAKE_CLAUSE => NONE) | 
| 22130 | 429 |   else (Output.debug (fn () => ("Omitting " ^ ax_name ^ ": Axiom is not FOL")); NONE)
 | 
| 20015 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
 mengj parents: 
19719diff
changeset | 430 | |
| 19443 
e32a4703d834
Take conjectures and axioms as thms when convert them to ResClause.clause format.
 mengj parents: 
19354diff
changeset | 431 | fun make_axiom_clauses [] = [] | 
| 22383 
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
 paulson parents: 
22130diff
changeset | 432 | | make_axiom_clauses ((th,(name,id))::thms) = | 
| 
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
 paulson parents: 
22130diff
changeset | 433 | case make_axiom_clause th (name,id) of | 
| 20022 | 434 | SOME cls => if isTaut cls then make_axiom_clauses thms | 
| 435 | else (name,cls) :: make_axiom_clauses thms | |
| 436 | | NONE => make_axiom_clauses thms; | |
| 19354 | 437 | |
| 15347 | 438 | (**** Isabelle arities ****) | 
| 439 | ||
| 440 | exception ARCLAUSE of string; | |
| 441 | ||
| 442 | type class = string; | |
| 443 | type tcons = string; | |
| 444 | ||
| 18868 | 445 | datatype arLit = TConsLit of bool * (class * tcons * string list) | 
| 446 | | TVarLit of bool * (class * string); | |
| 15347 | 447 | |
| 448 | datatype arityClause = | |
| 21373 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 449 | 	 ArityClause of {axiom_name: axiom_name,
 | 
| 15347 | 450 | kind: kind, | 
| 451 | conclLit: arLit, | |
| 452 | premLits: arLit list}; | |
| 453 | ||
| 454 | ||
| 18798 | 455 | fun gen_TVars 0 = [] | 
| 456 |   | gen_TVars n = ("T_" ^ Int.toString n) :: gen_TVars (n-1);
 | |
| 15347 | 457 | |
| 18411 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 458 | fun pack_sort(_,[]) = [] | 
| 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 459 | | pack_sort(tvar, "HOL.type"::srt) = pack_sort(tvar, srt) (*IGNORE sort "type"*) | 
| 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 460 | | pack_sort(tvar, cls::srt) = (make_type_class cls, tvar) :: pack_sort(tvar, srt); | 
| 15347 | 461 | |
| 21560 | 462 | fun make_TVarLit b (cls,str) = TVarLit(b, (cls,str)); | 
| 463 | ||
| 464 | fun make_TConsLit b (cls,tcons,tvars) = | |
| 18868 | 465 | TConsLit(b, (make_type_class cls, make_fixed_type_const tcons, tvars)); | 
| 15347 | 466 | |
| 18411 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 467 | (*Arity of type constructor tcon :: (arg1,...,argN)res*) | 
| 21373 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 468 | fun make_axiom_arity_clause (tcons, axiom_name, (res,args)) = | 
| 21560 | 469 | let val tvars = gen_TVars (length args) | 
| 17845 
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
 paulson parents: 
17775diff
changeset | 470 | val tvars_srts = ListPair.zip (tvars,args) | 
| 
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
 paulson parents: 
17775diff
changeset | 471 | in | 
| 21373 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 472 |       ArityClause {axiom_name = axiom_name, kind = Axiom, 
 | 
| 21560 | 473 | conclLit = make_TConsLit true (res,tcons,tvars), | 
| 474 | premLits = map (make_TVarLit false) (union_all(map pack_sort tvars_srts))} | |
| 17845 
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
 paulson parents: 
17775diff
changeset | 475 | end; | 
| 15347 | 476 | |
| 477 | ||
| 478 | (**** Isabelle class relations ****) | |
| 479 | ||
| 480 | datatype classrelClause = | |
| 18868 | 481 | 	 ClassrelClause of {axiom_name: axiom_name,
 | 
| 15347 | 482 | subclass: class, | 
| 18411 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
 paulson parents: 
18409diff
changeset | 483 | superclass: class}; | 
| 21290 
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
 paulson parents: 
21254diff
changeset | 484 | |
| 
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
 paulson parents: 
21254diff
changeset | 485 | (*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: 
21416diff
changeset | 486 | fun class_pairs thy [] supers = [] | 
| 
625797c592b2
Optimized class_pairs for the common case of no subclasses
 paulson parents: 
21416diff
changeset | 487 | | class_pairs thy subs supers = | 
| 
625797c592b2
Optimized class_pairs for the common case of no subclasses
 paulson parents: 
21416diff
changeset | 488 | let val class_less = Sorts.class_less(Sign.classes_of thy) | 
| 
625797c592b2
Optimized class_pairs for the common case of no subclasses
 paulson parents: 
21416diff
changeset | 489 | fun add_super sub (super,pairs) = | 
| 
625797c592b2
Optimized class_pairs for the common case of no subclasses
 paulson parents: 
21416diff
changeset | 490 | if class_less (sub,super) then (sub,super)::pairs else pairs | 
| 
625797c592b2
Optimized class_pairs for the common case of no subclasses
 paulson parents: 
21416diff
changeset | 491 | fun add_supers (sub,pairs) = foldl (add_super sub) pairs supers | 
| 
625797c592b2
Optimized class_pairs for the common case of no subclasses
 paulson parents: 
21416diff
changeset | 492 | in foldl add_supers [] subs end; | 
| 15347 | 493 | |
| 21290 
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
 paulson parents: 
21254diff
changeset | 494 | fun make_classrelClause (sub,super) = | 
| 
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
 paulson parents: 
21254diff
changeset | 495 |   ClassrelClause {axiom_name = clrelclause_prefix ^ ascii_of sub ^ "_" ^ ascii_of super,
 | 
| 
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
 paulson parents: 
21254diff
changeset | 496 | subclass = make_type_class sub, | 
| 
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
 paulson parents: 
21254diff
changeset | 497 | superclass = make_type_class super}; | 
| 15347 | 498 | |
| 21290 
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
 paulson parents: 
21254diff
changeset | 499 | fun make_classrel_clauses thy subs supers = | 
| 
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
 paulson parents: 
21254diff
changeset | 500 | map make_classrelClause (class_pairs thy subs supers); | 
| 18868 | 501 | |
| 502 | ||
| 503 | (** Isabelle arities **) | |
| 17845 
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
 paulson parents: 
17775diff
changeset | 504 | |
| 21373 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 505 | fun arity_clause _ _ (tcons, []) = [] | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 506 |   | arity_clause seen n (tcons, ("HOL.type",_)::ars) =  (*ignore*)
 | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 507 | arity_clause seen n (tcons,ars) | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 508 | | arity_clause seen n (tcons, (ar as (class,_)) :: ars) = | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 509 | if class mem_string seen then (*multiple arities for the same tycon, class pair*) | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 510 | make_axiom_arity_clause (tcons, lookup_type_const tcons ^ "_" ^ class ^ "_" ^ Int.toString n, ar) :: | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 511 | arity_clause seen (n+1) (tcons,ars) | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 512 | else | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 513 | make_axiom_arity_clause (tcons, lookup_type_const tcons ^ "_" ^ class, ar) :: | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 514 | arity_clause (class::seen) n (tcons,ars) | 
| 17845 
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
 paulson parents: 
17775diff
changeset | 515 | |
| 
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
 paulson parents: 
17775diff
changeset | 516 | fun multi_arity_clause [] = [] | 
| 19155 | 517 | | multi_arity_clause ((tcons,ars) :: tc_arlists) = | 
| 21373 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 518 | arity_clause [] 1 (tcons, ars) @ | 
| 19155 | 519 | multi_arity_clause tc_arlists | 
| 17845 
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
 paulson parents: 
17775diff
changeset | 520 | |
| 21373 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 521 | (*Generate all pairs (tycon,class,sorts) such that tycon belongs to class in theory thy.*) | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 522 | fun type_class_pairs thy tycons classes = | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 523 | let val alg = Sign.classes_of thy | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 524 | fun domain_sorts (tycon,class) = Sorts.mg_domain alg tycon [class] | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 525 | fun add_class tycon (class,pairs) = | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 526 | (class, domain_sorts(tycon,class))::pairs | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 527 | handle Sorts.CLASS_ERROR _ => pairs | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 528 | fun try_classes tycon = (tycon, foldl (add_class tycon) [] classes) | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 529 | in map try_classes tycons end; | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 530 | |
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 531 | fun arity_clause_thy thy tycons classes = | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 532 | multi_arity_clause (type_class_pairs thy tycons classes); | 
| 17845 
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
 paulson parents: 
17775diff
changeset | 533 | |
| 
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
 paulson parents: 
17775diff
changeset | 534 | |
| 18868 | 535 | (**** Find occurrences of predicates in clauses ****) | 
| 536 | ||
| 537 | (*FIXME: multiple-arity checking doesn't work, as update_new is the wrong | |
| 538 | function (it flags repeated declarations of a function, even with the same arity)*) | |
| 539 | ||
| 540 | fun update_many (tab, keypairs) = foldl (uncurry Symtab.update) tab keypairs; | |
| 541 | ||
| 542 | fun add_predicate_preds (Predicate(pname,tys,tms), preds) = | |
| 543 | if pname = "equal" then preds (*equality is built-in and requires no declaration*) | |
| 544 | else Symtab.update (pname, length tys + length tms) preds | |
| 545 | ||
| 20018 | 546 | fun add_literal_preds (Literal(_,pred), preds) = add_predicate_preds (pred,preds) | 
| 18868 | 547 | |
| 548 | fun add_type_sort_preds ((FOLTVar indx,s), preds) = | |
| 549 | update_many (preds, map pred_of_sort (sorts_on_typs (FOLTVar indx, s))) | |
| 550 | | add_type_sort_preds ((FOLTFree x,s), preds) = | |
| 551 | update_many (preds, map pred_of_sort (sorts_on_typs (FOLTFree x, s))); | |
| 17845 
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
 paulson parents: 
17775diff
changeset | 552 | |
| 18868 | 553 | fun add_clause_preds (Clause {literals, types_sorts, ...}, preds) =
 | 
| 554 | foldl add_literal_preds (foldl add_type_sort_preds preds types_sorts) literals | |
| 555 |   handle Symtab.DUP a => raise ERROR ("predicate " ^ a ^ " has multiple arities")
 | |
| 556 | ||
| 557 | fun add_classrelClause_preds (ClassrelClause {subclass,superclass,...}, preds) =
 | |
| 558 | 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: 
17775diff
changeset | 559 | |
| 21373 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 560 | fun class_of_arityLit (TConsLit(_, (tclass, _, _))) = tclass | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 561 | | class_of_arityLit (TVarLit(_, (tclass, _))) = tclass; | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 562 | |
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 563 | fun add_arityClause_preds (ArityClause {conclLit,premLits,...}, preds) =
 | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 564 | let val classes = map class_of_arityLit (conclLit::premLits) | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 565 | fun upd (class,preds) = Symtab.update (class,1) preds | 
| 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
 paulson parents: 
21290diff
changeset | 566 | in foldl upd preds classes end; | 
| 18868 | 567 | |
| 568 | fun preds_of_clauses clauses clsrel_clauses arity_clauses = | |
| 569 | Symtab.dest | |
| 570 | (foldl add_classrelClause_preds | |
| 571 | (foldl add_arityClause_preds | |
| 572 | (foldl add_clause_preds Symtab.empty clauses) | |
| 573 | arity_clauses) | |
| 574 | clsrel_clauses) | |
| 18798 | 575 | |
| 18868 | 576 | (*** Find occurrences of functions in clauses ***) | 
| 577 | ||
| 578 | fun add_foltype_funcs (AtomV _, funcs) = funcs | |
| 579 | | add_foltype_funcs (AtomF a, funcs) = Symtab.update (a,0) funcs | |
| 580 | | add_foltype_funcs (Comp(a,tys), funcs) = | |
| 581 | foldl add_foltype_funcs (Symtab.update (a, length tys) funcs) tys; | |
| 582 | ||
| 21813 | 583 | fun add_folterm_funcs (UVar _, funcs) = funcs | 
| 18868 | 584 | | add_folterm_funcs (Fun(a,tys,tms), funcs) = | 
| 585 | foldl add_foltype_funcs | |
| 586 | (foldl add_folterm_funcs (Symtab.update (a, length tys + length tms) funcs) | |
| 587 | tms) | |
| 588 | tys | |
| 18798 | 589 | |
| 18868 | 590 | fun add_predicate_funcs (Predicate(_,tys,tms), funcs) = | 
| 591 | foldl add_foltype_funcs (foldl add_folterm_funcs funcs tms) tys; | |
| 592 | ||
| 20018 | 593 | fun add_literal_funcs (Literal(_,pred), funcs) = add_predicate_funcs (pred,funcs) | 
| 18868 | 594 | |
| 20038 | 595 | (*TFrees are recorded as constants*) | 
| 596 | fun add_type_sort_funcs ((FOLTVar _, _), funcs) = funcs | |
| 597 | | add_type_sort_funcs ((FOLTFree a, _), funcs) = | |
| 598 | Symtab.update (make_fixed_type_var a, 0) funcs | |
| 599 | ||
| 18868 | 600 | fun add_arityClause_funcs (ArityClause {conclLit,...}, funcs) =
 | 
| 601 | let val TConsLit(_, (_, tcons, tvars)) = conclLit | |
| 602 | in Symtab.update (tcons, length tvars) funcs end; | |
| 17845 
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
 paulson parents: 
17775diff
changeset | 603 | |
| 20038 | 604 | fun add_clause_funcs (Clause {literals, types_sorts, ...}, funcs) =
 | 
| 605 | foldl add_literal_funcs (foldl add_type_sort_funcs funcs types_sorts) | |
| 606 | literals | |
| 18868 | 607 |   handle Symtab.DUP a => raise ERROR ("function " ^ a ^ " has multiple arities")
 | 
| 608 | ||
| 609 | fun funcs_of_clauses clauses arity_clauses = | |
| 610 | Symtab.dest (foldl add_arityClause_funcs | |
| 611 | (foldl add_clause_funcs Symtab.empty clauses) | |
| 612 | arity_clauses) | |
| 613 | ||
| 614 | ||
| 615 | (**** String-oriented operations ****) | |
| 15347 | 616 | |
| 21813 | 617 | fun string_of_term (UVar x) = x | 
| 18218 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
 paulson parents: 
18199diff
changeset | 618 | | string_of_term (Fun (name,typs,terms)) = | 
| 21790 
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
 paulson parents: 
21564diff
changeset | 619 | name ^ (paren_pack (map string_of_term terms @ map string_of_fol_type typs)); | 
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 620 | |
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 621 | fun string_of_pair [t1,t2] = (string_of_term t1, string_of_term t2) | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 622 |   | string_of_pair _ = raise ERROR ("equality predicate requires two arguments");
 | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 623 | |
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 624 | fun string_of_equality ts = | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 625 | let val (s1,s2) = string_of_pair ts | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 626 |   in "equal(" ^ s1 ^ "," ^ s2 ^ ")" end;
 | 
| 15347 | 627 | |
| 628 | (* before output the string of the predicate, check if the predicate corresponds to an equality or not. *) | |
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 629 | fun string_of_predicate (Predicate("equal",_,ts)) = string_of_equality ts
 | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 630 | | string_of_predicate (Predicate(name,typs,ts)) = | 
| 21790 
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
 paulson parents: 
21564diff
changeset | 631 | name ^ (paren_pack (map string_of_term ts @ map string_of_fol_type typs)); | 
| 17317 
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
 paulson parents: 
17312diff
changeset | 632 | |
| 
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
 paulson parents: 
17312diff
changeset | 633 | fun string_of_clausename (cls_id,ax_name) = | 
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 634 | 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: 
17312diff
changeset | 635 | |
| 21564 | 636 | fun clause_name_of (cls_id,ax_name) = | 
| 637 | ascii_of ax_name ^ "_" ^ Int.toString cls_id; | |
| 638 | ||
| 17317 
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
 paulson parents: 
17312diff
changeset | 639 | fun string_of_type_clsname (cls_id,ax_name,idx) = | 
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 640 | string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx); | 
| 18863 | 641 | |
| 642 | (*Write a list of strings to a file*) | |
| 643 | fun writeln_strs os = List.app (fn s => TextIO.output (os,s)); | |
| 644 | ||
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 645 | |
| 18868 | 646 | (**** Producing DFG files ****) | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 647 | |
| 18863 | 648 | (*Attach sign in DFG syntax: false means negate.*) | 
| 649 | fun dfg_sign true s = s | |
| 650 |   | dfg_sign false s = "not(" ^ s ^ ")"  
 | |
| 651 | ||
| 20018 | 652 | fun dfg_literal (Literal(pol,pred)) = dfg_sign pol (string_of_predicate pred) | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 653 | |
| 18798 | 654 | fun dfg_of_typeLit (LTVar (s,ty)) = "not(" ^ s ^ "(" ^ ty ^ "))"
 | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 655 |   | dfg_of_typeLit (LTFree (s,ty)) = s ^ "(" ^ ty ^ ")";
 | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 656 | |
| 18868 | 657 | (*Enclose the clause body by quantifiers, if necessary*) | 
| 658 | fun dfg_forall [] body = body | |
| 659 | | dfg_forall vars body = "forall([" ^ commas vars ^ "],\n" ^ body ^ ")" | |
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 660 | |
| 18868 | 661 | fun gen_dfg_cls (cls_id, ax_name, knd, lits, vars) = | 
| 662 |     "clause( %(" ^ knd ^ ")\n" ^ 
 | |
| 663 |     dfg_forall vars ("or(" ^ lits ^ ")") ^ ",\n" ^ 
 | |
| 18863 | 664 | string_of_clausename (cls_id,ax_name) ^ ").\n\n"; | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 665 | |
| 18869 
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
 paulson parents: 
18868diff
changeset | 666 | fun dfg_clause_aux (Clause{literals, types_sorts, ...}) = 
 | 
| 21790 
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
 paulson parents: 
21564diff
changeset | 667 | let val (tvar_lits,tfree_lits) = add_typs_aux types_sorts | 
| 
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
 paulson parents: 
21564diff
changeset | 668 | in (map dfg_of_typeLit tvar_lits @ map dfg_literal literals, | 
| 
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
 paulson parents: 
21564diff
changeset | 669 | map dfg_of_typeLit tfree_lits) | 
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 670 | end; | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 671 | |
| 20018 | 672 | fun dfg_folterms (Literal(pol,pred)) = | 
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 673 | let val Predicate (_, _, folterms) = pred | 
| 18218 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
 paulson parents: 
18199diff
changeset | 674 | in folterms end | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 675 | |
| 21813 | 676 | fun get_uvars (UVar a) = [a] | 
| 18868 | 677 | | get_uvars (Fun (_,typ,tlist)) = union_all(map get_uvars tlist) | 
| 17404 
d16c3a62c396
the experimental tagging system, and the usual tidying
 paulson parents: 
17375diff
changeset | 678 | |
| 18868 | 679 | fun dfg_vars (Clause {literals,...}) =
 | 
| 18920 | 680 | union_all (map get_uvars (List.concat (map dfg_folterms literals))) | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 681 | |
| 18798 | 682 | fun clause2dfg (cls as Clause{axiom_name,clause_id,kind,types_sorts,...}) =
 | 
| 17230 
77e93bf303a5
fixed arities and restored changes that had gone missing
 paulson parents: 
17150diff
changeset | 683 | let val (lits,tfree_lits) = dfg_clause_aux cls | 
| 18798 | 684 | (*"lits" includes the typing assumptions (TVars)*) | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 685 | val vars = dfg_vars cls | 
| 18798 | 686 | val tvars = get_tvar_strs types_sorts | 
| 20038 | 687 | val cls_str = gen_dfg_cls(clause_id, axiom_name, name_of_kind kind, | 
| 688 | commas lits, tvars@vars) | |
| 18798 | 689 | in (cls_str, tfree_lits) end; | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 690 | |
| 18798 | 691 | fun string_of_arity (name, num) =  "(" ^ name ^ "," ^ Int.toString num ^ ")"
 | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 692 | |
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 693 | fun string_of_preds [] = "" | 
| 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 694 | | 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: 
16976diff
changeset | 695 | |
| 18856 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 696 | fun string_of_funcs [] = "" | 
| 
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
 paulson parents: 
18798diff
changeset | 697 | | 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: 
16976diff
changeset | 698 | |
| 17234 | 699 | fun string_of_symbols predstr funcstr = | 
| 700 | "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: 
16976diff
changeset | 701 | |
| 18798 | 702 | fun string_of_start name = "begin_problem(" ^ name ^ ").\n\n";
 | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 703 | |
| 18863 | 704 | fun string_of_descrip name = | 
| 18868 | 705 |   "list_of_descriptions.\nname({*" ^ name ^ 
 | 
| 706 |   "*}).\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: 
16976diff
changeset | 707 | |
| 18863 | 708 | fun dfg_tfree_clause tfree_lit = | 
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 709 | "clause( %(negated_conjecture)\n" ^ "or( " ^ tfree_lit ^ "),\n" ^ "tfree_tcs" ^ ").\n\n" | 
| 18863 | 710 | |
| 711 | fun dfg_of_arLit (TConsLit(pol,(c,t,args))) = | |
| 712 |       dfg_sign pol (c ^ "(" ^ t ^ paren_pack args ^ ")")
 | |
| 713 | | dfg_of_arLit (TVarLit(pol,(c,str))) = | |
| 714 |       dfg_sign pol (c ^ "(" ^ str ^ ")")
 | |
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 715 | |
| 20038 | 716 | fun dfg_classrelLits sub sup =  "not(" ^ sub ^ "(T)), " ^ sup ^ "(T)";
 | 
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 717 | |
| 18868 | 718 | fun dfg_classrelClause (ClassrelClause {axiom_name,subclass,superclass,...}) =
 | 
| 719 | "clause(forall([T],\nor( " ^ dfg_classrelLits subclass superclass ^ ")),\n" ^ | |
| 720 | axiom_name ^ ").\n\n"; | |
| 721 | ||
| 21560 | 722 | fun string_of_ar axiom_name = arclause_prefix ^ ascii_of axiom_name; | 
| 723 | ||
| 724 | fun dfg_arity_clause (ArityClause{axiom_name,kind,conclLit,premLits,...}) = 
 | |
| 725 | let val TConsLit(_, (_,_,tvars)) = conclLit | |
| 18868 | 726 | val lits = map dfg_of_arLit (conclLit :: premLits) | 
| 18863 | 727 | in | 
| 21560 | 728 |       "clause( %(" ^ name_of_kind kind ^ ")\n" ^ 
 | 
| 18868 | 729 |       dfg_forall tvars ("or( " ^ commas lits ^ ")") ^ ",\n" ^
 | 
| 21560 | 730 | string_of_ar axiom_name ^ ").\n\n" | 
| 18863 | 731 | end; | 
| 732 | ||
| 733 | (* write out a subgoal in DFG format to the file "xxxx_N"*) | |
| 20038 | 734 | fun dfg_write_file thms filename (ax_tuples,classrel_clauses,arity_clauses) = | 
| 18863 | 735 | let | 
| 22130 | 736 |     val _ = Output.debug (fn () => ("Preparing to write the DFG file " ^ filename))
 | 
| 19719 | 737 | val conjectures = make_conjecture_clauses thms | 
| 20038 | 738 | val (clnames,axclauses) = ListPair.unzip (make_axiom_clauses ax_tuples) | 
| 18868 | 739 | val (dfg_clss, tfree_litss) = ListPair.unzip (map clause2dfg conjectures) | 
| 20038 | 740 | val clss = conjectures @ axclauses | 
| 18868 | 741 | val funcs = funcs_of_clauses clss arity_clauses | 
| 742 | and preds = preds_of_clauses clss classrel_clauses arity_clauses | |
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
21813diff
changeset | 743 | and probname = Path.implode (Path.base (Path.explode filename)) | 
| 20038 | 744 | val (axstrs, _) = ListPair.unzip (map clause2dfg axclauses) | 
| 18863 | 745 | val tfree_clss = map dfg_tfree_clause (union_all tfree_litss) | 
| 19155 | 746 | val out = TextIO.openOut filename | 
| 18863 | 747 | in | 
| 18868 | 748 | TextIO.output (out, string_of_start probname); | 
| 749 | TextIO.output (out, string_of_descrip probname); | |
| 750 | TextIO.output (out, string_of_symbols (string_of_funcs funcs) (string_of_preds preds)); | |
| 751 | TextIO.output (out, "list_of_clauses(axioms,cnf).\n"); | |
| 752 | writeln_strs out axstrs; | |
| 753 | List.app (curry TextIO.output out o dfg_classrelClause) classrel_clauses; | |
| 754 | List.app (curry TextIO.output out o dfg_arity_clause) arity_clauses; | |
| 755 | TextIO.output (out, "end_of_list.\n\nlist_of_clauses(conjectures,cnf).\n"); | |
| 756 | writeln_strs out tfree_clss; | |
| 757 | writeln_strs out dfg_clss; | |
| 758 | TextIO.output (out, "end_of_list.\n\nend_problem.\n"); | |
| 20022 | 759 | TextIO.closeOut out; | 
| 760 | clnames | |
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 761 | end; | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 762 | |
| 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 763 | |
| 18869 
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
 paulson parents: 
18868diff
changeset | 764 | (**** Produce TPTP files ****) | 
| 18868 | 765 | |
| 766 | (*Attach sign in TPTP syntax: false means negate.*) | |
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 767 | fun tptp_sign true s = s | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 768 | | tptp_sign false s = "~ " ^ s | 
| 18868 | 769 | |
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 770 | fun tptp_of_equality pol ts = | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 771 | let val (s1,s2) = string_of_pair ts | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 772 | val eqop = if pol then " = " else " != " | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 773 | in s1 ^ eqop ^ s2 end; | 
| 15347 | 774 | |
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 775 | fun tptp_literal (Literal(pol,Predicate("equal",_,ts))) = tptp_of_equality pol ts
 | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 776 | | tptp_literal (Literal(pol,pred)) = tptp_sign pol (string_of_predicate pred); | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 777 | |
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 778 | fun tptp_of_typeLit (LTVar (s,ty))  = tptp_sign false (s ^ "(" ^ ty ^ ")")
 | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 779 |   | tptp_of_typeLit (LTFree (s,ty)) = tptp_sign true  (s ^ "(" ^ ty ^ ")");
 | 
| 15347 | 780 | |
| 781 | fun gen_tptp_cls (cls_id,ax_name,knd,lits) = | |
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 782 |     "cnf(" ^ string_of_clausename (cls_id,ax_name) ^ "," ^ 
 | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 783 | name_of_kind knd ^ "," ^ tptp_pack lits ^ ").\n"; | 
| 15347 | 784 | |
| 18869 
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
 paulson parents: 
18868diff
changeset | 785 | fun tptp_type_lits (Clause {literals, types_sorts, ...}) = 
 | 
| 21790 
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
 paulson parents: 
21564diff
changeset | 786 | let val (tvar_lits,tfree_lits) = add_typs_aux types_sorts | 
| 
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
 paulson parents: 
21564diff
changeset | 787 | in | 
| 
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
 paulson parents: 
21564diff
changeset | 788 | (map tptp_of_typeLit tvar_lits @ map tptp_literal literals, | 
| 
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
 paulson parents: 
21564diff
changeset | 789 | map tptp_of_typeLit tfree_lits) | 
| 
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
 paulson parents: 
21564diff
changeset | 790 | end; | 
| 15347 | 791 | |
| 18869 
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
 paulson parents: 
18868diff
changeset | 792 | fun clause2tptp (cls as Clause {clause_id, axiom_name, kind, ...}) =
 | 
| 17422 | 793 | let val (lits,tfree_lits) = tptp_type_lits cls | 
| 17305 
6cef3aedd661
axioms  now included in tptp files, no /bin/cat and various tidying
 paulson parents: 
17261diff
changeset | 794 | (*"lits" includes the typing assumptions (TVars)*) | 
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 795 | val cls_str = gen_tptp_cls(clause_id, axiom_name, kind, lits) | 
| 15608 | 796 | in | 
| 797 | (cls_str,tfree_lits) | |
| 798 | end; | |
| 799 | ||
| 18863 | 800 | fun tptp_tfree_clause tfree_lit = | 
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 801 |     "cnf(" ^ "tfree_tcs," ^ "negated_conjecture" ^ "," ^ tptp_pack[tfree_lit] ^ ").\n";
 | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 802 | |
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 803 | fun tptp_of_arLit (TConsLit(b,(c,t,args))) = | 
| 18868 | 804 |       tptp_sign b (c ^ "(" ^ t ^ paren_pack args ^ ")")
 | 
| 17525 
ae5bb6001afb
tidying, and support for axclass/classrel clauses
 paulson parents: 
17422diff
changeset | 805 | | tptp_of_arLit (TVarLit(b,(c,str))) = | 
| 18868 | 806 |       tptp_sign b (c ^ "(" ^ str ^ ")")
 | 
| 15347 | 807 | |
| 21560 | 808 | fun tptp_arity_clause (ArityClause{axiom_name,kind,conclLit,premLits,...}) = 
 | 
| 809 |   "cnf(" ^ string_of_ar axiom_name ^ "," ^ name_of_kind kind ^ "," ^ 
 | |
| 810 | tptp_pack (map tptp_of_arLit (conclLit :: premLits)) ^ ").\n"; | |
| 15347 | 811 | |
| 812 | fun tptp_classrelLits sub sup = | |
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 813 | let val tvar = "(T)" | 
| 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 814 | in tptp_pack [tptp_sign false (sub^tvar), tptp_sign true (sup^tvar)] end; | 
| 15347 | 815 | |
| 18868 | 816 | fun tptp_classrelClause (ClassrelClause {axiom_name,subclass,superclass,...}) =
 | 
| 21509 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
 paulson parents: 
21470diff
changeset | 817 |   "cnf(" ^ axiom_name ^ ",axiom," ^ tptp_classrelLits subclass superclass ^ ").\n" 
 | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 818 | |
| 18863 | 819 | (* write out a subgoal as tptp clauses to the file "xxxx_N"*) | 
| 20038 | 820 | fun tptp_write_file thms filename (ax_tuples,classrel_clauses,arity_clauses) = | 
| 18863 | 821 | let | 
| 22130 | 822 |     val _ = Output.debug (fn () => ("Preparing to write the TPTP file " ^ filename))
 | 
| 19443 
e32a4703d834
Take conjectures and axioms as thms when convert them to ResClause.clause format.
 mengj parents: 
19354diff
changeset | 823 | val clss = make_conjecture_clauses thms | 
| 20038 | 824 | val (clnames,axclauses) = ListPair.unzip (make_axiom_clauses ax_tuples) | 
| 18863 | 825 | val (tptp_clss,tfree_litss) = ListPair.unzip (map clause2tptp clss) | 
| 826 | val tfree_clss = map tptp_tfree_clause (foldl (op union_string) [] tfree_litss) | |
| 827 | val out = TextIO.openOut filename | |
| 828 | in | |
| 20038 | 829 | List.app (curry TextIO.output out o #1 o clause2tptp) axclauses; | 
| 18863 | 830 | writeln_strs out tfree_clss; | 
| 831 | writeln_strs out tptp_clss; | |
| 18868 | 832 | List.app (curry TextIO.output out o tptp_classrelClause) classrel_clauses; | 
| 833 | List.app (curry TextIO.output out o tptp_arity_clause) arity_clauses; | |
| 20022 | 834 | TextIO.closeOut out; | 
| 835 | clnames | |
| 18863 | 836 | end; | 
| 837 | ||
| 15347 | 838 | end; |