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